@eliceio/cdk-cli 0.1.0-alpha.1 → 0.1.0-alpha.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.
Files changed (92) hide show
  1. package/README.md +171 -136
  2. package/es/cli.js +119 -26
  3. package/es/commands/build/index.d.ts +4 -1
  4. package/es/commands/build/index.js +28 -9
  5. package/es/commands/check/index.d.ts +8 -2
  6. package/es/commands/check/index.js +45 -5
  7. package/es/commands/create/index.d.ts +2 -0
  8. package/es/commands/create/index.js +28 -3
  9. package/es/commands/create/scaffold.d.ts +2 -0
  10. package/es/commands/create/scaffold.js +10 -6
  11. package/es/commands/dev/index.d.ts +1 -1
  12. package/es/commands/dev/index.js +6 -2
  13. package/es/commands/doctor/index.d.ts +12 -0
  14. package/es/commands/doctor/index.js +217 -7
  15. package/es/commands/guide/index.d.ts +29 -0
  16. package/es/commands/guide/index.js +120 -0
  17. package/es/commands/mcp/index.d.ts +134 -0
  18. package/es/commands/mcp/index.js +399 -0
  19. package/es/commands/setup/index.d.ts +40 -0
  20. package/es/commands/setup/index.js +157 -0
  21. package/es/commands/skill/index.d.ts +45 -0
  22. package/es/commands/skill/index.js +145 -0
  23. package/es/core/config.d.ts +63 -19
  24. package/es/core/config.js +108 -32
  25. package/es/core/prepare.js +3 -5
  26. package/es/core/project-check.d.ts +15 -0
  27. package/es/core/project-check.js +26 -0
  28. package/es/core/sandbox.d.ts +17 -0
  29. package/es/core/sandbox.js +182 -0
  30. package/es/core/templates.d.ts +25 -0
  31. package/es/core/templates.js +41 -0
  32. package/es/dev/grading.d.ts +14 -7
  33. package/es/dev/grading.js +27 -13
  34. package/es/dev/host-page.d.ts +1 -1
  35. package/es/dev/host-page.js +33 -33
  36. package/es/dev/mock-api.d.ts +20 -4
  37. package/es/dev/mock-api.js +70 -9
  38. package/es/dev/server.d.ts +9 -1
  39. package/es/dev/server.js +101 -25
  40. package/es/rules/check.js +126 -4
  41. package/es/rules/index.d.ts +1 -1
  42. package/es/rules/index.js +1 -1
  43. package/es/rules/manifest.d.ts +23 -9
  44. package/es/rules/manifest.js +60 -35
  45. package/es/rules/node.js +3 -1
  46. package/es/rules/semver.d.ts +5 -0
  47. package/es/rules/semver.js +32 -0
  48. package/es/rules/types.d.ts +29 -6
  49. package/es/rules.json.js +1 -1
  50. package/es/version.d.ts +2 -1
  51. package/es/version.js +5 -1
  52. package/guides/content-development.md +294 -0
  53. package/package.json +4 -2
  54. package/rules.json +113 -5
  55. package/skills/_shared/always.md +9 -0
  56. package/skills/elice-content-check/SKILL.md +22 -0
  57. package/skills/elice-content-create/SKILL.md +21 -0
  58. package/skills/elice-content-migrate/SKILL.md +21 -0
  59. package/skills/elice-content-publish/SKILL.md +22 -0
  60. package/templates/_shared/lib/cdk-mock.d.ts +21 -3
  61. package/templates/_shared/lib/cdk-mock.js +239 -80
  62. package/templates/_shared/lib/cdk.js +2 -2
  63. package/templates/_shared/lib/elice-content.css +206 -0
  64. package/templates/_shared/lib/elice-content.d.ts +112 -5
  65. package/templates/_shared/lib/elice-content.js +660 -62
  66. package/templates/blank/README.md +14 -5
  67. package/templates/blank/commentary.txt +2 -0
  68. package/templates/blank/completion.html +15 -0
  69. package/templates/blank/elice.config.json +3 -5
  70. package/templates/blank/gitignore +1 -0
  71. package/templates/blank/screens/completion.js +7 -0
  72. package/templates/blank/screens/edit.js +3 -0
  73. package/templates/blank/template.json +6 -0
  74. package/templates/quiz/README.md +37 -30
  75. package/templates/quiz/commentary.txt +2 -0
  76. package/templates/quiz/content.json +17 -63
  77. package/templates/quiz/core/behaviors.d.ts +8 -3
  78. package/templates/quiz/core/behaviors.js +15 -2
  79. package/templates/quiz/core/model.d.ts +27 -1
  80. package/templates/quiz/core/model.js +199 -4
  81. package/templates/quiz/elice.config.json +1 -6
  82. package/templates/quiz/gitignore +1 -0
  83. package/templates/quiz/grading.json +1 -10
  84. package/templates/quiz/screens/edit.js +106 -32
  85. package/templates/quiz/screens/learn.js +13 -9
  86. package/templates/quiz/styles.css +84 -24
  87. package/templates/quiz/template.json +6 -0
  88. package/templates/quiz/ui/templates/edit.d.ts +2 -1
  89. package/templates/quiz/ui/templates/edit.js +16 -13
  90. package/templates/quiz/ui/templates/group.js +29 -8
  91. package/templates/quiz/ui/templates/question.js +3 -3
  92. package/templates/quiz/ui/texts.js +53 -29
@@ -0,0 +1,399 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, mkdirSync, copyFileSync, writeFileSync, readFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { delimiter, join, dirname } from 'node:path';
5
+
6
+ const usage = `사용법: ecdk mcp setup [--target claude|helpycode|all] [--env prod|qa5] [--url <주소>] [--dry-run] [--force] [--json]
7
+
8
+ Elice 학습자료 서버 MCP(elice-material)를 AI 도구에 등록한다. 나중에 자료를 LXP에 올리는 스킬이 쓴다.
9
+ --target claude(Claude Code) · helpycode(Helpy Code 데스크톱 · CLI) · all(찾은 도구 모두, 기본)
10
+ --env 서버 환경 prod(운영, 기본) · qa5. 환경 변수 ECDK_ENV로도 정할 수 있다 (옵션이 먼저)
11
+ --url 그 밖의 서버 MCP 주소 (https, --env보다 먼저)
12
+ --dry-run 무엇을 바꿀지 보여 주기만 한다 (서버 확인도 하지 않음)
13
+ --force 이미 다른 주소로 등록돼 있거나 서버에 MCP가 없어 보여도 등록한다
14
+ 등록 전에 서버에 MCP가 있는지 확인하고, 로그인은 등록 뒤 각 도구에서 한다 (안내를 출력함).
15
+
16
+ 종료 코드: 0 성공 · 1 직접 할 일이 있음(서버에 MCP 없음, 주석이 있는 설정 파일, 다른 주소로 등록됨) · 2 잘못된 사용`;
17
+ const MCP_NAME = 'elice-material';
18
+ /**
19
+ * 서버 환경 → MCP 주소. 표는 여기 하나만 둔다.
20
+ * prod는 material API 주소(api-material.elice.io)에 /mcp를 붙인 **가정**이다: 2026-11-10 운영에는 아직 MCP가 없고
21
+ * (GET 405), 백엔드가 주소를 확정해 주기로 함 (백엔드 요청 B1). 그래서 등록 전에 probe로 확인한다.
22
+ */
23
+ const MCP_ENVS = {
24
+ prod: 'https://api-material.elice.io/mcp',
25
+ qa5: 'https://dev-v5-material-api.dev.elicer.io/mcp'
26
+ };
27
+ const DEFAULT_ENV = 'prod';
28
+ const PROBE_TIMEOUT_MS = 5000;
29
+ /** MCP initialize를 POST해 본다. 로그인 전이면 401과 www-authenticate(resource_metadata)가 와야 한다 */
30
+ async function probeMcp(url) {
31
+ try {
32
+ const res = await fetch(url, {
33
+ method: 'POST',
34
+ headers: {
35
+ 'content-type': 'application/json',
36
+ accept: 'application/json, text/event-stream'
37
+ },
38
+ body: JSON.stringify({
39
+ jsonrpc: '2.0',
40
+ id: 1,
41
+ method: 'initialize',
42
+ params: {
43
+ protocolVersion: '2025-06-18',
44
+ capabilities: {},
45
+ clientInfo: {
46
+ name: 'ecdk',
47
+ version: '0'
48
+ }
49
+ }
50
+ }),
51
+ signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
52
+ });
53
+ const auth = res.headers.get('www-authenticate') ?? '';
54
+ if (res.status === 401 && /bearer/i.test(auth) && auth.includes('resource_metadata')) return {
55
+ ok: true,
56
+ detail: '401 (로그인 필요)'
57
+ };
58
+ return {
59
+ ok: false,
60
+ detail: `HTTP ${res.status}`
61
+ };
62
+ } catch (e) {
63
+ return {
64
+ ok: false,
65
+ detail: e.message
66
+ };
67
+ }
68
+ }
69
+ function defaultMcpEnv() {
70
+ const pathDirs = (process.env.PATH ?? '').split(delimiter).filter(Boolean);
71
+ const exts = process.platform === 'win32' ? ['.cmd', '.exe', ''] : [''];
72
+ return {
73
+ home: homedir(),
74
+ platform: process.platform,
75
+ which: command => {
76
+ for (const dir of pathDirs) for (const ext of exts) {
77
+ const p = join(dir, command + ext);
78
+ if (existsSync(p)) return p;
79
+ }
80
+ return null;
81
+ },
82
+ exec: (command, args, timeoutMs) => {
83
+ const r = spawnSync(command, args, {
84
+ encoding: 'utf8',
85
+ timeout: timeoutMs,
86
+ shell: process.platform === 'win32'
87
+ });
88
+ return {
89
+ code: r.status ?? 1,
90
+ stdout: `${r.stdout ?? ''}${r.stderr ?? ''}`,
91
+ timedOut: r.error != null || r.signal != null || r.status === null
92
+ };
93
+ },
94
+ exists: existsSync,
95
+ probe: probeMcp,
96
+ envVar: process.env.ECDK_ENV
97
+ };
98
+ }
99
+ const helpyConfigPath = env => join(env.home, '.config', 'helpycode', 'helpycode.jsonc');
100
+ function detectTargets(env) {
101
+ const found = [];
102
+ if (env.which('claude')) found.push('claude');
103
+ if (env.exists(join(env.home, '.config', 'helpycode')) || env.which('helpycode') || env.platform === 'darwin' && env.exists('/Applications/HelpyCode.app')) found.push('helpycode');
104
+ return found;
105
+ }
106
+ /** 주소로 환경 이름 (표에 없으면 custom) */
107
+ const envOfUrl = url => Object.entries(MCP_ENVS).find(([, u]) => u === url)?.[0] ?? 'custom';
108
+ const CLAUDE_TIMEOUT_MS = 5000;
109
+ /**
110
+ * Claude Code 등록 상태. `claude mcp get`은 서버 연결 상태까지 확인해 느릴 수 있으므로
111
+ * 시간 초과 · 실행 실패는 "없음"이 아니라 "확인 못 함"으로 본다.
112
+ * 범위(Scope) 줄이 User가 아니면 이 폴더 전용(local · project) 등록이라 다른 폴더에서는 없다.
113
+ * Scope 줄이 없으면(옛 Claude CLI) 사용자 범위로 본다.
114
+ */
115
+ function claudeRegistration(env) {
116
+ const r = env.exec('claude', ['mcp', 'get', MCP_NAME], CLAUDE_TIMEOUT_MS);
117
+ if (r.timedOut) return {
118
+ state: 'unknown',
119
+ reason: `claude mcp get이 ${CLAUDE_TIMEOUT_MS / 1000}초 안에 끝나지 않음`
120
+ };
121
+ if (r.code !== 0) return {
122
+ state: 'none'
123
+ };
124
+ const url = /URL:\s*(\S+)/.exec(r.stdout)?.[1];
125
+ if (!url) return {
126
+ state: 'none'
127
+ };
128
+ const scope = /Scope:\s*([^\n(]+)/.exec(r.stdout)?.[1]?.trim();
129
+ if (scope && !/^user/i.test(scope)) return {
130
+ state: 'other-scope',
131
+ url,
132
+ scope
133
+ };
134
+ return {
135
+ state: 'user',
136
+ url
137
+ };
138
+ }
139
+ /** Claude Code 사용자 범위에 등록된 주소 (없거나 확인 못 하면 null) */
140
+ function claudeRegisteredUrl(env) {
141
+ const reg = claudeRegistration(env);
142
+ return reg.state === 'user' ? reg.url : null;
143
+ }
144
+ /** 주석 · 끝 쉼표가 있으면 다시 쓰지 않는다 (지우면 사람이 적은 설명이 사라짐) */
145
+ function readHelpyConfig(path) {
146
+ if (!existsSync(path)) return {
147
+ kind: 'missing'
148
+ };
149
+ const text = readFileSync(path, 'utf8');
150
+ if (!text.trim()) return {
151
+ kind: 'missing'
152
+ };
153
+ try {
154
+ const data = JSON.parse(text);
155
+ if (typeof data === 'object' && data !== null && !Array.isArray(data)) return {
156
+ kind: 'json',
157
+ data: data,
158
+ text
159
+ };
160
+ } catch {
161
+ // 주석이나 끝 쉼표가 있는 JSONC
162
+ }
163
+ return {
164
+ kind: 'jsonc',
165
+ text
166
+ };
167
+ }
168
+ const helpyEntry = url => ({
169
+ type: 'remote',
170
+ url,
171
+ enabled: true
172
+ });
173
+ /** Helpy Code 설정에 등록된 주소 (없으면 null, 읽을 수 없으면 undefined) */
174
+ function helpyRegisteredUrl(env) {
175
+ const config = readHelpyConfig(helpyConfigPath(env));
176
+ if (config.kind === 'missing') return null;
177
+ if (config.kind === 'jsonc') {
178
+ const m = new RegExp(`"${MCP_NAME}"[\\s\\S]*?"url"\\s*:\\s*"([^"]+)"`).exec(config.text);
179
+ return m?.[1] ?? null;
180
+ }
181
+ const mcp = config.data.mcp;
182
+ return mcp?.[MCP_NAME]?.url ?? null;
183
+ }
184
+ function setupClaude(env, url, dryRun, force) {
185
+ const reg = claudeRegistration(env);
186
+ if (reg.state === 'unknown') return {
187
+ target: 'claude',
188
+ action: 'manual',
189
+ message: `등록 여부를 확인하지 못해 건드리지 않았습니다 (${reg.reason}). \`claude mcp get ${MCP_NAME}\`로 확인해 주세요`
190
+ };
191
+ const current = reg.state === 'user' ? reg.url : null;
192
+ const localNote = reg.state === 'other-scope' ? ` · ${reg.scope} 범위 등록(${reg.url})은 이 폴더에서만 쓰여 그대로 두고 사용자 범위에 더함` : '';
193
+ if (current === url) return {
194
+ target: 'claude',
195
+ action: 'skipped',
196
+ message: `이미 같은 주소로 등록됨 (${url})`
197
+ };
198
+ if (current && !force) return {
199
+ target: 'claude',
200
+ action: 'conflict',
201
+ message: `다른 주소로 등록돼 있습니다 (${current}). 바꾸려면 --force`
202
+ };
203
+ const add = ['mcp', 'add', '--transport', 'http', '--scope', 'user', MCP_NAME, url];
204
+ if (dryRun) return {
205
+ target: 'claude',
206
+ action: current ? 'would-replace' : 'would-add',
207
+ message: `${current ? `claude mcp remove ${MCP_NAME} --scope user 뒤 ` : ''}claude ${add.join(' ')}${localNote}`
208
+ };
209
+ if (current) {
210
+ const rm = env.exec('claude', ['mcp', 'remove', MCP_NAME, '--scope', 'user'], 30000);
211
+ if (rm.code !== 0 || rm.timedOut) return {
212
+ target: 'claude',
213
+ action: 'failed',
214
+ message: `claude mcp remove 실패라 바꾸지 않았습니다: ${rm.stdout.trim() || '시간 초과'}`
215
+ };
216
+ }
217
+ const r = env.exec('claude', add, 30000);
218
+ if (r.code !== 0) return {
219
+ target: 'claude',
220
+ action: 'failed',
221
+ message: `claude mcp add 실패: ${r.stdout.trim()}`
222
+ };
223
+ return {
224
+ target: 'claude',
225
+ action: current ? 'replaced' : 'added',
226
+ message: `Claude Code 사용자 설정에 ${current ? '바꿈' : '등록'} (${url})${localNote}`
227
+ };
228
+ }
229
+ function setupHelpy(env, url, dryRun, force) {
230
+ const path = helpyConfigPath(env);
231
+ const config = readHelpyConfig(path);
232
+ const block = JSON.stringify({
233
+ mcp: {
234
+ [MCP_NAME]: helpyEntry(url)
235
+ }
236
+ }, null, 2);
237
+ if (config.kind === 'jsonc') {
238
+ const current = helpyRegisteredUrl(env);
239
+ if (current === url) return {
240
+ target: 'helpycode',
241
+ action: 'skipped',
242
+ message: `이미 같은 주소로 등록됨 (${url})`
243
+ };
244
+ return {
245
+ target: 'helpycode',
246
+ action: 'manual',
247
+ message: `${path}에 주석이나 끝 쉼표가 있어 직접 고치지 않았습니다. 아래 "mcp" 항목을 기존 내용은 두고 더해 주세요.`,
248
+ paste: block
249
+ };
250
+ }
251
+ const data = config.kind === 'json' ? {
252
+ ...config.data
253
+ } : {
254
+ $schema: 'https://opencode.ai/config.json'
255
+ };
256
+ const mcp = {
257
+ ...(data.mcp ?? {})
258
+ };
259
+ const current = mcp[MCP_NAME]?.url ?? null;
260
+ if (current === url) return {
261
+ target: 'helpycode',
262
+ action: 'skipped',
263
+ message: `이미 같은 주소로 등록됨 (${url})`
264
+ };
265
+ if (current && !force) return {
266
+ target: 'helpycode',
267
+ action: 'conflict',
268
+ message: `다른 주소로 등록돼 있습니다 (${current}). 바꾸려면 --force`
269
+ };
270
+ if (dryRun) return {
271
+ target: 'helpycode',
272
+ action: current ? 'would-replace' : 'would-add',
273
+ message: `${path}의 mcp.${MCP_NAME}를 ${url}로${config.kind === 'json' ? env.exists(`${path}.bak`) ? ' (.bak은 이미 있어 그대로 둠)' : ' (원본은 .bak)' : ' (새 파일)'}`
274
+ };
275
+ mcp[MCP_NAME] = helpyEntry(url);
276
+ data.mcp = mcp;
277
+ mkdirSync(dirname(path), {
278
+ recursive: true
279
+ });
280
+ // .bak은 처음 한 번만 만든다 (다시 실행해도 사람이 쓴 원본이 남게)
281
+ let bakNote = '';
282
+ if (config.kind === 'json') {
283
+ if (existsSync(`${path}.bak`)) bakNote = ' (.bak은 이미 있어 그대로 둠)';else {
284
+ copyFileSync(path, `${path}.bak`);
285
+ bakNote = ' (원본은 .bak)';
286
+ }
287
+ }
288
+ writeFileSync(path, `${JSON.stringify(data, null, 2)}\n`);
289
+ return {
290
+ target: 'helpycode',
291
+ action: current ? 'replaced' : 'added',
292
+ message: `${path}에 ${current ? '바꿈' : '등록'}${bakNote}`
293
+ };
294
+ }
295
+ const LOGIN = {
296
+ claude: ['Claude Code: /mcp → elice-material → Authenticate'],
297
+ helpycode: ['Helpy Code 데스크톱: ⌘ ; (또는 /mcp) → elice-material 켜기 → 브라우저 로그인', 'Helpy Code CLI: helpycode mcp auth elice-material']
298
+ };
299
+ async function setup(opts) {
300
+ const {
301
+ url
302
+ } = opts;
303
+ const targets = opts.target === 'all' ? detectTargets(opts.env) : [opts.target];
304
+ const login = [...targets.flatMap(t => LOGIN[t]), ...(opts.envName === 'qa5' ? ['로그인 창(accounts.qa-web-5)에서 dev5 계정으로 로그인'] : [])];
305
+ const probe = opts.dryRun ? 'skipped' : await opts.env.probe(url);
306
+ if (probe !== 'skipped' && !probe.ok && !opts.force) return {
307
+ env: opts.envName,
308
+ probe,
309
+ url,
310
+ targets,
311
+ steps: targets.map(target => ({
312
+ target,
313
+ action: 'unreachable',
314
+ message: `이 환경에 MCP가 아직 배포되지 않았거나 주소가 다릅니다 (${probe.detail}). 그래도 등록하려면 --force`
315
+ })),
316
+ login
317
+ };
318
+ const steps = targets.map(t => t === 'claude' ? setupClaude(opts.env, url, opts.dryRun, opts.force) : setupHelpy(opts.env, url, opts.dryRun, opts.force));
319
+ return {
320
+ env: opts.envName,
321
+ probe,
322
+ url,
323
+ targets,
324
+ steps,
325
+ login
326
+ };
327
+ }
328
+ const NEEDS_PERSON = ['conflict', 'manual', 'unreachable', 'failed'];
329
+ /** 주소: --url > --env > ECDK_ENV > prod */
330
+ function resolveUrl(args, env) {
331
+ if (args.url && !/^https:\/\/\S+$/.test(args.url)) return {
332
+ ok: false,
333
+ error: `--url은 https 주소여야 합니다: ${args.url}`
334
+ };
335
+ const envName = args.url ? envOfUrl(args.url) : args.envName ?? env.envVar ?? DEFAULT_ENV;
336
+ const source = args.url ? '--url' : args.envName ? '--env' : env.envVar ? 'ECDK_ENV' : '기본값';
337
+ const url = args.url ?? MCP_ENVS[envName];
338
+ if (!url) return {
339
+ ok: false,
340
+ error: `알 수 없는 환경: ${envName} (가능: ${Object.keys(MCP_ENVS).join(', ')}, 그 밖은 --url)`
341
+ };
342
+ return {
343
+ ok: true,
344
+ envName,
345
+ source,
346
+ url
347
+ };
348
+ }
349
+ /** 사람용 출력의 MCP 부분 (환경 · 서버 확인 · 도구별 결과) */
350
+ function formatSetupLines(result, source, dryRun) {
351
+ const probeLine = result.probe === 'skipped' ? '서버 확인: 건너뜀 (--dry-run)' : `서버 확인: ${result.probe.ok ? 'MCP 있음' : 'MCP 없음'} (${result.probe.detail})`;
352
+ return [`MCP ${MCP_NAME} · 환경 ${result.env} (${source}) · ${result.url}${dryRun ? ' · 미리보기(--dry-run)' : ''}`, probeLine, ...(result.env === 'prod' ? [] : [`※ 운영이 아닌 환경(${result.env})입니다. 운영 자료를 올리지 마세요.`]), ...result.steps.flatMap(s => [` ${s.target}: ${s.message}`, ...(s.paste ? s.paste.split('\n').map(l => ` ${l}`) : [])])];
353
+ }
354
+ async function run(args) {
355
+ if (args.sub !== 'setup') return {
356
+ exitCode: 2,
357
+ output: `알 수 없는 하위 명령: ${args.sub ?? '(없음)'}\n\n${usage}`
358
+ };
359
+ const target = args.target ?? 'all';
360
+ if (target !== 'claude' && target !== 'helpycode' && target !== 'all') return {
361
+ exitCode: 2,
362
+ output: `--target은 claude · helpycode · all 중 하나입니다.\n\n${usage}`
363
+ };
364
+ const env = args.env ?? defaultMcpEnv();
365
+ const resolved = resolveUrl(args, env);
366
+ if (!resolved.ok) return {
367
+ exitCode: 2,
368
+ output: `${resolved.error}\n\n${usage}`
369
+ };
370
+ const {
371
+ envName,
372
+ source,
373
+ url
374
+ } = resolved;
375
+ const result = await setup({
376
+ env,
377
+ envName,
378
+ url,
379
+ target,
380
+ dryRun: args.dryRun,
381
+ force: args.force
382
+ });
383
+ const needsPerson = result.steps.some(s => NEEDS_PERSON.includes(s.action));
384
+ if (args.json) return {
385
+ exitCode: needsPerson || result.targets.length === 0 ? 1 : 0,
386
+ output: JSON.stringify(result, null, 2)
387
+ };
388
+ if (result.targets.length === 0) return {
389
+ exitCode: 1,
390
+ output: 'Claude Code나 Helpy Code를 찾지 못했습니다. 설치한 뒤 다시 실행하거나 --target을 지정하세요.'
391
+ };
392
+ const lines = [...formatSetupLines(result, source, args.dryRun), '', '다음: 각 도구에서 로그인', ...result.login.map(l => ` - ${l}`)];
393
+ return {
394
+ exitCode: needsPerson ? 1 : 0,
395
+ output: lines.join('\n')
396
+ };
397
+ }
398
+
399
+ export { DEFAULT_ENV, MCP_ENVS, MCP_NAME, NEEDS_PERSON, claudeRegisteredUrl, claudeRegistration, defaultMcpEnv, detectTargets, envOfUrl, formatSetupLines, helpyConfigPath, helpyRegisteredUrl, probeMcp, readHelpyConfig, resolveUrl, run, setup, usage };
@@ -0,0 +1,40 @@
1
+ import { type DoctorCheck } from '../doctor/index.js';
2
+ import { type McpEnv, type SetupResult } from '../mcp/index.js';
3
+ import type { CommandResult } from '../../types.js';
4
+ export declare const usage = "\uC0AC\uC6A9\uBC95: ecdk setup [--env prod|qa5] [--url <\uC8FC\uC18C>] [--target claude|helpycode|all] [--dry-run] [--force] [--json]\n\n \uCC98\uC74C \uD55C \uBC88 \uC2E4\uD589\uD55C\uB2E4. \uCC28\uB840\uB85C:\n 1. \uC2A4\uD0AC \uC124\uCE58 (ecdk skill install\uACFC \uAC19\uC74C, ~/.claude/skills/)\n 2. \uD559\uC2B5\uC790\uB8CC \uC11C\uBC84 MCP \uB4F1\uB85D (ecdk mcp setup\uACFC \uAC19\uC74C, \uC635\uC158\uB3C4 \uAC19\uC74C)\n 3. \uC810\uAC80 \uC694\uC57D (Node \u00B7 \uC2A4\uD0AC \u00B7 MCP)\n 4. \uB3C4\uAD6C\uBCC4 \uB85C\uADF8\uC778 \uC548\uB0B4\n MCP\uB294 \uC544\uC9C1 \uBC30\uD3EC\uB418\uC9C0 \uC54A\uC558\uAC70\uB098 \uC9C1\uC811 \uD560 \uC77C\uC774 \uC788\uC5B4\uB3C4 \uC2E4\uD328\uB85C \uCE58\uC9C0 \uC54A\uB294\uB2E4 (\"\uC9C1\uC811 \uD560 \uC77C\"\uC5D0 \uC801\uC74C, \uC2A4\uD0AC\uC774 \uC4F8 \uC218 \uC788\uC73C\uBA74 \uC885\uB8CC \uCF54\uB4DC 0).\n --force\uB294 MCP \uB4F1\uB85D\uC5D0\uB9CC \uC4F4\uB2E4. \uC190\uC73C\uB85C \uACE0\uCE5C \uC2A4\uD0AC\uAE4C\uC9C0 \uBC14\uAFB8\uB824\uBA74 ecdk skill install --force.\n\n\uC885\uB8CC \uCF54\uB4DC: 0 \uC2A4\uD0AC \uC124\uCE58\uB428(MCP\uB294 \uC9C1\uC811 \uD560 \uC77C\uC774 \uB0A8\uC544\uB3C4) \u00B7 1 \uC2A4\uD0AC\uC744 \uC124\uCE58\uD558\uC9C0 \uBABB\uD568 \u00B7 2 \uC798\uBABB\uB41C \uC0AC\uC6A9";
5
+ export interface SetupAllResult {
6
+ skills: {
7
+ ok: true;
8
+ dir: string;
9
+ version: string;
10
+ items: {
11
+ name: string;
12
+ action: string;
13
+ }[];
14
+ } | {
15
+ ok: false;
16
+ error: string;
17
+ };
18
+ mcp: SetupResult;
19
+ checks: DoctorCheck[];
20
+ todo: string[];
21
+ }
22
+ export declare function setupAll(opts: {
23
+ env: McpEnv;
24
+ envName: string;
25
+ url: string;
26
+ target: 'claude' | 'helpycode' | 'all';
27
+ dryRun: boolean;
28
+ force: boolean;
29
+ nodeVersion?: string | undefined;
30
+ }): Promise<SetupAllResult>;
31
+ export declare function run(args: {
32
+ target: string | undefined;
33
+ envName: string | undefined;
34
+ url: string | undefined;
35
+ dryRun: boolean;
36
+ force: boolean;
37
+ json: boolean;
38
+ env?: McpEnv | undefined;
39
+ nodeVersion?: string | undefined;
40
+ }): Promise<CommandResult>;
@@ -0,0 +1,157 @@
1
+ import { checkNode, checkSkills, checkMcp } from '../doctor/index.js';
2
+ import { defaultMcpEnv, resolveUrl, formatSetupLines, NEEDS_PERSON, setup } from '../mcp/index.js';
3
+ import { skillsDir, install, skillNames, inspectSkill } from '../skill/index.js';
4
+
5
+ const usage = `사용법: ecdk setup [--env prod|qa5] [--url <주소>] [--target claude|helpycode|all] [--dry-run] [--force] [--json]
6
+
7
+ 처음 한 번 실행한다. 차례로:
8
+ 1. 스킬 설치 (ecdk skill install과 같음, ~/.claude/skills/)
9
+ 2. 학습자료 서버 MCP 등록 (ecdk mcp setup과 같음, 옵션도 같음)
10
+ 3. 점검 요약 (Node · 스킬 · MCP)
11
+ 4. 도구별 로그인 안내
12
+ MCP는 아직 배포되지 않았거나 직접 할 일이 있어도 실패로 치지 않는다 ("직접 할 일"에 적음, 스킬이 쓸 수 있으면 종료 코드 0).
13
+ --force는 MCP 등록에만 쓴다. 손으로 고친 스킬까지 바꾸려면 ecdk skill install --force.
14
+
15
+ 종료 코드: 0 스킬 설치됨(MCP는 직접 할 일이 남아도) · 1 스킬을 설치하지 못함 · 2 잘못된 사용`;
16
+ const SKILL_ACTION = {
17
+ installed: '설치',
18
+ updated: '바꿈',
19
+ skipped: '최신이라 건너뜀',
20
+ kept: '손으로 고친 스킬이라 그대로 둠',
21
+ newer: 'CLI보다 새 버전이라 그대로 둠',
22
+ 'would-install': '설치할 예정',
23
+ 'would-update': '바꿀 예정'
24
+ };
25
+ /** --dry-run: 스킬 폴더를 쓰지 않고 무엇을 할지만 */
26
+ function planSkills(home) {
27
+ const dir = skillsDir({
28
+ project: false,
29
+ home
30
+ });
31
+ return skillNames().map(name => {
32
+ const state = inspectSkill(dir, name).state;
33
+ const action = state === 'missing' ? 'would-install' : state === 'outdated' ? 'would-update' : state === 'current' ? 'skipped' : state === 'newer' ? 'newer' : 'kept';
34
+ return {
35
+ name,
36
+ action
37
+ };
38
+ });
39
+ }
40
+ async function setupAll(opts) {
41
+ const {
42
+ env
43
+ } = opts;
44
+ let skills;
45
+ if (opts.dryRun) {
46
+ skills = {
47
+ ok: true,
48
+ dir: skillsDir({
49
+ project: false,
50
+ home: env.home
51
+ }),
52
+ version: '',
53
+ items: planSkills(env.home)
54
+ };
55
+ } else {
56
+ try {
57
+ const r = await install({
58
+ project: false,
59
+ force: false,
60
+ home: env.home
61
+ });
62
+ skills = {
63
+ ok: true,
64
+ dir: r.dir,
65
+ version: r.version,
66
+ items: r.skills.map(s => ({
67
+ name: s.name,
68
+ action: s.action
69
+ }))
70
+ };
71
+ } catch (e) {
72
+ skills = {
73
+ ok: false,
74
+ error: e.message
75
+ };
76
+ }
77
+ }
78
+ const mcp = await setup({
79
+ env,
80
+ envName: opts.envName,
81
+ url: opts.url,
82
+ target: opts.target,
83
+ dryRun: opts.dryRun,
84
+ force: opts.force
85
+ });
86
+ const checks = [checkNode(opts.nodeVersion ?? process.version), checkSkills(env.home, env.home), checkMcp(env)];
87
+ const todo = [];
88
+ if (!skills.ok) todo.push(`스킬을 설치하지 못했습니다: ${skills.error}`);else if (skills.items.some(s => s.action === 'kept')) todo.push('손으로 고친 스킬이 있어 그대로 두었습니다. 바꾸려면 ecdk skill install --force');
89
+ {
90
+ if (mcp.targets.length === 0) todo.push('MCP: Claude Code나 Helpy Code를 찾지 못했습니다. 설치한 뒤 ecdk setup을 다시 실행하세요.');
91
+ for (const s of mcp.steps) {
92
+ if (s.action === 'unreachable') todo.push(`MCP(${s.target}): 아직 배포되지 않아 건너뜀 (배포 뒤 ecdk setup 다시 실행). QA는 --env qa5`);else if (NEEDS_PERSON.includes(s.action)) todo.push(`MCP(${s.target}): ${s.message}`);
93
+ }
94
+ }
95
+ return {
96
+ skills,
97
+ mcp,
98
+ checks,
99
+ todo
100
+ };
101
+ }
102
+ async function run(args) {
103
+ const target = args.target ?? 'all';
104
+ if (target !== 'claude' && target !== 'helpycode' && target !== 'all') return {
105
+ exitCode: 2,
106
+ output: `--target은 claude · helpycode · all 중 하나입니다.\n\n${usage}`
107
+ };
108
+ const env = args.env ?? defaultMcpEnv();
109
+ const resolved = resolveUrl(args, env);
110
+ if (!resolved.ok) return {
111
+ exitCode: 2,
112
+ output: `${resolved.error}\n\n${usage}`
113
+ };
114
+ const result = await setupAll({
115
+ env,
116
+ envName: resolved.envName,
117
+ url: resolved.url,
118
+ target,
119
+ dryRun: args.dryRun,
120
+ force: args.force,
121
+ nodeVersion: args.nodeVersion
122
+ });
123
+ // 스킬이 쓸 수 있으면 성공: MCP는 publish 스킬 전까지 쓰지 않고, 배포 전 · 주석 있는 설정은 사람이 나중에 해도 됨
124
+ const exitCode = result.skills.ok ? 0 : 1;
125
+ if (args.json) return {
126
+ exitCode,
127
+ output: JSON.stringify(result, null, 2)
128
+ };
129
+ const lines = [];
130
+ lines.push(`1. 스킬${args.dryRun ? ' (미리보기)' : ''}`);
131
+ if (result.skills.ok) {
132
+ lines.push(` 위치: ${result.skills.dir}${result.skills.version ? ` (ecdk ${result.skills.version})` : ''}`);
133
+ for (const s of result.skills.items) lines.push(` ${s.name}: ${SKILL_ACTION[s.action] ?? s.action}`);
134
+ } else lines.push(` 설치하지 못함: ${result.skills.error}`);
135
+ lines.push('', '2. 학습자료 서버 MCP');
136
+ {
137
+ if (result.mcp.targets.length === 0) lines.push(' Claude Code · Helpy Code를 찾지 못함');else lines.push(...formatSetupLines(result.mcp, resolved.source, args.dryRun).map(l => ` ${l}`));
138
+ }
139
+ lines.push('', '3. 점검');
140
+ for (const c of result.checks) lines.push(` [${c.level}] ${c.id.padEnd(16)} ${c.message}`);
141
+ // 등록했거나(할 예정이거나) 이미 등록된 도구가 있을 때만 로그인 안내 (배포 전이면 할 수 없음)
142
+ if (result.mcp.steps.some(s => !NEEDS_PERSON.includes(s.action))) {
143
+ lines.push('', '4. 로그인 (MCP를 등록한 도구에서, 자료를 LXP에 올릴 때 필요)');
144
+ for (const l of result.mcp.login) lines.push(` - ${l}`);
145
+ }
146
+ if (result.todo.length > 0) {
147
+ lines.push('', '직접 할 일');
148
+ for (const t of result.todo) lines.push(` - ${t}`);
149
+ }
150
+ lines.push('', result.skills.ok ? 'Claude Code · Helpy Code를 새로 열거나 /reload-skills를 입력하면 스킬이 적용됩니다.' : '스킬 설치가 끝나지 않았습니다. 위 오류를 확인하세요.');
151
+ return {
152
+ exitCode,
153
+ output: lines.join('\n')
154
+ };
155
+ }
156
+
157
+ export { run, setupAll, usage };
@@ -0,0 +1,45 @@
1
+ import { compareVersions } from '../../rules/semver.js';
2
+ import type { CommandResult } from '../../types.js';
3
+ export { compareVersions };
4
+ export declare const usage = "\uC0AC\uC6A9\uBC95: ecdk skill install [--project] [--force] [--json]\n\n Claude Code\uAC00 Elice \uD559\uC2B5\uC790\uB8CC \uC694\uCCAD\uC744 \uC54C\uC544\uBCF4\uACE0 ecdk guide\uB97C \uC77D\uAC8C \uD558\uB294 \uC2A4\uD0AC(stub)\uC744 \uC124\uCE58\uD55C\uB2E4.\n \uAE30\uBCF8\uC740 ~/.claude/skills/ (\uBAA8\uB4E0 \uD504\uB85C\uC81D\uD2B8), --project\uBA74 \uD604\uC7AC \uD3F4\uB354\uC758 .claude/skills/.\n \uAC19\uC740 \uBC84\uC804\uC774\uBA74 \uAC74\uB108\uB6F0\uACE0, \uC61B \uBC84\uC804\uC774\uBA74 \uBC14\uAFBC\uB2E4. CLI\uBCF4\uB2E4 \uC0C8 \uBC84\uC804\uC774\uAC70\uB098 \uC190\uC73C\uB85C \uACE0\uCE5C \uC2A4\uD0AC\uC740 --force\uC77C \uB54C\uB9CC \uBC14\uAFBC\uB2E4.\n\n\uC885\uB8CC \uCF54\uB4DC: 0 \uC131\uACF5 \u00B7 1 \uC190\uC73C\uB85C \uACE0\uCE5C \uC2A4\uD0AC\uC774 \uC788\uC5B4 \uAC74\uB108\uB700 \u00B7 2 \uC798\uBABB\uB41C \uC0AC\uC6A9";
5
+ export type SkillState = 'missing' | 'current' | 'outdated' | 'newer' | 'modified';
6
+ export interface SkillStatus {
7
+ name: string;
8
+ path: string;
9
+ state: SkillState;
10
+ /** 설치된 스킬의 버전 (없으면 undefined) */
11
+ version?: string | undefined;
12
+ }
13
+ /** 패키지에 든 스킬 이름 (공통 폴더 제외) */
14
+ export declare function skillNames(root?: string): string[];
15
+ /** 원본에 공통 규칙과 버전 줄을 넣는다. 지문은 버전 줄을 뺀 본문으로 */
16
+ export declare function renderSkill(name: string, root?: string, version?: string): string;
17
+ /** 설치 위치: --project면 현재 폴더, 아니면 홈 */
18
+ export declare function skillsDir(opts: {
19
+ project: boolean;
20
+ cwd?: string | undefined;
21
+ home?: string | undefined;
22
+ }): string;
23
+ /** 설치된 스킬의 상태. 지문이 본문과 다르면 손으로 고친 것 */
24
+ export declare function inspectSkill(dir: string, name: string, version?: string): SkillStatus;
25
+ export interface InstallResult {
26
+ dir: string;
27
+ version: string;
28
+ skills: (SkillStatus & {
29
+ action: 'installed' | 'updated' | 'skipped' | 'kept' | 'newer';
30
+ })[];
31
+ }
32
+ export declare function install(opts: {
33
+ project: boolean;
34
+ force: boolean;
35
+ cwd?: string | undefined;
36
+ home?: string | undefined;
37
+ root?: string | undefined;
38
+ version?: string | undefined;
39
+ }): Promise<InstallResult>;
40
+ export declare function run(args: {
41
+ sub: string | undefined;
42
+ project: boolean;
43
+ force: boolean;
44
+ json: boolean;
45
+ }): Promise<CommandResult>;