@jalaxy33/pi-tmux-subagent 0.1.0 → 0.1.1
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 +2 -0
- package/commands.ts +3 -0
- package/index.ts +9 -0
- package/package.json +2 -2
- package/shared.ts +21 -0
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Forked from [badlogic/pi-subagent](https://github.com/badlogic/pi-subagent). Obs
|
|
|
7
7
|
- Pi
|
|
8
8
|
- tmux
|
|
9
9
|
|
|
10
|
+
Windows is not supported, because tmux has no native Windows build. Run Pi inside WSL2 instead. When tmux is missing, the extension registers no tool or command and reports the reason on session start.
|
|
11
|
+
|
|
10
12
|
## Install
|
|
11
13
|
|
|
12
14
|
```sh
|
package/commands.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type InboxMessage,
|
|
19
19
|
type RunMetadata,
|
|
20
20
|
tmuxSessionExists,
|
|
21
|
+
tmuxUnavailableReason,
|
|
21
22
|
updateMetadata,
|
|
22
23
|
waitForRunShutdown,
|
|
23
24
|
writeMetadata,
|
|
@@ -92,6 +93,8 @@ function generateHandle(): string {
|
|
|
92
93
|
|
|
93
94
|
function spawnSubagent(args: string[], context: CommandContext): string {
|
|
94
95
|
if (process.env.PI_SUBAGENT_RUN_DIR) fail("Nested subagents are disabled");
|
|
96
|
+
const unavailable = tmuxUnavailableReason();
|
|
97
|
+
if (unavailable) fail(unavailable);
|
|
95
98
|
let name: string | undefined;
|
|
96
99
|
let provider = context.provider;
|
|
97
100
|
let model = context.model;
|
package/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type InboxMessage,
|
|
18
18
|
type RunMetadata,
|
|
19
19
|
tmuxSessionExists,
|
|
20
|
+
tmuxUnavailableReason,
|
|
20
21
|
updateMetadata,
|
|
21
22
|
waitForRunShutdown,
|
|
22
23
|
} from "./shared.ts";
|
|
@@ -155,6 +156,14 @@ function buildArgv(params: SubagentToolParams): string[] {
|
|
|
155
156
|
|
|
156
157
|
export default function subagentExtension(pi: ExtensionAPI) {
|
|
157
158
|
const runDir = process.env.PI_SUBAGENT_RUN_DIR;
|
|
159
|
+
const unavailable = runDir ? undefined : tmuxUnavailableReason();
|
|
160
|
+
if (unavailable) {
|
|
161
|
+
// Nothing here can work without tmux, so register no tool or skill and explain once per session.
|
|
162
|
+
pi.on("session_start", (_event, ctx) => {
|
|
163
|
+
if (ctx.hasUI) ctx.ui.notify(unavailable, "warning");
|
|
164
|
+
});
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
158
167
|
if (!runDir) {
|
|
159
168
|
pi.on("resources_discover", () => ({ skillPaths: [join(packageDir, "skills")] }));
|
|
160
169
|
pi.registerTool(subagentTool);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jalaxy33/pi-tmux-subagent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Observable Pi subagents that run in their own tmux session.",
|
|
5
5
|
"keywords": ["pi-package", "pi", "subagent", "tmux"],
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"bin": {
|
|
13
|
-
"subagent": "
|
|
13
|
+
"subagent": "subagent.ts"
|
|
14
14
|
},
|
|
15
15
|
"files": ["index.ts", "commands.ts", "shared.ts", "subagent.ts", "skills"],
|
|
16
16
|
"pi": {
|
package/shared.ts
CHANGED
|
@@ -155,6 +155,26 @@ export function tmuxSessionExists(session: string): boolean {
|
|
|
155
155
|
return spawnSync("tmux", ["has-session", "-t", session], { stdio: "ignore" }).status === 0;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/** Why subagents cannot run here, or undefined when tmux is usable. */
|
|
159
|
+
export function tmuxUnavailableReason(): string | undefined {
|
|
160
|
+
if (process.platform === "win32") {
|
|
161
|
+
return "Subagents need tmux, which has no native Windows build. Run Pi inside WSL2 or on macOS/Linux.";
|
|
162
|
+
}
|
|
163
|
+
const probe = spawnSync("tmux", ["-V"], { encoding: "utf8", timeout: 5000 });
|
|
164
|
+
const code = (probe.error as NodeJS.ErrnoException | undefined)?.code;
|
|
165
|
+
if (code === "ENOENT") {
|
|
166
|
+
return "Subagents need tmux, but it is not installed or not on PATH. Install tmux, then run /reload.";
|
|
167
|
+
}
|
|
168
|
+
if (probe.error) {
|
|
169
|
+
return `Subagents need tmux, but tmux cannot run here: ${probe.error.message}`;
|
|
170
|
+
}
|
|
171
|
+
if (probe.status !== 0) {
|
|
172
|
+
const detail = probe.stderr.trim() || `exit code ${probe.status}`;
|
|
173
|
+
return `Subagents need tmux, but "tmux -V" failed: ${detail}`;
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
158
178
|
/** Start the child pi process for a run in its tmux session. `initialArgs` are only passed on first spawn. */
|
|
159
179
|
export function launchRun(metadata: RunMetadata, initialArgs: string[] = []): void {
|
|
160
180
|
let launcher = "pi";
|
|
@@ -196,6 +216,7 @@ export function launchRun(metadata: RunMetadata, initialArgs: string[] = []): vo
|
|
|
196
216
|
],
|
|
197
217
|
{ encoding: "utf8" },
|
|
198
218
|
);
|
|
219
|
+
if (result.error) throw new Error(result.error.message);
|
|
199
220
|
if (result.status !== 0) throw new Error(result.stderr.trim() || "Failed to create tmux session");
|
|
200
221
|
}
|
|
201
222
|
|