mdx-artifacts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +234 -0
  3. package/README.zh-CN.md +129 -0
  4. package/agents/AGENTS.snippet.md +13 -0
  5. package/artifact-docs/examples/commentable-feedback.mdx +126 -0
  6. package/artifact-docs/examples/decision-matrix.mdx +80 -0
  7. package/artifact-docs/examples/layout-composition.mdx +216 -0
  8. package/artifact-docs/examples/streamlit-style-mixed.mdx +183 -0
  9. package/dist/lib/cli/artifact-state.d.ts +27 -0
  10. package/dist/lib/cli/artifact-state.js +115 -0
  11. package/dist/lib/cli/build.d.ts +1 -0
  12. package/dist/lib/cli/build.js +25 -0
  13. package/dist/lib/cli/components.d.ts +3 -0
  14. package/dist/lib/cli/components.js +58 -0
  15. package/dist/lib/cli/config.d.ts +2 -0
  16. package/dist/lib/cli/config.js +36 -0
  17. package/dist/lib/cli/dev.d.ts +1 -0
  18. package/dist/lib/cli/dev.js +24 -0
  19. package/dist/lib/cli/index.d.ts +2 -0
  20. package/dist/lib/cli/index.js +69 -0
  21. package/dist/lib/cli/review.d.ts +33 -0
  22. package/dist/lib/cli/review.js +390 -0
  23. package/dist/lib/cli/scaffold.d.ts +1 -0
  24. package/dist/lib/cli/scaffold.js +56 -0
  25. package/dist/lib/cli/types.d.ts +7 -0
  26. package/dist/lib/cli/types.js +1 -0
  27. package/dist/lib/cli/validate.d.ts +6 -0
  28. package/dist/lib/cli/validate.js +79 -0
  29. package/dist/lib/cli/vite-artifact.d.ts +13 -0
  30. package/dist/lib/cli/vite-artifact.js +213 -0
  31. package/dist/lib/react/components/AnnotatedCode.d.ts +19 -0
  32. package/dist/lib/react/components/AnnotatedCode.js +30 -0
  33. package/dist/lib/react/components/ArtifactState.d.ts +68 -0
  34. package/dist/lib/react/components/ArtifactState.js +286 -0
  35. package/dist/lib/react/components/Callout.d.ts +9 -0
  36. package/dist/lib/react/components/Callout.js +21 -0
  37. package/dist/lib/react/components/CodeBlock.d.ts +10 -0
  38. package/dist/lib/react/components/CodeBlock.js +28 -0
  39. package/dist/lib/react/components/Comments.d.ts +53 -0
  40. package/dist/lib/react/components/Comments.js +613 -0
  41. package/dist/lib/react/components/ComparisonSet.d.ts +24 -0
  42. package/dist/lib/react/components/ComparisonSet.js +30 -0
  43. package/dist/lib/react/components/DecisionMatrix.d.ts +16 -0
  44. package/dist/lib/react/components/DecisionMatrix.js +27 -0
  45. package/dist/lib/react/components/DiffBlock.d.ts +15 -0
  46. package/dist/lib/react/components/DiffBlock.js +24 -0
  47. package/dist/lib/react/components/ExportPanel.d.ts +7 -0
  48. package/dist/lib/react/components/ExportPanel.js +84 -0
  49. package/dist/lib/react/components/InlineText.d.ts +9 -0
  50. package/dist/lib/react/components/InlineText.js +18 -0
  51. package/dist/lib/react/components/Layout.d.ts +44 -0
  52. package/dist/lib/react/components/Layout.js +28 -0
  53. package/dist/lib/react/components/MarkdownBody.d.ts +7 -0
  54. package/dist/lib/react/components/MarkdownBody.js +36 -0
  55. package/dist/lib/react/components/OptionGrid.d.ts +13 -0
  56. package/dist/lib/react/components/OptionGrid.js +21 -0
  57. package/dist/lib/react/components/Section.d.ts +7 -0
  58. package/dist/lib/react/components/Section.js +41 -0
  59. package/dist/lib/react/components/SeverityBadge.d.ts +7 -0
  60. package/dist/lib/react/components/SeverityBadge.js +14 -0
  61. package/dist/lib/react/index.d.ts +33 -0
  62. package/dist/lib/react/index.js +16 -0
  63. package/dist/lib/react/registry.d.ts +24 -0
  64. package/dist/lib/react/registry.js +1002 -0
  65. package/dist/lib/react/styles.css +1417 -0
  66. package/docs/component-protocol.md +273 -0
  67. package/docs/component-taxonomy.md +273 -0
  68. package/docs/design.md +239 -0
  69. package/docs/design.zh-CN.md +217 -0
  70. package/docs/naming.md +123 -0
  71. package/docs/testing.md +138 -0
  72. package/package.json +90 -0
package/docs/design.md ADDED
@@ -0,0 +1,239 @@
1
+ # MDX Artifacts Design Notes
2
+
3
+ ## Language Policy
4
+
5
+ For open source and npm publishing:
6
+
7
+ - Code, types, runtime UI, CLI output, and error messages are English-first.
8
+ - `componentRegistry` is English because it is consumed by the CLI, agents, and future generated docs.
9
+ - `artifact-docs/examples` is English because examples double as public fixtures.
10
+ - `agents/AGENTS.snippet.md` is English so it does not impose a local language preference on user projects.
11
+ - `README.md` is English-first.
12
+ - Chinese notes live in `README.zh-CN.md` and `docs/design.zh-CN.md`.
13
+
14
+ ## Background
15
+
16
+ The value of an HTML artifact is not that it replaces Markdown. Its value is that comparison, tuning, sorting, exporting, and visual explanation workflows can become directly operable interfaces.
17
+
18
+ Asking an agent to generate raw HTML for every artifact has recurring problems:
19
+
20
+ - High token cost.
21
+ - Repeated layout and interaction code.
22
+ - Inconsistent export behavior.
23
+ - Poor diff quality.
24
+ - Throwaway pages rarely become reusable workflow assets.
25
+
26
+ This project keeps MDX as the source format and lets agents call reusable high-level components. The output is a standalone HTML artifact.
27
+
28
+ ## Architecture
29
+
30
+ ### 1. Component Protocol
31
+
32
+ The core asset is the high-level component protocol, not a specific frontend shell.
33
+
34
+ First-stage components:
35
+
36
+ - `InlineText`: short text with controlled inline Markdown.
37
+ - `MarkdownBody`: controlled component-local body Markdown.
38
+ - `DecisionMatrix`: compare options.
39
+ - `OptionGrid`: show alternatives side by side.
40
+ - `ExportPanel`: export Markdown or JSON.
41
+
42
+ Planned components:
43
+
44
+ - `PriorityBoard`: drag-and-drop priority sorting.
45
+ - `PromptWorkbench`: prompt variables and sample previews.
46
+ - `DiffExplainer`: PR and diff explanation.
47
+ - `ParameterTuner`: parameter tuning UI.
48
+
49
+ ### 2. Build Layer
50
+
51
+ Stage one uses Vite, React, and MDX:
52
+
53
+ ```text
54
+ artifact-docs/foo.mdx
55
+ -> Vite bundle
56
+ -> inline JS/CSS/assets
57
+ -> dist/artifacts/foo.html
58
+ ```
59
+
60
+ The goal is to validate the single HTML artifact loop before building a docs site.
61
+
62
+ ### 3. Docs Site Layer
63
+
64
+ Stage two can add an Astro adapter:
65
+
66
+ ```text
67
+ artifact-docs/
68
+ decisions/auth.mdx
69
+ pr-reviews/backpressure.mdx
70
+
71
+ -> Astro adapter
72
+
73
+ dist/site/
74
+ decisions/auth/index.html
75
+ pr-reviews/backpressure/index.html
76
+ ```
77
+
78
+ Astro is a good fit for long-lived documentation, but it should not define the core component API.
79
+
80
+ ## Why Not Bind the Core to Astro
81
+
82
+ Astro is useful for long-lived MDX documentation:
83
+
84
+ - MDX files can map naturally to pages.
85
+ - Layouts, frontmatter, routing, and static output are built in.
86
+ - Documentation archives become easier to maintain.
87
+
88
+ But it is not the right core abstraction for one-off artifacts:
89
+
90
+ - It is heavier than needed for temporary interactive tools.
91
+ - Agents need to understand Astro-specific `client:*` directives.
92
+ - High-level artifact components should remain portable.
93
+
94
+ Current strategy:
95
+
96
+ ```text
97
+ Core asset: React components + exporter protocol
98
+ First target: Vite single HTML artifact
99
+ Second target: Astro docs site
100
+ ```
101
+
102
+ ## Styling Protocol
103
+
104
+ Artifact Kit provides default CSS, but the default theme is not part of the core artifact contract.
105
+
106
+ Users can inject brand styles through `artifact-kit.config.mjs`:
107
+
108
+ ```js
109
+ /** @type {import("mdx-artifacts").ArtifactKitConfig} */
110
+ const config = {
111
+ docsDir: "artifact-docs",
112
+ outDir: "dist/artifacts",
113
+ includeDefaultStyles: true,
114
+ styles: ["artifact-theme.css"]
115
+ };
116
+ ```
117
+
118
+ Rules:
119
+
120
+ - `includeDefaultStyles: true` imports Artifact Kit default styles first.
121
+ - `styles` are imported in array order after the default styles.
122
+ - Users can override CSS variables or `ak-*` classes.
123
+ - `includeDefaultStyles: false` means the user owns all styling.
124
+ - The final CSS is still inlined into the standalone HTML artifact.
125
+
126
+ ## UI Dependencies
127
+
128
+ The current route is intentionally light:
129
+
130
+ - Tailwind is an internal styling build tool.
131
+ - Radix primitives are added only for complex headless interactions.
132
+ - shadcn/ui is not a runtime dependency; it may become a future registry/template option.
133
+ - daisyUI is not a core dependency; it may become a future demo theme/template.
134
+
135
+ ## Component Development
136
+
137
+ Storybook is a development dependency for isolated component previews.
138
+
139
+ Storybook is responsible for:
140
+
141
+ - Showing component states.
142
+ - Debugging long text, empty data, and narrow layouts.
143
+ - Providing public component examples.
144
+
145
+ Storybook is not responsible for:
146
+
147
+ - Compiling MDX artifacts.
148
+ - Producing standalone HTML.
149
+ - Managing agent workflows.
150
+ - Replacing a future Astro docs site.
151
+
152
+ Current workflow:
153
+
154
+ ```text
155
+ Component development: pnpm storybook
156
+ Protocol verification: pnpm typecheck / pnpm test / pnpm artifact:validate
157
+ Artifact verification: pnpm artifact:build
158
+ ```
159
+
160
+ ## Testing Protocol
161
+
162
+ The first test baseline protects the component protocol rather than browser behavior.
163
+
164
+ Current coverage:
165
+
166
+ - registry metadata contract
167
+ - `InlineText` and `MarkdownBody` controlled Markdown rendering
168
+ - CLI component lookup output
169
+ - MDX validation rules
170
+
171
+ The operational testing path lives in `docs/testing.md`.
172
+
173
+ Out of scope for the first baseline:
174
+
175
+ - browser E2E
176
+ - visual regression
177
+ - Astro adapter tests
178
+ - package tarball smoke tests
179
+
180
+ ## Agent Contract
181
+
182
+ When generating an artifact, agents should:
183
+
184
+ 1. Create `.mdx` files instead of raw HTML.
185
+ 2. Prefer existing high-level components.
186
+ 3. Provide an export path for interactive artifacts.
187
+ 4. Move bulky data into adjacent `.json` files.
188
+ 5. Run `artifact-kit components <ComponentName>` when props are unclear.
189
+ 6. Run `artifact-kit components --json` for machine-readable metadata.
190
+ 7. Run `artifact-kit validate <file.mdx>` before build.
191
+ 8. Run `artifact-kit build <file.mdx>` to produce standalone HTML.
192
+
193
+ ## CLI Component Query
194
+
195
+ To keep skills and agent instructions short, the CLI exposes component metadata:
196
+
197
+ ```bash
198
+ artifact-kit components
199
+ artifact-kit components ExportPanel
200
+ artifact-kit components --json
201
+ artifact-kit components ExportPanel --json
202
+ ```
203
+
204
+ The data comes from `componentRegistry`. Future docs, Storybook docs, validation rules, and agent skills should derive from the same source.
205
+
206
+ Component naming rules:
207
+
208
+ - Names must be self-describing, such as `DecisionMatrix` and `ExportPanel`.
209
+ - Avoid generic names such as `Panel` or `CardList`.
210
+ - A component should represent an artifact workflow, not a primitive UI element.
211
+ - Text rendering is intentionally split into `InlineText`, `MarkdownBody`, and future long-form prose components.
212
+
213
+ ## Public Roadmap and Local Execution Notes
214
+
215
+ Public project direction lives in:
216
+
217
+ - `ROADMAP.md`
218
+ - `docs/design.md`
219
+ - `docs/naming.md`
220
+ - `docs/component-protocol.md`
221
+ - `docs/component-taxonomy.md`
222
+ - `docs/testing.md`
223
+
224
+ Local phase execution notes belong in `docs/local/*.local.md` and are not committed. They can track temporary decisions, verification notes, and agent working state without adding process noise to the public repository.
225
+
226
+ ## Success Criteria
227
+
228
+ Stage one is complete when:
229
+
230
+ - Example MDX passes validation.
231
+ - Example MDX can be previewed locally.
232
+ - Example MDX builds into standalone HTML.
233
+ - The HTML opens directly and supports copy/export.
234
+
235
+ Stage two is complete when:
236
+
237
+ - The `artifact-docs` tree can generate a static docs site.
238
+ - The docs site uses the same high-level components.
239
+ - Single artifacts and the docs site share the same source files.
@@ -0,0 +1,217 @@
1
+ # MDX Artifacts 设计说明
2
+
3
+ ## 语言策略
4
+
5
+ 面向开源和 npm 发布时,项目语言边界如下:
6
+
7
+ - 代码、类型、运行时 UI、CLI 输出、错误信息使用英文。
8
+ - `componentRegistry` 使用英文,因为它会被 CLI、Agent 和未来文档生成共同消费。
9
+ - `artifact-docs/examples` 使用英文,作为开源示例和测试素材。
10
+ - `agents/AGENTS.snippet.md` 使用英文,避免下发给用户项目后造成语言预设。
11
+ - `README.md` 英文优先,中文内容放在 `README.zh-CN.md`。
12
+ - `docs/design.md` 英文优先,中文设计备忘放在 `docs/design.zh-CN.md`。
13
+
14
+ 这个约定的目标是:开源用户看到的默认行为是英文,同时保留中文文档服务当前产品和架构讨论。
15
+
16
+ ## 背景
17
+
18
+ HTML artifact 的价值不在于替代 Markdown,而在于把一些阅读、比较、调参、排序、导出类任务变成可操作界面。
19
+
20
+ 直接让 Agent 生成裸 HTML 有几个问题:
21
+
22
+ - Token 成本高。
23
+ - 样式和交互重复生成。
24
+ - 导出逻辑不稳定。
25
+ - HTML diff 不适合长期维护。
26
+ - 一次性页面难以沉淀成工作流资产。
27
+
28
+ 本项目的判断是:保留 MDX 作为源文件,让 Agent 调用预置高阶组件,最终编译成 HTML artifact。
29
+
30
+ ## 三层架构
31
+
32
+ ### 1. 组件协议层
33
+
34
+ 核心资产是高阶组件和数据协议,而不是某个前端框架壳。
35
+
36
+ 第一批组件:
37
+
38
+ - `InlineText`:单行短文本,支持受控 inline Markdown。
39
+ - `MarkdownBody`:组件内部正文,支持受控 block Markdown。
40
+ - `DecisionMatrix`:方案比较。
41
+ - `OptionGrid`:多个方案并排展示。
42
+ - `ExportPanel`:导出 Markdown / JSON。
43
+
44
+ 后续组件:
45
+
46
+ - `PriorityBoard`:任务拖拽排序。
47
+ - `PromptWorkbench`:提示词变量和样例预览。
48
+ - `DiffExplainer`:PR / diff 解释。
49
+ - `ParameterTuner`:参数调试器。
50
+
51
+ ### 2. 构建层
52
+
53
+ 第一阶段使用 Vite + React + MDX:
54
+
55
+ ```text
56
+ artifact-docs/foo.mdx
57
+ -> Vite bundle
58
+ -> inline JS/CSS/assets
59
+ -> dist/artifacts/foo.html
60
+ ```
61
+
62
+ 这个阶段的目标是验证单个 HTML artifact 闭环,不做文档站。
63
+
64
+ ### 3. 文档站层
65
+
66
+ 第二阶段提供 Astro template:
67
+
68
+ ```text
69
+ artifact-docs/
70
+ decisions/auth.mdx
71
+ pr-reviews/backpressure.mdx
72
+
73
+ -> Astro adapter
74
+
75
+ dist/site/
76
+ decisions/auth/index.html
77
+ pr-reviews/backpressure/index.html
78
+ ```
79
+
80
+ Astro 适合长期文档库,但不应该决定核心组件 API。
81
+
82
+ ## 为什么不先绑定 Astro
83
+
84
+ Astro 的优点:
85
+
86
+ - MDX 文件天然适合作为页面。
87
+ - 多页面、layout、frontmatter、静态输出更完整。
88
+ - 适合长期开发文档站。
89
+
90
+ Astro 的代价:
91
+
92
+ - 对一次性交互工具偏重。
93
+ - Agent 需要理解 `client:*` 这类 Astro 特有规则。
94
+ - 高阶组件本身不应该依赖 Astro。
95
+
96
+ 所以当前策略是:
97
+
98
+ ```text
99
+ 核心资产:React 高阶组件 + exporter 协议
100
+ 第一出口:Vite 单 HTML artifact
101
+ 第二出口:Astro 文档站
102
+ ```
103
+
104
+ ## UI 依赖边界
105
+
106
+ 当前采用“Tailwind + Radix primitives”的轻量路线。
107
+
108
+ ## 样式协议
109
+
110
+ Artifact Kit 提供默认 CSS,但默认样式不是闭环的一部分。
111
+
112
+ 使用者可以通过 `artifact-kit.config.ts` 注入品牌样式:
113
+
114
+ ```ts
115
+ const config = {
116
+ docsDir: "artifact-docs",
117
+ outDir: "dist/artifacts",
118
+ includeDefaultStyles: true,
119
+ styles: ["artifact-theme.css"]
120
+ };
121
+ ```
122
+
123
+ 约定:
124
+
125
+ - `includeDefaultStyles: true` 时,先导入 Artifact Kit 默认样式。
126
+ - `styles` 按数组顺序在默认样式之后导入。
127
+ - 使用者可以通过覆盖 CSS variables 或 `ak-*` class 调整品牌。
128
+ - `includeDefaultStyles: false` 表示完全接管样式。
129
+ - CLI 构建仍会把最终 CSS 内联到单文件 HTML。
130
+
131
+ ### Tailwind 的角色
132
+
133
+ Tailwind 是 artifact-kit 内部的样式生产工具,不要求用户项目自己配置 Tailwind。
134
+
135
+ ### Radix 的角色
136
+
137
+ Radix 只作为按需引入的 headless primitives,用于 Tabs、Dialog、Tooltip、Select、Accordion 这类复杂交互。
138
+
139
+ 第一阶段只在 `ExportPanel` 中使用 `@radix-ui/react-tabs` 验证集成边界。
140
+
141
+ ## 组件开发方式
142
+
143
+ 当前引入 Storybook 作为开发依赖,用于隔离调试 React 高阶组件。
144
+
145
+ Storybook 不负责:
146
+
147
+ - 编译 MDX artifact。
148
+ - 输出单文件 HTML。
149
+ - 管理 Agent 工作流。
150
+ - 替代后续 Astro 文档站。
151
+
152
+ 因此当前工作方式是:
153
+
154
+ ```text
155
+ 组件开发:pnpm storybook
156
+ 协议验证:pnpm typecheck / pnpm test / pnpm artifact:validate
157
+ artifact 验证:pnpm artifact:build
158
+ ```
159
+
160
+ ## 测试协议
161
+
162
+ 第一版测试基线先保护组件协议,不直接进入浏览器 E2E。
163
+
164
+ 当前覆盖:
165
+
166
+ - registry 元数据约束
167
+ - `InlineText` / `MarkdownBody` 的受控 Markdown 渲染
168
+ - CLI 组件查询输出
169
+ - MDX validate 规则
170
+
171
+ 具体测试路径见 `docs/testing.md`。
172
+
173
+ 第一版暂不覆盖:
174
+
175
+ - 浏览器 E2E
176
+ - 视觉回归
177
+ - Astro adapter 测试
178
+ - npm tarball 安装 smoke test
179
+
180
+ ## Agent 使用约定
181
+
182
+ Agent 生成 artifact 时应该遵守:
183
+
184
+ 1. 优先创建 `.mdx` 文件,不直接写裸 HTML。
185
+ 2. 优先使用已有高阶组件,不临时重写同类 UI。
186
+ 3. 交互型 artifact 必须提供导出入口。
187
+ 4. 大型数据后续应拆到相邻 `.json`。
188
+ 5. 不确定组件参数时运行 `artifact-kit components <ComponentName>`。
189
+ 6. 需要机器可读元数据时运行 `artifact-kit components --json`。
190
+ 7. 构建前运行 `artifact-kit validate <file.mdx>`。
191
+ 8. 单页输出运行 `artifact-kit build <file.mdx>`。
192
+
193
+ ## CLI 查询协议
194
+
195
+ 为了减少 skill、AGENTS.md、CLAUDE.md 中的冗余组件说明,CLI 提供组件查询能力:
196
+
197
+ ```bash
198
+ artifact-kit components
199
+ artifact-kit components ExportPanel
200
+ artifact-kit components --json
201
+ artifact-kit components ExportPanel --json
202
+ ```
203
+
204
+ 查询数据来自 `componentRegistry`,未来应同时服务 CLI 查询、Storybook docs、validate 规则和 Agent skill 说明。
205
+
206
+ ## 公开路线图与本地执行记录
207
+
208
+ 公开项目方向放在:
209
+
210
+ - `ROADMAP.md`
211
+ - `docs/design.md`
212
+ - `docs/naming.md`
213
+ - `docs/component-protocol.md`
214
+ - `docs/component-taxonomy.md`
215
+ - `docs/testing.md`
216
+
217
+ 本地阶段执行记录放在 `docs/local/*.local.md`,不提交到开源仓库。它用于记录临时判断、验收过程和 Agent 工作状态,避免把过程噪音暴露到公开文档中。
package/docs/naming.md ADDED
@@ -0,0 +1,123 @@
1
+ # Naming Conventions
2
+
3
+ Naming should help agents choose the right component without long prompt instructions.
4
+
5
+ ## Component Names
6
+
7
+ Use `PascalCase`.
8
+
9
+ Component names should describe the artifact workflow:
10
+
11
+ - `DecisionMatrix`
12
+ - `OptionGrid`
13
+ - `ExportPanel`
14
+ - `InlineText`
15
+ - `MarkdownBody`
16
+
17
+ Avoid vague primitive names:
18
+
19
+ - `Text`
20
+ - `Panel`
21
+ - `CardList`
22
+ - `Box`
23
+
24
+ Use `Markdown` in a component name only when the component consumes a Markdown string.
25
+
26
+ ## Text Field Names
27
+
28
+ Use a small shared vocabulary:
29
+
30
+ - `title`: short title, usually `inlineMarkdown`
31
+ - `subtitle`: secondary short title, usually `inlineMarkdown`
32
+ - `description`: short explanation, usually `inlineMarkdown`
33
+ - `caption`: auxiliary note, usually `inlineMarkdown`
34
+ - `text`: primary field for `InlineText`
35
+ - `body`: primary field for `MarkdownBody` and future long-form prose components
36
+
37
+ Avoid introducing synonyms unless a component has a specific workflow reason:
38
+
39
+ - `copy`
40
+ - `message`
41
+ - `content`
42
+ - `details`
43
+ - `richText`
44
+
45
+ ## Content Types
46
+
47
+ The registry can label prop content with these content types:
48
+
49
+ - `plainText`
50
+ - `inlineMarkdown`
51
+ - `blockMarkdown`
52
+ - `json`
53
+ - `code`
54
+
55
+ Agents should inspect content types through:
56
+
57
+ ```bash
58
+ artifact-kit components <ComponentName>
59
+ artifact-kit components <ComponentName> --json
60
+ ```
61
+
62
+ ## Complex Prop Types
63
+
64
+ Complex object props must be queryable without opening TypeScript source files.
65
+
66
+ If a prop type references a named object or object array, add `types` metadata in `src/react/registry.ts`.
67
+
68
+ Examples:
69
+
70
+ - `DecisionMatrixOption[]` requires a `DecisionMatrixOption` type entry.
71
+ - `DiffLine[]` requires a `DiffLine` type entry.
72
+ - `CodeAnnotation[]` requires a `CodeAnnotation` type entry.
73
+
74
+ Each nested field should include:
75
+
76
+ - `name`
77
+ - `type`
78
+ - `required` when true
79
+ - `contentType` when the field contains text, Markdown, JSON, or code
80
+ - `description`
81
+
82
+ The CLI output should be sufficient for an agent to write valid MDX without relying on editor LSP hover information.
83
+
84
+ ## Markdown Levels
85
+
86
+ `inlineMarkdown` supports:
87
+
88
+ - bold
89
+ - emphasis
90
+ - strikethrough
91
+ - inline code
92
+ - links
93
+
94
+ `blockMarkdown` supports:
95
+
96
+ - headings
97
+ - paragraphs
98
+ - ordered lists
99
+ - unordered lists
100
+ - blockquotes
101
+ - bold
102
+ - emphasis
103
+ - strikethrough
104
+ - inline code
105
+ - links
106
+
107
+ `blockMarkdown` intentionally does not support tables, HTML, math, or code blocks.
108
+
109
+ For main artifact structure, prefer component title props or `InlineText as="h2"` instead of headings inside body strings. Headings inside `MarkdownBody` are for local body sections.
110
+
111
+ Use:
112
+
113
+ ```tsx
114
+ <InlineText as="h3" text="**Recommended option**" />
115
+ ```
116
+
117
+ Avoid:
118
+
119
+ ```md
120
+ ### **Recommended option**
121
+ ```
122
+
123
+ inside component string props.
@@ -0,0 +1,138 @@
1
+ # Testing
2
+
3
+ The current test baseline protects the component protocol. It does not try to prove every browser behavior or release boundary yet.
4
+
5
+ ## Current Baseline
6
+
7
+ Run the default local check:
8
+
9
+ ```bash
10
+ pnpm check
11
+ ```
12
+
13
+ This runs:
14
+
15
+ 1. `pnpm typecheck`
16
+ 2. `pnpm test`
17
+ 3. `pnpm artifact:validate`
18
+
19
+ Current test coverage:
20
+
21
+ - registry metadata contract
22
+ - controlled text rendering for `InlineText` and `MarkdownBody`
23
+ - CLI component lookup output
24
+ - MDX validation rules
25
+
26
+ Current test files:
27
+
28
+ - `src/react/registry.test.ts`
29
+ - `src/react/components/text-components.test.tsx`
30
+ - `src/cli/components.test.ts`
31
+ - `src/cli/validate.test.ts`
32
+
33
+ ## Package Smoke Test
34
+
35
+ Run the package smoke test before publishing or after changes to package metadata, CLI output, config loading, generated scaffold files, dependency boundaries, or build output:
36
+
37
+ ```bash
38
+ pnpm pack:smoke
39
+ ```
40
+
41
+ The smoke test creates an npm tarball, installs it into a temporary project, and verifies:
42
+
43
+ - `import("mdx-artifacts/react")`
44
+ - `artifact-kit components`
45
+ - `artifact-kit init`
46
+ - `artifact-kit validate artifact-docs/examples/hello.mdx`
47
+ - `artifact-kit build artifact-docs/examples/hello.mdx`
48
+
49
+ It also checks that the tarball does not include `src/`, `docs/local/`, `.state.json`, or `.local.*` files.
50
+
51
+ This smoke test is intentionally narrow. It proves that the published package can be installed, imported, initialized, validated, and built. It does not yet cover the dev server, browser review UI, review state writes, or multi-artifact workspaces.
52
+
53
+ ## When Adding a Component
54
+
55
+ Add tests at the same layer as the new behavior.
56
+
57
+ Required:
58
+
59
+ - Add or update `src/react/registry.test.ts` if registry metadata shape changes.
60
+ - Add a component render test when the component owns rendering rules.
61
+ - Add a Storybook story for visual development states.
62
+ - Add or update an MDX example if the component changes the artifact workflow.
63
+ - Run `pnpm check`.
64
+
65
+ Recommended assertions:
66
+
67
+ - Important text renders.
68
+ - Optional fields can be omitted.
69
+ - Empty lists or missing optional data do not break layout.
70
+ - Controlled Markdown fields respect their documented content type.
71
+ - The component is registered with a clear example.
72
+ - Complex object props have matching registry `types` metadata.
73
+
74
+ Do not add browser E2E just because a component was added. Add browser tests only when the behavior depends on real browser APIs, focus, layout, clipboard, drag-and-drop, or navigation.
75
+
76
+ ## When Adding CLI Behavior
77
+
78
+ Required:
79
+
80
+ - Add or update a focused `src/cli/*.test.ts` file.
81
+ - Test command formatting through exported command functions when possible.
82
+ - Test errors and warnings as data before testing process exit behavior.
83
+ - Run `pnpm check`.
84
+
85
+ For CLI behavior that writes files or builds artifacts, prefer small integration tests with temporary directories.
86
+
87
+ Do not make the first assertion depend on full HTML build output unless the feature specifically changes build output.
88
+
89
+ ## When Adding Validation Rules
90
+
91
+ Required:
92
+
93
+ - Add a positive case.
94
+ - Add a negative case.
95
+ - Keep error and warning messages stable enough for agents to understand.
96
+ - Run `pnpm check`.
97
+
98
+ Validation rules should protect the artifact protocol, not personal style preferences.
99
+
100
+ ## When Adding Export Behavior
101
+
102
+ Required:
103
+
104
+ - Test serialization output as plain strings or structured data.
105
+ - Test the component wiring separately only if rendering logic changes.
106
+
107
+ Future export formats should have focused tests before being added to `ExportPanel`.
108
+
109
+ ## Heavier Checks
110
+
111
+ These checks are not part of the current default baseline:
112
+
113
+ - browser E2E
114
+ - visual regression
115
+ - Storybook test runner
116
+ - Astro adapter tests
117
+ - `artifact:build`
118
+ - `npm pack --dry-run`
119
+
120
+ Use them before npm publishing or when the changed behavior touches packaging, standalone HTML output, browser-only APIs, or future docs-site adapters.
121
+
122
+ ## Rule of Thumb
123
+
124
+ Use the lightest test that can fail for the bug you are trying to prevent.
125
+
126
+ For Phase 1, prefer:
127
+
128
+ ```text
129
+ typecheck + unit tests + validate
130
+ ```
131
+
132
+ over:
133
+
134
+ ```text
135
+ browser E2E + full build + package smoke test
136
+ ```
137
+
138
+ unless the change specifically needs the heavier layer.