-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathinstall.mjs
More file actions
executable file
·93 lines (80 loc) · 2.62 KB
/
install.mjs
File metadata and controls
executable file
·93 lines (80 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
/**
* pi-subagents installer
*
* Usage:
* npx pi-subagents # Install to ~/.pi/agent/extensions/subagent
* npx pi-subagents --remove # Remove the extension
*/
import { execSync } from "node:child_process";
import * as fs from "node:fs";
import * as path from "node:path";
import * as os from "node:os";
const EXTENSION_DIR = path.join(os.homedir(), ".pi", "agent", "extensions", "subagent");
const REPO_URL = "https://github.com/nicobailon/pi-subagents.git";
const args = process.argv.slice(2);
const isRemove = args.includes("--remove") || args.includes("-r");
const isHelp = args.includes("--help") || args.includes("-h");
if (isHelp) {
console.log(`
pi-subagents - Pi extension for delegating tasks to subagents
Usage:
npx pi-subagents Install the extension
npx pi-subagents --remove Remove the extension
npx pi-subagents --help Show this help
Installation directory: ${EXTENSION_DIR}
`);
process.exit(0);
}
if (isRemove) {
if (fs.existsSync(EXTENSION_DIR)) {
console.log(`Removing ${EXTENSION_DIR}...`);
fs.rmSync(EXTENSION_DIR, { recursive: true });
console.log("✓ pi-subagents removed");
} else {
console.log("pi-subagents is not installed");
}
process.exit(0);
}
// Install
console.log("Installing pi-subagents...\n");
// Ensure parent directory exists
const parentDir = path.dirname(EXTENSION_DIR);
if (!fs.existsSync(parentDir)) {
fs.mkdirSync(parentDir, { recursive: true });
}
// Check if already installed
if (fs.existsSync(EXTENSION_DIR)) {
const isGitRepo = fs.existsSync(path.join(EXTENSION_DIR, ".git"));
if (isGitRepo) {
console.log("Updating existing installation...");
try {
execSync("git pull", { cwd: EXTENSION_DIR, stdio: "inherit" });
console.log("\n✓ pi-subagents updated");
} catch (err) {
console.error("Failed to update. Try removing and reinstalling:");
console.error(" npx pi-subagents --remove && npx pi-subagents");
process.exit(1);
}
} else {
console.log(`Directory exists but is not a git repo: ${EXTENSION_DIR}`);
console.log("Remove it first with: npx pi-subagents --remove");
process.exit(1);
}
} else {
// Fresh install
console.log(`Cloning to ${EXTENSION_DIR}...`);
try {
execSync(`git clone ${REPO_URL} "${EXTENSION_DIR}"`, { stdio: "inherit" });
console.log("\n✓ pi-subagents installed");
} catch (err) {
console.error("Failed to clone repository");
process.exit(1);
}
}
console.log(`
The extension is now available in pi. Tools added:
• subagent - Delegate tasks to agents (single, chain, parallel)
• subagent_status - Check async run status
Documentation: ${EXTENSION_DIR}/README.md
`);