@johpaz/hive-sdk 0.1.3 → 0.1.5

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 (272) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +78 -23
  3. package/bunfig.toml +4 -2
  4. package/docs/API-AGENTS.md +78 -27
  5. package/docs/API-CONTEXT-COMPILER.md +31 -34
  6. package/docs/API-TOOLS-SKILLS-CHANNELS.md +58 -22
  7. package/docs/HIVE-HARNESS.md +1 -1
  8. package/docs/INDEX.md +4 -4
  9. package/docs/TEMPLATE-HIVE-APP.md +10 -10
  10. package/package.json +9 -4
  11. package/packages/cli/package.json +2 -2
  12. package/packages/cli/src/commands/create-app.test.ts +36 -7
  13. package/packages/cli/src/commands/init.ts +3 -3
  14. package/packages/cli/src/commands/run.ts +1 -1
  15. package/packages/cli/src/commands/test.ts +37 -25
  16. package/packages/cli/src/commands/trace.ts +30 -28
  17. package/packages/cli/templates/hive-app/.env.example +10 -2
  18. package/packages/cli/templates/hive-app/README.md +103 -0
  19. package/packages/cli/templates/hive-app/hive.config.ts +9 -3
  20. package/packages/cli/templates/hive-app/src/agents/coordinator.ts +8 -1
  21. package/packages/cli/templates/hive-app/src/main.ts +12 -19
  22. package/packages/core/package.json +5 -4
  23. package/packages/core/src/agent/acceptance-checks.ts +166 -0
  24. package/packages/core/src/agent/agent-catalog.ts +348 -0
  25. package/packages/core/src/agent/agent-loop.ts +1373 -0
  26. package/packages/core/src/agent/capability-search.ts +186 -0
  27. package/packages/core/src/agent/catalog-selector.ts +103 -0
  28. package/packages/core/src/agent/{Compaction.ts → compaction.ts} +86 -63
  29. package/packages/core/src/agent/context-compiler.ts +689 -0
  30. package/packages/core/src/agent/conversation-store.ts +381 -0
  31. package/packages/core/src/agent/curator.ts +276 -0
  32. package/packages/core/src/agent/delegation-runtime.ts +241 -0
  33. package/packages/core/src/agent/goal-runner.ts +323 -0
  34. package/packages/core/src/agent/index.ts +17 -12
  35. package/packages/core/src/agent/llm-client.ts +266 -0
  36. package/packages/core/src/agent/llm-providers/anthropic.ts +264 -0
  37. package/packages/core/src/agent/llm-providers/deepseek.ts +8 -0
  38. package/packages/core/src/agent/{providers → llm-providers}/gemini.ts +98 -60
  39. package/packages/core/src/agent/llm-providers/groq.ts +5 -0
  40. package/packages/core/src/agent/llm-providers/hiveagents.ts +253 -0
  41. package/packages/core/src/agent/{providers → llm-providers}/interface.ts +73 -13
  42. package/packages/core/src/agent/llm-providers/kimi.ts +8 -0
  43. package/packages/core/src/agent/llm-providers/minimax.ts +13 -0
  44. package/packages/core/src/agent/llm-providers/mistral.ts +5 -0
  45. package/packages/core/src/agent/llm-providers/modelscope.ts +5 -0
  46. package/packages/core/src/agent/llm-providers/nvidia.ts +5 -0
  47. package/packages/core/src/agent/{providers → llm-providers}/ollama.ts +31 -5
  48. package/packages/core/src/agent/llm-providers/openai-compat-base.ts +418 -0
  49. package/packages/core/src/agent/llm-providers/openai.ts +5 -0
  50. package/packages/core/src/agent/llm-providers/opencode-go.ts +9 -0
  51. package/packages/core/src/agent/llm-providers/openrouter.ts +5 -0
  52. package/packages/core/src/agent/llm-providers/qwen.ts +5 -0
  53. package/packages/core/src/agent/llm-providers/z-ai.ts +5 -0
  54. package/packages/core/src/agent/minimal-loadout.ts +47 -0
  55. package/packages/core/src/agent/playbook-selector.ts +119 -0
  56. package/packages/core/src/agent/{PromptBuilder.ts → prompt-builder.ts} +21 -22
  57. package/packages/core/src/{harness → agent}/proof-packet.ts +16 -21
  58. package/packages/core/src/agent/providers/index.ts +35 -16
  59. package/packages/core/src/agent/reflector.ts +320 -0
  60. package/packages/core/src/agent/routing-intent.ts +22 -0
  61. package/packages/core/src/{harness → agent}/run-epoch.ts +4 -3
  62. package/packages/core/src/{harness → agent}/run-store.ts +142 -81
  63. package/packages/core/src/agent/{Service.ts → service.ts} +37 -26
  64. package/packages/core/src/agent/skill-selector.ts +374 -0
  65. package/packages/core/src/agent/stuck-loop.ts +209 -0
  66. package/packages/core/src/agent/{selectors/ToolSelector.ts → tool-selector.ts} +188 -178
  67. package/packages/core/src/{ace/Tracer.ts → agent/tracer.ts} +37 -27
  68. package/packages/core/src/api/createAgent.test.ts +139 -27
  69. package/packages/core/src/api/createAgent.ts +232 -44
  70. package/packages/core/src/artifacts/store.ts +162 -0
  71. package/packages/core/src/canvas/canvas-manager.ts +161 -0
  72. package/packages/core/src/canvas/canvas.test.ts +8 -4
  73. package/packages/core/src/canvas/emitter.ts +131 -80
  74. package/packages/core/src/canvas/index.ts +1 -3
  75. package/packages/core/src/channels/base.ts +9 -1
  76. package/packages/core/src/channels/discord.ts +5 -4
  77. package/packages/core/src/channels/manager.ts +122 -30
  78. package/packages/core/src/channels/slack.ts +5 -4
  79. package/packages/core/src/channels/telegram.ts +36 -6
  80. package/packages/core/src/channels/webchat.ts +11 -10
  81. package/packages/core/src/channels/whatsapp.ts +23 -7
  82. package/packages/core/src/config/index.ts +13 -2
  83. package/packages/core/src/config/loader.ts +71 -29
  84. package/packages/core/src/ethics/EthicsGuard.test.ts +90 -36
  85. package/packages/core/src/ethics/EthicsGuard.ts +51 -47
  86. package/packages/core/src/events/agent-bus.ts +44 -68
  87. package/packages/core/src/events/channel-narration.ts +150 -0
  88. package/packages/core/src/events/narration.ts +82 -0
  89. package/packages/core/src/events/tool-narration.ts +62 -0
  90. package/packages/core/src/gateway/delegation-groups.ts +258 -0
  91. package/packages/core/src/{harness → gateway}/durable-queue.ts +102 -42
  92. package/packages/core/src/{harness → gateway}/job-store.ts +85 -48
  93. package/packages/core/src/gateway/lane-queue.ts +173 -0
  94. package/packages/core/src/gateway/notification-inbox.ts +57 -0
  95. package/packages/core/src/gateway/server.ts +1 -1
  96. package/packages/core/src/harness/index.ts +46 -27
  97. package/packages/core/src/index.ts +33 -20
  98. package/packages/core/src/mcp/hot-reload.ts +32 -23
  99. package/packages/core/src/mcp/index.ts +6 -3
  100. package/packages/core/src/mcp/singleton.ts +1 -4
  101. package/packages/core/src/mcp/tool-sync.ts +138 -0
  102. package/packages/core/src/memory/Scratchpad.test.ts +39 -20
  103. package/packages/core/src/memory/Scratchpad.ts +27 -34
  104. package/packages/core/src/multimodal/vision-service.ts +44 -38
  105. package/packages/core/src/resilience/retry.ts +95 -0
  106. package/packages/core/src/scheduler/CronScheduler.ts +334 -287
  107. package/packages/core/src/scheduler/index.ts +9 -7
  108. package/packages/core/src/scheduler/integration.ts +46 -26
  109. package/packages/core/src/scheduler/scheduler.test.ts +9 -13
  110. package/packages/core/src/scheduler/types.ts +7 -2
  111. package/packages/core/src/security/Pairing.ts +1 -1
  112. package/packages/core/src/skills/bundled/a2ui/a2ui_dashboard/SKILL.md +176 -0
  113. package/packages/core/src/skills/bundled/a2ui/a2ui_form/SKILL.md +202 -0
  114. package/packages/core/src/skills/bundled/a2ui/a2ui_interactive/SKILL.md +206 -0
  115. package/packages/core/src/skills/bundled/agents/agent_spawner/SKILL.md +173 -0
  116. package/packages/core/src/skills/bundled/agents/memory_manager/SKILL.md +143 -0
  117. package/packages/core/src/skills/bundled/agents/research_and_remember/SKILL.md +139 -0
  118. package/packages/core/src/skills/bundled/agents/task_orchestrator/SKILL.md +98 -0
  119. package/packages/core/src/skills/bundled/api/api_client/SKILL.md +132 -0
  120. package/packages/core/src/skills/bundled/cli/cli_pipeline/SKILL.md +135 -0
  121. package/packages/core/src/skills/bundled/cli/cli_safe_exec/SKILL.md +125 -0
  122. package/packages/core/src/skills/bundled/cli/software_engineering/SKILL.md +23 -0
  123. package/packages/core/src/skills/bundled/cron_manager/SKILL.md +188 -0
  124. package/packages/core/src/skills/bundled/cron_reminder/SKILL.md +112 -0
  125. package/packages/core/src/skills/bundled/filesystem/file_manager/SKILL.md +118 -0
  126. package/packages/core/src/skills/bundled/filesystem/file_read_and_summarize/SKILL.md +109 -0
  127. package/packages/core/src/skills/bundled/filesystem/file_writer/SKILL.md +129 -0
  128. package/packages/core/src/skills/bundled/filesystem/workspace_file_operator/SKILL.md +22 -0
  129. package/packages/core/src/skills/bundled/office/office_document_manager/SKILL.md +262 -0
  130. package/packages/core/src/skills/bundled/search_knowledge/capability_discovery/SKILL.md +75 -0
  131. package/packages/core/src/skills/bundled/web/browser_automate/SKILL.md +120 -0
  132. package/packages/core/src/skills/bundled/web/browser_scrape/SKILL.md +109 -0
  133. package/packages/core/src/skills/bundled/web/web_monitor/SKILL.md +127 -0
  134. package/packages/core/src/skills/bundled/web/web_research/SKILL.md +119 -0
  135. package/packages/core/src/skills/bundled-data.generated.ts +731 -2678
  136. package/packages/core/src/skills/skills.test.ts +52 -11
  137. package/packages/core/src/{harness → storage}/boot-id.ts +5 -2
  138. package/packages/core/src/storage/bootstrap.ts +151 -0
  139. package/packages/core/src/storage/causal-events.ts +84 -0
  140. package/packages/core/src/storage/collections.ts +680 -0
  141. package/packages/core/src/storage/crypto.ts +205 -74
  142. package/packages/core/src/{harness/db-helpers.ts → storage/hive.ts} +63 -7
  143. package/packages/core/src/storage/hivedb.ts +61 -0
  144. package/packages/core/src/storage/index.ts +111 -17
  145. package/packages/core/src/storage/model-id.ts +53 -0
  146. package/packages/core/src/storage/onboarding.ts +540 -972
  147. package/packages/core/src/storage/reconcile.ts +238 -0
  148. package/packages/core/src/storage/seed.ts +572 -406
  149. package/packages/core/src/storage/usage.ts +285 -225
  150. package/packages/core/src/storage/user-email.ts +11 -0
  151. package/packages/core/src/swarm/AgentExecutor.ts +1 -1
  152. package/packages/core/src/swarm/EventBridge.ts +1 -1
  153. package/packages/core/src/swarm/index.ts +12 -9
  154. package/packages/core/src/tool-runtime/index.ts +146 -23
  155. package/packages/core/src/tool-runtime/tool-worker.ts +2 -2
  156. package/packages/core/src/tool-runtime/worker-tools.ts +27 -0
  157. package/packages/core/src/{canvas/a2ui-tools.ts → tools/a2ui/index.ts} +17 -8
  158. package/packages/core/src/tools/agents/get-available-models.ts +36 -54
  159. package/packages/core/src/tools/agents/index.ts +784 -292
  160. package/packages/core/src/tools/api/api-request.test.ts +164 -0
  161. package/packages/core/src/tools/api/api-request.ts +174 -0
  162. package/packages/core/src/tools/api/index.ts +16 -0
  163. package/packages/core/src/tools/cli/index.ts +4 -0
  164. package/packages/core/src/tools/core/index.ts +281 -112
  165. package/packages/core/src/tools/cron/index.ts +121 -124
  166. package/packages/core/src/tools/index.ts +63 -78
  167. package/packages/core/src/tools/office/office-escribir-xlsx.ts +3 -1
  168. package/packages/core/src/tools/types.ts +3 -1
  169. package/packages/core/src/tools/web/artifact-inspect.ts +23 -0
  170. package/packages/core/src/tools/web/browser-screenshot.ts +26 -5
  171. package/packages/core/src/tools/web/browser-service.ts +5 -0
  172. package/packages/core/src/tools/web/browser-type.ts +3 -8
  173. package/packages/core/src/tools/web/index.ts +4 -4
  174. package/packages/core/src/voice/index.ts +89 -63
  175. package/packages/core/src/workers/agent.worker.ts +2 -2
  176. package/packages/core/src/workers/workers.test.ts +3 -10
  177. package/scripts/bump-version.ts +248 -0
  178. package/scripts/generate-skill-bundle.ts +108 -0
  179. package/test/agent-loop-terminal-synthesis.test.ts +32 -0
  180. package/test/catalog-agents-stay-enabled.test.ts +117 -0
  181. package/test/causal-events.test.ts +117 -0
  182. package/test/compaction.test.ts +105 -0
  183. package/test/context-compiler.test.ts +269 -0
  184. package/test/curator.test.ts +130 -0
  185. package/test/durable-queue.test.ts +114 -0
  186. package/test/harness-barrel.test.ts +64 -0
  187. package/test/hive-helpers.test.ts +130 -0
  188. package/test/hivedb-search.test.ts +189 -0
  189. package/test/internal-turns.test.ts +166 -0
  190. package/test/job-idempotency.test.ts +68 -0
  191. package/test/job-retry-backoff.test.ts +184 -0
  192. package/test/job-store.test.ts +381 -0
  193. package/test/llm-retry.test.ts +97 -0
  194. package/test/memory-perf.test.ts +774 -0
  195. package/test/minimal-loadout.test.ts +78 -0
  196. package/test/model-catalog.test.ts +105 -0
  197. package/test/preload.ts +12 -0
  198. package/test/reflector.test.ts +320 -0
  199. package/test/retention-cap.test.ts +91 -0
  200. package/test/retired-capabilities-pruned.test.ts +192 -0
  201. package/test/run-store.test.ts +355 -0
  202. package/test/scratchpad.test.ts +74 -0
  203. package/test/secrets-durability.test.ts +119 -0
  204. package/test/seed-model-reseed.test.ts +155 -0
  205. package/test/setup-agent-seed.test.ts +264 -0
  206. package/test/tool-inventory.test.ts +65 -0
  207. package/test/tool-runtime.test.ts +258 -0
  208. package/test/toon.test.ts +429 -0
  209. package/tsconfig.json +2 -0
  210. package/packages/core/src/ace/Curator.ts +0 -158
  211. package/packages/core/src/ace/Reflector.ts +0 -200
  212. package/packages/core/src/ace/index.ts +0 -4
  213. package/packages/core/src/agent/AgentRunner.ts +0 -711
  214. package/packages/core/src/agent/ContextCompiler.ts +0 -567
  215. package/packages/core/src/agent/ContextGuard.ts +0 -91
  216. package/packages/core/src/agent/ConversationStore.ts +0 -254
  217. package/packages/core/src/agent/Hooks.ts +0 -166
  218. package/packages/core/src/agent/StuckLoop.ts +0 -133
  219. package/packages/core/src/agent/providers/LLMClient.ts +0 -149
  220. package/packages/core/src/agent/providers/anthropic.ts +0 -212
  221. package/packages/core/src/agent/providers/openai-compat.ts +0 -231
  222. package/packages/core/src/agent/selectors/PlaybookSelector.ts +0 -121
  223. package/packages/core/src/agent/selectors/SkillSelector.ts +0 -322
  224. package/packages/core/src/agent/selectors/index.ts +0 -6
  225. package/packages/core/src/auth/auth.ts +0 -121
  226. package/packages/core/src/auth/index.ts +0 -1
  227. package/packages/core/src/canvas/CanvasManager.ts +0 -390
  228. package/packages/core/src/canvas/canvas-tools.ts +0 -448
  229. package/packages/core/src/harness/collections.ts +0 -98
  230. package/packages/core/src/harness/goal-verifier.ts +0 -141
  231. package/packages/core/src/harness/harness.test.ts +0 -236
  232. package/packages/core/src/harness/reconcile.ts +0 -149
  233. package/packages/core/src/mcp/MCPToolAdapter.ts +0 -176
  234. package/packages/core/src/multimodal/VisionService.ts +0 -293
  235. package/packages/core/src/scheduler/dag/AgentExecutor.ts +0 -53
  236. package/packages/core/src/scheduler/dag/DAGScheduler.ts +0 -250
  237. package/packages/core/src/scheduler/dag/EventBridge.ts +0 -122
  238. package/packages/core/src/scheduler/dag/TaskGraph.ts +0 -192
  239. package/packages/core/src/scheduler/dag/TaskNode.ts +0 -97
  240. package/packages/core/src/scheduler/dag/TaskResult.ts +0 -22
  241. package/packages/core/src/scheduler/dag/errors.ts +0 -37
  242. package/packages/core/src/scheduler/dag/index.ts +0 -26
  243. package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +0 -97
  244. package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +0 -21
  245. package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +0 -46
  246. package/packages/core/src/storage/HiveDBStorage.ts +0 -64
  247. package/packages/core/src/storage/SQLiteStorage.ts +0 -414
  248. package/packages/core/src/storage/hiveSeed.ts +0 -308
  249. package/packages/core/src/storage/hiveStorage.test.ts +0 -38
  250. package/packages/core/src/storage/schema.ts +0 -689
  251. package/packages/core/src/storage/storage.test.ts +0 -37
  252. package/packages/core/src/swarm/AgentBus.ts +0 -460
  253. package/packages/core/src/swarm/EventBus.ts +0 -169
  254. package/packages/core/src/swarm/WorkerPool.ts +0 -236
  255. package/packages/core/src/tools/bridge-events.ts +0 -26
  256. package/packages/core/src/tools/canvas/index.ts +0 -375
  257. package/packages/core/src/tools/codebridge/index.ts +0 -342
  258. package/packages/core/src/tools/meeting/index.ts +0 -353
  259. package/packages/core/src/tools/projects/index.ts +0 -37
  260. package/packages/core/src/tools/projects/project-create.ts +0 -94
  261. package/packages/core/src/tools/projects/project-done.ts +0 -66
  262. package/packages/core/src/tools/projects/project-fail.ts +0 -66
  263. package/packages/core/src/tools/projects/project-list.ts +0 -96
  264. package/packages/core/src/tools/projects/project-update.ts +0 -72
  265. package/packages/core/src/tools/projects/task-create.ts +0 -68
  266. package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
  267. package/packages/core/src/tools/projects/task-update.ts +0 -93
  268. package/packages/core/src/tools/voice/index.ts +0 -104
  269. package/packages/core/src/tools/web/api-request.test.ts +0 -170
  270. package/packages/core/src/tools/web/api-request.ts +0 -239
  271. package/test/setup-db.ts +0 -216
  272. /package/packages/core/src/agent/{NativeTools.ts → native-tools.ts} +0 -0
@@ -0,0 +1,680 @@
1
+ /**
2
+ * Document shapes for every HiveDB collection. Kept in one place — with no
3
+ * imports of its own — so any storage/route/agent module can import a type
4
+ * without risking a circular import.
5
+ *
6
+ * Nullable FK-like fields that are also equality-indexed (`createIndex`)
7
+ * store the {@link toIndexable}/{@link fromIndexable} sentinel (`__none__`)
8
+ * instead of `null`, since `findBy`/`createIndex` don't accept `null`.
9
+ */
10
+
11
+ // ─── Stage 1: identity/config core ───────────────────────────────────────────
12
+
13
+ export interface UserDoc {
14
+ id: string
15
+ name: string | null
16
+ language: string | null
17
+ timezone: string | null
18
+ occupation: string | null
19
+ notes: string | null
20
+ master_key_hash: string | null
21
+ email: string | null
22
+ password_hash: string | null
23
+ preferred_cron_channel: string
24
+ created_at: number
25
+ }
26
+
27
+ export interface ProviderDoc {
28
+ id: string
29
+ name: string
30
+ base_url: string | null
31
+ category: "llm" | "stt" | "tts"
32
+ num_ctx: number | null
33
+ num_gpu: number
34
+ enabled: boolean
35
+ active: boolean
36
+ created_at: number
37
+ }
38
+
39
+ export interface ModelDoc {
40
+ id: string
41
+ provider_id: string
42
+ name: string
43
+ model_type: "llm" | "stt" | "tts" | "vision" | "embedding"
44
+ context_window: number
45
+ capabilities: string | null
46
+ enabled: boolean
47
+ active: boolean
48
+ /**
49
+ * "catalog" for rows that come from SEED_DATA, "discovered" for rows
50
+ * inserted at runtime by querying a provider (Ollama tags, /v1/models).
51
+ * The boot reseed only purges catalog rows — a discovered model has no
52
+ * canonical source to be re-created from, so wiping it would orphan every
53
+ * agent pointing at it. Legacy rows (undefined) are treated as discovered.
54
+ */
55
+ source?: "catalog" | "discovered"
56
+ /**
57
+ * Precio en USD por millón de tokens. Única fuente de verdad para el costo
58
+ * del dashboard: `calculateCost` (storage/usage.ts) lee de acá, no de una
59
+ * tabla aparte. `null` = precio desconocido (modelo agregado a mano o
60
+ * descubierto en runtime), que se reporta como $0 con un warning.
61
+ */
62
+ input_per_1m?: number | null
63
+ output_per_1m?: number | null
64
+ }
65
+
66
+ export interface AgentDoc {
67
+ id: string
68
+ user_id: string
69
+ name: string
70
+ description: string | null
71
+ system_prompt: string | null
72
+ tone: string | null
73
+ role: "coordinator" | "worker"
74
+ status: string
75
+ enabled: boolean
76
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
77
+ provider_id: string
78
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
79
+ model_id: string
80
+ tools_json: string | null
81
+ skills_json: string | null
82
+ /** MCP server ids currently leased for this execution. */
83
+ active_mcp_json?: string | null
84
+ /** `toIndexable`-encoded — `NO_PARENT` for the coordinator. */
85
+ parent_id: string
86
+ max_iterations: number
87
+ workspace: string | null
88
+ /** Denormalized from `traces` — last time this agent produced a trace. */
89
+ lastTraceAt: number | null
90
+ created_at: number
91
+ updated_at: number
92
+
93
+ // ─── Catalog fields (only populated for source:"catalog" seeded agents) ────
94
+ /** "catalog" = seeded persona from agent-catalog.ts (insert-only, survives reseed). Absent/"user" for everything else (coordinator, agent_create workers). */
95
+ source?: "user" | "catalog"
96
+ /** BM25 routing metadata (capability-search.ts) — `description` itself is already routing-friendly (one line, suitable for small local models) and doubles as the catalog line shown to the coordinator. */
97
+ routing_examples_json?: string | null
98
+ routing_exclusions_json?: string | null
99
+ /** Glob patterns. When present, task_delegate re-expands against the live tool registry at delegation time instead of trusting a possibly-stale tools_json. */
100
+ tool_allowlist_json?: string | null
101
+ /** Persistent MCP server assignments. User specialists normally contain exactly one server id. */
102
+ mcp_server_ids_json?: string | null
103
+ workspace_scope_json?: string | null
104
+ model_override_json?: string | null
105
+ default_acceptance_json?: string | null
106
+ /** ACE learning counters — updated by deterministic acceptance checks and the coordinator's own accept/revise judgment (acceptance-checks.ts), not by loop completion. */
107
+ helpful_count?: number
108
+ harmful_count?: number
109
+ seed_version?: number
110
+ }
111
+
112
+ // ─── Stage 2: catalog ─────────────────────────────────────────────────────────
113
+
114
+ export interface ChannelDoc {
115
+ id: string
116
+ /** `toIndexable`-encoded — `NO_PARENT` for global (unowned) channels. */
117
+ user_id: string
118
+ type: string
119
+ enabled: boolean
120
+ active: boolean
121
+ status: string
122
+ last_active: number | null
123
+ voice_enabled: boolean
124
+ tts_enabled: boolean
125
+ stt_provider: string | null
126
+ tts_provider: string | null
127
+ tts_voice_id: string | null
128
+ step_delivery_mode: string
129
+ vision_enabled: boolean
130
+ ocr_provider: string | null
131
+ vision_provider: string | null
132
+ vision_model_id: string | null
133
+ }
134
+
135
+ export interface McpServerDoc {
136
+ id: string
137
+ name: string
138
+ transport: string
139
+ command: string | null
140
+ args: string | null
141
+ url: string | null
142
+ enabled: boolean
143
+ active: boolean
144
+ builtin: boolean
145
+ status: string
146
+ tools_count: number
147
+ /** Present only for user-created (non-builtin) servers, e.g. `"<userId>:<name>"` ids. */
148
+ user_id?: string
149
+ }
150
+
151
+ export interface SkillDoc {
152
+ id: string
153
+ name: string
154
+ description: string | null
155
+ version: string
156
+ author: string
157
+ icon: string
158
+ category: string
159
+ permissions: string
160
+ dependencies: string
161
+ tools: string
162
+ triggers: string
163
+ preferred_agents: string
164
+ body: string
165
+ version_num: number
166
+ active: boolean
167
+ created_at: number
168
+ updated_at: number
169
+ }
170
+
171
+ export interface ToolDoc {
172
+ id: string
173
+ name: string
174
+ description: string | null
175
+ category: string | null
176
+ enabled: boolean
177
+ active: boolean
178
+ created_at: number
179
+ updated_at: number
180
+ }
181
+
182
+ // Sub-types for AgentDoc's catalog fields (workspace_scope_json, model_override_json,
183
+ // default_acceptance_json) — kept as named types for readability even though they're
184
+ // stored as JSON strings on the shared agents table, not a separate collection.
185
+ export type AgentWorkspaceScope =
186
+ | { kind: "none" }
187
+ | { kind: "workspace"; read_globs: string[]; write_globs: string[] }
188
+ | { kind: "resource"; resource_types: string[] }
189
+
190
+ export interface AgentModelOverride {
191
+ required_capabilities: string[]
192
+ fallback: "general"
193
+ prefer_different_family?: boolean
194
+ }
195
+
196
+ export interface AgentAcceptanceCriterion {
197
+ id: string
198
+ description: string
199
+ check_tool?: string | null
200
+ }
201
+
202
+ export interface EthicsDoc {
203
+ id: string
204
+ name: string
205
+ description: string | null
206
+ content: string
207
+ is_default: boolean
208
+ enabled: boolean
209
+ active: boolean
210
+ }
211
+
212
+ export interface McpToolDoc {
213
+ id: string
214
+ server_id: string
215
+ server_name: string
216
+ tool_name: string
217
+ description: string | null
218
+ category: string | null
219
+ active: boolean
220
+ }
221
+
222
+ // ─── Stage 3: auth/identity ───────────────────────────────────────────────────
223
+
224
+ export interface UserIdentityDoc {
225
+ user_id: string
226
+ channel: string
227
+ channel_user_id: string
228
+ /** Account that owns this session — replies must go back out through it. Absent on legacy rows. */
229
+ account_id?: string
230
+ linked_at: number
231
+ }
232
+
233
+ export interface NotificationDoc {
234
+ id: string
235
+ user_id: string
236
+ channel: string
237
+ message: string
238
+ created_at: number
239
+ delivered_at: number | null
240
+ read_at: number | null
241
+ }
242
+
243
+ export interface UserChannelDoc {
244
+ id: string
245
+ user_id: string
246
+ channel: string
247
+ account_id: string
248
+ config: string
249
+ active: boolean
250
+ }
251
+
252
+ export interface OnboardingProgressDoc {
253
+ user_id: string
254
+ step: string
255
+ data: string
256
+ }
257
+
258
+ export interface RefreshTokenDoc {
259
+ id: string
260
+ user_id: string
261
+ token_hash: string
262
+ expires_at: number
263
+ revoked: boolean
264
+ }
265
+
266
+ // ─── Stage 4: chat/ACE ────────────────────────────────────────────────────────
267
+
268
+ /** Where an incoming turn's content came from. */
269
+ export type TurnSource =
270
+ | "message" | "audio" | "a2ui" | "canvas" | "api"
271
+ | "task_complete" | "delegation_summary"
272
+
273
+ /** What gets persisted — adds the synthetic marker for rows written before `source` existed. */
274
+ export type MessageSource = TurnSource | "legacy_internal"
275
+
276
+ export interface ConversationDoc {
277
+ id: string
278
+ thread_id: string
279
+ channel: string
280
+ /** @deprecated "system" only appears in rows written before `source` existed — never written going forward. */
281
+ role: "user" | "assistant" | "tool" | "system"
282
+ content: string
283
+ content_multimodal: string | null
284
+ tool_calls_json: string | null
285
+ tool_call_id: string | null
286
+ reasoning_content: string | null
287
+ /** null on rows written before this field existed (legacy). */
288
+ source: MessageSource | null
289
+ token_count: number
290
+ created_at: number
291
+ updated_at: number
292
+ }
293
+
294
+ export interface SummaryDoc {
295
+ thread_id: string
296
+ summary: string
297
+ messages_covered: number
298
+ last_message_id: string | null
299
+ }
300
+
301
+ export interface TraceDoc {
302
+ id: string
303
+ thread_id: string
304
+ agent_id: string
305
+ agent_name: string
306
+ tool_used: string | null
307
+ input_summary: string
308
+ output_summary: string
309
+ success: boolean
310
+ error_message: string | null
311
+ duration_ms: number | null
312
+ tokens_used: number | null
313
+ created_at: number
314
+ /** G9 causal stream id for this run (agent-loop.ts's causalStreamId), when the causal log is enabled. */
315
+ causal_stream_id?: string | null
316
+ /** Catalog agent id when this trace belongs to a source:"catalog" agent. */
317
+ catalog_agent_id?: string
318
+ }
319
+
320
+ export interface ReflectionDoc {
321
+ id: string
322
+ trace_ids: string
323
+ insight_type: "success_pattern" | "failure_pattern" | "optimization" | "ethics_violation" | "root_cause" | "learning_proposal"
324
+ description: string
325
+ affected_tools: string | null
326
+ affected_agents: string | null
327
+ confidence: number
328
+ created_at: number
329
+ }
330
+
331
+ export interface PlaybookDoc {
332
+ id: string
333
+ rule: string
334
+ category: string
335
+ applicable_to: string | null
336
+ helpful_count: number
337
+ harmful_count: number
338
+ active: boolean
339
+ /** `toIndexable`-encoded — `NO_PARENT` when not derived from a reflection. */
340
+ source_reflection_id: string
341
+ created_at: number
342
+ updated_at: number
343
+ }
344
+
345
+ export interface CursorDoc {
346
+ value: string
347
+ }
348
+
349
+ // ─── Stage 5: scheduler ───────────────────────────────────────────────────────
350
+
351
+ export interface AgentRunDoc {
352
+ id: string
353
+ thread_id: string
354
+ agent_id: string
355
+ user_id: string
356
+ channel: string | null
357
+ kind: "chat" | "worker" | "goal" | "cron" | "project"
358
+ status: "running" | "completed" | "failed" | "interrupted" | "aborted"
359
+
360
+ iterations_used: number
361
+ max_iterations: number
362
+ turns_used: number
363
+ max_turns: number | null
364
+ tokens_used: number
365
+ max_tokens: number | null
366
+
367
+ goal: string | null
368
+ goal_check_tool: string | null
369
+ goal_attempts: number
370
+
371
+ state_json: string
372
+ state_bytes: number
373
+ pending_tool_calls_json: string | null
374
+ checkpointed_at: number
375
+
376
+ boot_id: string
377
+ lease_expires_at: number
378
+ resume_policy: "resume" | "mark_interrupted" | "discard"
379
+
380
+ /** Whole-job acceptance criteria (harness-engineering "proof" concept): JSON array of {id, description, checkTool?}. */
381
+ acceptance_json: string | null
382
+ /** Fixed-worker epoch recorded at run creation: {provider, model, app_version, tool_catalog_hash}. */
383
+ epoch_json: string | null
384
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT` for ordinary agents. */
385
+ catalog_agent_id?: string
386
+
387
+ error: string | null
388
+ created_at: number
389
+ updated_at: number
390
+ finished_at: number | null
391
+ }
392
+
393
+ export interface JobDoc {
394
+ id: string
395
+ lane: string
396
+ type: "chat_turn" | "worker_task" | "goal_run"
397
+ status: "pending" | "running" | "completed" | "failed" | "cancelled" | "interrupted"
398
+ priority: number
399
+ payload_json: string
400
+ run_id: string
401
+ attempts: number
402
+ max_attempts: number
403
+ not_before: number
404
+ boot_id: string | null
405
+ lease_expires_at: number | null
406
+ result_json: string | null
407
+ error: string | null
408
+ created_at: number
409
+ started_at: number | null
410
+ finished_at: number | null
411
+ /** Logical-failure retries (executor returned {ok:false, retryable:true}). Separate from `attempts` (crash/lease-expiry only). */
412
+ retry_count: number
413
+ /** Error from the most recent logical-failure retry; `error` stays null until the job is terminal. */
414
+ last_error: string | null
415
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. Client-supplied dedup key for job creation. */
416
+ idempotency_key: string
417
+ }
418
+
419
+ export interface CronJobDoc {
420
+ id: string
421
+ name: string
422
+ task: string
423
+ task_type: "recurring" | "one_shot"
424
+ cron_expression: string | null
425
+ fire_at: string | null
426
+ timezone: string
427
+ start_at: string | null
428
+ stop_at: string | null
429
+ dom_and_dow: number
430
+ max_runs: number | null
431
+ protect: number
432
+ interval_sec: number | null
433
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
434
+ agent_id: string
435
+ channel: string
436
+ payload: string
437
+ tool_name: string | null
438
+ status: "active" | "paused" | "completed" | "failed" | "cancelled"
439
+ run_count: number
440
+ error_count: number
441
+ last_error: string | null
442
+ misfire_policy?: "skip" | "fire_once"
443
+ misfire_grace_min?: number
444
+ created_at: string
445
+ updated_at: string
446
+ last_run_at: string | null
447
+ next_run_at: string | null
448
+ completed_at: string | null
449
+ }
450
+
451
+ /**
452
+ * Compressed evidence artifact for a completed goal/project run — the
453
+ * "proof packet" concept from harness-engineering's proof/verification
454
+ * practice: what was intended, what was checked, what evidence backs the
455
+ * verdict, and known limits. Written once per run by the goal_run /
456
+ * project_task executors after verification.
457
+ */
458
+ export interface ProofPacketDoc {
459
+ id: string
460
+ run_id: string
461
+ agent_id: string
462
+ intended_outcome: string
463
+ /** Per-acceptance-criterion verdicts: [{id, description, met, evidence}]. */
464
+ acceptance_results_json: string
465
+ /** Names of checks executed (tool ids, LLM verifier, etc). */
466
+ checks_run_json: string
467
+ /** Free-form evidence snippets backing the verdict (tool outputs, verifier reasons). */
468
+ evidence_json: string
469
+ known_limits: string | null
470
+ /** Fixed-worker epoch this run executed under — copied from AgentRunDoc.epoch_json. */
471
+ epoch_json: string | null
472
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT`. */
473
+ catalog_agent_id: string
474
+ met: boolean
475
+ created_at: number
476
+ }
477
+
478
+ /** Durable metadata for binary evidence managed under HIVE_HOME/artifacts. */
479
+ export interface ArtifactDoc {
480
+ id: string
481
+ run_id: string | null
482
+ task_id: string | null
483
+ user_id: string
484
+ kind: string
485
+ path: string
486
+ mime_type: string
487
+ size: number
488
+ sha256: string
489
+ width: number | null
490
+ height: number | null
491
+ status: "active" | "expired"
492
+ created_at: number
493
+ expires_at: number
494
+ expired_at: number | null
495
+ }
496
+
497
+ export interface AgentProposalDoc {
498
+ id: string
499
+ type: "move_tool" | "create_agent" | "disable_agent"
500
+ agent_id: string
501
+ proposed_change_json: string
502
+ evidence_trace_ids_json: string
503
+ confidence: number
504
+ status: "proposed" | "approved" | "rejected" | "applied"
505
+ created_at: number
506
+ updated_at: number
507
+ }
508
+
509
+ export interface TaskRunDoc {
510
+ id: string
511
+ task_id: string
512
+ status: "running" | "success" | "failed" | "timeout"
513
+ started_at: string
514
+ finished_at: string | null
515
+ duration_ms: number | null
516
+ error_message: string | null
517
+ payload_snapshot: string | null
518
+ agent_response: string | null
519
+ }
520
+
521
+ // ─── Stage 6: orchestration ───────────────────────────────────────────────────
522
+
523
+ /** id = title — the old `notes`/`memory_*` table never existed, so this is a from-scratch fix. */
524
+ export interface MemoryDoc {
525
+ id: string
526
+ title: string
527
+ content: string
528
+ created_at: number
529
+ updated_at: number
530
+ }
531
+
532
+ export interface TaskDoc {
533
+ id: string
534
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
535
+ agent_id: string
536
+ name: string
537
+ description: string | null
538
+ status: "pending" | "in_progress" | "completed" | "failed" | "blocked"
539
+ progress: number
540
+ result: string | null
541
+ error: string | null
542
+ metadata: string | null
543
+ job_id: string | null
544
+ run_id: string | null
545
+ thread_id: string | null
546
+ delegation_group_id?: string | null
547
+ /** `toIndexable`-encoded catalog agent id, or `NO_PARENT`. */
548
+ catalog_agent_id?: string
549
+ started_at: number | null
550
+ attempts: number
551
+ created_at: number
552
+ updated_at: number
553
+ completed_at: number | null
554
+ }
555
+
556
+ export interface DelegationGroupOutcome {
557
+ task_id: string
558
+ job_id: string
559
+ worker_id: string
560
+ task_name: string
561
+ ok: boolean
562
+ result: unknown | null
563
+ error: string | null
564
+ finished_at: number
565
+ }
566
+
567
+ export interface DelegationGroupDoc {
568
+ id: string
569
+ turn_id: string
570
+ thread_id: string
571
+ channel: string
572
+ user_id: string
573
+ session_id: string
574
+ coordinator_agent_id: string
575
+ status: "open" | "sealed" | "ready" | "notified"
576
+ task_ids_json: string
577
+ outcomes_json: string
578
+ summary_job_id: string | null
579
+ created_at: number
580
+ sealed_at: number | null
581
+ ready_at: number | null
582
+ notified_at: number | null
583
+ }
584
+
585
+ export interface AgentBusMessageDoc {
586
+ id: string
587
+ event_type: string
588
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
589
+ from_worker_id: string
590
+ /** `toIndexable`-encoded — `BROADCAST` (`"*"`) for broadcast messages. */
591
+ to_worker_id: string
592
+ topic: string | null
593
+ content: string
594
+ metadata: string | null
595
+ read: boolean
596
+ created_at: number
597
+ }
598
+
599
+ export interface NarrationEventDoc {
600
+ id: string
601
+ turn_id: string
602
+ thread_id: string
603
+ channel: string
604
+ user_id: string
605
+ session_id: string
606
+ agent_id: string
607
+ agent_name: string
608
+ kind: "delegated" | "worker_started" | "tool_call" | "tool_result" | "verified" | "failed" | "group_ready"
609
+ status: "queued" | "running" | "done" | "error"
610
+ label: string
611
+ detail: string | null
612
+ dedupe_key: string
613
+ created_at: number
614
+ }
615
+
616
+ // ─── Stage 7: meeting ─────────────────────────────────────────────────────────
617
+
618
+ export interface MeetingSessionDoc {
619
+ id: string
620
+ /** `toIndexable`-encoded — `NO_PARENT` when unset. */
621
+ user_id: string
622
+ title: string
623
+ status: "active" | "stopped" | "report_ready"
624
+ stt_model: string
625
+ started_at: number
626
+ stopped_at: number | null
627
+ report_path: string | null
628
+ metadata: string | null
629
+ }
630
+
631
+ export interface MeetingSegmentDoc {
632
+ id: string
633
+ session_id: string
634
+ seq: number
635
+ speaker: string | null
636
+ text: string
637
+ duration_ms: number | null
638
+ created_at: number
639
+ }
640
+
641
+ // ─── Stage 8: usage/stats ─────────────────────────────────────────────────────
642
+
643
+ /** id = global counter (`nextId("usageRecords")`) — sortable, so "recent records" is a cheap reverse scan. */
644
+ export interface UsageRecordDoc {
645
+ id: string
646
+ provider: string
647
+ model: string
648
+ input_tokens: number
649
+ output_tokens: number
650
+ cost_usd: number
651
+ latency_ms: number | null
652
+ toon_saved_tokens: number
653
+ toon_saved_cost: number
654
+ toon_json_bytes: number
655
+ toon_toon_bytes: number
656
+ toon_saved_bytes: number
657
+ toon_saved_percent: number
658
+ toon_json_tokens: number
659
+ toon_toon_tokens: number
660
+ toon_saved_tokens_pct: number
661
+ created_at: number
662
+ }
663
+
664
+ export interface UsageRollupDoc {
665
+ inputTokens: number
666
+ outputTokens: number
667
+ costUsd: number
668
+ toonSavedTokens: number
669
+ toonSavedCost: number
670
+ toonSavedBytes: number
671
+ toonJsonTokens: number
672
+ toonToonTokens: number
673
+ toonJsonBytes: number
674
+ byProvider: Record<string, { inputTokens: number; outputTokens: number; costUsd: number }>
675
+ byModel: Record<string, { inputTokens: number; outputTokens: number; costUsd: number }>
676
+ }
677
+
678
+ export interface ActivityRollupDoc {
679
+ messageCount: number
680
+ }