@joplo-app/core 0.1.3 → 0.2.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.
package/dist/schema.js CHANGED
@@ -8,13 +8,13 @@ import { z } from 'zod';
8
8
  import { COMPONENT_TYPES } from "./catalog.js";
9
9
  export const SCHEMA_VERSION = 2;
10
10
  /** 作者可写的 ID(对象键、元素 id)。 */
11
- export const Id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/, 'ID 只能包含字母、数字、下划线和连字符,并以字母开头');
11
+ export const Id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/, 'ID must start with a letter and contain only letters, digits, underscores, and hyphens');
12
12
  /** 编译器生成的限定 ID,例如 `invite.happy`、`invite.a-modal@/members`。 */
13
13
  export const Qid = z.string().min(1).max(256);
14
14
  export const Source = z.string().optional();
15
15
  const Json = z.lazy(() => z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(Json), z.record(z.string(), Json)]));
16
16
  // ---------- 受控条件 ----------
17
- export const StatePath = z.string().regex(/^(ui|data|inputs)(\.[A-Za-z0-9_-]+)*$/, '路径根必须是 ui、data 或 inputs');
17
+ export const StatePath = z.string().regex(/^(ui|data|inputs)(\.[A-Za-z0-9_-]+)*$/, 'Path root must be ui, data, or inputs');
18
18
  export const Condition = z.lazy(() => z.union([
19
19
  z.strictObject({ truthy: StatePath }),
20
20
  z.strictObject({ falsy: StatePath }),
@@ -59,7 +59,10 @@ export const Action = z.discriminatedUnion('type', [
59
59
  z.strictObject({ type: z.literal('select'), target: Id, value: z.string() }),
60
60
  z.strictObject({ type: z.literal('toggle'), target: Id, value: z.boolean() }),
61
61
  z.strictObject({ type: z.literal('back') }),
62
+ z.strictObject({ type: z.literal('press'), keys: z.string() }),
62
63
  z.strictObject({ type: z.literal('event'), name: z.string().min(1) }),
64
+ /** 过渡卡(D56):整屏一句大字;role = 换到这个人(feature.roles 的键)。 */
65
+ z.strictObject({ type: z.literal('card'), title: z.string().min(1), sub: z.string().min(1).optional(), points: z.array(z.string().min(1)).optional(), role: Id.optional() }),
63
66
  ]);
64
67
  export const Effect = z.discriminatedUnion('type', [
65
68
  z.strictObject({ type: z.literal('set'), path: StatePath, value: Json }),
@@ -67,6 +70,8 @@ export const Effect = z.discriminatedUnion('type', [
67
70
  z.strictObject({ type: z.literal('toast'), text: z.string().min(1), tone: z.enum(['success', 'error', 'info']).default('info') }),
68
71
  z.strictObject({ type: z.literal('navigate'), sceneId: Qid }),
69
72
  z.strictObject({ type: z.literal('complete'), text: z.string().min(1), outcome: z.enum(['success', 'failure', 'cancelled']) }),
73
+ /** 流式输出(D56):状态上等同 set;播放到这一步时绑定它的文字逐字出现。 */
74
+ z.strictObject({ type: z.literal('stream'), path: StatePath, value: z.string() }),
70
75
  ]);
71
76
  /**
72
77
  * 调用链(D48):这一步 trace 的一条路径。nodes 按路径顺序;edges 是路径上的连线,reverse = 沿连线的 to→from 方向走。
@@ -79,11 +84,20 @@ export const Trace = z.strictObject({
79
84
  });
80
85
  /** 镜头(D43):这一步在某个层级里对准哪些元素;targets 为空 = 这一层的整体。 */
81
86
  export const Shot = z.strictObject({ layer: z.string().min(1), targets: z.array(z.string().min(1)) });
87
+ export const Fork = z.strictObject({ label: z.string().min(1), scenarioId: Qid, at: z.number().int().nonnegative() });
88
+ export const Mark = z.strictObject({ target: z.string().min(1), kind: z.enum(['circle', 'underline', 'box', 'arrow']), note: z.string().min(1).optional() });
82
89
  export const Step = z.strictObject({
83
90
  id: Qid,
84
- kind: z.enum(['user', 'system']),
91
+ kind: z.enum(['user', 'system', 'card']),
85
92
  action: Action,
86
93
  caption: z.string().min(1),
94
+ /** Generated caption metadata; caption remains the English fallback for tools. */
95
+ captionAuto: z.strictObject({
96
+ kind: z.enum(['click', 'type', 'select', 'check', 'uncheck', 'switch_on', 'switch_off', 'back', 'press']),
97
+ label: z.string(),
98
+ value: z.string().optional(),
99
+ keys: z.string().optional(),
100
+ }).optional(),
87
101
  effects: z.array(Effect).default([]),
88
102
  ruleIds: z.array(Qid).default([]),
89
103
  /** 这一步的镜头(来自 shot(),按层级归类)。没有 shot 的步骤为空,镜头沿用上一步。 */
@@ -94,6 +108,10 @@ export const Step = z.strictObject({
94
108
  explain: z.string().min(1).optional(),
95
109
  /** 这一步的调用链(来自 trace()):Diagram 节点与连线的 state 由 diagramStateAt 从它推算;发布站保留。 */
96
110
  traces: z.array(Trace).default([]),
111
+ /** 分叉是演示信息,发布保留;at 在编译时比较动作与业务效果的公共前缀。 */
112
+ forks: z.array(Fork).default([]),
113
+ /** 本步标注,不累积,不参与状态转换。 */
114
+ marks: z.array(Mark).default([]),
97
115
  source: Source,
98
116
  });
99
117
  export const Scenario = z.strictObject({
@@ -102,7 +120,7 @@ export const Scenario = z.strictObject({
102
120
  name: z.string().min(1),
103
121
  description: z.string().default(''),
104
122
  caseIds: z.array(Qid).default([]),
105
- mock: z.strictObject({ label: z.string().min(1), outcome: z.enum(['success', 'failure', 'denied', 'other']) }),
123
+ mock: z.strictObject({ label: z.string().min(1), outcome: z.enum(['success', 'failure', 'denied', 'other']), auto: z.literal(true).optional() }),
106
124
  initial: z.strictObject({
107
125
  sceneId: Qid,
108
126
  ui: z.record(z.string(), Json).default({}),
@@ -129,7 +147,8 @@ export const Feature = z.strictObject({
129
147
  id: Id,
130
148
  name: z.string().min(1),
131
149
  goal: z.string().min(1),
132
- roles: z.array(z.string()).default([]),
150
+ /** 角色(D56):id 来自 { 键: role('名字') } 写法,可被层级和过渡卡引用;旧的名字数组没有 id。color 已按顺序补齐。 */
151
+ roles: z.array(z.strictObject({ id: Id.optional(), name: z.string().min(1), desc: z.string().default(''), color: z.string().min(1) })).default([]),
133
152
  constraints: z.array(z.strictObject({ id: Id, text: z.string().min(1), hard: z.boolean().default(false) })).default([]),
134
153
  caseIds: z.array(Qid).default([]),
135
154
  optionIds: z.array(Qid).default([]),
@@ -167,7 +186,7 @@ export const Option = z.strictObject({
167
186
  routes: z.array(z.string()).default([]),
168
187
  coverage: z.record(Qid, Coverage).default({}),
169
188
  /** 层级(视角):键 → 标题与这一层自己的画面(完全独立的页面)。演示信息,发布站保留。 */
170
- layers: z.record(Id, z.strictObject({ title: z.string().min(1), sceneId: Qid })).default({}),
189
+ layers: z.record(Id, z.strictObject({ title: z.string().min(1), sceneId: Qid, role: Id.optional() })).default({}),
171
190
  source: Source,
172
191
  });
173
192
  export const RULE_ORIGINS = ['user', 'project_material', 'ai_assumption', 'code_observed', 'feedback'];
package/dist/validate.js CHANGED
@@ -5,7 +5,7 @@ import { JoploError } from "./result.js";
5
5
  /** IR v2 的确定性校验。源位置缺失(例如手工构造/发布 IR)时回退到配置文件。 */
6
6
  export function validate(project, opts = { mode: 'all' }) {
7
7
  if (!['structure', 'replay', 'all'].includes(opts.mode))
8
- throw new JoploError('USAGE', '无效校验模式');
8
+ throw new JoploError('USAGE', 'Invalid validation mode');
9
9
  const diagnostics = [];
10
10
  const verification = {};
11
11
  const seen = new Set();
@@ -43,7 +43,7 @@ export function validate(project, opts = { mode: 'all' }) {
43
43
  }
44
44
  const p = parsed.data;
45
45
  if (opts.optionId && !Object.hasOwn(p.options, opts.optionId))
46
- throw new JoploError('USAGE', `方案不存在:${opts.optionId}`);
46
+ throw new JoploError('USAGE', `Option does not exist: ${opts.optionId}`);
47
47
  const options = Object.values(p.options).filter(o => !opts.optionId || o.id === opts.optionId);
48
48
  const included = (optionId) => !opts.optionId || !optionId || optionId === opts.optionId;
49
49
  const scenarios = Object.values(p.scenarios).filter(s => included(s.optionId));
@@ -58,54 +58,54 @@ export function validate(project, opts = { mode: 'all' }) {
58
58
  for (const [id, value] of Object.entries(table)) {
59
59
  const optionId = 'optionId' in value ? value.optionId : kind === 'option' ? id : undefined;
60
60
  if (included(optionId))
61
- ref(id === value.id, `记录键 ${id} 与对象 ID ${value.id} 不一致`, { ...value, optionId }, kind);
61
+ ref(id === value.id, `Record key ${id} does not match object ID ${value.id}`, { ...value, optionId }, kind);
62
62
  }
63
63
  }
64
64
  for (const c of Object.values(p.cases).filter(c => !opts.optionId || c.featureId === p.options[opts.optionId]?.featureId)) {
65
- ref(p.features[c.featureId]?.caseIds.includes(c.id), `情况的功能不存在或未列出情况:${c.featureId}`, c, 'case');
65
+ ref(p.features[c.featureId]?.caseIds.includes(c.id), `Case feature does not exist or does not list the case: ${c.featureId}`, c, 'case');
66
66
  }
67
67
  for (const f of Object.values(p.features).filter(f => !opts.optionId || f.optionIds.includes(opts.optionId))) {
68
68
  for (const id of f.caseIds)
69
- ref(p.cases[id]?.featureId === f.id, `功能情况不存在或跨功能:${id}`, f, 'feature');
69
+ ref(p.cases[id]?.featureId === f.id, `Feature case is missing or belongs to another feature: ${id}`, f, 'feature');
70
70
  for (const id of f.optionIds)
71
- ref(p.options[id]?.featureId === f.id, `功能方案不存在或跨功能:${id}`, f, 'feature');
71
+ ref(p.options[id]?.featureId === f.id, `Feature option is missing or belongs to another feature: ${id}`, f, 'feature');
72
72
  if (f.pick)
73
- ref(p.options[f.pick]?.featureId === f.id, `选定方案不存在或跨功能:${f.pick}`, f, 'feature');
73
+ ref(p.options[f.pick]?.featureId === f.id, `Picked option is missing or belongs to another feature: ${f.pick}`, f, 'feature');
74
74
  }
75
75
  for (const o of options) {
76
76
  const value = { ...o, optionId: o.id };
77
- ref(p.features[o.featureId]?.optionIds.includes(o.id), `方案的功能不存在或未列出方案:${o.featureId}`, value, 'option');
77
+ ref(p.features[o.featureId]?.optionIds.includes(o.id), `Option feature does not exist or does not list the option: ${o.featureId}`, value, 'option');
78
78
  const cases = Object.values(p.cases).filter(c => c.featureId === o.featureId);
79
79
  for (const c of cases)
80
80
  if (!o.coverage[c.id])
81
- emit('warning', 'CASE_NOT_COVERED', `情况缺少覆盖:${c.id} ${c.title}`, o.source, { kind: 'case', id: c.id, optionId: o.id });
81
+ emit('warning', 'CASE_NOT_COVERED', `Case has no coverage: ${c.id} ${c.title}`, o.source, { kind: 'case', id: c.id, optionId: o.id });
82
82
  for (const [id, c] of Object.entries(o.coverage)) {
83
83
  const r = { kind: 'case', id, optionId: o.id };
84
- ref(p.cases[id]?.featureId === o.featureId, `coverage 情况不存在或跨功能:${id}`, value, 'option');
84
+ ref(p.cases[id]?.featureId === o.featureId, `coverage case is missing or belongs to another feature: ${id}`, value, 'option');
85
85
  for (const sid of c.scenarioIds)
86
- ref(p.scenarios[sid]?.optionId === o.id, `coverage 场景不存在或跨方案:${sid}`, value, 'option');
86
+ ref(p.scenarios[sid]?.optionId === o.id, `coverage scenario is missing or belongs to another option: ${sid}`, value, 'option');
87
87
  if (c.status === 'expressed' && !c.scenarioIds.length)
88
- emit('warning', 'EXPRESSED_WITHOUT_SCENARIO', `已表达情况没有场景:${id}`, o.source, r);
88
+ emit('warning', 'EXPRESSED_WITHOUT_SCENARIO', `Covered case has no scenario: ${id}`, o.source, r);
89
89
  if (['not_applicable', 'excluded'].includes(c.status) && !c.reason?.trim())
90
- emit('warning', 'COVERAGE_WITHOUT_REASON', `不适用或已排除必须说明原因:${id}`, o.source, r);
90
+ emit('warning', 'COVERAGE_WITHOUT_REASON', `Not applicable or Excluded requires a reason: ${id}`, o.source, r);
91
91
  if (c.status === 'missing')
92
- emit('warning', 'CASE_NOT_COVERED', `情况尚未表达:${id} ${p.cases[id]?.title ?? ''}`, o.source, r);
92
+ emit('warning', 'CASE_NOT_COVERED', `Case is not yet Covered: ${id} ${p.cases[id]?.title ?? ''}`, o.source, r);
93
93
  }
94
94
  }
95
95
  for (const r of Object.values(p.rules).filter(r => included(r.optionId) && (!opts.optionId || r.featureId === p.options[opts.optionId]?.featureId))) {
96
- ref(p.features[r.featureId], `规则的功能不存在:${r.featureId}`, r, 'rule');
96
+ ref(p.features[r.featureId], `Rule feature does not exist: ${r.featureId}`, r, 'rule');
97
97
  if (r.optionId)
98
- ref(p.options[r.optionId]?.featureId === r.featureId, `规则的方案不存在或跨功能:${r.optionId}`, r, 'rule');
98
+ ref(p.options[r.optionId]?.featureId === r.featureId, `Rule option is missing or belongs to another feature: ${r.optionId}`, r, 'rule');
99
99
  for (const id of r.caseIds)
100
- ref(p.cases[id]?.featureId === r.featureId, `规则情况不存在或跨功能:${id}`, r, 'rule');
100
+ ref(p.cases[id]?.featureId === r.featureId, `Rule case is missing or belongs to another feature: ${id}`, r, 'rule');
101
101
  const scenes = Object.values(p.scenes).filter(s => s.optionId && (r.optionId ? s.optionId === r.optionId : p.options[s.optionId]?.featureId === r.featureId));
102
102
  for (const id of r.elementIds)
103
103
  if (!scenes.some(s => findNode(s, id)))
104
- emit('warning', 'RULE_ELEMENT_NOT_FOUND', `规则关联的元素在相关方案的所有画面中均不存在:${id}`, r.source, { kind: 'rule', id: r.id, optionId: r.optionId });
104
+ emit('warning', 'RULE_ELEMENT_NOT_FOUND', `Rule element is absent from every stage in the related options: ${id}`, r.source, { kind: 'rule', id: r.id, optionId: r.optionId });
105
105
  if (r.origin === 'ai_assumption' && r.confirmation === 'pending')
106
106
  emit('info', 'PENDING_AI_ASSUMPTION', r.text, r.source, { kind: 'rule', id: r.id, optionId: r.optionId });
107
107
  if (r.origin === 'ai_assumption' && r.confirmation === 'confirmed')
108
- emit('error', 'ASSUMPTION_CONFIRMED', 'AI 假设不能标为已确认', r.source, { kind: 'rule', id: r.id, optionId: r.optionId });
108
+ emit('error', 'ASSUMPTION_CONFIRMED', 'An AI assumption cannot be Confirmed', r.source, { kind: 'rule', id: r.id, optionId: r.optionId });
109
109
  }
110
110
  // 从每个场景的路径和跳转追踪步骤目标;只按 id 全局匹配会误认其他页面的同名元素。
111
111
  const identity = (n) => JSON.stringify([n.source ?? '', n.from ?? '', n.id]);
@@ -137,52 +137,52 @@ export function validate(project, opts = { mode: 'all' }) {
137
137
  }
138
138
  for (const s of Object.values(p.scenes).filter(s => included(s.optionId))) {
139
139
  const value = { id: s.id, optionId: s.optionId ?? undefined, source: s.root.source ?? (s.optionId ? p.options[s.optionId]?.source : undefined) };
140
- ref(p.scenes[s.id] === s, `画面键与 ID 不一致:${s.id}`, value, 'scene');
140
+ ref(p.scenes[s.id] === s, `Stage key does not match ID: ${s.id}`, value, 'scene');
141
141
  if (s.optionId)
142
- ref(p.options[s.optionId], `画面方案不存在:${s.optionId}`, value, 'scene');
143
- ref(p.routes[s.route], `画面路径不存在:${s.route}`, value, 'scene');
142
+ ref(p.options[s.optionId], `Stage option does not exist: ${s.optionId}`, value, 'scene');
143
+ ref(p.routes[s.route], `Stage route does not exist: ${s.route}`, value, 'scene');
144
144
  const ids = new Set();
145
145
  walkNodes(s.root, n => {
146
146
  const r = { kind: 'element', id: n.id, optionId: n.from ?? s.optionId ?? undefined };
147
147
  if (ids.has(n.id))
148
- emit('error', 'DUPLICATE_ELEMENT', `画面内元素 ID 重复:${n.id}`, n.source, r, 'reference');
148
+ emit('error', 'DUPLICATE_ELEMENT', `Duplicate element ID in stage: ${n.id}`, n.source, r, 'reference');
149
149
  ids.add(n.id);
150
150
  if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim())
151
- emit('warning', 'DISABLED_WITHOUT_REASON', `禁用元素缺少原因:${n.id}`, n.source, r);
151
+ emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}`, n.source, r);
152
152
  if (INTERACTIVE_TYPES.has(n.type) && !bound.has(identity(n)) && !(n.disabled === true && n.disabledReason?.trim()) && !n.unmodeled)
153
- emit('warning', 'UNBOUND_INTERACTIVE', `可操作元素没有演示步骤:${n.id};请绑定步骤、禁用并说明原因或标记 unmodeled`, n.source, r);
153
+ 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);
154
154
  });
155
155
  }
156
156
  const stepIds = new Set();
157
157
  for (const sc of scenarios) {
158
158
  const o = p.options[sc.optionId];
159
- ref(o, `场景方案不存在:${sc.optionId}`, sc, 'scenario');
160
- ref(p.scenes[sc.initial.sceneId]?.optionId === sc.optionId, `场景初始画面不存在或跨方案:${sc.initial.sceneId}`, sc, 'scenario');
159
+ ref(o, `Scenario option does not exist: ${sc.optionId}`, sc, 'scenario');
160
+ ref(p.scenes[sc.initial.sceneId]?.optionId === sc.optionId, `Scenario initial stage is missing or belongs to another option: ${sc.initial.sceneId}`, sc, 'scenario');
161
161
  for (const id of sc.caseIds)
162
- ref(p.cases[id]?.featureId === o?.featureId, `场景情况不存在或跨功能:${id}`, sc, 'scenario');
162
+ ref(p.cases[id]?.featureId === o?.featureId, `Scenario case is missing or belongs to another feature: ${id}`, sc, 'scenario');
163
163
  if (!sc.steps.length)
164
- emit('info', 'EMPTY_SCENARIO', `场景没有步骤:${sc.name}`, sc.source, { kind: 'scenario', id: sc.id, optionId: sc.optionId });
164
+ emit('info', 'EMPTY_SCENARIO', `Scenario has no steps: ${sc.name}`, sc.source, { kind: 'scenario', id: sc.id, optionId: sc.optionId });
165
165
  for (const st of sc.steps) {
166
166
  const value = { ...st, optionId: sc.optionId };
167
- ref(!stepIds.has(st.id), `步骤 ID 重复:${st.id}`, value, 'step');
167
+ ref(!stepIds.has(st.id), `Duplicate step ID: ${st.id}`, value, 'step');
168
168
  stepIds.add(st.id);
169
169
  for (const id of st.ruleIds) {
170
170
  const rule = p.rules[id];
171
- ref(rule && rule.featureId === o?.featureId && (!rule.optionId || rule.optionId === sc.optionId), `步骤规则不存在或跨范围:${id}`, value, 'step');
171
+ ref(rule && rule.featureId === o?.featureId && (!rule.optionId || rule.optionId === sc.optionId), `Step rule is missing or outside its scope: ${id}`, value, 'step');
172
172
  }
173
173
  for (const e of st.effects)
174
174
  if (e.type === 'navigate')
175
- ref(p.scenes[e.sceneId]?.optionId === sc.optionId, `跳转画面不存在或跨方案:${e.sceneId}`, value, 'step');
175
+ ref(p.scenes[e.sceneId]?.optionId === sc.optionId, `Navigation stage is missing or belongs to another option: ${e.sceneId}`, value, 'step');
176
176
  // 字幕只用来点一句(只提示,不截断、不改写作者的文字);长内容放进单独的说明层,由导演切过去讲
177
177
  const r = { kind: 'step', id: st.id, optionId: sc.optionId, stepId: st.id };
178
178
  const at = st.source ?? sc.source;
179
179
  const cl = captionLength(st.caption);
180
180
  if (cl > CAPTION_MAX)
181
- emit('warning', 'CAPTION_TOO_LONG', `说明有 ${cl} 个字(建议不超过 ${CAPTION_MAX},英文按半个字算):「${st.caption}」。字幕只点一句;详细内容移到单独的说明层,例如 layers: { why: layer('设计理由', <Why />) },再在这一步 shot('why_xxx') 切过去讲`, at, r);
181
+ 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);
182
182
  if (st.explain) {
183
183
  const el = captionLength(st.explain);
184
184
  if (el > EXPLAIN_MAX)
185
- emit('warning', 'EXPLAIN_TOO_LONG', `explain 有 ${el} 个字(建议不超过 ${EXPLAIN_MAX})。信息很多时放进单独的说明层,例如 layers: { why: layer('设计理由', <Why />) },再用 shot 切过去`, at, r);
185
+ emit('warning', 'EXPLAIN_TOO_LONG', `explain note length is ${el} units (recommended maximum: ${EXPLAIN_MAX}; CJK characters count as 1 each, all others as 0.5; whitespace is not counted). Move long content to a separate explanation layer, for example layers: { why: layer('Design rationale', <Why />) }, then switch to it with shot`, at, r);
186
186
  }
187
187
  }
188
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@joplo-app/kit": "0.1.3",
22
+ "@joplo-app/kit": "0.2.1",
23
23
  "zod": "4.6.7"
24
24
  },
25
25
  "engines": {