relayax-cli 0.4.13 → 0.4.14
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/commands/init.js +5 -134
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -14,20 +14,6 @@ const command_adapter_js_1 = require("../lib/command-adapter.js");
|
|
|
14
14
|
const config_js_1 = require("../lib/config.js");
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
16
|
const pkg = require('../../package.json');
|
|
17
|
-
const VALID_AGENT_DIRS = ['skills', 'agents', 'rules', 'commands'];
|
|
18
|
-
function resolveTools(toolsArg) {
|
|
19
|
-
const raw = toolsArg.trim().toLowerCase();
|
|
20
|
-
if (raw === 'all') {
|
|
21
|
-
return ai_tools_js_1.AI_TOOLS.map((t) => t.value);
|
|
22
|
-
}
|
|
23
|
-
const tokens = raw.split(',').map((t) => t.trim()).filter(Boolean);
|
|
24
|
-
const valid = new Set(ai_tools_js_1.AI_TOOLS.map((t) => t.value));
|
|
25
|
-
const invalid = tokens.filter((t) => !valid.has(t));
|
|
26
|
-
if (invalid.length > 0) {
|
|
27
|
-
throw new Error(`알 수 없는 도구: ${invalid.join(', ')}\n사용 가능: ${[...valid].join(', ')}`);
|
|
28
|
-
}
|
|
29
|
-
return tokens;
|
|
30
|
-
}
|
|
31
17
|
function showWelcome() {
|
|
32
18
|
const lines = [
|
|
33
19
|
'',
|
|
@@ -48,23 +34,6 @@ function showWelcome() {
|
|
|
48
34
|
];
|
|
49
35
|
console.log(lines.join('\n'));
|
|
50
36
|
}
|
|
51
|
-
async function selectToolsInteractively(detectedIds) {
|
|
52
|
-
const { checkbox } = await import('@inquirer/prompts');
|
|
53
|
-
const choices = ai_tools_js_1.AI_TOOLS.map((tool) => {
|
|
54
|
-
const detected = detectedIds.has(tool.value);
|
|
55
|
-
return {
|
|
56
|
-
name: detected ? `${tool.name} \x1b[32m(detected)\x1b[0m` : tool.name,
|
|
57
|
-
value: tool.value,
|
|
58
|
-
checked: detected,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
const selected = await checkbox({
|
|
62
|
-
message: `연결할 에이전트 CLI를 선택하세요`,
|
|
63
|
-
choices,
|
|
64
|
-
pageSize: 8,
|
|
65
|
-
});
|
|
66
|
-
return selected;
|
|
67
|
-
}
|
|
68
37
|
/**
|
|
69
38
|
* 글로벌 User 커맨드를 감지된 모든 에이전트 CLI에 설치한다.
|
|
70
39
|
* ~/{skillsDir}/commands/relay/ 에 설치.
|
|
@@ -111,23 +80,6 @@ function installGlobalUserCommands() {
|
|
|
111
80
|
function hasGlobalUserCommands() {
|
|
112
81
|
return command_adapter_js_1.USER_COMMANDS.every((cmd) => fs_1.default.existsSync((0, command_adapter_js_1.getGlobalCommandPath)(cmd.id)));
|
|
113
82
|
}
|
|
114
|
-
/**
|
|
115
|
-
* 에이전트 프로젝트인지 감지한다 (.relay/ 디렉토리 내 relay.yaml 또는 에이전트 디렉토리 구조).
|
|
116
|
-
*/
|
|
117
|
-
function isAgentProject(projectPath) {
|
|
118
|
-
const relayDir = path_1.default.join(projectPath, '.relay');
|
|
119
|
-
if (!fs_1.default.existsSync(relayDir))
|
|
120
|
-
return false;
|
|
121
|
-
if (fs_1.default.existsSync(path_1.default.join(relayDir, 'relay.yaml'))) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return VALID_AGENT_DIRS.some((d) => {
|
|
125
|
-
const dirPath = path_1.default.join(relayDir, d);
|
|
126
|
-
if (!fs_1.default.existsSync(dirPath))
|
|
127
|
-
return false;
|
|
128
|
-
return fs_1.default.readdirSync(dirPath).filter((f) => !f.startsWith('.')).length > 0;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
83
|
function registerInit(program) {
|
|
132
84
|
program
|
|
133
85
|
.command('init')
|
|
@@ -142,8 +94,6 @@ function registerInit(program) {
|
|
|
142
94
|
const autoMode = opts.auto === true || opts.all === true || !process.stdin.isTTY;
|
|
143
95
|
const projectPath = (0, paths_js_1.resolveProjectPath)(opts.project);
|
|
144
96
|
const detected = (0, ai_tools_js_1.detectAgentCLIs)(projectPath);
|
|
145
|
-
const detectedIds = new Set(detected.map((t) => t.value));
|
|
146
|
-
const isBuilder = isAgentProject(projectPath);
|
|
147
97
|
// ── 0. --json 모드에서 --tools/--all 없으면 MISSING_TOOLS 에러 ──
|
|
148
98
|
if (json && !opts.tools && !opts.all && !opts.auto) {
|
|
149
99
|
const detectedOptions = detected.map((t) => ({ value: t.value, label: t.name }));
|
|
@@ -177,84 +127,18 @@ function registerInit(program) {
|
|
|
177
127
|
};
|
|
178
128
|
(0, config_js_1.saveInstalled)(installed);
|
|
179
129
|
}
|
|
180
|
-
|
|
181
|
-
// relay-publish가 글로벌로 승격되어 BUILDER_COMMANDS가 비어있으면 스킵
|
|
182
|
-
const localResults = [];
|
|
183
|
-
if (isBuilder && command_adapter_js_1.BUILDER_COMMANDS.length > 0) {
|
|
184
|
-
// 도구 선택
|
|
185
|
-
let targetToolIds;
|
|
186
|
-
if (opts.tools) {
|
|
187
|
-
targetToolIds = resolveTools(opts.tools);
|
|
188
|
-
}
|
|
189
|
-
else if (!autoMode) {
|
|
190
|
-
// interactive mode: only when stdin is a TTY and not --auto/--json
|
|
191
|
-
showWelcome();
|
|
192
|
-
if (detected.length > 0) {
|
|
193
|
-
console.log(` 감지된 에이전트 CLI: \x1b[36m${detected.map((t) => t.name).join(', ')}\x1b[0m\n`);
|
|
194
|
-
}
|
|
195
|
-
console.log(' \x1b[2mBuilder 프로젝트 감지 → 로컬 Builder 커맨드도 설치합니다.\x1b[0m\n');
|
|
196
|
-
targetToolIds = await selectToolsInteractively(detectedIds);
|
|
197
|
-
if (targetToolIds.length === 0) {
|
|
198
|
-
console.log('\n 선택된 도구가 없습니다.');
|
|
199
|
-
// 글로벌은 이미 설치됨
|
|
200
|
-
if (globalStatus === 'installed') {
|
|
201
|
-
console.log(' 글로벌 User 커맨드는 설치되었습니다.\n');
|
|
202
|
-
}
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
// auto mode: use detected CLIs, or all available tools if none detected
|
|
208
|
-
if (detected.length > 0) {
|
|
209
|
-
targetToolIds = detected.map((t) => t.value);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
targetToolIds = ai_tools_js_1.AI_TOOLS.map((t) => t.value);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// Builder 커맨드 설치 (기존 파일 중 현재 목록에 없는 것 제거)
|
|
216
|
-
const builderIds = new Set(command_adapter_js_1.BUILDER_COMMANDS.map((c) => c.id));
|
|
217
|
-
for (const toolId of targetToolIds) {
|
|
218
|
-
const tool = ai_tools_js_1.AI_TOOLS.find((t) => t.value === toolId);
|
|
219
|
-
if (!tool)
|
|
220
|
-
continue;
|
|
221
|
-
const adapter = (0, command_adapter_js_1.createAdapter)(tool);
|
|
222
|
-
const localDir = path_1.default.join(projectPath, tool.skillsDir, 'commands', 'relay');
|
|
223
|
-
// 기존 로컬 커맨드 중 Builder 목록에 없는 것 제거
|
|
224
|
-
if (fs_1.default.existsSync(localDir)) {
|
|
225
|
-
for (const file of fs_1.default.readdirSync(localDir)) {
|
|
226
|
-
const id = file.replace(/\.md$/, '');
|
|
227
|
-
if (!builderIds.has(id)) {
|
|
228
|
-
fs_1.default.unlinkSync(path_1.default.join(localDir, file));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const installedCommands = [];
|
|
233
|
-
for (const cmd of command_adapter_js_1.BUILDER_COMMANDS) {
|
|
234
|
-
const filePath = path_1.default.join(projectPath, adapter.getFilePath(cmd.id));
|
|
235
|
-
const fileContent = adapter.formatFile(cmd);
|
|
236
|
-
fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
237
|
-
fs_1.default.writeFileSync(filePath, fileContent);
|
|
238
|
-
installedCommands.push(cmd.id);
|
|
239
|
-
}
|
|
240
|
-
localResults.push({ tool: tool.name, commands: installedCommands });
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
else if (!autoMode) {
|
|
244
|
-
// User 모드: 글로벌만 설치, 안내 표시
|
|
130
|
+
if (!autoMode) {
|
|
245
131
|
showWelcome();
|
|
246
132
|
}
|
|
247
|
-
// ──
|
|
133
|
+
// ── 2. 출력 ──
|
|
248
134
|
if (json) {
|
|
249
135
|
console.log(JSON.stringify({
|
|
250
136
|
status: 'ok',
|
|
251
|
-
mode: isBuilder ? 'builder' : 'user',
|
|
252
137
|
global: {
|
|
253
138
|
status: globalStatus,
|
|
254
139
|
path: (0, command_adapter_js_1.getGlobalCommandDir)(),
|
|
255
140
|
commands: command_adapter_js_1.USER_COMMANDS.map((c) => c.id),
|
|
256
141
|
},
|
|
257
|
-
local: isBuilder ? localResults : undefined,
|
|
258
142
|
}));
|
|
259
143
|
}
|
|
260
144
|
else {
|
|
@@ -270,28 +154,15 @@ function registerInit(program) {
|
|
|
270
154
|
// 글로벌
|
|
271
155
|
{
|
|
272
156
|
const toolNames = globalTools.length > 0 ? globalTools.join(', ') : '(감지된 CLI 없음)';
|
|
273
|
-
console.log(` \x1b[
|
|
157
|
+
console.log(` \x1b[36m커맨드 (글로벌)\x1b[0m — ${globalStatus === 'updated' ? '업데이트됨' : '설치됨'}`);
|
|
274
158
|
console.log(` 감지된 CLI: \x1b[36m${toolNames}\x1b[0m`);
|
|
275
159
|
for (const cmd of command_adapter_js_1.USER_COMMANDS) {
|
|
276
160
|
console.log(` /${cmd.id}`);
|
|
277
161
|
}
|
|
278
162
|
console.log();
|
|
279
163
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
console.log(` \x1b[36mBuilder 커맨드 (로컬)\x1b[0m`);
|
|
283
|
-
for (const r of localResults) {
|
|
284
|
-
console.log(` ${r.tool}`);
|
|
285
|
-
for (const cmd of r.commands) {
|
|
286
|
-
console.log(` /${cmd}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
console.log();
|
|
290
|
-
}
|
|
291
|
-
if (!isBuilder) {
|
|
292
|
-
console.log(' 에이전트를 만들려면 \x1b[33mrelay create <name>\x1b[0m을 사용하세요.');
|
|
293
|
-
console.log();
|
|
294
|
-
}
|
|
164
|
+
console.log(' 에이전트를 만들려면 \x1b[33mrelay create <name>\x1b[0m을 사용하세요.');
|
|
165
|
+
console.log();
|
|
295
166
|
console.log(' IDE를 재시작하면 슬래시 커맨드가 활성화됩니다.');
|
|
296
167
|
}
|
|
297
168
|
});
|