@eliceio/cdk-cli 0.1.0-alpha.2 → 0.1.0-alpha.4

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 (103) hide show
  1. package/README.md +263 -191
  2. package/es/cli.js +93 -33
  3. package/es/commands/build/index.d.ts +1 -1
  4. package/es/commands/build/index.js +21 -12
  5. package/es/commands/check/index.d.ts +11 -2
  6. package/es/commands/check/index.js +51 -5
  7. package/es/commands/create/index.d.ts +6 -0
  8. package/es/commands/create/index.js +56 -8
  9. package/es/commands/create/install.d.ts +17 -0
  10. package/es/commands/create/install.js +53 -0
  11. package/es/commands/create/scaffold.d.ts +6 -1
  12. package/es/commands/create/scaffold.js +27 -17
  13. package/es/commands/dev/index.d.ts +1 -1
  14. package/es/commands/dev/index.js +6 -2
  15. package/es/commands/doctor/index.d.ts +21 -0
  16. package/es/commands/doctor/index.js +255 -38
  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 +2 -5
  22. package/es/commands/skill/index.js +1 -29
  23. package/es/core/collect.d.ts +5 -2
  24. package/es/core/config.d.ts +141 -31
  25. package/es/core/config.js +341 -59
  26. package/es/core/manifest.d.ts +2 -1
  27. package/es/core/manifest.js +2 -1
  28. package/es/core/minify.js +2 -2
  29. package/es/core/prepare.d.ts +18 -2
  30. package/es/core/prepare.js +47 -18
  31. package/es/core/project-check.d.ts +26 -0
  32. package/es/core/project-check.js +53 -0
  33. package/es/core/sandbox.js +2 -2
  34. package/es/core/sdk.d.ts +39 -0
  35. package/es/core/sdk.js +95 -0
  36. package/es/core/templates.d.ts +25 -0
  37. package/es/core/templates.js +41 -0
  38. package/es/dev/grading.d.ts +14 -7
  39. package/es/dev/grading.js +27 -13
  40. package/es/dev/host-page.d.ts +1 -1
  41. package/es/dev/host-page.js +34 -34
  42. package/es/dev/mock-api.d.ts +19 -4
  43. package/es/dev/mock-api.js +75 -9
  44. package/es/dev/server.d.ts +7 -0
  45. package/es/dev/server.js +112 -32
  46. package/es/rules/check.js +95 -10
  47. package/es/rules/index.d.ts +1 -1
  48. package/es/rules/index.js +1 -1
  49. package/es/rules/manifest.d.ts +23 -9
  50. package/es/rules/manifest.js +60 -35
  51. package/es/rules/node.js +3 -1
  52. package/es/rules/semver.d.ts +5 -0
  53. package/es/rules/semver.js +32 -0
  54. package/es/rules/types.d.ts +38 -7
  55. package/es/rules.json.js +2 -2
  56. package/es/test-packages.d.ts +7 -0
  57. package/guides/content-development.md +150 -55
  58. package/package.json +3 -3
  59. package/rules.json +77 -7
  60. package/skills/_shared/always.md +4 -2
  61. package/skills/elice-content-check/SKILL.md +3 -1
  62. package/skills/elice-content-create/SKILL.md +5 -4
  63. package/skills/elice-content-migrate/SKILL.md +2 -2
  64. package/skills/elice-content-publish/SKILL.md +23 -0
  65. package/templates/_shared/lib/cdk-mock.d.ts +21 -3
  66. package/templates/_shared/lib/cdk-mock.js +241 -82
  67. package/templates/_shared/lib/elice-content.css +204 -0
  68. package/templates/_shared/lib/elice-content.d.ts +115 -6
  69. package/templates/_shared/lib/elice-content.js +656 -43
  70. package/templates/blank/README.md +19 -7
  71. package/templates/blank/completion.html +15 -0
  72. package/templates/blank/gitignore +1 -0
  73. package/templates/blank/metadata.json +11 -0
  74. package/templates/blank/package.json +13 -0
  75. package/templates/blank/screens/completion.js +7 -0
  76. package/templates/blank/screens/edit.js +3 -0
  77. package/templates/blank/screens/instructor.js +12 -5
  78. package/templates/blank/screens/learn.js +16 -11
  79. package/templates/blank/template.json +6 -0
  80. package/templates/quiz/README.md +41 -31
  81. package/templates/quiz/core/behaviors.d.ts +5 -0
  82. package/templates/quiz/core/behaviors.js +12 -0
  83. package/templates/quiz/core/editor.d.ts +12 -1
  84. package/templates/quiz/core/editor.js +28 -5
  85. package/templates/quiz/core/model.d.ts +41 -1
  86. package/templates/quiz/core/model.js +272 -5
  87. package/templates/quiz/gitignore +1 -0
  88. package/templates/quiz/metadata.json +11 -0
  89. package/templates/quiz/package.json +13 -0
  90. package/templates/quiz/screens/edit.js +176 -46
  91. package/templates/quiz/screens/instructor.js +18 -12
  92. package/templates/quiz/screens/learn.js +43 -38
  93. package/templates/quiz/styles.css +47 -0
  94. package/templates/quiz/template.json +6 -0
  95. package/templates/quiz/ui/templates/edit.d.ts +3 -0
  96. package/templates/quiz/ui/templates/edit.js +53 -14
  97. package/templates/quiz/ui/texts.js +56 -29
  98. package/templates/_shared/lib/cdk.js +0 -3
  99. package/templates/blank/content.json +0 -4
  100. package/templates/blank/elice.config.json +0 -12
  101. package/templates/quiz/content.json +0 -81
  102. package/templates/quiz/elice.config.json +0 -14
  103. package/templates/quiz/grading.json +0 -13
@@ -1,15 +1,15 @@
1
- import { readFileSync } from 'node:fs';
2
- import { readdir, mkdir, cp, rename, readFile, writeFile } from 'node:fs/promises';
1
+ import { readdir, mkdir, cp, rm, rename, readFile, writeFile } from 'node:fs/promises';
3
2
  import { resolve, join, basename } from 'node:path';
4
3
  import { fileURLToPath } from 'node:url';
4
+ import { SDK_PACKAGE } from '../../core/sdk.js';
5
+ import { listTemplates } from '../../core/templates.js';
6
+ import { localSdkSpec } from './install.js';
5
7
 
6
8
  const TEMPLATES = ['quiz', 'blank'];
7
9
  /** 화면 테마. dark는 화면 HTML에 data-eds-theme="dark"를 붙여 EDS 어두운 팔레트를 쓴다 */
8
10
  const THEMES = ['light', 'dark'];
9
11
  /** 패키지 루트의 templates/ (es/commands/create/와 src/commands/create/ 모두 세 단계 위) */
10
12
  const TEMPLATE_ROOT = fileURLToPath(new URL('../../../templates', import.meta.url));
11
- /** 템플릿을 묶어 배포하는 @eliceio/cdk-cli 버전 (패키지 루트의 package.json) */
12
- const PACKAGE_VERSION = JSON.parse(readFileSync(fileURLToPath(new URL('../../../package.json', import.meta.url)), 'utf8')).version;
13
13
  async function listFiles(dir, base = '') {
14
14
  const out = [];
15
15
  for (const e of await readdir(join(dir, base), {
@@ -21,7 +21,8 @@ async function listFiles(dir, base = '') {
21
21
  return out.sort();
22
22
  }
23
23
  /**
24
- * 템플릿(화면 3개 + 내용 + 설정)과 공통 lib/(키트, @eliceio/cdk 묶음, 기본 스타일)를 새 폴더에 복사한다.
24
+ * 템플릿(화면 · metadata.json · package.json)과 공통 lib/(화면 키트 · 기본 스타일 · 로컬 mock)를 새 폴더에 복사한다.
25
+ * SDK(@eliceio/cdk)는 package.json 의존성이라 복사하지 않는다 (설치는 create 명령이 npm install로, build가 zip lib/cdk.js로 넣음).
25
26
  * 비어 있지 않은 폴더에는 만들지 않는다 (덮어쓰기 방지).
26
27
  */
27
28
  async function createProject(options) {
@@ -43,6 +44,10 @@ async function createProject(options) {
43
44
  await cp(join(TEMPLATE_ROOT, options.template), dir, {
44
45
  recursive: true
45
46
  });
47
+ // template.json은 CLI가 템플릿을 고를 때만 쓴다 (프로젝트 · zip에는 넣지 않음)
48
+ await rm(join(dir, 'template.json'), {
49
+ force: true
50
+ });
46
51
  // npm은 패키지 안의 .gitignore를 빼고 배포하므로 이름을 바꿔 두었다가 되돌린다
47
52
  await rename(join(dir, 'gitignore'), join(dir, '.gitignore'));
48
53
  if (theme === 'dark') {
@@ -53,27 +58,32 @@ async function createProject(options) {
53
58
  await writeFile(path, html.replace(/<html(?![^>]*data-eds-theme)/, '<html data-eds-theme="dark"'));
54
59
  }
55
60
  }
56
- // 어떤 템플릿 · 버전으로 만들었는지 (build가 metadata.json build.template에 적음)
57
- const configPath = join(dir, 'elice.config.json');
58
- const config = JSON.parse(await readFile(configPath, 'utf8'));
59
- await writeFile(configPath, `${JSON.stringify({
60
- template: `${options.template}@${PACKAGE_VERSION}`,
61
- ...config
62
- }, null, 2)}\n`);
61
+ // 어떤 템플릿 · 버전으로 만들었는지 (템플릿마다 따로 올리는 template.json version). package.json "ecdk".template에 적고
62
+ // build가 metadata.json build.template으로 옮긴다 (ADR 0011)
63
+ const version = listTemplates().find(t => t.name === options.template)?.version ?? '0.0.0';
63
64
  const name = options.name ?? basename(dir);
64
65
  const readme = join(dir, 'README.md');
65
66
  await writeFile(readme, (await readFile(readme, 'utf8')).replaceAll('{{name}}', name));
66
- await writeFile(join(dir, 'package.json'), `${JSON.stringify({
67
+ // package.json: 템플릿 것(스크립트 · SDK 범위 · "ecdk" 빌드 옵션)에 이름과 템플릿 버전("ecdk".template)을 붙인다.
68
+ // 템플릿의 SDK 범위는 저장소 워크스페이스 표기(workspace:^X)라 npm이 아는 범위(^X)로 바꾼다.
69
+ // ECDK_LOCAL_PACKAGES(저장소 시험용)면 SDK를 그 폴더의 패키지 파일(.tgz)로 (배포 전 SDK는 레지스트리에 없음)
70
+ const pkgPath = join(dir, 'package.json');
71
+ const pkg = JSON.parse(await readFile(pkgPath, 'utf8'));
72
+ const localSdk = await localSdkSpec(options.localPackages);
73
+ const dependencies = Object.fromEntries(Object.entries(pkg.dependencies ?? {}).map(([n, range]) => [n, n === SDK_PACKAGE && localSdk ? localSdk : range.replace(/^workspace:/, '')]));
74
+ await writeFile(pkgPath, `${JSON.stringify({
67
75
  name: name.toLowerCase().replace(/[^a-z0-9-_.]+/g, '-'),
68
- private: true,
69
- scripts: {
70
- doctor: 'ecdk doctor',
71
- build: 'ecdk build'
76
+ ...pkg,
77
+ dependencies,
78
+ ecdk: {
79
+ template: `${options.template}@${version}`,
80
+ ...pkg.ecdk
72
81
  }
73
82
  }, null, 2)}\n`);
74
83
  return {
75
84
  dir,
76
85
  template: options.template,
86
+ version,
77
87
  theme,
78
88
  files: await listFiles(dir)
79
89
  };
@@ -1,5 +1,5 @@
1
1
  import type { CommandResult } from '../../types.js';
2
- export declare const usage = "\uC0AC\uC6A9\uBC95: ecdk dev [\uD504\uB85C\uC81D\uD2B8 \uD3F4\uB354] [--port 4170]\n\n \uB85C\uCEEC\uC5D0\uC11C \uC6B4\uC601\uACFC \uAC19\uC740 \uC870\uAC74\uC73C\uB85C \uCF58\uD150\uCE20\uB97C \uB744\uC6B4\uB2E4.\n - http://localhost:<port> LXP \uD749\uB0B4 \uD654\uBA74: \uD559\uC0DD \u00B7 \uD29C\uD130\uB9C1 \u00B7 \uAD50\uC721\uC790 \uD654\uBA74 \u00B7 \uB0B4\uC6A9 \uD3B8\uC9D1\n - \uCF58\uD150\uCE20\uB294 \uB2E4\uB978 \uCD9C\uCC98(127.0.0.1:<port+1>)\uC5D0\uC11C \uC6B4\uC601 \uD5E4\uB354(CSP sandbox allow-scripts)\uB85C\n - \uC2E4\uC81C @eliceio/cdk\uAC00 elice-material \uD749\uB0B4 API\uC640 \uD1B5\uC2E0, \uCC44\uC810\uC740 grading.json(\uC720\uD615 \u00B7 \uC815\uB2F5, \uC5C6\uC73C\uBA74 gradingTypes \uCCAB \uC720\uD615)\n - \uD30C\uC77C\uC744 \uACE0\uCE58\uBA74 \uB2E4\uC2DC \uAC80\uC0AC\uD558\uACE0 \uD654\uBA74\uC744 \uC0C8\uB85C \uB744\uC6C0, \uCF58\uD150\uCE20\uC758 \uCF58\uC194 \uC624\uB958\uC640 404\uB97C \uC5EC\uAE30\uC5D0 \uD45C\uC2DC\n\n\uB05D\uB0B4\uAE30: Ctrl+C";
2
+ export declare const usage = "\uC0AC\uC6A9\uBC95: ecdk dev [\uD504\uB85C\uC81D\uD2B8 \uD3F4\uB354] [--port 4170]\n\n \uB85C\uCEEC\uC5D0\uC11C \uC6B4\uC601\uACFC \uAC19\uC740 \uC870\uAC74\uC73C\uB85C \uCF58\uD150\uCE20\uB97C \uB744\uC6B4\uB2E4.\n - http://localhost:<port> LXP \uD749\uB0B4 \uD654\uBA74: \uD559\uC0DD \u00B7 \uD29C\uD130\uB9C1 \u00B7 \uAD50\uC721\uC790 \uD654\uBA74 \u00B7 \uB0B4\uC6A9 \uD3B8\uC9D1 \u00B7 \uC644\uB8CC \uC815\uCC45\n - \uCF58\uD150\uCE20\uB294 \uB2E4\uB978 \uCD9C\uCC98(127.0.0.1:<port+1>)\uC5D0\uC11C \uC6B4\uC601 \uD5E4\uB354(CSP sandbox allow-scripts)\uB85C\n - \uD3EC\uD2B8\uB97C \uB450 \uAC1C(N \u00B7 N+1) \uC4F4\uB2E4. --port \uC5C6\uC774 \uC5F4 \uB54C 4170 \u00B7 4171\uC774 \uC4F0\uC774\uACE0 \uC788\uC73C\uBA74 \uB2E4\uC74C \uC30D(4172 \u00B7 4173 \u2026)\uC744 \uC4F4\uB2E4\n - \uC2E4\uC81C @eliceio/cdk\uAC00 elice-material \uD749\uB0B4 API\uC640 \uD1B5\uC2E0. \uB0B4\uC6A9 \uD3B8\uC9D1\uC5D0\uC11C \uC800\uC7A5\uD55C settings(\uB0B4\uC6A9 + \uCC44\uC810 \uBC29\uC2DD \u00B7 \uB2F5)\uB294\n .ecdk/settings.json, \uC644\uB8CC \uC815\uCC45\uC740 metadata.json completionPolicies \uCCAB \uAC12 (\uC644\uB8CC \uC815\uCC45 \uBCF4\uAE30\uC5D0\uC11C \uACE0\uB974\uBA74\n .ecdk/completion.json, screens.completionPolicy\uB97C \uCF20 \uC790\uB8CC\uB9CC)\uC5D0 \uC4F4\uB2E4. \uB2E4\uC2DC \uC5F4\uC5B4\uB3C4 \uB0A8\uACE0, zip\uC5D0\uB294 \uB4E4\uC5B4\uAC00\uC9C0 \uC54A\uB294\uB2E4\n (\uC6B4\uC601\uC740 SDK saveSettings \u00B7 saveCompletionPolicy \u2192 \uC11C\uBC84 settings \u00B7 completion_policy)\n - \uD30C\uC77C\uC744 \uACE0\uCE58\uBA74 \uB2E4\uC2DC \uAC80\uC0AC\uD558\uACE0 \uD654\uBA74\uC744 \uC0C8\uB85C \uB744\uC6C0, \uCF58\uD150\uCE20\uC758 \uCF58\uC194 \uC624\uB958\uC640 404\uB97C \uC5EC\uAE30\uC5D0 \uD45C\uC2DC\n\n\uB05D\uB0B4\uAE30: Ctrl+C";
3
3
  export declare function run(args: {
4
4
  target: string;
5
5
  port?: string;
@@ -3,9 +3,13 @@ import { startDevServer } from '../../dev/server.js';
3
3
  const usage = `사용법: ecdk dev [프로젝트 폴더] [--port 4170]
4
4
 
5
5
  로컬에서 운영과 같은 조건으로 콘텐츠를 띄운다.
6
- - http://localhost:<port> LXP 흉내 화면: 학생 · 튜터링 · 교육자 화면 · 내용 편집
6
+ - http://localhost:<port> LXP 흉내 화면: 학생 · 튜터링 · 교육자 화면 · 내용 편집 · 완료 정책
7
7
  - 콘텐츠는 다른 출처(127.0.0.1:<port+1>)에서 운영 헤더(CSP sandbox allow-scripts)로
8
- - 실제 @eliceio/cdk가 elice-material 흉내 API와 통신, 채점은 grading.json(유형 · 정답, 없으면 gradingTypes 첫 유형)
8
+ - 포트를 두 개(N · N+1) 쓴다. --port 없이 열 때 4170 · 4171이 쓰이고 있으면 다음 쌍(4172 · 4173 …)을 쓴다
9
+ - 실제 @eliceio/cdk가 elice-material 흉내 API와 통신. 내용 편집에서 저장한 settings(내용 + 채점 방식 · 답)는
10
+ .ecdk/settings.json, 완료 정책은 metadata.json completionPolicies 첫 값 (완료 정책 보기에서 고르면
11
+ .ecdk/completion.json, screens.completionPolicy를 켠 자료만)에 쓴다. 다시 열어도 남고, zip에는 들어가지 않는다
12
+ (운영은 SDK saveSettings · saveCompletionPolicy → 서버 settings · completion_policy)
9
13
  - 파일을 고치면 다시 검사하고 화면을 새로 띄움, 콘텐츠의 콘솔 오류와 404를 여기에 표시
10
14
 
11
15
  끝내기: Ctrl+C`;
@@ -1,3 +1,5 @@
1
+ import { type ContentConfig } from '../../core/config.js';
2
+ import { type McpEnv } from '../mcp/index.js';
1
3
  import type { CommandResult } from '../../types.js';
2
4
  export declare const usage = "\uC0AC\uC6A9\uBC95: ecdk doctor [\uD504\uB85C\uC81D\uD2B8 \uD3F4\uB354] [--fix] [--json]\n\n \uD658\uACBD(Node, \uD328\uD0A4\uC9C0 \uB9E4\uB2C8\uC800)\uACFC \uD504\uB85C\uC81D\uD2B8(\uC124\uC815, \uC6D0\uBCF8, \uC815\uB2F5 \uC720\uCD9C, \uAC80\uC0AC)\uB97C \uC810\uAC80\uD55C\uB2E4.\n --fix \uC790\uB3D9\uC73C\uB85C \uACE0\uCE60 \uC218 \uC788\uB294 \uD56D\uBAA9(auto)\uC744 \uACE0\uCE5C\uB2E4\n\n\uC885\uB8CC \uCF54\uB4DC: 0 \uC2E4\uD328 \uC5C6\uC74C \u00B7 1 \uC2E4\uD328 \uC788\uC74C \u00B7 2 \uC798\uBABB\uB41C \uC0AC\uC6A9";
3
5
  export type DoctorLevel = 'ok' | 'warn' | 'fail' | 'skip';
@@ -12,6 +14,10 @@ export interface DoctorCheck {
12
14
  } | undefined;
13
15
  fixed?: boolean | undefined;
14
16
  }
17
+ /** 자동 고침 동작은 출력(JSON)에 싣지 않고 점검 항목 옆에만 둔다. */
18
+ type Pending = DoctorCheck & {
19
+ apply?: () => Promise<void>;
20
+ };
15
21
  export interface DoctorResult {
16
22
  ok: boolean;
17
23
  cli: string;
@@ -19,10 +25,24 @@ export interface DoctorResult {
19
25
  checks: DoctorCheck[];
20
26
  }
21
27
  export declare function checkNode(version: string): DoctorCheck;
28
+ /** Claude Code 스킬: 프로젝트(.claude/skills) 또는 홈(~/.claude/skills)에 모두 있고 CLI와 같은 버전인지 */
29
+ export declare function checkSkills(dir: string, home?: string): DoctorCheck;
30
+ /** 프로젝트를 만든 템플릿 · 버전 (package.json "ecdk".template). 이 CLI에 더 새 버전이 있으면 알리기만 한다 (자동 갱신 없음) */
31
+ export declare function checkTemplate(config: ContentConfig): DoctorCheck;
32
+ /** dir부터 위로 올라가며 <폴더>/.claude/skills 목록. 홈 폴더나 파일 시스템 루트에서 멈춘다 (홈은 사용자 위치라 따로) */
33
+ export declare function projectSkillDirs(dir: string, home?: string): string[];
34
+ /**
35
+ * SDK 의존성 (ADR 0010 최종 결정): package.json의 @eliceio/cdk가 설치됐는지, rules.json minVersions.sdk 이상인지.
36
+ * package.json에 없고 옛 lib/cdk.js 복사본만 있으면 경고하고, --fix가 package.json dependencies에 넣는다 (npm install은 직접)
37
+ */
38
+ export declare function checkDeps(dir: string, config: ContentConfig): Promise<Pending>;
39
+ /** 학습자료 서버 MCP(elice-material)가 찾은 도구 중 하나에라도 등록돼 있는지 (읽기만) */
40
+ export declare function checkMcp(env: McpEnv): DoctorCheck;
22
41
  export declare function doctor(target: string, opts: {
23
42
  fix: boolean;
24
43
  nodeVersion?: string;
25
44
  home?: string | undefined;
45
+ mcp?: McpEnv | undefined;
26
46
  }): Promise<DoctorResult>;
27
47
  export declare function formatText(r: DoctorResult): string;
28
48
  export declare function run(args: {
@@ -32,3 +52,4 @@ export declare function run(args: {
32
52
  }): Promise<CommandResult>;
33
53
  /** 주석뿐이 아닌 줄에서 정답·설정 파일 이름이 나오는지. 줄 건너뛰기는 금지 API 검사와 같은 규칙(content-rules lineSkipper) */
34
54
  export declare function referencesAnswerFile(text: string): boolean;
55
+ export {};
@@ -1,13 +1,19 @@
1
- import { access, readFile, appendFile } from 'node:fs/promises';
2
- import { resolve, join } from 'node:path';
3
- import { loadConfig, CONFIG_FILE, loadGrading, GRADING_DATA_FILE } from '../../core/config.js';
1
+ import { readFile, writeFile, access, appendFile } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { resolve, join, dirname } from 'node:path';
4
+ import { loadConfig, CONFIG_FILE, planLegacyMigration, applyLegacyMigration, PACKAGE_FILE, PACKAGE_CONFIG_KEY, legacyGradingTypesWarning, loadGrading, SETTINGS_DATA_FILE } from '../../core/config.js';
4
5
  import { prepareContent } from '../../core/prepare.js';
6
+ import { projectCheckOptions, findLegacySdkCopy } from '../../core/project-check.js';
7
+ import { readProjectSdk, SDK_PACKAGE, INSTALL_COMMAND, UPDATE_COMMAND } from '../../core/sdk.js';
8
+ import { parseTemplateRef, listTemplates } from '../../core/templates.js';
5
9
  import { checkFiles } from '../../rules/check.js';
6
10
  import { lineSkipper } from '../../rules/skip.js';
7
- import { RULES_VERSION } from '../../rules/spec.js';
11
+ import { RULES_VERSION, rules } from '../../rules/spec.js';
8
12
  import 'fflate';
9
13
  import { VERSION } from '../../version.js';
14
+ import { defaultMcpEnv, detectTargets, claudeRegistration, helpyRegisteredUrl, envOfUrl, MCP_NAME } from '../mcp/index.js';
10
15
  import { skillsDir, skillNames, inspectSkill } from '../skill/index.js';
16
+ import { compareVersions } from '../../rules/semver.js';
11
17
 
12
18
  const usage = `사용법: ecdk doctor [프로젝트 폴더] [--fix] [--json]
13
19
 
@@ -87,21 +93,27 @@ async function checkGitignore(dir, config) {
87
93
  /** Claude Code 스킬: 프로젝트(.claude/skills) 또는 홈(~/.claude/skills)에 모두 있고 CLI와 같은 버전인지 */
88
94
  function checkSkills(dir, home) {
89
95
  const fix = {
90
- description: '스킬 설치 · 갱신',
91
- command: 'ecdk skill install',
96
+ description: '스킬 설치 · 갱신 (MCP 등록까지 한 번에)',
97
+ command: 'ecdk setup',
92
98
  auto: false
93
99
  };
94
- const project = skillsDir({
95
- project: true,
96
- cwd: dir
97
- });
100
+ // 프로젝트 폴더부터 위로(홈 · 루트까지) .claude/skills를 찾고, 없으면 홈(~/.claude/skills).
101
+ // Claude Code는 세션을 연 폴더의 .claude/skills를 읽으므로 ecdk create로 만든 하위 폴더에서도 상위 설치를 인정한다
98
102
  const user = skillsDir({
99
103
  project: false,
100
104
  home
101
105
  });
106
+ const dirs = [...projectSkillDirs(dir, home), user];
107
+ const where = new Set();
102
108
  const statuses = skillNames().map(name => {
103
- const local = inspectSkill(project, name);
104
- return local.state === 'missing' ? inspectSkill(user, name) : local;
109
+ for (const d of dirs) {
110
+ const s = inspectSkill(d, name);
111
+ if (s.state !== 'missing') {
112
+ where.add(d);
113
+ return s;
114
+ }
115
+ }
116
+ return inspectSkill(user, name);
105
117
  });
106
118
  const missing = statuses.filter(s => s.state === 'missing').map(s => s.name);
107
119
  const outdated = statuses.filter(s => s.state === 'outdated').map(s => s.name);
@@ -121,33 +133,81 @@ function checkSkills(dir, home) {
121
133
  return {
122
134
  id: 'skill.installed',
123
135
  level: 'ok',
124
- message: newer.length > 0 ? `Claude Code 스킬 ${statuses.length}개 · CLI(${VERSION})보다 새 버전: ${newer.join(', ')}` : `Claude Code 스킬 ${statuses.length}개`
136
+ message: newer.length > 0 ? `Claude Code 스킬 ${statuses.length}개 (${[...where].join(', ')}) · CLI(${VERSION})보다 새 버전: ${newer.join(', ')}` : `Claude Code 스킬 ${statuses.length}개 (${[...where].join(', ')})`
125
137
  };
126
138
  }
127
- /** grading.json: 형식 · 유형이 지원 유형 안인지. 정답 비교 유형을 지원하는데 파일이 없으면 로컬 채점을 흉내 낼 수 없다 */
139
+ /** 프로젝트를 만든 템플릿 · 버전 (package.json "ecdk".template). 이 CLI에 더 새 버전이 있으면 알리기만 한다 (자동 갱신 없음) */
140
+ function checkTemplate(config) {
141
+ const id = 'project.template';
142
+ if (!config.template) return {
143
+ id,
144
+ level: 'skip',
145
+ message: '템플릿 정보 없음 (ecdk create 없이 만들었거나 옛 프로젝트)'
146
+ };
147
+ const {
148
+ name,
149
+ version
150
+ } = parseTemplateRef(config.template);
151
+ const shipped = listTemplates().find(t => t.name === name);
152
+ if (!shipped) return {
153
+ id,
154
+ level: 'ok',
155
+ message: `${config.template} (이 ecdk에는 없는 템플릿)`
156
+ };
157
+ const newer = version !== undefined && (compareVersions(shipped.version, version) ?? 0) > 0;
158
+ return {
159
+ id,
160
+ level: 'ok',
161
+ message: newer ? `${config.template} · 이 ecdk에는 ${name}@${shipped.version}이 있습니다 (자동으로 바꾸지 않음. 바뀐 점은 ecdk create --list와 템플릿 README)` : config.template
162
+ };
163
+ }
164
+ /** dir부터 위로 올라가며 <폴더>/.claude/skills 목록. 홈 폴더나 파일 시스템 루트에서 멈춘다 (홈은 사용자 위치라 따로) */
165
+ function projectSkillDirs(dir, home = homedir()) {
166
+ const out = [];
167
+ const stop = resolve(home);
168
+ let cur = resolve(dir);
169
+ for (;;) {
170
+ if (cur === stop) break;
171
+ out.push(skillsDir({
172
+ project: true,
173
+ cwd: cur
174
+ }));
175
+ const parent = dirname(cur);
176
+ if (parent === cur) break;
177
+ cur = parent;
178
+ }
179
+ return out;
180
+ }
181
+ /**
182
+ * 로컬 채점 흉내 (ecdk dev): 완료 정책은 .ecdk/completion.json(ecdk dev 완료 정책 화면, completionPolicies 안일 때) · 첫 값,
183
+ * 채점 설정은 ecdk dev 내용 편집이 저장한 .ecdk/settings.json의 grading. 답이 아직 없어도 정상이다 (편집 화면에서 정함).
184
+ * 옛 elice.config.json gradingTypes는 경고, .ecdk/settings.json 형식이 틀리면 실패
185
+ */
128
186
  async function checkGrading(dir, config) {
129
187
  const id = 'project.grading';
130
- if (!config.gradingTypes || config.gradingTypes.length === 0) return {
188
+ if (config.kind === 'description') return {
131
189
  id,
132
190
  level: 'skip',
133
- message: '채점 유형 없음 (문제 설명)'
191
+ message: '채점 없음 (문제 설명)'
134
192
  };
193
+ const legacy = legacyGradingTypesWarning(config);
135
194
  try {
136
195
  const grading = await loadGrading(dir, config);
137
- const needsAnswers = config.gradingTypes.some(t => t === 'pattern' || t === 'rubric');
138
- if (needsAnswers && !(await exists(join(dir, GRADING_DATA_FILE)))) return {
196
+ if (legacy) return {
139
197
  id,
140
198
  level: 'warn',
141
- message: `${GRADING_DATA_FILE}이 없어 ecdk dev에서 pattern · rubric 채점을 흉내 낼 수 없습니다`,
199
+ message: legacy,
142
200
  fix: {
143
- description: `정답을 ${GRADING_DATA_FILE}에 적기 (zip에는 들어가지 않음)`,
201
+ description: `${CONFIG_FILE}에서 gradingTypes 지우기`,
144
202
  auto: false
145
203
  }
146
204
  };
205
+ const policy = grading?.completion_policy ?? '-';
206
+ const answers = grading?.grading ? ` · 답 ${grading.grading.type} (${SETTINGS_DATA_FILE})` : policy === 'on_graded' ? " · 답 아직 없음 (ecdk dev의 '내용 편집'에서 저장하면 학생 보기가 채점)" : '';
147
207
  return {
148
208
  id,
149
209
  level: 'ok',
150
- message: `${GRADING_DATA_FILE}: 로컬 채점 유형 ${grading?.type ?? '-'}`
210
+ message: `로컬 완료 정책 ${policy}${answers}`
151
211
  };
152
212
  } catch (e) {
153
213
  return {
@@ -155,31 +215,184 @@ async function checkGrading(dir, config) {
155
215
  level: 'fail',
156
216
  message: e.message,
157
217
  fix: {
158
- description: `${GRADING_DATA_FILE} 형식을 고치기 (ecdk guide 2)`,
218
+ description: `${SETTINGS_DATA_FILE}을 지우고 ecdk dev의 '내용 편집'에서 다시 저장`,
159
219
  auto: false
160
220
  }
161
221
  };
162
222
  }
163
223
  }
224
+ /**
225
+ * 프로젝트 설정 (ADR 0011): package.json "ecdk"(빌드 옵션) + 원본 metadata.json(화면 · 완료 정책). 옛 elice.config.json이
226
+ * 남아 있으면 경고하고, --fix가 metadata.json · package.json "ecdk"로 옮긴 뒤 지운다 (내용 · 답 파일은 옮기지 않음)
227
+ */
228
+ async function checkConfig(dir, config) {
229
+ const id = 'project.config';
230
+ if (await exists(join(dir, CONFIG_FILE))) {
231
+ const plan = await planLegacyMigration(dir);
232
+ const dropped = plan.dropped.length > 0 ? ` (${plan.dropped.join(' · ')}는 버림)` : '';
233
+ return {
234
+ id,
235
+ level: 'warn',
236
+ message: `옛 ${CONFIG_FILE}이 있습니다 (ADR 0011). 화면 · 완료 정책은 원본의 metadata.json, 빌드 옵션 · template은 package.json "ecdk"에 둡니다.${plan.ok ? '' : ` ${plan.reason}`}`,
237
+ fix: plan.ok ? {
238
+ description: `${plan.metadata ? `${plan.metadata.path} 만들기 · ` : ''}package.json "ecdk"로 옮기고 ${CONFIG_FILE} 지우기${dropped}`,
239
+ auto: true
240
+ } : {
241
+ description: plan.reason ?? '',
242
+ auto: false
243
+ },
244
+ ...(plan.ok ? {
245
+ apply: async () => {
246
+ await applyLegacyMigration(dir, plan);
247
+ }
248
+ } : {})
249
+ };
250
+ }
251
+ return {
252
+ id,
253
+ level: 'ok',
254
+ message: config.configFile === PACKAGE_FILE ? `${PACKAGE_FILE} "${PACKAGE_CONFIG_KEY}" 읽음` : `${PACKAGE_FILE} "${PACKAGE_CONFIG_KEY}" 없음 (기본값 사용)`
255
+ };
256
+ }
257
+ /**
258
+ * SDK 의존성 (ADR 0010 최종 결정): package.json의 @eliceio/cdk가 설치됐는지, rules.json minVersions.sdk 이상인지.
259
+ * package.json에 없고 옛 lib/cdk.js 복사본만 있으면 경고하고, --fix가 package.json dependencies에 넣는다 (npm install은 직접)
260
+ */
261
+ async function checkDeps(dir, config) {
262
+ const id = 'project.deps';
263
+ const min = rules.minVersions.sdk;
264
+ const sdk = await readProjectSdk(dir);
265
+ if (!sdk) {
266
+ const copy = await findLegacySdkCopy(dir, config);
267
+ if (!copy) return {
268
+ id,
269
+ level: 'skip',
270
+ message: `package.json에 ${SDK_PACKAGE} 없음 (SDK를 쓰지 않는 자료)`
271
+ };
272
+ return {
273
+ id,
274
+ level: 'warn',
275
+ message: `옛 ${copy} 복사본을 씁니다. SDK는 package.json 의존성으로 받습니다 (ecdk build가 node_modules에서 zip lib/cdk.js로 넣음). --fix로 넣은 뒤 ${INSTALL_COMMAND}을 실행해 주세요.`,
276
+ fix: {
277
+ description: `package.json dependencies에 "${SDK_PACKAGE}": "^${min}" 넣기 (그다음 ${INSTALL_COMMAND}, ${copy}는 지워도 됨)`,
278
+ auto: true
279
+ },
280
+ apply: async () => {
281
+ const path = join(dir, PACKAGE_FILE);
282
+ const raw = await readFile(path, 'utf8').catch(() => null);
283
+ const pkg = raw ? JSON.parse(raw) : {
284
+ private: true
285
+ };
286
+ const deps = pkg.dependencies ?? {};
287
+ pkg.dependencies = {
288
+ ...deps,
289
+ [SDK_PACKAGE]: `^${min}`
290
+ };
291
+ await writeFile(path, `${JSON.stringify(pkg, null, 2)}\n`);
292
+ }
293
+ };
294
+ }
295
+ if (!sdk.installed) return {
296
+ id,
297
+ level: 'fail',
298
+ message: `${SDK_PACKAGE}(${sdk.range})가 설치되지 않았습니다 (node_modules에 없음).`,
299
+ fix: {
300
+ description: '의존성 설치',
301
+ command: INSTALL_COMMAND,
302
+ auto: false
303
+ }
304
+ };
305
+ const {
306
+ version
307
+ } = sdk.installed;
308
+ if ((compareVersions(version, min) ?? 0) < 0) return {
309
+ id,
310
+ level: 'fail',
311
+ message: `${SDK_PACKAGE} ${version}은 최소 버전 ${min}보다 낮습니다 (LXP에서 저장 · 제출이 안 될 수 있음).`,
312
+ fix: {
313
+ description: 'SDK 올리기',
314
+ command: UPDATE_COMMAND,
315
+ auto: false
316
+ }
317
+ };
318
+ return {
319
+ id,
320
+ level: 'ok',
321
+ message: `${SDK_PACKAGE} ${version} (최소 ${min})`
322
+ };
323
+ }
324
+ /** 학습자료 서버 MCP(elice-material)가 찾은 도구 중 하나에라도 등록돼 있는지 (읽기만) */
325
+ function checkMcp(env) {
326
+ const id = 'mcp.material';
327
+ const fix = {
328
+ description: 'MCP 등록 (자료를 LXP에 올릴 때 필요)',
329
+ command: 'ecdk setup',
330
+ auto: false
331
+ };
332
+ const targets = detectTargets(env);
333
+ if (targets.length === 0) return {
334
+ id,
335
+ level: 'skip',
336
+ message: 'Claude Code · Helpy Code를 찾지 못함'
337
+ };
338
+ const found = [];
339
+ const notes = [];
340
+ const envs = new Set();
341
+ for (const t of targets) {
342
+ let url;
343
+ if (t === 'claude') {
344
+ const reg = claudeRegistration(env);
345
+ if (reg.state === 'unknown') {
346
+ notes.push(`Claude Code 확인 못 함 (${reg.reason})`);
347
+ continue;
348
+ }
349
+ if (reg.state === 'other-scope') {
350
+ notes.push(`Claude Code는 ${reg.scope} 범위에만 있음 (이 폴더 전용, 다른 폴더에서는 없음)`);
351
+ continue;
352
+ }
353
+ url = reg.state === 'user' ? reg.url : null;
354
+ } else url = helpyRegisteredUrl(env);
355
+ if (!url) continue;
356
+ const name = envOfUrl(url);
357
+ envs.add(name);
358
+ found.push(`${t === 'claude' ? 'Claude Code' : 'Helpy Code'}(${name})`);
359
+ }
360
+ const extra = notes.length > 0 ? ` · ${notes.join(' · ')}` : '';
361
+ const notProd = [...envs].filter(e => e !== 'prod');
362
+ const note = notProd.length > 0 ? ` — ${notProd.map(e => e === 'custom' ? '직접 지정한 서버' : `QA 환경(${e})`).join(' · ')}에 연결됨, 운영 자료를 올리지 마세요` : '';
363
+ if (found.length > 0) return {
364
+ id,
365
+ level: 'ok',
366
+ message: `${MCP_NAME} 등록: ${found.join(', ')}${note}${extra}`
367
+ };
368
+ // 확인만 못 한 경우는 경고하지 않는다 (등록돼 있는데 느린 것일 수 있음)
369
+ if (notes.length > 0 && notes.every(n => n.includes('확인 못 함'))) return {
370
+ id,
371
+ level: 'skip',
372
+ message: `${MCP_NAME} 등록 ${notes.join(' · ')}`
373
+ };
374
+ return {
375
+ id,
376
+ level: 'warn',
377
+ message: `${MCP_NAME} MCP가 사용자 범위에 등록돼 있지 않습니다${extra}`,
378
+ fix
379
+ };
380
+ }
164
381
  async function doctor(target, opts) {
165
382
  const dir = resolve(target);
166
383
  const checks = [checkNode(opts.nodeVersion ?? process.version), await checkPackageManager(dir)];
167
384
  let config = null;
168
385
  try {
169
386
  config = await loadConfig(dir);
170
- checks.push({
171
- id: 'project.config',
172
- level: 'ok',
173
- message: (await exists(join(dir, CONFIG_FILE))) ? `${CONFIG_FILE} 읽음` : `${CONFIG_FILE} 없음 (기본값 사용)`
174
- });
387
+ checks.push(await checkConfig(dir, config));
175
388
  } catch (e) {
176
389
  checks.push({
177
390
  id: 'project.config',
178
391
  level: 'fail',
179
- message: `${CONFIG_FILE}을 읽을 수 없습니다: ${e.message}`
392
+ message: `설정을 읽을 수 없습니다: ${e.message}`
180
393
  });
181
394
  }
182
- if (config) checks.push(await checkGrading(dir, config));
395
+ if (config) checks.push(await checkDeps(dir, config), checkTemplate(config), await checkGrading(dir, config));
183
396
  if (config) {
184
397
  const srcDir = resolve(dir, config.root);
185
398
  if (!(await exists(srcDir))) {
@@ -191,7 +404,10 @@ async function doctor(target, opts) {
191
404
  } else {
192
405
  let prepared = null;
193
406
  try {
194
- prepared = await prepareContent(dir, config);
407
+ // SDK 설치 여부는 project.deps가 알린다
408
+ prepared = await prepareContent(dir, config, {
409
+ requireSdk: false
410
+ });
195
411
  } catch (e) {
196
412
  checks.push({
197
413
  id: 'project.root',
@@ -210,7 +426,7 @@ async function doctor(target, opts) {
210
426
  });
211
427
  // 빌드에서 빠지는 정답·설정 파일을 콘텐츠가 참조하면: 배포본에서 깨지고, 정답을 콘텐츠로 가져오려 한 신호.
212
428
  // 주석 줄은 보지 않고, 일부러 참조하는 줄은 `ecdk-ignore project.answer-import`로 끈다
213
- // (템플릿 mock SDK는 프로젝트 폴더에서 열 때 로컬 채점용으로 elice.config.json · grading.json을 읽는다)
429
+ // (키트 mock SDK는 프로젝트 폴더에서 열 때 로컬 채점용으로 .ecdk/settings.json을 읽는다)
214
430
  const decoder = new TextDecoder();
215
431
  const leaks = files.filter(f => /\.(html?|m?js|css)$/i.test(f.path)).filter(f => referencesAnswerFile(decoder.decode(f.data))).map(f => f.path);
216
432
  checks.push(leaks.length > 0 ? {
@@ -226,10 +442,7 @@ async function doctor(target, opts) {
226
442
  level: 'ok',
227
443
  message: '콘텐츠가 정답·설정 파일을 참조하지 않음'
228
444
  });
229
- const result = checkFiles(files, {
230
- input: 'zip',
231
- bundlesModules: true
232
- });
445
+ const result = checkFiles(files, await projectCheckOptions(dir, config));
233
446
  const errors = result.issues.filter(i => i.level === 'error');
234
447
  const warns = result.issues.length - errors.length;
235
448
  checks.push(errors.length > 0 ? {
@@ -257,6 +470,8 @@ async function doctor(target, opts) {
257
470
  if (await exists(join(dir, 'package.json'))) checks.push(await checkGitignore(dir, config));
258
471
  }
259
472
  checks.push(checkSkills(dir, opts.home));
473
+ // MCP는 도구 설정을 읽으므로 실행 환경을 받았을 때만 (run은 실제 환경, 테스트는 가짜 환경)
474
+ if (opts.mcp) checks.push(checkMcp(opts.mcp));
260
475
  // 서버 API(D8)가 정해지면 규칙·프로토콜 버전을 서버와 비교
261
476
  checks.push({
262
477
  id: 'compat.server',
@@ -294,18 +509,20 @@ function formatText(r) {
294
509
  }
295
510
  async function run(args) {
296
511
  const result = await doctor(args.target, {
297
- fix: args.fix
512
+ fix: args.fix,
513
+ mcp: defaultMcpEnv()
298
514
  });
299
515
  return {
300
516
  exitCode: result.ok ? 0 : 1,
301
517
  output: args.json ? JSON.stringify(result, null, 2) : formatText(result)
302
518
  };
303
519
  }
304
- const ANSWER_FILE = /\b(?:answers\.[a-z]+|elice\.config\.[a-z]+|grading\.json)\b/i;
520
+ // 옛 정답 · 설정 파일과 ecdk dev가 저장한 settings(정답 포함)
521
+ const ANSWER_FILE = /\b(?:answers\.[a-z]+|elice\.config\.[a-z]+|grading\.json)\b|\.ecdk\/settings\.json\b/i;
305
522
  /** 주석뿐이 아닌 줄에서 정답·설정 파일 이름이 나오는지. 줄 건너뛰기는 금지 API 검사와 같은 규칙(content-rules lineSkipper) */
306
523
  function referencesAnswerFile(text) {
307
524
  const skip = lineSkipper(text);
308
525
  return skip.lines.some((line, i) => ANSWER_FILE.test(line) && !skip.isSkipped(i + 1, 'project.answer-import'));
309
526
  }
310
527
 
311
- export { checkNode, doctor, formatText, referencesAnswerFile, run, usage };
528
+ export { checkDeps, checkMcp, checkNode, checkSkills, checkTemplate, doctor, formatText, projectSkillDirs, referencesAnswerFile, run, usage };