mdx-artifacts 0.1.2 → 0.2.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 (141) hide show
  1. package/README.md +211 -59
  2. package/README.zh-CN.md +299 -42
  3. package/agents/AGENTS.snippet.md +21 -10
  4. package/artifact-docs/examples/commentable-feedback.mdx +76 -70
  5. package/artifact-docs/examples/decision-matrix.mdx +122 -50
  6. package/artifact-docs/examples/layout-composition.mdx +106 -128
  7. package/artifact-docs/examples/streamlit-style-mixed.mdx +100 -85
  8. package/dist/lib/cli/{build.js → commands/build.js} +2 -2
  9. package/dist/lib/cli/{components.js → commands/components.js} +19 -3
  10. package/dist/lib/cli/{dev.js → commands/dev.js} +2 -2
  11. package/dist/lib/cli/commands/interactions.d.ts +2 -0
  12. package/dist/lib/cli/commands/interactions.js +280 -0
  13. package/dist/lib/cli/commands/review.d.ts +1 -0
  14. package/dist/lib/cli/commands/review.js +171 -0
  15. package/dist/lib/cli/commands/scaffold.d.ts +16 -0
  16. package/dist/lib/cli/commands/scaffold.js +440 -0
  17. package/dist/lib/cli/commands/validate.d.ts +18 -0
  18. package/dist/lib/cli/commands/validate.js +311 -0
  19. package/dist/lib/cli/config/config.d.ts +2 -0
  20. package/dist/lib/cli/{config.js → config/config.js} +3 -2
  21. package/dist/lib/cli/{types.d.ts → config/types.d.ts} +2 -1
  22. package/dist/lib/cli/{vite-artifact.d.ts → dev-server/vite-artifact.d.ts} +3 -3
  23. package/dist/lib/cli/{vite-artifact.js → dev-server/vite-artifact.js} +170 -10
  24. package/dist/lib/cli/diagnostics/diagnostics.d.ts +11 -0
  25. package/dist/lib/cli/diagnostics/diagnostics.js +1 -0
  26. package/dist/lib/cli/index.js +39 -18
  27. package/dist/lib/cli/mdx/sortable-list.d.ts +14 -0
  28. package/dist/lib/cli/mdx/sortable-list.js +520 -0
  29. package/dist/lib/cli/resources/resource-policy.d.ts +15 -0
  30. package/dist/lib/cli/resources/resource-policy.js +46 -0
  31. package/dist/lib/cli/resources/safe-path.d.ts +13 -0
  32. package/dist/lib/cli/resources/safe-path.js +55 -0
  33. package/dist/lib/cli/services/interaction-service.d.ts +40 -0
  34. package/dist/lib/cli/services/interaction-service.js +226 -0
  35. package/dist/lib/cli/services/review.d.ts +43 -0
  36. package/dist/lib/cli/{review.js → services/review.js} +34 -172
  37. package/dist/lib/react/{components → composites/comparison-set}/ComparisonSet.d.ts +1 -1
  38. package/dist/lib/react/{components → composites/comparison-set}/ComparisonSet.js +3 -3
  39. package/dist/lib/react/composites/comparison-set/index.d.ts +2 -0
  40. package/dist/lib/react/composites/comparison-set/index.js +1 -0
  41. package/dist/lib/react/composites/content-set/ContentItem.d.ts +37 -0
  42. package/dist/lib/react/composites/content-set/ContentItem.js +49 -0
  43. package/dist/lib/react/composites/content-set/index.d.ts +2 -0
  44. package/dist/lib/react/composites/content-set/index.js +1 -0
  45. package/dist/lib/react/{components → composites/export-panel}/ExportPanel.js +2 -2
  46. package/dist/lib/react/composites/export-panel/index.d.ts +2 -0
  47. package/dist/lib/react/composites/export-panel/index.js +1 -0
  48. package/dist/lib/react/{components → composites/section}/Section.js +1 -1
  49. package/dist/lib/react/composites/section/index.d.ts +2 -0
  50. package/dist/lib/react/composites/section/index.js +1 -0
  51. package/dist/lib/react/index.d.ts +36 -31
  52. package/dist/lib/react/index.js +18 -15
  53. package/dist/lib/react/interactions/artifact-state/index.d.ts +1 -0
  54. package/dist/lib/react/interactions/artifact-state/index.js +1 -0
  55. package/dist/lib/react/{components → interactions/comments}/Comments.d.ts +2 -2
  56. package/dist/lib/react/{components → interactions/comments}/Comments.js +3 -3
  57. package/dist/lib/react/interactions/comments/index.d.ts +1 -0
  58. package/dist/lib/react/interactions/comments/index.js +1 -0
  59. package/dist/lib/react/interactions/sortable-list/SortableList.d.ts +29 -0
  60. package/dist/lib/react/interactions/sortable-list/SortableList.js +282 -0
  61. package/dist/lib/react/interactions/sortable-list/index.d.ts +1 -0
  62. package/dist/lib/react/interactions/sortable-list/index.js +1 -0
  63. package/dist/lib/react/layout/layout-primitives/index.d.ts +2 -0
  64. package/dist/lib/react/layout/layout-primitives/index.js +1 -0
  65. package/dist/lib/react/legacy/LegacyContentComponents.d.ts +65 -0
  66. package/dist/lib/react/legacy/LegacyContentComponents.js +26 -0
  67. package/dist/lib/react/mdx-components.d.ts +5 -0
  68. package/dist/lib/react/mdx-components.js +38 -0
  69. package/dist/lib/react/{components → primitives/annotated-code}/AnnotatedCode.d.ts +1 -1
  70. package/dist/lib/react/{components → primitives/annotated-code}/AnnotatedCode.js +5 -5
  71. package/dist/lib/react/primitives/annotated-code/index.d.ts +2 -0
  72. package/dist/lib/react/primitives/annotated-code/index.js +1 -0
  73. package/dist/lib/react/primitives/callout/Callout.d.ts +11 -0
  74. package/dist/lib/react/{components → primitives/callout}/Callout.js +9 -6
  75. package/dist/lib/react/primitives/callout/index.d.ts +2 -0
  76. package/dist/lib/react/primitives/callout/index.js +1 -0
  77. package/dist/lib/react/primitives/code-block/CodeBlock.d.ts +20 -0
  78. package/dist/lib/react/primitives/code-block/CodeBlock.js +32 -0
  79. package/dist/lib/react/primitives/code-block/index.d.ts +2 -0
  80. package/dist/lib/react/primitives/code-block/index.js +1 -0
  81. package/dist/lib/react/primitives/code-surface/CodeSurface.d.ts +11 -0
  82. package/dist/lib/react/primitives/code-surface/CodeSurface.js +34 -0
  83. package/dist/lib/react/primitives/code-surface/index.d.ts +2 -0
  84. package/dist/lib/react/primitives/code-surface/index.js +1 -0
  85. package/dist/lib/react/primitives/diff-block/DiffBlock.js +25 -0
  86. package/dist/lib/react/primitives/diff-block/index.d.ts +2 -0
  87. package/dist/lib/react/primitives/diff-block/index.js +1 -0
  88. package/dist/lib/react/{components → primitives/inline-text}/InlineText.d.ts +4 -2
  89. package/dist/lib/react/primitives/inline-text/InlineText.js +28 -0
  90. package/dist/lib/react/primitives/inline-text/index.d.ts +2 -0
  91. package/dist/lib/react/primitives/inline-text/index.js +1 -0
  92. package/dist/lib/react/primitives/markdown-body/MarkdownBody.d.ts +9 -0
  93. package/dist/lib/react/primitives/markdown-body/MarkdownBody.js +49 -0
  94. package/dist/lib/react/primitives/markdown-body/index.d.ts +2 -0
  95. package/dist/lib/react/primitives/markdown-body/index.js +1 -0
  96. package/dist/lib/react/primitives/severity-badge/index.d.ts +2 -0
  97. package/dist/lib/react/primitives/severity-badge/index.js +1 -0
  98. package/dist/lib/react/registry.d.ts +10 -0
  99. package/dist/lib/react/registry.js +505 -210
  100. package/dist/lib/react/styles.css +490 -38
  101. package/docs/cli-structure.md +141 -0
  102. package/docs/component-protocol.md +199 -33
  103. package/docs/component-taxonomy.md +40 -4
  104. package/docs/design.md +42 -21
  105. package/docs/design.zh-CN.md +41 -21
  106. package/docs/naming.md +17 -7
  107. package/docs/releasing.md +132 -0
  108. package/docs/testing.md +35 -10
  109. package/package.json +9 -7
  110. package/dist/lib/cli/config.d.ts +0 -2
  111. package/dist/lib/cli/review.d.ts +0 -33
  112. package/dist/lib/cli/scaffold.d.ts +0 -1
  113. package/dist/lib/cli/scaffold.js +0 -56
  114. package/dist/lib/cli/validate.d.ts +0 -6
  115. package/dist/lib/cli/validate.js +0 -79
  116. package/dist/lib/react/components/Callout.d.ts +0 -9
  117. package/dist/lib/react/components/CodeBlock.d.ts +0 -10
  118. package/dist/lib/react/components/CodeBlock.js +0 -28
  119. package/dist/lib/react/components/DecisionMatrix.d.ts +0 -16
  120. package/dist/lib/react/components/DecisionMatrix.js +0 -27
  121. package/dist/lib/react/components/DiffBlock.js +0 -24
  122. package/dist/lib/react/components/InlineText.js +0 -18
  123. package/dist/lib/react/components/MarkdownBody.d.ts +0 -7
  124. package/dist/lib/react/components/MarkdownBody.js +0 -36
  125. package/dist/lib/react/components/OptionGrid.d.ts +0 -13
  126. package/dist/lib/react/components/OptionGrid.js +0 -21
  127. /package/dist/lib/cli/{build.d.ts → commands/build.d.ts} +0 -0
  128. /package/dist/lib/cli/{components.d.ts → commands/components.d.ts} +0 -0
  129. /package/dist/lib/cli/{dev.d.ts → commands/dev.d.ts} +0 -0
  130. /package/dist/lib/cli/{types.js → config/types.js} +0 -0
  131. /package/dist/lib/cli/{artifact-state.d.ts → state/artifact-state.d.ts} +0 -0
  132. /package/dist/lib/cli/{artifact-state.js → state/artifact-state.js} +0 -0
  133. /package/dist/lib/react/{components → composites/export-panel}/ExportPanel.d.ts +0 -0
  134. /package/dist/lib/react/{components → composites/section}/Section.d.ts +0 -0
  135. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.d.ts +0 -0
  136. /package/dist/lib/react/{components → interactions/artifact-state}/ArtifactState.js +0 -0
  137. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.d.ts +0 -0
  138. /package/dist/lib/react/{components → layout/layout-primitives}/Layout.js +0 -0
  139. /package/dist/lib/react/{components → primitives/diff-block}/DiffBlock.d.ts +0 -0
  140. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.d.ts +0 -0
  141. /package/dist/lib/react/{components → primitives/severity-badge}/SeverityBadge.js +0 -0
package/README.zh-CN.md CHANGED
@@ -1,23 +1,32 @@
1
1
  # MDX Artifacts
2
2
 
3
- 一个面向 Agent 的交互式 MDX artifact 工具原型。
3
+ 一个面向 Agent 的交互式 MDX artifact 工具。
4
4
 
5
- 目标不是让模型每次生成一整份裸 HTML,而是让模型写较稳定的 MDX
5
+ 目标不是让模型每次生成一整份裸 HTML,也不是让模型在 MDX 里写一个 React app DSL。目标是让源文件保持 Markdown-native,同时用稳定的高阶组件表达语义岛:
6
6
 
7
7
  ```mdx
8
- import { DecisionMatrix, ExportPanel } from "../../src/react";
9
-
10
- <DecisionMatrix
11
- question="是否先用 Vite 跑通单 HTML artifact?"
12
- options={[
13
- {
14
- name: "先做 Vite 单页",
15
- pros: ["闭环短", "更贴近交互工具"],
16
- cons: ["暂时没有文档站导航"],
17
- verdict: "第一阶段推荐"
18
- }
19
- ]}
20
- />
8
+ import { ContentSet, ExportPanel } from "mdx-artifacts/react";
9
+
10
+ <ContentSet
11
+ id="set.stage-one"
12
+ title="是否先用 Vite 跑通单 HTML artifact?"
13
+ columns={3}
14
+ >
15
+ <ContentSet.Item
16
+ id="vite"
17
+ title="先做 Vite 单页"
18
+ badge="第一阶段推荐"
19
+ tone="positive"
20
+ emphasis="primary"
21
+ summary="先验证从 Markdown-native source 到交互式 HTML 的最短闭环。"
22
+ >
23
+ ### 取舍
24
+
25
+ - 闭环短
26
+ - 更贴近交互工具
27
+ - 暂时没有文档站导航
28
+ </ContentSet.Item>
29
+ </ContentSet>
21
30
 
22
31
  <ExportPanel
23
32
  title="导出决策"
@@ -28,49 +37,260 @@ import { DecisionMatrix, ExportPanel } from "../../src/react";
28
37
 
29
38
  再由 CLI 输出一个可在浏览器中直接打开的 HTML artifact。
30
39
 
40
+ ## 写作哲学
41
+
42
+ MDX Artifacts 是一个 Markdown-native 的 artifact system。
43
+
44
+ 源文件应该读起来像文档;输出文件可以表现为更强的交互式 HTML artifact。组件应该是文档中的语义岛,而不是把整篇文档替换成一个巨大的 JSX 配置对象。
45
+
46
+ 做组件和写 artifact 时,用这组边界做判断:
47
+
48
+ - 叙事内容、解释、长描述、列表、可 review 的正文,优先使用原生 Markdown 或 MDX children。
49
+ - 决策、对比、代码 review、导出交接、交互状态等结构化工作流区域,使用语义组件。
50
+ - 稳定 id、短标签、枚举设置、布局控制、机器可读 value、真正的数据结构,继续使用 props。
51
+ - 不要把所有语义都挪进隐式 Markdown parser。标题、列表、表格不应该在没有显式组件 slot 的情况下偷偷变成组件数据。
52
+ - 不要把 artifact source 写成 React 应用源码。如果一个 artifact 需要任意状态 UI、项目级 CSS 或应用级交互,应使用专门的 web artifact builder 或项目本地组件。
53
+
54
+ 因此,新组件 API 默认应该是:人类可读内容 children-first,机器可读配置 props-first。
55
+
56
+ ## 什么时候使用
57
+
58
+ 当 agent 需要创建一个本地、可 review、可验证、最终能输出独立 HTML 的 MDX artifact 时,适合使用 MDX Artifacts。
59
+
60
+ 适合的场景:
61
+
62
+ - 决策报告、方案对比、代码 review 交接、实施计划。
63
+ - 源文件仍需要保持 MDX 可读性。
64
+ - 希望 agent 先查询组件 metadata,再 validate,最后 build。
65
+ - 需要项目本地 React 组件补充能力,但主体仍然是 MDX 文档。
66
+
67
+ 不适合的场景:普通 README、简单笔记、裸 HTML 页面、完整 web app,或者需要任意应用状态和自定义运行时代码的 artifact。
68
+
69
+ ## 0.2.0 迁移说明
70
+
71
+ `DecisionMatrix` 和 `OptionGrid` 现在是 deprecated compatibility components。已有 MDX 仍可渲染,但新 artifact 应使用 `ContentSet` 表达成组内容卡片,使用 `ContentItem` 表达独立内容卡片。
72
+
73
+ 这次变更的目标是统一内容写作模型:解释、理由、优缺点、风险和取舍这类可读正文,应该放在 MDX children 中,而不是继续塞进对象数组 props。
74
+
75
+ 推荐写法:
76
+
77
+ ```mdx
78
+ <ContentSet id="set.path" title="选择实现路径" columns={3}>
79
+ <ContentSet.Item
80
+ id="path-a"
81
+ title="路径 A"
82
+ badge="推荐"
83
+ tone="positive"
84
+ emphasis="primary"
85
+ summary="适合作为第一步。"
86
+ >
87
+ ### 取舍
88
+
89
+ - MDX source 更容易阅读
90
+ - 长解释可以继续保留 Markdown 结构
91
+ </ContentSet.Item>
92
+ </ContentSet>
93
+ ```
94
+
95
+ 新 artifact 不要再使用 `DecisionMatrix`、`DecisionMatrix.Option`、`OptionGrid`、`OptionGrid.Item` 或 `options={[...]}`。`validate` 命令会对这些 deprecated compatibility components,以及 `question`、`name`、`intent`、`pros`、`cons`、`risks`、`confidence`、`verdict`、`tradeoffs` 等旧 props 给出迁移 warning。
96
+
31
97
  ## 当前阶段
32
98
 
33
99
  第一阶段只做最小闭环:
34
100
 
35
- 1. `artifact-docs/**/*.mdx` 作为源文件。
36
- 2. `src/react` 提供高阶组件。
37
- 3. `src/cli` 提供 `dev`、`build`、`validate`、`init`。
38
- 4. CLI 提供 `components` 查询组件参数和示例。
101
+ 1. 配置里的 `docsDir` 是 MDX 源文件根目录,默认是 `artifact-docs/`。
102
+ 2. `mdx-artifacts/react` 导出高阶 artifact 组件。
103
+ 3. `mdx-artifacts` CLI 提供 `init`、`components`、`validate`、`dev`、`build` 和窄口径 review-state 命令。
104
+ 4. `mdx-artifacts components` 暴露组件参数和示例,供 agent 查询。
39
105
  5. `build` 输出单个 self-contained HTML 文件。
40
106
  6. `InlineText` / `MarkdownBody` 提供受控的文本渲染边界。
41
107
 
42
108
  暂不把核心绑定到 Astro。Astro 后续只作为“结构化文档站 adapter”加入。
43
109
 
44
- ## 命令
110
+ ## 从 npm 安装
45
111
 
46
- 安装依赖后:
112
+ 对 npm 使用者来说,最短的首次使用路径是:
47
113
 
48
114
  ```bash
49
- pnpm check
50
- pnpm artifact:validate
51
- pnpm artifact:dev
52
- pnpm artifact:build
53
- pnpm storybook
115
+ npm install --save-dev mdx-artifacts
116
+ npx mdx-artifacts init
117
+ npx mdx-artifacts validate artifact-docs/examples/hello.mdx
118
+ npx mdx-artifacts build artifact-docs/examples/hello.mdx
119
+ ```
120
+
121
+ 最后一条命令会输出:
122
+
123
+ ```text
124
+ dist/artifacts/examples/hello.html
125
+ ```
126
+
127
+ 如果使用 pnpm,在需要生成本地 artifacts 的项目中安装:
128
+
129
+ ```bash
130
+ pnpm add -D mdx-artifacts
131
+ ```
132
+
133
+ 如果是在 pnpm workspace root 安装,需要显式加 `-w`:
134
+
135
+ ```bash
136
+ pnpm add -Dw mdx-artifacts
137
+ ```
138
+
139
+ React 和 React DOM 是 peer dependencies。现代包管理器通常会为这个开发工具链自动安装它们;如果你的项目关闭了 peer dependency 自动安装,再显式补上:
140
+
141
+ ```bash
142
+ npm install --save-dev mdx-artifacts react react-dom
143
+ pnpm add -D mdx-artifacts react react-dom
144
+ ```
145
+
146
+ 初始化工作区:
147
+
148
+ ```bash
149
+ npx mdx-artifacts init
150
+ pnpm exec mdx-artifacts init
151
+ ```
152
+
153
+ 交互式初始化会使用编号选项。直接回车表示接受默认值:
154
+
155
+ ```text
156
+ Where should MDX artifact source files live?
157
+ 1. ./artifact-docs/ (default)
158
+ 2. Enter a custom directory
159
+ Select an option (1)
160
+
161
+ Use project-local React components?
162
+ Adds a Tailwind source directory; it does not auto-register components.
163
+ 1. No (default)
164
+ 2. Yes, choose a project-local component source directory
165
+ Select an option (1)
166
+ ```
167
+
168
+ 非交互初始化时,可以显式传入项目结构:
169
+
170
+ ```bash
171
+ pnpm exec mdx-artifacts init --yes --docs-dir docs/artifacts --components-dir artifact-components --agent codex
172
+ ```
173
+
174
+ 初始化完成后,CLI 会输出 summary,列出已选择的目录、生成的 agent guidance 文件,以及下一步 validate/build 命令。脚手架会包含:
175
+
176
+ ```text
177
+ mdx-artifacts.config.mjs
178
+ <docsDir>/examples/hello.mdx
179
+ agents/AGENTS.snippet.md
180
+ ```
181
+
182
+ `components-dir` 是项目本地组件源码目录,会写入 `tailwindSources` 供 Tailwind 扫描 class,但不等于自动注册组件,也不会让组件自动出现在 `mdx-artifacts components` 中。
183
+
184
+ ### Agent Guidance
185
+
186
+ `mdx-artifacts init --agent <agent>` 可以安装项目本地的 agent 写作指导:
187
+
188
+ ```text
189
+ --agent codex .agents/skills/mdx-artifacts/SKILL.md
190
+ --agent claude-code .claude/skills/mdx-artifacts/SKILL.md
191
+ --agent cursor .cursor/rules/mdx-artifacts.mdc
192
+ --agent all 安装所有支持的项目本地 guidance 文件
193
+ ```
194
+
195
+ 这些 guidance 会告诉 agent:什么时候使用 MDX Artifacts、`.mdx` 文件应该放在哪里、如何查询组件 metadata、如何处理本地资源,并要求 agent 在 build 前先运行 `mdx-artifacts validate`。组件 props 的真相来源仍然是 CLI registry,不应该把大段组件 metadata 复制进 agent instructions。
196
+
197
+ 验证和构建初始化示例。默认初始化时,示例文件位于 `artifact-docs/`:
198
+
199
+ ```bash
200
+ pnpm exec mdx-artifacts validate artifact-docs/examples/hello.mdx
201
+ pnpm exec mdx-artifacts build artifact-docs/examples/hello.mdx
54
202
  ```
55
203
 
204
+ 如果初始化时传入了自定义 `--docs-dir`,请改用 `<docsDir>/examples/hello.mdx`。
205
+
206
+ 开发服务模式:
207
+
208
+ ```bash
209
+ pnpm exec mdx-artifacts dev artifact-docs/examples/hello.mdx
210
+ ```
211
+
212
+ ## CLI
213
+
56
214
  查询组件:
57
215
 
58
216
  ```bash
59
- pnpm artifact components
60
- pnpm artifact components ExportPanel
61
- pnpm artifact components --json
217
+ pnpm exec mdx-artifacts components
218
+ pnpm exec mdx-artifacts components ExportPanel
219
+ pnpm exec mdx-artifacts components --json
62
220
  ```
63
221
 
64
222
  单文件构建:
65
223
 
66
224
  ```bash
67
- pnpm artifact build artifact-docs/examples/decision-matrix.mdx
225
+ pnpm exec mdx-artifacts build artifact-docs/examples/hello.mdx
68
226
  ```
69
227
 
70
- 默认输出:
228
+ ## Review State
229
+
230
+ MDX Artifacts 可以把本地 review threads 保存在 MDX 文件旁边的 sibling `.state.json` 文件中:
71
231
 
72
232
  ```text
73
- dist/artifacts/examples/decision-matrix.html
233
+ artifact-docs/examples/hello.mdx
234
+ artifact-docs/examples/hello.state.json
235
+ ```
236
+
237
+ 在 MDX 中使用稳定 anchor,可以让 review threads 在编辑后继续定位:
238
+
239
+ ```mdx
240
+ import { ContentSet, Section } from "mdx-artifacts/react";
241
+
242
+ <Section id="section.context">
243
+
244
+ ## Context
245
+
246
+ Native MDX prose can be reviewed through the section anchor.
247
+
248
+ </Section>
249
+
250
+ <ContentSet
251
+ id="set.stage-one"
252
+ title="Should this artifact use stable anchors?"
253
+ columns={2}
254
+ >
255
+ <ContentSet.Item id="yes" title="Use stable anchors" badge="Recommended" tone="positive" emphasis="primary">
256
+ Stable child anchors keep review threads attached across edits.
257
+ </ContentSet.Item>
258
+ </ContentSet>
259
+ ```
260
+
261
+ Agent 可以新增 thread、追加 assistant reply,并验证 state 中的 anchor 是否仍存在于当前 MDX:
262
+
263
+ ```bash
264
+ pnpm exec mdx-artifacts review add artifact-docs/examples/hello.mdx \
265
+ --anchor set.stage-one \
266
+ --body "Clarify this decision."
267
+
268
+ pnpm exec mdx-artifacts review reply artifact-docs/examples/hello.mdx \
269
+ --thread thr_set_stage_one \
270
+ --body "Updated the decision copy." \
271
+ --status resolved
272
+
273
+ pnpm exec mdx-artifacts review validate artifact-docs/examples/hello.mdx
274
+ ```
275
+
276
+ Review 命令读写源 MDX 的 sibling `.state.json` 文件,不会直接修改 MDX source。`review validate` 会检查已保存的 review threads 是否仍然指向当前 MDX 中存在的 anchors。
277
+
278
+ 如果 anchor 从 MDX 中移除,浏览器 review layer 会把对应 thread 保留为 unplaced comment,而不是删除它;CLI 也会报告同类问题。
279
+
280
+ ## 仓库开发
281
+
282
+ 安装依赖后:
283
+
284
+ ```bash
285
+ pnpm install
286
+ ```
287
+
288
+ 验证并构建仓库示例 artifact:
289
+
290
+ ```bash
291
+ pnpm check
292
+ pnpm mdx-artifacts:validate
293
+ pnpm mdx-artifacts:build
74
294
  ```
75
295
 
76
296
  组件开发:
@@ -79,40 +299,76 @@ dist/artifacts/examples/decision-matrix.html
79
299
  pnpm storybook
80
300
  ```
81
301
 
82
- Storybook 只用于隔离调试 React 组件;最终 artifact 闭环仍以 `artifact-kit validate/build` 为准。
302
+ Storybook 只用于隔离调试 React 组件;最终 artifact 闭环仍以 `mdx-artifacts validate/build` 为准。
83
303
 
84
304
  基础测试:
85
305
 
86
306
  ```bash
87
307
  pnpm test
88
308
  pnpm typecheck
89
- pnpm artifact:validate
309
+ pnpm mdx-artifacts:validate
90
310
  ```
91
311
 
92
- ## 样式注入
312
+ 发布前或修改 package metadata、公开文档、examples、agent guidance 后,运行轻量 release 检查:
93
313
 
94
- 默认情况下,Artifact Kit 会注入内置样式。使用者可以在 `artifact-kit.config.ts` 里追加自己的品牌 CSS:
314
+ ```bash
315
+ pnpm release:check
316
+ ```
95
317
 
96
- ```ts
97
- import type { ArtifactKitConfig } from "./src/cli/types";
318
+ 发布前或修改 package 边界、CLI 输出、config loading、scaffold、依赖边界、build output 后,运行 package smoke test:
98
319
 
99
- const config: ArtifactKitConfig = {
320
+ ```bash
321
+ pnpm pack:smoke
322
+ ```
323
+
324
+ 最终手动发布前,可以再运行:
325
+
326
+ ```bash
327
+ npm pack --dry-run --cache /private/tmp/mdx-artifacts-npm-cache
328
+ ```
329
+
330
+ ## 样式注入
331
+
332
+ 默认情况下,MDX Artifacts 会注入内置样式。使用者可以在 `mdx-artifacts.config.mjs` 里追加自己的品牌 CSS:
333
+
334
+ ```js
335
+ /** @type {import("mdx-artifacts").MdxArtifactsConfig} */
336
+ const config = {
100
337
  docsDir: "artifact-docs",
101
338
  outDir: "dist/artifacts",
102
339
  includeDefaultStyles: true,
103
- styles: ["artifact-theme.css"]
340
+ styles: ["artifact-theme.css"],
341
+ tailwindSources: ["artifact-components/**/*.{ts,tsx}"]
104
342
  };
105
343
 
106
344
  export default config;
107
345
  ```
108
346
 
109
- `styles` 会在默认样式之后导入,因此可以覆盖 CSS variables 或 `ak-*` class。若要完全接管样式,可以设置 `includeDefaultStyles: false`。
347
+ `styles` 会在默认样式之后导入,因此可以覆盖 CSS variables 或 `ak-*` class。若要关闭 MDX Artifacts 默认样式,可以设置 `includeDefaultStyles: false`。
348
+
349
+ CLI 会自动把当前 MDX 文件注册为 Tailwind source,因此本地 MDX 组件里的 Tailwind utility class 会在 artifact 构建时生成。若 MDX import 了项目本地组件,并且这些组件文件里也写了 Tailwind class,可以用 `tailwindSources` 显式注册这些路径。
350
+
351
+ ## 本地资源和安全模型
352
+
353
+ MDX Artifacts 面向项目工作区内生成的本地、可 review artifact。
354
+
355
+ - 已接入 resource policy 的本地资源路径必须留在 project root 内。
356
+ - 已接入 resource policy 的远程 URL、`~` 路径、逃逸 project root 的路径会被拒绝。
357
+ - 当前 `validate` 会检查配置中的 `styles` 资源;data、artifact、component-module 引用后续成为一等输入时,可以接入同一套策略。
358
+ - `tailwindSources` 用于 Tailwind class 扫描,应该只指向项目本地源码文件;它是配置约定,不是组件注册机制。
359
+ - `componentsDir` 是用户自有 React 组件的源码位置,不是组件注册表。
360
+ - 原生 React import 仍然只是普通 MDX import;只有内置语义组件不够用时,才使用项目本地组件。
361
+ - build 前建议先运行 `mdx-artifacts validate <file.mdx>`,提前暴露当前支持的路径、组件和诊断问题。
110
362
 
111
363
  ## 设计原则
112
364
 
113
365
  - 源文件是 MDX,不是裸 HTML。
366
+ - 源文件应该保持 Markdown-native;输出可以是更丰富的交互式 HTML。
367
+ - 组件是文档中的语义岛,不是整个写作模型。
114
368
  - 组件 API 要语义化,避免让 Agent 手写布局。
115
- - 交互工具必须提供导出能力。
369
+ - 人类可读正文优先使用 MDX children 或显式 slot,不要长期塞在长字符串 props 中。
370
+ - props 适合承载 id、短标签、变体、布局控制和结构化数据。
371
+ - 交互工具应该提供导出能力;缺失时 `validate` 会给出 warning。
116
372
  - 大数据后续应放到相邻 JSON 文件,不要塞进 MDX props。
117
373
  - 核心组件保持 React/TypeScript,可被 Vite、Astro、Claude artifact builder 复用。
118
374
  - Tailwind 作为内部样式构建能力,最终仍输出内联 CSS 的单 HTML。
@@ -127,3 +383,4 @@ export default config;
127
383
  - [英文组件协议](docs/component-protocol.md)
128
384
  - [英文组件分类](docs/component-taxonomy.md)
129
385
  - [英文测试协议](docs/testing.md)
386
+ - [英文发布检查清单](docs/releasing.md)
@@ -1,13 +1,24 @@
1
- # Artifact Kit Agent Instructions
1
+ # MDX Artifacts Agent Instructions
2
2
 
3
- When creating an interactive report, option comparison, temporary tool, or visual explanation page:
3
+ Use MDX Artifacts when the user asks for an interactive report, option comparison, review handoff, temporary tool, or visual explanation page that should be authored as Markdown-native MDX.
4
4
 
5
- 1. Do not generate raw HTML unless explicitly requested.
6
- 2. Create `.mdx` files under `artifact-docs/`.
5
+ Do not use MDX Artifacts for ordinary README files, simple notes, raw HTML pages, full web apps, or cases where the user explicitly asks for plain Markdown.
6
+
7
+ Authoring rules:
8
+
9
+ 1. Create `.mdx` files under the configured `docsDir`. If no config exists, use `artifact-docs/`.
10
+ 2. Keep prose in Markdown and use semantic React components as islands.
7
11
  3. Prefer high-level components from `mdx-artifacts/react`.
8
- 4. Interactive artifacts must include `ExportPanel` or an equivalent export path.
9
- 5. Do not inline bulky data in JSX props. Prefer adjacent `.json` files.
10
- 6. Run `artifact-kit components <ComponentName>` when component props are unclear.
11
- 7. Run `artifact-kit components --json` when machine-readable component metadata is needed.
12
- 8. Run `artifact-kit validate <file.mdx>` before build.
13
- 9. Run `artifact-kit build <file.mdx>` to produce standalone HTML.
12
+ 4. Prefer MDX children for human-readable body content when a component supports it.
13
+ 5. Use props for stable ids, short labels, variants, layout controls, export values, and structured data.
14
+ 6. Do not inline bulky data in JSX props. Prefer adjacent local files when the project supports them.
15
+ 7. Local resource paths must stay inside the project root. Do not use remote URLs, `~` paths, or project-root escapes.
16
+ 8. Interactive artifacts must include `ExportPanel` or an equivalent export path.
17
+ 9. Run `mdx-artifacts components <ComponentName>` when component props are unclear.
18
+ 10. Run `mdx-artifacts components --json` when machine-readable component metadata is needed.
19
+ 11. Run `mdx-artifacts validate <file.mdx>` before build.
20
+ 12. Run `mdx-artifacts validate <file.mdx> --json` when structured diagnostics are useful for repairs.
21
+ 13. If validation reports diagnostics, fix errors first, review warnings, and validate again.
22
+ 14. Run `mdx-artifacts build <file.mdx>` to produce standalone HTML.
23
+
24
+ For project-local components, choose a stable project-local component source directory and include it in `tailwindSources` when those files use Tailwind classes. This directory is a source location for user-owned React components, not automatic component registration.
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  Callout,
3
3
  CommentTarget,
4
- DecisionMatrix,
4
+ ContentSet,
5
5
  ExportPanel,
6
- OptionGrid,
7
6
  Section,
8
7
  } from "mdx-artifacts/react";
9
8
 
@@ -11,38 +10,38 @@ import {
11
10
 
12
11
  This example shows a local block-level comment loop. The author marks stable review targets with `Section` or component ids, the reader adds comments in the browser, and artifact state is saved beside the MDX file during local dev.
13
12
 
14
- <DecisionMatrix
15
- id="decision.comment-targets"
16
- question="Should comment targets be explicit blocks in v1?"
17
- options={[
18
- {
19
- id: "explicit",
20
- name: "Explicit comment blocks",
21
- summary:
22
- "Authors wrap reviewable sections with a stable block id and title.",
23
- pros: [
24
- "Stable export target",
25
- "Works for prose and components",
26
- "Does not change existing component props",
27
- ],
28
- cons: ["Adds one wrapper around reviewable regions"],
29
- confidence: "high",
30
- verdict: "Recommended for v1",
31
- },
32
- {
33
- id: "implicit",
34
- name: "Implicit component comments",
35
- summary: "Every artifact component becomes commentable by default.",
36
- pros: ["Less explicit authoring syntax"],
37
- cons: [
38
- "Cannot naturally target prose",
39
- "Requires changing many component APIs",
40
- ],
41
- confidence: "medium",
42
- verdict: "Defer until block comments prove useful",
43
- },
44
- ]}
45
- />
13
+ <ContentSet
14
+ id="set.comment-targets"
15
+ title="Should comment targets be explicit blocks in v1?"
16
+ layout="grid"
17
+ columns={2}
18
+ >
19
+ <ContentSet.Item
20
+ id="explicit"
21
+ title="Explicit comment blocks"
22
+ badge="Recommended"
23
+ tone="positive"
24
+ emphasis="primary"
25
+ summary="Authors wrap reviewable sections with a stable block id and title."
26
+ >
27
+ - Stable export target
28
+ - Works for prose and components
29
+ - Does not change existing component props
30
+ - Adds one wrapper around reviewable regions
31
+ </ContentSet.Item>
32
+ <ContentSet.Item
33
+ id="implicit"
34
+ title="Implicit component comments"
35
+ badge="Deferred"
36
+ tone="warning"
37
+ emphasis="subtle"
38
+ summary="Every artifact component becomes commentable by default."
39
+ >
40
+ - Less explicit authoring syntax
41
+ - Cannot naturally target prose
42
+ - Requires changing many component APIs
43
+ </ContentSet.Item>
44
+ </ContentSet>
46
45
 
47
46
  <Section id="section.prose-guidance">
48
47
 
@@ -66,41 +65,47 @@ Use section comments when feedback should attach to a visible native MDX region:
66
65
 
67
66
  </Section>
68
67
 
69
- <OptionGrid
70
- id="option.comment-flow"
68
+ <ContentSet
69
+ id="set.comment-flow"
71
70
  title="Comment workflow pieces"
72
- options={[
73
- {
74
- id: "layer",
75
- name: "CommentLayer",
76
- intent:
77
- "The artifact shell now provides this review context automatically.",
78
- tradeoffs: [
79
- "No production backend",
80
- "Local dev persists to sidecar state",
81
- ],
82
- },
83
- {
84
- id: "section",
85
- name: "Section",
86
- intent:
87
- "Marks native MDX prose with a stable anchor id while keeping native headings in the section body.",
88
- tradeoffs: [
89
- "Clear review context",
90
- "Authors choose the section boundary",
91
- ],
92
- },
93
- {
94
- id: "export",
95
- name: "ExportPanel",
96
- intent: "Exports the artifact result when a static handoff is needed.",
97
- tradeoffs: [
98
- "Agent-friendly handoff",
99
- "State is handled by the local dev shell",
100
- ],
101
- },
102
- ]}
103
- />
71
+ layout="grid"
72
+ columns={3}
73
+ >
74
+ <ContentSet.Item
75
+ id="layer"
76
+ title="CommentLayer"
77
+ tone="info"
78
+ summary="The artifact shell now provides this review context automatically."
79
+ >
80
+ Use this as the shared review context for local browser comments.
81
+
82
+ - No production backend
83
+ - Local dev persists to sidecar state
84
+ </ContentSet.Item>
85
+ <ContentSet.Item
86
+ id="section"
87
+ title="Section"
88
+ tone="accent"
89
+ emphasis="primary"
90
+ summary="Marks native MDX prose with a stable anchor id while keeping native headings in the section body."
91
+ >
92
+ Use this when feedback should attach to visible native MDX prose.
93
+
94
+ - Clear review context
95
+ - Authors choose the section boundary
96
+ </ContentSet.Item>
97
+ <ContentSet.Item
98
+ id="export"
99
+ title="ExportPanel"
100
+ tone="neutral"
101
+ summary="Exports the artifact result when a static handoff is needed."
102
+ >
103
+ Use this for copying the result and associated review context back into the workflow.
104
+
105
+ - Agent-friendly handoff
106
+ - State is handled by the local dev shell
107
+ </ContentSet.Item>
108
+ </ContentSet>
104
109
 
105
110
  <CommentTarget
106
111
  targetId="custom-comment-target"
@@ -111,8 +116,9 @@ Use section comments when feedback should attach to a visible native MDX region:
111
116
  id="callout.custom-target"
112
117
  tone="warning"
113
118
  title="Custom targets still work"
114
- body="Use CommentTarget when an artifact has a smaller local region that should be commentable without turning the whole section into a target."
115
- />
119
+ >
120
+ Use CommentTarget when an artifact has a smaller local region that should be commentable without turning the whole section into a target.
121
+ </Callout>
116
122
  </CommentTarget>
117
123
 
118
124
  <ExportPanel