ai-agent-claude-swarm 1.0.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 (276) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/.claude-plugin/plugin.json +9 -0
  3. package/README.md +545 -0
  4. package/dist/agents/agent.d.ts +27 -0
  5. package/dist/agents/agent.d.ts.map +1 -0
  6. package/dist/agents/agent.js +106 -0
  7. package/dist/agents/agent.js.map +1 -0
  8. package/dist/agents/index.d.ts +4 -0
  9. package/dist/agents/index.d.ts.map +1 -0
  10. package/dist/agents/index.js +4 -0
  11. package/dist/agents/index.js.map +1 -0
  12. package/dist/agents/model-router.d.ts +9 -0
  13. package/dist/agents/model-router.d.ts.map +1 -0
  14. package/dist/agents/model-router.js +102 -0
  15. package/dist/agents/model-router.js.map +1 -0
  16. package/dist/agents/spawner.d.ts +25 -0
  17. package/dist/agents/spawner.d.ts.map +1 -0
  18. package/dist/agents/spawner.js +151 -0
  19. package/dist/agents/spawner.js.map +1 -0
  20. package/dist/aidefence/index.d.ts +87 -0
  21. package/dist/aidefence/index.d.ts.map +1 -0
  22. package/dist/aidefence/index.js +167 -0
  23. package/dist/aidefence/index.js.map +1 -0
  24. package/dist/aidefence/threat-detection.d.ts +70 -0
  25. package/dist/aidefence/threat-detection.d.ts.map +1 -0
  26. package/dist/aidefence/threat-detection.js +405 -0
  27. package/dist/aidefence/threat-detection.js.map +1 -0
  28. package/dist/aidefence/threat-learning.d.ts +97 -0
  29. package/dist/aidefence/threat-learning.d.ts.map +1 -0
  30. package/dist/aidefence/threat-learning.js +255 -0
  31. package/dist/aidefence/threat-learning.js.map +1 -0
  32. package/dist/aidefence/types.d.ts +162 -0
  33. package/dist/aidefence/types.d.ts.map +1 -0
  34. package/dist/aidefence/types.js +21 -0
  35. package/dist/aidefence/types.js.map +1 -0
  36. package/dist/claims/claim-service.d.ts +52 -0
  37. package/dist/claims/claim-service.d.ts.map +1 -0
  38. package/dist/claims/claim-service.js +352 -0
  39. package/dist/claims/claim-service.js.map +1 -0
  40. package/dist/claims/events.d.ts +197 -0
  41. package/dist/claims/events.d.ts.map +1 -0
  42. package/dist/claims/events.js +125 -0
  43. package/dist/claims/events.js.map +1 -0
  44. package/dist/claims/index.d.ts +20 -0
  45. package/dist/claims/index.d.ts.map +1 -0
  46. package/dist/claims/index.js +14 -0
  47. package/dist/claims/index.js.map +1 -0
  48. package/dist/claims/load-balancer.d.ts +178 -0
  49. package/dist/claims/load-balancer.d.ts.map +1 -0
  50. package/dist/claims/load-balancer.js +299 -0
  51. package/dist/claims/load-balancer.js.map +1 -0
  52. package/dist/claims/rules.d.ts +89 -0
  53. package/dist/claims/rules.d.ts.map +1 -0
  54. package/dist/claims/rules.js +269 -0
  55. package/dist/claims/rules.js.map +1 -0
  56. package/dist/claims/types.d.ts +301 -0
  57. package/dist/claims/types.d.ts.map +1 -0
  58. package/dist/claims/types.js +91 -0
  59. package/dist/claims/types.js.map +1 -0
  60. package/dist/claims/work-stealing.d.ts +60 -0
  61. package/dist/claims/work-stealing.d.ts.map +1 -0
  62. package/dist/claims/work-stealing.js +426 -0
  63. package/dist/claims/work-stealing.js.map +1 -0
  64. package/dist/cli/commands/agent.d.ts +2 -0
  65. package/dist/cli/commands/agent.d.ts.map +1 -0
  66. package/dist/cli/commands/agent.js +126 -0
  67. package/dist/cli/commands/agent.js.map +1 -0
  68. package/dist/cli/commands/config.d.ts +2 -0
  69. package/dist/cli/commands/config.d.ts.map +1 -0
  70. package/dist/cli/commands/config.js +101 -0
  71. package/dist/cli/commands/config.js.map +1 -0
  72. package/dist/cli/commands/doctor.d.ts +2 -0
  73. package/dist/cli/commands/doctor.d.ts.map +1 -0
  74. package/dist/cli/commands/doctor.js +113 -0
  75. package/dist/cli/commands/doctor.js.map +1 -0
  76. package/dist/cli/commands/hooks.d.ts +10 -0
  77. package/dist/cli/commands/hooks.d.ts.map +1 -0
  78. package/dist/cli/commands/hooks.js +117 -0
  79. package/dist/cli/commands/hooks.js.map +1 -0
  80. package/dist/cli/commands/init.d.ts +2 -0
  81. package/dist/cli/commands/init.d.ts.map +1 -0
  82. package/dist/cli/commands/init.js +159 -0
  83. package/dist/cli/commands/init.js.map +1 -0
  84. package/dist/cli/commands/mcp.d.ts +2 -0
  85. package/dist/cli/commands/mcp.d.ts.map +1 -0
  86. package/dist/cli/commands/mcp.js +28 -0
  87. package/dist/cli/commands/mcp.js.map +1 -0
  88. package/dist/cli/commands/memory.d.ts +2 -0
  89. package/dist/cli/commands/memory.d.ts.map +1 -0
  90. package/dist/cli/commands/memory.js +168 -0
  91. package/dist/cli/commands/memory.js.map +1 -0
  92. package/dist/cli/commands/session.d.ts +2 -0
  93. package/dist/cli/commands/session.d.ts.map +1 -0
  94. package/dist/cli/commands/session.js +98 -0
  95. package/dist/cli/commands/session.js.map +1 -0
  96. package/dist/cli/commands/status.d.ts +2 -0
  97. package/dist/cli/commands/status.d.ts.map +1 -0
  98. package/dist/cli/commands/status.js +30 -0
  99. package/dist/cli/commands/status.js.map +1 -0
  100. package/dist/cli/commands/swarm.d.ts +2 -0
  101. package/dist/cli/commands/swarm.d.ts.map +1 -0
  102. package/dist/cli/commands/swarm.js +117 -0
  103. package/dist/cli/commands/swarm.js.map +1 -0
  104. package/dist/cli/commands/task.d.ts +2 -0
  105. package/dist/cli/commands/task.d.ts.map +1 -0
  106. package/dist/cli/commands/task.js +106 -0
  107. package/dist/cli/commands/task.js.map +1 -0
  108. package/dist/cli/index.d.ts +3 -0
  109. package/dist/cli/index.d.ts.map +1 -0
  110. package/dist/cli/index.js +76 -0
  111. package/dist/cli/index.js.map +1 -0
  112. package/dist/hooks/built-in.d.ts +7 -0
  113. package/dist/hooks/built-in.d.ts.map +1 -0
  114. package/dist/hooks/built-in.js +460 -0
  115. package/dist/hooks/built-in.js.map +1 -0
  116. package/dist/hooks/daemons.d.ts +72 -0
  117. package/dist/hooks/daemons.d.ts.map +1 -0
  118. package/dist/hooks/daemons.js +202 -0
  119. package/dist/hooks/daemons.js.map +1 -0
  120. package/dist/hooks/executor.d.ts +37 -0
  121. package/dist/hooks/executor.d.ts.map +1 -0
  122. package/dist/hooks/executor.js +175 -0
  123. package/dist/hooks/executor.js.map +1 -0
  124. package/dist/hooks/index.d.ts +6 -0
  125. package/dist/hooks/index.d.ts.map +1 -0
  126. package/dist/hooks/index.js +6 -0
  127. package/dist/hooks/index.js.map +1 -0
  128. package/dist/hooks/registry.d.ts +85 -0
  129. package/dist/hooks/registry.d.ts.map +1 -0
  130. package/dist/hooks/registry.js +229 -0
  131. package/dist/hooks/registry.js.map +1 -0
  132. package/dist/hooks/workers.d.ts +88 -0
  133. package/dist/hooks/workers.d.ts.map +1 -0
  134. package/dist/hooks/workers.js +287 -0
  135. package/dist/hooks/workers.js.map +1 -0
  136. package/dist/index.d.ts +52 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +78 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/mcp/index.d.ts +4 -0
  141. package/dist/mcp/index.d.ts.map +1 -0
  142. package/dist/mcp/index.js +3 -0
  143. package/dist/mcp/index.js.map +1 -0
  144. package/dist/mcp/server.d.ts +14 -0
  145. package/dist/mcp/server.d.ts.map +1 -0
  146. package/dist/mcp/server.js +102 -0
  147. package/dist/mcp/server.js.map +1 -0
  148. package/dist/mcp/tools-coordination.d.ts +11 -0
  149. package/dist/mcp/tools-coordination.d.ts.map +1 -0
  150. package/dist/mcp/tools-coordination.js +382 -0
  151. package/dist/mcp/tools-coordination.js.map +1 -0
  152. package/dist/mcp/tools-extended.d.ts +13 -0
  153. package/dist/mcp/tools-extended.d.ts.map +1 -0
  154. package/dist/mcp/tools-extended.js +22 -0
  155. package/dist/mcp/tools-extended.js.map +1 -0
  156. package/dist/mcp/tools-security.d.ts +10 -0
  157. package/dist/mcp/tools-security.d.ts.map +1 -0
  158. package/dist/mcp/tools-security.js +321 -0
  159. package/dist/mcp/tools-security.js.map +1 -0
  160. package/dist/mcp/tools.d.ts +11 -0
  161. package/dist/mcp/tools.d.ts.map +1 -0
  162. package/dist/mcp/tools.js +332 -0
  163. package/dist/mcp/tools.js.map +1 -0
  164. package/dist/memory/index.d.ts +5 -0
  165. package/dist/memory/index.d.ts.map +1 -0
  166. package/dist/memory/index.js +7 -0
  167. package/dist/memory/index.js.map +1 -0
  168. package/dist/memory/json-store.d.ts +22 -0
  169. package/dist/memory/json-store.d.ts.map +1 -0
  170. package/dist/memory/json-store.js +234 -0
  171. package/dist/memory/json-store.js.map +1 -0
  172. package/dist/memory/namespaces.d.ts +8 -0
  173. package/dist/memory/namespaces.d.ts.map +1 -0
  174. package/dist/memory/namespaces.js +52 -0
  175. package/dist/memory/namespaces.js.map +1 -0
  176. package/dist/security/credential-generator.d.ts +176 -0
  177. package/dist/security/credential-generator.d.ts.map +1 -0
  178. package/dist/security/credential-generator.js +262 -0
  179. package/dist/security/credential-generator.js.map +1 -0
  180. package/dist/security/index.d.ts +101 -0
  181. package/dist/security/index.d.ts.map +1 -0
  182. package/dist/security/index.js +127 -0
  183. package/dist/security/index.js.map +1 -0
  184. package/dist/security/input-validator.d.ts +347 -0
  185. package/dist/security/input-validator.d.ts.map +1 -0
  186. package/dist/security/input-validator.js +399 -0
  187. package/dist/security/input-validator.js.map +1 -0
  188. package/dist/security/password-hasher.d.ts +122 -0
  189. package/dist/security/password-hasher.d.ts.map +1 -0
  190. package/dist/security/password-hasher.js +169 -0
  191. package/dist/security/password-hasher.js.map +1 -0
  192. package/dist/security/path-validator.d.ts +118 -0
  193. package/dist/security/path-validator.d.ts.map +1 -0
  194. package/dist/security/path-validator.js +410 -0
  195. package/dist/security/path-validator.js.map +1 -0
  196. package/dist/security/safe-executor.d.ts +142 -0
  197. package/dist/security/safe-executor.d.ts.map +1 -0
  198. package/dist/security/safe-executor.js +358 -0
  199. package/dist/security/safe-executor.js.map +1 -0
  200. package/dist/security/token-generator.d.ts +224 -0
  201. package/dist/security/token-generator.d.ts.map +1 -0
  202. package/dist/security/token-generator.js +351 -0
  203. package/dist/security/token-generator.js.map +1 -0
  204. package/dist/swarm/agent-pool.d.ts +52 -0
  205. package/dist/swarm/agent-pool.d.ts.map +1 -0
  206. package/dist/swarm/agent-pool.js +347 -0
  207. package/dist/swarm/agent-pool.js.map +1 -0
  208. package/dist/swarm/consensus/byzantine.d.ts +63 -0
  209. package/dist/swarm/consensus/byzantine.d.ts.map +1 -0
  210. package/dist/swarm/consensus/byzantine.js +307 -0
  211. package/dist/swarm/consensus/byzantine.js.map +1 -0
  212. package/dist/swarm/consensus/gossip.d.ts +69 -0
  213. package/dist/swarm/consensus/gossip.d.ts.map +1 -0
  214. package/dist/swarm/consensus/gossip.js +356 -0
  215. package/dist/swarm/consensus/gossip.js.map +1 -0
  216. package/dist/swarm/consensus/index.d.ts +49 -0
  217. package/dist/swarm/consensus/index.d.ts.map +1 -0
  218. package/dist/swarm/consensus/index.js +192 -0
  219. package/dist/swarm/consensus/index.js.map +1 -0
  220. package/dist/swarm/consensus/raft.d.ts +62 -0
  221. package/dist/swarm/consensus/raft.d.ts.map +1 -0
  222. package/dist/swarm/consensus/raft.js +307 -0
  223. package/dist/swarm/consensus/raft.js.map +1 -0
  224. package/dist/swarm/coordinator.d.ts +47 -0
  225. package/dist/swarm/coordinator.d.ts.map +1 -0
  226. package/dist/swarm/coordinator.js +304 -0
  227. package/dist/swarm/coordinator.js.map +1 -0
  228. package/dist/swarm/index.d.ts +11 -0
  229. package/dist/swarm/index.d.ts.map +1 -0
  230. package/dist/swarm/index.js +11 -0
  231. package/dist/swarm/index.js.map +1 -0
  232. package/dist/swarm/message-bus.d.ts +47 -0
  233. package/dist/swarm/message-bus.d.ts.map +1 -0
  234. package/dist/swarm/message-bus.js +464 -0
  235. package/dist/swarm/message-bus.js.map +1 -0
  236. package/dist/swarm/task-queue.d.ts +30 -0
  237. package/dist/swarm/task-queue.d.ts.map +1 -0
  238. package/dist/swarm/task-queue.js +172 -0
  239. package/dist/swarm/task-queue.js.map +1 -0
  240. package/dist/swarm/topology.d.ts +27 -0
  241. package/dist/swarm/topology.d.ts.map +1 -0
  242. package/dist/swarm/topology.js +146 -0
  243. package/dist/swarm/topology.js.map +1 -0
  244. package/dist/types/agent.d.ts +36 -0
  245. package/dist/types/agent.d.ts.map +1 -0
  246. package/dist/types/agent.js +157 -0
  247. package/dist/types/agent.js.map +1 -0
  248. package/dist/types/hooks.d.ts +261 -0
  249. package/dist/types/hooks.d.ts.map +1 -0
  250. package/dist/types/hooks.js +57 -0
  251. package/dist/types/hooks.js.map +1 -0
  252. package/dist/types/index.d.ts +6 -0
  253. package/dist/types/index.d.ts.map +1 -0
  254. package/dist/types/index.js +6 -0
  255. package/dist/types/index.js.map +1 -0
  256. package/dist/types/memory.d.ts +48 -0
  257. package/dist/types/memory.d.ts.map +1 -0
  258. package/dist/types/memory.js +9 -0
  259. package/dist/types/memory.js.map +1 -0
  260. package/dist/types/swarm.d.ts +197 -0
  261. package/dist/types/swarm.d.ts.map +1 -0
  262. package/dist/types/swarm.js +22 -0
  263. package/dist/types/swarm.js.map +1 -0
  264. package/dist/types/task.d.ts +35 -0
  265. package/dist/types/task.d.ts.map +1 -0
  266. package/dist/types/task.js +16 -0
  267. package/dist/types/task.js.map +1 -0
  268. package/dist/utils/id.d.ts +4 -0
  269. package/dist/utils/id.d.ts.map +1 -0
  270. package/dist/utils/id.js +12 -0
  271. package/dist/utils/id.js.map +1 -0
  272. package/dist/utils/index.d.ts +2 -0
  273. package/dist/utils/index.d.ts.map +1 -0
  274. package/dist/utils/index.js +2 -0
  275. package/dist/utils/index.js.map +1 -0
  276. package/package.json +43 -0
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
3
+ "name": "ai-agent-claude-swarm",
4
+ "description": "Multi-agent swarm orchestration plugin for Claude Code with consensus algorithms, AI defence, security validation, work coordination, and cross-session JSON memory",
5
+ "owner": {
6
+ "name": "Locotine"
7
+ },
8
+ "plugins": [
9
+ {
10
+ "name": "ai-agent-claude-swarm",
11
+ "version": "1.0.0",
12
+ "description": "38 MCP tools, 25 agent types, Byzantine/Raft/Gossip consensus, AI threat detection, security validation, work claiming, cross-session memory — all running locally with zero external dependencies",
13
+ "source": "./"
14
+ }
15
+ ],
16
+ "version": "1.0.0"
17
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "ai-agent-claude-swarm",
3
+ "version": "1.0.0",
4
+ "description": "Multi-agent swarm orchestration plugin for Claude Code — 38 MCP tools, 25 agent types, consensus algorithms, AI defence, cross-session memory",
5
+ "author": { "name": "Locotine" },
6
+ "repository": "https://gitlab.com/locotine/ai-agent-claude-swarm",
7
+ "license": "MIT",
8
+ "keywords": ["swarm", "multi-agent", "coordination", "consensus", "security", "ai-defence"]
9
+ }
package/README.md ADDED
@@ -0,0 +1,545 @@
1
+ # AI Agent Claude Swarm
2
+
3
+ Multi-agent swarm orchestration plugin for Claude Code with consensus algorithms, AI threat detection, security validation, work coordination, and cross-session JSON memory.
4
+
5
+ **38 MCP tools | 25 agent types | 19 lifecycle hooks | 6 background workers | 0 external dependencies**
6
+
7
+ ## Features
8
+
9
+ | Feature | Description |
10
+ |---------|-------------|
11
+ | **Multi-Agent Swarm** | Hierarchical/mesh topologies, auto-scaling agent pool, 3-tier model routing (haiku/sonnet/opus) |
12
+ | **Consensus Algorithms** | Byzantine PBFT (3-phase), Raft (leader election + log replication), Gossip (epidemic protocol) |
13
+ | **AI Threat Detection** | 50+ injection patterns, PII detection (SSN, credit cards, emails), confidence-weighted scoring |
14
+ | **Security Validation** | Zod-based input validation, path traversal prevention, command injection prevention via `execFile` |
15
+ | **Work Coordination** | Claims with handoffs, work stealing with contest windows, load balancing with utilization tracking |
16
+ | **Lifecycle Hooks** | 19 built-in hooks, 5 priority levels, 6 background workers, 2 daemons (metrics + swarm monitor) |
17
+ | **Cross-Session Memory** | JSON file storage with atomic writes (tmp+rename), LRU eviction, in-memory cache, namespaced |
18
+ | **O(1) Message Bus** | Circular deque with ACK tracking, retry logic, topic subscriptions, broadcast/unicast |
19
+ | **Claude Code Plugin** | Auto-registers MCP server + safety hooks via `npx ai-agent-claude-swarm init` |
20
+
21
+ ## Quick Start
22
+
23
+ ### Prerequisites
24
+
25
+ - **Node.js 20+**
26
+ - **Claude Code** (CLI)
27
+
28
+ ### Install
29
+
30
+ ```bash
31
+ npm install -g ai-agent-claude-swarm
32
+ ```
33
+
34
+ Or use directly with npx:
35
+
36
+ ```bash
37
+ npx ai-agent-claude-swarm init
38
+ ```
39
+
40
+ ### Initialize Plugin
41
+
42
+ Run inside your project directory:
43
+
44
+ ```bash
45
+ npx ai-agent-claude-swarm init
46
+ ```
47
+
48
+ This will:
49
+ 1. Create `.ai-swarm/` directory with config and memory storage
50
+ 2. Register the MCP server in `.claude/settings.json`
51
+ 3. Add safety hooks (blocks `git push --force` and `rm -rf`)
52
+ 4. Add session-start hook for automatic initialization
53
+ 5. Update `.gitignore` to exclude `.ai-swarm/` and `.env`
54
+
55
+ ### Restart Claude Code
56
+
57
+ After init, restart Claude Code to activate the plugin. You'll have access to all 38 MCP tools.
58
+
59
+ ## MCP Tools (38 Total)
60
+
61
+ ### Agent Management (5 tools)
62
+
63
+ | Tool | Description |
64
+ |------|-------------|
65
+ | `agent_spawn` | Create a new agent with type, name, and configuration |
66
+ | `agent_list` | List all active agents with status |
67
+ | `agent_status` | Get detailed status of a specific agent |
68
+ | `agent_stop` | Gracefully stop an agent |
69
+ | `agent_types` | List all 25 available agent types |
70
+
71
+ ### Swarm Orchestration (4 tools)
72
+
73
+ | Tool | Description |
74
+ |------|-------------|
75
+ | `swarm_init` | Initialize swarm with topology (hierarchical/mesh) and strategy |
76
+ | `swarm_execute` | Execute a task across the swarm |
77
+ | `swarm_status` | Get swarm health, agent count, task progress |
78
+ | `swarm_decompose` | Break a complex task into subtasks for parallel execution |
79
+
80
+ ### Memory (5 tools)
81
+
82
+ | Tool | Description |
83
+ |------|-------------|
84
+ | `memory_store` | Store key-value data in a namespace |
85
+ | `memory_search` | Search across memory with pattern matching |
86
+ | `memory_get` | Retrieve a specific memory entry |
87
+ | `memory_stats` | Get memory usage statistics |
88
+ | `memory_clear` | Clear a namespace or all memory |
89
+
90
+ ### Security (5 tools)
91
+
92
+ | Tool | Description |
93
+ |------|-------------|
94
+ | `security_validate_input` | Validate input against Zod schemas (string, email, URL, path, command, JSON) |
95
+ | `security_validate_path` | Check for path traversal attacks |
96
+ | `security_check_command` | Validate commands for injection patterns |
97
+ | `security_generate_token` | Generate HMAC-SHA256 signed tokens |
98
+ | `security_audit` | Run a full security audit of the project |
99
+
100
+ ### AI Defence (4 tools)
101
+
102
+ | Tool | Description |
103
+ |------|-------------|
104
+ | `aidefence_detect` | Full threat analysis with 50+ patterns |
105
+ | `aidefence_quick_scan` | Fast scan for common injection patterns |
106
+ | `aidefence_check_pii` | Detect PII (SSN, credit cards, emails, phone numbers) |
107
+ | `aidefence_consensus` | Multi-engine consensus threat detection |
108
+
109
+ ### Claims & Work Coordination (5 tools)
110
+
111
+ | Tool | Description |
112
+ |------|-------------|
113
+ | `claims_claim` | Claim a work item for an agent |
114
+ | `claims_release` | Release a claimed work item |
115
+ | `claims_handoff` | Hand off work from one agent to another |
116
+ | `claims_list` | List all active claims |
117
+ | `claims_status` | Get claim status and history |
118
+
119
+ ### Consensus (4 tools)
120
+
121
+ | Tool | Description |
122
+ |------|-------------|
123
+ | `consensus_create` | Create a consensus group with algorithm selection |
124
+ | `consensus_propose` | Submit a proposal for group voting |
125
+ | `consensus_status` | Get consensus group state |
126
+ | `consensus_select_algorithm` | Auto-select optimal algorithm based on requirements |
127
+
128
+ ### Hooks (3 tools)
129
+
130
+ | Tool | Description |
131
+ |------|-------------|
132
+ | `hooks_list` | List all registered hooks |
133
+ | `hooks_stats` | Get hook execution statistics |
134
+ | `hooks_workers` | List background worker status |
135
+
136
+ ### Task & Session (3 tools)
137
+
138
+ | Tool | Description |
139
+ |------|-------------|
140
+ | `task_create` | Create a new task |
141
+ | `task_list` | List tasks with filtering |
142
+ | `session_status` | Get current session information |
143
+
144
+ ## Agent Types (25)
145
+
146
+ | Type | Tier | Description |
147
+ |------|------|-------------|
148
+ | `coder` | Sonnet | Code writing, implementation, debugging |
149
+ | `reviewer` | Sonnet | Code review, quality analysis |
150
+ | `tester` | Sonnet | Test writing, coverage analysis |
151
+ | `researcher` | Sonnet | Information gathering, analysis |
152
+ | `architect` | Opus | System design, architecture decisions |
153
+ | `debugger` | Sonnet | Bug investigation, root cause analysis |
154
+ | `optimizer` | Sonnet | Performance optimization |
155
+ | `documenter` | Haiku | Documentation generation |
156
+ | `devops` | Sonnet | CI/CD, deployment, infrastructure |
157
+ | `security` | Opus | Security auditing, vulnerability analysis |
158
+ | `data-analyst` | Sonnet | Data analysis, SQL, visualization |
159
+ | `ml-engineer` | Opus | Machine learning, model training |
160
+ | `frontend` | Sonnet | UI/UX implementation |
161
+ | `backend` | Sonnet | API, server-side development |
162
+ | `mobile` | Sonnet | Mobile app development |
163
+ | `qa` | Sonnet | Quality assurance, test planning |
164
+ | `technical-writer` | Haiku | Technical documentation |
165
+ | `project-manager` | Sonnet | Project coordination, planning |
166
+ | `mentor` | Opus | Code teaching, best practices |
167
+ | `refactorer` | Sonnet | Code refactoring, modernization |
168
+ | `integrator` | Sonnet | System integration, API connections |
169
+ | `migrator` | Sonnet | Database/code migration |
170
+ | `monitor` | Haiku | System monitoring, alerting |
171
+ | `planner` | Opus | Strategic planning, roadmapping |
172
+ | `general` | Sonnet | General-purpose assistant |
173
+
174
+ ### 3-Tier Model Routing
175
+
176
+ Agents are automatically routed to the optimal model tier:
177
+
178
+ | Tier | Model | Use Case |
179
+ |------|-------|----------|
180
+ | **Fast** | Haiku | Documentation, monitoring, simple tasks |
181
+ | **Balanced** | Sonnet | Implementation, testing, most development work |
182
+ | **Deep** | Opus | Architecture, security, ML, strategic planning |
183
+
184
+ ## Consensus Algorithms
185
+
186
+ ### Byzantine PBFT
187
+
188
+ Tolerates up to `f < n/3` faulty or malicious nodes. Three-phase protocol:
189
+
190
+ 1. **Pre-prepare**: Leader broadcasts proposal
191
+ 2. **Prepare**: Nodes validate and broadcast prepare messages
192
+ 3. **Commit**: Nodes commit after receiving 2f+1 prepare messages
193
+
194
+ Best for: High-security decisions, untrusted environments.
195
+
196
+ ### Raft
197
+
198
+ Leader-based consensus tolerating `f < n/2` failures:
199
+
200
+ 1. **Leader Election**: Candidates request votes with randomized timeouts
201
+ 2. **Log Replication**: Leader replicates entries to followers
202
+ 3. **Commitment**: Entry committed after majority acknowledgment
203
+
204
+ Best for: General coordination, agent task assignment.
205
+
206
+ ### Gossip
207
+
208
+ Epidemic protocol for eventual consistency:
209
+
210
+ 1. **Infection**: Nodes spread updates to random peers
211
+ 2. **Convergence**: All nodes eventually receive all updates
212
+ 3. **Crumbling**: Old data is eventually garbage collected
213
+
214
+ Best for: Large swarms, status propagation, soft state.
215
+
216
+ ### Algorithm Selection
217
+
218
+ Use `consensus_select_algorithm` to auto-select based on your requirements:
219
+
220
+ ```
221
+ Fault tolerance priority → Byzantine PBFT
222
+ Performance priority → Raft
223
+ Scalability priority → Gossip
224
+ ```
225
+
226
+ ## CLI Commands
227
+
228
+ ```bash
229
+ npx ai-agent-claude-swarm <command>
230
+ ```
231
+
232
+ | Command | Description |
233
+ |---------|-------------|
234
+ | `init` | Initialize plugin in current project |
235
+ | `agent spawn` | Spawn a new agent |
236
+ | `agent list` | List active agents |
237
+ | `agent status <id>` | Get agent status |
238
+ | `agent stop <id>` | Stop an agent |
239
+ | `swarm start` | Start swarm orchestration |
240
+ | `swarm status` | Get swarm status |
241
+ | `memory store` | Store a memory entry |
242
+ | `memory search` | Search memory |
243
+ | `task create` | Create a task |
244
+ | `task list` | List tasks |
245
+ | `session status` | Current session info |
246
+ | `config show` | Show configuration |
247
+ | `hooks list` | List registered hooks |
248
+ | `hooks stats` | Hook execution statistics |
249
+ | `hooks session-start` | Trigger session start hooks |
250
+ | `doctor` | Run health diagnostics |
251
+ | `mcp start` | Start MCP server (used by Claude Code) |
252
+ | `status` | Overall system status |
253
+
254
+ ## Programmatic Usage
255
+
256
+ ### Plugin Entry Point
257
+
258
+ ```typescript
259
+ import { AiSwarmPlugin, createPlugin } from 'ai-agent-claude-swarm';
260
+
261
+ const plugin = createPlugin();
262
+ await plugin.initialize();
263
+ ```
264
+
265
+ ### Security Module
266
+
267
+ ```typescript
268
+ import {
269
+ createSecurityModule,
270
+ validateInput,
271
+ validatePath,
272
+ SafeExecutor,
273
+ } from 'ai-agent-claude-swarm';
274
+
275
+ // Create full security module
276
+ const security = createSecurityModule({ baseDir: process.cwd() });
277
+
278
+ // Input validation
279
+ const result = security.inputValidator.validateString('user input', {
280
+ maxLength: 1000,
281
+ pattern: /^[a-zA-Z0-9\s]+$/,
282
+ });
283
+
284
+ // Path validation
285
+ const pathResult = security.pathValidator.validate('/safe/path/file.ts');
286
+
287
+ // Safe command execution (no shell, uses execFile)
288
+ const executor = new SafeExecutor({ allowedCommands: ['git', 'npm', 'node'] });
289
+ const output = await executor.execute('git', ['status']);
290
+ ```
291
+
292
+ ### Consensus
293
+
294
+ ```typescript
295
+ import { ConsensusEngine, selectOptimalAlgorithm } from 'ai-agent-claude-swarm';
296
+
297
+ // Auto-select algorithm
298
+ const algorithm = selectOptimalAlgorithm({
299
+ faultTolerance: 'high',
300
+ performance: 'medium',
301
+ scalability: 'low',
302
+ });
303
+
304
+ // Create consensus group
305
+ const engine = new ConsensusEngine();
306
+ const group = engine.createGroup({
307
+ algorithm: 'raft', // or 'byzantine', 'gossip'
308
+ nodes: ['agent-1', 'agent-2', 'agent-3'],
309
+ });
310
+
311
+ // Submit proposal
312
+ const result = await group.propose({
313
+ type: 'task-assignment',
314
+ value: { task: 'implement-feature', assignee: 'agent-1' },
315
+ });
316
+ ```
317
+
318
+ ### AI Threat Detection
319
+
320
+ ```typescript
321
+ import { detectThreats, quickScan, checkPII } from 'ai-agent-claude-swarm';
322
+
323
+ // Full threat analysis (50+ patterns)
324
+ const threats = detectThreats('user input to analyze');
325
+ console.log(threats.severity); // 'none' | 'low' | 'medium' | 'high' | 'critical'
326
+ console.log(threats.patterns); // matched injection patterns
327
+
328
+ // Quick scan (fast, fewer patterns)
329
+ const quick = quickScan('check this input');
330
+
331
+ // PII detection
332
+ const pii = checkPII('Call me at 555-123-4567 or email john@example.com');
333
+ console.log(pii.found); // ['phone', 'email']
334
+ ```
335
+
336
+ ### Claims & Work Coordination
337
+
338
+ ```typescript
339
+ import { ClaimService, WorkStealingService, LoadBalancer } from 'ai-agent-claude-swarm';
340
+
341
+ const claimService = new ClaimService();
342
+
343
+ // Claim work
344
+ const claim = await claimService.claim('issue-123', 'agent-coder-1');
345
+
346
+ // Handoff to another agent
347
+ await claimService.handoff('issue-123', 'agent-coder-1', 'agent-reviewer-1');
348
+
349
+ // Work stealing (detect stale claims)
350
+ const stealer = new WorkStealingService(claimService);
351
+ const stolen = await stealer.detectAndSteal({ staleThresholdMs: 300000 });
352
+
353
+ // Load balancing
354
+ const balancer = new LoadBalancer();
355
+ const optimal = balancer.selectAgent(availableAgents, taskRequirements);
356
+ ```
357
+
358
+ ### Hooks System
359
+
360
+ ```typescript
361
+ import { HookRegistry, HookExecutor, WorkerManager, DaemonManager } from 'ai-agent-claude-swarm';
362
+
363
+ const registry = new HookRegistry();
364
+ const executor = new HookExecutor(registry);
365
+
366
+ // Register a custom hook
367
+ registry.register({
368
+ name: 'my-hook',
369
+ event: 'post-task',
370
+ priority: 500,
371
+ handler: async (context) => {
372
+ console.log('Task completed:', context.taskId);
373
+ },
374
+ });
375
+
376
+ // Start background workers
377
+ const workers = new WorkerManager();
378
+ workers.startAll();
379
+
380
+ // Start daemons
381
+ const daemons = new DaemonManager();
382
+ daemons.startAll();
383
+ ```
384
+
385
+ ### Memory
386
+
387
+ ```typescript
388
+ import { JsonStore } from 'ai-agent-claude-swarm';
389
+
390
+ const store = new JsonStore({ basePath: '.ai-swarm/memory' });
391
+
392
+ // Store with namespace
393
+ await store.set('agents', 'coder-1-state', { status: 'active', task: 'feature-x' });
394
+
395
+ // Retrieve
396
+ const state = await store.get('agents', 'coder-1-state');
397
+
398
+ // Search
399
+ const results = await store.search('agents', 'active');
400
+
401
+ // Stats
402
+ const stats = store.getStats();
403
+ ```
404
+
405
+ ## Configuration
406
+
407
+ ### `.ai-swarm/config.json`
408
+
409
+ ```json
410
+ {
411
+ "swarm": {
412
+ "topology": "hierarchical",
413
+ "maxAgents": 8,
414
+ "strategy": "specialized"
415
+ },
416
+ "memory": {
417
+ "path": ".ai-swarm/memory",
418
+ "maxEntriesPerNamespace": 1000
419
+ },
420
+ "agents": {
421
+ "defaultTimeout": 120000,
422
+ "modelRouting": {
423
+ "simple": "haiku",
424
+ "medium": "sonnet",
425
+ "complex": "opus"
426
+ }
427
+ },
428
+ "hooks": {
429
+ "enabled": true,
430
+ "builtIn": true
431
+ }
432
+ }
433
+ ```
434
+
435
+ ### Safety Hooks (Auto-Registered)
436
+
437
+ The plugin automatically registers safety hooks in `.claude/settings.json`:
438
+
439
+ | Hook | Trigger | Action |
440
+ |------|---------|--------|
441
+ | `PreToolUse` | `git push --force*` | **Blocks** force pushes |
442
+ | `PreToolUse` | `rm -rf*` | **Blocks** recursive deletes |
443
+ | `SessionStart` | Session begins | Initializes swarm session |
444
+
445
+ ## Architecture
446
+
447
+ ```
448
+ src/
449
+ ├── index.ts # Plugin entry point (AiSwarmPlugin, createPlugin)
450
+ ├── agents/ # Agent lifecycle, model routing, spawning
451
+ │ ├── agent.ts # Agent entity with state management
452
+ │ ├── model-router.ts # 3-tier model routing (haiku/sonnet/opus)
453
+ │ └── spawner.ts # Agent creation and claude -p execution
454
+ ├── swarm/ # Swarm coordination and orchestration
455
+ │ ├── coordinator.ts # Main orchestration engine
456
+ │ ├── topology.ts # Hierarchical/mesh topology management
457
+ │ ├── task-queue.ts # Priority queue with dependency resolution
458
+ │ ├── message-bus.ts # O(1) circular deque message bus
459
+ │ ├── agent-pool.ts # Auto-scaling agent pool
460
+ │ └── consensus/ # Distributed consensus algorithms
461
+ │ ├── raft.ts # Leader election + log replication
462
+ │ ├── byzantine.ts # PBFT 3-phase consensus
463
+ │ ├── gossip.ts # Epidemic protocol
464
+ │ └── index.ts # Factory + algorithm selection
465
+ ├── security/ # Security validation and hardening
466
+ │ ├── input-validator.ts # Zod-based input validation
467
+ │ ├── path-validator.ts # Path traversal prevention
468
+ │ ├── safe-executor.ts # Command injection prevention
469
+ │ ├── password-hasher.ts # bcrypt hashing
470
+ │ ├── token-generator.ts # HMAC-SHA256 signed tokens
471
+ │ ├── credential-generator.ts # Secure credential generation
472
+ │ └── index.ts
473
+ ├── claims/ # Work coordination and claiming
474
+ │ ├── types.ts # Claim types, work stealing, load balancing
475
+ │ ├── rules.ts # Pure validation functions
476
+ │ ├── events.ts # Domain events + factory functions
477
+ │ ├── claim-service.ts # Claiming, handoffs, auto-assign
478
+ │ ├── work-stealing.ts # Stale work detection and stealing
479
+ │ ├── load-balancer.ts # Agent utilization and rebalancing
480
+ │ └── index.ts
481
+ ├── aidefence/ # AI threat detection
482
+ │ ├── types.ts # Threat types and interfaces
483
+ │ ├── threat-detection.ts # 50+ patterns, PII detection
484
+ │ ├── threat-learning.ts # Pattern learning, mitigation tracking
485
+ │ └── index.ts # Facade with convenience functions
486
+ ├── memory/ # JSON file-based cross-session memory
487
+ │ ├── json-store.ts # Atomic writes, LRU eviction, in-memory cache
488
+ │ └── namespaces.ts # Convenience helpers
489
+ ├── hooks/ # Lifecycle hooks system
490
+ │ ├── registry.ts # Priority-sorted registration, stats tracking
491
+ │ ├── executor.ts # Timeout handling, context threading
492
+ │ ├── built-in.ts # 19 built-in hooks
493
+ │ ├── workers.ts # 6 background workers
494
+ │ └── daemons.ts # MetricsDaemon, SwarmMonitorDaemon
495
+ ├── mcp/ # MCP server for Claude Code
496
+ │ ├── server.ts # stdio JSON-RPC server
497
+ │ ├── tools.ts # 17 core MCP tools
498
+ │ ├── tools-security.ts # 9 security + aidefence tools
499
+ │ ├── tools-coordination.ts # 12 claims + consensus + hooks tools
500
+ │ └── tools-extended.ts # Aggregator
501
+ ├── cli/ # CLI commands
502
+ │ └── commands/ # 11 commands
503
+ ├── types/ # Shared type definitions
504
+ └── utils/
505
+ └── id.ts # ID generation utilities
506
+ ```
507
+
508
+ ## Development
509
+
510
+ ```bash
511
+ # Install dependencies
512
+ npm install
513
+
514
+ # Build
515
+ npm run build
516
+
517
+ # Type-check
518
+ npm run typecheck
519
+
520
+ # Clean
521
+ npm run clean
522
+ ```
523
+
524
+ ## Dependencies
525
+
526
+ | Package | Purpose |
527
+ |---------|---------|
528
+ | `bcrypt` | Password hashing (security module) |
529
+ | `zod` | Runtime input validation schemas |
530
+ | `typescript` | Build toolchain (dev only) |
531
+
532
+ No database required. All storage uses JSON files in `.ai-swarm/memory/`.
533
+
534
+ ## How It Works
535
+
536
+ 1. **Plugin registers** as an MCP server in Claude Code via `.claude/settings.json`
537
+ 2. **Claude Code discovers** the 38 tools at startup via stdio JSON-RPC
538
+ 3. **You interact** with Claude Code normally — it uses swarm tools when beneficial
539
+ 4. **Agents coordinate** through the message bus, consensus protocols, and shared memory
540
+ 5. **Safety hooks** prevent dangerous operations (force push, recursive delete)
541
+ 6. **Memory persists** across sessions via JSON files with atomic writes
542
+
543
+ ## License
544
+
545
+ MIT
@@ -0,0 +1,27 @@
1
+ import { AgentConfig, AgentState, AgentStatus, AgentMetrics } from '../types/agent.js';
2
+ export declare class Agent {
3
+ private state;
4
+ constructor(config: AgentConfig);
5
+ get id(): string;
6
+ get name(): string;
7
+ get type(): string;
8
+ get status(): AgentStatus;
9
+ get config(): AgentConfig;
10
+ get metrics(): AgentMetrics;
11
+ get currentTaskIds(): string[];
12
+ start(): void;
13
+ pause(): void;
14
+ resume(): void;
15
+ terminate(): void;
16
+ setError(error: string): void;
17
+ recover(): void;
18
+ assignTask(taskId: string): void;
19
+ completeTask(taskId: string, durationMs: number, success: boolean): void;
20
+ canAcceptTask(): boolean;
21
+ getUtilization(): number;
22
+ isAvailable(): boolean;
23
+ getState(): AgentState;
24
+ toJSON(): AgentState;
25
+ static fromJSON(data: AgentState): Agent;
26
+ }
27
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agents/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEvF,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAa;gBAEd,MAAM,EAAE,WAAW;IAa/B,IAAI,EAAE,IAAI,MAAM,CAAiC;IACjD,IAAI,IAAI,IAAI,MAAM,CAAmC;IACrD,IAAI,IAAI,IAAI,MAAM,CAAmC;IACrD,IAAI,MAAM,IAAI,WAAW,CAA8B;IACvD,IAAI,MAAM,IAAI,WAAW,CAA8B;IACvD,IAAI,OAAO,IAAI,YAAY,CAA+B;IAC1D,IAAI,cAAc,IAAI,MAAM,EAAE,CAA2C;IAEzE,KAAK,IAAI,IAAI;IAMb,KAAK,IAAI,IAAI;IAOb,MAAM,IAAI,IAAI;IAMd,SAAS,IAAI,IAAI;IAKjB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,OAAO,IAAI,IAAI;IAOf,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOhC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAqBxE,aAAa,IAAI,OAAO;IAKxB,cAAc,IAAI,MAAM;IAIxB,WAAW,IAAI,OAAO;IAKtB,QAAQ,IAAI,UAAU;IAItB,MAAM,IAAI,UAAU;IAIpB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,KAAK;CAKzC"}