Agent 生成协议

Agent 生成协议

MiniKit 文档不仅给开发者阅读,也给 Agent 读取。生成器应优先使用基础组件,只有明确需要绘图、媒体、相机或地图时才使用能力组件。

机器可读入口

入口说明
agent-pack.json完整上下文:组件、API、Schema、模板、诊断和质量门禁。
component-manifest.json轻量组件 manifest。
api-manifest.json轻量 API manifest。
llms.txt面向 AI 工具的文档入口。

生成守则

  • Agent 生成的小程序只能使用标准组件。
  • 复杂应用优先使用源码项目结构:app.js 引入 pages/ 与 tests/,miniapp.json 声明构建输出,manifest.json 和 app-service.js 由构建生成。
  • 不要手工编辑生成产物 app-service.js 或 manifest.json;发布前应从 SDK 源码重新生成归档。
  • 优先使用基础布局、表单、内容和导航组件;只有明确需要时才生成 canvas、diagram-view、媒体、相机或地图能力组件。
  • canvas、diagram-view、媒体、相机和地图都属于能力组件,需要声明权限和 manifest.apisUsed,并调用对应 ac.* API。
  • Mermaid 编辑场景应配合 code-editor 与 diagram-view;渲染使用 ac.renderMermaid,导出或复制图片可配合 ac.captureNode 与 ac.setClipboardImage。
  • 网络、文件、权限、剪贴板、位置、分享、扫码、Socket 和流式 API 都需要在 manifest.apisUsed 中声明对应 ac.* 调用。
  • 页面脚本优先使用 script: ({ Page, ac }) => Page(...),并通过 await ac.<method>(params) 调用宿主 API。
  • 只有需要节点测量时才使用 ac.createSelectorQuery;不要直接访问 DOM API。
  • 官方 AppsChat API 统一命名为 ac.*;页面实例 this 只用于状态和 this.setData,宿主能力通过捕获到的 ac 命名空间调用。
  • 路由变化使用 ac.navigateTo、ac.redirectTo 和 ac.navigateBack。
  • 需要的权限必须声明在 manifest.permissions。
  • 主要用户流程需要添加可执行 manifest.tests。
  • 打包前运行 miniapp report --require-tests。

质量门禁

[
  {
    "id": "schema",
    "command": "node scripts/miniapp.mjs validate <module> --smoke --json",
    "args": [
      "validate",
      "<module>",
      "--smoke",
      "--json"
    ],
    "passWhen": "ok is true and smoke.nonEmptyHtml is true"
  },
  {
    "id": "manifestTests",
    "command": "node scripts/miniapp.mjs report <module> --require-tests --json",
    "args": [
      "report",
      "<module>",
      "--require-tests",
      "--json"
    ],
    "passWhen": "tests.ok is true and tests.count is greater than 0"
  },
  {
    "id": "snapshot",
    "command": "node scripts/miniapp.mjs snapshot <module> --json",
    "args": [
      "snapshot",
      "<module>",
      "--json"
    ],
    "passWhen": "htmlBytes is greater than 0 and components match the intended UI"
  },
  {
    "id": "package",
    "command": "node scripts/miniapp.mjs pack <module> --out record.json --require-tests --json",
    "args": [
      "pack",
      "<module>",
      "--out",
      "record.json",
      "--require-tests",
      "--json"
    ],
    "passWhen": "ok is true and outputFile exists"
  }
]