@joplo-app/core 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/validate.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { orderedFeatures } from "./features.js";
2
2
  import { Project } from "./schema.js";
3
- import { CAPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, captionLength } from "./catalog.js";
3
+ import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
4
+ import { scenarioEstimateMs } from "./outline.js";
4
5
  import { walkNodes, findNode, replay } from "./player.js";
5
6
  import { JoploError } from "./result.js";
6
7
  import { schemaDiagnostics } from "./schema-issues.js";
8
+ import { focusReplayDiagnostics, focusStructureDiagnostics } from "./focus-check.js";
7
9
  /** IR v2 的确定性校验。源位置缺失(例如手工构造/发布 IR)时回退到配置文件。 */
8
10
  export function validate(project, opts = { mode: 'all' }) {
9
11
  if (!['structure', 'replay', 'all'].includes(opts.mode))
@@ -80,9 +82,16 @@ export function validate(project, opts = { mode: 'all' }) {
80
82
  if (['not_applicable', 'excluded'].includes(c.status) && !c.reason?.trim())
81
83
  emit('warning', 'COVERAGE_WITHOUT_REASON', `Not applicable or Excluded requires a reason: ${id}`, o.source, r);
82
84
  if (c.status === 'missing')
83
- emit('warning', 'CASE_NOT_COVERED', `Case is not yet Covered: ${id} ${p.cases[id]?.title ?? ''}`, o.source, r);
85
+ emit('warning', 'CASE_NOT_COVERED', `Case is not yet Covered: ${id} ${p.cases[id]?.title ?? ''}${caseHint(p.cases[id])}`, o.source, r);
84
86
  }
85
87
  }
88
+ // 只有顺利路径(D67,Joplo 要解决的“看不全”):功能只声明了 main 情况,而且参与的方案里每个场景都成功
89
+ for (const f of orderedFeatures(p).filter(f => !opts.optionId || f.optionIds.includes(opts.optionId))) {
90
+ const own = scenarios.filter(s => p.options[s.optionId]?.featureId === f.id);
91
+ const edge = f.caseIds.some(id => p.cases[id] && p.cases[id].dimension !== 'main');
92
+ if (p.mode === 'dev' && own.length && !edge && own.every(s => s.mock.outcome === 'success'))
93
+ emit('info', 'HAPPY_PATH_ONLY', `Feature "${f.name}" only shows the happy path: every case is a main-flow case and every scenario succeeds. Ask the user about input, permission, async, and lifecycle cases (npx joplo skill cases), then add at least one error-and-recovery scenario`, f.source, { kind: 'feature', id: f.id });
94
+ }
86
95
  for (const r of Object.values(p.rules).filter(r => included(r.optionId) && (!opts.optionId || r.featureId === p.options[opts.optionId]?.featureId))) {
87
96
  ref(p.features[r.featureId], `Rule feature does not exist: ${r.featureId}`, r, 'rule');
88
97
  if (r.optionId)
@@ -138,8 +147,9 @@ export function validate(project, opts = { mode: 'all' }) {
138
147
  if (ids.has(n.id))
139
148
  emit('error', 'DUPLICATE_ELEMENT', `Duplicate element ID in stage: ${n.id}`, n.source, r, 'reference');
140
149
  ids.add(n.id);
141
- if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim())
142
- emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}`, n.source, r);
150
+ // Indicator 的 disabled 只是隐藏角标(Mantine 的含义),不是“不能用”,不要求原因
151
+ if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim() && n.type !== 'Indicator')
152
+ emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}. Add disabledReason="…" (for example disabledReason="Only admins can invite"), or bind it to state like disabled: disabledReason={$.ui.sendHint}`, n.source, r);
143
153
  if (INTERACTIVE_TYPES.has(n.type) && !bound.has(identity(n)) && !(n.disabled === true && n.disabledReason?.trim()) && !n.unmodeled)
144
154
  emit('warning', 'UNBOUND_INTERACTIVE', `Interactive element has no demo step: ${n.id}; bind a step, disable with a reason, or mark unmodeled`, n.source, r);
145
155
  });
@@ -151,8 +161,16 @@ export function validate(project, opts = { mode: 'all' }) {
151
161
  ref(p.scenes[sc.initial.sceneId]?.optionId === sc.optionId, `Scenario initial stage is missing or belongs to another option: ${sc.initial.sceneId}`, sc, 'scenario');
152
162
  for (const id of sc.caseIds)
153
163
  ref(p.cases[id]?.featureId === o?.featureId, `Scenario case is missing or belongs to another feature: ${id}`, sc, 'scenario');
164
+ const sr = { kind: 'scenario', id: sc.id, optionId: sc.optionId };
154
165
  if (!sc.steps.length)
155
- emit('info', 'EMPTY_SCENARIO', `Scenario has no steps: ${sc.name}`, sc.source, { kind: 'scenario', id: sc.id, optionId: sc.optionId });
166
+ emit('info', 'EMPTY_SCENARIO', `Scenario has no steps: ${sc.name}`, sc.source, sr);
167
+ // 叙事(D67):封面说明 30 字以内(D61);一个场景讲一件事,太长时拆开
168
+ const dl = captionLength(sc.description);
169
+ if (dl > DESCRIPTION_MAX)
170
+ emit('warning', 'DESCRIPTION_TOO_LONG', `flow description (the scenario cover text) is ${dl} units (recommended maximum: ${DESCRIPTION_MAX}; CJK characters count as 1 each, all others as 0.5): "${sc.description}". Say in one sentence what this scenario shows; the cover clips longer text`, sc.source, sr);
171
+ const ms = scenarioEstimateMs(sc);
172
+ if (ms > SCENARIO_MS_MAX)
173
+ emit('info', 'SCENARIO_TOO_LONG', `Scenario "${sc.name}" plays about ${Math.round(ms / 1000)} s at 1× (${sc.steps.length} steps; recommended maximum: ${SCENARIO_MS_MAX / 1000} s). One scenario tells one thing: split it into scenarios (for example the happy path and each recovery), or branch with fork(); run npx joplo outline to see the pacing`, sc.source, sr);
156
174
  for (const st of sc.steps) {
157
175
  const value = { ...st, optionId: sc.optionId };
158
176
  ref(!stepIds.has(st.id), `Duplicate step ID: ${st.id}`, value, 'step');
@@ -170,6 +188,18 @@ export function validate(project, opts = { mode: 'all' }) {
170
188
  const cl = captionLength(st.caption);
171
189
  if (cl > CAPTION_MAX)
172
190
  emit('warning', 'CAPTION_TOO_LONG', `Caption length is ${cl} units (recommended maximum: ${CAPTION_MAX}; CJK characters count as 1 each, all others as 0.5; whitespace is not counted): "${st.caption}". Keep the caption to one point; move details to a separate explanation layer, for example layers: { why: layer('Design rationale', <Why />) }, then use shot('why_xxx') in this step to present it`, at, r);
191
+ if (st.action.type === 'card') {
192
+ const sub = st.action.sub ? captionLength(st.action.sub) : 0;
193
+ const points = st.action.points ?? [];
194
+ const longPoint = points.map(captionLength).find((n) => n > CAPTION_MAX);
195
+ const issues = [
196
+ ...(sub > EXPLAIN_MAX ? [`sub is ${sub} units (maximum ${EXPLAIN_MAX})`] : []),
197
+ ...(longPoint !== undefined ? [`a point is ${longPoint} units (maximum ${CAPTION_MAX})`] : []),
198
+ ...(points.length > CARD_POINTS_MAX ? [`${points.length} points (maximum ${CARD_POINTS_MAX})`] : []),
199
+ ];
200
+ if (issues.length)
201
+ emit('info', 'CARD_TEXT_TOO_LONG', `Transition card "${st.action.title}": ${issues.join('; ')}. A card is read in a few seconds: keep one sentence and at most ${CARD_POINTS_MAX} short points, and move details into the scenario steps`, at, r);
202
+ }
173
203
  if (st.explain) {
174
204
  const el = captionLength(st.explain);
175
205
  if (el > EXPLAIN_MAX)
@@ -177,6 +207,7 @@ export function validate(project, opts = { mode: 'all' }) {
177
207
  }
178
208
  }
179
209
  }
210
+ focusStructureDiagnostics(p, scenarios, emit); // 焦点提示(D70)
180
211
  for (const o of options)
181
212
  if (!diagnostics.some(d => d.severity === 'error' && (!d.ref?.optionId || d.ref.optionId === o.id)))
182
213
  verification[o.id] = 'structure_ok';
@@ -185,6 +216,8 @@ export function validate(project, opts = { mode: 'all' }) {
185
216
  const failed = new Set();
186
217
  for (const sc of scenarios) {
187
218
  const result = replay(p, sc.id);
219
+ if (!result.diagnostics.length)
220
+ focusReplayDiagnostics(p, sc, emit); // 焦点提示(D70)
188
221
  for (const d of result.diagnostics) {
189
222
  failed.add(sc.optionId);
190
223
  const step = sc.steps.find(st => st.id === (d.ref?.stepId ?? d.ref?.id)) ?? (result.finalState ? sc.steps[result.reached] : undefined);
@@ -197,3 +230,10 @@ export function validate(project, opts = { mode: 'all' }) {
197
230
  }
198
231
  return report();
199
232
  }
233
+ /** CASE_NOT_COVERED 的补充:高优先级与期望结果(PM 的 Then),帮 Agent 知道该补什么场景。 */
234
+ function caseHint(c) {
235
+ if (!c)
236
+ return '';
237
+ const parts = [...(c.priority === 'high' ? ['high priority'] : []), ...(c.expected.trim() ? [`expected: ${c.expected.trim()}`] : [])];
238
+ return parts.length ? ` (${parts.join('; ')})` : '';
239
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@joplo-app/kit": "0.2.6",
22
+ "@joplo-app/kit": "0.2.8",
23
+ "elkjs": "0.12.1",
23
24
  "zod": "4.6.7"
24
25
  },
25
26
  "engines": {