@mdsohail99/opencode-agent-teams 2.0.0 → 2.0.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/bin/cli.js CHANGED
@@ -1,351 +1,351 @@
1
- #!/usr/bin/env node
2
- import fs from "node:fs"
3
- import path from "node:path"
4
- import os from "node:os"
5
- import { fileURLToPath } from "node:url"
6
- import readline from "node:readline/promises"
7
-
8
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
- const rootDir = path.resolve(__dirname, "..")
10
-
11
- const args = process.argv.slice(2)
12
- const binName = path.basename(process.argv[1] || "")
13
-
14
- // ANSI styling
15
- const c = {
16
- reset: "\x1b[0m",
17
- bold: "\x1b[1m",
18
- dim: "\x1b[2m",
19
- red: "\x1b[31m",
20
- green: "\x1b[32m",
21
- yellow: "\x1b[33m",
22
- cyan: "\x1b[36m",
23
- white: "\x1b[37m",
24
- }
25
-
26
- function resolveConfigRoot(globalMode = true) {
27
- if (globalMode) {
28
- if (process.env.OPENCODE_CONFIG_DIR) {
29
- return path.resolve(process.env.OPENCODE_CONFIG_DIR)
30
- }
31
- return path.join(os.homedir(), ".config", "opencode")
32
- }
33
- return process.cwd()
34
- }
35
-
36
- function getShippedAgents() {
37
- const shipped = []
38
- const sourceAgentsDir = path.resolve(rootDir, "agents")
39
- if (!fs.existsSync(sourceAgentsDir)) return shipped
40
-
41
- function scan(dir) {
42
- for (const item of fs.readdirSync(dir, { withFileTypes: true })) {
43
- const p = path.join(dir, item.name)
44
- if (item.isDirectory()) {
45
- scan(p)
46
- } else if (item.isFile() && item.name.endsWith(".md")) {
47
- shipped.push({
48
- name: item.name,
49
- sourcePath: p,
50
- })
51
- }
52
- }
53
- }
54
- scan(sourceAgentsDir)
55
- return shipped
56
- }
57
-
58
- function getStatus(globalMode = true) {
59
- const targetDir = resolveConfigRoot(globalMode)
60
- const configPath = path.resolve(targetDir, "opencode.json")
61
- const agentsDir = globalMode
62
- ? path.resolve(targetDir, "agents")
63
- : path.resolve(targetDir, ".opencode", "agents")
64
-
65
- let configExists = false
66
- let subagentDepth = null
67
- let isPluginRegistered = false
68
- let agentCount = 0
69
-
70
- if (fs.existsSync(configPath)) {
71
- configExists = true
72
- try {
73
- const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"))
74
- subagentDepth = parsed.subagent_depth ?? null
75
- if (Array.isArray(parsed.plugins)) {
76
- isPluginRegistered = parsed.plugins.some(
77
- (p) => typeof p === "string" && (p.includes("agent-teams") || p.includes("orchestration"))
78
- )
79
- }
80
- } catch {}
81
- }
82
-
83
- if (fs.existsSync(agentsDir)) {
84
- try {
85
- agentCount = fs.readdirSync(agentsDir).filter((f) => f.endsWith(".md")).length
86
- } catch {}
87
- }
88
-
89
- const isInstalled = isPluginRegistered && agentCount > 0
90
- return {
91
- targetDir,
92
- configPath,
93
- agentsDir,
94
- configExists,
95
- subagentDepth,
96
- isPluginRegistered,
97
- agentCount,
98
- isInstalled,
99
- }
100
- }
101
-
102
- async function doInstall(globalMode = true) {
103
- const targetDir = resolveConfigRoot(globalMode)
104
- const configPath = path.resolve(targetDir, "opencode.json")
105
- const agentsTargetDir = globalMode
106
- ? path.resolve(targetDir, "agents")
107
- : path.resolve(targetDir, ".opencode", "agents")
108
- const manifestPath = path.resolve(agentsTargetDir, ".agent-teams-manifest.json")
109
-
110
- console.log(`\n${c.cyan}Installing Agent-Teams (${globalMode ? "Global" : "Local"})...${c.reset}`)
111
- console.log(`${c.dim}Target directory: ${targetDir}${c.reset}`)
112
-
113
- let config = {
114
- $schema: "https://opencode.ai/config.json",
115
- subagent_depth: 2,
116
- plugins: [],
117
- }
118
-
119
- if (fs.existsSync(configPath)) {
120
- try {
121
- config = JSON.parse(fs.readFileSync(configPath, "utf-8"))
122
- } catch (err) {
123
- console.warn("Notice: Creating fresh config structure due to parse error.")
124
- }
125
- }
126
-
127
- config.subagent_depth = 2
128
-
129
- const pluginRef = fs.existsSync(path.join(rootDir, "src", "index.ts"))
130
- ? rootDir.replace(/\\/g, "/")
131
- : "@mdsohail99/opencode-agent-teams"
132
-
133
- if (!Array.isArray(config.plugins)) {
134
- config.plugins = []
135
- }
136
- if (!config.plugins.includes(pluginRef)) {
137
- config.plugins.push(pluginRef)
138
- }
139
-
140
- fs.mkdirSync(path.dirname(configPath), { recursive: true })
141
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8")
142
- console.log(` ${c.green}✓${c.reset} Configured opencode.json (subagent_depth: 2, plugin: ${pluginRef})`)
143
-
144
- const shippedAgents = getShippedAgents()
145
- if (shippedAgents.length > 0) {
146
- fs.mkdirSync(agentsTargetDir, { recursive: true })
147
- const installedList = []
148
-
149
- for (const agent of shippedAgents) {
150
- const dest = path.resolve(agentsTargetDir, agent.name)
151
- fs.copyFileSync(agent.sourcePath, dest)
152
- installedList.push(agent.name)
153
- }
154
-
155
- fs.writeFileSync(
156
- manifestPath,
157
- JSON.stringify({ plugin: "@mdsohail99/opencode-agent-teams", version: "2.0.0", files: installedList }, null, 2),
158
- "utf-8"
159
- )
160
- console.log(` ${c.green}✓${c.reset} Installed ${installedList.length} curated agents into ${agentsTargetDir}`)
161
- }
162
-
163
- console.log(`\n${c.green}${c.bold}✓ Setup complete!${c.reset} Launch OpenCode with ${c.bold}opencode${c.reset} and select agent-teams.\n`)
164
- }
165
-
166
- async function doUninstall(globalMode = true) {
167
- const targetDir = resolveConfigRoot(globalMode)
168
- const configPath = path.resolve(targetDir, "opencode.json")
169
- const agentsTargetDir = globalMode
170
- ? path.resolve(targetDir, "agents")
171
- : path.resolve(targetDir, ".opencode", "agents")
172
- const manifestPath = path.resolve(agentsTargetDir, ".agent-teams-manifest.json")
173
-
174
- console.log(`\n${c.yellow}Uninstalling Agent-Teams (${globalMode ? "Global" : "Local"})...${c.reset}`)
175
- console.log(`${c.dim}Target directory: ${targetDir}${c.reset}`)
176
-
177
- if (fs.existsSync(configPath)) {
178
- try {
179
- const raw = fs.readFileSync(configPath, "utf-8")
180
- const config = JSON.parse(raw)
181
- if (Array.isArray(config.plugins)) {
182
- const beforeCount = config.plugins.length
183
- config.plugins = config.plugins.filter((p) => {
184
- if (typeof p === "string" && (p.includes("agent-teams") || p.includes("orchestration"))) return false
185
- return true
186
- })
187
- if (config.plugins.length !== beforeCount) {
188
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8")
189
- console.log(` ${c.green}✓${c.reset} Removed plugin from opencode.json`)
190
- }
191
- }
192
- } catch {}
193
- }
194
-
195
- let filesRemoved = 0
196
- if (fs.existsSync(agentsTargetDir)) {
197
- let filesToDelete = []
198
- if (fs.existsSync(manifestPath)) {
199
- try {
200
- const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"))
201
- if (Array.isArray(manifest.files)) filesToDelete = manifest.files
202
- } catch {}
203
- }
204
- if (filesToDelete.length === 0) {
205
- filesToDelete = getShippedAgents().map((a) => a.name)
206
- }
207
-
208
- for (const file of filesToDelete) {
209
- const targetFile = path.resolve(agentsTargetDir, file)
210
- if (fs.existsSync(targetFile)) {
211
- try {
212
- fs.unlinkSync(targetFile)
213
- filesRemoved++
214
- } catch {}
215
- }
216
- }
217
-
218
- if (fs.existsSync(manifestPath)) {
219
- try {
220
- fs.unlinkSync(manifestPath)
221
- } catch {}
222
- }
223
-
224
- try {
225
- const remaining = fs.readdirSync(agentsTargetDir)
226
- if (remaining.length === 0) fs.rmdirSync(agentsTargetDir)
227
- } catch {}
228
-
229
- console.log(` ${c.green}✓${c.reset} Removed ${filesRemoved} agent markdown files from ${agentsTargetDir}`)
230
- }
231
-
232
- console.log(`\n${c.green}${c.bold}✓ Uninstall complete!${c.reset} Agent-Teams cleanly removed.\n`)
233
- }
234
-
235
- function printStatus() {
236
- const globalStat = getStatus(true)
237
- const localStat = getStatus(false)
238
-
239
- console.log(`\n${c.bold}${c.cyan}Agent-Teams v2 Status Report${c.reset}\n`)
240
- console.log(`${c.bold}Global Configuration (~/.config/opencode):${c.reset}`)
241
- console.log(` Status: ${globalStat.isInstalled ? c.green + "Installed (Active)" + c.reset : c.dim + "Not Installed" + c.reset}`)
242
- console.log(` Config Path: ${globalStat.configPath}`)
243
- console.log(` Subagent Depth: ${globalStat.subagentDepth ?? "not set"}`)
244
- console.log(` Plugin Linked: ${globalStat.isPluginRegistered ? c.green + "Yes" + c.reset : "No"}`)
245
- console.log(` Agents Count: ${globalStat.agentCount} agents in ${globalStat.agentsDir}`)
246
-
247
- console.log(`\n${c.bold}Local Directory Configuration (.opencode):${c.reset}`)
248
- console.log(` Status: ${localStat.isInstalled ? c.green + "Installed (Local Active)" + c.reset : c.dim + "Not Installed" + c.reset}`)
249
- console.log(` Config Path: ${localStat.configPath}`)
250
- console.log(` Plugin Linked: ${localStat.isPluginRegistered ? c.green + "Yes" + c.reset : "No"}`)
251
- console.log(` Agents Count: ${localStat.agentCount} agents\n`)
252
- }
253
-
254
- async function runInteractiveMenu() {
255
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
256
-
257
- while (true) {
258
- const stat = getStatus(true)
259
- console.log(`
260
- ${c.bold}${c.cyan}┌────────────────────────────────────────────────────────┐${c.reset}
261
- ${c.bold}${c.cyan}│ Agent-Teams v2 Setup & Management │${c.reset}
262
- ${c.bold}${c.cyan}└────────────────────────────────────────────────────────┘${c.reset}
263
- ${c.dim}Global Config:${c.reset} ${stat.targetDir}
264
- ${c.dim}Status:${c.reset} ${stat.isInstalled ? c.green + "● Installed & Active" + c.reset : c.yellow + "○ Not Installed" + c.reset} ${stat.isInstalled ? `(Agents: ${stat.agentCount}, Depth: ${stat.subagentDepth})` : ""}
265
-
266
- ${c.cyan}1${c.reset} Install / Update Agent-Teams ${c.green}(Global - Recommended)${c.reset}
267
- ${c.cyan}2${c.reset} Install to Current Project Only ${c.dim}(Local)${c.reset}
268
- ${c.cyan}3${c.reset} Inspect Status & Registered Agents
269
- ${c.cyan}4${c.reset} Uninstall Agent-Teams
270
- ${c.cyan}5${c.reset} Exit
271
- `)
272
-
273
- const choice = (await rl.question(` ${c.bold}Choose option [1-5]:${c.reset} `)).trim()
274
-
275
- if (choice === "1") {
276
- await doInstall(true)
277
- } else if (choice === "2") {
278
- await doInstall(false)
279
- } else if (choice === "3") {
280
- printStatus()
281
- } else if (choice === "4") {
282
- await doUninstall(true)
283
- } else if (choice === "5" || choice.toLowerCase() === "q" || choice.toLowerCase() === "exit") {
284
- console.log(`\n${c.dim}Goodbye!${c.reset}\n`)
285
- break
286
- } else {
287
- console.log(`\n${c.red}Invalid choice. Please select 1-5.${c.reset}`)
288
- }
289
-
290
- await rl.question(`\n${c.dim}Press Enter to return to menu...${c.reset}`)
291
- }
292
-
293
- rl.close()
294
- }
295
-
296
- // -------------------------------------------------------------
297
- // CLI EXECUTION DISPATCHER
298
- // -------------------------------------------------------------
299
- const isUninstallCommand =
300
- binName.includes("uninstall") ||
301
- args.includes("uninstall") ||
302
- args.includes("--uninstall") ||
303
- args.includes("-u")
304
-
305
- const isLocal = args.includes("--local") || args.includes("-l")
306
- const isGlobal = !isLocal
307
- const isHelp = args.includes("--help") || args.includes("-h")
308
- const isStatus = args.includes("status") || args.includes("--status")
309
- const isInstallExplicit = args.includes("install") || args.includes("--install")
310
-
311
- if (isHelp) {
312
- console.log(`
313
- Agent-Teams v2 CLI for OpenCode
314
-
315
- Usage:
316
- npx @mdsohail99/opencode-agent-teams Launch interactive menu (default)
317
- npx @mdsohail99/opencode-agent-teams install [options] Install Agent-Teams plugin and agents
318
- npx @mdsohail99/opencode-agent-teams uninstall [options] Uninstall Agent-Teams cleanly
319
- npx @mdsohail99/opencode-agent-teams status Inspect current status
320
-
321
- Options:
322
- -l, --local Target current project directory only instead of global OpenCode (~/.config/opencode)
323
- -u, --uninstall Uninstall Agent-Teams and remove associated agents
324
- -h, --help Show this help message
325
- `)
326
- process.exit(0)
327
- }
328
-
329
- if (isStatus) {
330
- printStatus()
331
- process.exit(0)
332
- }
333
-
334
- if (isUninstallCommand) {
335
- await doUninstall(isGlobal)
336
- process.exit(0)
337
- }
338
-
339
- if (isInstallExplicit) {
340
- await doInstall(isGlobal)
341
- process.exit(0)
342
- }
343
-
344
- // If invoked without arguments:
345
- // In an interactive TTY -> launch interactive menu!
346
- // In a non-interactive/scripted environment -> default to install
347
- if (process.stdin.isTTY && args.length === 0) {
348
- await runInteractiveMenu()
349
- } else {
350
- await doInstall(isGlobal)
351
- }
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs"
3
+ import path from "node:path"
4
+ import os from "node:os"
5
+ import { fileURLToPath } from "node:url"
6
+ import readline from "node:readline/promises"
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
9
+ const rootDir = path.resolve(__dirname, "..")
10
+
11
+ const args = process.argv.slice(2)
12
+ const binName = path.basename(process.argv[1] || "")
13
+
14
+ // ANSI styling
15
+ const c = {
16
+ reset: "\x1b[0m",
17
+ bold: "\x1b[1m",
18
+ dim: "\x1b[2m",
19
+ red: "\x1b[31m",
20
+ green: "\x1b[32m",
21
+ yellow: "\x1b[33m",
22
+ cyan: "\x1b[36m",
23
+ white: "\x1b[37m",
24
+ }
25
+
26
+ function resolveConfigRoot(globalMode = true) {
27
+ if (globalMode) {
28
+ if (process.env.OPENCODE_CONFIG_DIR) {
29
+ return path.resolve(process.env.OPENCODE_CONFIG_DIR)
30
+ }
31
+ return path.join(os.homedir(), ".config", "opencode")
32
+ }
33
+ return process.cwd()
34
+ }
35
+
36
+ function getShippedAgents() {
37
+ const shipped = []
38
+ const sourceAgentsDir = path.resolve(rootDir, "agents")
39
+ if (!fs.existsSync(sourceAgentsDir)) return shipped
40
+
41
+ function scan(dir) {
42
+ for (const item of fs.readdirSync(dir, { withFileTypes: true })) {
43
+ const p = path.join(dir, item.name)
44
+ if (item.isDirectory()) {
45
+ scan(p)
46
+ } else if (item.isFile() && item.name.endsWith(".md")) {
47
+ shipped.push({
48
+ name: item.name,
49
+ sourcePath: p,
50
+ })
51
+ }
52
+ }
53
+ }
54
+ scan(sourceAgentsDir)
55
+ return shipped
56
+ }
57
+
58
+ function getStatus(globalMode = true) {
59
+ const targetDir = resolveConfigRoot(globalMode)
60
+ const configPath = path.resolve(targetDir, "opencode.json")
61
+ const agentsDir = globalMode
62
+ ? path.resolve(targetDir, "agents")
63
+ : path.resolve(targetDir, ".opencode", "agents")
64
+
65
+ let configExists = false
66
+ let subagentDepth = null
67
+ let isPluginRegistered = false
68
+ let agentCount = 0
69
+
70
+ if (fs.existsSync(configPath)) {
71
+ configExists = true
72
+ try {
73
+ const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"))
74
+ subagentDepth = parsed.subagent_depth ?? null
75
+ if (Array.isArray(parsed.plugins)) {
76
+ isPluginRegistered = parsed.plugins.some(
77
+ (p) => typeof p === "string" && (p.includes("agent-teams") || p.includes("orchestration"))
78
+ )
79
+ }
80
+ } catch {}
81
+ }
82
+
83
+ if (fs.existsSync(agentsDir)) {
84
+ try {
85
+ agentCount = fs.readdirSync(agentsDir).filter((f) => f.endsWith(".md")).length
86
+ } catch {}
87
+ }
88
+
89
+ const isInstalled = isPluginRegistered && agentCount > 0
90
+ return {
91
+ targetDir,
92
+ configPath,
93
+ agentsDir,
94
+ configExists,
95
+ subagentDepth,
96
+ isPluginRegistered,
97
+ agentCount,
98
+ isInstalled,
99
+ }
100
+ }
101
+
102
+ async function doInstall(globalMode = true) {
103
+ const targetDir = resolveConfigRoot(globalMode)
104
+ const configPath = path.resolve(targetDir, "opencode.json")
105
+ const agentsTargetDir = globalMode
106
+ ? path.resolve(targetDir, "agents")
107
+ : path.resolve(targetDir, ".opencode", "agents")
108
+ const manifestPath = path.resolve(agentsTargetDir, ".agent-teams-manifest.json")
109
+
110
+ console.log(`\n${c.cyan}Installing Agent-Teams (${globalMode ? "Global" : "Local"})...${c.reset}`)
111
+ console.log(`${c.dim}Target directory: ${targetDir}${c.reset}`)
112
+
113
+ let config = {
114
+ $schema: "https://opencode.ai/config.json",
115
+ subagent_depth: 2,
116
+ plugins: [],
117
+ }
118
+
119
+ if (fs.existsSync(configPath)) {
120
+ try {
121
+ config = JSON.parse(fs.readFileSync(configPath, "utf-8"))
122
+ } catch (err) {
123
+ console.warn("Notice: Creating fresh config structure due to parse error.")
124
+ }
125
+ }
126
+
127
+ config.subagent_depth = 2
128
+
129
+ const pluginRef = fs.existsSync(path.join(rootDir, "src", "index.ts"))
130
+ ? rootDir.replace(/\\/g, "/")
131
+ : "@mdsohail99/opencode-agent-teams"
132
+
133
+ if (!Array.isArray(config.plugins)) {
134
+ config.plugins = []
135
+ }
136
+ if (!config.plugins.includes(pluginRef)) {
137
+ config.plugins.push(pluginRef)
138
+ }
139
+
140
+ fs.mkdirSync(path.dirname(configPath), { recursive: true })
141
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8")
142
+ console.log(` ${c.green}✓${c.reset} Configured opencode.json (subagent_depth: 2, plugin: ${pluginRef})`)
143
+
144
+ const shippedAgents = getShippedAgents()
145
+ if (shippedAgents.length > 0) {
146
+ fs.mkdirSync(agentsTargetDir, { recursive: true })
147
+ const installedList = []
148
+
149
+ for (const agent of shippedAgents) {
150
+ const dest = path.resolve(agentsTargetDir, agent.name)
151
+ fs.copyFileSync(agent.sourcePath, dest)
152
+ installedList.push(agent.name)
153
+ }
154
+
155
+ fs.writeFileSync(
156
+ manifestPath,
157
+ JSON.stringify({ plugin: "@mdsohail99/opencode-agent-teams", version: "2.0.0", files: installedList }, null, 2),
158
+ "utf-8"
159
+ )
160
+ console.log(` ${c.green}✓${c.reset} Installed ${installedList.length} curated agents into ${agentsTargetDir}`)
161
+ }
162
+
163
+ console.log(`\n${c.green}${c.bold}✓ Setup complete!${c.reset} Launch OpenCode with ${c.bold}opencode${c.reset} and select agent-teams.\n`)
164
+ }
165
+
166
+ async function doUninstall(globalMode = true) {
167
+ const targetDir = resolveConfigRoot(globalMode)
168
+ const configPath = path.resolve(targetDir, "opencode.json")
169
+ const agentsTargetDir = globalMode
170
+ ? path.resolve(targetDir, "agents")
171
+ : path.resolve(targetDir, ".opencode", "agents")
172
+ const manifestPath = path.resolve(agentsTargetDir, ".agent-teams-manifest.json")
173
+
174
+ console.log(`\n${c.yellow}Uninstalling Agent-Teams (${globalMode ? "Global" : "Local"})...${c.reset}`)
175
+ console.log(`${c.dim}Target directory: ${targetDir}${c.reset}`)
176
+
177
+ if (fs.existsSync(configPath)) {
178
+ try {
179
+ const raw = fs.readFileSync(configPath, "utf-8")
180
+ const config = JSON.parse(raw)
181
+ if (Array.isArray(config.plugins)) {
182
+ const beforeCount = config.plugins.length
183
+ config.plugins = config.plugins.filter((p) => {
184
+ if (typeof p === "string" && (p.includes("agent-teams") || p.includes("orchestration"))) return false
185
+ return true
186
+ })
187
+ if (config.plugins.length !== beforeCount) {
188
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8")
189
+ console.log(` ${c.green}✓${c.reset} Removed plugin from opencode.json`)
190
+ }
191
+ }
192
+ } catch {}
193
+ }
194
+
195
+ let filesRemoved = 0
196
+ if (fs.existsSync(agentsTargetDir)) {
197
+ let filesToDelete = []
198
+ if (fs.existsSync(manifestPath)) {
199
+ try {
200
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"))
201
+ if (Array.isArray(manifest.files)) filesToDelete = manifest.files
202
+ } catch {}
203
+ }
204
+ if (filesToDelete.length === 0) {
205
+ filesToDelete = getShippedAgents().map((a) => a.name)
206
+ }
207
+
208
+ for (const file of filesToDelete) {
209
+ const targetFile = path.resolve(agentsTargetDir, file)
210
+ if (fs.existsSync(targetFile)) {
211
+ try {
212
+ fs.unlinkSync(targetFile)
213
+ filesRemoved++
214
+ } catch {}
215
+ }
216
+ }
217
+
218
+ if (fs.existsSync(manifestPath)) {
219
+ try {
220
+ fs.unlinkSync(manifestPath)
221
+ } catch {}
222
+ }
223
+
224
+ try {
225
+ const remaining = fs.readdirSync(agentsTargetDir)
226
+ if (remaining.length === 0) fs.rmdirSync(agentsTargetDir)
227
+ } catch {}
228
+
229
+ console.log(` ${c.green}✓${c.reset} Removed ${filesRemoved} agent markdown files from ${agentsTargetDir}`)
230
+ }
231
+
232
+ console.log(`\n${c.green}${c.bold}✓ Uninstall complete!${c.reset} Agent-Teams cleanly removed.\n`)
233
+ }
234
+
235
+ function printStatus() {
236
+ const globalStat = getStatus(true)
237
+ const localStat = getStatus(false)
238
+
239
+ console.log(`\n${c.bold}${c.cyan}Agent-Teams v2 Status Report${c.reset}\n`)
240
+ console.log(`${c.bold}Global Configuration (~/.config/opencode):${c.reset}`)
241
+ console.log(` Status: ${globalStat.isInstalled ? c.green + "Installed (Active)" + c.reset : c.dim + "Not Installed" + c.reset}`)
242
+ console.log(` Config Path: ${globalStat.configPath}`)
243
+ console.log(` Subagent Depth: ${globalStat.subagentDepth ?? "not set"}`)
244
+ console.log(` Plugin Linked: ${globalStat.isPluginRegistered ? c.green + "Yes" + c.reset : "No"}`)
245
+ console.log(` Agents Count: ${globalStat.agentCount} agents in ${globalStat.agentsDir}`)
246
+
247
+ console.log(`\n${c.bold}Local Directory Configuration (.opencode):${c.reset}`)
248
+ console.log(` Status: ${localStat.isInstalled ? c.green + "Installed (Local Active)" + c.reset : c.dim + "Not Installed" + c.reset}`)
249
+ console.log(` Config Path: ${localStat.configPath}`)
250
+ console.log(` Plugin Linked: ${localStat.isPluginRegistered ? c.green + "Yes" + c.reset : "No"}`)
251
+ console.log(` Agents Count: ${localStat.agentCount} agents\n`)
252
+ }
253
+
254
+ async function runInteractiveMenu() {
255
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
256
+
257
+ while (true) {
258
+ const stat = getStatus(true)
259
+ console.log(`
260
+ ${c.bold}${c.cyan}┌────────────────────────────────────────────────────────┐${c.reset}
261
+ ${c.bold}${c.cyan}│ Agent-Teams v2 Setup & Management │${c.reset}
262
+ ${c.bold}${c.cyan}└────────────────────────────────────────────────────────┘${c.reset}
263
+ ${c.dim}Global Config:${c.reset} ${stat.targetDir}
264
+ ${c.dim}Status:${c.reset} ${stat.isInstalled ? c.green + "● Installed & Active" + c.reset : c.yellow + "○ Not Installed" + c.reset} ${stat.isInstalled ? `(Agents: ${stat.agentCount}, Depth: ${stat.subagentDepth})` : ""}
265
+
266
+ ${c.cyan}1${c.reset} Install / Update Agent-Teams ${c.green}(Global - Recommended)${c.reset}
267
+ ${c.cyan}2${c.reset} Install to Current Project Only ${c.dim}(Local)${c.reset}
268
+ ${c.cyan}3${c.reset} Inspect Status & Registered Agents
269
+ ${c.cyan}4${c.reset} Uninstall Agent-Teams
270
+ ${c.cyan}5${c.reset} Exit
271
+ `)
272
+
273
+ const choice = (await rl.question(` ${c.bold}Choose option [1-5]:${c.reset} `)).trim()
274
+
275
+ if (choice === "1") {
276
+ await doInstall(true)
277
+ } else if (choice === "2") {
278
+ await doInstall(false)
279
+ } else if (choice === "3") {
280
+ printStatus()
281
+ } else if (choice === "4") {
282
+ await doUninstall(true)
283
+ } else if (choice === "5" || choice.toLowerCase() === "q" || choice.toLowerCase() === "exit") {
284
+ console.log(`\n${c.dim}Goodbye!${c.reset}\n`)
285
+ break
286
+ } else {
287
+ console.log(`\n${c.red}Invalid choice. Please select 1-5.${c.reset}`)
288
+ }
289
+
290
+ await rl.question(`\n${c.dim}Press Enter to return to menu...${c.reset}`)
291
+ }
292
+
293
+ rl.close()
294
+ }
295
+
296
+ // -------------------------------------------------------------
297
+ // CLI EXECUTION DISPATCHER
298
+ // -------------------------------------------------------------
299
+ const isUninstallCommand =
300
+ binName.includes("uninstall") ||
301
+ args.includes("uninstall") ||
302
+ args.includes("--uninstall") ||
303
+ args.includes("-u")
304
+
305
+ const isLocal = args.includes("--local") || args.includes("-l")
306
+ const isGlobal = !isLocal
307
+ const isHelp = args.includes("--help") || args.includes("-h")
308
+ const isStatus = args.includes("status") || args.includes("--status")
309
+ const isInstallExplicit = args.includes("install") || args.includes("--install")
310
+
311
+ if (isHelp) {
312
+ console.log(`
313
+ Agent-Teams v2 CLI for OpenCode
314
+
315
+ Usage:
316
+ npx @mdsohail99/opencode-agent-teams Launch interactive menu (default)
317
+ npx @mdsohail99/opencode-agent-teams install [options] Install Agent-Teams plugin and agents
318
+ npx @mdsohail99/opencode-agent-teams uninstall [options] Uninstall Agent-Teams cleanly
319
+ npx @mdsohail99/opencode-agent-teams status Inspect current status
320
+
321
+ Options:
322
+ -l, --local Target current project directory only instead of global OpenCode (~/.config/opencode)
323
+ -u, --uninstall Uninstall Agent-Teams and remove associated agents
324
+ -h, --help Show this help message
325
+ `)
326
+ process.exit(0)
327
+ }
328
+
329
+ if (isStatus) {
330
+ printStatus()
331
+ process.exit(0)
332
+ }
333
+
334
+ if (isUninstallCommand) {
335
+ await doUninstall(isGlobal)
336
+ process.exit(0)
337
+ }
338
+
339
+ if (isInstallExplicit) {
340
+ await doInstall(isGlobal)
341
+ process.exit(0)
342
+ }
343
+
344
+ // If invoked without arguments:
345
+ // In an interactive TTY -> launch interactive menu!
346
+ // In a non-interactive/scripted environment -> default to install
347
+ if (process.stdin.isTTY && args.length === 0) {
348
+ await runInteractiveMenu()
349
+ } else {
350
+ await doInstall(isGlobal)
351
+ }