@johpaz/hive-sdk 0.0.14 → 0.0.16

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 (257) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +280 -0
  3. package/docs/API-AGENTS.md +316 -0
  4. package/docs/API-CONTEXT-COMPILER.md +252 -0
  5. package/docs/API-DAG-SCHEDULER.md +273 -0
  6. package/docs/API-TOOLS-SKILLS-CHANNELS.md +350 -0
  7. package/docs/API-WORKERS-EVENTS.md +299 -0
  8. package/docs/INDEX.md +190 -0
  9. package/docs/README.md +161 -0
  10. package/docs/TEMPLATE-HIVE-APP.md +360 -0
  11. package/package.json +60 -104
  12. package/packages/cli/bin/hive +2 -0
  13. package/packages/cli/package.json +17 -0
  14. package/packages/cli/src/commands/add-skill.ts +42 -0
  15. package/packages/cli/src/commands/add-tool.ts +45 -0
  16. package/packages/cli/src/commands/add-worker.ts +49 -0
  17. package/packages/cli/src/commands/create-app-utils.ts +32 -0
  18. package/packages/cli/src/commands/create-app.test.ts +151 -0
  19. package/packages/cli/src/commands/create-app.ts +35 -0
  20. package/packages/cli/src/commands/init.ts +56 -0
  21. package/packages/cli/src/commands/run.ts +45 -0
  22. package/packages/cli/src/commands/test.ts +42 -0
  23. package/packages/cli/src/commands/trace.ts +55 -0
  24. package/packages/cli/src/index.ts +59 -0
  25. package/packages/cli/templates/hive-app/.env.example +17 -0
  26. package/packages/cli/templates/hive-app/docker-compose.yml +20 -0
  27. package/packages/cli/templates/hive-app/hive.config.ts +19 -0
  28. package/packages/cli/templates/hive-app/package.json +16 -0
  29. package/packages/cli/templates/hive-app/src/agents/coordinator.ts +9 -0
  30. package/packages/cli/templates/hive-app/src/main.ts +56 -0
  31. package/packages/core/package.json +58 -0
  32. package/packages/core/src/ace/Curator.ts +158 -0
  33. package/packages/core/src/ace/Reflector.ts +200 -0
  34. package/packages/core/src/ace/Tracer.ts +100 -0
  35. package/packages/core/src/ace/index.ts +4 -0
  36. package/packages/core/src/agent/AgentRunner.ts +699 -0
  37. package/packages/core/src/agent/Compaction.ts +221 -0
  38. package/packages/core/src/agent/ContextCompiler.ts +567 -0
  39. package/packages/core/src/agent/ContextGuard.ts +91 -0
  40. package/packages/core/src/agent/ConversationStore.ts +244 -0
  41. package/packages/core/src/agent/Hooks.ts +166 -0
  42. package/packages/core/src/agent/NativeTools.ts +31 -0
  43. package/packages/core/src/agent/PromptBuilder.ts +169 -0
  44. package/packages/core/src/agent/Service.ts +267 -0
  45. package/packages/core/src/agent/StuckLoop.ts +133 -0
  46. package/packages/core/src/agent/index.ts +12 -0
  47. package/packages/core/src/agent/providers/LLMClient.ts +149 -0
  48. package/packages/core/src/agent/providers/anthropic.ts +212 -0
  49. package/packages/core/src/agent/providers/gemini.ts +215 -0
  50. package/packages/core/src/agent/providers/index.ts +199 -0
  51. package/packages/core/src/agent/providers/interface.ts +195 -0
  52. package/packages/core/src/agent/providers/ollama.ts +175 -0
  53. package/packages/core/src/agent/providers/openai-compat.ts +231 -0
  54. package/packages/core/src/agent/selectors/PlaybookSelector.ts +147 -0
  55. package/packages/core/src/agent/selectors/SkillSelector.ts +478 -0
  56. package/packages/core/src/agent/selectors/ToolSelector.ts +577 -0
  57. package/packages/core/src/agent/selectors/index.ts +6 -0
  58. package/packages/core/src/api/createAgent.test.ts +48 -0
  59. package/packages/core/src/api/createAgent.ts +122 -0
  60. package/packages/core/src/api/index.ts +2 -0
  61. package/packages/core/src/auth/auth.ts +108 -0
  62. package/packages/core/src/auth/index.ts +1 -0
  63. package/packages/core/src/canvas/CanvasManager.ts +390 -0
  64. package/packages/core/src/canvas/a2ui-tools.ts +255 -0
  65. package/packages/core/src/canvas/canvas-tools.ts +448 -0
  66. package/packages/core/src/canvas/canvas.test.ts +32 -0
  67. package/packages/core/src/canvas/emitter.ts +149 -0
  68. package/packages/core/src/canvas/index.ts +3 -0
  69. package/packages/core/src/channels/base.ts +154 -0
  70. package/packages/core/src/channels/channels.test.ts +18 -0
  71. package/packages/core/src/channels/discord.ts +273 -0
  72. package/packages/core/src/channels/index.ts +7 -0
  73. package/packages/core/src/channels/manager.ts +450 -0
  74. package/packages/core/src/channels/slack.ts +323 -0
  75. package/packages/core/src/channels/telegram.ts +612 -0
  76. package/packages/core/src/channels/webchat.ts +139 -0
  77. package/packages/core/src/channels/whatsapp.ts +548 -0
  78. package/packages/core/src/config/index.ts +2 -0
  79. package/packages/core/src/config/loader.ts +554 -0
  80. package/packages/core/src/ethics/EthicsGuard.test.ts +54 -0
  81. package/packages/core/src/ethics/EthicsGuard.ts +66 -0
  82. package/packages/core/src/ethics/index.ts +2 -0
  83. package/packages/core/src/events/agent-bus.ts +460 -0
  84. package/packages/core/src/events/event-bus.ts +169 -0
  85. package/packages/core/src/gateway/channel-notify.ts +37 -0
  86. package/packages/core/src/gateway/gateway.test.ts +38 -0
  87. package/packages/core/src/gateway/index.ts +2 -0
  88. package/packages/core/src/gateway/server.ts +139 -0
  89. package/packages/core/src/heartbeat/index.ts +157 -0
  90. package/packages/core/src/index.ts +81 -0
  91. package/packages/core/src/mcp/MCPClient.ts +439 -0
  92. package/packages/core/src/mcp/MCPToolAdapter.ts +176 -0
  93. package/packages/core/src/mcp/config.ts +13 -0
  94. package/packages/core/src/mcp/hot-reload.ts +147 -0
  95. package/packages/core/src/mcp/index.ts +11 -0
  96. package/packages/core/src/mcp/logger.ts +42 -0
  97. package/packages/core/src/mcp/singleton.ts +21 -0
  98. package/packages/core/src/mcp/transports/index.ts +67 -0
  99. package/packages/core/src/mcp/transports/sse.ts +241 -0
  100. package/packages/core/src/mcp/transports/websocket.ts +159 -0
  101. package/packages/core/src/memory/Scratchpad.test.ts +47 -0
  102. package/packages/core/src/memory/Scratchpad.ts +37 -0
  103. package/packages/core/src/memory/Storage.ts +6 -0
  104. package/packages/core/src/memory/index.ts +2 -0
  105. package/packages/core/src/multimodal/VisionService.ts +293 -0
  106. package/packages/core/src/multimodal/index.ts +2 -0
  107. package/packages/core/src/multimodal/types.ts +28 -0
  108. package/packages/core/src/multimodal/vision-service.ts +283 -0
  109. package/packages/core/src/plugins/api.ts +128 -0
  110. package/packages/core/src/plugins/index.ts +2 -0
  111. package/packages/core/src/plugins/loader.ts +365 -0
  112. package/packages/core/src/resilience/circuit-breaker.ts +225 -0
  113. package/packages/core/src/scheduler/CronScheduler.ts +699 -0
  114. package/packages/core/src/scheduler/dag/AgentExecutor.ts +53 -0
  115. package/packages/core/src/scheduler/dag/DAGScheduler.ts +250 -0
  116. package/packages/core/src/scheduler/dag/EventBridge.ts +122 -0
  117. package/packages/core/src/scheduler/dag/TaskGraph.ts +192 -0
  118. package/packages/core/src/scheduler/dag/TaskNode.ts +97 -0
  119. package/packages/core/src/scheduler/dag/TaskResult.ts +22 -0
  120. package/packages/core/src/scheduler/dag/errors.ts +37 -0
  121. package/packages/core/src/scheduler/dag/index.ts +26 -0
  122. package/packages/core/src/scheduler/dag/presets/ResearchPreset.ts +97 -0
  123. package/packages/core/src/scheduler/dag/strategies/ParallelStrategy.ts +21 -0
  124. package/packages/core/src/scheduler/dag/strategies/PriorityStrategy.ts +46 -0
  125. package/packages/core/src/scheduler/index.ts +22 -0
  126. package/packages/core/src/scheduler/integration.ts +237 -0
  127. package/packages/core/src/scheduler/scheduler.test.ts +19 -0
  128. package/packages/core/src/scheduler/types.ts +164 -0
  129. package/packages/core/src/security/Pairing.ts +250 -0
  130. package/packages/core/src/security/RateLimit.ts +270 -0
  131. package/packages/core/src/security/google-chat.ts +269 -0
  132. package/packages/core/src/security/index.ts +192 -0
  133. package/packages/core/src/security/rate-limit.ts +270 -0
  134. package/packages/core/src/security/signal.ts +321 -0
  135. package/packages/core/src/skills/SkillLoader.ts +388 -0
  136. package/packages/core/src/skills/bundled-data.generated.ts +3332 -0
  137. package/packages/core/src/skills/defineSkill.ts +18 -0
  138. package/packages/core/src/skills/index.ts +4 -0
  139. package/packages/core/src/state/index.ts +2 -0
  140. package/packages/core/src/state/store.ts +312 -0
  141. package/packages/core/src/storage/SQLiteStorage.ts +407 -0
  142. package/packages/core/src/storage/crypto.ts +233 -0
  143. package/packages/core/src/storage/index.ts +10 -0
  144. package/packages/core/src/storage/onboarding.ts +1603 -0
  145. package/packages/core/src/storage/schema.ts +689 -0
  146. package/packages/core/src/storage/seed.ts +740 -0
  147. package/packages/core/src/storage/storage.test.ts +37 -0
  148. package/packages/core/src/storage/usage.ts +374 -0
  149. package/packages/core/src/swarm/AgentBus.ts +460 -0
  150. package/packages/core/src/swarm/AgentExecutor.ts +53 -0
  151. package/packages/core/src/swarm/Coordinator.ts +251 -0
  152. package/packages/core/src/swarm/EventBridge.ts +122 -0
  153. package/packages/core/src/swarm/EventBus.ts +169 -0
  154. package/packages/core/src/swarm/TaskGraph.ts +192 -0
  155. package/packages/core/src/swarm/TaskNode.ts +97 -0
  156. package/packages/core/src/swarm/TaskResult.ts +22 -0
  157. package/packages/core/src/swarm/WorkerPool.ts +236 -0
  158. package/packages/core/src/swarm/errors.ts +37 -0
  159. package/packages/core/src/swarm/index.ts +30 -0
  160. package/packages/core/src/swarm/presets/HiveLearnPreset.ts +99 -0
  161. package/packages/core/src/swarm/presets/ResearchPreset.ts +97 -0
  162. package/packages/core/src/swarm/presets/index.ts +4 -0
  163. package/packages/core/src/swarm/strategies/ParallelStrategy.ts +21 -0
  164. package/packages/core/src/swarm/strategies/PriorityStrategy.ts +46 -0
  165. package/packages/core/src/swarm/strategies/index.ts +3 -0
  166. package/packages/core/src/swarm/swarm.test.ts +24 -0
  167. package/packages/core/src/swarm/types.ts +164 -0
  168. package/packages/core/src/tool-runtime/index.ts +522 -0
  169. package/packages/core/src/tool-runtime/tool-runtime.test.ts +91 -0
  170. package/packages/core/src/tool-runtime/tool-worker.ts +125 -0
  171. package/packages/core/src/tools/ToolExecutor.ts +58 -0
  172. package/packages/core/src/tools/ToolRegistry.test.ts +98 -0
  173. package/packages/core/src/tools/ToolRegistry.ts +61 -0
  174. package/packages/core/src/tools/agents/get-available-models.ts +118 -0
  175. package/packages/core/src/tools/agents/index.ts +715 -0
  176. package/packages/core/src/tools/bridge-events.ts +26 -0
  177. package/packages/core/src/tools/canvas/index.ts +375 -0
  178. package/packages/core/src/tools/cli/index.ts +142 -0
  179. package/packages/core/src/tools/codebridge/index.ts +342 -0
  180. package/packages/core/src/tools/core/index.ts +476 -0
  181. package/packages/core/src/tools/cron/index.ts +626 -0
  182. package/packages/core/src/tools/filesystem/fs-delete.ts +78 -0
  183. package/packages/core/src/tools/filesystem/fs-edit.ts +106 -0
  184. package/packages/core/src/tools/filesystem/fs-exists.ts +63 -0
  185. package/packages/core/src/tools/filesystem/fs-glob.ts +108 -0
  186. package/packages/core/src/tools/filesystem/fs-list.ts +129 -0
  187. package/packages/core/src/tools/filesystem/fs-read.ts +72 -0
  188. package/packages/core/src/tools/filesystem/fs-write.ts +67 -0
  189. package/packages/core/src/tools/filesystem/index.ts +34 -0
  190. package/packages/core/src/tools/filesystem/workspace-guard.ts +62 -0
  191. package/packages/core/src/tools/index.ts +231 -0
  192. package/packages/core/src/tools/meeting/index.ts +363 -0
  193. package/packages/core/src/tools/office/index.ts +47 -0
  194. package/packages/core/src/tools/office/office-escribir-docx.ts +192 -0
  195. package/packages/core/src/tools/office/office-escribir-pdf.ts +172 -0
  196. package/packages/core/src/tools/office/office-escribir-pptx.ts +174 -0
  197. package/packages/core/src/tools/office/office-escribir-xlsx.ts +116 -0
  198. package/packages/core/src/tools/office/office-leer-docx.ts +93 -0
  199. package/packages/core/src/tools/office/office-leer-pdf.ts +114 -0
  200. package/packages/core/src/tools/office/office-leer-pptx.ts +136 -0
  201. package/packages/core/src/tools/office/office-leer-xlsx.ts +124 -0
  202. package/packages/core/src/tools/projects/index.ts +37 -0
  203. package/packages/core/src/tools/projects/project-create.ts +94 -0
  204. package/packages/core/src/tools/projects/project-done.ts +66 -0
  205. package/packages/core/src/tools/projects/project-fail.ts +66 -0
  206. package/packages/core/src/tools/projects/project-list.ts +96 -0
  207. package/packages/core/src/tools/projects/project-update.ts +72 -0
  208. package/packages/core/src/tools/projects/task-create.ts +68 -0
  209. package/packages/core/src/tools/projects/task-evaluate.ts +93 -0
  210. package/packages/core/src/tools/projects/task-update.ts +93 -0
  211. package/packages/core/src/tools/types.ts +39 -0
  212. package/packages/core/src/tools/voice/index.ts +104 -0
  213. package/packages/core/src/tools/web/browser-click.ts +78 -0
  214. package/packages/core/src/tools/web/browser-extract.ts +139 -0
  215. package/packages/core/src/tools/web/browser-navigate.ts +106 -0
  216. package/packages/core/src/tools/web/browser-screenshot.ts +87 -0
  217. package/packages/core/src/tools/web/browser-script.ts +88 -0
  218. package/packages/core/src/tools/web/browser-service.ts +554 -0
  219. package/packages/core/src/tools/web/browser-type.ts +101 -0
  220. package/packages/core/src/tools/web/browser-wait.ts +136 -0
  221. package/packages/core/src/tools/web/index.ts +41 -0
  222. package/packages/core/src/tools/web/web-fetch.ts +78 -0
  223. package/packages/core/src/tools/web/web-search.ts +123 -0
  224. package/packages/core/src/utils/benchmark.ts +80 -0
  225. package/packages/core/src/utils/crypto.ts +73 -0
  226. package/packages/core/src/utils/date.ts +42 -0
  227. package/packages/core/src/utils/index.ts +10 -0
  228. package/packages/core/src/utils/logger.ts +389 -0
  229. package/packages/core/src/utils/retry.ts +70 -0
  230. package/packages/core/src/utils/toon.ts +253 -0
  231. package/packages/core/src/voice/index.ts +643 -0
  232. package/packages/core/src/workers/WorkerPool.ts +167 -0
  233. package/packages/core/src/workers/agent.worker.ts +68 -0
  234. package/packages/core/src/workers/createWorker.ts +144 -0
  235. package/packages/core/src/workers/index.ts +5 -0
  236. package/packages/core/src/workers/workers.test.ts +48 -0
  237. package/test/setup-db.ts +216 -0
  238. package/tsconfig.json +40 -0
  239. package/src/agents.ts +0 -1
  240. package/src/canvas.ts +0 -1
  241. package/src/channels.ts +0 -1
  242. package/src/config.ts +0 -1
  243. package/src/events.ts +0 -1
  244. package/src/gateway.ts +0 -1
  245. package/src/index.ts +0 -304
  246. package/src/mcp.ts +0 -1
  247. package/src/multimodal.ts +0 -1
  248. package/src/scheduler.ts +0 -1
  249. package/src/security.ts +0 -1
  250. package/src/skills.ts +0 -1
  251. package/src/state.ts +0 -1
  252. package/src/storage.ts +0 -1
  253. package/src/tools.ts +0 -1
  254. package/src/tts.ts +0 -1
  255. package/src/types.ts +0 -82
  256. package/src/utils.ts +0 -1
  257. package/src/voice.ts +0 -1
@@ -0,0 +1,42 @@
1
+ export {};
2
+ async function testCommand() {
3
+ const filter = process.argv[3];
4
+
5
+ console.log("Hive Test Runner\n");
6
+
7
+ const { initializeDatabase, dbService } = await import("@hive/core");
8
+ await initializeDatabase();
9
+
10
+ const { Glob } = await import("bun");
11
+ const glob = new Glob("packages/core/src/**/*.{test,spec}.ts");
12
+ const testFiles = Array.from(glob.scanSync({ cwd: process.cwd(), absolute: true }));
13
+
14
+ const tests = filter
15
+ ? testFiles.filter((f: string) => f.includes(filter))
16
+ : testFiles;
17
+
18
+ if (tests.length === 0) {
19
+ console.log("No tests found.");
20
+ } else {
21
+ console.log(`Found ${tests.length} test(s)\n`);
22
+ let passed = 0;
23
+ let failed = 0;
24
+
25
+ for (const test of tests as string[]) {
26
+ try {
27
+ await import(test);
28
+ console.log(` ✓ ${test.split("/").pop()}`);
29
+ passed++;
30
+ } catch (err) {
31
+ console.error(` ✗ ${test.split("/").pop()}: ${(err as Error).message}`);
32
+ failed++;
33
+ }
34
+ }
35
+
36
+ console.log(`\n${passed} passed, ${failed} failed`);
37
+ }
38
+
39
+ dbService.close();
40
+ }
41
+
42
+ testCommand();
@@ -0,0 +1,55 @@
1
+ export {};
2
+ async function traceCommand() {
3
+ const { initializeDatabase } = await import("@hive/core");
4
+ const { getDb } = await import("@hive/core/storage");
5
+
6
+ await initializeDatabase();
7
+ const db = getDb();
8
+
9
+ const limit = parseInt(process.argv[3] || "20", 10);
10
+
11
+ console.log(`\nRecent Trace Logs (last ${limit})\n`);
12
+ console.log("─".repeat(80));
13
+
14
+ try {
15
+ const rows = db
16
+ .query(
17
+ `SELECT id, agent_id, model, tool_calls, duration_ms, tokens_used, created_at
18
+ FROM traces
19
+ ORDER BY created_at DESC
20
+ LIMIT ?`
21
+ )
22
+ .all(limit) as Array<{
23
+ id: string;
24
+ agent_id: string;
25
+ model: string;
26
+ tool_calls: string;
27
+ duration_ms: number;
28
+ tokens_used: number;
29
+ created_at: string;
30
+ }>;
31
+
32
+ if (rows.length === 0) {
33
+ console.log("No traces found.");
34
+ return;
35
+ }
36
+
37
+ for (const row of rows) {
38
+ console.log(`ID: ${row.id}`);
39
+ console.log(`Agent: ${row.agent_id}`);
40
+ console.log(`Model: ${row.model}`);
41
+ console.log(`Duration: ${row.duration_ms}ms`);
42
+ console.log(`Tokens: ${row.tokens_used}`);
43
+ console.log(`Time: ${row.created_at}`);
44
+ if (row.tool_calls) {
45
+ const tools = JSON.parse(row.tool_calls);
46
+ console.log(`Tools: ${Array.isArray(tools) ? tools.join(", ") : row.tool_calls}`);
47
+ }
48
+ console.log("─".repeat(80));
49
+ }
50
+ } catch (err) {
51
+ console.log("No traces table found (run the agent first).");
52
+ }
53
+ }
54
+
55
+ traceCommand();
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bun
2
+
3
+ export {};
4
+ const command = process.argv[2];
5
+
6
+ switch (command) {
7
+ case "init":
8
+ await import("./commands/init.ts");
9
+ break;
10
+ case "create-app":
11
+ await import("./commands/create-app.ts");
12
+ break;
13
+ case "add-tool":
14
+ await import("./commands/add-tool.ts");
15
+ break;
16
+ case "add-skill":
17
+ await import("./commands/add-skill.ts");
18
+ break;
19
+ case "add-worker":
20
+ await import("./commands/add-worker.ts");
21
+ break;
22
+ case "run":
23
+ await import("./commands/run.ts");
24
+ break;
25
+ case "test":
26
+ await import("./commands/test.ts");
27
+ break;
28
+ case "trace":
29
+ await import("./commands/trace.ts");
30
+ break;
31
+ case "--help":
32
+ case "-h":
33
+ case undefined:
34
+ printHelp();
35
+ break;
36
+ default:
37
+ console.error(`Unknown command: ${command}`);
38
+ printHelp();
39
+ process.exit(1);
40
+ }
41
+
42
+ function printHelp() {
43
+ console.log(`
44
+ Usage: hive <command> [options]
45
+
46
+ Commands:
47
+ init <name> Initialize a new Hive agent project
48
+ create-app <name> Create a full Hive harness application
49
+ add-tool <name> Add a new tool to the current project
50
+ add-skill <name> Add a new skill to the current project
51
+ add-worker <name> Add a new Bun Worker to the current project
52
+ run Run the agent
53
+ test Test tools or skills
54
+ trace View trace execution logs
55
+
56
+ Options:
57
+ --help, -h Show this help message
58
+ `);
59
+ }
@@ -0,0 +1,17 @@
1
+ # Hive Harness Configuration
2
+ HIVE_HOST=127.0.0.1
3
+ HIVE_PORT=18790
4
+ HIVE_DATA_DIR=./data
5
+
6
+ # LLM Providers
7
+ OPENAI_API_KEY=sk-...
8
+ ANTHROPIC_API_KEY=sk-ant-...
9
+ GOOGLE_API_KEY=...
10
+
11
+ # Channels (enable as needed)
12
+ TELEGRAM_BOT_TOKEN=
13
+ DISCORD_BOT_TOKEN=
14
+ SLACK_BOT_TOKEN=
15
+
16
+ # Logging
17
+ LOG_LEVEL=info
@@ -0,0 +1,20 @@
1
+ services:
2
+ app:
3
+ image: oven/bun:latest
4
+ working_dir: /app
5
+ volumes:
6
+ - .:/app
7
+ - hive-data:/app/data
8
+ ports:
9
+ - "${HIVE_PORT:-18790}:18790"
10
+ environment:
11
+ - HIVE_HOST=0.0.0.0
12
+ - HIVE_PORT=18790
13
+ - HIVE_DATA_DIR=/app/data
14
+ - OPENAI_API_KEY=${OPENAI_API_KEY}
15
+ - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
16
+ command: ["bun", "run", "src/main.ts"]
17
+ restart: unless-stopped
18
+
19
+ volumes:
20
+ hive-data:
@@ -0,0 +1,19 @@
1
+ import type { Config } from "@johpaz/hive-sdk";
2
+
3
+ export default {
4
+ name: "{{APP_NAME}}",
5
+ gateway: {
6
+ host: process.env.HIVE_HOST ?? "127.0.0.1",
7
+ port: Number(process.env.HIVE_PORT ?? 18790),
8
+ },
9
+ channels: {
10
+ webchat: { enabled: true },
11
+ telegram: { enabled: false },
12
+ discord: { enabled: false },
13
+ whatsapp: { enabled: false },
14
+ slack: { enabled: false },
15
+ },
16
+ database: {
17
+ path: process.env.HIVE_DATA_DIR ?? "./data/hive.db",
18
+ },
19
+ } satisfies Config;
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "{{APP_NAME}}",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "bun run src/main.ts",
7
+ "start": "bun run src/main.ts",
8
+ "build": "bun build src/main.ts --outdir dist --target bun"
9
+ },
10
+ "dependencies": {
11
+ "@johpaz/hive-sdk": "latest"
12
+ },
13
+ "devDependencies": {
14
+ "@types/bun": "latest"
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ import { createAgent } from "@johpaz/hive-sdk";
2
+
3
+ export const coordinatorAgent = await createAgent({
4
+ name: "coordinator",
5
+ provider: "openai",
6
+ model: "gpt-4o-mini",
7
+ systemPrompt:
8
+ "You are the coordinator agent. You orchestrate tasks, answer questions, and delegate to specialized agents when needed.",
9
+ });
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import {
4
+ createAgent,
5
+ startGateway,
6
+ initializeDatabase,
7
+ ChannelManager,
8
+ logger,
9
+ loadConfig,
10
+ } from "@johpaz/hive-sdk";
11
+ import config from "../hive.config.ts";
12
+
13
+ const log = logger.child("app");
14
+
15
+ async function main() {
16
+ log.info(`Starting {{APP_NAME}}...`);
17
+
18
+ // Initialize database
19
+ await initializeDatabase();
20
+
21
+ // Create the main agent
22
+ const agent = await createAgent({
23
+ name: "coordinator",
24
+ provider: "openai",
25
+ model: "gpt-4o-mini",
26
+ systemPrompt:
27
+ "You are a helpful AI assistant running in a Hive harness. You can use tools, manage tasks, and communicate across channels.",
28
+ });
29
+
30
+ log.info(`Agent ready: ${agent.name}`);
31
+
32
+ // Initialize channels
33
+ const channelManager = new ChannelManager();
34
+ // TODO: configure channels from hive.config.ts
35
+
36
+ // Start the gateway
37
+ const gateway = await startGateway({
38
+ host: config.gateway?.host,
39
+ port: config.gateway?.port,
40
+ agentId: "coordinator",
41
+ });
42
+
43
+ log.info(`{{APP_NAME}} is running at http://${gateway.hostname}:${gateway.port}`);
44
+
45
+ // Graceful shutdown
46
+ process.on("SIGINT", async () => {
47
+ log.info("Shutting down...");
48
+ gateway.stop(true);
49
+ process.exit(0);
50
+ });
51
+ }
52
+
53
+ main().catch((err) => {
54
+ log.error("Fatal error:", err);
55
+ process.exit(1);
56
+ });
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@hive/core",
3
+ "version": "0.0.15",
4
+ "description": "Hive Core — Agentes AI con Context Engineering, FTS5, ACE, Swarm",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "exports": {
10
+ ".": "./src/index.ts",
11
+ "./agent": "./src/agent/index.ts",
12
+ "./agent/providers": "./src/agent/providers/index.ts",
13
+ "./agent/selectors": "./src/agent/selectors/index.ts",
14
+ "./tools": "./src/tools/index.ts",
15
+ "./skills": "./src/skills/index.ts",
16
+ "./storage": "./src/storage/index.ts",
17
+ "./swarm": "./src/swarm/index.ts",
18
+ "./swarm/strategies": "./src/swarm/strategies/index.ts",
19
+ "./swarm/presets": "./src/swarm/presets/index.ts",
20
+ "./ace": "./src/ace/index.ts",
21
+ "./ethics": "./src/ethics/index.ts",
22
+ "./canvas": "./src/canvas/index.ts",
23
+ "./config": "./src/config/index.ts",
24
+ "./mcp": "./src/mcp/index.ts",
25
+ "./mcp/transports": "./src/mcp/transports/index.ts",
26
+ "./memory": "./src/memory/index.ts",
27
+ "./multimodal": "./src/multimodal/index.ts",
28
+ "./security": "./src/security/index.ts",
29
+ "./state": "./src/state/index.ts",
30
+ "./utils": "./src/utils/index.ts",
31
+ "./gateway": "./src/gateway/index.ts",
32
+ "./api": "./src/api/index.ts"
33
+ },
34
+ "dependencies": {
35
+ "@anthropic-ai/sdk": "^0.74.0",
36
+ "@google/genai": "^1.43.0",
37
+ "@modelcontextprotocol/sdk": "latest",
38
+ "@sapphire/snowflake": "latest",
39
+ "async-mutex": "^0.5.0",
40
+ "cron-parser": "^5.5.0",
41
+ "croner": "^10.0.1",
42
+ "docx": "^9.6.1",
43
+ "groq-sdk": "^0.37.0",
44
+ "jszip": "^3.10.1",
45
+ "pdf-lib": "^1.17.1",
46
+ "mammoth": "^1.12.0",
47
+ "ollama": "^0.6.3",
48
+ "openai": "^6.18.0",
49
+ "pdfjs-dist": "^5.6.205",
50
+ "pptxgenjs": "^4.0.1",
51
+ "toon-format-parser": "^1.1.0",
52
+ "xlsx": "^0.18.5",
53
+ "zod": "latest"
54
+ },
55
+ "peerDependencies": {
56
+ "typescript": "^5.0.0"
57
+ }
58
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * ACE Curator — converts reflections into playbook rules.
3
+ *
4
+ * Runs after the Reflector. Performs incremental edits to the playbook:
5
+ * - New insights → new rules
6
+ * - Repeated patterns → increment helpful_count
7
+ * - Contradicted rules → increment harmful_count or deactivate
8
+ * - Deactivate rules where harmful_count > helpful_count
9
+ * - Archive unused workers
10
+ *
11
+ * Never rewrites the whole playbook — only incremental edits.
12
+ */
13
+
14
+ import { logger } from "../utils/logger.ts"
15
+
16
+ const log = logger.child("curator")
17
+
18
+ const DAYS_BEFORE_ARCHIVE = 14 // archive workers not used in N days
19
+ const MAX_HARMFUL_BEFORE_PRUNE = 3
20
+
21
+ /** Entry point — called by reflector.ts after it inserts new reflections */
22
+ export async function runCurator(): Promise<void> {
23
+ try {
24
+ const { getDb } = await import("../storage/SQLiteStorage.ts")
25
+ const db = getDb()
26
+
27
+ // Process unprocessed reflections (those newer than last run)
28
+ const lastProcessed = (db.query<any, []>(
29
+ "SELECT COALESCE(MAX(source_reflection_id), 0) as mid FROM playbook"
30
+ ).get() as any)?.mid ?? 0
31
+
32
+ const reflections = (db.query as any)(
33
+ "SELECT * FROM reflections WHERE id > ? ORDER BY id ASC"
34
+ ).all(lastProcessed)
35
+
36
+ if (reflections.length === 0) {
37
+ log.debug("[curator] No new reflections to process")
38
+ } else {
39
+ log.info(`[curator] Processing ${reflections.length} new reflections`)
40
+ for (const reflection of reflections) {
41
+ processReflection(db, reflection)
42
+ }
43
+ }
44
+
45
+ // Prune rules where harmful > helpful (consistently bad rules)
46
+ db.query(`
47
+ UPDATE playbook
48
+ SET active = 0, updated_at = unixepoch()
49
+ WHERE active = 1
50
+ AND harmful_count > helpful_count
51
+ AND harmful_count >= ?
52
+ `).run(MAX_HARMFUL_BEFORE_PRUNE)
53
+
54
+ // Archive unused workers
55
+ const cutoff = Math.floor(Date.now() / 1000) - (DAYS_BEFORE_ARCHIVE * 86400)
56
+ const staleworkers = (db.query as any)(`
57
+ SELECT a.id, a.name
58
+ FROM agents a
59
+ WHERE a.role = 'worker'
60
+ AND a.status != 'archived'
61
+ AND a.enabled = 1
62
+ AND (
63
+ SELECT MAX(t.created_at) FROM traces t WHERE t.agent_id = a.id
64
+ ) < ?
65
+ `).all(cutoff)
66
+
67
+ for (const worker of staleworkers) {
68
+ db.query(
69
+ "UPDATE agents SET status = 'archived', updated_at = unixepoch() WHERE id = ?"
70
+ ).run(worker.id)
71
+
72
+ // Add playbook note about archival
73
+ addOrUpdateRule(db, {
74
+ rule: `Worker '${worker.name}' was archived due to inactivity (>${DAYS_BEFORE_ARCHIVE} days unused).`,
75
+ category: "agent_creation",
76
+ applicable_to: null,
77
+ sourceReflectionId: null,
78
+ })
79
+
80
+ log.info(`[curator] Archived inactive worker: ${worker.name} (${worker.id})`)
81
+ }
82
+
83
+ log.info("[curator] Playbook updated")
84
+ } catch (err) {
85
+ log.warn("[curator] Error:", err)
86
+ }
87
+ }
88
+
89
+ // ─── Process a single reflection ─────────────────────────────────────────────
90
+
91
+ function processReflection(db: any, reflection: any): void {
92
+ const category = mapInsightTypeToCategory(reflection.insight_type)
93
+
94
+ // Check if a similar rule already exists (fuzzy check by first 60 chars)
95
+ const prefix = reflection.description.substring(0, 60)
96
+ const existing = (db.query as any)(
97
+ "SELECT id, helpful_count FROM playbook WHERE rule LIKE ? AND active = 1 LIMIT 1"
98
+ ).get(`${prefix}%`)
99
+
100
+ if (existing) {
101
+ // Reinforce existing rule
102
+ db.query(
103
+ "UPDATE playbook SET helpful_count = helpful_count + 1, updated_at = unixepoch() WHERE id = ?"
104
+ ).run(existing.id)
105
+ return
106
+ }
107
+
108
+ // Insert new rule
109
+ db.query(`
110
+ INSERT INTO playbook (rule, category, applicable_to, helpful_count, source_reflection_id)
111
+ VALUES (?, ?, ?, 1, ?)
112
+ `).run(
113
+ reflection.description,
114
+ category,
115
+ reflection.affected_tools
116
+ ? JSON.stringify(JSON.parse(reflection.affected_tools))
117
+ : null,
118
+ reflection.id,
119
+ )
120
+ }
121
+
122
+ function mapInsightTypeToCategory(
123
+ type: string
124
+ ): "tool_selection" | "response_quality" | "error_avoidance" | "optimization" | "agent_creation" {
125
+ const map: Record<string, any> = {
126
+ success_pattern: "tool_selection",
127
+ failure_pattern: "error_avoidance",
128
+ optimization: "optimization",
129
+ ethics_violation: "error_avoidance",
130
+ }
131
+ return map[type] ?? "optimization"
132
+ }
133
+
134
+ function addOrUpdateRule(
135
+ db: any,
136
+ opts: {
137
+ rule: string
138
+ category: string
139
+ applicable_to: string | null
140
+ sourceReflectionId: number | null
141
+ }
142
+ ): void {
143
+ const prefix = opts.rule.substring(0, 60)
144
+ const existing = (db.query as any)(
145
+ "SELECT id FROM playbook WHERE rule LIKE ? LIMIT 1"
146
+ ).get(`${prefix}%`)
147
+
148
+ if (existing) {
149
+ db.query(
150
+ "UPDATE playbook SET helpful_count = helpful_count + 1, updated_at = unixepoch() WHERE id = ?"
151
+ ).run(existing.id)
152
+ } else {
153
+ db.query(`
154
+ INSERT INTO playbook (rule, category, applicable_to, helpful_count, source_reflection_id)
155
+ VALUES (?, ?, ?, 1, ?)
156
+ `).run(opts.rule, opts.category, opts.applicable_to, opts.sourceReflectionId)
157
+ }
158
+ }