@joplo-app/core 0.2.4 → 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.js +3 -2
- package/dist/guide.d.ts +5 -5
- package/dist/guide.js +97 -12
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/result.d.ts +2 -0
- package/dist/schema-issues.d.ts +25 -0
- package/dist/schema-issues.js +63 -0
- package/dist/schema.d.ts +4 -4
- package/dist/validate.js +4 -14
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 技能的唯一模板(D64):
|
|
3
|
+
* - 仓库根目录的官方技能 `skills/<name>/SKILL.md`(`npx skills add Joplo-app/Joplo` 安装),
|
|
4
|
+
* - `joplo skill install` 写进项目的 `.claude/skills/<name>/SKILL.md` 与 AGENTS.md 托管段,
|
|
5
|
+
* - `joplo skill`(无主题)总览开头的心智模型与起步顺序,
|
|
6
|
+
* 都由这里生成。版本标记与哈希由 CLI 加上(packages/cli/src/skill.ts,需要 node:crypto)。
|
|
7
|
+
* 原则:薄技能——只放心智模型、起步顺序和最常见的坑,具体 API 指向 `npx joplo skill <主题>`(与项目安装的版本一致)。
|
|
8
|
+
*/
|
|
9
|
+
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
|
+
export declare const MENTAL_MODEL: readonly ["Joplo is a player for pre-declared scenarios, not a free-form app prototype.", "Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.", "Clicking the highlighted element plays the next declared step; other clicks only show a hint.", "Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.", "Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published."];
|
|
11
|
+
/** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
|
|
12
|
+
export declare const START_ORDER: readonly ["Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.", "With minimal code, write one happy path and one error-and-recovery scenario.", "Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.", "Extend to every option and every case agreed with the user; run check until 0 errors.", "Give the user the board URL and a short list of what to check, then wait for their feedback."];
|
|
13
|
+
/** 最常见的坑:一句话 + 详细主题。 */
|
|
14
|
+
export declare const PITFALLS: readonly [readonly ["when takes a condition, not a boolean: when={eq($.ui.mode, 'code')}, never when={mode === 'code'}; for values known while writing use {flag && <X/>}", "authoring"], readonly ["Only catalog components and the listed HTML tags exist; <br/> is UNKNOWN_COMPONENT, so write 'Line 1\\nLine 2' inside <Text>", "components"], readonly ["Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE", "check"], readonly ["No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)", "authoring"], readonly ["Full-height layouts squeeze tables and forms: rows exist in the DOM but are cut off on screen; show 5–8 rows or move the table to its own layer", "demo"], readonly ["Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key; layer= is ignored); wait for rendering before screenshots", "demo"], readonly ["Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user", "cases"], readonly ["Never share or deploy without the user's go-ahead; free share links expire after 1 hour", "publish"]];
|
|
15
|
+
export type AgentSkill = {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
body: string;
|
|
19
|
+
};
|
|
20
|
+
/** 官方技能与 `joplo skill install` 共用的两个技能(顺序即写入顺序)。 */
|
|
21
|
+
export declare function agentSkills(): AgentSkill[];
|
|
22
|
+
/** SKILL.md 正文(不含版本标记):frontmatter + 正文,以换行结尾。 */
|
|
23
|
+
export declare function skillMarkdown(skill: AgentSkill): string;
|
|
24
|
+
/** AGENTS.md 托管段(不含起止标记):心智模型、起步顺序、最常见的坑,细节指向主题。 */
|
|
25
|
+
export declare function agentsBlock(): string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 技能的唯一模板(D64):
|
|
3
|
+
* - 仓库根目录的官方技能 `skills/<name>/SKILL.md`(`npx skills add Joplo-app/Joplo` 安装),
|
|
4
|
+
* - `joplo skill install` 写进项目的 `.claude/skills/<name>/SKILL.md` 与 AGENTS.md 托管段,
|
|
5
|
+
* - `joplo skill`(无主题)总览开头的心智模型与起步顺序,
|
|
6
|
+
* 都由这里生成。版本标记与哈希由 CLI 加上(packages/cli/src/skill.ts,需要 node:crypto)。
|
|
7
|
+
* 原则:薄技能——只放心智模型、起步顺序和最常见的坑,具体 API 指向 `npx joplo skill <主题>`(与项目安装的版本一致)。
|
|
8
|
+
*/
|
|
9
|
+
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
|
+
export const MENTAL_MODEL = [
|
|
11
|
+
'Joplo is a player for pre-declared scenarios, not a free-form app prototype.',
|
|
12
|
+
'Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.',
|
|
13
|
+
'Clicking the highlighted element plays the next declared step; other clicks only show a hint.',
|
|
14
|
+
'Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.',
|
|
15
|
+
'Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published.',
|
|
16
|
+
];
|
|
17
|
+
/** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
|
|
18
|
+
export const START_ORDER = [
|
|
19
|
+
'Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.',
|
|
20
|
+
'With minimal code, write one happy path and one error-and-recovery scenario.',
|
|
21
|
+
'Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.',
|
|
22
|
+
'Extend to every option and every case agreed with the user; run check until 0 errors.',
|
|
23
|
+
'Give the user the board URL and a short list of what to check, then wait for their feedback.',
|
|
24
|
+
];
|
|
25
|
+
/** 最常见的坑:一句话 + 详细主题。 */
|
|
26
|
+
export const PITFALLS = [
|
|
27
|
+
['when takes a condition, not a boolean: when={eq($.ui.mode, \'code\')}, never when={mode === \'code\'}; for values known while writing use {flag && <X/>}', 'authoring'],
|
|
28
|
+
['Only catalog components and the listed HTML tags exist; <br/> is UNKNOWN_COMPONENT, so write \'Line 1\\nLine 2\' inside <Text>', 'components'],
|
|
29
|
+
['Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE', 'check'],
|
|
30
|
+
['No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)', 'authoring'],
|
|
31
|
+
['Full-height layouts squeeze tables and forms: rows exist in the DOM but are cut off on screen; show 5–8 rows or move the table to its own layer', 'demo'],
|
|
32
|
+
['Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key; layer= is ignored); wait for rendering before screenshots', 'demo'],
|
|
33
|
+
['Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user', 'cases'],
|
|
34
|
+
['Never share or deploy without the user\'s go-ahead; free share links expire after 1 hour', 'publish'],
|
|
35
|
+
];
|
|
36
|
+
/** 中文触发词:技能 description 里的匹配文本,不是 CLI 界面文案(english-output 测试的白名单)。 */
|
|
37
|
+
const ZH_JOPLO = '功能原型、可交互演示、方案对比、给产品 / 设计 / 评审看的演示';
|
|
38
|
+
const ZH_FEEDBACK = '评审有结论了、按评审意见修改演示';
|
|
39
|
+
const JOPLO_DESCRIPTION = `Build clickable, replayable feature demos with Joplo (scripted scenarios in TSX, viewed in a local board) when the user wants a feature prototype, an interactive or clickable demo, an A/B comparison of options or edge cases, or a demo for product, design, or review (${ZH_JOPLO}), including in a repo without joplo.config.ts.`;
|
|
40
|
+
const FEEDBACK_DESCRIPTION = `Apply Joplo review results when reviewers have commented on or decided about a Joplo review link and the user says the review has conclusions or asks to update the demo as reviewed (${ZH_FEEDBACK}); pulls decisions with npx joplo feedback and writes them back into the source.`;
|
|
41
|
+
const list = (items) => items.map((s, i) => `${i + 1}. ${s}`);
|
|
42
|
+
function joploBody() {
|
|
43
|
+
return [
|
|
44
|
+
'# Joplo',
|
|
45
|
+
'',
|
|
46
|
+
...MENTAL_MODEL,
|
|
47
|
+
'',
|
|
48
|
+
'## When to use',
|
|
49
|
+
'- The user wants to think a feature through before building it: a prototype, clickable demo, A/B options, edge cases, or a walkthrough for product, design, or review.',
|
|
50
|
+
'- Not for production UI code, real backends, or demos where viewers type free input.',
|
|
51
|
+
'',
|
|
52
|
+
'## Workflow',
|
|
53
|
+
'1. No joplo.config.ts yet: npx joplo@latest init <dir>, then npm install in that directory (versions are pinned). In an existing Joplo project, use its installed npx joplo.',
|
|
54
|
+
...list(START_ORDER).map(line => line.replace(/^(\d+)/, (_, n) => String(Number(n) + 1))),
|
|
55
|
+
`${START_ORDER.length + 2}. After the user agrees: npx joplo share --format json (picked options), or npx joplo share --review for reviewers comparing every option. Apply review results with the joplo-feedback skill.`,
|
|
56
|
+
'',
|
|
57
|
+
'## Common pitfalls',
|
|
58
|
+
...PITFALLS.map(([text, topic]) => `- ${text}. See npx joplo skill ${topic}.`),
|
|
59
|
+
'',
|
|
60
|
+
'Exact APIs: npx joplo skill <topic> prints guidance matching the installed version (authoring, demo, components, cases, check, selection, publish). Run npx joplo skill for the overview.',
|
|
61
|
+
'After the user Alt+clicks a board element, run npx joplo selection and edit only that location.',
|
|
62
|
+
].join('\n');
|
|
63
|
+
}
|
|
64
|
+
function feedbackBody() {
|
|
65
|
+
return [
|
|
66
|
+
'# Joplo review feedback',
|
|
67
|
+
'',
|
|
68
|
+
'Reviewers open the review link from npx joplo share --review, compare every option, comment, and the owner decides. Decisions come back to you; apply them to the source.',
|
|
69
|
+
'',
|
|
70
|
+
'## When to use',
|
|
71
|
+
'- The user says the review has conclusions, or asks you to update the Joplo demo according to the review.',
|
|
72
|
+
'- Requires a project that was shared (.joplo/cloud.json) or a share id from the user.',
|
|
73
|
+
'',
|
|
74
|
+
'## Steps',
|
|
75
|
+
'1. npx joplo feedback --format json. It reads the review share in .joplo/cloud.json, else the main share; pass --share <id> for another. data.decisions are decisions not yet applied (id, kind, featureId, targetId, note); data.comments are unresolved comments with scenario, step, stepId, and element.',
|
|
76
|
+
'2. Apply each decision to the source:',
|
|
77
|
+
' - pick: set pick in features/<feature>/feature.ts to the option file name (targetId without the "<feature>." prefix).',
|
|
78
|
+
' - confirm_rule: set that rule to origin: \'user\', status: \'confirmed\'.',
|
|
79
|
+
' - reject_rule: rewrite the rule as the note says. If the note does not say what to do instead, set status: \'conflict\' and ask the user; do not guess.',
|
|
80
|
+
' - answer: delete the question and add a rule stating the answer with origin: \'user\', status: \'confirmed\'.',
|
|
81
|
+
' - Comments are discussion input only; change the source from a comment only when the user asks.',
|
|
82
|
+
'3. npx joplo check until 0 errors.',
|
|
83
|
+
'4. Republish when the user wants: npx joplo share --review --format json updates the review version (every option); npx joplo share --format json publishes picked options only.',
|
|
84
|
+
'5. npx joplo feedback --applied <decision ids, comma-separated> --ref <git commit sha>. Mark only decisions you actually wrote back.',
|
|
85
|
+
'',
|
|
86
|
+
'AUTH_REQUIRED or AUTH_EXPIRED (exit 3): ask the user to run npx joplo login in their own terminal; never log in or out for them.',
|
|
87
|
+
'Details: npx joplo skill publish (Review and feedback).',
|
|
88
|
+
].join('\n');
|
|
89
|
+
}
|
|
90
|
+
/** 官方技能与 `joplo skill install` 共用的两个技能(顺序即写入顺序)。 */
|
|
91
|
+
export function agentSkills() {
|
|
92
|
+
return [
|
|
93
|
+
{ name: 'joplo', description: JOPLO_DESCRIPTION, body: joploBody() },
|
|
94
|
+
{ name: 'joplo-feedback', description: FEEDBACK_DESCRIPTION, body: feedbackBody() },
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/** SKILL.md 正文(不含版本标记):frontmatter + 正文,以换行结尾。 */
|
|
98
|
+
export function skillMarkdown(skill) {
|
|
99
|
+
return `---\nname: ${skill.name}\ndescription: ${skill.description}\n---\n${skill.body}\n`;
|
|
100
|
+
}
|
|
101
|
+
/** AGENTS.md 托管段(不含起止标记):心智模型、起步顺序、最常见的坑,细节指向主题。 */
|
|
102
|
+
export function agentsBlock() {
|
|
103
|
+
return [
|
|
104
|
+
'## Joplo',
|
|
105
|
+
'This project designs features as Joplo demos (joplo.config.ts). Read npx joplo skill first, then the relevant topics: authoring for pages/options/scenarios, components, cases before asking about edge cases, demo for layers, shots, traces, and captions.',
|
|
106
|
+
`Mental model: ${MENTAL_MODEL.slice(0, 4).join(' ')}`,
|
|
107
|
+
`Start: ${START_ORDER.map((s, i) => `(${i + 1}) ${s}`).join(' ')}`,
|
|
108
|
+
'Pitfalls:',
|
|
109
|
+
...PITFALLS.slice(0, 6).map(([text, topic]) => `- ${text} (npx joplo skill ${topic}).`),
|
|
110
|
+
'After editing, run npx joplo check. After a board selection, run npx joplo selection and edit only that location. Review results: npx joplo feedback (npx joplo skill publish).',
|
|
111
|
+
].join('\n');
|
|
112
|
+
}
|
package/dist/catalog.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
|
|
7
7
|
* 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
|
|
8
8
|
*/
|
|
9
|
+
export declare const HTML_TAGS: readonly string[];
|
|
9
10
|
export declare const COMPONENT_TYPES: readonly ["AppShell", "AppShell.Header", "AppShell.Navbar", "AppShell.Main", "AppShell.Aside", "AppShell.Footer", "Container", "Stack", "Group", "Flex", "Grid", "Grid.Col", "SimpleGrid", "Center", "Box", "Space", "Paper", "Card", "Card.Section", "Divider", "ScrollArea", "Title", "Text", "Code", "Kbd", "Blockquote", "List", "List.Item", "Badge", "Avatar", "Image", "ThemeIcon", "Indicator", "Timeline", "Timeline.Item", "Table", "Table.Thead", "Table.Tbody", "Table.Tr", "Table.Th", "Table.Td", "DataTable", "Accordion", "Accordion.Item", "Accordion.Panel", "Radio", "Tabs.List", "Tabs.Panel", "Breadcrumbs", "Stepper", "Stepper.Step", "Alert", "Loader", "Progress", "RingProgress", "Skeleton", "Notification", "Modal", "Drawer", "ChatMessage", "ToolCall", "Thinking", "Artifact", "Email", "DataCard", "StateFlow", "Terminal", "Terminal.Command", "Terminal.Output", "Phone", "Diagram", "Diagram.Group", "Diagram.Node", "Diagram.Edge", "div", "span", "p", "h1", "h2", "h3", "h4", "main", "section", "header", "footer", "nav", "aside", "ul", "ol", "li", "strong", "em", "small", "code", "Placeholder", "Custom", "#text", "Button", "ActionIcon", "CloseButton", "Anchor", "a", "NavLink", "Burger", "TextInput", "PasswordInput", "NumberInput", "Textarea", "Select", "MultiSelect", "Checkbox", "Radio.Group", "Switch", "SegmentedControl", "FileInput", "Tabs", "Tabs.Tab", "Accordion.Control", "Pagination", "PromptInput", "Terminal.Input", "Artifact.Ref"];
|
|
10
11
|
export type ComponentType = (typeof COMPONENT_TYPES)[number];
|
|
11
12
|
export declare const INTERACTIVE_TYPES: ReadonlySet<string>;
|
package/dist/catalog.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
|
|
7
7
|
* 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
|
|
8
8
|
*/
|
|
9
|
+
/** HTML 兜底标签(不可操作);`a` 在 INTERACTIVE 里。目录之外的标签(br、img、button、input…)报 UNKNOWN_COMPONENT。 */
|
|
10
|
+
const HTML = ['div', 'span', 'p', 'h1', 'h2', 'h3', 'h4', 'main', 'section', 'header', 'footer', 'nav', 'aside', 'ul', 'ol', 'li', 'strong', 'em', 'small', 'code'];
|
|
11
|
+
export const HTML_TAGS = [...HTML, 'a'];
|
|
9
12
|
/** 布局、展示与容器:不可操作。 */
|
|
10
13
|
const STRUCTURE = [
|
|
11
14
|
// 布局
|
|
@@ -29,7 +32,7 @@ const STRUCTURE = [
|
|
|
29
32
|
// 架构图(Joplo 自有,D41):节点与连线的 state 绑定 $.ui,由 flow 步骤驱动
|
|
30
33
|
'Diagram', 'Diagram.Group', 'Diagram.Node', 'Diagram.Edge',
|
|
31
34
|
// HTML 兜底
|
|
32
|
-
|
|
35
|
+
...HTML,
|
|
33
36
|
// Joplo
|
|
34
37
|
'Placeholder', // props: label, h —— 图片/图表等占位
|
|
35
38
|
'Custom', // props: kind —— 逃生口:目录没有的组件,渲染为带说明的占位框
|
package/dist/compile.js
CHANGED
|
@@ -11,6 +11,7 @@ import { isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
|
11
11
|
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER, INTERACTIVE_TYPES, PAGE_LAYER, matchChoice, nodeLabel } from "./catalog.js";
|
|
12
12
|
import { choicesOf, commonPrefix } from "./player.js";
|
|
13
13
|
import { LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
14
|
+
import { schemaDiagnostics } from "./schema-issues.js";
|
|
14
15
|
const KNOWN = new Set(COMPONENT_TYPES);
|
|
15
16
|
const OVERLAY = 'overlay';
|
|
16
17
|
const MOCK_LABEL = { success: 'Mock success', failure: 'Mock failure', denied: 'Mock permission denied', other: 'Mock' };
|
|
@@ -552,8 +553,8 @@ export function compile(src, mode) {
|
|
|
552
553
|
return { project: null, diagnostics: diags };
|
|
553
554
|
const parsed = Project.safeParse(out);
|
|
554
555
|
if (!parsed.success) {
|
|
555
|
-
|
|
556
|
-
|
|
556
|
+
// 同一根因(共享的 JSX)在多个画面展开时合并成一条,定位到作者元素(schema-issues.ts)
|
|
557
|
+
diags.push(...schemaDiagnostics(out, parsed.error.issues, { limit: 20, rel }));
|
|
557
558
|
return { project: null, diagnostics: diags };
|
|
558
559
|
}
|
|
559
560
|
return { project: parsed.data, diagnostics: diags };
|
package/dist/guide.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export declare const SKILL_TOPICS: readonly [{
|
|
2
2
|
readonly name: "authoring";
|
|
3
|
-
readonly description: "
|
|
3
|
+
readonly description: "Mental model, first steps, page / option / flow syntax, when conditions, a form example";
|
|
4
4
|
}, {
|
|
5
5
|
readonly name: "demo";
|
|
6
|
-
readonly description: "Layers, shots,
|
|
6
|
+
readonly description: "Layers, shots, captions, full-height layout, deep links, and screenshots";
|
|
7
7
|
}, {
|
|
8
8
|
readonly name: "components";
|
|
9
|
-
readonly description: "Component catalog
|
|
9
|
+
readonly description: "Component catalog, supported HTML tags, line breaks, and props";
|
|
10
10
|
}, {
|
|
11
11
|
readonly name: "cases";
|
|
12
12
|
readonly description: "Case dimensions: ask the user before starting";
|
|
13
13
|
}, {
|
|
14
14
|
readonly name: "check";
|
|
15
|
-
readonly description: "Read diagnostics and fix the indicated file and line";
|
|
15
|
+
readonly description: "Read diagnostics, UNBOUND_INTERACTIVE, and fix the indicated file and line";
|
|
16
16
|
}, {
|
|
17
17
|
readonly name: "selection";
|
|
18
18
|
readonly description: "Edit only the element selected by the user in the board";
|
|
19
19
|
}, {
|
|
20
20
|
readonly name: "publish";
|
|
21
|
-
readonly description: "pick, build,
|
|
21
|
+
readonly description: "pick, build, share, review version, feedback write-back, deployment";
|
|
22
22
|
}];
|
|
23
23
|
export type SkillTopic = (typeof SKILL_TOPICS)[number]['name'];
|
|
24
24
|
/** CLI 传入其 package.json 版本;行数来自同一次生成的主题正文。 */
|
package/dist/guide.js
CHANGED
|
@@ -1,14 +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";
|
|
3
4
|
import { LAYER_ICONS } from "./schema.js";
|
|
4
5
|
export const SKILL_TOPICS = [
|
|
5
|
-
{ name: 'authoring', description: '
|
|
6
|
-
{ name: 'demo', description: 'Layers, shots,
|
|
7
|
-
{ 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' },
|
|
8
9
|
{ name: 'cases', description: 'Case dimensions: ask the user before starting' },
|
|
9
|
-
{ 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' },
|
|
10
11
|
{ name: 'selection', description: 'Edit only the element selected by the user in the board' },
|
|
11
|
-
{ name: 'publish', description: 'pick, build,
|
|
12
|
+
{ name: 'publish', description: 'pick, build, share, review version, feedback write-back, deployment' },
|
|
12
13
|
];
|
|
13
14
|
const related = {
|
|
14
15
|
authoring: ['demo', 'components', 'cases', 'check', 'selection', 'publish'],
|
|
@@ -23,6 +24,13 @@ const related = {
|
|
|
23
24
|
export function skillIndex(version, docs) {
|
|
24
25
|
return [
|
|
25
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):',
|
|
26
34
|
...SKILL_TOPICS.map(t => ` ${t.name.padEnd(11)} ${t.description} ${skillTopic(t.name, docs).trimEnd().split('\n').length} lines`),
|
|
27
35
|
'Usage: npx joplo skill <topic> Install for agents: npx joplo skill install',
|
|
28
36
|
'',
|
|
@@ -51,6 +59,12 @@ function componentTopic(docs = {}) {
|
|
|
51
59
|
'Import components from @joplo-app/kit/ui. Names below come from the current compiler catalog; do not invent components.',
|
|
52
60
|
'Prop hints follow names when available; otherwise only names are listed. Write HTML tags directly in JSX; do not import them from ui.',
|
|
53
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
|
+
'',
|
|
54
68
|
'## Component catalog',
|
|
55
69
|
...names.map(name => `- ${name}${Object.hasOwn(docs, name) && docs[name]?.trim() ? `: ${docs[name].replace(/\s+/g, ' ').trim()}` : ''}`),
|
|
56
70
|
'',
|
|
@@ -61,13 +75,21 @@ function componentTopic(docs = {}) {
|
|
|
61
75
|
'',
|
|
62
76
|
`Joplo props: ${JOPLO_PROPS.join(', ')}; disabled is the component disable prop.`,
|
|
63
77
|
'when controls visibility; disabledReason explains disabling; unmodeled marks behavior not modeled by this prototype; note is an authoring note.',
|
|
64
|
-
'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.',
|
|
65
80
|
'See authoring for bindings, conditions, and steps; check for component error fixes.',
|
|
66
81
|
].join('\n');
|
|
67
82
|
}
|
|
68
83
|
const CONTENT = {
|
|
69
84
|
authoring: `# Joplo authoring: authoring
|
|
70
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
|
+
|
|
71
93
|
Describe designs in TS/TSX. Source files are authoritative; Git manages versions. The board and published site consume compiled IR.
|
|
72
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.
|
|
73
95
|
|
|
@@ -107,17 +129,51 @@ Read only the topics needed, usually one or two at a time. See components for co
|
|
|
107
129
|
- uses('rule_key', ...): link rules from this option or feature.
|
|
108
130
|
|
|
109
131
|
## Bindings and conditions
|
|
110
|
-
- $.ui.x / $.data.x / $.inputs.x bind whole values; arbitrary expressions are not evaluated.
|
|
111
|
-
-
|
|
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>.
|
|
112
134
|
- not(x), eq(x, value), neq(x, value), empty(x), notEmpty(x), oneOf(x, values), and(...xs), or(...xs).
|
|
113
135
|
- Overlays: <Modal id="dlg" opened={$.ui.open} title="…">; Drawer works the same way. Only opened controls visibility.
|
|
114
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
|
+
|
|
115
144
|
## Layout and responsiveness (Mantine names and props; no className)
|
|
116
145
|
- Use Stack / Group / SimpleGrid / Grid props: <Group justify="space-between">, <SimpleGrid cols={{ base: 1, md: 3 }}>.
|
|
117
146
|
- Use responsive objects { base, xs, sm, md, lg, xl }, or visibleFrom="sm" / hiddenFrom="sm". AppShell collapses navigation below navbar.breakpoint.
|
|
118
147
|
- Set input labels directly: <TextInput id="email" label="Email"/>. Auto captions use them.
|
|
119
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.
|
|
120
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
|
+
|
|
121
177
|
## Rules and boundaries
|
|
122
178
|
- rule('Constraint', { origin?, status?, cases?: ['happy'], elements?: ['invite'] }).
|
|
123
179
|
- origin: user/project_material/ai_assumption/code_observed/feedback; default ai_assumption.
|
|
@@ -175,6 +231,18 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
|
|
|
175
231
|
<Group><PromptInput id="prompt"/><Button id="send">Send</Button></Group></Stack></Grid.Col></Grid>
|
|
176
232
|
- The same applies to placeholders and artifacts: use h="100%" on Placeholder; Artifact fills its container by default.
|
|
177
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.
|
|
178
246
|
|
|
179
247
|
## Transition cards, roles, and Agent output (D56)
|
|
180
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.
|
|
@@ -205,6 +273,7 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
|
|
|
205
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.
|
|
206
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).
|
|
207
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.
|
|
208
277
|
- Example themes/brand.css:
|
|
209
278
|
:root {
|
|
210
279
|
--jp-font: "Inter", system-ui, sans-serif;
|
|
@@ -289,6 +358,8 @@ Pick relevant cases to ask the user before starting. Do not include every preset
|
|
|
289
358
|
- Each option uses flow(..., { cases: ['happy'] }) to reference the shared cases for comparison.
|
|
290
359
|
- A case with a scenario is automatically \`expressed\`; one with neither a scenario nor a declaration is \`missing\`.
|
|
291
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.
|
|
292
363
|
|
|
293
364
|
## Declare coverage without a scenario
|
|
294
365
|
Coverage status values: \`expressed\`, \`undecided\`, \`missing\`, \`not_applicable\`, \`excluded\`.
|
|
@@ -309,6 +380,8 @@ The whole project still compiles. Option filtering does not hide project compila
|
|
|
309
380
|
\`file:line:column severity CODE message\`
|
|
310
381
|
Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Interactive element has no demo step.
|
|
311
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].
|
|
312
385
|
- error exits 1; usage errors exit 2; warning/info only exits 0.
|
|
313
386
|
- The last line totals error, warning, info. Run check again after fixing.
|
|
314
387
|
|
|
@@ -338,7 +411,8 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
338
411
|
- UNKNOWN_DIAGRAM_NODE: Diagram.Edge from/to does not reference a node in this Diagram. Correct the endpoint ids.
|
|
339
412
|
- ELEMENT_PROP: A component prop contains JSX. Use strings for icons, such as leftSection="+", and children for content.
|
|
340
413
|
- ASSUMPTION_CONFIRMED: Keep AI assumptions \`pending\`. After user confirmation, record the actual origin; do not change only status.
|
|
341
|
-
- 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.
|
|
342
416
|
- DISABLED_WITHOUT_REASON: Add disabledReason explaining why the element cannot be used.
|
|
343
417
|
- CASE_NOT_COVERED: Add a scenario or declare coverage truthfully. Ask about missing behavior first.
|
|
344
418
|
- EXPRESSED_WITHOUT_SCENARIO / COVERAGE_WITHOUT_REASON: Add a scenario or a reason for \`not_applicable\`/\`excluded\`.
|
|
@@ -351,6 +425,13 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
351
425
|
- ALREADY_COMPLETED / NOTHING_TO_GO_BACK: Fix steps after done, or add route navigation before back.
|
|
352
426
|
- LOAD_FAILED / WRONG_EXPORT / INVALID_SCHEMA: Follow the message to fix imports, default exports, or field structure.
|
|
353
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
|
+
|
|
354
435
|
When the user points to a stage element, read selection first for its exact location.`,
|
|
355
436
|
selection: `# Joplo selection: selection
|
|
356
437
|
|
|
@@ -413,6 +494,7 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
|
|
|
413
494
|
- Pro share updates the same-server link in .joplo/cloud.json; --new creates another link and --title sets its title.
|
|
414
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.
|
|
415
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.
|
|
416
498
|
- maxUploadBytes limits only newly uploaded cloud blobs. The CLI prechecks maxTotalBytes and maxFiles. TOO_LARGE details.kind distinguishes upload / total / files.
|
|
417
499
|
- Credentials are stored only in JOPLO_HOME/credentials.json (default ~/.joplo). Never copy them into a project, print them, or commit them.
|
|
418
500
|
- Cloud commands accept --server <url>, overriding JOPLO_CLOUD_URL; the default is https://cloud.joplo.app.
|
|
@@ -420,7 +502,7 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
|
|
|
420
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.
|
|
421
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.
|
|
422
504
|
|
|
423
|
-
## Review and feedback
|
|
505
|
+
## Review and feedback (the joplo-feedback skill has the same steps)
|
|
424
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.
|
|
425
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.
|
|
426
508
|
- Apply each decision to the source, then run npx joplo check:
|
|
@@ -429,7 +511,10 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
|
|
|
429
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.
|
|
430
512
|
- answer: delete the question and add a rule with origin: 'user' (status: 'confirmed') stating the answer.
|
|
431
513
|
- Comments are input for discussion only; do not change the source from a comment unless the user asks.
|
|
432
|
-
- 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
|
|
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.`,
|
|
433
518
|
};
|
|
434
519
|
function distance(a, b) {
|
|
435
520
|
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +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';
|
|
9
10
|
export * from './embed.js';
|
|
10
11
|
export * from './features.js';
|
|
11
12
|
export * from './review.js';
|
|
13
|
+
export * from './agent-skill.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +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";
|
|
9
10
|
export * from "./embed.js";
|
|
10
11
|
export * from "./features.js";
|
|
11
12
|
export * from "./review.js";
|
|
13
|
+
export * from "./agent-skill.js";
|
package/dist/result.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -206,12 +206,12 @@ export declare const Step: z.ZodObject<{
|
|
|
206
206
|
caption: z.ZodString;
|
|
207
207
|
captionAuto: z.ZodOptional<z.ZodObject<{
|
|
208
208
|
kind: z.ZodEnum<{
|
|
209
|
+
check: "check";
|
|
209
210
|
click: "click";
|
|
210
211
|
type: "type";
|
|
211
212
|
select: "select";
|
|
212
213
|
press: "press";
|
|
213
214
|
back: "back";
|
|
214
|
-
check: "check";
|
|
215
215
|
uncheck: "uncheck";
|
|
216
216
|
switch_on: "switch_on";
|
|
217
217
|
switch_off: "switch_off";
|
|
@@ -350,12 +350,12 @@ export declare const Scenario: z.ZodObject<{
|
|
|
350
350
|
caption: z.ZodString;
|
|
351
351
|
captionAuto: z.ZodOptional<z.ZodObject<{
|
|
352
352
|
kind: z.ZodEnum<{
|
|
353
|
+
check: "check";
|
|
353
354
|
click: "click";
|
|
354
355
|
type: "type";
|
|
355
356
|
select: "select";
|
|
356
357
|
press: "press";
|
|
357
358
|
back: "back";
|
|
358
|
-
check: "check";
|
|
359
359
|
uncheck: "uncheck";
|
|
360
360
|
switch_on: "switch_on";
|
|
361
361
|
switch_off: "switch_off";
|
|
@@ -592,8 +592,8 @@ export declare const Project: z.ZodObject<{
|
|
|
592
592
|
theme: z.ZodDefault<z.ZodString>;
|
|
593
593
|
themes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
594
594
|
mode: z.ZodEnum<{
|
|
595
|
-
dev: "dev";
|
|
596
595
|
publish: "publish";
|
|
596
|
+
dev: "dev";
|
|
597
597
|
review: "review";
|
|
598
598
|
}>;
|
|
599
599
|
routes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
@@ -788,12 +788,12 @@ export declare const Project: z.ZodObject<{
|
|
|
788
788
|
caption: z.ZodString;
|
|
789
789
|
captionAuto: z.ZodOptional<z.ZodObject<{
|
|
790
790
|
kind: z.ZodEnum<{
|
|
791
|
+
check: "check";
|
|
791
792
|
click: "click";
|
|
792
793
|
type: "type";
|
|
793
794
|
select: "select";
|
|
794
795
|
press: "press";
|
|
795
796
|
back: "back";
|
|
796
|
-
check: "check";
|
|
797
797
|
uncheck: "uncheck";
|
|
798
798
|
switch_on: "switch_on";
|
|
799
799
|
switch_off: "switch_off";
|
package/dist/validate.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Project } from "./schema.js";
|
|
|
3
3
|
import { CAPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, captionLength } from "./catalog.js";
|
|
4
4
|
import { walkNodes, findNode, replay } from "./player.js";
|
|
5
5
|
import { JoploError } from "./result.js";
|
|
6
|
+
import { schemaDiagnostics } from "./schema-issues.js";
|
|
6
7
|
/** IR v2 的确定性校验。源位置缺失(例如手工构造/发布 IR)时回退到配置文件。 */
|
|
7
8
|
export function validate(project, opts = { mode: 'all' }) {
|
|
8
9
|
if (!['structure', 'replay', 'all'].includes(opts.mode))
|
|
@@ -26,20 +27,9 @@ export function validate(project, opts = { mode: 'all' }) {
|
|
|
26
27
|
} });
|
|
27
28
|
const parsed = Project.safeParse(project);
|
|
28
29
|
if (!parsed.success) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (const key of issue.path) {
|
|
33
|
-
if (value && typeof value === 'object') {
|
|
34
|
-
if ('source' in value && typeof value.source === 'string')
|
|
35
|
-
at = value.source;
|
|
36
|
-
value = value[key];
|
|
37
|
-
}
|
|
38
|
-
else
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
emit('error', 'INVALID_SCHEMA', `${issue.path.join('.') || 'project'}: ${issue.message}`, at, undefined, 'schema');
|
|
42
|
-
}
|
|
30
|
+
// 与编译器同一套:定位到最近的作者元素,同一根因合并成一条(schema-issues.ts)
|
|
31
|
+
for (const d of schemaDiagnostics(project, parsed.error.issues))
|
|
32
|
+
diagnostics.push({ ...d, at: d.at ?? 'joplo.config.ts:1:1' });
|
|
43
33
|
return report();
|
|
44
34
|
}
|
|
45
35
|
const p = parsed.data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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.2.
|
|
22
|
+
"@joplo-app/kit": "0.2.5",
|
|
23
23
|
"zod": "4.6.7"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|