Codewiki Generator
Overview
Generate a DeepWiki-style, code-first documentation site for a given repository. The output will reside in the
codewiki/ directory, including a VitePress configuration and an auto-generated sidebar. The documentation must reflect the project's current state and prioritize explaining the system's design rationale over merely describing its functionality.
Workflow
0) Confirm Language Preference
Ask the user: "What language should the documentation be written in? (e.g., English, 中文, 日本語, etc.)"
IF the user specifies a language THEN store the provided language and apply it to all generated prose content.
ELSE IF the user does not specify a language THEN default to English.
1) Inspect the Codebase First (Code > Docs)
- - Scan source files, configuration files, build/test pipelines, entry points, and architectural directories.
- Treat existing documentation (e.g.,
README, docs/) as secondary hints. - Prioritize code evidence as the ultimate source of truth.
- Identify and report any discrepancies between documentation and code.
2) Analyze Codebase → Structured Metadata
Execute the analyzer script to scan the codebase and generate structured metadata.
<skill-root> refers to the directory containing this
SKILL.md.
CODEBLOCK0
This command generates the following outputs:
- -
codewiki/.meta/ directory containing deps.json, entrypoints.json, evidence.json, doc_plan.json, and symbols.json (if ctags is available). - INLINECODE11 detailing coverage and pages with low confidence.
- VitePress configuration scaffolding, without placeholder
.md files.
Note: This step does not generate placeholder .md files. The LLM is responsible for writing documentation content directly in Step 4.
Note: Images referenced in existing Markdown files are copied into codewiki/assets/.
3) Dynamically Determine the Documentation Set
- - Include all minimally required pages.
- Add conditional modules only when corresponding code evidence exists.
- Split or merge pages based on project size and complexity.
- Adhere to the guidelines specified in
references/structure-and-heuristics.md. - Use lowercase directory and file names for all generated documentation.
4) Write the Documentation (Code-first, Visual-first)
Read
codewiki/.meta/doc_plan.json and process each planned page:
- - IF a page has no supporting evidence OR low relevance to the codebase THEN skip that page.
- ELSE create an
.md file only for pages containing actual content.
Writing guidelines:
- - Use the language determined in Step 0 for all prose content.
- Retain original formatting for code snippets, file paths, and technical terms.
- Start every page with a low-contrast
# Related Code block (fenced text block), not a heading. - Utilize Mermaid for diagrams (context, class, sequence, component, dataflow).
- Adhere to Mermaid-safe syntax: use simple node IDs, avoid
/, (), and : in labels, and prefer node[plain label]. - Explain the rationale behind design choices, trade-offs, and constraints.
- Provide informed opinions: highlight strengths, technical debt, or "code smells."
- Link concepts to specific file paths, classes, or entry points.
- Reuse existing images/diagrams IF they are accurate.
- Maintain Markdown lint-friendly practices: consistent headings, no trailing spaces, and proper list formatting.
Refer to references/doc-templates.md for detailed, evidence-linked page templates.
5) Refresh Sidebar and Run the Site
After documentation generation, update the sidebar to reflect the actual files:
CODEBLOCK1
Install documentation dependencies (Mermaid support is enabled by default):
CODEBLOCK2
Launch the documentation site:
CODEBLOCK3
Alternative launch command (without prior npm install):
CODEBLOCK4
6) Offer Optional Workflows
After the site is operational, inform the user about available options:
"Documentation site is ready! You can now:
- - Option A: Deploy to Cloudflare Pages — publish the site to a live URL
- Option B: Add multi-language support (i18n) — translate docs to another language
Let me know if you'd like to proceed with any of these."
Optional Workflows
These workflows are available for execution after the core documentation generation process is complete.
Option A) Deploy to Cloudflare Pages
Deploy the documentation site to Cloudflare Pages using the wrangler CLI.
Trigger: The user requests to deploy, publish, or host the documentation.
See: references/deploy-cloudflare.md for comprehensive instructions (including wrangler installation, login verification, build process, deployment, and updating index.md with the live URL).
Option B) Add Multi-language Support (i18n)
Translate existing documentation into a second language and configure the VitePress language switcher.
Trigger: The user requests translation, multi-language, or internationalization (i18n) support.
See: references/i18n-setup.md for comprehensive instructions (including directory structure, VitePress locales configuration, and translation guidelines).
Quality Bar (Non-negotiable)
- - Visual First: Prioritize diagrams over extensive text blocks.
- Insightful: Explain design intent beyond mere mechanics.
- Opinionated: Highlight architectural strengths and identified risks.
- Linked: Reference concrete files/classes for all key concepts.
- Code-first: The codebase is the authoritative source; documentation serves as a complementary explanation.
Resources
scripts/
- -
codewiki_analyze.py: Scans the codebase and generates .meta/*.json metadata files. - INLINECODE34 : Scaffolds the
codewiki/ directory, copies referenced images, and generates the sidebar.
references/
- -
structure-and-heuristics.md: Contains rules for module selection and signal identification. - INLINECODE37 : Provides comprehensive, evidence-linked templates for all page types.
- INLINECODE38 : Details the workflow for deploying to Cloudflare Pages.
- INLINECODE39 : Outlines the configuration process for multi-language support.
assets/
- -
vitepress/: Contains minimal VitePress configuration and a landing page template.
Codewiki Generator
概述
为指定仓库生成DeepWiki风格的、以代码优先的文档站点。输出将存放在codewiki/目录中,包含VitePress配置和自动生成的侧边栏。文档必须反映项目的当前状态,并优先解释系统的设计原理,而非仅仅描述其功能。
工作流程
0) 确认语言偏好
询问用户:文档应使用哪种语言编写?(例如,English, 中文, 日本語等)
如果用户指定了语言,则存储该语言并将其应用于所有生成的散文内容。
否则,如果用户未指定语言,则默认使用英语。
1) 先检查代码库(代码优先于文档)
- - 扫描源文件、配置文件、构建/测试流水线、入口点和架构目录。
- 将现有文档(例如README、docs/)视为次要参考。
- 优先将代码证据作为最终事实来源。
- 识别并报告文档与代码之间的任何差异。
2) 分析代码库 → 结构化元数据
执行分析器脚本以扫描代码库并生成结构化元数据。
指包含此SKILL.md的目录。
bash
python3 /scripts/codewiki_analyze.py \
--repo-root \
--out-dir codewiki \
--force
此命令生成以下输出:
- - codewiki/.meta/目录,包含deps.json、entrypoints.json、evidence.json、doc_plan.json和symbols.json(如果ctags可用)。
- codewiki/quality-report.md,详细说明覆盖范围和低置信度页面。
- VitePress配置脚手架,不包含占位符.md文件。
注意:此步骤不生成占位符.md文件。LLM负责在第4步直接编写文档内容。
注意:现有Markdown文件中引用的图像将被复制到codewiki/assets/中。
3) 动态确定文档集
- - 包含所有最低要求的页面。
- 仅当存在相应代码证据时,才添加条件模块。
- 根据项目规模和复杂性拆分或合并页面。
- 遵循references/structure-and-heuristics.md中指定的指南。
- 所有生成的文档使用小写目录和文件名。
4) 编写文档(代码优先、视觉优先)
读取codewiki/.meta/doc_plan.json并处理每个计划页面:
- - 如果页面没有支持证据或与代码库相关性低,则跳过该页面。
- 否则,仅为包含实际内容的页面创建.md文件。
编写指南:
- - 所有散文内容使用第0步确定的语言。
- 保留代码片段、文件路径和技术术语的原始格式。
- 每个页面以低对比度的# Related Code块(围栏text块)开头,而非标题。
- 使用Mermaid绘制图表(上下文图、类图、序列图、组件图、数据流图)。
- 遵循Mermaid安全语法:使用简单节点ID,避免在标签中使用/、()和:,优先使用node[plain label]。
- 解释设计选择、权衡和约束背后的原理。
- 提供有见地的意见:突出优势、技术债务或代码异味。
- 将概念链接到具体的文件路径、类或入口点。
- 如果现有图像/图表准确,则重复使用。
- 保持Markdown lint友好实践:一致的标题、无尾随空格和正确的列表格式。
有关详细且带有证据链接的页面模板,请参阅references/doc-templates.md。
5) 刷新侧边栏并运行站点
文档生成后,更新侧边栏以反映实际文件:
bash
python3 /scripts/codewiki_bootstrap.py \
--repo-root \
--out-dir codewiki \
--refresh-sidebar
安装文档依赖项(默认启用Mermaid支持):
bash
npm --prefix codewiki install
启动文档站点:
bash
npm --prefix codewiki run docs:dev
替代启动命令(无需事先执行npm install):
bash
npx -p vitepress -p vitepress-plugin-mermaid -p mermaid vitepress dev codewiki
6) 提供可选工作流程
站点运行后,告知用户可用选项:
文档站点已就绪!您现在可以:
- - 选项A:部署到Cloudflare Pages — 将站点发布到在线URL
- 选项B:添加多语言支持(i18n)— 将文档翻译为其他语言
如果您希望继续执行任何操作,请告知。
可选工作流程
这些工作流程可在核心文档生成过程完成后执行。
选项A) 部署到Cloudflare Pages
使用wrangler CLI将文档站点部署到Cloudflare Pages。
触发条件:用户请求部署、发布或托管文档。
参见:references/deploy-cloudflare.md获取完整说明(包括wrangler安装、登录验证、构建过程、部署以及使用在线URL更新index.md)。
选项B) 添加多语言支持(i18n)
将现有文档翻译为第二种语言,并配置VitePress语言切换器。
触发条件:用户请求翻译、多语言或国际化(i18n)支持。
参见:references/i18n-setup.md获取完整说明(包括目录结构、VitePress locales配置和翻译指南)。
质量标准(不可协商)
- - 视觉优先:优先使用图表而非大量文本块。
- 有见地:解释设计意图,超越单纯机制。
- 有观点:突出架构优势和已识别的风险。
- 可链接:所有关键概念引用具体文件/类。
- 代码优先:代码库是权威来源;文档作为补充说明。
资源
scripts/
- - codewikianalyze.py:扫描代码库并生成.meta/*.json元数据文件。
- codewikibootstrap.py:搭建codewiki/目录结构,复制引用的图像,并生成侧边栏。
references/
- - structure-and-heuristics.md:包含模块选择和信号识别的规则。
- doc-templates.md:为所有页面类型提供完整且带有证据链接的模板。
- deploy-cloudflare.md:详细说明部署到Cloudflare Pages的工作流程。
- i18n-setup.md:概述多语言支持的配置过程。
assets/
- - vitepress/:包含最小的VitePress配置和登录页面模板。