@inixiative/hivemind 0.1.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 (287) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -0
  3. package/dist/agents/agents.test.d.ts +1 -0
  4. package/dist/agents/agents.test.js +167 -0
  5. package/dist/agents/getActiveAgents.d.ts +6 -0
  6. package/dist/agents/getActiveAgents.js +11 -0
  7. package/dist/agents/getAgent.d.ts +6 -0
  8. package/dist/agents/getAgent.js +7 -0
  9. package/dist/agents/getAgentBySessionId.d.ts +10 -0
  10. package/dist/agents/getAgentBySessionId.js +17 -0
  11. package/dist/agents/index.d.ts +10 -0
  12. package/dist/agents/index.js +12 -0
  13. package/dist/agents/markAgentDead.d.ts +6 -0
  14. package/dist/agents/markAgentDead.js +26 -0
  15. package/dist/agents/markAgentIdle.d.ts +5 -0
  16. package/dist/agents/markAgentIdle.js +12 -0
  17. package/dist/agents/registerAgent.d.ts +6 -0
  18. package/dist/agents/registerAgent.js +29 -0
  19. package/dist/agents/types.d.ts +30 -0
  20. package/dist/agents/types.js +1 -0
  21. package/dist/agents/unregisterAgent.d.ts +5 -0
  22. package/dist/agents/unregisterAgent.js +8 -0
  23. package/dist/agents/updateAgentContext.d.ts +5 -0
  24. package/dist/agents/updateAgentContext.js +12 -0
  25. package/dist/agents/updateAgentTask.d.ts +5 -0
  26. package/dist/agents/updateAgentTask.js +12 -0
  27. package/dist/agents/updateAgentWorktree.d.ts +5 -0
  28. package/dist/agents/updateAgentWorktree.js +12 -0
  29. package/dist/cli/index.d.ts +8 -0
  30. package/dist/cli/index.js +8 -0
  31. package/dist/cli/init.d.ts +14 -0
  32. package/dist/cli/init.js +71 -0
  33. package/dist/cli/install.d.ts +8 -0
  34. package/dist/cli/install.js +47 -0
  35. package/dist/cli/join.d.ts +9 -0
  36. package/dist/cli/join.js +38 -0
  37. package/dist/cli/registerMcp.d.ts +28 -0
  38. package/dist/cli/registerMcp.js +138 -0
  39. package/dist/cli/status.d.ts +8 -0
  40. package/dist/cli/status.js +82 -0
  41. package/dist/cli/watch.d.ts +6 -0
  42. package/dist/cli/watch.js +68 -0
  43. package/dist/cli.d.ts +12 -0
  44. package/dist/cli.js +49 -0
  45. package/dist/coordinator/coordinator.test.d.ts +1 -0
  46. package/dist/coordinator/coordinator.test.js +171 -0
  47. package/dist/coordinator/index.d.ts +16 -0
  48. package/dist/coordinator/index.js +166 -0
  49. package/dist/coordinator/spawn.d.ts +22 -0
  50. package/dist/coordinator/spawn.js +66 -0
  51. package/dist/datetime/datetime.test.d.ts +1 -0
  52. package/dist/datetime/datetime.test.js +63 -0
  53. package/dist/datetime/formatDate.d.ts +6 -0
  54. package/dist/datetime/formatDate.js +11 -0
  55. package/dist/datetime/formatDatetime.d.ts +6 -0
  56. package/dist/datetime/formatDatetime.js +12 -0
  57. package/dist/datetime/formatTime.d.ts +6 -0
  58. package/dist/datetime/formatTime.js +11 -0
  59. package/dist/datetime/index.d.ts +4 -0
  60. package/dist/datetime/index.js +7 -0
  61. package/dist/datetime/isStale.d.ts +10 -0
  62. package/dist/datetime/isStale.js +18 -0
  63. package/dist/datetime/now.d.ts +6 -0
  64. package/dist/datetime/now.js +9 -0
  65. package/dist/datetime/parseDatetime.d.ts +7 -0
  66. package/dist/datetime/parseDatetime.js +28 -0
  67. package/dist/db/constants.d.ts +4 -0
  68. package/dist/db/constants.js +6 -0
  69. package/dist/db/db.test.d.ts +1 -0
  70. package/dist/db/db.test.js +141 -0
  71. package/dist/db/ensureProjectDirs.d.ts +4 -0
  72. package/dist/db/ensureProjectDirs.js +12 -0
  73. package/dist/db/getConnection.d.ts +19 -0
  74. package/dist/db/getConnection.js +51 -0
  75. package/dist/db/getCurrentProject.d.ts +8 -0
  76. package/dist/db/getCurrentProject.js +14 -0
  77. package/dist/db/getProjectPaths.d.ts +21 -0
  78. package/dist/db/getProjectPaths.js +26 -0
  79. package/dist/db/index.d.ts +10 -0
  80. package/dist/db/index.js +13 -0
  81. package/dist/db/initializeDb.d.ts +7 -0
  82. package/dist/db/initializeDb.js +23 -0
  83. package/dist/db/nextEventSeq.d.ts +5 -0
  84. package/dist/db/nextEventSeq.js +13 -0
  85. package/dist/db/nextSubtaskSeq.d.ts +5 -0
  86. package/dist/db/nextSubtaskSeq.js +12 -0
  87. package/dist/db/nextTaskSeq.d.ts +5 -0
  88. package/dist/db/nextTaskSeq.js +13 -0
  89. package/dist/db/resetDb.d.ts +10 -0
  90. package/dist/db/resetDb.js +36 -0
  91. package/dist/events/emit.d.ts +6 -0
  92. package/dist/events/emit.js +31 -0
  93. package/dist/events/events.test.d.ts +1 -0
  94. package/dist/events/events.test.js +145 -0
  95. package/dist/events/getEventsByAgent.d.ts +6 -0
  96. package/dist/events/getEventsByAgent.js +14 -0
  97. package/dist/events/getEventsByBranch.d.ts +6 -0
  98. package/dist/events/getEventsByBranch.js +12 -0
  99. package/dist/events/getEventsByPlan.d.ts +6 -0
  100. package/dist/events/getEventsByPlan.js +14 -0
  101. package/dist/events/getEventsByWorktree.d.ts +6 -0
  102. package/dist/events/getEventsByWorktree.js +12 -0
  103. package/dist/events/getEventsSince.d.ts +12 -0
  104. package/dist/events/getEventsSince.js +47 -0
  105. package/dist/events/getRecentEvents.d.ts +6 -0
  106. package/dist/events/getRecentEvents.js +12 -0
  107. package/dist/events/index.d.ts +8 -0
  108. package/dist/events/index.js +9 -0
  109. package/dist/events/types.d.ts +34 -0
  110. package/dist/events/types.js +1 -0
  111. package/dist/git/getBranch.d.ts +4 -0
  112. package/dist/git/getBranch.js +14 -0
  113. package/dist/git/getCurrentWorktree.d.ts +5 -0
  114. package/dist/git/getCurrentWorktree.js +15 -0
  115. package/dist/git/getGitInfo.d.ts +10 -0
  116. package/dist/git/getGitInfo.js +23 -0
  117. package/dist/git/getRepoName.d.ts +4 -0
  118. package/dist/git/getRepoName.js +32 -0
  119. package/dist/git/getRepoRoot.d.ts +4 -0
  120. package/dist/git/getRepoRoot.js +14 -0
  121. package/dist/git/getWorktrees.d.ts +10 -0
  122. package/dist/git/getWorktrees.js +39 -0
  123. package/dist/git/index.d.ts +9 -0
  124. package/dist/git/index.js +7 -0
  125. package/dist/git/isGitRepo.d.ts +4 -0
  126. package/dist/git/isGitRepo.js +13 -0
  127. package/dist/hooks/index.d.ts +1 -0
  128. package/dist/hooks/index.js +1 -0
  129. package/dist/hooks/sessionStart.d.ts +21 -0
  130. package/dist/hooks/sessionStart.js +93 -0
  131. package/dist/ids/generateHex.d.ts +4 -0
  132. package/dist/ids/generateHex.js +7 -0
  133. package/dist/ids/getParentTaskId.d.ts +7 -0
  134. package/dist/ids/getParentTaskId.js +15 -0
  135. package/dist/ids/getPlanHexFromTaskId.d.ts +6 -0
  136. package/dist/ids/getPlanHexFromTaskId.js +9 -0
  137. package/dist/ids/ids.test.d.ts +1 -0
  138. package/dist/ids/ids.test.js +215 -0
  139. package/dist/ids/index.d.ts +16 -0
  140. package/dist/ids/index.js +17 -0
  141. package/dist/ids/isSubtask.d.ts +7 -0
  142. package/dist/ids/isSubtask.js +11 -0
  143. package/dist/ids/isValidId.d.ts +9 -0
  144. package/dist/ids/isValidId.js +22 -0
  145. package/dist/ids/makeAgentId.d.ts +8 -0
  146. package/dist/ids/makeAgentId.js +15 -0
  147. package/dist/ids/makeEventId.d.ts +11 -0
  148. package/dist/ids/makeEventId.js +12 -0
  149. package/dist/ids/makePlanId.d.ts +11 -0
  150. package/dist/ids/makePlanId.js +15 -0
  151. package/dist/ids/makeSubtaskId.d.ts +8 -0
  152. package/dist/ids/makeSubtaskId.js +15 -0
  153. package/dist/ids/makeTaskId.d.ts +8 -0
  154. package/dist/ids/makeTaskId.js +14 -0
  155. package/dist/ids/makeWorktreeId.d.ts +5 -0
  156. package/dist/ids/makeWorktreeId.js +12 -0
  157. package/dist/ids/parseId.d.ts +11 -0
  158. package/dist/ids/parseId.js +26 -0
  159. package/dist/ids/sanitizeLabel.d.ts +7 -0
  160. package/dist/ids/sanitizeLabel.js +12 -0
  161. package/dist/ids/typedIds.d.ts +34 -0
  162. package/dist/ids/typedIds.js +22 -0
  163. package/dist/ids/types.d.ts +14 -0
  164. package/dist/ids/types.js +1 -0
  165. package/dist/init/claudeConfig.d.ts +39 -0
  166. package/dist/init/claudeConfig.js +161 -0
  167. package/dist/llm/extractTasks.d.ts +28 -0
  168. package/dist/llm/extractTasks.js +108 -0
  169. package/dist/llm/index.d.ts +2 -0
  170. package/dist/llm/index.js +2 -0
  171. package/dist/llm/reconcileTasks.d.ts +21 -0
  172. package/dist/llm/reconcileTasks.js +82 -0
  173. package/dist/mcp/server.d.ts +2 -0
  174. package/dist/mcp/server.js +100 -0
  175. package/dist/mcp/tools/emitEvent.d.ts +62 -0
  176. package/dist/mcp/tools/emitEvent.js +84 -0
  177. package/dist/mcp/tools/events.d.ts +55 -0
  178. package/dist/mcp/tools/events.js +56 -0
  179. package/dist/mcp/tools/index.d.ts +18 -0
  180. package/dist/mcp/tools/index.js +13 -0
  181. package/dist/mcp/tools/query.d.ts +54 -0
  182. package/dist/mcp/tools/query.js +70 -0
  183. package/dist/mcp/tools/register.d.ts +47 -0
  184. package/dist/mcp/tools/register.js +79 -0
  185. package/dist/mcp/tools/reset.d.ts +38 -0
  186. package/dist/mcp/tools/reset.js +56 -0
  187. package/dist/mcp/tools/setup.d.ts +42 -0
  188. package/dist/mcp/tools/setup.js +75 -0
  189. package/dist/mcp/tools/status.d.ts +44 -0
  190. package/dist/mcp/tools/status.js +74 -0
  191. package/dist/mcp/tools/tasks.d.ts +116 -0
  192. package/dist/mcp/tools/tasks.js +143 -0
  193. package/dist/mcp/tools/worktreeCleanup.d.ts +38 -0
  194. package/dist/mcp/tools/worktreeCleanup.js +67 -0
  195. package/dist/plans/createPlan.d.ts +6 -0
  196. package/dist/plans/createPlan.js +29 -0
  197. package/dist/plans/getActivePlans.d.ts +6 -0
  198. package/dist/plans/getActivePlans.js +11 -0
  199. package/dist/plans/getPlan.d.ts +6 -0
  200. package/dist/plans/getPlan.js +7 -0
  201. package/dist/plans/index.d.ts +5 -0
  202. package/dist/plans/index.js +5 -0
  203. package/dist/plans/plans.test.d.ts +1 -0
  204. package/dist/plans/plans.test.js +107 -0
  205. package/dist/plans/types.d.ts +32 -0
  206. package/dist/plans/types.js +1 -0
  207. package/dist/plans/updatePlanStatus.d.ts +6 -0
  208. package/dist/plans/updatePlanStatus.js +8 -0
  209. package/dist/tasks/assignTask.d.ts +7 -0
  210. package/dist/tasks/assignTask.js +20 -0
  211. package/dist/tasks/blockTask.d.ts +5 -0
  212. package/dist/tasks/blockTask.js +12 -0
  213. package/dist/tasks/claimTask.d.ts +7 -0
  214. package/dist/tasks/claimTask.js +21 -0
  215. package/dist/tasks/completeTask.d.ts +6 -0
  216. package/dist/tasks/completeTask.js +18 -0
  217. package/dist/tasks/createTask.d.ts +6 -0
  218. package/dist/tasks/createTask.js +36 -0
  219. package/dist/tasks/getPendingTasks.d.ts +6 -0
  220. package/dist/tasks/getPendingTasks.js +19 -0
  221. package/dist/tasks/getTask.d.ts +6 -0
  222. package/dist/tasks/getTask.js +7 -0
  223. package/dist/tasks/getTasksByPlan.d.ts +6 -0
  224. package/dist/tasks/getTasksByPlan.js +11 -0
  225. package/dist/tasks/index.d.ts +11 -0
  226. package/dist/tasks/index.js +12 -0
  227. package/dist/tasks/startTask.d.ts +5 -0
  228. package/dist/tasks/startTask.js +12 -0
  229. package/dist/tasks/tasks.test.d.ts +1 -0
  230. package/dist/tasks/tasks.test.js +209 -0
  231. package/dist/tasks/types.d.ts +36 -0
  232. package/dist/tasks/types.js +1 -0
  233. package/dist/tasks/unclaimTask.d.ts +5 -0
  234. package/dist/tasks/unclaimTask.js +12 -0
  235. package/dist/test/factories/agentFactory.d.ts +13 -0
  236. package/dist/test/factories/agentFactory.js +5 -0
  237. package/dist/test/factories/eventFactory.d.ts +20 -0
  238. package/dist/test/factories/eventFactory.js +16 -0
  239. package/dist/test/factories/factories.test.d.ts +1 -0
  240. package/dist/test/factories/factories.test.js +101 -0
  241. package/dist/test/factories/index.d.ts +4 -0
  242. package/dist/test/factories/index.js +4 -0
  243. package/dist/test/factories/planFactory.d.ts +15 -0
  244. package/dist/test/factories/planFactory.js +14 -0
  245. package/dist/test/factories/taskFactory.d.ts +22 -0
  246. package/dist/test/factories/taskFactory.js +44 -0
  247. package/dist/test/multiAgentDemo.d.ts +16 -0
  248. package/dist/test/multiAgentDemo.js +20 -0
  249. package/dist/test/multiAgentDemo.test.d.ts +1 -0
  250. package/dist/test/multiAgentDemo.test.js +14 -0
  251. package/dist/test/setup.d.ts +9 -0
  252. package/dist/test/setup.js +50 -0
  253. package/dist/utils/index.d.ts +5 -0
  254. package/dist/utils/index.js +5 -0
  255. package/dist/utils/math.d.ts +6 -0
  256. package/dist/utils/math.js +10 -0
  257. package/dist/utils/math.test.d.ts +1 -0
  258. package/dist/utils/math.test.js +26 -0
  259. package/dist/utils/string.d.ts +11 -0
  260. package/dist/utils/string.js +17 -0
  261. package/dist/utils/string.test.d.ts +1 -0
  262. package/dist/utils/string.test.js +30 -0
  263. package/dist/watcher/index.d.ts +1 -0
  264. package/dist/watcher/index.js +1 -0
  265. package/dist/watcher/planWatcher.d.ts +31 -0
  266. package/dist/watcher/planWatcher.js +171 -0
  267. package/dist/worktrees/getAllWorktrees.d.ts +6 -0
  268. package/dist/worktrees/getAllWorktrees.js +10 -0
  269. package/dist/worktrees/getWorktreeById.d.ts +6 -0
  270. package/dist/worktrees/getWorktreeById.js +7 -0
  271. package/dist/worktrees/getWorktreeByPath.d.ts +6 -0
  272. package/dist/worktrees/getWorktreeByPath.js +7 -0
  273. package/dist/worktrees/index.d.ts +9 -0
  274. package/dist/worktrees/index.js +13 -0
  275. package/dist/worktrees/registerWorktree.d.ts +6 -0
  276. package/dist/worktrees/registerWorktree.js +28 -0
  277. package/dist/worktrees/removeWorktree.d.ts +6 -0
  278. package/dist/worktrees/removeWorktree.js +9 -0
  279. package/dist/worktrees/syncWorktreesFromGit.d.ts +7 -0
  280. package/dist/worktrees/syncWorktreesFromGit.js +51 -0
  281. package/dist/worktrees/types.d.ts +29 -0
  282. package/dist/worktrees/types.js +1 -0
  283. package/dist/worktrees/updateWorktreeCommit.d.ts +5 -0
  284. package/dist/worktrees/updateWorktreeCommit.js +13 -0
  285. package/dist/worktrees/updateWorktreeSeen.d.ts +5 -0
  286. package/dist/worktrees/updateWorktreeSeen.js +13 -0
  287. package/package.json +58 -0
@@ -0,0 +1,62 @@
1
+ import type { EventType } from '../../events/types';
2
+ export declare const emitEventTool: {
3
+ name: string;
4
+ description: string;
5
+ annotations: {
6
+ readOnlyHint: boolean;
7
+ destructiveHint: boolean;
8
+ idempotentHint: boolean;
9
+ openWorldHint: boolean;
10
+ };
11
+ inputSchema: {
12
+ type: string;
13
+ properties: {
14
+ project: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ agentId: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ sessionId: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ type: {
27
+ type: string;
28
+ description: string;
29
+ };
30
+ content: {
31
+ type: string;
32
+ description: string;
33
+ };
34
+ planId: {
35
+ type: string;
36
+ description: string;
37
+ };
38
+ taskId: {
39
+ type: string;
40
+ description: string;
41
+ };
42
+ };
43
+ required: string[];
44
+ };
45
+ };
46
+ export type EmitEventInput = {
47
+ project: string;
48
+ agentId?: string;
49
+ sessionId?: string;
50
+ type: EventType;
51
+ content: string;
52
+ planId?: string;
53
+ taskId?: string;
54
+ };
55
+ export type EmitEventResult = {
56
+ success: boolean;
57
+ eventId?: string;
58
+ agentId?: string;
59
+ timestamp?: string;
60
+ message: string;
61
+ };
62
+ export declare function executeEmitEvent(input: EmitEventInput): EmitEventResult;
@@ -0,0 +1,84 @@
1
+ import { getConnection } from '../../db/getConnection';
2
+ import { getProjectPaths } from '../../db/getProjectPaths';
3
+ import { emit } from '../../events/emit';
4
+ import { getAgentBySessionId } from '../../agents/getAgentBySessionId';
5
+ import { ensureCoordinator } from '../../coordinator/spawn';
6
+ import { getBranch } from '../../git/getBranch';
7
+ export const emitEventTool = {
8
+ name: 'hivemind_emit',
9
+ description: 'Emit an event to the hivemind log for other agents to see. ' +
10
+ 'Can use either agentId directly or sessionId to look up the agent.',
11
+ annotations: {
12
+ readOnlyHint: false,
13
+ destructiveHint: false,
14
+ idempotentHint: false,
15
+ openWorldHint: false,
16
+ },
17
+ inputSchema: {
18
+ type: 'object',
19
+ properties: {
20
+ project: {
21
+ type: 'string',
22
+ description: 'Project name',
23
+ },
24
+ agentId: {
25
+ type: 'string',
26
+ description: "This agent's ID (optional if sessionId provided)",
27
+ },
28
+ sessionId: {
29
+ type: 'string',
30
+ description: 'Claude session ID to look up agent (alternative to agentId)',
31
+ },
32
+ type: {
33
+ type: 'string',
34
+ description: 'Event type (decision, question, answer, context, note, etc.)',
35
+ },
36
+ content: {
37
+ type: 'string',
38
+ description: 'Event content/message',
39
+ },
40
+ planId: {
41
+ type: 'string',
42
+ description: 'Optional plan ID this event relates to',
43
+ },
44
+ taskId: {
45
+ type: 'string',
46
+ description: 'Optional task ID this event relates to',
47
+ },
48
+ },
49
+ required: ['project', 'type', 'content'],
50
+ },
51
+ };
52
+ export function executeEmitEvent(input) {
53
+ const db = getConnection(input.project);
54
+ const paths = getProjectPaths(input.project);
55
+ // Ensure coordinator is running
56
+ ensureCoordinator({ project: input.project, dataDir: paths.projectDir });
57
+ // Resolve agent ID - either directly provided or looked up by session
58
+ let agentId = input.agentId;
59
+ if (!agentId && input.sessionId) {
60
+ const agent = getAgentBySessionId(db, input.sessionId);
61
+ agentId = agent?.id;
62
+ }
63
+ if (!agentId) {
64
+ return {
65
+ success: false,
66
+ message: 'No agent found - provide agentId or valid sessionId',
67
+ };
68
+ }
69
+ const event = emit(db, {
70
+ agent_id: agentId,
71
+ plan_id: input.planId,
72
+ task_id: input.taskId,
73
+ branch: getBranch() ?? undefined,
74
+ type: input.type,
75
+ content: input.content,
76
+ });
77
+ return {
78
+ success: true,
79
+ eventId: event.id,
80
+ agentId,
81
+ timestamp: event.timestamp,
82
+ message: `Event ${event.id} emitted`,
83
+ };
84
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Events MCP tool - simple event tailing
3
+ */
4
+ export declare const eventsTool: {
5
+ name: string;
6
+ description: string;
7
+ annotations: {
8
+ readOnlyHint: boolean;
9
+ destructiveHint: boolean;
10
+ idempotentHint: boolean;
11
+ openWorldHint: boolean;
12
+ };
13
+ inputSchema: {
14
+ type: string;
15
+ properties: {
16
+ project: {
17
+ type: string;
18
+ description: string;
19
+ };
20
+ limit: {
21
+ type: string;
22
+ description: string;
23
+ };
24
+ since: {
25
+ type: string;
26
+ description: string;
27
+ };
28
+ type: {
29
+ type: string;
30
+ description: string;
31
+ };
32
+ };
33
+ required: string[];
34
+ };
35
+ };
36
+ export type EventsInput = {
37
+ project: string;
38
+ limit?: number;
39
+ since?: string;
40
+ type?: string;
41
+ };
42
+ export type EventsResult = {
43
+ events: Array<{
44
+ id: string;
45
+ type: string;
46
+ content: string;
47
+ agent_id?: string;
48
+ plan_id?: string;
49
+ task_id?: string;
50
+ created_at: string;
51
+ }>;
52
+ count: number;
53
+ latest_timestamp?: string;
54
+ };
55
+ export declare function executeEvents(input: EventsInput): EventsResult;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Events MCP tool - simple event tailing
3
+ */
4
+ import { getConnection } from '../../db/getConnection';
5
+ import { getRecentEvents } from '../../events/getRecentEvents';
6
+ import { getEventsSince } from '../../events/getEventsSince';
7
+ export const eventsTool = {
8
+ name: 'hivemind_events',
9
+ description: 'Get recent events from the hivemind. Use to see what other agents are doing.',
10
+ annotations: {
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ },
16
+ inputSchema: {
17
+ type: 'object',
18
+ properties: {
19
+ project: { type: 'string', description: 'Project name' },
20
+ limit: { type: 'number', description: 'Max events to return (default 20)' },
21
+ since: { type: 'string', description: 'ISO timestamp - get events after this time' },
22
+ type: { type: 'string', description: 'Filter by event type (e.g., "task:claim", "decision")' },
23
+ },
24
+ required: ['project'],
25
+ },
26
+ };
27
+ export function executeEvents(input) {
28
+ const db = getConnection(input.project);
29
+ const limit = input.limit ?? 20;
30
+ let events;
31
+ if (input.since) {
32
+ events = getEventsSince(db, input.since, limit);
33
+ }
34
+ else {
35
+ events = getRecentEvents(db, limit);
36
+ }
37
+ // Filter by type if specified
38
+ if (input.type) {
39
+ events = events.filter((e) => e.event_type === input.type);
40
+ }
41
+ // Format for output
42
+ const formatted = events.map((e) => ({
43
+ id: e.id,
44
+ type: e.event_type,
45
+ content: e.content ?? '',
46
+ agent_id: e.agent_id ?? undefined,
47
+ plan_id: e.plan_id ?? undefined,
48
+ task_id: e.task_id ?? undefined,
49
+ created_at: e.timestamp,
50
+ }));
51
+ return {
52
+ events: formatted,
53
+ count: formatted.length,
54
+ latest_timestamp: formatted[0]?.created_at,
55
+ };
56
+ }
@@ -0,0 +1,18 @@
1
+ export { setupTool, executeSetup } from './setup';
2
+ export type { SetupInput, SetupResult } from './setup';
3
+ export { registerTool, executeRegister } from './register';
4
+ export type { RegisterInput, RegisterResult } from './register';
5
+ export { emitEventTool, executeEmitEvent } from './emitEvent';
6
+ export type { EmitEventInput, EmitEventResult } from './emitEvent';
7
+ export { queryTool, executeQuery } from './query';
8
+ export type { QueryInput, QueryResult } from './query';
9
+ export { statusTool, executeStatus } from './status';
10
+ export type { StatusInput, StatusResult } from './status';
11
+ export { resetTool, executeReset } from './reset';
12
+ export type { ResetInput, ResetResult } from './reset';
13
+ export { claimTaskTool, executeClaimTask, startTaskTool, executeStartTask, completeTaskTool, executeCompleteTask, } from './tasks';
14
+ export type { ClaimTaskInput, StartTaskInput, CompleteTaskInput } from './tasks';
15
+ export { eventsTool, executeEvents } from './events';
16
+ export type { EventsInput, EventsResult } from './events';
17
+ export { worktreeCleanupTool, executeWorktreeCleanup } from './worktreeCleanup';
18
+ export type { WorktreeCleanupInput, WorktreeCleanupResult } from './worktreeCleanup';
@@ -0,0 +1,13 @@
1
+ // Tool definitions
2
+ export { setupTool, executeSetup } from './setup';
3
+ export { registerTool, executeRegister } from './register';
4
+ export { emitEventTool, executeEmitEvent } from './emitEvent';
5
+ export { queryTool, executeQuery } from './query';
6
+ export { statusTool, executeStatus } from './status';
7
+ export { resetTool, executeReset } from './reset';
8
+ // Task management
9
+ export { claimTaskTool, executeClaimTask, startTaskTool, executeStartTask, completeTaskTool, executeCompleteTask, } from './tasks';
10
+ // Events tailing
11
+ export { eventsTool, executeEvents } from './events';
12
+ // Worktree management
13
+ export { worktreeCleanupTool, executeWorktreeCleanup } from './worktreeCleanup';
@@ -0,0 +1,54 @@
1
+ import type { Event } from '../../events/types';
2
+ export declare const queryTool: {
3
+ name: string;
4
+ description: string;
5
+ annotations: {
6
+ readOnlyHint: boolean;
7
+ destructiveHint: boolean;
8
+ idempotentHint: boolean;
9
+ openWorldHint: boolean;
10
+ };
11
+ inputSchema: {
12
+ type: string;
13
+ properties: {
14
+ project: {
15
+ type: string;
16
+ description: string;
17
+ };
18
+ planId: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ agentId: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ branch: {
27
+ type: string;
28
+ description: string;
29
+ };
30
+ since: {
31
+ type: string;
32
+ description: string;
33
+ };
34
+ limit: {
35
+ type: string;
36
+ description: string;
37
+ };
38
+ };
39
+ required: string[];
40
+ };
41
+ };
42
+ export type QueryInput = {
43
+ project: string;
44
+ planId?: string;
45
+ agentId?: string;
46
+ branch?: string;
47
+ since?: string;
48
+ limit?: number;
49
+ };
50
+ export type QueryResult = {
51
+ events: Event[];
52
+ count: number;
53
+ };
54
+ export declare function executeQuery(input: QueryInput): QueryResult;
@@ -0,0 +1,70 @@
1
+ import { getConnection } from '../../db/getConnection';
2
+ import { getRecentEvents } from '../../events/getRecentEvents';
3
+ import { getEventsByPlan } from '../../events/getEventsByPlan';
4
+ import { getEventsByAgent } from '../../events/getEventsByAgent';
5
+ import { getEventsByBranch } from '../../events/getEventsByBranch';
6
+ import { getEventsSince } from '../../events/getEventsSince';
7
+ export const queryTool = {
8
+ name: 'hivemind_query',
9
+ description: 'Query events from the hivemind log.',
10
+ annotations: {
11
+ readOnlyHint: true,
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ },
16
+ inputSchema: {
17
+ type: 'object',
18
+ properties: {
19
+ project: {
20
+ type: 'string',
21
+ description: 'Project name',
22
+ },
23
+ planId: {
24
+ type: 'string',
25
+ description: 'Filter by plan ID',
26
+ },
27
+ agentId: {
28
+ type: 'string',
29
+ description: 'Filter by agent ID',
30
+ },
31
+ branch: {
32
+ type: 'string',
33
+ description: 'Filter by branch name',
34
+ },
35
+ since: {
36
+ type: 'string',
37
+ description: 'Get events since this timestamp (yyyy/mm/dd hh:mm:ss TZ)',
38
+ },
39
+ limit: {
40
+ type: 'number',
41
+ description: 'Max events to return (default 50)',
42
+ },
43
+ },
44
+ required: ['project'],
45
+ },
46
+ };
47
+ export function executeQuery(input) {
48
+ const db = getConnection(input.project);
49
+ const limit = input.limit ?? 50;
50
+ let events;
51
+ if (input.since) {
52
+ events = getEventsSince(db, input.since, limit);
53
+ }
54
+ else if (input.planId) {
55
+ events = getEventsByPlan(db, input.planId, limit);
56
+ }
57
+ else if (input.agentId) {
58
+ events = getEventsByAgent(db, input.agentId, limit);
59
+ }
60
+ else if (input.branch) {
61
+ events = getEventsByBranch(db, input.branch, limit);
62
+ }
63
+ else {
64
+ events = getRecentEvents(db, limit);
65
+ }
66
+ return {
67
+ events,
68
+ count: events.length,
69
+ };
70
+ }
@@ -0,0 +1,47 @@
1
+ export declare const registerTool: {
2
+ name: string;
3
+ description: string;
4
+ annotations: {
5
+ readOnlyHint: boolean;
6
+ destructiveHint: boolean;
7
+ idempotentHint: boolean;
8
+ openWorldHint: boolean;
9
+ };
10
+ inputSchema: {
11
+ type: string;
12
+ properties: {
13
+ project: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ label: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ sessionId: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ contextSummary: {
26
+ type: string;
27
+ description: string;
28
+ };
29
+ };
30
+ required: string[];
31
+ };
32
+ };
33
+ export type RegisterInput = {
34
+ project: string;
35
+ label?: string;
36
+ sessionId?: string;
37
+ pid?: number;
38
+ contextSummary?: string;
39
+ };
40
+ export type RegisterResult = {
41
+ agentId: string;
42
+ project: string;
43
+ worktreeId?: string;
44
+ branch?: string;
45
+ message: string;
46
+ };
47
+ export declare function executeRegister(input: RegisterInput): RegisterResult;
@@ -0,0 +1,79 @@
1
+ import { getConnection } from '../../db/getConnection';
2
+ import { registerAgent } from '../../agents/registerAgent';
3
+ import { emit } from '../../events/emit';
4
+ import { syncWorktreesFromGit } from '../../worktrees/syncWorktreesFromGit';
5
+ import { getWorktreeByPath } from '../../worktrees/getWorktreeByPath';
6
+ import { getCurrentWorktree } from '../../git/getCurrentWorktree';
7
+ import { getBranch } from '../../git/getBranch';
8
+ export const registerTool = {
9
+ name: 'hivemind_register',
10
+ description: 'Register this Claude agent with the hivemind. Call this at the start of a session.',
11
+ annotations: {
12
+ readOnlyHint: false,
13
+ destructiveHint: false,
14
+ idempotentHint: false,
15
+ openWorldHint: false,
16
+ },
17
+ inputSchema: {
18
+ type: 'object',
19
+ properties: {
20
+ project: {
21
+ type: 'string',
22
+ description: 'Project name (required)',
23
+ },
24
+ label: {
25
+ type: 'string',
26
+ description: 'Optional label for this agent (e.g., "alice", "backend")',
27
+ },
28
+ sessionId: {
29
+ type: 'string',
30
+ description: 'Claude session ID for --resume support',
31
+ },
32
+ contextSummary: {
33
+ type: 'string',
34
+ description: 'Brief description of what this agent knows/is working on',
35
+ },
36
+ },
37
+ required: ['project'],
38
+ },
39
+ };
40
+ export function executeRegister(input) {
41
+ const db = getConnection(input.project);
42
+ // Sync worktrees from git
43
+ syncWorktreesFromGit(db);
44
+ // Find current worktree
45
+ const gitWorktree = getCurrentWorktree();
46
+ let worktreeId;
47
+ if (gitWorktree) {
48
+ const dbWorktree = getWorktreeByPath(db, gitWorktree.path);
49
+ worktreeId = dbWorktree?.id;
50
+ }
51
+ const branch = getBranch() ?? undefined;
52
+ // Register the agent
53
+ const agent = registerAgent(db, {
54
+ label: input.label,
55
+ pid: input.pid,
56
+ session_id: input.sessionId,
57
+ worktree_id: worktreeId,
58
+ context_summary: input.contextSummary,
59
+ });
60
+ // Emit registration event
61
+ emit(db, {
62
+ agent_id: agent.id,
63
+ worktree_id: worktreeId,
64
+ branch,
65
+ type: 'agent:register',
66
+ content: input.contextSummary,
67
+ metadata: {
68
+ sessionId: input.sessionId,
69
+ label: input.label,
70
+ },
71
+ });
72
+ return {
73
+ agentId: agent.id,
74
+ project: input.project,
75
+ worktreeId,
76
+ branch,
77
+ message: `Agent ${agent.id} registered to hivemind:${input.project}${branch ? ` on branch ${branch}` : ''}`,
78
+ };
79
+ }
@@ -0,0 +1,38 @@
1
+ export declare const resetTool: {
2
+ name: string;
3
+ description: string;
4
+ annotations: {
5
+ readOnlyHint: boolean;
6
+ destructiveHint: boolean;
7
+ idempotentHint: boolean;
8
+ openWorldHint: boolean;
9
+ };
10
+ inputSchema: {
11
+ type: string;
12
+ properties: {
13
+ project: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ confirm: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ };
22
+ required: string[];
23
+ };
24
+ };
25
+ export type ResetInput = {
26
+ project: string;
27
+ confirm: boolean;
28
+ };
29
+ export type ResetResult = {
30
+ success: boolean;
31
+ message: string;
32
+ deleted?: string[];
33
+ created?: string;
34
+ };
35
+ /**
36
+ * Execute reset - deletes database and recreates with fresh schema
37
+ */
38
+ export declare function executeReset(input: ResetInput): ResetResult;
@@ -0,0 +1,56 @@
1
+ import { existsSync } from 'fs';
2
+ import { getProjectPaths } from '../../db/getProjectPaths';
3
+ import { resetDb } from '../../db/resetDb';
4
+ import { formatDatetime } from '../../datetime/formatDatetime';
5
+ export const resetTool = {
6
+ name: 'hivemind_reset',
7
+ description: 'Reset the hivemind database. Deletes all data and recreates with fresh schema. Use for schema migrations.',
8
+ annotations: {
9
+ readOnlyHint: false,
10
+ destructiveHint: true,
11
+ idempotentHint: false,
12
+ openWorldHint: false,
13
+ },
14
+ inputSchema: {
15
+ type: 'object',
16
+ properties: {
17
+ project: {
18
+ type: 'string',
19
+ description: 'Project name (required)',
20
+ },
21
+ confirm: {
22
+ type: 'boolean',
23
+ description: 'Must be true to confirm reset. This is destructive!',
24
+ },
25
+ },
26
+ required: ['project', 'confirm'],
27
+ },
28
+ };
29
+ /**
30
+ * Execute reset - deletes database and recreates with fresh schema
31
+ */
32
+ export function executeReset(input) {
33
+ // Safety check
34
+ if (!input.confirm) {
35
+ return {
36
+ success: false,
37
+ message: 'Reset not confirmed. Set confirm: true to proceed. WARNING: This deletes all data!',
38
+ };
39
+ }
40
+ const paths = getProjectPaths(input.project);
41
+ // Check if database exists
42
+ if (!existsSync(paths.dbPath)) {
43
+ return {
44
+ success: false,
45
+ message: `No database found for project "${input.project}" at ${paths.dbPath}`,
46
+ };
47
+ }
48
+ // Perform reset
49
+ const result = resetDb(input.project);
50
+ return {
51
+ success: true,
52
+ message: `hivemind reset: ${input.project}\ndeleted: ${result.deleted.length} files\ncreated: ${result.created}\ntimestamp: ${formatDatetime()}`,
53
+ deleted: result.deleted,
54
+ created: result.created,
55
+ };
56
+ }
@@ -0,0 +1,42 @@
1
+ export declare const setupTool: {
2
+ name: string;
3
+ description: string;
4
+ annotations: {
5
+ readOnlyHint: boolean;
6
+ destructiveHint: boolean;
7
+ idempotentHint: boolean;
8
+ openWorldHint: boolean;
9
+ };
10
+ inputSchema: {
11
+ type: string;
12
+ properties: {
13
+ project: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ useGit: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ };
22
+ };
23
+ };
24
+ export type SetupInput = {
25
+ project?: string;
26
+ useGit?: boolean;
27
+ };
28
+ export type SetupResult = {
29
+ needsInput: boolean;
30
+ gitInfo?: {
31
+ repoName: string | null;
32
+ branch: string | null;
33
+ root: string | null;
34
+ };
35
+ message?: string;
36
+ project?: string;
37
+ dbPath?: string;
38
+ };
39
+ /**
40
+ * Execute setup - may return prompt for user input
41
+ */
42
+ export declare function executeSetup(input: SetupInput): SetupResult;