wormaworma

AI 文档生成器

生成 AI 可读的接口知识文档,让编码助手准确感知项目 API

AI 文档生成器

本插件用于自动生成符合 Skills 规范的接口知识文档,让编码助手准确感知项目中的所有 API,避免对函数名和参数进行猜测。通常与其他模板(alova、axios 等)配合使用。

主要功能

  • 自动生成 SKILL.md 总览索引和按 tag 分组的 API 参考文档
  • 支持自定义模板路径和输出目录
  • 支持自动安装 Skill 到主流编码助手(Cursor、Claude Code、Windsurf 等)

基本使用

import { defineConfig } from "wormajs";
import { alova, aiDoc } from "wormajs/plugin";

export default defineConfig({
  generator: [
    {
      input: "https://api.example.com/openapi.json",
      output: "src/api",
      plugins: [alova(), aiDoc()],
    },
  ],
});

配置参数

interface AiDocConfig {
  /** 自定义模板路径,不传则使用内置模板 */
  template?: string;
  /** 输出目录名,默认为 'aidocs' */
  outputDir?: string;
  /** 是否自动安装 Skill 到编码助手,默认 false */
  installSkill?: boolean;
}

function aiDoc(config?: AiDocConfig): ApiPlugin;

参数说明

参数名类型默认值描述
templatestring自定义模板路径,不传则使用内置模板
outputDirstring'aidocs'输出目录名
installSkillbooleanfalse是否自动安装 Skill 到编码助手

生成结构

SKILL.md
addPet.md
getPetById.md
findPetsByStatus.md
  • SKILL.md:总览索引,列出所有 API 端点和对应文档链接
  • references/{tag}/{api}.md:按 tag 分组,每个 API 端点一个独立文档,包含请求方法、路径、参数 Schema 和请求/响应示例

关于生成内容的结构详情和使用方式,请参阅 AI Skills 集成

自动安装 Skill

启用 installSkill: true 后,执行 worma gen 时会自动将生成的 Skill 安装到编码助手中。

配置步骤

  1. 在项目根目录创建 .env.local,配置编码助手名称:
# Worma aiDoc skill installer configuration
# Please set the coding agent you are using (e.g. cursor, claude-code, windsurf).
# Supported agents list: https://www.npmjs.com/package/skills#supported-agents
agent=cursor
  1. 运行生成命令
worma gen

worma 会读取 .env.local 中的 agent 配置,自动将生成的 Skill 安装到对应助手中。支持的主流编码助手列表请参考 skills 文档

.env.local 首次运行时如不存在会自动创建,并在 .gitignore 中追加 *.local 规则,避免敏感配置被提交。

On this page