@joplo-app/core 0.2.2 → 0.2.5
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/agent-skill.d.ts +25 -0
- package/dist/agent-skill.js +112 -0
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.js +4 -1
- package/dist/compile.d.ts +2 -1
- package/dist/compile.js +41 -17
- package/dist/embed.d.ts +28 -0
- package/dist/embed.js +31 -0
- package/dist/features.d.ts +5 -0
- package/dist/features.js +4 -0
- package/dist/guide.d.ts +5 -5
- package/dist/guide.js +120 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/player.d.ts +2 -1
- package/dist/player.js +2 -1
- package/dist/result.d.ts +2 -0
- package/dist/review.d.ts +91 -0
- package/dist/review.js +119 -0
- package/dist/schema-issues.d.ts +25 -0
- package/dist/schema-issues.js +63 -0
- package/dist/schema.d.ts +37 -4
- package/dist/schema.js +14 -3
- package/dist/validate.js +6 -15
- package/package.json +2 -2
package/dist/guide.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MENTAL_MODEL, START_ORDER } from "./agent-skill.js";
|
|
2
|
+
import { COMPONENT_TYPES, GATED_CONTAINERS, HTML_TAGS, INTERACTIVE_TYPES, JOPLO_PROPS, VALUE_TYPES } from "./catalog.js";
|
|
2
3
|
import { JoploError } from "./result.js";
|
|
4
|
+
import { LAYER_ICONS } from "./schema.js";
|
|
3
5
|
export const SKILL_TOPICS = [
|
|
4
|
-
{ name: 'authoring', description: '
|
|
5
|
-
{ name: 'demo', description: 'Layers, shots,
|
|
6
|
-
{ name: 'components', description: 'Component catalog
|
|
6
|
+
{ name: 'authoring', description: 'Mental model, first steps, page / option / flow syntax, when conditions, a form example' },
|
|
7
|
+
{ name: 'demo', description: 'Layers, shots, captions, full-height layout, deep links, and screenshots' },
|
|
8
|
+
{ name: 'components', description: 'Component catalog, supported HTML tags, line breaks, and props' },
|
|
7
9
|
{ name: 'cases', description: 'Case dimensions: ask the user before starting' },
|
|
8
|
-
{ name: 'check', description: 'Read diagnostics and fix the indicated file and line' },
|
|
10
|
+
{ name: 'check', description: 'Read diagnostics, UNBOUND_INTERACTIVE, and fix the indicated file and line' },
|
|
9
11
|
{ name: 'selection', description: 'Edit only the element selected by the user in the board' },
|
|
10
|
-
{ name: 'publish', description: 'pick, build,
|
|
12
|
+
{ name: 'publish', description: 'pick, build, share, review version, feedback write-back, deployment' },
|
|
11
13
|
];
|
|
12
14
|
const related = {
|
|
13
15
|
authoring: ['demo', 'components', 'cases', 'check', 'selection', 'publish'],
|
|
@@ -22,6 +24,13 @@ const related = {
|
|
|
22
24
|
export function skillIndex(version, docs) {
|
|
23
25
|
return [
|
|
24
26
|
`Joplo ${version} · Agent usage (read on demand)`,
|
|
27
|
+
'',
|
|
28
|
+
...MENTAL_MODEL,
|
|
29
|
+
'',
|
|
30
|
+
'Start here:',
|
|
31
|
+
...START_ORDER.map((s, i) => ` ${i + 1}. ${s}`),
|
|
32
|
+
'',
|
|
33
|
+
'Topics (suggested order: authoring, cases, components, demo, check; selection and publish when needed):',
|
|
25
34
|
...SKILL_TOPICS.map(t => ` ${t.name.padEnd(11)} ${t.description} ${skillTopic(t.name, docs).trimEnd().split('\n').length} lines`),
|
|
26
35
|
'Usage: npx joplo skill <topic> Install for agents: npx joplo skill install',
|
|
27
36
|
'',
|
|
@@ -50,6 +59,12 @@ function componentTopic(docs = {}) {
|
|
|
50
59
|
'Import components from @joplo-app/kit/ui. Names below come from the current compiler catalog; do not invent components.',
|
|
51
60
|
'Prop hints follow names when available; otherwise only names are listed. Write HTML tags directly in JSX; do not import them from ui.',
|
|
52
61
|
'',
|
|
62
|
+
'## HTML tags and line breaks',
|
|
63
|
+
`- Supported HTML tags: ${HTML_TAGS.join(', ')} (a is interactive). Any other tag (br, img, button, input, table, form, label, hr, h5) is UNKNOWN_COMPONENT; use the component instead (Divider, Image, Button, TextInput, Table).`,
|
|
64
|
+
"- Line breaks: JSX collapses newlines in text, and there is no <br/>. Text, Blockquote, List.Item, Timeline.Item, and Accordion.Panel keep \\n, so write <Text>{'Line 1\\nLine 2'}</Text>.",
|
|
65
|
+
"- Elsewhere add style={{ whiteSpace: 'pre-line' }}, or stack several <Text> in a <Stack gap={4}>. Text with truncate stays on one line.",
|
|
66
|
+
'- Every component accepts style={{ … }} and the Mantine style props (m, p, w, h, c, bg, fz, fw, ta…); className is not needed.',
|
|
67
|
+
'',
|
|
53
68
|
'## Component catalog',
|
|
54
69
|
...names.map(name => `- ${name}${Object.hasOwn(docs, name) && docs[name]?.trim() ? `: ${docs[name].replace(/\s+/g, ' ').trim()}` : ''}`),
|
|
55
70
|
'',
|
|
@@ -60,13 +75,21 @@ function componentTopic(docs = {}) {
|
|
|
60
75
|
'',
|
|
61
76
|
`Joplo props: ${JOPLO_PROPS.join(', ')}; disabled is the component disable prop.`,
|
|
62
77
|
'when controls visibility; disabledReason explains disabling; unmodeled marks behavior not modeled by this prototype; note is an authoring note.',
|
|
63
|
-
'Interactive elements need a flow step, disabled=true with a
|
|
78
|
+
'Interactive elements need a flow step, disabled={true} with a disabledReason, or explicit unmodeled (see check: UNBOUND_INTERACTIVE).',
|
|
79
|
+
'Value components are read-only on stage: they show inputs[id] written by .type/.select/.toggle steps, or a bound value prop. Viewers cannot type their own text.',
|
|
64
80
|
'See authoring for bindings, conditions, and steps; check for component error fixes.',
|
|
65
81
|
].join('\n');
|
|
66
82
|
}
|
|
67
83
|
const CONTENT = {
|
|
68
84
|
authoring: `# Joplo authoring: authoring
|
|
69
85
|
|
|
86
|
+
## Mental model (read first)
|
|
87
|
+
${MENTAL_MODEL.map(s => `- ${s}`).join('\n')}
|
|
88
|
+
- So write what the viewer should see as steps: typing is .type(id, 'sample'), a click is .click(id), a server answer is .system('caption', set(...)).
|
|
89
|
+
|
|
90
|
+
## Start small
|
|
91
|
+
${START_ORDER.map((s, i) => `${i + 1}. ${s}`).join('\n')}
|
|
92
|
+
|
|
70
93
|
Describe designs in TS/TSX. Source files are authoritative; Git manages versions. The board and published site consume compiled IR.
|
|
71
94
|
Read only the topics needed, usually one or two at a time. See components for components, cases for questions before starting, and demo for organizing and presenting demos.
|
|
72
95
|
|
|
@@ -84,7 +107,8 @@ Read only the topics needed, usually one or two at a time. See components for co
|
|
|
84
107
|
- config({ name, description?, theme?: theme name (9 built-ins or themes/<name>.css; see demo), layout?, home? }).
|
|
85
108
|
- layout(tree); Outlet places the current page; <Slot name="actions"/> declares a slot for additions.
|
|
86
109
|
- page({ title, layout?: string|false, viewport?: 'desktop'|'mobile' }, tree). See demo for devices and stages.
|
|
87
|
-
- feature({ name, goal, cases, roles?, constraints?, rules?, questions?, pick? }).
|
|
110
|
+
- feature({ name, goal, cases, order?, roles?, constraints?, rules?, questions?, pick? }).
|
|
111
|
+
- Do not number feature names by hand; use finite numeric order. The compiler writes featureIds into IR (including publish): ascending order first, then natural folder-name order for ties or omitted values. All views read that list.
|
|
88
112
|
- option({ name, idea, on?, routes?, state?, rules?, questions?, coverage?, scenarios }).
|
|
89
113
|
- on: { '/members': { actions: <Button id="invite">Invite</Button> } }: add elements to a slot on an existing route.
|
|
90
114
|
- routes: { '/members/new': page({ title: 'New member' }, <Stack>…</Stack>) }: add a route for this option.
|
|
@@ -105,17 +129,51 @@ Read only the topics needed, usually one or two at a time. See components for co
|
|
|
105
129
|
- uses('rule_key', ...): link rules from this option or feature.
|
|
106
130
|
|
|
107
131
|
## Bindings and conditions
|
|
108
|
-
- $.ui.x / $.data.x / $.inputs.x bind whole values; arbitrary expressions are not evaluated.
|
|
109
|
-
-
|
|
132
|
+
- $.ui.x / $.data.x / $.inputs.x bind whole values; arbitrary expressions are not evaluated. $.inputs.<id> is the value typed into element <id>.
|
|
133
|
+
- Props can bind: <TextInput id="email" error={$.ui.emailError}/>, <Text>{$.data.name}</Text>.
|
|
110
134
|
- not(x), eq(x, value), neq(x, value), empty(x), notEmpty(x), oneOf(x, values), and(...xs), or(...xs).
|
|
111
135
|
- Overlays: <Modal id="dlg" opened={$.ui.open} title="…">; Drawer works the same way. Only opened controls visibility.
|
|
112
136
|
|
|
137
|
+
## when takes a condition, never a plain value
|
|
138
|
+
- Right: when={$.ui.sent}, when={not($.ui.sent)}, when={eq($.ui.mode, 'code')}, when={and(notEmpty($.inputs.email), not($.ui.sending))}.
|
|
139
|
+
- Wrong: when={!link}, when={mode === 'code'}, when={true}. JavaScript evaluates these once while the project loads, so when gets a plain boolean: check reports INVALID_CONDITION at that line.
|
|
140
|
+
- Value known while writing (a prop of your own component, a loop variable, an option-specific flag): render conditionally in your code instead, {mode === 'code' && <CodeForm/>}. false, null, and undefined children are dropped.
|
|
141
|
+
- Value that changes during the demo: keep it in option state and change it with set() in a step.
|
|
142
|
+
- disabled accepts true/false or a condition: disabled={$.ui.sending} disabledReason="Sending…".
|
|
143
|
+
|
|
113
144
|
## Layout and responsiveness (Mantine names and props; no className)
|
|
114
145
|
- Use Stack / Group / SimpleGrid / Grid props: <Group justify="space-between">, <SimpleGrid cols={{ base: 1, md: 3 }}>.
|
|
115
146
|
- Use responsive objects { base, xs, sm, md, lg, xl }, or visibleFrom="sm" / hiddenFrom="sm". AppShell collapses navigation below navbar.breakpoint.
|
|
116
147
|
- Set input labels directly: <TextInput id="email" label="Email"/>. Auto captions use them.
|
|
117
148
|
- Stage height follows the window. Do not use fixed pixel heights for full-height layouts, which clip bottom inputs and buttons in short windows. See Full-height layout in demo.
|
|
118
149
|
|
|
150
|
+
## Example: form with an error and a retry
|
|
151
|
+
Inputs show what the steps type; the error comes from set(), not from validation code.
|
|
152
|
+
\`\`\`tsx
|
|
153
|
+
import { $, done, flow, option, page, set } from '@joplo-app/kit';
|
|
154
|
+
import { Alert, Button, Loader, Stack, TextInput } from '@joplo-app/kit/ui';
|
|
155
|
+
const send = (name: string, cases: string[]) => flow(name, { start: '/reset', cases })
|
|
156
|
+
.type('email', 'ana@exmple.com').click('send', 'Send the reset link', set($.ui.sending, true));
|
|
157
|
+
export default option({
|
|
158
|
+
name: 'A · Email link', idea: 'Send a reset link by email',
|
|
159
|
+
state: { ui: { sending: false, sent: false, emailError: '' } },
|
|
160
|
+
routes: { '/reset': page({ title: 'Reset password' }, <Stack>
|
|
161
|
+
<TextInput id="email" label="Email" error={$.ui.emailError} />
|
|
162
|
+
<Button id="send" disabled={$.ui.sending} disabledReason="Sending…">Send link</Button>
|
|
163
|
+
<Loader when={$.ui.sending} />
|
|
164
|
+
<Alert id="sent" color="green" when={$.ui.sent}>Check your inbox</Alert>
|
|
165
|
+
</Stack>) },
|
|
166
|
+
scenarios: {
|
|
167
|
+
unknown_email: send('Typo, then retry', ['unknown_email'])
|
|
168
|
+
.system('No account for this email', set($.ui.sending, false), set($.ui.emailError, 'No account with this email'))
|
|
169
|
+
.type('email', 'ana@example.com', set($.ui.emailError, ''))
|
|
170
|
+
.click('send', 'Retry', set($.ui.sending, true))
|
|
171
|
+
.system('Server accepts', set($.ui.sending, false), set($.ui.sent, true), done('Link sent after retry')),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
\`\`\`
|
|
175
|
+
Add the happy path the same way; declare both cases in feature.ts. Add layers (see demo) once this works in the board.
|
|
176
|
+
|
|
119
177
|
## Rules and boundaries
|
|
120
178
|
- rule('Constraint', { origin?, status?, cases?: ['happy'], elements?: ['invite'] }).
|
|
121
179
|
- origin: user/project_material/ai_assumption/code_observed/feedback; default ai_assumption.
|
|
@@ -160,10 +218,11 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
|
|
|
160
218
|
## Captions and fitting one screen
|
|
161
219
|
- Keep captions within about 24 units and explain('Additional note') within about 48. CJK characters count as 1 each; all others count as 0.5; whitespace is ignored. check warns when exceeded.
|
|
162
220
|
- Captions and explain notes appear below the stage, never over it. Tell one thing per step; move long content to an explanation layer.
|
|
163
|
-
- Autoplay
|
|
221
|
+
- Autoplay reading time: CJK 8 chars/s (125ms each), Latin 15 non-whitespace chars/s; clamp to 3–7 seconds before 0.5× / 1× / 1.5× scaling. Streams, shots and edge waits can exceed 7 seconds. Shots use 700ms ease-out without overshoot.
|
|
164
222
|
- Do not make viewers scroll through a long page. Fit one screen and zoom into details with shots.
|
|
165
223
|
- Each page has one device, desktop by default. page({ viewport: 'mobile' }, tree) uses a Phone frame at a fixed width of 390.
|
|
166
224
|
- For a mobile layer, use layer('Mobile', <MobileView/>, { viewport: 'mobile' }). Make a separate page or demo when mobile is needed (D44).
|
|
225
|
+
- Each layer tab shows an icon so viewers can tell layers apart when many tabs are squeezed: layer('Terminal', <Cli/>, { icon: 'terminal' }). Presets: ${LAYER_ICONS.join(', ')}. Default: mobile for mobile layers, otherwise window.
|
|
167
226
|
|
|
168
227
|
## Full-height layout: Follow stage height
|
|
169
228
|
- Layers and desktop pages fill the stage, whose size follows the board window. Fixed pixel heights (h={690}) push bottom content outside short windows.
|
|
@@ -172,6 +231,18 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
|
|
|
172
231
|
<Group><PromptInput id="prompt"/><Button id="send">Send</Button></Group></Stack></Grid.Col></Grid>
|
|
173
232
|
- The same applies to placeholders and artifacts: use h="100%" on Placeholder; Artifact fills its container by default.
|
|
174
233
|
- Use fixed pixels only for elements with a fixed height (avatars, icons, Diagram canvas height).
|
|
234
|
+
- What gets squeezed: in an h="100%" column, a Table, DataTable, or ScrollArea shrinks to the space left and scrolls inside. Rows stay in the DOM and check passes, but viewers see fewer rows.
|
|
235
|
+
- Budget the height: render uses a 1280×800 desktop stage (the board follows the window, so leave margin); a table row is about 38px, a labeled input about 64px plus the gap.
|
|
236
|
+
- Fixes: show fewer rows (5–8), split a long form across steps or layers, or move the table to its own layer and shot it. style={{ flexShrink: 0 }} keeps every row but pushes what follows off the stage.
|
|
237
|
+
- Verify with npx joplo render: it warns when the next step's target is not visible.
|
|
238
|
+
|
|
239
|
+
## Deep links and screenshots
|
|
240
|
+
- Board: http://127.0.0.1:<port>/#/<project>/f/<feature>?o=<option>&c=<case>&s=<scenario>&step=<n>&l=<layer>&speed=<0.5|1.5>. Copy the project part from the board URL.
|
|
241
|
+
- Published site: <site>/#/f/<feature>?s=<scenario>&step=<n>&l=<layer>. Embeds use ?embed=1&scenario=<scenario>&autoplay=1 (see publish).
|
|
242
|
+
- Ids are qualified: option invite.a-modal, case invite.no_permission, scenario invite.a-modal.happy. step=n is the state after n steps (0 = initial). l is the layer key from layers: { … }; it turns Follow director off.
|
|
243
|
+
- Other parameters (layer=, option=, scenario= in the hash) are ignored; the board logs a console warning naming them.
|
|
244
|
+
- Screenshot one step: npx joplo render --scenario-id invite.a-modal.happy --step-id 'invite.a-modal.happy#2' --out shot.png. It waits for fonts, layout, and the camera, and needs Playwright (npx playwright install chromium).
|
|
245
|
+
- In a browser, open the deep link, wait for [data-jcamera][data-camera-settled="1"] plus two animation frames, then capture. During autoplay or typing animations the DOM can be ahead of the pixels; pause first.
|
|
175
246
|
|
|
176
247
|
## Transition cards, roles, and Agent output (D56)
|
|
177
248
|
- .card('Title', { sub?, points?, role? }, ...effects): one large sentence filling the stage, as a step. Use for openings, endings, time jumps, and role switches.
|
|
@@ -202,6 +273,7 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
|
|
|
202
273
|
- Published sites use the config theme, subset fonts against all built text, and never load WenKai. Newly typed characters absent from the build may use system fonts.
|
|
203
274
|
- Variables alone work and are scoped to the stage, leaving the board unaffected: --jp-font, --jp-font-mono, --jp-font-size, --jp-ink, --jp-bg, --jp-surface, --jp-subtle, --jp-muted, --jp-faint, --jp-line, --jp-line-strong, --jp-border, --jp-accent (highlight), --jp-select, --jp-info (Diagram active), --jp-ok, --jp-warn, --jp-danger, --jp-annot (annotations; defaults to danger), --jp-radius, --jp-shadow, --jp-stroke (rough hand-drawn / clean thin lines).
|
|
204
275
|
- Ordinary selectors (.jbox, h1, etc.) also work within the stage. In dark themes, check contrast of --jp-info / --jp-ok / --jp-danger / --jp-accent against the background.
|
|
276
|
+
- Filled buttons default to --jp-ink, so changing --jp-ink also recolors body text. There is no primary-color variable yet: set the brand color on the button itself, <Button color="#e8590c">, instead of overriding inline styles.
|
|
205
277
|
- Example themes/brand.css:
|
|
206
278
|
:root {
|
|
207
279
|
--jp-font: "Inter", system-ui, sans-serif;
|
|
@@ -286,6 +358,8 @@ Pick relevant cases to ask the user before starting. Do not include every preset
|
|
|
286
358
|
- Each option uses flow(..., { cases: ['happy'] }) to reference the shared cases for comparison.
|
|
287
359
|
- A case with a scenario is automatically \`expressed\`; one with neither a scenario nor a declaration is \`missing\`.
|
|
288
360
|
- After adding a case, run check: reconsider it in every option.
|
|
361
|
+
- Start with two scenarios per option, the happy path and one error-and-recovery case; add the rest after the user has seen them in the board.
|
|
362
|
+
- A rule the user stated in this conversation is origin: 'user', status: 'confirmed'; a rule you inferred stays ai_assumption, pending.
|
|
289
363
|
|
|
290
364
|
## Declare coverage without a scenario
|
|
291
365
|
Coverage status values: \`expressed\`, \`undecided\`, \`missing\`, \`not_applicable\`, \`excluded\`.
|
|
@@ -306,6 +380,8 @@ The whole project still compiles. Option filtering does not hide project compila
|
|
|
306
380
|
\`file:line:column severity CODE message\`
|
|
307
381
|
Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Interactive element has no demo step.
|
|
308
382
|
- File and line/column identify the edit location. Read nearby source and fix only that location; do not rewrite the page.
|
|
383
|
+
- The location is the author element or call that caused the problem. joplo.config.ts:1:1 means no source location was known.
|
|
384
|
+
- One root cause in a shared view (a layout, a component reused in routes and layers) prints once with "(affects N views)" and counts once; JSON adds affects: [view ids].
|
|
309
385
|
- error exits 1; usage errors exit 2; warning/info only exits 0.
|
|
310
386
|
- The last line totals error, warning, info. Run check again after fixing.
|
|
311
387
|
|
|
@@ -315,6 +391,7 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
315
391
|
- FUNCTION_PROP: Replace onClick and other callbacks with flow steps and state effects.
|
|
316
392
|
- UNKNOWN_CASE / UNKNOWN_RULE / INVALID_REFERENCE: Check case, rule, and reference keys and their owning option.
|
|
317
393
|
- UNKNOWN_SLOT / UNKNOWN_ROUTE / UNKNOWN_LAYOUT: Check routes, layouts, and Slot declarations; add elements only to existing locations.
|
|
394
|
+
- FEATURE_ORDER_INVALID: feature({ order }) must be a finite number; omit it for natural folder-name order. NaN, Infinity and strings are invalid.
|
|
318
395
|
- UNKNOWN_PICK: pick must be an option filename under this feature's options/.
|
|
319
396
|
- NOT_PICKED: The feature has no picked option and will not publish. Compare options, then set feature.pick to the chosen filename.
|
|
320
397
|
- ROUTE_EXISTS: An option route duplicates an existing route. Use on to add elements, or choose a new route.
|
|
@@ -323,6 +400,7 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
323
400
|
- CAPTION_TOO_LONG: Shorten the caption to about 24 units: CJK characters count as 1 each, all others as 0.5; whitespace is ignored. One thing per step; move long content to an explanation layer. See demo.
|
|
324
401
|
- EXPLAIN_TOO_LONG: Shorten the explain note to about 48 units, using the same CJK 1 / other 0.5 calculation. Put detailed rationale in a separate explanation layer. See demo.
|
|
325
402
|
- ROLE_UNKNOWN: A layer or card role is not in feature.roles. Declare roles as { key: role('Name') }; see demo.
|
|
403
|
+
- ICON_UNKNOWN: A layer icon is not a preset. Use one of ${LAYER_ICONS.join(', ')}; see demo.
|
|
326
404
|
- FORK_UNKNOWN: fork must target another scenario key in the same option; it cannot reference itself.
|
|
327
405
|
- MARK_UNKNOWN: The mark target is absent from this step's route stage and all layers. Check the element id; currently hidden targets are valid references.
|
|
328
406
|
- SHOT_UNKNOWN: The shot target is absent from this step's stage and all layers. Check its id and layer; see demo.
|
|
@@ -333,7 +411,8 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
333
411
|
- UNKNOWN_DIAGRAM_NODE: Diagram.Edge from/to does not reference a node in this Diagram. Correct the endpoint ids.
|
|
334
412
|
- ELEMENT_PROP: A component prop contains JSX. Use strings for icons, such as leftSection="+", and children for content.
|
|
335
413
|
- ASSUMPTION_CONFIRMED: Keep AI assumptions \`pending\`. After user confirmation, record the actual origin; do not change only status.
|
|
336
|
-
- UNBOUND_INTERACTIVE:
|
|
414
|
+
- UNBOUND_INTERACTIVE: see the section below.
|
|
415
|
+
- INVALID_CONDITION: when got a plain boolean, number, or string (when={!x}, when={mode === 'code'}). Use a condition such as when={eq($.ui.mode, 'code')}, or render conditionally in your code: {flag && <X/>}. See authoring.
|
|
337
416
|
- DISABLED_WITHOUT_REASON: Add disabledReason explaining why the element cannot be used.
|
|
338
417
|
- CASE_NOT_COVERED: Add a scenario or declare coverage truthfully. Ask about missing behavior first.
|
|
339
418
|
- EXPRESSED_WITHOUT_SCENARIO / COVERAGE_WITHOUT_REASON: Add a scenario or a reason for \`not_applicable\`/\`excluded\`.
|
|
@@ -346,6 +425,13 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
346
425
|
- ALREADY_COMPLETED / NOTHING_TO_GO_BACK: Fix steps after done, or add route navigation before back.
|
|
347
426
|
- LOAD_FAILED / WRONG_EXPORT / INVALID_SCHEMA: Follow the message to fix imports, default exports, or field structure.
|
|
348
427
|
|
|
428
|
+
## UNBOUND_INTERACTIVE: is every interaction expressed?
|
|
429
|
+
An element that looks usable (Button, TextInput, Select, NavLink, a, …; see components) has an id but no step in any scenario of this option. Viewers will try it; decide what happens:
|
|
430
|
+
1. Show it: add a step to a scenario, .click('send') or .type('email', 'ana@example.com'). Inputs that only display a value need a .type step too.
|
|
431
|
+
2. It cannot be used here: disabled={true} with disabledReason="Only admins can invite". A conditional disabled does not count; it still needs a step for the enabled state.
|
|
432
|
+
3. Out of scope for this prototype: add unmodeled (note="…" optional). Clicking it shows "This demo does not cover …".
|
|
433
|
+
Do not add fake steps just to silence the warning.
|
|
434
|
+
|
|
349
435
|
When the user points to a stage element, read selection first for its exact location.`,
|
|
350
436
|
selection: `# Joplo selection: selection
|
|
351
437
|
|
|
@@ -402,12 +488,33 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
|
|
|
402
488
|
- On AUTH_REQUIRED, ask the user to sign in. Do not run \`joplo logout\` on the user's behalf.
|
|
403
489
|
- AUTH_EXPIRED also exits 3: ask the user to sign in again. Read error.code / message / details for other failures.
|
|
404
490
|
- Free links expire after 1 hour; read data.expiresAt for the exact time. Pro permanent links have expiresAt: null.
|
|
491
|
+
- Successful share JSON includes data.embed: { iframe, markdown, badge, preview }. To add the demo to a README, write data.embed.markdown as is; do not build badge links yourself. For a free link, tell the user the badge shows "expired" after data.expiresAt.
|
|
492
|
+
- data.embed.iframe embeds a player for blogs and docs: it shows a cover first; append &scenario=<scenario id> to pick the start or &autoplay=1 to skip the cover.
|
|
493
|
+
- share also uploads a 1200x630 preview image of the default scenario when local Playwright is installed; without it, share still succeeds and prints one "Skipped the preview image" line.
|
|
405
494
|
- Pro share updates the same-server link in .joplo/cloud.json; --new creates another link and --title sets its title.
|
|
495
|
+
- The review version is a separate share (review: { shareId, url } in .joplo/cloud.json); it never replaces the main link. If the cloud rejects the review manifest, plain share retries once without it and still publishes.
|
|
406
496
|
- npx joplo whoami --format json shows the account, plan, and limits; npx joplo logout signs out.
|
|
497
|
+
- CLIENT_OUTDATED: the cloud needs a newer CLI. In a project, npx joplo@latest still runs the project's version; upgrade both packages to the same version (npm i -D joplo@latest @joplo-app/kit@latest), then share again.
|
|
407
498
|
- maxUploadBytes limits only newly uploaded cloud blobs. The CLI prechecks maxTotalBytes and maxFiles. TOO_LARGE details.kind distinguishes upload / total / files.
|
|
408
499
|
- Credentials are stored only in JOPLO_HOME/credentials.json (default ~/.joplo). Never copy them into a project, print them, or commit them.
|
|
409
500
|
- Cloud commands accept --server <url>, overriding JOPLO_CLOUD_URL; the default is https://cloud.joplo.app.
|
|
410
|
-
- Local check / build / dev remain free and do not connect to the cloud
|
|
501
|
+
- Local check / build / dev remain free and do not connect to the cloud.
|
|
502
|
+
- CI: set JOPLO_API_KEY (jpk_..., created in Settings → API keys) instead of logging in. Every cloud command then uses it; credentials.json and browser login are never touched. An invalid or revoked key returns AUTH_EXPIRED: ask the user for a new key.
|
|
503
|
+
- PR previews: in GitHub Actions run npx joplo share --new --pr <number> --format json; repo, commit, and run URL come from the Actions environment. Outside Actions pass --repo owner/name. data.pr.comment "skipped" means the Joplo GitHub App is not installed; tell the user, the share itself succeeded.
|
|
504
|
+
|
|
505
|
+
## Review and feedback (the joplo-feedback skill has the same steps)
|
|
506
|
+
- npx joplo share --review publishes the review version: every option of every feature, so reviewers can compare A/B. Rules, questions, cases, and AI assumptions still never appear in uploaded files; they go only to the review page through the request body. Plain share publishes only picked options.
|
|
507
|
+
- After reviewers comment and the owner decides on the review page, run npx joplo feedback --format json (uses the review share in .joplo/cloud.json, else the main share, or --share <id>). data.decisions are decisions not yet applied; data.comments are unresolved viewer comments with scenario, step, stepId, and element.
|
|
508
|
+
- Apply each decision to the source, then run npx joplo check:
|
|
509
|
+
- pick: set feature.pick in features/<f>/feature.ts to the option file name (the part after "<feature>.").
|
|
510
|
+
- confirm_rule: set that rule to origin: 'user', status: 'confirmed'.
|
|
511
|
+
- reject_rule: rewrite the rule as the note (reason) says. If the reason does not say what to do instead, mark it status: 'conflict' and ask the user; do not guess.
|
|
512
|
+
- answer: delete the question and add a rule with origin: 'user' (status: 'confirmed') stating the answer.
|
|
513
|
+
- Comments are input for discussion only; do not change the source from a comment unless the user asks.
|
|
514
|
+
- When check passes, mark what you applied: npx joplo feedback --applied <decision ids, comma-separated> [--ref <commit or source version>]. Mark only decisions you actually wrote back.
|
|
515
|
+
- Full loop: npx joplo share --review --format json (data.mode is "review"; give the user data.url) → reviewers comment, the owner decides → npx joplo feedback --format json → edit source → npx joplo check → commit → npx joplo share --review --format json to refresh the review link → npx joplo feedback --applied d1,d2 --ref "$(git rev-parse HEAD)".
|
|
516
|
+
- data.decisions items: { id, kind: pick|confirm_rule|reject_rule|answer, featureId, targetId, note, decidedAt, version }. targetId is the option id (pick), rule id (confirm_rule, reject_rule), or question id (answer); for answer, note is the answer.
|
|
517
|
+
- --ref works only together with --applied. --applied is idempotent; text output without --format json ends with a Next: line listing the ids.`,
|
|
411
518
|
};
|
|
412
519
|
function distance(a, b) {
|
|
413
520
|
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,3 +6,8 @@ export * from './compile.js';
|
|
|
6
6
|
export type { Selection } from './selection.js';
|
|
7
7
|
export * from './validate.js';
|
|
8
8
|
export * from './guide.js';
|
|
9
|
+
export { schemaDiagnostics, whenMessage } from './schema-issues.js';
|
|
10
|
+
export * from './embed.js';
|
|
11
|
+
export * from './features.js';
|
|
12
|
+
export * from './review.js';
|
|
13
|
+
export * from './agent-skill.js';
|
package/dist/index.js
CHANGED
|
@@ -6,3 +6,8 @@ export * from "./compile.js";
|
|
|
6
6
|
// validate.ts 仍是 IR v1 版本,待 T-cli 迁移到 IR v2 后再导出。
|
|
7
7
|
export * from "./validate.js";
|
|
8
8
|
export * from "./guide.js";
|
|
9
|
+
export { schemaDiagnostics, whenMessage } from "./schema-issues.js";
|
|
10
|
+
export * from "./embed.js";
|
|
11
|
+
export * from "./features.js";
|
|
12
|
+
export * from "./review.js";
|
|
13
|
+
export * from "./agent-skill.js";
|
package/dist/player.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* “上一步”通过从初始状态重放到 k-1 实现,因此恢复的是业务可见状态,而不是撤销动画。
|
|
7
7
|
*/
|
|
8
8
|
import { type Choice } from './catalog.js';
|
|
9
|
-
import type { Condition, Project, Scenario, Scene, SceneNode, Step } from './schema.js';
|
|
9
|
+
import type { Condition, LayerIcon, Project, Scenario, Scene, SceneNode, Step } from './schema.js';
|
|
10
10
|
import { JoploError, type Diagnostic } from './result.js';
|
|
11
11
|
export type Toast = {
|
|
12
12
|
id: string;
|
|
@@ -131,6 +131,7 @@ export declare function layersOf(project: Project, scenarioId: string | null): {
|
|
|
131
131
|
id: string;
|
|
132
132
|
title: string;
|
|
133
133
|
sceneId: string;
|
|
134
|
+
icon: LayerIcon;
|
|
134
135
|
}[];
|
|
135
136
|
/** 包含某个元素的层级(多层都有同名 id 时都返回)。 */
|
|
136
137
|
export declare function layersWithNode(project: Project, scenarioId: string, nodeId: string): string[];
|
package/dist/player.js
CHANGED
|
@@ -478,7 +478,8 @@ export function explainClick(project, state, nodeId, sceneId) {
|
|
|
478
478
|
export function layersOf(project, scenarioId) {
|
|
479
479
|
const sc = scenarioId ? project.scenarios[scenarioId] : null;
|
|
480
480
|
const opt = sc ? project.options[sc.optionId] : null;
|
|
481
|
-
|
|
481
|
+
// 图标:作者写的优先;没写时手机视口用 mobile,其余用 window
|
|
482
|
+
return Object.entries(opt?.layers ?? {}).map(([id, l]) => ({ id, title: l.title, sceneId: l.sceneId, icon: l.icon ?? (project.scenes[l.sceneId]?.viewport === 'mobile' ? 'mobile' : 'window') }));
|
|
482
483
|
}
|
|
483
484
|
/** 包含某个元素的层级(多层都有同名 id 时都返回)。 */
|
|
484
485
|
export function layersWithNode(project, scenarioId, nodeId) {
|
package/dist/result.d.ts
CHANGED
package/dist/review.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Project } from './schema.js';
|
|
2
|
+
export declare const REVIEW_MANIFEST_VERSION: 1;
|
|
3
|
+
/** 契约 8.1:评审清单 JSON(UTF-8)最多 512 KiB。 */
|
|
4
|
+
export declare const REVIEW_MANIFEST_MAX_BYTES: number;
|
|
5
|
+
/** 字段上限(客户端截断;SaaS 的 zod 校验至少要接受这些值)。 */
|
|
6
|
+
export declare const REVIEW_LIMITS: {
|
|
7
|
+
readonly features: 100;
|
|
8
|
+
/** 每个功能的方案数。 */
|
|
9
|
+
readonly options: 20;
|
|
10
|
+
/** 每个功能的规则数(功能级 + 方案级)。 */
|
|
11
|
+
readonly rules: 300;
|
|
12
|
+
readonly questions: 100;
|
|
13
|
+
readonly tradeoffs: 20;
|
|
14
|
+
/** 每条规则关联的元素数。 */
|
|
15
|
+
readonly elementIds: 50;
|
|
16
|
+
readonly scenarios: 500;
|
|
17
|
+
/** 每个场景的步骤数。 */
|
|
18
|
+
readonly steps: 200;
|
|
19
|
+
/** 每一步关联的规则数。 */
|
|
20
|
+
readonly ruleIds: 50;
|
|
21
|
+
readonly elements: 2000;
|
|
22
|
+
readonly text: {
|
|
23
|
+
readonly name: 200;
|
|
24
|
+
readonly goal: 2000;
|
|
25
|
+
readonly idea: 2000;
|
|
26
|
+
readonly tradeoff: 500;
|
|
27
|
+
readonly rule: 2000;
|
|
28
|
+
readonly question: 2000;
|
|
29
|
+
readonly caption: 500;
|
|
30
|
+
readonly explain: 2000;
|
|
31
|
+
readonly label: 200;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type ReviewManifestMode = 'publish' | 'review';
|
|
35
|
+
export type ReviewManifest = {
|
|
36
|
+
v: typeof REVIEW_MANIFEST_VERSION;
|
|
37
|
+
mode: ReviewManifestMode;
|
|
38
|
+
features: {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
goal: string;
|
|
42
|
+
pick: string | null;
|
|
43
|
+
options: {
|
|
44
|
+
id: string;
|
|
45
|
+
key: string;
|
|
46
|
+
name: string;
|
|
47
|
+
idea: string;
|
|
48
|
+
tradeoffs: string[];
|
|
49
|
+
}[];
|
|
50
|
+
rules: {
|
|
51
|
+
id: string;
|
|
52
|
+
optionId: string | null;
|
|
53
|
+
text: string;
|
|
54
|
+
origin: string;
|
|
55
|
+
confirmation: string;
|
|
56
|
+
elementIds: string[];
|
|
57
|
+
}[];
|
|
58
|
+
questions: {
|
|
59
|
+
id: string;
|
|
60
|
+
optionId: string | null;
|
|
61
|
+
text: string;
|
|
62
|
+
severity: 'blocker' | 'major' | 'minor';
|
|
63
|
+
}[];
|
|
64
|
+
}[];
|
|
65
|
+
scenarios: {
|
|
66
|
+
id: string;
|
|
67
|
+
featureId: string;
|
|
68
|
+
optionId: string;
|
|
69
|
+
name: string;
|
|
70
|
+
steps: {
|
|
71
|
+
id: string;
|
|
72
|
+
index: number;
|
|
73
|
+
caption: string;
|
|
74
|
+
explain: string | null;
|
|
75
|
+
ruleIds: string[];
|
|
76
|
+
}[];
|
|
77
|
+
}[];
|
|
78
|
+
elements: {
|
|
79
|
+
id: string;
|
|
80
|
+
label: string;
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
/** 作者写的元素 id(和 Rule.elementIds 同一套);编译器生成的以 `_` 开头,不算。 */
|
|
84
|
+
export declare const AUTHOR_ELEMENT_ID: RegExp;
|
|
85
|
+
/** 按码点截断,超出时最后一个码点换成 “…”。 */
|
|
86
|
+
export declare function clipText(text: string, max: number): string;
|
|
87
|
+
export declare function reviewManifest(project: Project, mode: ReviewManifestMode): ReviewManifest;
|
|
88
|
+
/** 序列化后的 UTF-8 字节数(请求体里就是这份 JSON)。 */
|
|
89
|
+
export declare function reviewManifestBytes(manifest: ReviewManifest): number;
|
|
90
|
+
/** 超过 512 KiB 时报错:减少规则、问题、步骤说明后重试。 */
|
|
91
|
+
export declare function assertReviewManifestSize(manifest: ReviewManifest): void;
|
package/dist/review.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 评审清单(云端契约 8.1,v1):`joplo share` 放进 `POST /api/v1/shares` 请求体的 `review` 字段,
|
|
3
|
+
* 不作为分享文件上传(不进 R2、不进 meta.json,分享页 Worker 读不到)。评审页据此显示方案、规则、问题和每一步涉及的规则。
|
|
4
|
+
*
|
|
5
|
+
* - 输入必须是 dev IR(只有它带规则和问题);mode = publish 时只含选定方案的内容(与 publish 构建同一范围:
|
|
6
|
+
* 没有选定方案的功能不出现,规则与问题只含功能级和选定方案的),mode = review 时含所有功能的所有方案。
|
|
7
|
+
* - id 全部沿用 IR(功能 Id、方案 / 规则 / 问题 / 场景 / 步骤的 Qid、元素 Id);步骤 index 从 0 开始。
|
|
8
|
+
* - 上限:字符串按 Unicode 码点截断(末尾 “…”),数组超出部分丢弃,id 永不截断(Qid ≤ 256、Id ≤ 64 由 schema 保证);
|
|
9
|
+
* 截断后序列化仍超过 512 KiB 时 assertReviewManifestSize 报错(share 在发任何请求之前失败),不静默丢内容。
|
|
10
|
+
*/
|
|
11
|
+
import { nodeLabel } from "./catalog.js";
|
|
12
|
+
import { orderedFeatures } from "./features.js";
|
|
13
|
+
import { JoploError } from "./result.js";
|
|
14
|
+
export const REVIEW_MANIFEST_VERSION = 1;
|
|
15
|
+
/** 契约 8.1:评审清单 JSON(UTF-8)最多 512 KiB。 */
|
|
16
|
+
export const REVIEW_MANIFEST_MAX_BYTES = 512 * 1024;
|
|
17
|
+
/** 字段上限(客户端截断;SaaS 的 zod 校验至少要接受这些值)。 */
|
|
18
|
+
export const REVIEW_LIMITS = {
|
|
19
|
+
features: 100,
|
|
20
|
+
/** 每个功能的方案数。 */
|
|
21
|
+
options: 20,
|
|
22
|
+
/** 每个功能的规则数(功能级 + 方案级)。 */
|
|
23
|
+
rules: 300,
|
|
24
|
+
questions: 100,
|
|
25
|
+
tradeoffs: 20,
|
|
26
|
+
/** 每条规则关联的元素数。 */
|
|
27
|
+
elementIds: 50,
|
|
28
|
+
scenarios: 500,
|
|
29
|
+
/** 每个场景的步骤数。 */
|
|
30
|
+
steps: 200,
|
|
31
|
+
/** 每一步关联的规则数。 */
|
|
32
|
+
ruleIds: 50,
|
|
33
|
+
elements: 2000,
|
|
34
|
+
text: { name: 200, goal: 2000, idea: 2000, tradeoff: 500, rule: 2000, question: 2000, caption: 500, explain: 2000, label: 200 },
|
|
35
|
+
};
|
|
36
|
+
/** 作者写的元素 id(和 Rule.elementIds 同一套);编译器生成的以 `_` 开头,不算。 */
|
|
37
|
+
export const AUTHOR_ELEMENT_ID = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
38
|
+
/** 按码点截断,超出时最后一个码点换成 “…”。 */
|
|
39
|
+
export function clipText(text, max) {
|
|
40
|
+
const chars = [...text];
|
|
41
|
+
return chars.length <= max ? text : `${chars.slice(0, max - 1).join('')}…`;
|
|
42
|
+
}
|
|
43
|
+
export function reviewManifest(project, mode) {
|
|
44
|
+
if (project.mode !== 'dev')
|
|
45
|
+
throw new JoploError('USAGE', `The review manifest needs the dev IR (rules and questions); got a ${project.mode} IR`);
|
|
46
|
+
const L = REVIEW_LIMITS;
|
|
47
|
+
const T = L.text;
|
|
48
|
+
const features = [];
|
|
49
|
+
const scenarios = [];
|
|
50
|
+
/** 参与的方案(publish:每个功能的选定方案)。 */
|
|
51
|
+
const included = new Set();
|
|
52
|
+
for (const f of orderedFeatures(project)) {
|
|
53
|
+
const optionIds = (mode === 'publish' ? (f.pick ? [f.pick] : []) : f.optionIds).filter((id) => project.options[id]);
|
|
54
|
+
if (mode === 'publish' && !optionIds.length)
|
|
55
|
+
continue;
|
|
56
|
+
for (const id of optionIds)
|
|
57
|
+
included.add(id);
|
|
58
|
+
const inScope = (optionId) => optionId === undefined || optionIds.includes(optionId);
|
|
59
|
+
features.push({
|
|
60
|
+
id: f.id,
|
|
61
|
+
name: clipText(f.name, T.name),
|
|
62
|
+
goal: clipText(f.goal, T.goal),
|
|
63
|
+
pick: f.pick ?? null,
|
|
64
|
+
options: optionIds.slice(0, L.options).map((id) => {
|
|
65
|
+
const o = project.options[id];
|
|
66
|
+
return { id: o.id, key: o.key, name: clipText(o.name, T.name), idea: clipText(o.idea, T.idea), tradeoffs: o.tradeoffs.slice(0, L.tradeoffs).map((t) => clipText(t, T.tradeoff)) };
|
|
67
|
+
}),
|
|
68
|
+
rules: Object.values(project.rules)
|
|
69
|
+
.filter((r) => r.featureId === f.id && inScope(r.optionId))
|
|
70
|
+
.slice(0, L.rules)
|
|
71
|
+
.map((r) => ({ id: r.id, optionId: r.optionId ?? null, text: clipText(r.text, T.rule), origin: r.origin, confirmation: r.confirmation, elementIds: r.elementIds.slice(0, L.elementIds) })),
|
|
72
|
+
questions: Object.values(project.issues)
|
|
73
|
+
.filter((q) => q.featureId === f.id && inScope(q.optionId))
|
|
74
|
+
.slice(0, L.questions)
|
|
75
|
+
.map((q) => ({ id: q.id, optionId: q.optionId ?? null, text: clipText(q.text, T.question), severity: q.severity })),
|
|
76
|
+
});
|
|
77
|
+
for (const optionId of optionIds) {
|
|
78
|
+
for (const s of Object.values(project.scenarios)) {
|
|
79
|
+
if (s.optionId !== optionId)
|
|
80
|
+
continue;
|
|
81
|
+
scenarios.push({
|
|
82
|
+
id: s.id,
|
|
83
|
+
featureId: f.id,
|
|
84
|
+
optionId: s.optionId,
|
|
85
|
+
name: clipText(s.name, T.name),
|
|
86
|
+
steps: s.steps.slice(0, L.steps).map((st, index) => ({ id: st.id, index, caption: clipText(st.caption, T.caption), explain: st.explain === undefined ? null : clipText(st.explain, T.explain), ruleIds: st.ruleIds.slice(0, L.ruleIds) })),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// 元素:参与方案能看到的所有画面(发布视图 `@路径`、方案的路径画面与层级画面)里的作者 id;同一个 id 取第一次出现的标签
|
|
92
|
+
const elements = new Map();
|
|
93
|
+
const visit = (n) => {
|
|
94
|
+
if (n.type !== '#text' && AUTHOR_ELEMENT_ID.test(n.id) && !elements.has(n.id))
|
|
95
|
+
elements.set(n.id, clipText(nodeLabel(n), T.label));
|
|
96
|
+
for (const c of n.children ?? [])
|
|
97
|
+
visit(c);
|
|
98
|
+
};
|
|
99
|
+
for (const scene of Object.values(project.scenes))
|
|
100
|
+
if (scene.optionId === null || included.has(scene.optionId))
|
|
101
|
+
visit(scene.root);
|
|
102
|
+
return {
|
|
103
|
+
v: REVIEW_MANIFEST_VERSION,
|
|
104
|
+
mode,
|
|
105
|
+
features: features.slice(0, L.features),
|
|
106
|
+
scenarios: scenarios.slice(0, L.scenarios),
|
|
107
|
+
elements: [...elements].slice(0, L.elements).map(([id, label]) => ({ id, label })),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** 序列化后的 UTF-8 字节数(请求体里就是这份 JSON)。 */
|
|
111
|
+
export function reviewManifestBytes(manifest) {
|
|
112
|
+
return new TextEncoder().encode(JSON.stringify(manifest)).length;
|
|
113
|
+
}
|
|
114
|
+
/** 超过 512 KiB 时报错:减少规则、问题、步骤说明后重试。 */
|
|
115
|
+
export function assertReviewManifestSize(manifest) {
|
|
116
|
+
const actualBytes = reviewManifestBytes(manifest);
|
|
117
|
+
if (actualBytes > REVIEW_MANIFEST_MAX_BYTES)
|
|
118
|
+
throw new JoploError('EXPORT_FAILED', `The review manifest is ${actualBytes} bytes, over the 512 KiB limit (${REVIEW_MANIFEST_MAX_BYTES} bytes). Shorten or remove rules, questions, captions, or explanations, then share again; nothing was uploaded`, { details: { maxBytes: REVIEW_MANIFEST_MAX_BYTES, actualBytes } });
|
|
119
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 结构校验(zod)问题 → 作者能直接改的诊断。
|
|
3
|
+
*
|
|
4
|
+
* 不变量:
|
|
5
|
+
* - 定位取路径上最近一个带 `source` 的对象(通常是作者写的 JSX 元素),而不是整份 IR 的根;
|
|
6
|
+
* - 同一个根因(同一源位置、同一代码、同一说明)在多个画面 / 层级里展开时只输出一条,
|
|
7
|
+
* 说明后面附 “affects N views”,`affects` 列出受影响的画面或对象(新增字段,旧字段不变);
|
|
8
|
+
* - `when` 收到普通值(布尔、数字、字符串、null)时给出专门的 INVALID_CONDITION 说明,其余仍是 INVALID_SCHEMA。
|
|
9
|
+
* 计数语义:合并后的每一条只算一个 error。
|
|
10
|
+
*/
|
|
11
|
+
import type { Diagnostic } from './result.js';
|
|
12
|
+
export type SchemaIssue = {
|
|
13
|
+
readonly path: readonly PropertyKey[];
|
|
14
|
+
readonly message: string;
|
|
15
|
+
};
|
|
16
|
+
/** `when` 只接受条件表达式:说明里给出可直接照抄的写法。 */
|
|
17
|
+
export declare function whenMessage(value: unknown, element?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* root 是被校验的对象(编译中的 IR),issues 是 zod 的问题列表。
|
|
20
|
+
* rel 把绝对源路径转成项目相对路径(compile 传入;validate 读的 IR 已是相对路径)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function schemaDiagnostics(root: unknown, issues: readonly SchemaIssue[], opts?: {
|
|
23
|
+
limit?: number;
|
|
24
|
+
rel?: (s: string) => string | undefined;
|
|
25
|
+
}): Diagnostic[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** `when` 只接受条件表达式:说明里给出可直接照抄的写法。 */
|
|
2
|
+
export function whenMessage(value, element) {
|
|
3
|
+
const shown = typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
4
|
+
return `${element ? `<${element}> ` : ''}when received a plain ${value === null ? 'null' : typeof value} (${shown}); when accepts only condition expressions bound to state, `
|
|
5
|
+
+ `e.g. when={$.ui.sent}, when={not($.ui.sent)}, when={eq($.ui.mode, 'code')}. `
|
|
6
|
+
+ `For a value already known while writing, render conditionally in your own code instead: {showHint && <Alert …/>}`;
|
|
7
|
+
}
|
|
8
|
+
const isPlain = (v) => v === null || ['boolean', 'number', 'string'].includes(typeof v);
|
|
9
|
+
/**
|
|
10
|
+
* root 是被校验的对象(编译中的 IR),issues 是 zod 的问题列表。
|
|
11
|
+
* rel 把绝对源路径转成项目相对路径(compile 传入;validate 读的 IR 已是相对路径)。
|
|
12
|
+
*/
|
|
13
|
+
export function schemaDiagnostics(root, issues, opts = {}) {
|
|
14
|
+
const groups = new Map();
|
|
15
|
+
for (const issue of issues) {
|
|
16
|
+
const path = issue.path.map(String);
|
|
17
|
+
let value = root;
|
|
18
|
+
let at;
|
|
19
|
+
let element;
|
|
20
|
+
let sourced = -1;
|
|
21
|
+
let reached = true;
|
|
22
|
+
for (let i = 0; i < path.length; i++) {
|
|
23
|
+
if (value && typeof value === 'object') {
|
|
24
|
+
const record = value;
|
|
25
|
+
if (typeof record.source === 'string') {
|
|
26
|
+
at = record.source;
|
|
27
|
+
sourced = i;
|
|
28
|
+
element = typeof record.type === 'string' && !record.type.startsWith('#') ? record.type : undefined;
|
|
29
|
+
}
|
|
30
|
+
value = record[path[i]];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
reached = false;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// 叶子本身带 source(例如整条 Step 不合法)时也用它
|
|
38
|
+
if (reached && value && typeof value === 'object' && typeof value.source === 'string') {
|
|
39
|
+
at = value.source;
|
|
40
|
+
sourced = path.length;
|
|
41
|
+
element = undefined;
|
|
42
|
+
}
|
|
43
|
+
const where = at ? (opts.rel?.(at) ?? at) : undefined;
|
|
44
|
+
const local = sourced >= 0 ? path.slice(sourced).join('.') : '';
|
|
45
|
+
const full = path.join('.') || 'project';
|
|
46
|
+
const condition = reached && path.at(-1) === 'when' && isPlain(value) && sourced === path.length - 1;
|
|
47
|
+
const code = condition ? 'INVALID_CONDITION' : 'INVALID_SCHEMA';
|
|
48
|
+
// 有源位置时说明只写元素内的相对路径,这样展开到多个画面的同一错误说明相同、能合并
|
|
49
|
+
const message = condition ? whenMessage(value, element) : where ? `${element ? `<${element}> ` : ''}${local || full}: ${issue.message}` : `${full}: ${issue.message}`;
|
|
50
|
+
// 受影响的对象:画面 id(scenes.<id>)或表名 + id(options.<id> 等)
|
|
51
|
+
const scope = path.length >= 2 ? (path[0] === 'scenes' ? path[1] : `${path[0]}.${path[1]}`) : full;
|
|
52
|
+
const key = JSON.stringify([code, where ?? full, message]);
|
|
53
|
+
const group = groups.get(key);
|
|
54
|
+
if (group) {
|
|
55
|
+
if (!group.affects.includes(scope))
|
|
56
|
+
group.affects.push(scope);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
groups.set(key, { diagnostic: { severity: 'error', code, message, source: 'schema', ...(where ? { at: where } : {}) }, affects: [scope] });
|
|
60
|
+
}
|
|
61
|
+
const out = [...groups.values()].map(({ diagnostic, affects }) => affects.length > 1 ? { ...diagnostic, message: `${diagnostic.message} (affects ${affects.length} views)`, affects } : diagnostic);
|
|
62
|
+
return opts.limit === undefined ? out : out.slice(0, opts.limit);
|
|
63
|
+
}
|