@eliceio/cdk-cli 1.5.4 → 1.6.0-entryqa.1

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 (74) hide show
  1. package/README.md +31 -29
  2. package/es/commands/create/index.js +1 -0
  3. package/es/commands/create/scaffold.d.ts +1 -1
  4. package/es/commands/create/scaffold.js +1 -1
  5. package/es/core/config.d.ts +61 -2
  6. package/es/core/config.js +309 -3
  7. package/es/dev/grading.d.ts +31 -2
  8. package/es/dev/grading.js +68 -1
  9. package/es/dev/mock-api.d.ts +3 -1
  10. package/es/dev/mock-api.js +34 -4
  11. package/es/dev/server.js +5 -4
  12. package/es/rules/answers.d.ts +1 -0
  13. package/es/rules/answers.js +3 -0
  14. package/es/rules/check.js +8 -1
  15. package/es/rules/csp.d.ts +7 -0
  16. package/es/rules/csp.js +24 -3
  17. package/es/rules/index.d.ts +1 -1
  18. package/es/rules/index.js +1 -1
  19. package/es/rules/types.d.ts +4 -3
  20. package/es/rules.json.js +1 -1
  21. package/package.json +2 -2
  22. package/rules.json +5 -4
  23. package/skills/_shared/references/02-design-the-material.md +2 -1
  24. package/skills/_shared/references/05-screen-code.md +1 -0
  25. package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
  26. package/templates/_shared/lib/cdk-mock.d.ts +33 -2
  27. package/templates/_shared/lib/cdk-mock.js +171 -5
  28. package/templates/_shared/lib/elice-content.d.ts +38 -0
  29. package/templates/_shared/lib/elice-content.js +85 -2
  30. package/templates/blank/template.json +1 -1
  31. package/templates/document/template.json +3 -2
  32. package/templates/entry/README.md +117 -0
  33. package/templates/entry/commentary.txt +2 -0
  34. package/templates/entry/core/autosave.d.ts +13 -0
  35. package/templates/entry/core/autosave.js +69 -0
  36. package/templates/entry/core/default-project.d.ts +2 -0
  37. package/templates/entry/core/default-project.js +139 -0
  38. package/templates/entry/core/dom.d.ts +13 -0
  39. package/templates/entry/core/dom.js +83 -0
  40. package/templates/entry/core/grading.d.ts +52 -0
  41. package/templates/entry/core/grading.js +139 -0
  42. package/templates/entry/core/pack.d.ts +12 -0
  43. package/templates/entry/core/pack.js +71 -0
  44. package/templates/entry/core/settings.d.ts +33 -0
  45. package/templates/entry/core/settings.js +79 -0
  46. package/templates/entry/core/workspace.d.ts +40 -0
  47. package/templates/entry/core/workspace.js +320 -0
  48. package/templates/entry/docs/storage.md +44 -0
  49. package/templates/entry/edit.html +17 -0
  50. package/templates/entry/gitignore +4 -0
  51. package/templates/entry/index.html +17 -0
  52. package/templates/entry/metadata.json +9 -0
  53. package/templates/entry/package.json +13 -0
  54. package/templates/entry/screens/edit/panels/answer-project.js +15 -0
  55. package/templates/entry/screens/edit/panels/grading.d.ts +18 -0
  56. package/templates/entry/screens/edit/panels/grading.js +627 -0
  57. package/templates/entry/screens/edit/panels/index.js +25 -0
  58. package/templates/entry/screens/edit/panels/preference.js +56 -0
  59. package/templates/entry/screens/edit/panels/project-panel.js +93 -0
  60. package/templates/entry/screens/edit/panels/start-project.js +6 -0
  61. package/templates/entry/screens/edit.js +293 -0
  62. package/templates/entry/screens/learn.js +268 -0
  63. package/templates/entry/styles.css +1037 -0
  64. package/templates/entry/template.json +6 -0
  65. package/templates/entry/ui/templates/page.js +106 -0
  66. package/templates/entry/ui/texts.d.ts +3 -0
  67. package/templates/entry/ui/texts.js +160 -0
  68. package/templates/entry/ui/theme.css +17 -0
  69. package/templates/quiz/README.md +1 -1
  70. package/templates/quiz/template.json +3 -2
  71. package/templates/steps/template.json +1 -1
  72. package/templates/survey/README.md +1 -0
  73. package/templates/survey/template.json +3 -2
  74. package/templates/video/template.json +3 -2
@@ -0,0 +1,268 @@
1
+ // 학생 화면. 엔트리 워크스페이스(?mode=user)를 화면 가득 띄우고, 작품을 자동 저장하고, 제출 버튼으로 작품을 냅니다.
2
+ // 채점: 편집 화면이 저장한 settings.grading(일반 · AI 채점, 학생에게는 내려오지 않음)으로 서버가 채점합니다. 아래 줄에 '최종 제출 : N점 (11월 25일 오후 02:05)',
3
+ // 일반 채점이면 '올바르게 작성했어요' · '틀렸어요. 다시 해보세요.'(LXP 문구), AI 채점이면 'AI 채점' 표시 · 기다림 문구와
4
+ // 기준별 피드백(서버 grading_feedback)을 'AI 피드백 보기'로 보여 줍니다. 제출 전에는 비우고, 채점 설정이 없으면 점수는 '--'.
5
+ // 채점 방식은 app.gradingMode(SDK material.gradingMode, 서버 /me grading_mode)로 압니다. gradingMode · 제출 결과의
6
+ // gradingFeedback은 SDK 1.6.0부터 옵니다. 그 전 SDK는 gradingMode가 null이라 'AI 채점' 표시를 하지 않고, submit()이
7
+ // gradingFeedback을 버려서 제출 직후에는 결과 문구 · 피드백이 안 나오고 다시 열 때(history) 나옵니다.
8
+ //
9
+ // 여는 작품: kvstore 'entry'에 저장한 작품 → 없으면 편집 화면의 시작 작품(settings.entry.startProject) → 없으면 엔트리 기본 작품
10
+ // 자동 저장: 워크스페이스가 블록이 바뀔 때마다 보내는 UPDATED_PROJECT를 2초 모아 → TO_GET_PROJECT로 작품을 꺼내 → kvstore 'entry'.
11
+ // 워크스페이스 안 '저장하기'(SAVE_PROJECT)도 같은 칸에 바로 저장합니다.
12
+ // 제출: TO_GET_PROJECT → 줄인 작품 { v, project } → app.submit. 64KB를 넘으면 막고 안내합니다.
13
+ // 화면 배치: 워크스페이스 · 아래 파란 줄(저장 표시 · 오류 · 최종 제출 · 제출하기) — ui/templates/page.js
14
+ // 튜터링(보기 전용) · 편집기 미리보기는 저장 · 제출하지 않습니다 (튜터는 학생이 저장한 작품을 봄).
15
+ // 저장 칸 · 모양 표: docs/storage.md
16
+ import { start } from '../lib/elice-content.js';
17
+ import { createAutosave } from '../core/autosave.js';
18
+ import { html, part } from '../core/dom.js';
19
+ import { formatBytes, jsonBytes, pack, unpack } from '../core/pack.js';
20
+ import {
21
+ answerValue,
22
+ LIMITS,
23
+ normalizePreference,
24
+ PROGRESS_KEY,
25
+ progressValue,
26
+ readProgress,
27
+ splitSettings,
28
+ } from '../core/settings.js';
29
+ import { connectWorkspace } from '../core/workspace.js';
30
+ import { learnPage, loading, unavailable } from '../ui/templates/page.js';
31
+ import { texts } from '../ui/texts.js';
32
+
33
+ const t = texts.learn;
34
+ const root = document.getElementById('app');
35
+ document.title = texts.page.learn;
36
+ document.body.classList.add('en-page');
37
+ root.replaceChildren(loading('learn'));
38
+ const app = await start({ screen: 'learn' });
39
+
40
+ if (!app.hasContent) root.replaceChildren(app.emptyState());
41
+ else await show();
42
+
43
+ async function show() {
44
+ const { entry } = splitSettings(app.content);
45
+ const startProject = await unpack(entry.startProject);
46
+ const preference = normalizePreference(entry.preference);
47
+ // 저장 · 제출: 학생(과 학습 페이지의 교육자). 튜터링은 보기 전용, 편집기 미리보기는 기록하지 않음
48
+ const canSave = !app.readOnly && !app.isDraft;
49
+ const canSubmit = !app.readOnly;
50
+
51
+ // 다시 열기: 저장한 작품 (튜터는 보고 있는 학생의 것). 읽지 못하면 시작 작품으로 열고 알림
52
+ let saved = null;
53
+ let loadError = '';
54
+ try {
55
+ saved = readProgress(await app.kvstore.get({ key: PROGRESS_KEY }));
56
+ } catch (e) {
57
+ loadError = e.message;
58
+ }
59
+ const savedProject = saved ? await unpack(saved.project) : null;
60
+
61
+ const view = learnPage({ canSubmit });
62
+ const stage = part(view, 'stage');
63
+ const status = part(view, 'status');
64
+ const submitted = part(view, 'submitted');
65
+ const error = part(view, 'error');
66
+ const submitButton = part(view, 'submit');
67
+ const feedback = part(view, 'feedback');
68
+ const feedbackBody = part(view, 'feedback-body');
69
+ const feedbackToggle = part(view, 'feedback-toggle');
70
+ const verdict = part(view, 'verdict');
71
+ const aiBadge = part(view, 'ai-badge');
72
+ root.replaceChildren(view);
73
+ // 채점 방식: 서버가 알려 줄 때만 (옛 SDK · 채점 없음은 null)
74
+ const gradingMode = app.gradingMode ?? null;
75
+ aiBadge.hidden = gradingMode !== 'ai';
76
+
77
+ const time = d => d.toLocaleTimeString('ko-KR', { hour: '2-digit', minute: '2-digit' });
78
+ const pad = n => String(n).padStart(2, '0');
79
+ /** 최종 제출 시각: 11월 25일 오후 02:05 */
80
+ const dateTime = d =>
81
+ `${d.getMonth() + 1}월 ${d.getDate()}일 ${d.getHours() < 12 ? '오전' : '오후'} ${pad(d.getHours() % 12 || 12)}:${pad(d.getMinutes())}`;
82
+ /** 저장 표시. 저장됨이면 앞에 체크 표시 */
83
+ const setStatus = (text, check = false) => {
84
+ status.replaceChildren();
85
+ if (check) {
86
+ const mark = document.createElement('span');
87
+ mark.className = 'en-check';
88
+ mark.setAttribute('aria-hidden', 'true');
89
+ mark.textContent = '✓';
90
+ status.append(mark, ` ${text}`);
91
+ } else status.textContent = text;
92
+ };
93
+ if (!canSave) setStatus(app.readOnly ? t.readOnly : t.draft);
94
+ else if (saved?.savedAt) setStatus(t.save.saved(time(new Date(saved.savedAt))), true);
95
+ if (loadError) error.textContent = loadError;
96
+
97
+ /** 저장할 작품 (자동 저장 · 저장 메뉴가 넘긴 것) */
98
+ async function writeProgress(project) {
99
+ const value = progressValue(await pack(project));
100
+ const size = jsonBytes(value);
101
+ if (size > LIMITS.kvBytes)
102
+ throw new Error(t.save.tooLarge(formatBytes(size), formatBytes(LIMITS.kvBytes)));
103
+ await app.kvstore.post({ key: PROGRESS_KEY, value });
104
+ }
105
+
106
+ /** 저장 메뉴가 넘긴 작품 (없으면 워크스페이스에서 꺼냄) */
107
+ let menuProject = null;
108
+ const autosave = createAutosave({
109
+ delayMs: 2000,
110
+ save: async () => {
111
+ const project = menuProject ?? (await ws.getProject());
112
+ menuProject = null;
113
+ await writeProgress(project);
114
+ },
115
+ onState: (state, info) => {
116
+ if (state === 'idle') return;
117
+ if (state === 'saved') setStatus(t.save.saved(time(info.at ?? new Date())), true);
118
+ else if (state === 'error')
119
+ setStatus(t.save.error(info.error?.message ?? String(info.error)));
120
+ else setStatus(t.save[state]);
121
+ },
122
+ });
123
+
124
+ const ws = connectWorkspace({
125
+ mode: 'user',
126
+ title: texts.page.workspace,
127
+ preference,
128
+ provider: {
129
+ getProject: () => savedProject ?? startProject,
130
+ getInitialProject: () => startProject,
131
+ // 워크스페이스 '저장하기': 넘긴 작품을 바로 저장 (실패해도 워크스페이스에는 답한다: 저장 표시가 알림)
132
+ saveProject: async project => {
133
+ if (!canSave || !project) return;
134
+ menuProject = project;
135
+ await autosave.saveNow();
136
+ },
137
+ },
138
+ });
139
+ stage.append(ws.element);
140
+ // 워크스페이스를 띄우지 못하면 안내로 바꾸고 제출 버튼을 끈다 (낼 작품이 없음)
141
+ ws.ready.catch(e => {
142
+ stage.replaceChildren(
143
+ unavailable(e?.code === 'blocked' ? texts.unavailable.blocked : texts.unavailable.timeout)
144
+ );
145
+ if (submitButton) submitButton.disabled = true;
146
+ });
147
+
148
+ if (canSave) {
149
+ ws.onChange(() => autosave.schedule());
150
+ // 창을 닫기 전: 기다리는 저장이 있으면 바로 시도 (다른 출처 iframe 왕복이라 끝나기 전에 닫힐 수 있음)
151
+ const flush = () => void autosave.flush();
152
+ addEventListener('pagehide', flush);
153
+ document.addEventListener('visibilitychange', () => {
154
+ if (document.visibilityState === 'hidden') flush();
155
+ });
156
+ }
157
+
158
+ if (!submitButton) return;
159
+
160
+ /** 최종 제출 점수 · 시각 (한 줄, 제출 기록이 없으면 비움) */
161
+ const showFinal = (score, at) => {
162
+ submitted.textContent = at
163
+ ? t.lastSubmission(typeof score === 'number' ? score : null, dateTime(at))
164
+ : '';
165
+ };
166
+ /**
167
+ * 일반 채점 결과 문구. 채점 방식을 모르면(옛 SDK) grading_feedback이 일반 모양({ criteria: [] })일 때만.
168
+ * AI 채점 · 채점 없음(isCorrect null)이면 비움
169
+ */
170
+ const showVerdict = (isCorrect, gradingFeedback) => {
171
+ const general =
172
+ gradingMode === 'general' ||
173
+ (gradingMode === null &&
174
+ Array.isArray(gradingFeedback?.criteria) &&
175
+ !gradingFeedback.criteria.length);
176
+ verdict.textContent =
177
+ general && typeof isCorrect === 'boolean'
178
+ ? isCorrect
179
+ ? t.verdict.correct
180
+ : t.verdict.wrong
181
+ : '';
182
+ };
183
+ /** AI 채점 피드백 { message, criteria: [{ feedback }] }. 글이 없으면(일반 채점 · 채점 없음) 버튼을 숨김 */
184
+ const showFeedback = value => {
185
+ const message = typeof value?.message === 'string' ? value.message.trim() : '';
186
+ const criteria = Array.isArray(value?.criteria)
187
+ ? value.criteria.map(c => (typeof c?.feedback === 'string' ? c.feedback.trim() : ''))
188
+ : [];
189
+ const has = Boolean(message) || criteria.some(Boolean);
190
+ feedbackToggle.hidden = !has;
191
+ if (!has) setFeedbackOpen(false);
192
+ const items = [];
193
+ if (message) items.push(html`<p class="en-feedback-message">${message}</p>`);
194
+ criteria.forEach((text, i) => {
195
+ if (text)
196
+ items.push(
197
+ html`<div class="en-feedback-item">
198
+ <p class="en-feedback-label">${t.feedback.criterion(i + 1)}</p>
199
+ <p>${text}</p>
200
+ </div>`
201
+ );
202
+ });
203
+ feedbackBody.replaceChildren(...items);
204
+ };
205
+ function setFeedbackOpen(open) {
206
+ feedback.hidden = !open;
207
+ feedbackToggle.setAttribute('aria-expanded', String(open));
208
+ feedbackToggle.textContent = open ? t.feedback.close : t.feedback.open;
209
+ }
210
+ feedbackToggle.addEventListener('click', () => setFeedbackOpen(feedback.hidden));
211
+
212
+ // 마지막 제출 (기록에서): 점수 · 시각 · AI 피드백
213
+ app
214
+ .lastSubmission()
215
+ .then(last => {
216
+ if (!last) return;
217
+ showFinal(last.score, last.createdAt ? new Date(last.createdAt) : null);
218
+ showVerdict(last.isCorrect, last.gradingFeedback);
219
+ showFeedback(last.gradingFeedback);
220
+ })
221
+ .catch(() => {});
222
+
223
+ submitButton.addEventListener('click', async () => {
224
+ submitButton.disabled = true;
225
+ submitButton.textContent = t.submitting;
226
+ error.textContent = '';
227
+ // AI 채점은 서버가 AI 답을 최대 45초 기다림
228
+ verdict.textContent = gradingMode === 'ai' ? t.aiGrading : '';
229
+ try {
230
+ let project;
231
+ try {
232
+ project = await ws.getProject();
233
+ } catch {
234
+ throw new Error(t.noProject);
235
+ }
236
+ const answer = answerValue(await pack(project));
237
+ const size = jsonBytes(answer);
238
+ if (size > LIMITS.answerBytes)
239
+ throw new Error(t.tooLargeToSubmit(formatBytes(size), formatBytes(LIMITS.answerBytes)));
240
+ const res = await app.submit(answer);
241
+ showFinal(res?.score, new Date());
242
+ showVerdict(res?.isCorrect, res?.gradingFeedback);
243
+ // AI 피드백: 옛 SDK(1.5.x까지) submit은 grading_feedback을 넘기지 않아 기록에서 다시 읽음
244
+ // (미리보기 · 교육자처럼 기록되지 않는 제출이면 피드백을 지움)
245
+ if (res?.gradingFeedback) showFeedback(res.gradingFeedback);
246
+ else if (app.isDraft || app.viewer !== 'student') showFeedback(null);
247
+ else
248
+ void app
249
+ .lastSubmission()
250
+ .then(last => {
251
+ showVerdict(res?.isCorrect, last?.gradingFeedback);
252
+ showFeedback(last?.gradingFeedback);
253
+ })
254
+ .catch(() => {});
255
+ // 낸 작품을 자동 저장 칸에도 (다시 열면 낸 작품부터)
256
+ if (canSave) {
257
+ menuProject = project;
258
+ void autosave.saveNow();
259
+ }
260
+ } catch (e) {
261
+ verdict.textContent = '';
262
+ error.textContent = t.submitFailed(e.message);
263
+ } finally {
264
+ submitButton.disabled = false;
265
+ submitButton.textContent = t.submit;
266
+ }
267
+ });
268
+ }