@eliceio/cdk-cli 0.1.0-alpha.2 → 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 (81) hide show
  1. package/README.md +158 -138
  2. package/es/cli.js +88 -33
  3. package/es/commands/build/index.d.ts +1 -1
  4. package/es/commands/build/index.js +16 -6
  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 +11 -0
  14. package/es/commands/doctor/index.js +155 -26
  15. package/es/commands/mcp/index.d.ts +134 -0
  16. package/es/commands/mcp/index.js +399 -0
  17. package/es/commands/setup/index.d.ts +40 -0
  18. package/es/commands/setup/index.js +157 -0
  19. package/es/commands/skill/index.d.ts +2 -5
  20. package/es/commands/skill/index.js +1 -29
  21. package/es/core/config.d.ts +63 -19
  22. package/es/core/config.js +108 -32
  23. package/es/core/prepare.js +3 -5
  24. package/es/core/project-check.d.ts +15 -0
  25. package/es/core/project-check.js +26 -0
  26. package/es/core/templates.d.ts +25 -0
  27. package/es/core/templates.js +41 -0
  28. package/es/dev/grading.d.ts +14 -7
  29. package/es/dev/grading.js +27 -13
  30. package/es/dev/host-page.d.ts +1 -1
  31. package/es/dev/host-page.js +33 -33
  32. package/es/dev/mock-api.d.ts +20 -4
  33. package/es/dev/mock-api.js +70 -9
  34. package/es/dev/server.d.ts +7 -0
  35. package/es/dev/server.js +84 -23
  36. package/es/rules/check.js +56 -7
  37. package/es/rules/index.d.ts +1 -1
  38. package/es/rules/index.js +1 -1
  39. package/es/rules/manifest.d.ts +23 -9
  40. package/es/rules/manifest.js +60 -35
  41. package/es/rules/node.js +3 -1
  42. package/es/rules/semver.d.ts +5 -0
  43. package/es/rules/semver.js +32 -0
  44. package/es/rules/types.d.ts +27 -6
  45. package/es/rules.json.js +1 -1
  46. package/guides/content-development.md +136 -49
  47. package/package.json +2 -2
  48. package/rules.json +62 -7
  49. package/skills/_shared/always.md +3 -1
  50. package/skills/elice-content-check/SKILL.md +1 -1
  51. package/skills/elice-content-create/SKILL.md +4 -4
  52. package/skills/elice-content-migrate/SKILL.md +1 -1
  53. package/skills/elice-content-publish/SKILL.md +22 -0
  54. package/templates/_shared/lib/cdk-mock.d.ts +21 -3
  55. package/templates/_shared/lib/cdk-mock.js +239 -80
  56. package/templates/_shared/lib/cdk.js +2 -2
  57. package/templates/_shared/lib/elice-content.css +196 -0
  58. package/templates/_shared/lib/elice-content.d.ts +110 -5
  59. package/templates/_shared/lib/elice-content.js +643 -38
  60. package/templates/blank/README.md +12 -3
  61. package/templates/blank/completion.html +15 -0
  62. package/templates/blank/elice.config.json +3 -5
  63. package/templates/blank/gitignore +1 -0
  64. package/templates/blank/screens/completion.js +7 -0
  65. package/templates/blank/screens/edit.js +3 -0
  66. package/templates/blank/template.json +6 -0
  67. package/templates/quiz/README.md +35 -28
  68. package/templates/quiz/content.json +17 -63
  69. package/templates/quiz/core/behaviors.d.ts +5 -0
  70. package/templates/quiz/core/behaviors.js +12 -0
  71. package/templates/quiz/core/model.d.ts +27 -1
  72. package/templates/quiz/core/model.js +199 -4
  73. package/templates/quiz/elice.config.json +1 -6
  74. package/templates/quiz/gitignore +1 -0
  75. package/templates/quiz/grading.json +1 -10
  76. package/templates/quiz/screens/edit.js +105 -31
  77. package/templates/quiz/screens/learn.js +7 -8
  78. package/templates/quiz/template.json +6 -0
  79. package/templates/quiz/ui/templates/edit.d.ts +2 -0
  80. package/templates/quiz/ui/templates/edit.js +16 -9
  81. package/templates/quiz/ui/texts.js +52 -27
@@ -1,25 +1,52 @@
1
1
  /**
2
- * 채점 유형. 원본은 rules.json `manifest.gradingTypes`이고, 타입 검사(오타 · 막아 둔 manual)를 위해 여기 리터럴로 둔다.
3
- * 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음
2
+ * 완료 정책 (ADR 0009). 원본은 rules.json `manifest.completionPolicies`이고, 타입 검사를 위해 여기 리터럴로 둔다.
3
+ * 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음.
4
+ * 자료가 지원하는 완료 정책은 metadata `completionPolicies`(서버가 첫 값으로 정함), 바꾸기는 완료 정책 화면 · SDK
5
+ * `saveCompletionPolicy`(PATCH completion_policy). settings.grading에는 없다
4
6
  */
5
- export declare const GRADING_TYPES: readonly ["on_access", "on_submit", "pattern", "rubric"];
6
- export type GradingType = (typeof GRADING_TYPES)[number];
7
+ export declare const COMPLETION_POLICIES: readonly ["on_access", "on_submit", "on_graded"];
7
8
  /**
8
- * 로컬 채점 설정(유형 · 정답 · 채점 기준). 프로젝트 맨 위 `grading.json`에 적는다. LXP 채점 설정에서 교육자가 고르고
9
- * 넣는 값과 같다. zip에는 들어가지 않는다 (운영은 LXP 채점 설정). CLI · mock의 로컬 채점에만 쓴다.
9
+ * 채점 방식 = `settings.grading.type` (on_graded일 때만). 원본은 rules.json `manifest.graderTypes`.
10
+ * pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖
10
11
  */
11
- export interface GradingData {
12
- /** 로컬에서 흉내 낼 유형 (gradingTypes 중 하나). 없으면 gradingTypes의 첫 유형 */
13
- type?: GradingType;
14
- match?: 'exact' | 'regex';
15
- answer_key?: unknown;
12
+ export declare const GRADER_TYPES: readonly ["pattern", "rubric"];
13
+ export type CompletionPolicy = (typeof COMPLETION_POLICIES)[number];
14
+ export type GraderType = (typeof GRADER_TYPES)[number];
15
+ /**
16
+ * 채점 설정 = 운영 `settings.grading` (서버 §5.1 스키마, 2026-11-11 결정). 편집 화면이 saveSettings로 저장한다.
17
+ * 로컬은 프로젝트 맨 위 `grading.json`이고 `ecdk dev`의 편집 화면이 저장하면 이 파일에 쓴다. zip에는 들어가지 않는다 (정답).
18
+ *
19
+ * { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" } // 정규식 하나. 답 문자열 앞뒤 공백을 자르고 전체 일치
20
+ * { "type": "rubric", "rubric": "핵심 개념 2개 이상 언급하면 만점" }
21
+ *
22
+ * on_access · on_submit은 grading에서 빠졌다 (완료 정책은 completion_policy, 2026-11-11).
23
+ */
24
+ export interface GradingConfig {
25
+ type: GraderType;
26
+ /** pattern: 정답 정규식 (문자열 하나) */
27
+ answer_key?: string;
28
+ /** rubric: 평가 기준 */
16
29
  rubric?: string;
17
30
  }
18
- /** 로컬 채점에 쓰는 값: grading.json에 유형을 채운 것. elice-material `material_version.grading`과 같은 모양 */
19
- export interface GradingConfig extends GradingData {
20
- type: GradingType;
31
+ /** 로컬 채점 흉내에 쓰는 값: 완료 정책(로컬 `.ecdk/completion.json` · completionPolicies 첫 값)과 채점 설정(grading.json) */
32
+ export interface LocalGrading {
33
+ completion_policy: CompletionPolicy;
34
+ /** grading.json (없으면 null) */
35
+ grading: GradingConfig | null;
21
36
  }
22
37
  export declare const GRADING_DATA_FILE = "grading.json";
38
+ /**
39
+ * 로컬 완료 정책 (dev 전용): `ecdk dev` 완료 정책 화면의 saveCompletionPolicy를 흉내 서버가 여기에 쓴다.
40
+ * 운영은 서버 material_version.completion_policy. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다
41
+ */
42
+ export declare const COMPLETION_DATA_FILE = ".ecdk/completion.json";
43
+ /** completionPolicies가 없을 때(검사 오류) ecdk dev가 흉내 내는 정책 (제출하면 완료) */
44
+ export declare const DEFAULT_COMPLETION_POLICY: CompletionPolicy;
45
+ /**
46
+ * 채점 설정 값 검사 (grading.json · 편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
47
+ * 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
48
+ */
49
+ export declare function parseGrading(data: unknown): GradingConfig | string;
23
50
  export interface ContentConfig {
24
51
  /** 콘텐츠 원본 폴더 (프로젝트 기준). 기본 '.' */
25
52
  root: string;
@@ -31,8 +58,16 @@ export interface ContentConfig {
31
58
  kind?: 'material' | 'description';
32
59
  /** 화면별 진입 파일 → build가 metadata.json로 만든다. 없으면 원본의 metadata.json, 그것도 없으면 { learn: 'index.html' } */
33
60
  screens?: Record<string, string>;
34
- /** 이 자료가 지원하는 채점 유형 → metadata.json `gradingTypes` (자료 본문은 필수). 로컬 채점 유형 · 정답은 grading.json */
35
- gradingTypes?: GradingType[];
61
+ /**
62
+ * 지원하는 완료 정책 → metadata.json `completionPolicies` (ADR 0009 2026-11-11 결정 2). 서버는 첫 값으로 완료 정책을 정한다.
63
+ * 하나면 고정(퀴즈 ["on_graded"]), 여럿이면 완료 정책 화면(screens.completionPolicy)이 그 안에서 바꾼다. 자료 본문은 필수
64
+ */
65
+ completionPolicies?: CompletionPolicy[];
66
+ /**
67
+ * @deprecated 2026-11-10 삭제 (ADR 0008 · 0009). 완료 정책은 completionPolicies · 완료 정책 화면이, 채점 방식은 편집 화면이 정한다.
68
+ * 남아 있으면 build · doctor가 경고만 하고 metadata.json에 옮기지 않는다
69
+ */
70
+ gradingTypes?: unknown;
36
71
  /** true면 build가 JS · CSS · JSON을 줄여 zip에 넣는다 (용량 줄이기). 기본 false */
37
72
  minify?: boolean;
38
73
  /**
@@ -48,8 +83,17 @@ export interface ContentConfig {
48
83
  export declare const CONFIG_FILE = "elice.config.json";
49
84
  /** 1단계는 JSON만. `.ts` 설정은 Node 20의 TS 실행 지원 문제로 엔진 작업(3단계)과 함께 결정. */
50
85
  export declare function loadConfig(projectDir: string): Promise<ContentConfig>;
86
+ /** elice.config.json에 옛 `gradingTypes`가 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
87
+ export declare function legacyGradingTypesWarning(config: ContentConfig): string | null;
88
+ /**
89
+ * 로컬 완료 정책 (ecdk dev 흉내): `.ecdk/completion.json`(ecdk dev 완료 정책 화면이 저장)이 completionPolicies 안에
90
+ * 있으면 그것, 아니면 completionPolicies 첫 값(서버가 업로드 때 정하는 값), 없으면 on_submit.
91
+ * completionPolicies가 바뀌어 저장해 둔 값이 목록에서 빠졌으면 첫 값으로 돌아간다
92
+ */
93
+ export declare function loadCompletionPolicy(projectDir: string, config: ContentConfig): Promise<CompletionPolicy>;
94
+ /** grading.json (없으면 null). 문제가 있으면 오류 */
95
+ export declare function loadGradingFile(projectDir: string): Promise<GradingConfig | null>;
51
96
  /**
52
- * 로컬 채점용 설정: grading.json(있으면) + 유형. 유형은 grading.json `type`, 없으면 gradingTypes의 첫 유형.
53
- * 지원 유형이 없으면(문제 설명) undefined.
97
+ * 로컬 채점 흉내용 값: 완료 정책 + grading.json. 문제 설명(채점 없음)은 undefined
54
98
  */
55
- export declare function loadGrading(projectDir: string, config: ContentConfig): Promise<GradingConfig | undefined>;
99
+ export declare function loadGrading(projectDir: string, config: ContentConfig): Promise<LocalGrading | undefined>;
package/es/core/config.js CHANGED
@@ -1,16 +1,69 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import 'fflate';
4
- import { gradingTypesError } from '../rules/manifest.js';
4
+ import { parseCompletionPolicies, completionPolicyError, graderTypeError, COMPLETION_POLICIES_EXAMPLE } from '../rules/manifest.js';
5
5
  import { rules } from '../rules/spec.js';
6
6
 
7
7
  /**
8
- * 채점 유형. 원본은 rules.json `manifest.gradingTypes`이고, 타입 검사(오타 · 막아 둔 manual)를 위해 여기 리터럴로 둔다.
9
- * 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음
8
+ * 완료 정책 (ADR 0009). 원본은 rules.json `manifest.completionPolicies`이고, 타입 검사를 위해 여기 리터럴로 둔다.
9
+ * 둘이 같은지는 docs.test.ts가 대조한다. 수동 채점 manual · 채점 없음 none은 Custom HTML에서 쓰지 않음.
10
+ * 자료가 지원하는 완료 정책은 metadata `completionPolicies`(서버가 첫 값으로 정함), 바꾸기는 완료 정책 화면 · SDK
11
+ * `saveCompletionPolicy`(PATCH completion_policy). settings.grading에는 없다
10
12
  */
11
- const GRADING_TYPES = ['on_access', 'on_submit', 'pattern', 'rubric'];
13
+ const COMPLETION_POLICIES = ['on_access', 'on_submit', 'on_graded'];
14
+ /**
15
+ * 채점 방식 = `settings.grading.type` (on_graded일 때만). 원본은 rules.json `manifest.graderTypes`.
16
+ * pattern: 정답 정규식 · rubric: AI 평가 기준. code_exec는 이번 범위 밖
17
+ */
18
+ const GRADER_TYPES = ['pattern', 'rubric'];
12
19
  const GRADING_DATA_FILE = 'grading.json';
13
- const GRADING_DATA_KEYS = ['type', 'match', 'answer_key', 'rubric'];
20
+ /**
21
+ * 로컬 완료 정책 (dev 전용): `ecdk dev` 완료 정책 화면의 saveCompletionPolicy를 흉내 서버가 여기에 쓴다.
22
+ * 운영은 서버 material_version.completion_policy. 프로젝트의 점(.) 폴더라 zip에 들어가지 않는다
23
+ */
24
+ const COMPLETION_DATA_FILE = '.ecdk/completion.json';
25
+ const GRADING_DATA_KEYS = ['type', 'answer_key', 'rubric'];
26
+ /** completionPolicies가 없을 때(검사 오류) ecdk dev가 흉내 내는 정책 (제출하면 완료) */
27
+ const DEFAULT_COMPLETION_POLICY = 'on_submit';
28
+ /**
29
+ * 채점 설정 값 검사 (grading.json · 편집 화면이 저장한 settings.grading). 문제가 있으면 문장, 없으면 GradingConfig.
30
+ * 옛 모양(`type: on_access · on_submit`, `completion_policy` · `grader_type`, `match` · 객체 정답)은 바꾸는 법을 알려 준다.
31
+ */
32
+ function parseGrading(data) {
33
+ const example = '예: { "type": "pattern", "answer_key": "^q1=b$" } · { "type": "rubric", "rubric": "…" }';
34
+ if (typeof data !== 'object' || data === null || Array.isArray(data)) return `객체여야 합니다. ${example}`;
35
+ const record = data;
36
+ if (record.type === 'manual' || record.type === 'none') return completionPolicyError(record.type, COMPLETION_POLICIES) ?? '';
37
+ if (record.type === 'on_access' || record.type === 'on_submit') return `완료 정책(${record.type})은 grading에 적지 않습니다 (2026-11-11). 운영은 completion_policy(metadata completionPolicies 첫 값 · 완료 정책 화면), ecdk dev에서는 completionPolicies 첫 값 · 완료 정책 화면(${COMPLETION_DATA_FILE})으로 정합니다. grading은 { "type": "pattern" | "rubric" }만.`;
38
+ if (record.completion_policy !== undefined || record.grader_type !== undefined) return `completion_policy · grader_type은 쓰지 않습니다 (2026-11-11 결정: grading은 type 모양 그대로). ${example}`;
39
+ if (record.match !== undefined || record.answer_key !== undefined && typeof record.answer_key !== 'string') return `옛 형식입니다 (match · 객체 정답). 정답은 정규식 문자열 하나입니다: { "type": "pattern", "answer_key": "^q1=b;q2=a,d$" }. 퀴즈는 ecdk dev의 내용 편집에서 정답을 다시 고르면 새 형식으로 저장됩니다.`;
40
+ const unknown = Object.keys(record).filter(k => !GRADING_DATA_KEYS.includes(k));
41
+ if (unknown.length > 0) return `알 수 없는 필드입니다: ${unknown.join(', ')} (가능: ${GRADING_DATA_KEYS.join(', ')})`;
42
+ const {
43
+ type,
44
+ answer_key: answerKey,
45
+ rubric
46
+ } = record;
47
+ const typeError = graderTypeError(type, GRADER_TYPES);
48
+ if (typeError) return `type: ${typeError}`;
49
+ if (type === 'pattern') {
50
+ if (typeof answerKey !== 'string' || answerKey.trim() === '') return 'pattern 채점에는 정답 정규식 answer_key(문자열)가 필요합니다. 예: "^q1=b$"';
51
+ try {
52
+ new RegExp(answerKey);
53
+ } catch (e) {
54
+ return `answer_key가 올바른 정규식이 아닙니다: ${e.message}`;
55
+ }
56
+ return {
57
+ type,
58
+ answer_key: answerKey
59
+ };
60
+ }
61
+ if (typeof rubric !== 'string' || rubric.trim() === '') return 'rubric 채점에는 평가 기준 rubric(문자열)이 필요합니다.';
62
+ return {
63
+ type: 'rubric',
64
+ rubric
65
+ };
66
+ }
14
67
  const CONFIG_FILE = 'elice.config.json';
15
68
  /** JSON 형식 오류에 파일 이름을 붙인다 (SyntaxError만 나오면 어느 파일인지 모름) */
16
69
  function parseJson(raw, fail) {
@@ -47,17 +100,22 @@ async function loadConfig(projectDir) {
47
100
  if (json.screens !== undefined && !isStringRecord(json.screens)) throw fail('screens는 켤 화면만 파일 이름으로 적습니다: { "learn": "index.html", "instructor": "..." } (metadata.json의 { "enabled", "entry" } 모양과 다름).');
48
101
  // 오타는 metadata.json 파서와 같은 문구로 막는다 (조용히 빠지면 그 화면이 꺼진 채로 만들어짐)
49
102
  const unknownScreen = Object.keys(json.screens ?? {}).find(m => !rules.manifest.modes.includes(m));
103
+ if (unknownScreen === 'completion' || unknownScreen === 'grading') throw fail(`완료 정책 화면의 이름은 completionPolicy입니다 (2026-11-11): screens.${unknownScreen} → "completionPolicy": "${json.screens?.[unknownScreen] ?? 'completion.html'}"`);
50
104
  if (unknownScreen) throw fail(`알 수 없는 화면입니다: ${unknownScreen} (가능: ${rules.manifest.modes.join(', ')})`);
51
105
  if (json.minify !== undefined && typeof json.minify !== 'boolean') throw fail('minify는 true 또는 false여야 합니다.');
52
106
  if (json.sourcemap !== undefined && typeof json.sourcemap !== 'boolean') throw fail('sourcemap은 true 또는 false여야 합니다.');
53
107
  if (json.sourcemap && !json.minify) throw fail('sourcemap은 minify와 함께 씁니다 ("minify": true). 줄이지 않으면 원본 그대로라 필요 없습니다.');
54
108
  if (json.template !== undefined && typeof json.template !== 'string') throw fail('template은 문자열이어야 합니다 (ecdk create가 적는 값).');
55
- if (json.answers !== undefined) throw fail('answers 대신 gradingTypes와 grading.json을 써 주세요 (예: elice.config.json { "gradingTypes": ["pattern"] }, grading.json { "type": "pattern", "match": "exact", "answer_key": ... }).');
109
+ if (json.answers !== undefined) throw fail(`answers 대신 ${GRADING_DATA_FILE}에 채점 설정을 적어 주세요 (예: { "type": "pattern", "answer_key": "^q1=b$" }). 운영에서는 편집 화면이 정합니다.`);
56
110
  const legacy = json;
57
- if (legacy.grading !== undefined) throw fail(`grading 대신 gradingTypes에 이 자료가 지원하는 채점 유형을 모두 적어 주세요 (예: "gradingTypes": ["on_submit", "pattern"]). 로컬에서 흉내 낼 유형과 정답은 ${GRADING_DATA_FILE}에.`);
58
- if (json.gradingTypes !== undefined) {
59
- const error = gradingTypesError(json.gradingTypes, GRADING_TYPES);
60
- if (error) throw fail(error);
111
+ if (legacy.grading !== undefined) throw fail(`grading(채점 설정)은 elice.config.json이 아니라 ${GRADING_DATA_FILE}에 적어 주세요. 운영에서는 편집 화면이 정합니다.`);
112
+ const old = json;
113
+ if (old.completion !== undefined) throw fail(`completion 대신 completionPolicies(지원하는 완료 정책 배열, 첫 값이 기본)를 적어 주세요 (2026-11-11). ${COMPLETION_POLICIES_EXAMPLE}`);
114
+ if (json.completionPolicies !== undefined) {
115
+ if (json.kind === 'description') throw fail('문제 설명(kind: description)은 완료 · 채점하지 않으므로 completionPolicies를 넣지 않습니다.');
116
+ const parsed = parseCompletionPolicies(json.completionPolicies, rules);
117
+ if (typeof parsed === 'string') throw fail(parsed);
118
+ json.completionPolicies = parsed;
61
119
  }
62
120
  if (json.commentary !== undefined && typeof json.commentary !== 'string') throw fail('commentary는 학습 참고 내용 파일 이름(문자열)이어야 합니다. 예: "commentary.txt"');
63
121
  if (json.kind !== undefined && json.kind !== 'material' && json.kind !== 'description') throw fail('kind는 material(자료 본문) 또는 description(문제 설명)이어야 합니다.');
@@ -67,43 +125,61 @@ async function loadConfig(projectDir) {
67
125
  const extra = Object.keys(json.screens).filter(m => !allowed.includes(m));
68
126
  if (extra.length > 0) throw fail(`${json.kind === 'description' ? '문제 설명(kind: description)' : json.kind}은 ${allowed.join(' · ')} 화면만 켤 수 있습니다. screens에서 ${extra.join(', ')}를 지워 주세요.`);
69
127
  }
70
- // 문제 설명은 채점하지 않는다: 채점은 설명을 붙인 문제 자료가 한다
71
- if (json.kind === 'description' && json.gradingTypes !== undefined) throw fail('문제 설명(kind: description)은 채점하지 않습니다. gradingTypes를 지워 주세요 (채점은 문제 자료의 채점 설정에서).');
72
128
  return {
73
129
  ...defaults,
74
130
  ...json
75
131
  };
76
132
  }
133
+ /** elice.config.json에 옛 `gradingTypes`가 남아 있을 때 build · doctor가 보여 줄 경고. 없으면 null */
134
+ function legacyGradingTypesWarning(config) {
135
+ return config.gradingTypes === undefined ? null : `${CONFIG_FILE}의 gradingTypes는 더 쓰지 않습니다 (2026-11-10, 지워 주세요). 완료 정책은 completionPolicies · 완료 정책 화면(screens.completionPolicy)이, 채점 방식 · 답은 편집 화면(settings.grading)이 정하고 (ADR 0009), 로컬 채점은 ${GRADING_DATA_FILE}로 흉내 냅니다.`;
136
+ }
77
137
  /**
78
- * 로컬 채점용 설정: grading.json(있으면) + 유형. 유형은 grading.json `type`, 없으면 gradingTypes의 첫 유형.
79
- * 지원 유형이 없으면(문제 설명) undefined.
138
+ * 로컬 완료 정책 (ecdk dev 흉내): `.ecdk/completion.json`(ecdk dev 완료 정책 화면이 저장)이 completionPolicies 안에
139
+ * 있으면 그것, 아니면 completionPolicies 첫 값(서버가 업로드 때 정하는 값), 없으면 on_submit.
140
+ * completionPolicies가 바뀌어 저장해 둔 값이 목록에서 빠졌으면 첫 값으로 돌아간다
80
141
  */
81
- async function loadGrading(projectDir, config) {
82
- const supported = config.gradingTypes;
83
- if (!supported || supported.length === 0) return undefined;
142
+ async function loadCompletionPolicy(projectDir, config) {
143
+ const policies = config.completionPolicies ?? [];
144
+ const first = policies[0] ?? DEFAULT_COMPLETION_POLICY;
145
+ try {
146
+ const raw = await readFile(join(projectDir, COMPLETION_DATA_FILE), 'utf8');
147
+ const fail = msg => new Error(`${COMPLETION_DATA_FILE}: ${msg}`);
148
+ // 값 이름은 서버 material_version.completion_policy와 같게
149
+ const json = parseJson(raw, fail);
150
+ const policyError = completionPolicyError(json?.completion_policy, COMPLETION_POLICIES);
151
+ if (policyError) throw fail(policyError);
152
+ const saved = json?.completion_policy;
153
+ return policies.includes(saved) ? saved : first;
154
+ } catch (e) {
155
+ if (e.code !== 'ENOENT') throw e;
156
+ }
157
+ return first;
158
+ }
159
+ /** grading.json (없으면 null). 문제가 있으면 오류 */
160
+ async function loadGradingFile(projectDir) {
84
161
  let raw;
85
162
  try {
86
163
  raw = await readFile(join(projectDir, GRADING_DATA_FILE), 'utf8');
87
164
  } catch (e) {
88
- if (e.code === 'ENOENT') return {
89
- type: supported[0]
90
- };
165
+ if (e.code === 'ENOENT') return null;
91
166
  throw e;
92
167
  }
93
168
  const fail = msg => new Error(`${GRADING_DATA_FILE}: ${msg}`);
94
- const data = parseJson(raw, fail);
95
- if (typeof data !== 'object' || data === null || Array.isArray(data)) throw fail('객체여야 합니다. 예: { "type": "pattern", "match": "exact", "answer_key": { "answers": { "q1": "b" } } }');
96
- const unknown = Object.keys(data).filter(k => !GRADING_DATA_KEYS.includes(k));
97
- if (unknown.length > 0) throw fail(`알 수 없는 필드입니다: ${unknown.join(', ')} (가능: ${GRADING_DATA_KEYS.join(', ')})`);
98
- const {
99
- type,
100
- ...rest
101
- } = data;
102
- if (type !== undefined && !supported.includes(type)) throw fail(`type은 elice.config.json gradingTypes(${supported.join(', ')}) 중 하나여야 합니다: ${type}`);
169
+ const parsed = parseGrading(parseJson(raw, fail));
170
+ if (typeof parsed === 'string') throw fail(parsed);
171
+ return parsed;
172
+ }
173
+ /**
174
+ * 로컬 채점 흉내용 값: 완료 정책 + grading.json. 문제 설명(채점 없음)은 undefined
175
+ */
176
+ async function loadGrading(projectDir, config) {
177
+ if (config.kind === 'description') return undefined;
178
+ const grading = await loadGradingFile(projectDir);
103
179
  return {
104
- ...rest,
105
- type: type ?? supported[0]
180
+ completion_policy: await loadCompletionPolicy(projectDir, config),
181
+ grading
106
182
  };
107
183
  }
108
184
 
109
- export { CONFIG_FILE, GRADING_DATA_FILE, GRADING_TYPES, loadConfig, loadGrading };
185
+ export { COMPLETION_DATA_FILE, COMPLETION_POLICIES, CONFIG_FILE, DEFAULT_COMPLETION_POLICY, GRADER_TYPES, GRADING_DATA_FILE, legacyGradingTypesWarning, loadCompletionPolicy, loadConfig, loadGrading, loadGradingFile, parseGrading };
@@ -42,7 +42,7 @@ async function prepareContent(projectDir, config) {
42
42
  if (config.commentary !== undefined && !hasCommentary) throw new Error(`학습 참고 내용 파일이 원본 최상위에 없습니다: ${config.commentary} (elice.config.json commentary)`);
43
43
  const commentary = hasCommentary ? commentaryName : undefined;
44
44
  const authored = files.find(f => f.path === rules.manifest.file);
45
- const fromConfig = config.screens ? 'screens' : config.kind ? 'kind' : config.commentary !== undefined ? 'commentary' : null;
45
+ const fromConfig = config.screens ? 'screens' : config.kind ? 'kind' : config.completionPolicies ? 'completionPolicies' : config.commentary !== undefined ? 'commentary' : null;
46
46
  if (authored && fromConfig) throw new Error(`원본에 ${rules.manifest.file}이 있고 ${fromConfig}도 있습니다. 둘 중 하나만 써 주세요.`);
47
47
  if (authored) {
48
48
  // 형식이 틀리면 그대로 두고 검사가 알려 준다. 맞으면 다른 필드는 지키고 build만 바꾼다
@@ -57,8 +57,6 @@ async function prepareContent(projectDir, config) {
57
57
  build
58
58
  }, null, 2)}\n`);
59
59
  } else {
60
- // 자료 본문은 채점 유형이 반드시 있다 (문제 설명은 채점하지 않음)
61
- if ((config.kind ?? rules.manifest.defaultKind) !== 'description' && !config.gradingTypes) throw new Error(`elice.config.json에 이 자료가 지원하는 채점 유형을 적어 주세요: "gradingTypes": [${rules.manifest.gradingTypes.map(t => `"${t}"`).join(', ')}] 중 하나 이상. 보기만 하는 자료는 ["on_access"].`);
62
60
  const entries = config.screens ?? {
63
61
  learn: rules.manifest.defaultEntry
64
62
  };
@@ -66,9 +64,9 @@ async function prepareContent(projectDir, config) {
66
64
  path: rules.manifest.file,
67
65
  data: new TextEncoder().encode(serializeManifest({
68
66
  kind: config.kind,
67
+ // 정답은 metadata에 넣지 않는다: 편집 화면이 settings.grading에 저장. 지원하는 완료 정책만 적는다 (ADR 0009)
69
68
  entries,
70
- // 지원 채점 유형만 (교육자가 LXP 채점 설정에서 고르고 정답을 넣음). 문제 설명은 채점하지 않음
71
- gradingTypes: config.gradingTypes,
69
+ completionPolicies: config.completionPolicies,
72
70
  commentary,
73
71
  build
74
72
  }, rules))
@@ -0,0 +1,15 @@
1
+ import type { CheckOptions } from '../rules/index.js';
2
+ import type { ContentConfig, GradingConfig } from './config.js';
3
+ /**
4
+ * 프로젝트(ecdk 프로젝트 폴더)를 검사할 때 build · dev · doctor · check가 함께 쓰는 검사 옵션.
5
+ * 파일은 prepareContent가 만든 zip 내용(원본)이고, 모듈 묶기는 build가 하므로 module-src는 보지 않는다.
6
+ * 프로젝트에만 있는 정보(예: 로컬 grading.json, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
7
+ * 그래야 `ecdk check <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
8
+ *
9
+ * grading: 로컬 grading.json (loadGradingFile, 없으면 null). 읽지 못했으면 undefined → grading.missing을 보지 않는다.
10
+ * 문제 설명은 채점이 없어 넘기지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown)
11
+ */
12
+ export declare function projectCheckOptions(config: ContentConfig, extra?: {
13
+ zipBytes?: number | undefined;
14
+ grading?: GradingConfig | null | undefined;
15
+ }): CheckOptions;
@@ -0,0 +1,26 @@
1
+ import { knownTemplates } from './templates.js';
2
+
3
+ /**
4
+ * 프로젝트(ecdk 프로젝트 폴더)를 검사할 때 build · dev · doctor · check가 함께 쓰는 검사 옵션.
5
+ * 파일은 prepareContent가 만든 zip 내용(원본)이고, 모듈 묶기는 build가 하므로 module-src는 보지 않는다.
6
+ * 프로젝트에만 있는 정보(예: 로컬 grading.json, 템플릿 목록)를 검사에 더할 때는 이 함수에만 더한다.
7
+ * 그래야 `ecdk check <프로젝트>`와 `ecdk build` 결과가 어긋나지 않는다.
8
+ *
9
+ * grading: 로컬 grading.json (loadGradingFile, 없으면 null). 읽지 못했으면 undefined → grading.missing을 보지 않는다.
10
+ * 문제 설명은 채점이 없어 넘기지 않는다. templates: 이 CLI가 가진 템플릿 · 버전 (build.template-unknown)
11
+ */
12
+ function projectCheckOptions(config, extra = {}) {
13
+ return {
14
+ input: 'zip',
15
+ bundlesModules: true,
16
+ templates: knownTemplates(),
17
+ ...(extra.zipBytes !== undefined ? {
18
+ zipBytes: extra.zipBytes
19
+ } : {}),
20
+ ...(config.kind !== 'description' && extra.grading !== undefined ? {
21
+ grading: extra.grading
22
+ } : {})
23
+ };
24
+ }
25
+
26
+ export { projectCheckOptions };
@@ -0,0 +1,25 @@
1
+ /** 패키지 루트의 templates/ (es/core/와 src/core/ 모두 두 단계 위) */
2
+ export declare const TEMPLATE_ROOT: string;
3
+ /**
4
+ * 템플릿 한 개의 정보 (`templates/<이름>/template.json`). 템플릿마다 버전을 따로 올린다 (CLI 버전과 별개).
5
+ * 화면 구성 · 완료 정책은 template.json에 다시 적지 않고 템플릿의 elice.config.json을 그대로 읽는다 (한 곳만 고치게).
6
+ */
7
+ export interface TemplateInfo {
8
+ name: string;
9
+ version: string;
10
+ title: string;
11
+ description: string;
12
+ /** 템플릿 elice.config.json의 screens 키 */
13
+ screens: string[];
14
+ /** 템플릿 elice.config.json의 completionPolicies (첫 값이 기본, 하나면 고정) */
15
+ completionPolicies?: string[] | undefined;
16
+ }
17
+ /** 이 CLI가 가진 템플릿 (이름 순, 공통 폴더 `_shared` 제외) */
18
+ export declare function listTemplates(root?: string): TemplateInfo[];
19
+ /** 검사 규칙 build.template-unknown에 넘길 { 이름: 버전 } */
20
+ export declare function knownTemplates(root?: string): Record<string, string>;
21
+ /** "quiz@1.0.0" → { name, version } (버전이 없으면 undefined) */
22
+ export declare function parseTemplateRef(ref: string): {
23
+ name: string;
24
+ version?: string | undefined;
25
+ };
@@ -0,0 +1,41 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ /** 패키지 루트의 templates/ (es/core/와 src/core/ 모두 두 단계 위) */
6
+ const TEMPLATE_ROOT = fileURLToPath(new URL('../../templates', import.meta.url));
7
+ /** 이 CLI가 가진 템플릿 (이름 순, 공통 폴더 `_shared` 제외) */
8
+ function listTemplates(root = TEMPLATE_ROOT) {
9
+ return readdirSync(root, {
10
+ withFileTypes: true
11
+ }).filter(d => d.isDirectory() && !d.name.startsWith('_')).map(d => {
12
+ const meta = JSON.parse(readFileSync(join(root, d.name, 'template.json'), 'utf8'));
13
+ const config = JSON.parse(readFileSync(join(root, d.name, 'elice.config.json'), 'utf8'));
14
+ return {
15
+ name: meta.name,
16
+ version: meta.version,
17
+ title: meta.title,
18
+ description: meta.description,
19
+ screens: Object.keys(config.screens ?? {}),
20
+ ...(config.completionPolicies ? {
21
+ completionPolicies: config.completionPolicies
22
+ } : {})
23
+ };
24
+ }).sort((a, b) => a.name.localeCompare(b.name));
25
+ }
26
+ /** 검사 규칙 build.template-unknown에 넘길 { 이름: 버전 } */
27
+ function knownTemplates(root = TEMPLATE_ROOT) {
28
+ return Object.fromEntries(listTemplates(root).map(t => [t.name, t.version]));
29
+ }
30
+ /** "quiz@1.0.0" → { name, version } (버전이 없으면 undefined) */
31
+ function parseTemplateRef(ref) {
32
+ const at = ref.lastIndexOf('@');
33
+ return at > 0 ? {
34
+ name: ref.slice(0, at),
35
+ version: ref.slice(at + 1)
36
+ } : {
37
+ name: ref
38
+ };
39
+ }
40
+
41
+ export { TEMPLATE_ROOT, knownTemplates, listTemplates, parseTemplateRef };
@@ -1,15 +1,22 @@
1
- import type { GradingConfig } from '../core/config.js';
2
- /** 제출 응답 `{ is_correct, score }` (서버 설계 v25). 채점하지 않는 유형은 둘 다 null */
1
+ import type { LocalGrading } from '../core/config.js';
2
+ /** 제출 응답 `{ is_correct, score }` (서버 설계 v25). 채점하지 않는 정책은 둘 다 null */
3
3
  export interface GradeResult {
4
4
  isCorrect: boolean | null;
5
5
  score: number | null;
6
6
  }
7
7
  /** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
8
8
  export declare const RUBRIC_DEV_SCORE = 80;
9
+ /** 정답 비교에 쓰는 답 문자열: 문자열은 앞뒤 공백을 자르고, 그 밖은 JSON으로 */
10
+ export declare const answerText: (answer: unknown) => string;
11
+ /** pattern: 정답 정규식(문자열 하나)이 답 문자열 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
12
+ export declare function matchesPattern(answerKey: unknown, answer: unknown): boolean;
9
13
  /**
10
- * elice-material `grading` 흉내 (서버 설계 v25). 채점은 모두 요청 안에서 끝난다 (rubric 포함).
11
- * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이고,
12
- * pattern exact는 서버처럼 답 전체를 한 번에 비교한다 (부분 점수 없음).
13
- * manual · none 등 자동 채점이 아닌 유형은 `{ isCorrect: null, score: null }`.
14
+ * elice-material 채점 흉내 (ADR 0009: 완료 정책 → 채점 방식 → 점수). 채점은 모두 요청 안에서 끝난다.
15
+ * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이다.
16
+ * - on_access: 열면 완료, 제출은 점수 없음 `{ null, null }`
17
+ * - on_submit: 제출하면 100
18
+ * - on_graded + pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
19
+ * - on_graded + rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음, G136)
20
+ * - on_graded인데 grading.json이 없으면 채점할 수 없어 `{ null, null }`
14
21
  */
15
- export declare function grade(grading: GradingConfig | undefined, answer: unknown): GradeResult;
22
+ export declare function grade(local: LocalGrading | undefined, answer: unknown): GradeResult;
package/es/dev/grading.js CHANGED
@@ -1,30 +1,44 @@
1
1
  /** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
2
2
  const RUBRIC_DEV_SCORE = 80;
3
- const normalize = v => typeof v === 'string' ? v.trim().toLowerCase() : Array.isArray(v) ? v.map(normalize).sort() : v && typeof v === 'object' ? Object.fromEntries(Object.keys(v).sort().map(k => [k, normalize(v[k])])) : v;
3
+ /** 정답 비교에 쓰는 답 문자열: 문자열은 앞뒤 공백을 자르고, 그 밖은 JSON으로 */
4
+ const answerText = answer => typeof answer === 'string' ? answer.trim() : JSON.stringify(answer ?? null);
5
+ /** pattern: 정답 정규식(문자열 하나)이 답 문자열 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
6
+ function matchesPattern(answerKey, answer) {
7
+ if (typeof answerKey !== 'string') return false;
8
+ try {
9
+ return new RegExp(`^(?:${answerKey})$`).test(answerText(answer));
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
4
14
  /**
5
- * elice-material `grading` 흉내 (서버 설계 v25). 채점은 모두 요청 안에서 끝난다 (rubric 포함).
6
- * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이고,
7
- * pattern exact는 서버처럼 답 전체를 한 번에 비교한다 (부분 점수 없음).
8
- * manual · none 등 자동 채점이 아닌 유형은 `{ isCorrect: null, score: null }`.
15
+ * elice-material 채점 흉내 (ADR 0009: 완료 정책 → 채점 방식 → 점수). 채점은 모두 요청 안에서 끝난다.
16
+ * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이다.
17
+ * - on_access: 열면 완료, 제출은 점수 없음 `{ null, null }`
18
+ * - on_submit: 제출하면 100
19
+ * - on_graded + pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
20
+ * - on_graded + rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음, G136)
21
+ * - on_graded인데 grading.json이 없으면 채점할 수 없어 `{ null, null }`
9
22
  */
10
- function grade(grading, answer) {
11
- const type = grading?.type ?? 'on_submit';
12
- if (type === 'on_access') return {
23
+ function grade(local, answer) {
24
+ const policy = local?.completion_policy ?? 'on_submit';
25
+ if (policy === 'on_access') return {
13
26
  isCorrect: null,
14
27
  score: null
15
28
  };
16
- if (type === 'on_submit') return {
29
+ if (policy === 'on_submit') return {
17
30
  isCorrect: true,
18
31
  score: 100
19
32
  };
20
- if (type === 'pattern') {
21
- const ok = grading?.match === 'regex' ? new RegExp(String(grading.answer_key)).test(String(answer)) : JSON.stringify(normalize(answer)) === JSON.stringify(normalize(grading?.answer_key));
33
+ const grading = local?.grading;
34
+ if (grading?.type === 'pattern') {
35
+ const ok = matchesPattern(grading.answer_key, answer);
22
36
  return {
23
37
  isCorrect: ok,
24
38
  score: ok ? 100 : 0
25
39
  };
26
40
  }
27
- if (type === 'rubric') return {
41
+ if (grading?.type === 'rubric') return {
28
42
  isCorrect: true,
29
43
  score: RUBRIC_DEV_SCORE
30
44
  };
@@ -34,4 +48,4 @@ function grade(grading, answer) {
34
48
  };
35
49
  }
36
50
 
37
- export { RUBRIC_DEV_SCORE, grade };
51
+ export { RUBRIC_DEV_SCORE, answerText, grade, matchesPattern };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * LXP 학습 · 편집 페이지 흉내. 보기를 바꾸고 콘텐츠를 sandbox iframe으로 띄우며,
3
- * @eliceio/cdk가 보내는 postMessage(settings-change · navigate-*)를 받아 처리한다
3
+ * @eliceio/cdk가 보내는 postMessage(settings-saved · navigate-*)를 받아 처리한다
4
4
  */
5
5
  export declare function hostPage(opts: {
6
6
  title: string;