pi-teams 0.8.2 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -2
- package/extensions/index.ts +135 -123
- package/package.json +1 -1
- package/src/adapters/iterm2-adapter.ts +162 -20
- package/src/adapters/terminal-registry.ts +19 -0
- package/src/adapters/tmux-adapter.ts +35 -0
- package/src/adapters/wezterm-adapter.ts +138 -0
- package/src/adapters/zellij-adapter.ts +35 -0
- package/src/utils/models.ts +2 -0
- package/src/utils/teams.ts +3 -1
- package/src/utils/terminal-adapter.ts +49 -4
package/README.md
CHANGED
|
@@ -45,6 +45,8 @@ pi install npm:pi-teams
|
|
|
45
45
|
- **Beautiful UI**: Optimized vertical splits in `tmux` with clear labels so you always know who is doing what.
|
|
46
46
|
|
|
47
47
|
### Advanced Features
|
|
48
|
+
- **Isolated OS Windows**: Launch teammates in true separate OS windows instead of panes.
|
|
49
|
+
- **Persistent Window Titles**: Windows are automatically titled `[team-name]: [agent-name]` for easy identification in your window manager.
|
|
48
50
|
- **Plan Approval Mode**: Require teammates to submit their implementation plans for your approval before they touch any code.
|
|
49
51
|
- **Broadcast Messaging**: Send a message to the entire team at once for global coordination and announcements.
|
|
50
52
|
- **Quality Gate Hooks**: Automated shell scripts run when tasks are completed (e.g., to run tests or linting).
|
|
@@ -58,9 +60,20 @@ pi install npm:pi-teams
|
|
|
58
60
|
**Set a default model for the whole team:**
|
|
59
61
|
> **You:** "Create a team named 'Research' and use 'gpt-4o' for everyone."
|
|
60
62
|
|
|
63
|
+
**Start a team in "Separate Windows" mode:**
|
|
64
|
+
> **You:** "Create a team named 'Dev' and open everyone in separate windows."
|
|
65
|
+
*(Supported in iTerm2 and WezTerm only)*
|
|
66
|
+
|
|
61
67
|
### 2. Spawn Teammate with Custom Settings
|
|
62
68
|
> **You:** "Spawn a teammate named 'security-bot' in the current folder. Tell them to scan for hardcoded API keys."
|
|
63
69
|
|
|
70
|
+
**Spawn a specific teammate in a separate window:**
|
|
71
|
+
> **You:** "Spawn 'researcher' in a separate window."
|
|
72
|
+
|
|
73
|
+
**Move the Team Lead to a separate window:**
|
|
74
|
+
> **You:** "Open the team lead in its own window."
|
|
75
|
+
*(Requires separate_windows mode enabled or iTerm2/WezTerm)*
|
|
76
|
+
|
|
64
77
|
**Use a different model:**
|
|
65
78
|
> **You:** "Spawn a teammate named 'speed-bot' using 'haiku' to quickly run some benchmarks."
|
|
66
79
|
|
|
@@ -111,11 +124,15 @@ Simply start `pi` inside a Zellij session. **pi-teams** will detect it via the `
|
|
|
111
124
|
|
|
112
125
|
### Option 3: iTerm2 (macOS)
|
|
113
126
|
|
|
114
|
-
If you are using **iTerm2** on macOS and are *not* inside tmux or Zellij, **pi-teams**
|
|
127
|
+
If you are using **iTerm2** on macOS and are *not* inside tmux or Zellij, **pi-teams** can manage your team in two ways:
|
|
128
|
+
1. **Panes (Default)**: Automatically split your current window into an optimized layout.
|
|
129
|
+
2. **Windows**: Create true separate OS windows for each agent.
|
|
130
|
+
|
|
131
|
+
It will name the panes or windows with the teammate's agent name for easy identification.
|
|
115
132
|
|
|
116
133
|
### Option 4: WezTerm (macOS, Linux, Windows)
|
|
117
134
|
|
|
118
|
-
**WezTerm** is a GPU-accelerated, cross-platform terminal emulator written in Rust.
|
|
135
|
+
**WezTerm** is a GPU-accelerated, cross-platform terminal emulator written in Rust. Like iTerm2, it supports both **Panes** and **Separate OS Windows**.
|
|
119
136
|
|
|
120
137
|
Install WezTerm:
|
|
121
138
|
- **macOS**: `brew install --cask wezterm`
|
package/extensions/index.ts
CHANGED
|
@@ -8,15 +8,14 @@ import * as messaging from "../src/utils/messaging";
|
|
|
8
8
|
import { Member } from "../src/utils/models";
|
|
9
9
|
import { getTerminalAdapter } from "../src/adapters/terminal-registry";
|
|
10
10
|
import { Iterm2Adapter } from "../src/adapters/iterm2-adapter";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import fs from "node:fs";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
13
|
|
|
14
14
|
export default function (pi: ExtensionAPI) {
|
|
15
15
|
const isTeammate = !!process.env.PI_AGENT_NAME;
|
|
16
16
|
const agentName = process.env.PI_AGENT_NAME || "team-lead";
|
|
17
17
|
const teamName = process.env.PI_TEAM_NAME;
|
|
18
18
|
|
|
19
|
-
// Get the terminal adapter once at startup
|
|
20
19
|
const terminal = getTerminalAdapter();
|
|
21
20
|
|
|
22
21
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -27,20 +26,24 @@ export default function (pi: ExtensionAPI) {
|
|
|
27
26
|
fs.writeFileSync(pidFile, process.pid.toString());
|
|
28
27
|
}
|
|
29
28
|
ctx.ui.notify(`Teammate: ${agentName} (Team: ${teamName})`, "info");
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Set the terminal pane title for better visibility
|
|
29
|
+
ctx.ui.setStatus("00-pi-teams", `[${agentName.toUpperCase()}]`);
|
|
30
|
+
|
|
34
31
|
if (terminal) {
|
|
35
|
-
|
|
32
|
+
const fullTitle = teamName ? `${teamName}: ${agentName}` : agentName;
|
|
33
|
+
const setIt = () => {
|
|
34
|
+
if ((ctx.ui as any).setTitle) (ctx.ui as any).setTitle(fullTitle);
|
|
35
|
+
terminal.setTitle(fullTitle);
|
|
36
|
+
};
|
|
37
|
+
setIt();
|
|
38
|
+
setTimeout(setIt, 500);
|
|
39
|
+
setTimeout(setIt, 2000);
|
|
40
|
+
setTimeout(setIt, 5000);
|
|
36
41
|
}
|
|
37
|
-
|
|
38
|
-
// Auto-trigger the first turn for teammates
|
|
42
|
+
|
|
39
43
|
setTimeout(() => {
|
|
40
44
|
pi.sendUserMessage(`I am starting my work as '${agentName}' on team '${teamName}'. Checking my inbox for instructions...`);
|
|
41
45
|
}, 1000);
|
|
42
46
|
|
|
43
|
-
// Periodically check for new messages when idle
|
|
44
47
|
setInterval(async () => {
|
|
45
48
|
if (ctx.isIdle() && teamName) {
|
|
46
49
|
const unread = await messaging.readInbox(teamName, agentName, true, false);
|
|
@@ -54,12 +57,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
|
|
60
|
+
pi.on("turn_start", async (_event, ctx) => {
|
|
61
|
+
if (isTeammate) {
|
|
62
|
+
const fullTitle = teamName ? `${teamName}: ${agentName}` : agentName;
|
|
63
|
+
if ((ctx.ui as any).setTitle) (ctx.ui as any).setTitle(fullTitle);
|
|
64
|
+
if (terminal) terminal.setTitle(fullTitle);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
57
68
|
let firstTurn = true;
|
|
58
69
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
59
70
|
if (isTeammate && firstTurn) {
|
|
60
71
|
firstTurn = false;
|
|
61
72
|
|
|
62
|
-
// Get the teammate's model and thinking level from team config for accurate reporting
|
|
63
73
|
let modelInfo = "";
|
|
64
74
|
if (teamName) {
|
|
65
75
|
try {
|
|
@@ -73,7 +83,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
73
83
|
modelInfo += `. When reporting your model or thinking level, use these exact values.`;
|
|
74
84
|
}
|
|
75
85
|
} catch (e) {
|
|
76
|
-
//
|
|
86
|
+
// Ignore
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
|
|
@@ -93,10 +103,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
93
103
|
process.kill(parseInt(pid), "SIGKILL");
|
|
94
104
|
fs.unlinkSync(pidFile);
|
|
95
105
|
} catch (e) {
|
|
96
|
-
// ignore
|
|
106
|
+
// ignore
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
109
|
|
|
110
|
+
if (member.windowId && terminal) {
|
|
111
|
+
terminal.killWindow(member.windowId);
|
|
112
|
+
}
|
|
113
|
+
|
|
100
114
|
if (member.tmuxPaneId && terminal) {
|
|
101
115
|
terminal.kill(member.tmuxPaneId);
|
|
102
116
|
}
|
|
@@ -111,9 +125,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
111
125
|
team_name: Type.String(),
|
|
112
126
|
description: Type.Optional(Type.String()),
|
|
113
127
|
default_model: Type.Optional(Type.String()),
|
|
128
|
+
separate_windows: Type.Optional(Type.Boolean({ default: false, description: "Open teammates in separate OS windows instead of panes" })),
|
|
114
129
|
}),
|
|
115
130
|
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
116
|
-
const config = teams.createTeam(params.team_name, "local-session", "lead-agent", params.description, params.default_model);
|
|
131
|
+
const config = teams.createTeam(params.team_name, "local-session", "lead-agent", params.description, params.default_model, params.separate_windows);
|
|
117
132
|
return {
|
|
118
133
|
content: [{ type: "text", text: `Team ${params.team_name} created.` }],
|
|
119
134
|
details: { config },
|
|
@@ -124,7 +139,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
124
139
|
pi.registerTool({
|
|
125
140
|
name: "spawn_teammate",
|
|
126
141
|
label: "Spawn Teammate",
|
|
127
|
-
description: "Spawn a new teammate in a terminal pane.",
|
|
142
|
+
description: "Spawn a new teammate in a terminal pane or separate window.",
|
|
128
143
|
parameters: Type.Object({
|
|
129
144
|
team_name: Type.String(),
|
|
130
145
|
name: Type.String(),
|
|
@@ -133,6 +148,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
133
148
|
model: Type.Optional(Type.String()),
|
|
134
149
|
thinking: Type.Optional(StringEnum(["off", "minimal", "low", "medium", "high"])),
|
|
135
150
|
plan_mode_required: Type.Optional(Type.Boolean({ default: false })),
|
|
151
|
+
separate_window: Type.Optional(Type.Boolean({ default: false })),
|
|
136
152
|
}),
|
|
137
153
|
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
138
154
|
const safeName = paths.sanitizeName(params.name);
|
|
@@ -143,20 +159,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
143
159
|
}
|
|
144
160
|
|
|
145
161
|
if (!terminal) {
|
|
146
|
-
throw new Error("No terminal adapter detected.
|
|
162
|
+
throw new Error("No terminal adapter detected.");
|
|
147
163
|
}
|
|
148
164
|
|
|
149
165
|
const teamConfig = await teams.readConfig(safeTeamName);
|
|
150
166
|
let chosenModel = params.model || teamConfig.defaultModel;
|
|
151
167
|
|
|
152
|
-
// If model doesn't include provider prefix (provider/model), use the team's defaultModel or fallback
|
|
153
168
|
if (chosenModel && !chosenModel.includes('/')) {
|
|
154
|
-
// Check if team has a defaultModel with a provider prefix
|
|
155
169
|
if (teamConfig.defaultModel && teamConfig.defaultModel.includes('/')) {
|
|
156
170
|
const [provider] = teamConfig.defaultModel.split('/');
|
|
157
171
|
chosenModel = `${provider}/${chosenModel}`;
|
|
158
172
|
} else {
|
|
159
|
-
// Infer provider from model name
|
|
160
173
|
if (chosenModel.startsWith('glm-')) {
|
|
161
174
|
chosenModel = `zai/${chosenModel}`;
|
|
162
175
|
} else if (chosenModel.startsWith('claude-')) {
|
|
@@ -165,6 +178,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
165
178
|
}
|
|
166
179
|
}
|
|
167
180
|
|
|
181
|
+
const useSeparateWindow = params.separate_window ?? teamConfig.separateWindows ?? false;
|
|
182
|
+
if (useSeparateWindow && !terminal.supportsWindows()) {
|
|
183
|
+
throw new Error(`Separate windows mode is not supported in ${terminal.name}.`);
|
|
184
|
+
}
|
|
185
|
+
|
|
168
186
|
const member: Member = {
|
|
169
187
|
agentId: `${safeName}@${safeTeamName}`,
|
|
170
188
|
name: safeName,
|
|
@@ -183,14 +201,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
183
201
|
await teams.addMember(safeTeamName, member);
|
|
184
202
|
await messaging.sendPlainMessage(safeTeamName, "team-lead", safeName, params.prompt, "Initial prompt");
|
|
185
203
|
|
|
186
|
-
const piBinary = process.argv[1] ? `node ${process.argv[1]}` : "pi";
|
|
204
|
+
const piBinary = process.argv[1] ? `node ${process.argv[1]}` : "pi";
|
|
187
205
|
let piCmd = piBinary;
|
|
188
206
|
|
|
189
|
-
// Build model command with thinking level if specified
|
|
190
207
|
if (chosenModel) {
|
|
191
208
|
const [provider, ...modelParts] = chosenModel.split('/');
|
|
192
209
|
const modelName = modelParts.join('/');
|
|
193
|
-
|
|
194
210
|
if (params.thinking) {
|
|
195
211
|
piCmd = `${piBinary} --provider ${provider} --model ${modelName}:${params.thinking}`;
|
|
196
212
|
} else {
|
|
@@ -206,39 +222,83 @@ export default function (pi: ExtensionAPI) {
|
|
|
206
222
|
PI_AGENT_NAME: safeName,
|
|
207
223
|
};
|
|
208
224
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const teammates = teamConfig.members.filter(m => m.agentType === "teammate" && m.tmuxPaneId.startsWith("iterm_"));
|
|
212
|
-
const lastTeammate = teammates.length > 0 ? teammates[teammates.length - 1] : null;
|
|
213
|
-
if (lastTeammate?.tmuxPaneId) {
|
|
214
|
-
terminal.setSpawnContext({ lastSessionId: lastTeammate.tmuxPaneId.replace("iterm_", "") });
|
|
215
|
-
} else {
|
|
216
|
-
terminal.setSpawnContext({});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
225
|
+
let terminalId = "";
|
|
226
|
+
let isWindow = false;
|
|
219
227
|
|
|
220
|
-
let paneId = "";
|
|
221
228
|
try {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
229
|
+
if (useSeparateWindow) {
|
|
230
|
+
isWindow = true;
|
|
231
|
+
terminalId = terminal.spawnWindow({
|
|
232
|
+
name: safeName,
|
|
233
|
+
cwd: params.cwd,
|
|
234
|
+
command: piCmd,
|
|
235
|
+
env: env,
|
|
236
|
+
teamName: safeTeamName,
|
|
237
|
+
});
|
|
238
|
+
await teams.updateMember(safeTeamName, safeName, { windowId: terminalId });
|
|
239
|
+
} else {
|
|
240
|
+
if (terminal instanceof Iterm2Adapter) {
|
|
241
|
+
const teammates = teamConfig.members.filter(m => m.agentType === "teammate" && m.tmuxPaneId.startsWith("iterm_"));
|
|
242
|
+
const lastTeammate = teammates.length > 0 ? teammates[teammates.length - 1] : null;
|
|
243
|
+
if (lastTeammate?.tmuxPaneId) {
|
|
244
|
+
terminal.setSpawnContext({ lastSessionId: lastTeammate.tmuxPaneId.replace("iterm_", "") });
|
|
245
|
+
} else {
|
|
246
|
+
terminal.setSpawnContext({});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
terminalId = terminal.spawn({
|
|
251
|
+
name: safeName,
|
|
252
|
+
cwd: params.cwd,
|
|
253
|
+
command: piCmd,
|
|
254
|
+
env: env,
|
|
255
|
+
});
|
|
256
|
+
await teams.updateMember(safeTeamName, safeName, { tmuxPaneId: terminalId });
|
|
257
|
+
}
|
|
228
258
|
} catch (e) {
|
|
229
|
-
throw new Error(`Failed to spawn ${terminal.name} pane: ${e}`);
|
|
259
|
+
throw new Error(`Failed to spawn ${terminal.name} ${isWindow ? 'window' : 'pane'}: ${e}`);
|
|
230
260
|
}
|
|
231
261
|
|
|
232
|
-
// Update member with paneId
|
|
233
|
-
await teams.updateMember(params.team_name, params.name, { tmuxPaneId: paneId });
|
|
234
|
-
|
|
235
262
|
return {
|
|
236
|
-
content: [{ type: "text", text: `Teammate ${params.name} spawned in pane ${
|
|
237
|
-
details: { agentId: member.agentId,
|
|
263
|
+
content: [{ type: "text", text: `Teammate ${params.name} spawned in ${isWindow ? 'window' : 'pane'} ${terminalId}.` }],
|
|
264
|
+
details: { agentId: member.agentId, terminalId, isWindow },
|
|
238
265
|
};
|
|
239
266
|
},
|
|
240
267
|
});
|
|
241
268
|
|
|
269
|
+
pi.registerTool({
|
|
270
|
+
name: "spawn_lead_window",
|
|
271
|
+
label: "Spawn Lead Window",
|
|
272
|
+
description: "Open the team lead in a separate OS window.",
|
|
273
|
+
parameters: Type.Object({
|
|
274
|
+
team_name: Type.String(),
|
|
275
|
+
cwd: Type.Optional(Type.String()),
|
|
276
|
+
}),
|
|
277
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
278
|
+
const safeTeamName = paths.sanitizeName(params.team_name);
|
|
279
|
+
if (!teams.teamExists(safeTeamName)) throw new Error(`Team ${params.team_name} does not exist`);
|
|
280
|
+
if (!terminal || !terminal.supportsWindows()) throw new Error("Windows mode not supported.");
|
|
281
|
+
|
|
282
|
+
const teamConfig = await teams.readConfig(safeTeamName);
|
|
283
|
+
const cwd = params.cwd || process.cwd();
|
|
284
|
+
const piBinary = process.argv[1] ? `node ${process.argv[1]}` : "pi";
|
|
285
|
+
let piCmd = piBinary;
|
|
286
|
+
if (teamConfig.defaultModel) {
|
|
287
|
+
const [provider, ...modelParts] = teamConfig.defaultModel.split('/');
|
|
288
|
+
piCmd = `${piBinary} --provider ${provider} --model ${modelParts.join('/')}`;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const env = { ...process.env, PI_TEAM_NAME: safeTeamName, PI_AGENT_NAME: "team-lead" };
|
|
292
|
+
try {
|
|
293
|
+
const windowId = terminal.spawnWindow({ name: "team-lead", cwd, command: piCmd, env, teamName: safeTeamName });
|
|
294
|
+
await teams.updateMember(safeTeamName, "team-lead", { windowId });
|
|
295
|
+
return { content: [{ type: "text", text: `Lead window spawned: ${windowId}` }], details: { windowId } };
|
|
296
|
+
} catch (e) {
|
|
297
|
+
throw new Error(`Failed: ${e}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
242
302
|
pi.registerTool({
|
|
243
303
|
name: "send_message",
|
|
244
304
|
label: "Send Message",
|
|
@@ -286,7 +346,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
286
346
|
agent_name: Type.Optional(Type.String({ description: "Whose inbox to read. Defaults to your own." })),
|
|
287
347
|
unread_only: Type.Optional(Type.Boolean({ default: true })),
|
|
288
348
|
}),
|
|
289
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
349
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
290
350
|
const targetAgent = params.agent_name || agentName;
|
|
291
351
|
const msgs = await messaging.readInbox(params.team_name, targetAgent, params.unread_only);
|
|
292
352
|
return {
|
|
@@ -305,7 +365,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
305
365
|
subject: Type.String(),
|
|
306
366
|
description: Type.String(),
|
|
307
367
|
}),
|
|
308
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
368
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
309
369
|
const task = await tasks.createTask(params.team_name, params.subject, params.description);
|
|
310
370
|
return {
|
|
311
371
|
content: [{ type: "text", text: `Task ${task.id} created.` }],
|
|
@@ -354,11 +414,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
354
414
|
pi.registerTool({
|
|
355
415
|
name: "task_list",
|
|
356
416
|
label: "List Tasks",
|
|
357
|
-
description: "List all team
|
|
417
|
+
description: "List all tasks for a team.",
|
|
358
418
|
parameters: Type.Object({
|
|
359
419
|
team_name: Type.String(),
|
|
360
420
|
}),
|
|
361
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
421
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
362
422
|
const taskList = await tasks.listTasks(params.team_name);
|
|
363
423
|
return {
|
|
364
424
|
content: [{ type: "text", text: JSON.stringify(taskList, null, 2) }],
|
|
@@ -390,61 +450,39 @@ export default function (pi: ExtensionAPI) {
|
|
|
390
450
|
});
|
|
391
451
|
|
|
392
452
|
pi.registerTool({
|
|
393
|
-
name: "
|
|
394
|
-
label: "
|
|
395
|
-
description: "
|
|
453
|
+
name: "team_shutdown",
|
|
454
|
+
label: "Shutdown Team",
|
|
455
|
+
description: "Shutdown the entire team and close all panes/windows.",
|
|
396
456
|
parameters: Type.Object({
|
|
397
457
|
team_name: Type.String(),
|
|
398
458
|
}),
|
|
399
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
459
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
400
460
|
const teamName = params.team_name;
|
|
401
461
|
try {
|
|
402
462
|
const config = await teams.readConfig(teamName);
|
|
403
463
|
for (const member of config.members) {
|
|
404
|
-
|
|
405
|
-
ctx.ui.notify(`Stopping teammate: ${member.name}`, "info");
|
|
406
|
-
await killTeammate(teamName, member);
|
|
407
|
-
}
|
|
464
|
+
await killTeammate(teamName, member);
|
|
408
465
|
}
|
|
466
|
+
const dir = paths.teamDir(teamName);
|
|
467
|
+
const tasksDir = paths.taskDir(teamName);
|
|
468
|
+
if (fs.existsSync(tasksDir)) fs.rmSync(tasksDir, { recursive: true });
|
|
469
|
+
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true });
|
|
470
|
+
return { content: [{ type: "text", text: `Team ${teamName} shut down.` }], details: {} };
|
|
409
471
|
} catch (e) {
|
|
410
|
-
|
|
472
|
+
throw new Error(`Failed to shutdown team: ${e}`);
|
|
411
473
|
}
|
|
412
|
-
|
|
413
|
-
const dir = paths.teamDir(teamName);
|
|
414
|
-
const tasksDir = paths.taskDir(teamName);
|
|
415
|
-
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true });
|
|
416
|
-
if (fs.existsSync(tasksDir)) fs.rmSync(tasksDir, { recursive: true });
|
|
417
|
-
return {
|
|
418
|
-
content: [{ type: "text", text: `Team ${teamName} deleted.` }],
|
|
419
|
-
};
|
|
420
|
-
},
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
pi.registerTool({
|
|
424
|
-
name: "read_config",
|
|
425
|
-
label: "Read Config",
|
|
426
|
-
description: "Read the current team configuration.",
|
|
427
|
-
parameters: Type.Object({
|
|
428
|
-
team_name: Type.String(),
|
|
429
|
-
}),
|
|
430
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
431
|
-
const config = await teams.readConfig(params.team_name);
|
|
432
|
-
return {
|
|
433
|
-
content: [{ type: "text", text: JSON.stringify(config, null, 2) }],
|
|
434
|
-
details: { config },
|
|
435
|
-
};
|
|
436
474
|
},
|
|
437
475
|
});
|
|
438
476
|
|
|
439
477
|
pi.registerTool({
|
|
440
|
-
name: "
|
|
441
|
-
label: "
|
|
442
|
-
description: "
|
|
478
|
+
name: "task_read",
|
|
479
|
+
label: "Read Task",
|
|
480
|
+
description: "Read details of a specific task.",
|
|
443
481
|
parameters: Type.Object({
|
|
444
482
|
team_name: Type.String(),
|
|
445
483
|
task_id: Type.String(),
|
|
446
484
|
}),
|
|
447
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
485
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
448
486
|
const task = await tasks.readTask(params.team_name, params.task_id);
|
|
449
487
|
return {
|
|
450
488
|
content: [{ type: "text", text: JSON.stringify(task, null, 2) }],
|
|
@@ -453,29 +491,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
453
491
|
},
|
|
454
492
|
});
|
|
455
493
|
|
|
456
|
-
pi.registerTool({
|
|
457
|
-
name: "force_kill_teammate",
|
|
458
|
-
label: "Force Kill Teammate",
|
|
459
|
-
description: "Forcibly kill a teammate's terminal pane.",
|
|
460
|
-
parameters: Type.Object({
|
|
461
|
-
team_name: Type.String(),
|
|
462
|
-
agent_name: Type.String(),
|
|
463
|
-
}),
|
|
464
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
465
|
-
const config = await teams.readConfig(params.team_name);
|
|
466
|
-
const member = config.members.find(m => m.name === params.agent_name);
|
|
467
|
-
if (!member) throw new Error(`Teammate ${params.agent_name} not found`);
|
|
468
|
-
|
|
469
|
-
await killTeammate(params.team_name, member);
|
|
470
|
-
|
|
471
|
-
await teams.removeMember(params.team_name, params.agent_name);
|
|
472
|
-
await tasks.resetOwnerTasks(params.team_name, params.agent_name);
|
|
473
|
-
return {
|
|
474
|
-
content: [{ type: "text", text: `${params.agent_name} has been stopped.` }],
|
|
475
|
-
};
|
|
476
|
-
},
|
|
477
|
-
});
|
|
478
|
-
|
|
479
494
|
pi.registerTool({
|
|
480
495
|
name: "check_teammate",
|
|
481
496
|
label: "Check Teammate",
|
|
@@ -484,18 +499,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
484
499
|
team_name: Type.String(),
|
|
485
500
|
agent_name: Type.String(),
|
|
486
501
|
}),
|
|
487
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
502
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
488
503
|
const config = await teams.readConfig(params.team_name);
|
|
489
504
|
const member = config.members.find(m => m.name === params.agent_name);
|
|
490
505
|
if (!member) throw new Error(`Teammate ${params.agent_name} not found`);
|
|
491
506
|
|
|
492
507
|
let alive = false;
|
|
493
|
-
if (member.
|
|
508
|
+
if (member.windowId && terminal) {
|
|
509
|
+
alive = terminal.isWindowAlive(member.windowId);
|
|
510
|
+
} else if (member.tmuxPaneId && terminal) {
|
|
494
511
|
alive = terminal.isAlive(member.tmuxPaneId);
|
|
495
512
|
}
|
|
496
513
|
|
|
497
514
|
const unreadCount = (await messaging.readInbox(params.team_name, params.agent_name, true, false)).length;
|
|
498
|
-
|
|
499
515
|
return {
|
|
500
516
|
content: [{ type: "text", text: JSON.stringify({ alive, unreadCount }, null, 2) }],
|
|
501
517
|
details: { alive, unreadCount },
|
|
@@ -511,18 +527,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
511
527
|
team_name: Type.String(),
|
|
512
528
|
agent_name: Type.String(),
|
|
513
529
|
}),
|
|
514
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
530
|
+
async execute(toolCallId, params: any, signal, onUpdate, ctx) {
|
|
515
531
|
const config = await teams.readConfig(params.team_name);
|
|
516
532
|
const member = config.members.find(m => m.name === params.agent_name);
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
await tasks.resetOwnerTasks(params.team_name, params.agent_name);
|
|
523
|
-
return {
|
|
524
|
-
content: [{ type: "text", text: `${params.agent_name} removed from team.` }],
|
|
525
|
-
};
|
|
533
|
+
if (member) {
|
|
534
|
+
await killTeammate(params.team_name, member);
|
|
535
|
+
await teams.removeMember(params.team_name, params.agent_name);
|
|
536
|
+
}
|
|
537
|
+
return { content: [{ type: "text", text: `Teammate ${params.agent_name} shutdown processed.` }], details: {} };
|
|
526
538
|
},
|
|
527
539
|
});
|
|
528
540
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* iTerm2 Terminal Adapter
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Implements the TerminalAdapter interface for iTerm2 terminal emulator.
|
|
5
5
|
* Uses AppleScript for all operations.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { TerminalAdapter, SpawnOptions, execCommand } from "../utils/terminal-adapter";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Context needed for iTerm2 spawning (tracks last pane for layout)
|
|
@@ -20,23 +21,36 @@ export class Iterm2Adapter implements TerminalAdapter {
|
|
|
20
21
|
private spawnContext: Iterm2SpawnContext = {};
|
|
21
22
|
|
|
22
23
|
detect(): boolean {
|
|
23
|
-
// iTerm2 is available if TERM_PROGRAM is iTerm.app and not in tmux/zellij
|
|
24
24
|
return process.env.TERM_PROGRAM === "iTerm.app" && !process.env.TMUX && !process.env.ZELLIJ;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Helper to execute AppleScript via stdin to avoid escaping issues with -e
|
|
29
|
+
*/
|
|
30
|
+
private runAppleScript(script: string): { stdout: string; stderr: string; status: number | null } {
|
|
31
|
+
const result = spawnSync("osascript", ["-"], {
|
|
32
|
+
input: script,
|
|
33
|
+
encoding: "utf-8",
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
stdout: result.stdout?.toString() ?? "",
|
|
37
|
+
stderr: result.stderr?.toString() ?? "",
|
|
38
|
+
status: result.status,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
27
42
|
spawn(options: SpawnOptions): string {
|
|
28
43
|
const envStr = Object.entries(options.env)
|
|
29
44
|
.filter(([k]) => k.startsWith("PI_"))
|
|
30
45
|
.map(([k, v]) => `${k}=${v}`)
|
|
31
46
|
.join(" ");
|
|
32
|
-
|
|
47
|
+
|
|
33
48
|
const itermCmd = `cd '${options.cwd}' && ${envStr} ${options.command}`;
|
|
34
49
|
const escapedCmd = itermCmd.replace(/"/g, '\\"');
|
|
35
50
|
|
|
36
51
|
let script: string;
|
|
37
|
-
|
|
52
|
+
|
|
38
53
|
if (!this.spawnContext.lastSessionId) {
|
|
39
|
-
// First teammate: split current session vertically (side-by-side)
|
|
40
54
|
script = `tell application "iTerm2"
|
|
41
55
|
tell current session of current window
|
|
42
56
|
set newSession to split vertically with default profile
|
|
@@ -47,7 +61,6 @@ export class Iterm2Adapter implements TerminalAdapter {
|
|
|
47
61
|
end tell
|
|
48
62
|
end tell`;
|
|
49
63
|
} else {
|
|
50
|
-
// Subsequent teammate: split the last teammate's session horizontally (stacking)
|
|
51
64
|
script = `tell application "iTerm2"
|
|
52
65
|
repeat with aWindow in windows
|
|
53
66
|
repeat with aTab in tabs of aWindow
|
|
@@ -67,21 +80,21 @@ end tell`;
|
|
|
67
80
|
end tell`;
|
|
68
81
|
}
|
|
69
82
|
|
|
70
|
-
const result =
|
|
71
|
-
|
|
83
|
+
const result = this.runAppleScript(script);
|
|
84
|
+
|
|
72
85
|
if (result.status !== 0) {
|
|
73
86
|
throw new Error(`osascript failed with status ${result.status}: ${result.stderr}`);
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
const sessionId = result.stdout.toString().trim();
|
|
77
90
|
this.spawnContext.lastSessionId = sessionId;
|
|
78
|
-
|
|
91
|
+
|
|
79
92
|
return `iterm_${sessionId}`;
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
kill(paneId: string): void {
|
|
83
|
-
if (!paneId || !paneId.startsWith("iterm_")) {
|
|
84
|
-
return;
|
|
96
|
+
if (!paneId || !paneId.startsWith("iterm_") || paneId.startsWith("iterm_win_")) {
|
|
97
|
+
return;
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
const itermId = paneId.replace("iterm_", "");
|
|
@@ -99,15 +112,15 @@ end tell`;
|
|
|
99
112
|
end tell`;
|
|
100
113
|
|
|
101
114
|
try {
|
|
102
|
-
|
|
115
|
+
this.runAppleScript(script);
|
|
103
116
|
} catch {
|
|
104
|
-
// Ignore errors
|
|
117
|
+
// Ignore errors
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
isAlive(paneId: string): boolean {
|
|
109
|
-
if (!paneId || !paneId.startsWith("iterm_")) {
|
|
110
|
-
return false;
|
|
122
|
+
if (!paneId || !paneId.startsWith("iterm_") || paneId.startsWith("iterm_win_")) {
|
|
123
|
+
return false;
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
const itermId = paneId.replace("iterm_", "");
|
|
@@ -124,7 +137,7 @@ end tell`;
|
|
|
124
137
|
end tell`;
|
|
125
138
|
|
|
126
139
|
try {
|
|
127
|
-
const result =
|
|
140
|
+
const result = this.runAppleScript(script);
|
|
128
141
|
return result.stdout.includes("Alive");
|
|
129
142
|
} catch {
|
|
130
143
|
return false;
|
|
@@ -132,16 +145,145 @@ end tell`;
|
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
setTitle(title: string): void {
|
|
148
|
+
const escapedTitle = title.replace(/"/g, '\\"');
|
|
149
|
+
const script = `tell application "iTerm2" to tell current session of current window
|
|
150
|
+
set name to "${escapedTitle}"
|
|
151
|
+
end tell`;
|
|
135
152
|
try {
|
|
136
|
-
|
|
137
|
-
"-e",
|
|
138
|
-
`tell application "iTerm2" to tell current session of current window to set name to "${title}"`
|
|
139
|
-
]);
|
|
153
|
+
this.runAppleScript(script);
|
|
140
154
|
} catch {
|
|
141
155
|
// Ignore errors
|
|
142
156
|
}
|
|
143
157
|
}
|
|
144
158
|
|
|
159
|
+
/**
|
|
160
|
+
* iTerm2 supports spawning separate OS windows via AppleScript
|
|
161
|
+
*/
|
|
162
|
+
supportsWindows(): boolean {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Spawn a new separate OS window with the given options.
|
|
168
|
+
*/
|
|
169
|
+
spawnWindow(options: SpawnOptions): string {
|
|
170
|
+
const envStr = Object.entries(options.env)
|
|
171
|
+
.filter(([k]) => k.startsWith("PI_"))
|
|
172
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
173
|
+
.join(" ");
|
|
174
|
+
|
|
175
|
+
const itermCmd = `cd '${options.cwd}' && ${envStr} ${options.command}`;
|
|
176
|
+
const escapedCmd = itermCmd.replace(/"/g, '\\"');
|
|
177
|
+
|
|
178
|
+
const windowTitle = options.teamName
|
|
179
|
+
? `${options.teamName}: ${options.name}`
|
|
180
|
+
: options.name;
|
|
181
|
+
|
|
182
|
+
const escapedTitle = windowTitle.replace(/"/g, '\\"');
|
|
183
|
+
|
|
184
|
+
const script = `tell application "iTerm2"
|
|
185
|
+
set newWindow to (create window with default profile)
|
|
186
|
+
tell current session of newWindow
|
|
187
|
+
-- Set the session name (tab title)
|
|
188
|
+
set name to "${escapedTitle}"
|
|
189
|
+
-- Set window title via escape sequence (OSC 2)
|
|
190
|
+
-- We use double backslashes for AppleScript to emit a single backslash to the shell
|
|
191
|
+
write text "printf '\\\\033]2;${escapedTitle}\\\\007'"
|
|
192
|
+
-- Execute the command
|
|
193
|
+
write text "cd '${options.cwd}' && ${escapedCmd}"
|
|
194
|
+
return id of newWindow
|
|
195
|
+
end tell
|
|
196
|
+
end tell`;
|
|
197
|
+
|
|
198
|
+
const result = this.runAppleScript(script);
|
|
199
|
+
|
|
200
|
+
if (result.status !== 0) {
|
|
201
|
+
throw new Error(`osascript failed with status ${result.status}: ${result.stderr}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const windowId = result.stdout.toString().trim();
|
|
205
|
+
return `iterm_win_${windowId}`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Set the title of a specific window.
|
|
210
|
+
*/
|
|
211
|
+
setWindowTitle(windowId: string, title: string): void {
|
|
212
|
+
if (!windowId || !windowId.startsWith("iterm_win_")) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const itermId = windowId.replace("iterm_win_", "");
|
|
217
|
+
const escapedTitle = title.replace(/"/g, '\\"');
|
|
218
|
+
|
|
219
|
+
const script = `tell application "iTerm2"
|
|
220
|
+
repeat with aWindow in windows
|
|
221
|
+
if id of aWindow is "${itermId}" then
|
|
222
|
+
tell current session of aWindow
|
|
223
|
+
write text "printf '\\\\033]2;${escapedTitle}\\\\007'"
|
|
224
|
+
end tell
|
|
225
|
+
exit repeat
|
|
226
|
+
end if
|
|
227
|
+
end repeat
|
|
228
|
+
end tell`;
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
this.runAppleScript(script);
|
|
232
|
+
} catch {
|
|
233
|
+
// Silently fail
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Kill/terminate a window.
|
|
239
|
+
*/
|
|
240
|
+
killWindow(windowId: string): void {
|
|
241
|
+
if (!windowId || !windowId.startsWith("iterm_win_")) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const itermId = windowId.replace("iterm_win_", "");
|
|
246
|
+
const script = `tell application "iTerm2"
|
|
247
|
+
repeat with aWindow in windows
|
|
248
|
+
if id of aWindow is "${itermId}" then
|
|
249
|
+
close aWindow
|
|
250
|
+
return "Closed"
|
|
251
|
+
end if
|
|
252
|
+
end repeat
|
|
253
|
+
end tell`;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
this.runAppleScript(script);
|
|
257
|
+
} catch {
|
|
258
|
+
// Silently fail
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Check if a window is still alive/active.
|
|
264
|
+
*/
|
|
265
|
+
isWindowAlive(windowId: string): boolean {
|
|
266
|
+
if (!windowId || !windowId.startsWith("iterm_win_")) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const itermId = windowId.replace("iterm_win_", "");
|
|
271
|
+
const script = `tell application "iTerm2"
|
|
272
|
+
repeat with aWindow in windows
|
|
273
|
+
if id of aWindow is "${itermId}" then
|
|
274
|
+
return "Alive"
|
|
275
|
+
end if
|
|
276
|
+
end repeat
|
|
277
|
+
end tell`;
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
const result = this.runAppleScript(script);
|
|
281
|
+
return result.stdout.includes("Alive");
|
|
282
|
+
} catch {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
145
287
|
/**
|
|
146
288
|
* Set the spawn context (used to restore state when needed)
|
|
147
289
|
*/
|
|
@@ -99,3 +99,22 @@ export function setAdapter(adapter: TerminalAdapter): void {
|
|
|
99
99
|
export function hasTerminalAdapter(): boolean {
|
|
100
100
|
return getTerminalAdapter() !== null;
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check if the current terminal supports spawning separate OS windows.
|
|
105
|
+
*
|
|
106
|
+
* @returns true if the detected terminal supports windows (iTerm2, WezTerm)
|
|
107
|
+
*/
|
|
108
|
+
export function supportsWindows(): boolean {
|
|
109
|
+
const adapter = getTerminalAdapter();
|
|
110
|
+
return adapter?.supportsWindows() ?? false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get the name of the currently detected terminal adapter.
|
|
115
|
+
*
|
|
116
|
+
* @returns The adapter name, or null if none detected
|
|
117
|
+
*/
|
|
118
|
+
export function getTerminalName(): string | null {
|
|
119
|
+
return getTerminalAdapter()?.name ?? null;
|
|
120
|
+
}
|
|
@@ -74,4 +74,39 @@ export class TmuxAdapter implements TerminalAdapter {
|
|
|
74
74
|
// Ignore errors
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* tmux does not support spawning separate OS windows
|
|
80
|
+
*/
|
|
81
|
+
supportsWindows(): boolean {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Not supported - throws error
|
|
87
|
+
*/
|
|
88
|
+
spawnWindow(_options: SpawnOptions): string {
|
|
89
|
+
throw new Error("tmux does not support spawning separate OS windows. Use iTerm2 or WezTerm instead.");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Not supported - no-op
|
|
94
|
+
*/
|
|
95
|
+
setWindowTitle(_windowId: string, _title: string): void {
|
|
96
|
+
// Not supported
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Not supported - no-op
|
|
101
|
+
*/
|
|
102
|
+
killWindow(_windowId: string): void {
|
|
103
|
+
// Not supported
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Not supported - always returns false
|
|
108
|
+
*/
|
|
109
|
+
isWindowAlive(_windowId: string): boolean {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
77
112
|
}
|
|
@@ -163,4 +163,142 @@ export class WezTermAdapter implements TerminalAdapter {
|
|
|
163
163
|
execCommand(weztermBin, ["cli", "set-tab-title", title]);
|
|
164
164
|
} catch {}
|
|
165
165
|
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* WezTerm supports spawning separate OS windows via CLI
|
|
169
|
+
*/
|
|
170
|
+
supportsWindows(): boolean {
|
|
171
|
+
return this.findWeztermBinary() !== null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Spawn a new separate OS window with the given options.
|
|
176
|
+
* Uses `wezterm cli spawn --new-window` and sets the window title.
|
|
177
|
+
*/
|
|
178
|
+
spawnWindow(options: SpawnOptions): string {
|
|
179
|
+
const weztermBin = this.findWeztermBinary();
|
|
180
|
+
if (!weztermBin) {
|
|
181
|
+
throw new Error("WezTerm CLI binary not found.");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const envArgs = Object.entries(options.env)
|
|
185
|
+
.filter(([k]) => k.startsWith("PI_"))
|
|
186
|
+
.map(([k, v]) => `${k}=${v}`);
|
|
187
|
+
|
|
188
|
+
// Format window title as "teamName: agentName" if teamName is provided
|
|
189
|
+
const windowTitle = options.teamName
|
|
190
|
+
? `${options.teamName}: ${options.name}`
|
|
191
|
+
: options.name;
|
|
192
|
+
|
|
193
|
+
// Spawn a new window
|
|
194
|
+
const spawnArgs = [
|
|
195
|
+
"cli", "spawn", "--new-window",
|
|
196
|
+
"--cwd", options.cwd,
|
|
197
|
+
"--", "env", ...envArgs, "sh", "-c", options.command
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
const result = execCommand(weztermBin, spawnArgs);
|
|
201
|
+
if (result.status !== 0) {
|
|
202
|
+
throw new Error(`wezterm spawn-window failed: ${result.stderr}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// The output is the pane ID, we need to find the window ID
|
|
206
|
+
const paneId = result.stdout.trim();
|
|
207
|
+
|
|
208
|
+
// Query to get window ID from pane ID
|
|
209
|
+
const windowId = this.getWindowIdFromPaneId(parseInt(paneId, 10));
|
|
210
|
+
|
|
211
|
+
// Set the window title if we found the window
|
|
212
|
+
if (windowId !== null) {
|
|
213
|
+
this.setWindowTitle(`wezterm_win_${windowId}`, windowTitle);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return `wezterm_win_${windowId || paneId}`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Get window ID from a pane ID by querying WezTerm
|
|
221
|
+
*/
|
|
222
|
+
private getWindowIdFromPaneId(paneId: number): number | null {
|
|
223
|
+
const weztermBin = this.findWeztermBinary();
|
|
224
|
+
if (!weztermBin) return null;
|
|
225
|
+
|
|
226
|
+
const result = execCommand(weztermBin, ["cli", "list", "--format", "json"]);
|
|
227
|
+
if (result.status !== 0) return null;
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const allPanes = JSON.parse(result.stdout);
|
|
231
|
+
const pane = allPanes.find((p: any) => p.pane_id === paneId);
|
|
232
|
+
return pane?.window_id ?? null;
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Set the title of a specific window.
|
|
240
|
+
*/
|
|
241
|
+
setWindowTitle(windowId: string, title: string): void {
|
|
242
|
+
if (!windowId?.startsWith("wezterm_win_")) return;
|
|
243
|
+
|
|
244
|
+
const weztermBin = this.findWeztermBinary();
|
|
245
|
+
if (!weztermBin) return;
|
|
246
|
+
|
|
247
|
+
const weztermWindowId = windowId.replace("wezterm_win_", "");
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
execCommand(weztermBin, ["cli", "set-window-title", "--window-id", weztermWindowId, title]);
|
|
251
|
+
} catch {
|
|
252
|
+
// Silently fail
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Kill/terminate a window.
|
|
258
|
+
*/
|
|
259
|
+
killWindow(windowId: string): void {
|
|
260
|
+
if (!windowId?.startsWith("wezterm_win_")) return;
|
|
261
|
+
|
|
262
|
+
const weztermBin = this.findWeztermBinary();
|
|
263
|
+
if (!weztermBin) return;
|
|
264
|
+
|
|
265
|
+
const weztermWindowId = windowId.replace("wezterm_win_", "");
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
// WezTerm doesn't have a direct kill-window command, so we kill all panes in the window
|
|
269
|
+
const result = execCommand(weztermBin, ["cli", "list", "--format", "json"]);
|
|
270
|
+
if (result.status !== 0) return;
|
|
271
|
+
|
|
272
|
+
const allPanes = JSON.parse(result.stdout);
|
|
273
|
+
const windowPanes = allPanes.filter((p: any) => p.window_id.toString() === weztermWindowId);
|
|
274
|
+
|
|
275
|
+
for (const pane of windowPanes) {
|
|
276
|
+
execCommand(weztermBin, ["cli", "kill-pane", "--pane-id", pane.pane_id.toString()]);
|
|
277
|
+
}
|
|
278
|
+
} catch {
|
|
279
|
+
// Silently fail
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Check if a window is still alive/active.
|
|
285
|
+
*/
|
|
286
|
+
isWindowAlive(windowId: string): boolean {
|
|
287
|
+
if (!windowId?.startsWith("wezterm_win_")) return false;
|
|
288
|
+
|
|
289
|
+
const weztermBin = this.findWeztermBinary();
|
|
290
|
+
if (!weztermBin) return false;
|
|
291
|
+
|
|
292
|
+
const weztermWindowId = windowId.replace("wezterm_win_", "");
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
const result = execCommand(weztermBin, ["cli", "list", "--format", "json"]);
|
|
296
|
+
if (result.status !== 0) return false;
|
|
297
|
+
|
|
298
|
+
const allPanes = JSON.parse(result.stdout);
|
|
299
|
+
return allPanes.some((p: any) => p.window_id.toString() === weztermWindowId);
|
|
300
|
+
} catch {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
166
304
|
}
|
|
@@ -59,4 +59,39 @@ export class ZellijAdapter implements TerminalAdapter {
|
|
|
59
59
|
// Zellij pane titles are set via --name at spawn time
|
|
60
60
|
// No runtime title changing supported
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Zellij does not support spawning separate OS windows
|
|
65
|
+
*/
|
|
66
|
+
supportsWindows(): boolean {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Not supported - throws error
|
|
72
|
+
*/
|
|
73
|
+
spawnWindow(_options: SpawnOptions): string {
|
|
74
|
+
throw new Error("Zellij does not support spawning separate OS windows. Use iTerm2 or WezTerm instead.");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Not supported - no-op
|
|
79
|
+
*/
|
|
80
|
+
setWindowTitle(_windowId: string, _title: string): void {
|
|
81
|
+
// Not supported
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Not supported - no-op
|
|
86
|
+
*/
|
|
87
|
+
killWindow(_windowId: string): void {
|
|
88
|
+
// Not supported
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Not supported - always returns false
|
|
93
|
+
*/
|
|
94
|
+
isWindowAlive(_windowId: string): boolean {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
62
97
|
}
|
package/src/utils/models.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface Member {
|
|
|
5
5
|
model?: string;
|
|
6
6
|
joinedAt: number;
|
|
7
7
|
tmuxPaneId: string;
|
|
8
|
+
windowId?: string;
|
|
8
9
|
cwd: string;
|
|
9
10
|
subscriptions: any[];
|
|
10
11
|
prompt?: string;
|
|
@@ -23,6 +24,7 @@ export interface TeamConfig {
|
|
|
23
24
|
leadSessionId: string;
|
|
24
25
|
members: Member[];
|
|
25
26
|
defaultModel?: string;
|
|
27
|
+
separateWindows?: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface TaskFile {
|
package/src/utils/teams.ts
CHANGED
|
@@ -13,7 +13,8 @@ export function createTeam(
|
|
|
13
13
|
sessionId: string,
|
|
14
14
|
leadAgentId: string,
|
|
15
15
|
description = "",
|
|
16
|
-
defaultModel?: string
|
|
16
|
+
defaultModel?: string,
|
|
17
|
+
separateWindows?: boolean
|
|
17
18
|
): TeamConfig {
|
|
18
19
|
const dir = teamDir(name);
|
|
19
20
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
@@ -39,6 +40,7 @@ export function createTeam(
|
|
|
39
40
|
leadSessionId: sessionId,
|
|
40
41
|
members: [leadMember],
|
|
41
42
|
defaultModel,
|
|
43
|
+
separateWindows,
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
fs.writeFileSync(configPath(name), JSON.stringify(config, null, 2));
|
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
import { spawnSync } from "node:child_process";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Options for spawning a new terminal pane
|
|
11
|
+
* Options for spawning a new terminal pane or window
|
|
12
12
|
*/
|
|
13
13
|
export interface SpawnOptions {
|
|
14
|
-
/** Name/identifier for the pane */
|
|
14
|
+
/** Name/identifier for the pane/window */
|
|
15
15
|
name: string;
|
|
16
|
-
/** Working directory for the new pane */
|
|
16
|
+
/** Working directory for the new pane/window */
|
|
17
17
|
cwd: string;
|
|
18
|
-
/** Command to execute in the pane */
|
|
18
|
+
/** Command to execute in the pane/window */
|
|
19
19
|
command: string;
|
|
20
20
|
/** Environment variables to set (key-value pairs) */
|
|
21
21
|
env: Record<string, string>;
|
|
22
|
+
/** Team name for window title formatting (e.g., "team: agent") */
|
|
23
|
+
teamName?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -70,6 +72,49 @@ export interface TerminalAdapter {
|
|
|
70
72
|
* @param title - The title to set
|
|
71
73
|
*/
|
|
72
74
|
setTitle(title: string): void;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Check if this terminal supports spawning separate OS windows.
|
|
78
|
+
* Terminals like tmux and Zellij only support panes/tabs within a session.
|
|
79
|
+
*
|
|
80
|
+
* @returns true if spawnWindow() is supported
|
|
81
|
+
*/
|
|
82
|
+
supportsWindows(): boolean;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Spawn a new separate OS window with the given options.
|
|
86
|
+
* Only available if supportsWindows() returns true.
|
|
87
|
+
*
|
|
88
|
+
* @param options - Spawn configuration
|
|
89
|
+
* @returns Window ID that can be used for subsequent operations
|
|
90
|
+
* @throws Error if spawn fails or not supported
|
|
91
|
+
*/
|
|
92
|
+
spawnWindow(options: SpawnOptions): string;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set the title of a specific window.
|
|
96
|
+
* Used for identifying windows in the OS window manager.
|
|
97
|
+
*
|
|
98
|
+
* @param windowId - The window ID returned from spawnWindow()
|
|
99
|
+
* @param title - The title to set
|
|
100
|
+
*/
|
|
101
|
+
setWindowTitle(windowId: string, title: string): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Kill/terminate a window.
|
|
105
|
+
* Should be idempotent - no error if window doesn't exist.
|
|
106
|
+
*
|
|
107
|
+
* @param windowId - The window ID returned from spawnWindow()
|
|
108
|
+
*/
|
|
109
|
+
killWindow(windowId: string): void;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Check if a window is still alive/active.
|
|
113
|
+
*
|
|
114
|
+
* @param windowId - The window ID returned from spawnWindow()
|
|
115
|
+
* @returns true if window exists and is active
|
|
116
|
+
*/
|
|
117
|
+
isWindowAlive(windowId: string): boolean;
|
|
73
118
|
}
|
|
74
119
|
|
|
75
120
|
/**
|