opencode-agents 1.1.1 → 1.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.
- package/dist/index.js +61 -76
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/src/commands/add.ts +30 -27
- package/src/commands/list.ts +9 -9
- package/src/core/installer.ts +0 -3
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { AgentPlatform, InstallOptions, AgentFile } from '../types/index.js
|
|
|
8
8
|
import { basename, join } from 'path';
|
|
9
9
|
import { mkdtempSync } from 'fs';
|
|
10
10
|
import degit from 'degit';
|
|
11
|
-
import { showLogo,
|
|
11
|
+
import { showLogo, S_BAR, S_BRANCH, S_BRANCH_END, S_BULLET, S_STEP_ACTIVE } from '../utils/ui.js';
|
|
12
12
|
|
|
13
13
|
interface AddCommandOptions {
|
|
14
14
|
global: boolean | undefined;
|
|
@@ -90,8 +90,9 @@ export async function addCommand(source: string, options: AddCommandOptions): Pr
|
|
|
90
90
|
isGlobal = await promptInstallLocation();
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
//
|
|
94
|
-
|
|
93
|
+
// 使用统一的树状结构
|
|
94
|
+
console.log(`${S_STEP_ACTIVE} ${pc.cyan('Source:')} ${pc.dim(`https://github.com/${source}.git`)}`);
|
|
95
|
+
console.log(S_BAR);
|
|
95
96
|
|
|
96
97
|
const s = p.spinner();
|
|
97
98
|
s.start('Cloning repository...');
|
|
@@ -99,30 +100,34 @@ export async function addCommand(source: string, options: AddCommandOptions): Pr
|
|
|
99
100
|
let tempDir: string;
|
|
100
101
|
try {
|
|
101
102
|
tempDir = await fetchSource(source);
|
|
102
|
-
s.stop('Repository cloned
|
|
103
|
+
s.stop(`${pc.green('✓')} Repository cloned`);
|
|
103
104
|
} catch (err) {
|
|
104
|
-
s.stop('Failed to clone repository
|
|
105
|
-
error(`Failed to fetch source: ${err instanceof Error ? err.message : String(err)}`);
|
|
105
|
+
s.stop(`${pc.red('✗')} Failed to clone repository`);
|
|
106
|
+
p.log.error(`Failed to fetch source: ${err instanceof Error ? err.message : String(err)}`);
|
|
106
107
|
process.exit(1);
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
console.log(S_BAR);
|
|
111
|
+
|
|
109
112
|
// 步骤 2: 发现 agents
|
|
110
113
|
s.start('Discovering agents...');
|
|
111
114
|
let agents: AgentFile[];
|
|
112
115
|
try {
|
|
113
116
|
agents = await discoverFromDirectory(tempDir);
|
|
114
|
-
s.stop(
|
|
117
|
+
s.stop(`${pc.green('✓')} Found ${agents.length} agent(s)`);
|
|
115
118
|
} catch (err) {
|
|
116
|
-
s.stop('Failed to discover agents
|
|
117
|
-
error(`Failed to discover agents: ${err instanceof Error ? err.message : String(err)}`);
|
|
119
|
+
s.stop(`${pc.red('✗')} Failed to discover agents`);
|
|
120
|
+
p.log.error(`Failed to discover agents: ${err instanceof Error ? err.message : String(err)}`);
|
|
118
121
|
process.exit(1);
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
if (agents.length === 0) {
|
|
122
|
-
error('No agents found in the source');
|
|
125
|
+
p.log.error('No agents found in the source');
|
|
123
126
|
process.exit(1);
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
console.log(S_BAR);
|
|
130
|
+
|
|
126
131
|
// 步骤 3: 选择 agents
|
|
127
132
|
let selectedAgents: AgentFile[];
|
|
128
133
|
if (options.yes) {
|
|
@@ -136,18 +141,18 @@ export async function addCommand(source: string, options: AddCommandOptions): Pr
|
|
|
136
141
|
process.exit(0);
|
|
137
142
|
}
|
|
138
143
|
|
|
139
|
-
// 显示选中的 agents
|
|
140
|
-
console.log();
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
144
|
+
// 显示选中的 agents - 作为树的分支
|
|
145
|
+
console.log(`${S_BAR} ${S_BRANCH} ${pc.dim('Selected:')}`);
|
|
146
|
+
selectedAgents.forEach((agent, index) => {
|
|
147
|
+
const isLast = index === selectedAgents.length - 1;
|
|
148
|
+
const prefix = isLast ? S_BRANCH_END : S_BRANCH;
|
|
149
|
+
const name = agent.agent.name || basename(agent.path, '.md');
|
|
150
|
+
console.log(`${S_BAR} ${isLast ? ' ' : S_BAR} ${prefix} ${S_BULLET} ${pc.bold(name)}`);
|
|
151
|
+
});
|
|
148
152
|
|
|
149
153
|
// 步骤 4: 安装
|
|
150
|
-
|
|
154
|
+
console.log(S_BAR);
|
|
155
|
+
s.start('Installing agents...');
|
|
151
156
|
|
|
152
157
|
try {
|
|
153
158
|
let platforms: AgentPlatform[];
|
|
@@ -171,17 +176,15 @@ export async function addCommand(source: string, options: AddCommandOptions): Pr
|
|
|
171
176
|
|
|
172
177
|
await installAgent(installOptions);
|
|
173
178
|
|
|
174
|
-
s.stop(pc.green(
|
|
179
|
+
s.stop(`${pc.green('✓')} Successfully installed ${selectedAgents.length} agent(s)`);
|
|
175
180
|
|
|
176
181
|
console.log();
|
|
177
|
-
|
|
178
|
-
console.log();
|
|
179
|
-
console.log(pc.dim(' Try:'));
|
|
180
|
-
console.log(pc.dim(` npx opencode-agents list`));
|
|
182
|
+
console.log(pc.dim(' Next steps:'));
|
|
183
|
+
console.log(pc.dim(` npx opencode-agents list View installed agents`));
|
|
181
184
|
console.log();
|
|
182
185
|
} catch (err) {
|
|
183
|
-
s.stop('Installation failed
|
|
184
|
-
error(`Failed to install agent: ${err instanceof Error ? err.message : String(err)}`);
|
|
186
|
+
s.stop(`${pc.red('✗')} Installation failed`);
|
|
187
|
+
p.log.error(`Failed to install agent: ${err instanceof Error ? err.message : String(err)}`);
|
|
185
188
|
process.exit(1);
|
|
186
189
|
} finally {
|
|
187
190
|
if (existsSync(tempDir) && tempDir.startsWith(tmpdir())) {
|
package/src/commands/list.ts
CHANGED
|
@@ -32,24 +32,24 @@ export async function listCommand(options: ListCommandOptions): Promise<void> {
|
|
|
32
32
|
|
|
33
33
|
hasAnyAgents = true;
|
|
34
34
|
|
|
35
|
-
console.log(pc.bold(pc.cyan(
|
|
35
|
+
console.log(pc.bold(pc.cyan(`◆ ${platform} agents`)));
|
|
36
36
|
console.log();
|
|
37
37
|
|
|
38
38
|
// 项目级别
|
|
39
39
|
if (projectAgents.length > 0) {
|
|
40
|
-
console.log(` ${S_BRANCH} ${pc.dim('Project')} ${pc.dim('(./.opencode/agents/)')}`);
|
|
40
|
+
console.log(` ${globalAgents.length > 0 ? S_BRANCH : S_BRANCH_END} ${pc.dim('Project')} ${pc.dim('(./.opencode/agents/)')}`);
|
|
41
41
|
|
|
42
42
|
projectAgents.forEach((agent, index) => {
|
|
43
|
-
const isLast = index === projectAgents.length - 1
|
|
43
|
+
const isLast = index === projectAgents.length - 1;
|
|
44
44
|
const prefix = isLast ? S_BRANCH_END : S_BRANCH;
|
|
45
45
|
|
|
46
46
|
const name = agent.agent.name || agent.path.split(/[/\\]/).pop()?.replace('.md', '') || 'unknown';
|
|
47
47
|
const mode = agent.agent.mode || 'subagent';
|
|
48
48
|
|
|
49
|
-
console.log(` ${S_BAR} ${prefix} ${S_BULLET} ${pc.bold(name)} ${pc.dim(`[${mode}]`)}`);
|
|
49
|
+
console.log(` ${globalAgents.length > 0 ? S_BAR : ' '} ${prefix} ${S_BULLET} ${pc.bold(name)} ${pc.dim(`[${mode}]`)}`);
|
|
50
50
|
|
|
51
51
|
if (agent.agent.description) {
|
|
52
|
-
console.log(` ${S_BAR} ${isLast ? ' ' : `${S_BAR} `} ${pc.dim(agent.agent.description)}`);
|
|
52
|
+
console.log(` ${globalAgents.length > 0 ? S_BAR : ' '} ${isLast ? ' ' : `${S_BAR} `} ${pc.dim(agent.agent.description)}`);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -58,7 +58,7 @@ export async function listCommand(options: ListCommandOptions): Promise<void> {
|
|
|
58
58
|
|
|
59
59
|
// 全局级别
|
|
60
60
|
if (globalAgents.length > 0) {
|
|
61
|
-
console.log(` ${
|
|
61
|
+
console.log(` ${S_BRANCH_END} ${pc.dim('Global')} ${pc.dim('(~/.config/opencode/agents/)')}`);
|
|
62
62
|
|
|
63
63
|
globalAgents.forEach((agent, index) => {
|
|
64
64
|
const isLast = index === globalAgents.length - 1;
|
|
@@ -67,10 +67,10 @@ export async function listCommand(options: ListCommandOptions): Promise<void> {
|
|
|
67
67
|
const name = agent.agent.name || agent.path.split(/[/\\]/).pop()?.replace('.md', '') || 'unknown';
|
|
68
68
|
const mode = agent.agent.mode || 'subagent';
|
|
69
69
|
|
|
70
|
-
console.log(`
|
|
70
|
+
console.log(` ${prefix} ${S_BULLET} ${pc.bold(name)} ${pc.dim(`[${mode}]`)}`);
|
|
71
71
|
|
|
72
72
|
if (agent.agent.description) {
|
|
73
|
-
console.log(`
|
|
73
|
+
console.log(` ${isLast ? ' ' : `${S_BAR} `} ${pc.dim(agent.agent.description)}`);
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -81,7 +81,7 @@ export async function listCommand(options: ListCommandOptions): Promise<void> {
|
|
|
81
81
|
if (!hasAnyAgents) {
|
|
82
82
|
p.log.info(pc.dim('No agents installed'));
|
|
83
83
|
console.log();
|
|
84
|
-
console.log(pc.dim('
|
|
84
|
+
console.log(pc.dim(' To install an agent:'));
|
|
85
85
|
console.log(pc.dim(` npx opencode-agents add <repo>`));
|
|
86
86
|
console.log();
|
|
87
87
|
}
|
package/src/core/installer.ts
CHANGED
|
@@ -11,8 +11,6 @@ import type { AgentPlatform, AgentFile, InstallOptions } from '../types/index.js
|
|
|
11
11
|
export async function installAgent(options: InstallOptions): Promise<void> {
|
|
12
12
|
const { source, sourcePath, global, platforms, agentName, copy, selectedAgents } = options;
|
|
13
13
|
|
|
14
|
-
logger.info(`Installing agent from: ${source}`);
|
|
15
|
-
|
|
16
14
|
let tempDir: string;
|
|
17
15
|
let agents: AgentFile[];
|
|
18
16
|
|
|
@@ -53,7 +51,6 @@ export async function installAgent(options: InstallOptions): Promise<void> {
|
|
|
53
51
|
} else {
|
|
54
52
|
copyFileSync(sourcePath, finalPath);
|
|
55
53
|
}
|
|
56
|
-
logger.success(`Copied agent "${name}" to ${finalPath}`);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
}
|