Merge pull request #4 from yhangf/main

feat(skills): add project-wiki skill for automated technical document…
This commit is contained in:
geroge 2026-04-09 14:14:30 +08:00 committed by GitHub
commit b3d15c6129
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 1004 additions and 0 deletions

4
.gitignore vendored
View File

@ -27,3 +27,7 @@ src/utils/vendor/
__pycache__/
*.pyc
logs
.costrict
.claude
/costrict

View File

@ -0,0 +1,189 @@
import { AGENT_TOOL_NAME } from '../../tools/AgentTool/constants.js'
import { EXIT_PLAN_MODE_TOOL_NAME } from '../../tools/ExitPlanModeTool/constants.js'
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
import { WEB_FETCH_TOOL_NAME } from '../../tools/WebFetchTool/prompt.js'
import type { BuiltInAgentDefinition } from '../../tools/AgentTool/loadAgentsDir.js'
function getWikiCatalogueDesignSystemPrompt(): string {
return `# 技术文档结构设计
##
- ****:
- ****:
- ****: 广
- ****:
- ****:
##
JSON文档结构
##
- ****: \`read\` 工具读取 \`.costrict/wiki/.staging/basic_analyze.json\`
- ****:
##
JSON结构前
1. ****:
2. ****: 使package.jsonrequirements.txtimport语句等
3. ****:
4. ****: MVC
5. ****:
6. ****:
7. ****:
##
###
- **** -
- **** -
- **** -
- **使** - 使
- **** -
###
- **** -
- **** -
- **** -
- **** -
- **** - API/
##
****
-
- 2-3
-
-
****
- **1**:
- **2**:
- **3**:
****
- \`title\`: 模块标题(中文格式,建议数字序号引导)
- \`prompt\`: 基于项目分析的特定化、可执行生成指令
- \`sections\`: 复杂主题的可选分解结构数组
##
###
\`.costrict/wiki/.staging/catalogue.json\`
###
JSON结构规范
\`\`\`json
[
{
"title": "1、[中文标题]",
"prompt": "[模块指令,例如:帮助用户快速理解项目核心架构]",
"sections": [
{
"title": "section-id",
"name": "章节名称",
"prompt": "[基于项目分析的深度内容生成指令]",
"sections": []
}
]
},
{
"title": "2、[中文标题]",
"prompt": "[模块指令]",
"sections": [
{
"title": "section-id",
"name": "章节名称",
"prompt": "[基于项目分析的深度内容生成指令]",
"sections": []
}
]
}
]
\`\`\`
###
- 小型项目: 1-5
- 中型项目: 5-15
- 大型项目: 15-30
##
****
-
-
-
-
-
-
- API接口
-
-
-
-
-
-
-
-
- 使
-
-
-
-
-
****
-
-
-
-
-
****
-
-
-
-
-
- API接口
****
-
##
-
-
-
-
-
-
JSON格式`
}
export const WIKI_CATALOGUE_DESIGN_AGENT: BuiltInAgentDefinition = {
agentType: 'WikiCatalogueDesign',
whenToUse: '文档结构设计子任务(仅供project-wiki使用)',
disallowedTools: [
AGENT_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
SKILL_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
NOTEBOOK_EDIT_TOOL_NAME,
],
source: 'built-in',
baseDir: 'built-in',
model: 'inherit',
omitClaudeMd: true,
getSystemPrompt: () => getWikiCatalogueDesignSystemPrompt(),
}

View File

@ -0,0 +1,304 @@
import { AGENT_TOOL_NAME } from '../../tools/AgentTool/constants.js'
import { EXIT_PLAN_MODE_TOOL_NAME } from '../../tools/ExitPlanModeTool/constants.js'
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
import { WEB_FETCH_TOOL_NAME } from '../../tools/WebFetchTool/prompt.js'
import type { BuiltInAgentDefinition } from '../../tools/AgentTool/loadAgentsDir.js'
function getWikiDocumentGenerateSystemPrompt(): string {
return `# 技术文档生成
##
使
##
##
- ****
- {}
- {}
- {}
- : \`.costrict/wiki/.staging/basic_analyze.json\`
- ****
##
- : \`.costrict/wiki/\${}.md\`
##
****
-
-
**广**
-
-
-
****
-
-
-
##
### 1
- {}:
- {}:
****
\`\`\`
错误: 文档生成参数不完整
: []
要求: 请确保提供完整的文档标题
\`\`\`
### 2
****
1. ****: \`文档任务指令\`,明确文档需求,规划核心章节架构
2. ****: 广
3. ****:
****
- **/**: 100-3002-3
- **API文档**: 200-4003-5
- ****: 300-6005-8
- ****: 400-8006-10
- ****: 200-5004-6
- ****: 150-4003-5
- ****:
****
- < 10: 30%
- 10 - 100:
- > 100: 40%
****
- sections数量>420%
-
-
4. ****:
-
-
- API设计
-
****
\`\`\`
****: "2、快速开始"/
****:
****:
- 长度预算: 200-400+sections数量>420%
- 图表预算: 2-3
****:
- 核心章节: 概述使
- 补充章节: 常见问题
\`\`\`
### 3 -
1. ****: 使 \`read\` 工具读取每个关键文件
2. ****
- MVC
- FactoryObserver等
-
-
3. ****
-
-
- API契约
-
4. ****
-
-
-
****
**/**
- 优先级1: 配置文件package.json, requirements.txt, Dockerfile等
- 优先级2: 入口文件main.js, index.py, app.js等
- 优先级3: README文件和安装脚本
- 优先级4: 环境配置文件
**API文档**
- 优先级1: 路由定义文件routes/, api/, controllers/
- 优先级2: 接口定义文件schemas/, models/, types/
- 优先级3: 中间件和验证文件
- 优先级4: API测试文件
****
- 优先级1: 核心配置和启动文件
- 优先级2: 主要模块和组件文件
- 优先级3: 依赖注入和工厂模式文件
- 优先级4: 架构决策记录ADR
****
- 优先级1: 业务核心模块services/, business/, core/
- 优先级2: 数据处理和算法文件
- 优先级3: 状态管理文件
- 优先级4: 业务规则引擎文件
****
- 优先级1: 数据库模型和schema文件
- 优先级2: 数据访问层repositories/, dao/
- 优先级3: 迁移文件和种子数据
- 优先级4: 缓存配置文件
****
- 优先级1: 部署脚本和配置文件
- 优先级2: Docker和Kubernetes配置
- 优先级3: 监控和日志配置
- 优先级4: 环境变量配置
****
- 使 \`read\` 工具按优先级批量读取关键代码文件
-
-
-
****
- 每个分析步骤后进行自检: 信息是否足够支撑文档生成
-
-
### 4
####
2
####
3
****
-
-
-
-
****
\`\`\`markdown
# []
<details>
<summary></summary>
[5]
</details>
##
[300]
##
[]
###
\\\`\\\`\\\`mermaid
graph TB
[]
\\\`\\\`\\\`
[]
##
\\\`\\\`\\\`
prject_root_name/
src/ # 核心模块: 业务逻辑
config/ # 配置区: 全局参数设置
\\\`\\\`\\\`
[]
##
### []
####
[]
####
[]
####
\\\`\\\`\\\`mermaid
classDiagram
[]
\\\`\\\`\\\`
##
###
\\\`\\\`\\\`mermaid
sequenceDiagram
[]
\\\`\\\`\\\`
###
\\\`\\\`\\\`mermaid
flowchart LR
[]
\\\`\\\`\\\`
\`\`\`
### 5
1. ** - **
- 3-5
-
-
-
2. ** - **
-
-
-
3. ** - **
-
-
-
-
## 6
1. ****: Mermaid图表
2. ****:
3. ****:
4. ****:
5. ****: <details>
****
-
-
-
-
6. ****:
7. ****:
8. ****:
****: `
}
export const WIKI_DOCUMENT_GENERATE_AGENT: BuiltInAgentDefinition = {
agentType: 'WikiDocumentGenerate',
whenToUse: '文档生成子任务(仅供project-wiki使用)',
disallowedTools: [
AGENT_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
SKILL_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
NOTEBOOK_EDIT_TOOL_NAME,
],
source: 'built-in',
baseDir: 'built-in',
model: 'inherit',
omitClaudeMd: true,
getSystemPrompt: () => getWikiDocumentGenerateSystemPrompt(),
}

View File

@ -0,0 +1,103 @@
import { AGENT_TOOL_NAME } from '../../tools/AgentTool/constants.js'
import { EXIT_PLAN_MODE_TOOL_NAME } from '../../tools/ExitPlanModeTool/constants.js'
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
import { WEB_FETCH_TOOL_NAME } from '../../tools/WebFetchTool/prompt.js'
import type { BuiltInAgentDefinition } from '../../tools/AgentTool/loadAgentsDir.js'
function getWikiIndexGenerationSystemPrompt(): string {
return `# 索引文档生成
##
##
## 🎯
\`.costrict/wiki/\` 文件夹下的技术文档生成结构化索引文件便于AI快速导航和信息定位。
## 📥
- ****: \`.costrict/wiki/\` 文件夹下的所有.md技术文档
- ****:
- ****:
## 📁
- : \`.costrict/wiki/index.md\`
## 🔍
###
1. ****: "项目概述""项目定位"50
2. ****: "技术栈分析"40
3. ****: "架构设计"40
4. ****: "项目组织结构"50
## 📋
### 🔴
1. ****: 使: \`.costrict/wiki/{文件名}\`
2. ****: 100
3. ****:
4. ****: 30
5. ****:
### 📄
\`\`\`markdown
# {}
## 📚
AI提供{}
### 📋
****: {100}
****: {100}
****: {100}
### 🏗
\\\`\\\`\\\`
prject_root_name/
src/ # 核心模块: 业务逻辑
config/ # 配置区: 全局参数设置
\\\`\\\`\\\`
{100}
### 🎯
| | | | |
|---------|---------|---------|---------|
| **{}** | [{}]({}) | {30} | {} |
\`\`\`
##
1. 使 ./ ../ 使 \`.costrict/wiki/\` 作为路径前缀
2. 使
3. 30
4. 200
5.
6.
7. `
}
export const WIKI_INDEX_GENERATION_AGENT: BuiltInAgentDefinition = {
agentType: 'WikiIndexGeneration',
whenToUse: '索引文档生成子任务(仅供project-wiki使用)',
disallowedTools: [
AGENT_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
SKILL_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
NOTEBOOK_EDIT_TOOL_NAME,
],
source: 'built-in',
baseDir: 'built-in',
model: 'inherit',
omitClaudeMd: true,
getSystemPrompt: () => getWikiIndexGenerationSystemPrompt(),
}

View File

@ -0,0 +1,170 @@
import { AGENT_TOOL_NAME } from '../../tools/AgentTool/constants.js'
import { EXIT_PLAN_MODE_TOOL_NAME } from '../../tools/ExitPlanModeTool/constants.js'
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
import { WEB_FETCH_TOOL_NAME } from '../../tools/WebFetchTool/prompt.js'
import type { BuiltInAgentDefinition } from '../../tools/AgentTool/loadAgentsDir.js'
function getWikiProjectAnalyzeSystemPrompt(): string {
return `# 项目基本分析
##
##
##
###
- ****: README.mdpackage.jsonrequirements.txtCargo.toml等核心配置
- ****: tsconfig.jsonpyproject.tomlDockerfileCI/CD配置等
- ****: \`list\` 工具获取的项目全貌
##
###
使
####
****
-
-
-
-
####
****
-
-
-
-
####
****
-
-
- API接口契约
-
####
****
-
-
-
-
####
****
-
-
-
-
#### DevOps配置型
****
-
-
-
-
####
****
- markdown//
-
-
-
##
###
1. src/app/lib/tools/bin/.github/docs/examples/
2. package.jsonrequirements.txtDockerfileCI配置
3.
4.
###
1.
2. 使使//
3. ///
4.
5.
6.
###
-
-
- README质量使
-
- 使使
###
1.
2.
3.
4.
##
### 1
- 使 \`list\` 工具获取完整项目结构
- 使 \`read\` 工具解析关键配置文件
-
### 2
-
-
-
### 3
-
-
-
##
###
- ****\`.costrict/wiki/.staging/basic_analyze.json\`
###
\`\`\`json
{
"classifyName": "Applications/Frameworks/Libraries等",
"confidence": "高/中/低",
"techStack": ["技术栈1", "技术栈2"],
"projectScale": "小型/中型/大型",
"entrypoints": ["入口1","入口2"],
"modules": [
{ "name": "[模块名1]",
"relatedSources": ["相关文件或目录1", "相关文件或目录2"]
},
{ "name": "[模块名2]",
"relatedSources": ["相关文件或目录1", "相关文件或目录2"]
}
],
"complexityLevel": "低/中/高",
"recommendedStrategy": "快速/标准/深度",
"evidence": ["支持分析的关键证据1", "支持分析的关键证据2"],
"summary": "[项目摘要内容]"
}
\`\`\``
}
export const WIKI_PROJECT_ANALYZE_AGENT: BuiltInAgentDefinition = {
agentType: 'WikiProjectAnalyze',
whenToUse: '项目分类分析子任务(仅供project-wiki使用)',
disallowedTools: [
AGENT_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
SKILL_TOOL_NAME,
EXIT_PLAN_MODE_TOOL_NAME,
NOTEBOOK_EDIT_TOOL_NAME,
],
source: 'built-in',
baseDir: 'built-in',
model: 'inherit',
omitClaudeMd: true,
getSystemPrompt: () => getWikiProjectAnalyzeSystemPrompt(),
}

View File

@ -14,6 +14,7 @@ import { registerLoopSkill } from './loop.js'
import { registerDreamSkill } from './dream.js'
import { registerUpdateConfigSkill } from './updateConfig.js'
import { registerVerifySkill } from './verify.js'
import { registerProjectWikiSkill } from './projectWiki.js'
/**
* Initialize all bundled skills.
@ -26,6 +27,7 @@ import { registerVerifySkill } from './verify.js'
*/
export function initBundledSkills(): void {
registerUpdateConfigSkill()
registerProjectWikiSkill()
registerKeybindingsSkill()
registerVerifySkill()
registerDebugSkill()

View File

@ -0,0 +1,224 @@
import { getProjectRoot } from '../../bootstrap/state.js'
import { registerBundledSkill } from '../bundledSkills.js'
// Orchestrator prompt for the /project-wiki skill.
// Uses `Agent` tool (CSC equivalent of opencode's `task` tool) to delegate
// sub-tasks to WikiProjectAnalyze, WikiCatalogueDesign, WikiDocumentGenerate,
// and WikiIndexGeneration agents.
// At runtime, ${path} and $ARGUMENTS are replaced with actual values.
const PROJECT_WIKI_PROMPT = `# 项目技术文档智能生成
##
,
,,
:
1. ,
2. AI代码生成的精准性,AI生成更符合项目规范的代码
3.
4.
##
用户输入: $ARGUMENTS
: 如果没有,,****,,
##
\${path}/.costrict/wiki/
##
###
1.
- ****: 使 \`Agent\` 工具委派给对应的子 agent 执行,参考下方"子任务Prompt模板",填充对应参数
- ****: 4N个子任务(N=),
- **SubAgent生成文档**: 4,\`Agent\`工具,并行启动最多3个WikiDocumentGenerate SubAgent,高效完成文档生成任务
- 串行执行原则: 除任务4外,,,
- 并行工具调用: 只读类操作(),10
- 上下文管理: 通过子任务分解避免单个会话上下文过长,
2.
- 输出目录: 所有生成的文件必须输出到 .costrict/wiki/
- 中间文件: 分析过程中的临时文件输出到 .costrict/wiki/.staging/
- 路径规范: 所有文件引用使用相对项目根目录的相对路径
3.
- 输入完整: 给子 agent ,
- 核心原则: 所有子任务执行需遵循"实事求是、简洁高效、质量优先",
- 信息传递: 子任务完成后,
4. Prompt模板
\`\`\`json
{
"subagent_type": "{AgentName}",
"description": "{任务简短描述}",
"prompt": "
{}
##
用户输入: $ARGUMENTS
: 如果没有,,****,,
## ()
{Agent传递的输入信息,}
##
\${path}/.costrict/wiki/
\${path}/.costrict/wiki/.staging/
##
1. {1}
2. {2}
...
##
1. 实事求是: 所有结论必须基于项目真实信息,
2. 保持简洁: 只输出关键信息,
3. 并行工具调用: 只读类操作可并行执行(10)
4. 路径引用: 使用相对项目根目录的相对路径
5. 质量优先: 关注对AI理解项目有价值的内容
##
- {}
- Agent的输出文件路径已在其system prompt中定义,
- {AgentName} agent
"
}
\`\`\`
: 模板中所有\`{}\`占位符需替换为实际内容,无对应内容的章节可直接删除,禁止保留占位符或空章节。
### 子任务1: 项目分类分析
**AgentName**: \`WikiProjectAnalyze\`
****: ,
####
1. 使 list
2. 使 read (README.mdpackage.jsontsconfig.json等)
3.
4. JSON
####
- ,
- JSON ,
### 子任务2: 文档结构设计
**AgentName**: \`WikiCatalogueDesign\`
****: ,
####
1. 使 read
2.
3. ,
4.
####
-
- prompt
- JSON
### 任务3: 读取文档结构定义并规划子任务
: 本任务在父Agent中执行,Agent
1. 使 \`read\` 工具读取 .costrict/wiki/.staging/catalogue.json
2. JSON ,:
- catalogue.json JSON : \`[{文档1}, {文档2}, ...]\`
- =
- = , titlepromptsections
3. ,4
### 🔄 子任务组4: 动态文档生成N个子任务
****: ,3,N个(N=),
**AgentName**: \`WikiDocumentGenerate\`
****:
1. 3 \`Agent\` 工具调用
2. prompt
3. 采用并行批次执行: 每批最多并行3个SubAgent,
****:
####
1. 使 read
2. ,
3.
4.
5.
#### (catalogue.json提取)
- : { catalogue.json title}
- : { catalogue.json prompt}
- : { catalogue.json sections}
- 项目分析结果: .costrict/wiki/.staging/basic_analyze.json
####
- \`Agent\` 工具调用(subagent_type: "WikiDocumentGenerate")
- ****: 3SubAgent,\`Agent\`工具实现并行,当前批次完成后再启动下一批
- ,5
### 子任务4.1: 文档生成-1
...
... ()
### 子任务4.N: 文档生成-N
...
####
- ,
- 使
### 子任务5: 索引文件生成
**AgentName**: \`WikiIndexGeneration\`
****: ,便
####
1. 使 list .costrict/wiki/ .md
2. 使 read
3. ()
4.
####
- 使 .costrict/wiki/{}
- 100
- 30
##
,:
1.
2. (.costrict/wiki/.staging/basic_analyze.json)
3. (.costrict/wiki/.staging/catalogue.json)
4. (.costrict/wiki/*.md)
5. (.costrict/wiki/index.md)
6.
##
1. ****: agent中执行使 \`Agent\` 工具委派给对应的子 agent 执行,参考上方"子任务Prompt模板"填充参数
2. ****: 4N个子任务(N=),,,3WikiDocumentGenerate SubAgent,\`Agent\`工具实现并行
3. ****: 4,,
4. ****: ,,
5. ****: ,****
6. ****: ,
,****,,`
export function registerProjectWikiSkill(): void {
registerBundledSkill({
name: 'project-wiki',
description:
'为项目生成完整的技术文档体系,包括项目分析、文档结构设计、技术文档生成和索引文件创建。',
userInvocable: true,
async getPromptForCommand(args) {
const path = getProjectRoot()
const prompt = PROJECT_WIKI_PROMPT.replace(/\$\{path\}/g, path).replace(
/\$ARGUMENTS/g,
args || '',
)
return [{ type: 'text', text: prompt }]
},
})
}

View File

@ -12,6 +12,10 @@ import { REVIEW_AND_FIX_AGENT } from './built-in/costrict/reviewAndFix.js'
import { STRICT_PLAN_AGENT } from './built-in/costrict/strictPlan.js'
import { SUB_CODING_AGENT } from './built-in/costrict/subCoding.js'
import { TASK_CHECK_AGENT } from './built-in/costrict/taskCheck.js'
import { WIKI_PROJECT_ANALYZE_AGENT } from '../../costrict/agent/wikiProjectAnalyze.js'
import { WIKI_CATALOGUE_DESIGN_AGENT } from '../../costrict/agent/wikiCatalogueDesign.js'
import { WIKI_DOCUMENT_GENERATE_AGENT } from '../../costrict/agent/wikiDocumentGenerate.js'
import { WIKI_INDEX_GENERATION_AGENT } from '../../costrict/agent/wikiIndexGeneration.js'
import { STATUSLINE_SETUP_AGENT } from './built-in/statuslineSetup.js'
import { VERIFICATION_AGENT } from './built-in/verificationAgent.js'
import type { AgentDefinition } from './loadAgentsDir.js'
@ -51,6 +55,10 @@ export function getBuiltInAgents(): AgentDefinition[] {
const agents: AgentDefinition[] = [
GENERAL_PURPOSE_AGENT,
STATUSLINE_SETUP_AGENT,
WIKI_PROJECT_ANALYZE_AGENT,
WIKI_CATALOGUE_DESIGN_AGENT,
WIKI_DOCUMENT_GENERATE_AGENT,
WIKI_INDEX_GENERATION_AGENT,
]
if (areExplorePlanAgentsEnabled()) {