multiagents 0.1.2 → 0.1.3

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 (3) hide show
  1. package/cli/setup.ts +44 -214
  2. package/package.json +1 -1
  3. package/.mcp.json +0 -12
package/cli/setup.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  // ============================================================================
2
- // multiagents — Interactive Setup Wizard
2
+ // multiagents — Setup: detect agents + install MCP globally
3
3
  // ============================================================================
4
4
 
5
- import { DEFAULT_BROKER_PORT, BROKER_HOSTNAME, SESSION_DIR, SESSION_FILE } from "../shared/constants.ts";
5
+ import { DEFAULT_BROKER_PORT, BROKER_HOSTNAME } from "../shared/constants.ts";
6
6
  import { BrokerClient } from "../shared/broker-client.ts";
7
- import { expandHome, getGitRoot, slugify } from "../shared/utils.ts";
8
- import type { AgentType, SessionFile } from "../shared/types.ts";
9
- import * as readline from "node:readline";
10
7
  import * as path from "node:path";
11
8
  import * as fs from "node:fs";
12
9
  import * as os from "node:os";
@@ -14,20 +11,7 @@ import * as os from "node:os";
14
11
  const BROKER_PORT = parseInt(process.env.MULTIAGENTS_PORT ?? String(DEFAULT_BROKER_PORT), 10);
15
12
  const BROKER_URL = `http://${BROKER_HOSTNAME}:${BROKER_PORT}`;
16
13
 
17
- // --- Helpers ---
18
-
19
- function prompt(question: string, defaultValue?: string): Promise<string> {
20
- return new Promise((resolve) => {
21
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
22
- const suffix = defaultValue ? ` [${defaultValue}]` : "";
23
- rl.question(`${question}${suffix}: `, (answer) => {
24
- rl.close();
25
- resolve(answer.trim() || defaultValue || "");
26
- });
27
- });
28
- }
29
-
30
- /** Known install locations per agent type, checked as fallbacks when `which` fails. */
14
+ /** Known install locations per agent type. */
31
15
  const KNOWN_PATHS: Record<string, string[]> = {
32
16
  claude: [
33
17
  path.join(os.homedir(), ".local", "bin", "claude"),
@@ -50,7 +34,6 @@ const KNOWN_PATHS: Record<string, string[]> = {
50
34
  };
51
35
 
52
36
  function detectAgent(name: string): { available: boolean; version?: string; resolvedPath?: string } {
53
- // 1. Try `which`
54
37
  let agentPath: string | null = null;
55
38
  try {
56
39
  const which = Bun.spawnSync(["which", name]);
@@ -59,50 +42,38 @@ function detectAgent(name: string): { available: boolean; version?: string; reso
59
42
  }
60
43
  } catch { /* which failed */ }
61
44
 
62
- // 2. Fallback: check known paths
63
45
  if (!agentPath) {
64
- const candidates = KNOWN_PATHS[name] ?? [];
65
- for (const p of candidates) {
66
- if (fs.existsSync(p)) {
67
- agentPath = p;
68
- break;
69
- }
46
+ for (const p of (KNOWN_PATHS[name] ?? [])) {
47
+ if (fs.existsSync(p)) { agentPath = p; break; }
70
48
  }
71
49
  }
72
50
 
73
51
  if (!agentPath) return { available: false };
74
52
 
75
- // 3. Get version (with timeout protection — some CLIs hang)
76
53
  let version: string | undefined;
77
54
  try {
78
- const ver = Bun.spawnSync([agentPath, "--version"], {
79
- timeout: 5000, // 5s timeout
80
- });
55
+ const ver = Bun.spawnSync([agentPath, "--version"], { timeout: 5000 });
81
56
  if (ver.exitCode === 0) {
82
57
  version = new TextDecoder().decode(ver.stdout).trim().split("\n")[0] || undefined;
83
58
  }
84
- } catch {
85
- // Version check failed — agent exists but version unknown
86
- version = undefined;
87
- }
59
+ } catch { version = undefined; }
88
60
 
89
61
  return { available: true, version, resolvedPath: agentPath };
90
62
  }
91
63
 
92
64
  export async function setup(): Promise<void> {
93
- // 1. Header banner
94
65
  console.log(`
95
- \x1b[1m\x1b[36m multiagents\x1b[0m
96
- \x1b[90m Interactive Setup Wizard\x1b[0m
66
+ \x1b[1m\x1b[36m multiagents setup\x1b[0m
67
+ \x1b[90m Configure MCP + detect agents\x1b[0m
97
68
  \x1b[90m ─────────────────────────────────\x1b[0m
98
69
  `);
99
70
 
100
- // 2. Detect installed agents
71
+ // 1. Detect agents
101
72
  console.log("\x1b[1mDetecting installed agents...\x1b[0m\n");
102
- const agents: { type: AgentType; name: string; cmd: string; info: ReturnType<typeof detectAgent> }[] = [
103
- { type: "claude", name: "Claude Code", cmd: "claude", info: detectAgent("claude") },
104
- { type: "codex", name: "Codex CLI", cmd: "codex", info: detectAgent("codex") },
105
- { type: "gemini", name: "Gemini CLI", cmd: "gemini", info: detectAgent("gemini") },
73
+ const agents = [
74
+ { name: "Claude Code", cmd: "claude", info: detectAgent("claude") },
75
+ { name: "Codex CLI", cmd: "codex", info: detectAgent("codex") },
76
+ { name: "Gemini CLI", cmd: "gemini", info: detectAgent("gemini") },
106
77
  ];
107
78
 
108
79
  for (const a of agents) {
@@ -111,202 +82,61 @@ export async function setup(): Promise<void> {
111
82
  console.log(` ${icon} ${a.name}${ver}`);
112
83
  }
113
84
 
114
- const available = agents.filter((a) => a.info.available);
85
+ const available = agents.filter(a => a.info.available);
115
86
  if (available.length === 0) {
116
- console.error("\n\x1b[31mNo supported agents found. Install at least one agent CLI first.\x1b[0m");
117
- process.exit(1);
118
- }
119
-
120
- // 3. Prompt user to select agents
121
- console.log("\n\x1b[1mSelect agents to orchestrate:\x1b[0m\n");
122
- for (let i = 0; i < available.length; i++) {
123
- console.log(` ${i + 1}. ${available[i].name} (${available[i].cmd})`);
124
- }
125
- console.log(` a. All available agents`);
126
-
127
- const selection = await prompt("\nEnter numbers separated by commas, or 'a' for all", "a");
128
- let selected: typeof available;
129
- if (selection === "a" || selection === "A") {
130
- selected = available;
131
- } else {
132
- const indices = selection.split(",").map((s) => parseInt(s.trim(), 10) - 1);
133
- selected = indices
134
- .filter((i) => i >= 0 && i < available.length)
135
- .map((i) => available[i]);
136
- }
137
-
138
- if (selected.length === 0) {
139
- console.error("\n\x1b[31mNo agents selected.\x1b[0m");
87
+ console.error("\n\x1b[31mNo supported agents found. Install at least one: claude, codex, or gemini.\x1b[0m");
140
88
  process.exit(1);
141
89
  }
142
- console.log(`\nSelected: ${selected.map((a) => a.name).join(", ")}`);
143
90
 
144
- // 4. Prompt for working directory
145
- const projectDir = await prompt("\nProject directory", process.cwd());
146
- const resolvedDir = path.resolve(expandHome(projectDir));
147
- if (!fs.existsSync(resolvedDir)) {
148
- console.error(`\n\x1b[31mDirectory does not exist: ${resolvedDir}\x1b[0m`);
149
- process.exit(1);
150
- }
151
-
152
- // 5. Prompt for session name
153
- const dirName = path.basename(resolvedDir);
154
- const sessionName = await prompt("Session name", dirName);
155
- const sessionId = slugify(sessionName);
156
-
157
- // 6. Install global MCP config (Claude Code + settings.json)
158
- console.log("\n\x1b[1mConfiguring global MCP...\x1b[0m\n");
91
+ // 2. Install global MCP config
92
+ console.log("\n\x1b[1mConfiguring MCP servers...\x1b[0m\n");
159
93
  const { installMcpSilent } = await import("./install-mcp.ts");
160
94
  await installMcpSilent();
161
95
 
162
- // 7. Configure per-agent MCP
163
- console.log("\x1b[1mConfiguring per-agent MCP...\x1b[0m\n");
164
-
165
- const cliPath = path.resolve(import.meta.dir, "..");
166
-
167
- for (const agent of selected) {
168
- try {
169
- switch (agent.type) {
170
- case "claude":
171
- await configureClaudeMcp(resolvedDir, cliPath);
172
- break;
173
- case "codex":
174
- await configureCodexMcp(resolvedDir, cliPath);
175
- break;
176
- case "gemini":
177
- await configureGeminiMcp(cliPath);
178
- break;
179
- }
180
- console.log(` \x1b[32m✔\x1b[0m ${agent.name} MCP configured`);
181
- } catch (e) {
182
- console.error(` \x1b[31m✗\x1b[0m ${agent.name}: ${e instanceof Error ? e.message : String(e)}`);
183
- }
184
- }
185
-
186
- // 7. Start broker
96
+ // 3. Start broker
187
97
  console.log("\n\x1b[1mStarting broker...\x1b[0m");
188
98
  const client = new BrokerClient(BROKER_URL);
189
99
  let brokerAlive = await client.isAlive();
190
100
  if (!brokerAlive) {
191
- const proc = Bun.spawn(["bun", path.resolve(cliPath, "broker.ts")], {
192
- stdio: ["ignore", "ignore", "ignore"],
193
- });
101
+ const brokerBin = findBrokerBinary();
102
+ const proc = Bun.spawn([brokerBin], { stdio: ["ignore", "ignore", "ignore"] });
194
103
  proc.unref();
195
104
  for (let i = 0; i < 30; i++) {
196
105
  if (await client.isAlive()) { brokerAlive = true; break; }
197
106
  await Bun.sleep(200);
198
107
  }
199
108
  }
200
- if (!brokerAlive) {
201
- console.error(" \x1b[31m✗\x1b[0m Broker failed to start");
202
- process.exit(1);
203
- }
204
- console.log(` \x1b[32m✔\x1b[0m Broker running on ${BROKER_URL}`);
205
-
206
- // 8. Create session
207
- console.log("\n\x1b[1mCreating session...\x1b[0m");
208
- const gitRoot = await getGitRoot(resolvedDir);
209
- try {
210
- await client.createSession({
211
- id: sessionId,
212
- name: sessionName,
213
- project_dir: resolvedDir,
214
- git_root: gitRoot,
215
- });
216
- console.log(` \x1b[32m✔\x1b[0m Session "${sessionName}" (${sessionId}) created`);
217
- } catch (e) {
218
- const msg = e instanceof Error ? e.message : String(e);
219
- if (msg.includes("409") || msg.includes("UNIQUE") || msg.includes("already")) {
220
- console.log(` \x1b[33m!\x1b[0m Session "${sessionId}" already exists, reusing`);
221
- } else {
222
- throw e;
223
- }
109
+ if (brokerAlive) {
110
+ console.log(` \x1b[32m✔\x1b[0m Broker running on ${BROKER_URL}`);
111
+ } else {
112
+ console.log(` \x1b[33m!\x1b[0m Broker not started — will auto-start when agents connect`);
224
113
  }
225
114
 
226
- // 9. Write session.json
227
- const sessionDir = path.join(resolvedDir, SESSION_DIR);
228
- if (!fs.existsSync(sessionDir)) fs.mkdirSync(sessionDir, { recursive: true });
229
-
230
- const sessionFile: SessionFile = {
231
- session_id: sessionId,
232
- created_at: new Date().toISOString(),
233
- broker_port: BROKER_PORT,
234
- };
235
- await Bun.write(path.join(resolvedDir, SESSION_FILE), JSON.stringify(sessionFile, null, 2));
236
- console.log(` \x1b[32m✔\x1b[0m Wrote ${SESSION_FILE}`);
237
-
238
- // 10. Print next steps
115
+ // 4. Done
239
116
  console.log(`
240
117
  \x1b[1m\x1b[32mSetup complete!\x1b[0m
241
118
 
242
- \x1b[1mNext steps:\x1b[0m
243
- 1. Open your agents in the project directory:
244
- \x1b[90mcd ${resolvedDir}\x1b[0m
245
- ${selected.map((a) => ` \x1b[90m${a.cmd}\x1b[0m`).join("\n")}
246
-
247
- 2. Each agent will auto-connect to the session via MCP.
248
-
249
- 3. Monitor with the dashboard:
250
- \x1b[90mmultiagents dashboard\x1b[0m
251
-
252
- 4. Or use the orchestrator for automated coordination:
253
- \x1b[90mmultiagents orchestrator\x1b[0m
119
+ \x1b[1mUsage:\x1b[0m
120
+ 1. Restart Claude Code to load the multiagents tools.
121
+ 2. In Claude Code, ask it to use the multiagents tools.
122
+ 3. Or use the orchestrator to create a team:
123
+ \x1b[90mmultiagents create-team --project /path/to/project\x1b[0m
124
+
125
+ \x1b[1mAvailable commands:\x1b[0m
126
+ \x1b[90mmultiagents dashboard\x1b[0m Live monitoring
127
+ \x1b[90mmultiagents status\x1b[0m Broker health + peers
128
+ \x1b[90mmultiagents peers\x1b[0m List connected agents
129
+ \x1b[90mmultiagents install-mcp\x1b[0m Reconfigure MCP if needed
254
130
  `);
255
131
  }
256
132
 
257
- // --- Agent MCP configuration ---
258
-
259
- async function configureClaudeMcp(projectDir: string, cliPath: string): Promise<void> {
260
- // Write project-level .mcp.json
261
- const mcpPath = path.join(projectDir, ".mcp.json");
262
- let config: Record<string, unknown> = {};
263
- try {
264
- const existing = await Bun.file(mcpPath).text();
265
- config = JSON.parse(existing);
266
- } catch { /* file doesn't exist */ }
267
-
268
- const mcpServers = (config.mcpServers as Record<string, unknown>) ?? {};
269
- mcpServers["multiagents"] = {
270
- command: "bun",
271
- args: [path.resolve(cliPath, "cli.ts"), "mcp-server", "--agent-type", "claude"],
272
- };
273
- config.mcpServers = mcpServers;
274
- await Bun.write(mcpPath, JSON.stringify(config, null, 2));
275
- }
276
-
277
- async function configureCodexMcp(projectDir: string, cliPath: string): Promise<void> {
278
- // Write .codex/config.toml
279
- const codexDir = path.join(projectDir, ".codex");
280
- if (!fs.existsSync(codexDir)) fs.mkdirSync(codexDir, { recursive: true });
281
-
282
- const tomlPath = path.join(codexDir, "config.toml");
283
- let existing = "";
284
- try { existing = await Bun.file(tomlPath).text(); } catch { /* ok */ }
285
-
286
- // Remove any existing multiagents section
287
- existing = existing.replace(/\[mcp_servers\.multiagents\][\s\S]*?(?=\n\[|$)/, "").trim();
288
-
289
- const entry = `\n\n[mcp_servers.multiagents]\ncommand = "bun"\nargs = [${JSON.stringify(path.resolve(cliPath, "cli.ts"))}, "mcp-server", "--agent-type", "codex"]\n`;
290
- await Bun.write(tomlPath, existing + entry);
291
- }
292
-
293
- async function configureGeminiMcp(cliPath: string): Promise<void> {
294
- // Write ~/.gemini/settings.json
295
- const geminiDir = expandHome("~/.gemini");
296
- if (!fs.existsSync(geminiDir)) fs.mkdirSync(geminiDir, { recursive: true });
297
-
298
- const settingsPath = path.join(geminiDir, "settings.json");
299
- let config: Record<string, unknown> = {};
133
+ function findBrokerBinary(): string {
300
134
  try {
301
- const existing = await Bun.file(settingsPath).text();
302
- config = JSON.parse(existing);
135
+ const which = Bun.spawnSync(["which", "multiagents-broker"]);
136
+ const found = new TextDecoder().decode(which.stdout).trim();
137
+ if (found) return found;
303
138
  } catch { /* ok */ }
304
-
305
- const mcpServers = (config.mcpServers as Record<string, unknown>) ?? {};
306
- mcpServers["multiagents"] = {
307
- command: "bun",
308
- args: [path.resolve(cliPath, "cli.ts"), "mcp-server", "--agent-type", "gemini"],
309
- };
310
- config.mcpServers = mcpServers;
311
- await Bun.write(settingsPath, JSON.stringify(config, null, 2));
139
+ const bun = path.join(os.homedir(), ".bun", "bin", "multiagents-broker");
140
+ if (fs.existsSync(bun)) return bun;
141
+ return "multiagents-broker";
312
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multiagents",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Multi-agent orchestration platform for Claude Code, Codex CLI, and Gemini CLI",
5
5
  "module": "index.ts",
6
6
  "type": "module",
package/.mcp.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "mcpServers": {
3
- "agent-peers": {
4
- "command": "/Users/armanandreasyan/.bun/bin/bun",
5
- "args": ["/Users/armanandreasyan/Documents/multi-agent-peers/server.ts"]
6
- },
7
- "agent-peers-orchestrator": {
8
- "command": "/Users/armanandreasyan/.bun/bin/bun",
9
- "args": ["/Users/armanandreasyan/Documents/multi-agent-peers/orchestrator/orchestrator-server.ts"]
10
- }
11
- }
12
- }