mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
Refactor project analysis phases: remove diagram generation phase, enhance report generation with detailed structure and quality checks, and introduce consolidation agent for cross-module analysis. Update CLI commands to support final output options and improve history management with copy functionality.
This commit is contained in:
@@ -8,88 +8,119 @@ allowed-tools: Task, AskUserQuestion, Read, Bash, Glob, Grep, Write
|
||||
|
||||
Generate CPCC-compliant software design specification documents (软件设计说明书) through multi-phase code analysis.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Context-Optimized Architecture │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ Phase 1: Metadata → project-metadata.json │
|
||||
│ ↓ │
|
||||
│ Phase 2: 6 Parallel → sections/section-N.md (直接写MD) │
|
||||
│ Agents ↓ 返回简要JSON │
|
||||
│ ↓ │
|
||||
│ Phase 2.5: Consolidation → cross-module-summary.md │
|
||||
│ Agent ↓ 返回问题列表 │
|
||||
│ ↓ │
|
||||
│ Phase 4: Assembly → 合并MD + 跨模块总结 │
|
||||
│ ↓ │
|
||||
│ Phase 5: Refinement → 最终文档 │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
1. **Agent 直接输出 MD**: 避免 JSON → MD 转换的上下文开销
|
||||
2. **简要返回**: Agent 只返回路径+摘要,不返回完整内容
|
||||
3. **汇总 Agent**: 独立 Agent 负责跨模块问题检测
|
||||
4. **引用合并**: Phase 4 读取文件合并,不在上下文中传递
|
||||
|
||||
## Execution Flow
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Phase 1: Metadata Collection │
|
||||
│ → Read: phases/01-metadata-collection.md │
|
||||
│ → Collect: software name, version, category, scope │
|
||||
│ Phase 1: Metadata Collection │
|
||||
│ → Read: phases/01-metadata-collection.md │
|
||||
│ → Collect: software name, version, category, scope │
|
||||
│ → Output: project-metadata.json │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 2: Deep Code Analysis │
|
||||
│ → Read: phases/02-deep-analysis.md │
|
||||
│ → Launch: 6 parallel agents (architecture, functions, │
|
||||
│ algorithms, data_structures, interfaces, exceptions) │
|
||||
│ Phase 2: Deep Code Analysis (6 Parallel Agents) │
|
||||
│ → Read: phases/02-deep-analysis.md │
|
||||
│ → Reference: specs/cpcc-requirements.md │
|
||||
│ → Each Agent: 分析代码 → 直接写 sections/section-N.md │
|
||||
│ → Return: {"status", "output_file", "summary", "cross_notes"} │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 3: Diagram Generation │
|
||||
│ → Read: phases/03-diagram-generation.md │
|
||||
│ → Reference: ../_shared/mermaid-utils.md │
|
||||
│ → Generate: Mermaid diagrams for all 7 sections │
|
||||
│ Phase 2.5: Consolidation (New!) │
|
||||
│ → Read: phases/02.5-consolidation.md │
|
||||
│ → Input: Agent 返回的简要信息 + cross_module_notes │
|
||||
│ → Analyze: 一致性/完整性/关联性/质量检查 │
|
||||
│ → Output: cross-module-summary.md │
|
||||
│ → Return: {"issues": {errors, warnings, info}, "stats"} │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 4: Document Assembly │
|
||||
│ → Read: phases/04-document-assembly.md │
|
||||
│ → Reference: specs/cpcc-requirements.md │
|
||||
│ → Assemble: 7-section CPCC-compliant document │
|
||||
│ Phase 4: Document Assembly │
|
||||
│ → Read: phases/04-document-assembly.md │
|
||||
│ → Check: 如有 errors,提示用户处理 │
|
||||
│ → Merge: Section 1 + sections/*.md + 跨模块附录 │
|
||||
│ → Output: {软件名称}-软件设计说明书.md │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 5: Compliance Review & Refinement │
|
||||
│ → Read: phases/05-compliance-refinement.md │
|
||||
│ → Reference: specs/cpcc-requirements.md (Compliance Checklist) │
|
||||
│ → Validate: run CPCC compliance checks before each iteration │
|
||||
│ → Loop: discovery-driven questions until all checks pass │
|
||||
│ Phase 5: Compliance Review & Refinement │
|
||||
│ → Read: phases/05-compliance-refinement.md │
|
||||
│ → Reference: specs/cpcc-requirements.md │
|
||||
│ → Loop: 发现问题 → 提问 → 修复 → 重新检查 │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Document Sections (7 Required)
|
||||
|
||||
| Section | Title | Diagram |
|
||||
|---------|-------|---------|
|
||||
| 1 | 软件概述 | - |
|
||||
| 2 | 系统架构图 | graph TD |
|
||||
| 3 | 功能模块设计 | flowchart TD |
|
||||
| 4 | 核心算法与流程 | flowchart TD |
|
||||
| 5 | 数据结构设计 | classDiagram |
|
||||
| 6 | 接口设计 | sequenceDiagram |
|
||||
| 7 | 异常处理设计 | flowchart TD |
|
||||
| Section | Title | Diagram | Agent |
|
||||
|---------|-------|---------|-------|
|
||||
| 1 | 软件概述 | - | Phase 4 生成 |
|
||||
| 2 | 系统架构图 | graph TD | architecture |
|
||||
| 3 | 功能模块设计 | flowchart TD | functions |
|
||||
| 4 | 核心算法与流程 | flowchart TD | algorithms |
|
||||
| 5 | 数据结构设计 | classDiagram | data_structures |
|
||||
| 6 | 接口设计 | sequenceDiagram | interfaces |
|
||||
| 7 | 异常处理设计 | flowchart TD | exceptions |
|
||||
|
||||
## Directory Setup
|
||||
|
||||
```bash
|
||||
timestamp=$(date +%Y%m%d-%H%M%S)
|
||||
dir=".workflow/.scratchpad/copyright-$timestamp"
|
||||
mkdir -p "$dir/diagrams" "$dir/iterations"
|
||||
mkdir -p "$dir/sections" "$dir/iterations"
|
||||
echo "$dir"
|
||||
```
|
||||
|
||||
## Output Structure
|
||||
|
||||
```
|
||||
.workflow/.scratchpad/copyright-{timestamp}/
|
||||
├── project-metadata.json # Phase 1
|
||||
├── sections/ # Phase 2 (Agent 直接写入)
|
||||
│ ├── section-2-architecture.md
|
||||
│ ├── section-3-functions.md
|
||||
│ ├── section-4-algorithms.md
|
||||
│ ├── section-5-data-structures.md
|
||||
│ ├── section-6-interfaces.md
|
||||
│ └── section-7-exceptions.md
|
||||
├── cross-module-summary.md # Phase 2.5
|
||||
├── iterations/ # Phase 5
|
||||
│ ├── v1.md
|
||||
│ └── v2.md
|
||||
└── {软件名称}-软件设计说明书.md # Final Output
|
||||
```
|
||||
|
||||
## Reference Documents
|
||||
|
||||
| Document | Purpose |
|
||||
|----------|---------|
|
||||
| [phases/01-metadata-collection.md](phases/01-metadata-collection.md) | Software info collection |
|
||||
| [phases/02-deep-analysis.md](phases/02-deep-analysis.md) | 6-agent parallel analysis |
|
||||
| [phases/03-diagram-generation.md](phases/03-diagram-generation.md) | Mermaid diagram generation |
|
||||
| [phases/04-document-assembly.md](phases/04-document-assembly.md) | Document structure assembly |
|
||||
| [phases/02.5-consolidation.md](phases/02.5-consolidation.md) | Cross-module consolidation |
|
||||
| [phases/04-document-assembly.md](phases/04-document-assembly.md) | Document merge & assembly |
|
||||
| [phases/05-compliance-refinement.md](phases/05-compliance-refinement.md) | Iterative refinement loop |
|
||||
| [specs/cpcc-requirements.md](specs/cpcc-requirements.md) | CPCC compliance checklist |
|
||||
| [templates/agent-base.md](templates/agent-base.md) | Agent prompt templates |
|
||||
| [../_shared/mermaid-utils.md](../_shared/mermaid-utils.md) | Shared Mermaid utilities |
|
||||
|
||||
## Output Structure
|
||||
|
||||
```
|
||||
.workflow/.scratchpad/copyright-{timestamp}/
|
||||
├── project-metadata.json
|
||||
├── analysis-architecture.json
|
||||
├── analysis-functions.json
|
||||
├── analysis-algorithms.json
|
||||
├── analysis-data_structures.json
|
||||
├── analysis-interfaces.json
|
||||
├── analysis-exceptions.json
|
||||
├── diagrams/
|
||||
│ ├── manifest.json
|
||||
│ ├── architecture.mmd
|
||||
│ ├── functions.mmd
|
||||
│ ├── class-diagram.mmd
|
||||
│ ├── algorithm-*.mmd
|
||||
│ └── sequence-*.mmd
|
||||
├── iterations/
|
||||
└── {软件名称}-软件设计说明书.md
|
||||
```
|
||||
|
||||
@@ -1,138 +1,402 @@
|
||||
# Phase 2: Deep Code Analysis
|
||||
|
||||
Launch 6 parallel agents for multi-dimensional code analysis.
|
||||
6 个并行 Agent,各自直接写入 MD 章节文件。
|
||||
|
||||
## Execution
|
||||
> **模板参考**: [../templates/agent-base.md](../templates/agent-base.md)
|
||||
> **规范参考**: [../specs/cpcc-requirements.md](../specs/cpcc-requirements.md)
|
||||
|
||||
### Analysis Dimensions
|
||||
## Agent 配置
|
||||
|
||||
| Agent | Dimension | Analysis Focus | Output Section |
|
||||
|-------|-----------|----------------|----------------|
|
||||
| 1 | architecture | 分层、模块、依赖 | Section 2 |
|
||||
| 2 | functions | 功能、工作流、交互 | Section 3 |
|
||||
| 3 | algorithms | 核心逻辑、复杂度、流程 | Section 4 |
|
||||
| 4 | data_structures | 实体、属性、关系 | Section 5 |
|
||||
| 5 | interfaces | API、参数、响应 | Section 6 |
|
||||
| 6 | exceptions | 错误类型、处理、恢复 | Section 7 |
|
||||
| Agent | 输出文件 | 章节 |
|
||||
|-------|----------|------|
|
||||
| architecture | section-2-architecture.md | 系统架构图 |
|
||||
| functions | section-3-functions.md | 功能模块设计 |
|
||||
| algorithms | section-4-algorithms.md | 核心算法与流程 |
|
||||
| data_structures | section-5-data-structures.md | 数据结构设计 |
|
||||
| interfaces | section-6-interfaces.md | 接口设计 |
|
||||
| exceptions | section-7-exceptions.md | 异常处理设计 |
|
||||
|
||||
### Agent Prompts
|
||||
## CPCC 规范要点 (所有 Agent 共用)
|
||||
|
||||
```
|
||||
[CPCC_SPEC]
|
||||
1. 内容基于代码分析,无臆测或未来计划
|
||||
2. 图表编号格式: 图N-M (如图2-1, 图3-1)
|
||||
3. 每个子章节内容不少于100字
|
||||
4. Mermaid 语法必须正确可渲染
|
||||
5. 包含具体文件路径引用
|
||||
6. 中文输出,技术术语可用英文
|
||||
```
|
||||
|
||||
## 执行流程
|
||||
|
||||
```javascript
|
||||
// 1. 准备目录
|
||||
Bash(`mkdir -p ${outputDir}/sections`);
|
||||
|
||||
// 2. 并行启动 6 个 Agent
|
||||
const results = await Promise.all([
|
||||
launchAgent('architecture', metadata, outputDir),
|
||||
launchAgent('functions', metadata, outputDir),
|
||||
launchAgent('algorithms', metadata, outputDir),
|
||||
launchAgent('data_structures', metadata, outputDir),
|
||||
launchAgent('interfaces', metadata, outputDir),
|
||||
launchAgent('exceptions', metadata, outputDir)
|
||||
]);
|
||||
|
||||
// 3. 收集返回信息
|
||||
const summaries = results.map(r => JSON.parse(r));
|
||||
|
||||
// 4. 传递给 Phase 2.5
|
||||
return { summaries, cross_notes: summaries.flatMap(s => s.cross_module_notes) };
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Agent 提示词
|
||||
|
||||
### Architecture
|
||||
|
||||
**Architecture Analysis:**
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
## 分析目标
|
||||
分析项目的系统架构,为"系统架构图"章节提供数据。
|
||||
[ROLE] 系统架构师,专注于分层设计和模块依赖。
|
||||
|
||||
## 分析内容
|
||||
1. 分层结构:识别代码的分层(Controller/Service/Repository)
|
||||
2. 模块边界:各模块的职责范围和边界
|
||||
3. 依赖关系:模块间的依赖方向和类型
|
||||
4. 核心组件:系统的核心组件及其作用
|
||||
5. 数据流向:数据在各层之间的流动路径
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 2: 系统架构图。
|
||||
输出: ${outDir}/sections/section-2-architecture.md
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"layers": [{name, components, responsibility}],
|
||||
"modules": [{name, path, responsibility, dependencies}],
|
||||
"data_flow": [{from, to, data_type, description}],
|
||||
"core_components": [{name, type, responsibility}]
|
||||
}
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图2-1, 图2-2...
|
||||
- 每个子章节 ≥100字
|
||||
- 包含文件路径引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 2. 系统架构图
|
||||
|
||||
本章节展示${meta.software_name}的系统架构设计。
|
||||
|
||||
\`\`\`mermaid
|
||||
graph TD
|
||||
subgraph Layer1["层名"]
|
||||
Comp1[组件1]
|
||||
end
|
||||
Comp1 --> Comp2
|
||||
\`\`\`
|
||||
|
||||
**图2-1 系统架构图**
|
||||
|
||||
### 2.1 分层说明
|
||||
| 层级 | 组件 | 职责 |
|
||||
|------|------|------|
|
||||
|
||||
### 2.2 模块依赖
|
||||
| 模块 | 依赖 | 说明 |
|
||||
|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. 分层: 识别代码层次 (Controller/Service/Repository 或其他)
|
||||
2. 模块: 核心模块及职责边界
|
||||
3. 依赖: 模块间依赖方向
|
||||
4. 数据流: 请求/数据的流动路径
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-2-architecture.md","summary":"<50字摘要>","cross_module_notes":["跨模块发现"],"stats":{"diagrams":1,"subsections":2}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
**Function Analysis:**
|
||||
```javascript
|
||||
prompt = `
|
||||
## 分析目标
|
||||
分析项目的功能模块,为"功能模块设计"章节提供数据。
|
||||
### Functions
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"feature_list": [{id, name, description, module, entry_file}],
|
||||
"feature_groups": [{group_name, features: []}],
|
||||
"feature_hierarchy": {root: {children: [...]}},
|
||||
"interactions": [{caller, callee, trigger, description}],
|
||||
"key_workflows": [{name, steps: [], files_involved}]
|
||||
}
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 功能分析师,专注于功能点识别和交互。
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 3: 功能模块设计。
|
||||
输出: ${outDir}/sections/section-3-functions.md
|
||||
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图3-1, 图3-2...
|
||||
- 每个子章节 ≥100字
|
||||
- 包含文件路径引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 3. 功能模块设计
|
||||
|
||||
本章节展示${meta.software_name}的功能模块结构。
|
||||
|
||||
\`\`\`mermaid
|
||||
flowchart TD
|
||||
ROOT["${meta.software_name}"]
|
||||
subgraph Group1["模块组1"]
|
||||
F1["功能1"]
|
||||
end
|
||||
ROOT --> Group1
|
||||
\`\`\`
|
||||
|
||||
**图3-1 功能模块结构图**
|
||||
|
||||
### 3.1 功能清单
|
||||
| ID | 功能名称 | 模块 | 入口文件 | 说明 |
|
||||
|----|----------|------|----------|------|
|
||||
|
||||
### 3.2 功能交互
|
||||
| 调用方 | 被调用方 | 触发条件 |
|
||||
|--------|----------|----------|
|
||||
|
||||
[FOCUS]
|
||||
1. 功能点: 枚举所有用户可见功能
|
||||
2. 模块分组: 按业务域分组
|
||||
3. 入口: 每个功能的代码入口 \`src/path/file.ts\`
|
||||
4. 交互: 功能间的调用关系
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-3-functions.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
**Algorithm Analysis:**
|
||||
```javascript
|
||||
prompt = `
|
||||
## 分析目标
|
||||
分析项目的核心算法和业务逻辑,为"核心算法与流程"章节提供数据。
|
||||
### Algorithms
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"algorithms": [{
|
||||
name, file, line, description, complexity,
|
||||
inputs: [{name, type, description}],
|
||||
outputs: [{name, type, description}],
|
||||
steps: [{step_num, description, type, next, conditions}]
|
||||
}],
|
||||
"complex_functions": [{name, file, cyclomatic_complexity}]
|
||||
}
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 算法工程师,专注于核心逻辑和复杂度分析。
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 4: 核心算法与流程。
|
||||
输出: ${outDir}/sections/section-4-algorithms.md
|
||||
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图4-1, 图4-2... (每个算法一个流程图)
|
||||
- 每个算法说明 ≥100字
|
||||
- 包含文件路径和行号引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 4. 核心算法与流程
|
||||
|
||||
本章节展示${meta.software_name}的核心算法设计。
|
||||
|
||||
### 4.1 {算法名称}
|
||||
|
||||
**说明**: {描述,≥100字}
|
||||
**位置**: \`src/path/file.ts:line\`
|
||||
|
||||
**输入**: param1 (type) - 说明
|
||||
**输出**: result (type) - 说明
|
||||
|
||||
\`\`\`mermaid
|
||||
flowchart TD
|
||||
Start([开始]) --> Input[/输入/]
|
||||
Input --> Check{判断}
|
||||
Check -->|是| P1[步骤1]
|
||||
Check -->|否| P2[步骤2]
|
||||
P1 --> End([结束])
|
||||
P2 --> End
|
||||
\`\`\`
|
||||
|
||||
**图4-1 {算法名称}流程图**
|
||||
|
||||
### 4.N 复杂度分析
|
||||
| 算法 | 时间 | 空间 | 文件 |
|
||||
|------|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. 核心算法: 业务逻辑的关键算法 (>10行或含分支循环)
|
||||
2. 流程步骤: 分支/循环/条件逻辑
|
||||
3. 复杂度: 时间/空间复杂度估算
|
||||
4. 输入输出: 参数类型和返回值
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-4-algorithms.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
**Data Structure Analysis:**
|
||||
```javascript
|
||||
prompt = `
|
||||
## 分析目标
|
||||
分析项目的数据结构,为"数据结构设计"章节提供数据。
|
||||
### Data Structures
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"entities": [{
|
||||
name, file, type,
|
||||
properties: [{name, type, visibility, description}],
|
||||
methods: [{name, params, return_type, visibility}]
|
||||
}],
|
||||
"relationships": [{from, to, type, cardinality, description}],
|
||||
"enums": [{name, values: [{name, value, description}]}]
|
||||
}
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 数据建模师,专注于实体关系和类型定义。
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 5: 数据结构设计。
|
||||
输出: ${outDir}/sections/section-5-data-structures.md
|
||||
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图5-1 (数据结构类图)
|
||||
- 每个子章节 ≥100字
|
||||
- 包含文件路径引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 5. 数据结构设计
|
||||
|
||||
本章节展示${meta.software_name}的核心数据结构。
|
||||
|
||||
\`\`\`mermaid
|
||||
classDiagram
|
||||
class Entity1 {
|
||||
+type field1
|
||||
+method1()
|
||||
}
|
||||
Entity1 "1" --> "*" Entity2 : 关系
|
||||
\`\`\`
|
||||
|
||||
**图5-1 数据结构类图**
|
||||
|
||||
### 5.1 实体说明
|
||||
| 实体 | 类型 | 文件 | 说明 |
|
||||
|------|------|------|------|
|
||||
|
||||
### 5.2 关系说明
|
||||
| 源 | 目标 | 类型 | 基数 |
|
||||
|----|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. 实体: class/interface/type 定义
|
||||
2. 属性: 字段类型和可见性 (+public/-private/#protected)
|
||||
3. 关系: 继承(--|>)/组合(*--)/关联(-->)
|
||||
4. 枚举: enum 类型及其值
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-5-data-structures.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
**Interface Analysis:**
|
||||
```javascript
|
||||
prompt = `
|
||||
## 分析目标
|
||||
分析项目的接口设计,为"接口设计"章节提供数据。
|
||||
### Interfaces
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"apis": [{
|
||||
name, path, method, description,
|
||||
parameters: [{name, type, required, description}],
|
||||
response: {type, schema, description},
|
||||
category
|
||||
}],
|
||||
"protocols": [{name, type, description}]
|
||||
}
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] API设计师,专注于接口契约和协议。
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 6: 接口设计。
|
||||
输出: ${outDir}/sections/section-6-interfaces.md
|
||||
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图6-1, 图6-2... (每个核心接口一个时序图)
|
||||
- 每个接口详情 ≥100字
|
||||
- 包含文件路径引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 6. 接口设计
|
||||
|
||||
本章节展示${meta.software_name}的接口设计。
|
||||
|
||||
\`\`\`mermaid
|
||||
sequenceDiagram
|
||||
participant C as Client
|
||||
participant A as API
|
||||
participant S as Service
|
||||
C->>A: POST /api/xxx
|
||||
A->>S: method()
|
||||
S-->>A: result
|
||||
A-->>C: 200 OK
|
||||
\`\`\`
|
||||
|
||||
**图6-1 {接口名}时序图**
|
||||
|
||||
### 6.1 接口清单
|
||||
| 接口 | 方法 | 路径 | 说明 |
|
||||
|------|------|------|------|
|
||||
|
||||
### 6.2 接口详情
|
||||
|
||||
#### METHOD /path
|
||||
**请求**:
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
|
||||
**响应**:
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. API端点: 路径/方法/说明
|
||||
2. 参数: 请求参数类型和校验规则
|
||||
3. 响应: 响应格式、状态码、错误码
|
||||
4. 时序: 典型调用流程 (选2-3个核心接口)
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-6-interfaces.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
**Exception Analysis:**
|
||||
```javascript
|
||||
prompt = `
|
||||
## 分析目标
|
||||
分析项目的异常处理机制,为"异常处理设计"章节提供数据。
|
||||
### Exceptions
|
||||
|
||||
## 输出格式
|
||||
{
|
||||
"exception_types": [{name, parent, code, message, file}],
|
||||
"error_codes": [{code, message, severity, category}],
|
||||
"handling_patterns": [{pattern, locations: [], description}],
|
||||
"recovery_strategies": [{strategy, trigger, action, files}]
|
||||
}
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 可靠性工程师,专注于异常处理和恢复策略。
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 Section 7: 异常处理设计。
|
||||
输出: ${outDir}/sections/section-7-exceptions.md
|
||||
|
||||
[CPCC_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 图表编号: 图7-1 (异常处理流程图)
|
||||
- 每个子章节 ≥100字
|
||||
- 包含文件路径引用
|
||||
|
||||
[TEMPLATE]
|
||||
## 7. 异常处理设计
|
||||
|
||||
本章节展示${meta.software_name}的异常处理机制。
|
||||
|
||||
\`\`\`mermaid
|
||||
flowchart TD
|
||||
Req[请求] --> Try{Try-Catch}
|
||||
Try -->|正常| Process[处理]
|
||||
Try -->|异常| ErrType{类型}
|
||||
ErrType -->|E1| H1[处理1]
|
||||
ErrType -->|E2| H2[处理2]
|
||||
H1 --> Log[日志]
|
||||
H2 --> Log
|
||||
Process --> Resp[响应]
|
||||
\`\`\`
|
||||
|
||||
**图7-1 异常处理流程图**
|
||||
|
||||
### 7.1 异常类型
|
||||
| 异常类 | 错误码 | HTTP状态 | 说明 |
|
||||
|--------|--------|----------|------|
|
||||
|
||||
### 7.2 恢复策略
|
||||
| 场景 | 策略 | 说明 |
|
||||
|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. 异常类型: 自定义异常类及继承关系
|
||||
2. 错误码: 错误码定义和分类
|
||||
3. 处理模式: try-catch/中间件/装饰器
|
||||
4. 恢复策略: 重试/降级/熔断/告警
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-7-exceptions.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Output
|
||||
|
||||
Save each analysis to `analysis-{dimension}.json`.
|
||||
各 Agent 写入 `sections/section-N-xxx.md`,返回简要 JSON 供 Phase 2.5 汇总。
|
||||
|
||||
184
.claude/skills/copyright-docs/phases/02.5-consolidation.md
Normal file
184
.claude/skills/copyright-docs/phases/02.5-consolidation.md
Normal file
@@ -0,0 +1,184 @@
|
||||
# Phase 2.5: Consolidation Agent
|
||||
|
||||
汇总所有分析 Agent 的产出,识别跨模块问题,生成汇总报告。
|
||||
|
||||
## 输入
|
||||
|
||||
```typescript
|
||||
interface ConsolidationInput {
|
||||
output_dir: string;
|
||||
agent_summaries: AgentReturn[]; // 6个Agent的简要返回
|
||||
cross_module_notes: string[]; // 所有跨模块备注
|
||||
metadata: ProjectMetadata;
|
||||
}
|
||||
```
|
||||
|
||||
## 执行
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
## 任务
|
||||
作为汇总 Agent,读取所有章节文件,执行跨模块分析,生成汇总报告。
|
||||
|
||||
## 输入
|
||||
- 章节文件: {output_dir}/sections/section-*.md
|
||||
- Agent 摘要: ${JSON.stringify(agent_summaries)}
|
||||
- 跨模块备注: ${JSON.stringify(cross_module_notes)}
|
||||
|
||||
## 分析维度
|
||||
|
||||
### 1. 一致性检查
|
||||
- 术语一致性:同一概念是否使用相同名称
|
||||
- 命名规范:中英文命名是否统一
|
||||
- 图表编号:是否连续且正确
|
||||
|
||||
### 2. 完整性检查
|
||||
- 功能覆盖:section-3的功能是否都有对应接口(section-6)
|
||||
- 算法覆盖:section-4的算法是否在功能中被引用
|
||||
- 异常覆盖:section-7的异常是否覆盖所有接口
|
||||
|
||||
### 3. 关联性检查
|
||||
- 模块依赖:架构图(section-2)的依赖是否与实际一致
|
||||
- 数据流向:数据结构(section-5)是否与接口(section-6)匹配
|
||||
- 跨模块调用:是否存在未记录的跨模块依赖
|
||||
|
||||
### 4. 质量检查
|
||||
- 图表语法:Mermaid 语法是否正确
|
||||
- 内容深度:各章节是否有足够的详细说明
|
||||
- 代码引用:是否包含具体的文件路径和行号
|
||||
|
||||
## 输出文件
|
||||
|
||||
写入: {output_dir}/cross-module-summary.md
|
||||
|
||||
### 文件格式
|
||||
|
||||
\`\`\`markdown
|
||||
# 跨模块分析报告
|
||||
|
||||
## 1. 文档统计
|
||||
|
||||
| 章节 | 图表数 | 子章节数 | 字数 |
|
||||
|------|--------|----------|------|
|
||||
| 系统架构图 | 1 | 2 | ~500 |
|
||||
| ... | ... | ... | ... |
|
||||
|
||||
## 2. 发现的问题
|
||||
|
||||
### 2.1 严重问题 (必须修复)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 | 建议 |
|
||||
|----|------|------|------|------|
|
||||
| E001 | 缺失 | section-6 | 缺少权限管理接口 | 补充 /api/permissions 相关接口 |
|
||||
|
||||
### 2.2 警告 (建议修复)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 | 建议 |
|
||||
|----|------|------|------|------|
|
||||
| W001 | 一致性 | section-3/6 | 功能名"用户管理"与接口名"UserModule"不一致 | 统一使用中文或英文 |
|
||||
|
||||
### 2.3 提示 (可选修复)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 |
|
||||
|----|------|------|------|
|
||||
| I001 | 增强 | section-4 | 建议为复杂算法添加复杂度分析 |
|
||||
|
||||
## 3. 跨模块关联图
|
||||
|
||||
\`\`\`mermaid
|
||||
graph LR
|
||||
S2[架构] --> S3[功能]
|
||||
S3 --> S4[算法]
|
||||
S3 --> S6[接口]
|
||||
S5[数据结构] --> S6
|
||||
S6 --> S7[异常]
|
||||
|
||||
S3 -.->|缺少关联| S5
|
||||
\`\`\`
|
||||
|
||||
## 4. 修复建议优先级
|
||||
|
||||
1. **E001**: 补充权限管理接口 (阻塞合规)
|
||||
2. **W001**: 统一术语命名 (影响一致性)
|
||||
3. ...
|
||||
|
||||
## 5. 下一步行动
|
||||
|
||||
- [ ] 修复 E001-E00x 严重问题
|
||||
- [ ] 处理 W001-W00x 警告
|
||||
- [ ] 可选处理 I001-I00x 提示
|
||||
\`\`\`
|
||||
|
||||
## 返回格式 (JSON)
|
||||
|
||||
{
|
||||
"status": "completed",
|
||||
"output_file": "cross-module-summary.md",
|
||||
"stats": {
|
||||
"total_sections": 6,
|
||||
"total_diagrams": 8,
|
||||
"total_words": 3500
|
||||
},
|
||||
"issues": {
|
||||
"errors": [
|
||||
{"id": "E001", "type": "missing", "section": "section-6", "desc": "缺少权限管理接口"}
|
||||
],
|
||||
"warnings": [
|
||||
{"id": "W001", "type": "inconsistency", "sections": ["section-3", "section-6"], "desc": "术语不一致"}
|
||||
],
|
||||
"info": [
|
||||
{"id": "I001", "type": "enhancement", "section": "section-4", "desc": "建议添加复杂度分析"}
|
||||
]
|
||||
},
|
||||
"cross_refs": {
|
||||
"found": 12,
|
||||
"missing": 3
|
||||
}
|
||||
}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
## 问题分类
|
||||
|
||||
| 严重级别 | 前缀 | 含义 | 处理方式 |
|
||||
|----------|------|------|----------|
|
||||
| Error | E | 阻塞合规检查 | 必须修复 |
|
||||
| Warning | W | 影响文档质量 | 建议修复 |
|
||||
| Info | I | 可改进项 | 可选修复 |
|
||||
|
||||
## 问题类型
|
||||
|
||||
| 类型 | 说明 | 检查范围 |
|
||||
|------|------|----------|
|
||||
| missing | 缺失内容 | 功能-接口对应、异常覆盖 |
|
||||
| inconsistency | 不一致 | 术语、命名、编号 |
|
||||
| circular | 循环依赖 | 模块依赖关系 |
|
||||
| orphan | 孤立内容 | 未被引用的功能/数据结构 |
|
||||
| syntax | 语法错误 | Mermaid 图表 |
|
||||
| enhancement | 增强建议 | 内容深度、引用 |
|
||||
|
||||
## 与 Phase 4 的集成
|
||||
|
||||
```javascript
|
||||
// Phase 4 装配时读取汇总报告
|
||||
const summary = JSON.parse(Read(`${outputDir}/cross-module-summary.md`));
|
||||
|
||||
if (summary.issues.errors.length > 0) {
|
||||
// 阻止装配,先修复严重问题
|
||||
return {
|
||||
action: "fix_required",
|
||||
errors: summary.issues.errors
|
||||
};
|
||||
}
|
||||
|
||||
// 在最终文档中插入跨模块说明
|
||||
insertCrossModuleSummary(document, summary);
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
- 文件: `cross-module-summary.md`
|
||||
- 返回: 问题列表 + 统计信息
|
||||
@@ -1,147 +0,0 @@
|
||||
# Phase 3: Mermaid Diagram Generation
|
||||
|
||||
Generate Mermaid diagrams for each document section.
|
||||
|
||||
> **Reference**: See [mermaid-utils.md](../../_shared/mermaid-utils.md) for utility functions.
|
||||
|
||||
## Execution
|
||||
|
||||
### Diagram Mapping
|
||||
|
||||
| Section | Diagram Type | Format | File |
|
||||
|---------|--------------|--------|------|
|
||||
| 2. 系统架构图 | Architecture | graph TD | architecture.mmd |
|
||||
| 3. 功能模块设计 | Function Tree | flowchart TD | functions.mmd |
|
||||
| 4. 核心算法与流程 | Algorithm Flow | flowchart TD | algorithm-*.mmd |
|
||||
| 5. 数据结构设计 | Class Diagram | classDiagram | class-diagram.mmd |
|
||||
| 6. 接口设计 | Sequence | sequenceDiagram | sequence-*.mmd |
|
||||
| 7. 异常处理设计 | Error Flow | flowchart TD | exception-flow.mmd |
|
||||
|
||||
### Section 2: System Architecture
|
||||
|
||||
```javascript
|
||||
function generateArchitectureDiagram(analysis) {
|
||||
let mermaid = 'graph TD\n';
|
||||
|
||||
for (const layer of analysis.layers) {
|
||||
mermaid += ` subgraph ${sanitizeId(layer.name)}["${escapeLabel(layer.name)}"]\n`;
|
||||
for (const comp of layer.components) {
|
||||
mermaid += ` ${sanitizeId(comp)}["${escapeLabel(comp)}"]\n`;
|
||||
}
|
||||
mermaid += ' end\n';
|
||||
}
|
||||
|
||||
for (const flow of analysis.data_flow) {
|
||||
mermaid += ` ${sanitizeId(flow.from)} -->|"${escapeLabel(flow.description)}"| ${sanitizeId(flow.to)}\n`;
|
||||
}
|
||||
|
||||
return mermaid;
|
||||
}
|
||||
```
|
||||
|
||||
### Section 3: Function Modules
|
||||
|
||||
```javascript
|
||||
function generateFunctionDiagram(analysis, softwareName) {
|
||||
let mermaid = 'flowchart TD\n';
|
||||
mermaid += ` ROOT["${escapeLabel(softwareName)}"]\n`;
|
||||
|
||||
for (const group of analysis.feature_groups) {
|
||||
mermaid += ` subgraph ${sanitizeId(group.group_name)}["${escapeLabel(group.group_name)}"]\n`;
|
||||
for (const feature of group.features) {
|
||||
mermaid += ` ${sanitizeId(feature.id)}["${escapeLabel(feature.name)}"]\n`;
|
||||
}
|
||||
mermaid += ' end\n';
|
||||
mermaid += ` ROOT --> ${sanitizeId(group.group_name)}\n`;
|
||||
}
|
||||
|
||||
return mermaid;
|
||||
}
|
||||
```
|
||||
|
||||
### Section 4: Algorithm Flowchart (with branches)
|
||||
|
||||
```javascript
|
||||
// Uses generateAlgorithmFlowchart from _shared/mermaid-utils.md
|
||||
// Supports: type (process/decision/io), next, conditions
|
||||
|
||||
const flowchart = generateAlgorithmFlowchart({
|
||||
name: algorithm.name,
|
||||
inputs: algorithm.inputs,
|
||||
outputs: algorithm.outputs,
|
||||
steps: algorithm.steps // Each step can have type, next, conditions
|
||||
});
|
||||
```
|
||||
|
||||
### Section 5: Class Diagram
|
||||
|
||||
```javascript
|
||||
function generateClassDiagram(analysis) {
|
||||
let mermaid = 'classDiagram\n';
|
||||
|
||||
for (const entity of analysis.entities) {
|
||||
mermaid += ` class ${sanitizeId(entity.name)} {\n`;
|
||||
for (const prop of entity.properties) {
|
||||
const vis = {public: '+', private: '-', protected: '#'}[prop.visibility] || '+';
|
||||
mermaid += ` ${vis}${sanitizeType(prop.type)} ${prop.name}\n`;
|
||||
}
|
||||
for (const method of entity.methods) {
|
||||
const vis = {public: '+', private: '-', protected: '#'}[method.visibility] || '+';
|
||||
mermaid += ` ${vis}${method.name}(${method.params}) ${sanitizeType(method.return_type)}\n`;
|
||||
}
|
||||
mermaid += ' }\n';
|
||||
}
|
||||
|
||||
const arrows = {
|
||||
inheritance: '--|>',
|
||||
composition: '*--',
|
||||
aggregation: 'o--',
|
||||
association: '-->'
|
||||
};
|
||||
|
||||
for (const rel of analysis.relationships) {
|
||||
const arrow = arrows[rel.type] || '-->';
|
||||
mermaid += ` ${sanitizeId(rel.from)} ${arrow} ${sanitizeId(rel.to)} : ${escapeLabel(rel.description)}\n`;
|
||||
}
|
||||
|
||||
return mermaid;
|
||||
}
|
||||
```
|
||||
|
||||
### Section 6: Sequence Diagram
|
||||
|
||||
```javascript
|
||||
function generateSequenceDiagram(scenario) {
|
||||
let mermaid = 'sequenceDiagram\n';
|
||||
|
||||
for (const actor of scenario.actors) {
|
||||
mermaid += ` participant ${sanitizeId(actor.id)} as ${escapeLabel(actor.name)}\n`;
|
||||
}
|
||||
|
||||
for (const msg of scenario.messages) {
|
||||
const arrow = msg.type === 'async' ? '-)' : '->>';
|
||||
mermaid += ` ${sanitizeId(msg.from)}${arrow}${sanitizeId(msg.to)}: ${escapeLabel(msg.description)}\n`;
|
||||
}
|
||||
|
||||
return mermaid;
|
||||
}
|
||||
```
|
||||
|
||||
### Validation
|
||||
|
||||
```javascript
|
||||
// Validate all generated diagrams
|
||||
const results = validateDiagramDirectory(`${outputDir}/diagrams`);
|
||||
const failed = results.filter(r => !r.valid);
|
||||
|
||||
if (failed.length > 0) {
|
||||
// Regenerate failed diagrams with stricter escaping
|
||||
for (const f of failed) {
|
||||
regenerateWithFixes(f.file, f.issues);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
Save diagrams to `diagrams/` with `manifest.json`.
|
||||
@@ -1,128 +1,276 @@
|
||||
# Phase 4: Document Assembly
|
||||
|
||||
Assemble all analysis and diagrams into CPCC-compliant document.
|
||||
合并所有章节文件,生成最终 CPCC 合规文档。
|
||||
|
||||
## Execution
|
||||
> **规范参考**: [../specs/cpcc-requirements.md](../specs/cpcc-requirements.md)
|
||||
|
||||
### Document Structure (7 Sections)
|
||||
## 输入
|
||||
|
||||
```typescript
|
||||
interface AssemblyInput {
|
||||
output_dir: string;
|
||||
metadata: ProjectMetadata;
|
||||
consolidation: {
|
||||
issues: { errors: Issue[], warnings: Issue[], info: Issue[] };
|
||||
stats: { total_sections: number, total_diagrams: number };
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## 执行流程
|
||||
|
||||
```javascript
|
||||
// 1. 检查是否有阻塞性问题
|
||||
if (consolidation.issues.errors.length > 0) {
|
||||
// 阻止装配,先修复
|
||||
return AskUserQuestion({
|
||||
questions: [{
|
||||
question: `发现 ${consolidation.issues.errors.length} 个严重问题,如何处理?`,
|
||||
header: "阻塞问题",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{label: "查看并修复", description: "显示问题列表,手动修复后重试"},
|
||||
{label: "忽略继续", description: "跳过问题检查,继续装配"},
|
||||
{label: "终止", description: "停止文档生成"}
|
||||
]
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 读取章节文件
|
||||
const sections = [
|
||||
Read(`${outputDir}/sections/section-2-architecture.md`),
|
||||
Read(`${outputDir}/sections/section-3-functions.md`),
|
||||
Read(`${outputDir}/sections/section-4-algorithms.md`),
|
||||
Read(`${outputDir}/sections/section-5-data-structures.md`),
|
||||
Read(`${outputDir}/sections/section-6-interfaces.md`),
|
||||
Read(`${outputDir}/sections/section-7-exceptions.md`)
|
||||
];
|
||||
|
||||
// 3. 读取汇总报告
|
||||
const crossModuleSummary = Read(`${outputDir}/cross-module-summary.md`);
|
||||
|
||||
// 4. 装配文档
|
||||
const finalDoc = assembleDocument(metadata, sections, crossModuleSummary);
|
||||
|
||||
// 5. 写入最终文件
|
||||
Write(`${outputDir}/${metadata.software_name}-软件设计说明书.md`, finalDoc);
|
||||
```
|
||||
|
||||
## 文档结构
|
||||
|
||||
```markdown
|
||||
<!-- 页眉:{软件名称} - 版本号:{版本号} -->
|
||||
<!-- 注:最终文档页码位于每页右上角 -->
|
||||
|
||||
# {软件名称} 软件设计说明书
|
||||
|
||||
## 文档信息
|
||||
|
||||
| 项目 | 内容 |
|
||||
|------|------|
|
||||
| 软件名称 | {software_name} |
|
||||
| 版本号 | {version} |
|
||||
| 生成日期 | {date} |
|
||||
|
||||
---
|
||||
|
||||
## 1. 软件概述
|
||||
|
||||
### 1.1 软件背景与用途
|
||||
{从 metadata 生成}
|
||||
|
||||
### 1.2 开发目标与特点
|
||||
{从 metadata 生成}
|
||||
|
||||
### 1.3 运行环境与技术架构
|
||||
{从 metadata.tech_stack 生成}
|
||||
|
||||
## 2. 系统架构图
|
||||
图2-1 系统架构图
|
||||
(Mermaid graph TD)
|
||||
---
|
||||
|
||||
## 3. 功能模块设计
|
||||
图3-1 功能模块结构图
|
||||
(Mermaid flowchart TD)
|
||||
<!-- 以下章节直接引用 Agent 产出 -->
|
||||
|
||||
## 4. 核心算法与流程
|
||||
图4-1 {算法名称}流程图
|
||||
(Mermaid flowchart TD)
|
||||
{section-2-architecture.md 内容}
|
||||
|
||||
## 5. 数据结构设计
|
||||
图5-1 数据结构类图
|
||||
(Mermaid classDiagram)
|
||||
---
|
||||
|
||||
## 6. 接口设计
|
||||
图6-1 接口调用时序图
|
||||
(Mermaid sequenceDiagram)
|
||||
{section-3-functions.md 内容}
|
||||
|
||||
## 7. 异常处理设计
|
||||
图7-1 异常处理流程图
|
||||
(Mermaid flowchart TD)
|
||||
---
|
||||
|
||||
{section-4-algorithms.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-5-data-structures.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-6-interfaces.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-7-exceptions.md 内容}
|
||||
|
||||
---
|
||||
|
||||
## 附录A:跨模块分析
|
||||
|
||||
{cross-module-summary.md 的问题列表和关联图}
|
||||
|
||||
---
|
||||
|
||||
## 附录B:文档统计
|
||||
|
||||
| 章节 | 图表数 | 字数 |
|
||||
|------|--------|------|
|
||||
| ... | ... | ... |
|
||||
|
||||
---
|
||||
|
||||
<!-- 页脚:生成时间 {timestamp} -->
|
||||
```
|
||||
|
||||
### Section Templates
|
||||
## Section 1 生成
|
||||
|
||||
**Section 1: 软件概述**
|
||||
```markdown
|
||||
```javascript
|
||||
function generateSection1(metadata) {
|
||||
const categoryDescriptions = {
|
||||
"命令行工具 (CLI)": "提供命令行界面,用户通过终端命令与系统交互",
|
||||
"后端服务/API": "提供 RESTful/GraphQL API 接口,支持前端或其他服务调用",
|
||||
"SDK/库": "提供可复用的代码库,供其他项目集成使用",
|
||||
"数据处理系统": "处理数据导入、转换、分析和导出",
|
||||
"自动化脚本": "自动执行重复性任务,提高工作效率"
|
||||
};
|
||||
|
||||
return `
|
||||
## 1. 软件概述
|
||||
|
||||
### 1.1 软件背景与用途
|
||||
|
||||
${software_name}是一款${category}软件,主要用于${inferred_purpose}。
|
||||
${metadata.software_name}是一款${metadata.category}软件。${categoryDescriptions[metadata.category]}
|
||||
|
||||
本软件基于${tech_stack.language}语言开发,采用${tech_stack.framework}实现核心功能。
|
||||
本软件基于${metadata.tech_stack.language}语言开发,运行于${metadata.tech_stack.runtime}环境,采用${metadata.tech_stack.framework || '原生'}框架实现核心功能。
|
||||
|
||||
### 1.2 开发目标与特点
|
||||
|
||||
**开发目标**:
|
||||
${objectives}
|
||||
${generateObjectives(metadata)}
|
||||
|
||||
**技术特点**:
|
||||
${features}
|
||||
${generateFeatures(metadata)}
|
||||
|
||||
### 1.3 运行环境与技术架构
|
||||
|
||||
**运行环境**:
|
||||
- 操作系统:${os}
|
||||
- 运行时:${runtime}
|
||||
- 依赖环境:${dependencies}
|
||||
- 操作系统:${metadata.os || 'Windows/Linux/macOS'}
|
||||
- 运行时:${metadata.tech_stack.runtime}
|
||||
- 依赖环境:${metadata.tech_stack.dependencies?.join(', ') || '无'}
|
||||
|
||||
**技术架构**:
|
||||
- 架构模式:${architecture_pattern}
|
||||
- 核心框架:${framework}
|
||||
```
|
||||
|
||||
**Section 2-7: Pattern**
|
||||
```markdown
|
||||
## {N}. {章节标题}
|
||||
|
||||
本章节展示${software_name}的{描述}。
|
||||
|
||||
\`\`\`mermaid
|
||||
${diagram_content}
|
||||
\`\`\`
|
||||
|
||||
**图{N}-1 {图表标题}**
|
||||
|
||||
### {子标题}
|
||||
|
||||
{详细说明}
|
||||
```
|
||||
|
||||
### Figure Numbering
|
||||
|
||||
| Section | Figure Number | Title |
|
||||
|---------|---------------|-------|
|
||||
| 2 | 图2-1 | 系统架构图 |
|
||||
| 3 | 图3-1 | 功能模块结构图 |
|
||||
| 4 | 图4-1, 图4-2... | {算法名称}流程图 |
|
||||
| 5 | 图5-1 | 数据结构类图 |
|
||||
| 6 | 图6-1, 图6-2... | {接口名称}时序图 |
|
||||
| 7 | 图7-1 | 异常处理流程图 |
|
||||
|
||||
### Assembly Code
|
||||
|
||||
```javascript
|
||||
function assembleDocument(metadata, analyses, diagrams) {
|
||||
let doc = '';
|
||||
|
||||
// Header
|
||||
doc += `<!-- 页眉:${metadata.software_name} - 版本号:${metadata.version} -->\n`;
|
||||
doc += `<!-- 注:最终文档页码位于每页右上角 -->\n\n`;
|
||||
|
||||
// Generate each section
|
||||
doc += generateSection1(metadata, analyses.architecture);
|
||||
doc += generateSection2(analyses.architecture, diagrams.architecture);
|
||||
doc += generateSection3(analyses.functions, diagrams.functions, metadata.software_name);
|
||||
doc += generateSection4(analyses.algorithms, diagrams.algorithms);
|
||||
doc += generateSection5(analyses.data_structures, diagrams.class);
|
||||
doc += generateSection6(analyses.interfaces, diagrams.sequences);
|
||||
doc += generateSection7(analyses.exceptions, diagrams.exception_flow);
|
||||
|
||||
return doc;
|
||||
- 架构模式:${metadata.architecture_pattern || '分层架构'}
|
||||
- 核心框架:${metadata.tech_stack.framework || '原生实现'}
|
||||
- 主要模块:${metadata.main_modules?.join(', ') || '见第2章'}
|
||||
`;
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
## 装配函数
|
||||
|
||||
Generate `{软件名称}-软件设计说明书.md`.
|
||||
```javascript
|
||||
function assembleDocument(metadata, sections, crossModuleSummary) {
|
||||
const header = `<!-- 页眉:${metadata.software_name} - 版本号:${metadata.version} -->
|
||||
<!-- 注:最终文档页码位于每页右上角 -->
|
||||
|
||||
# ${metadata.software_name} 软件设计说明书
|
||||
|
||||
## 文档信息
|
||||
|
||||
| 项目 | 内容 |
|
||||
|------|------|
|
||||
| 软件名称 | ${metadata.software_name} |
|
||||
| 版本号 | ${metadata.version} |
|
||||
| 生成日期 | ${new Date().toLocaleDateString('zh-CN')} |
|
||||
|
||||
---
|
||||
|
||||
`;
|
||||
|
||||
const section1 = generateSection1(metadata);
|
||||
|
||||
// 合并章节 (sections 已经是完整的 MD 内容)
|
||||
const mainContent = sections.join('\n\n---\n\n');
|
||||
|
||||
// 提取跨模块问题作为附录
|
||||
const appendixA = extractAppendixA(crossModuleSummary);
|
||||
|
||||
// 生成统计
|
||||
const appendixB = generateStats(sections);
|
||||
|
||||
const footer = `
|
||||
---
|
||||
|
||||
<!-- 页脚:生成时间 ${new Date().toISOString()} -->
|
||||
`;
|
||||
|
||||
return header + section1 + '\n\n---\n\n' + mainContent + '\n\n' + appendixA + '\n\n' + appendixB + footer;
|
||||
}
|
||||
```
|
||||
|
||||
## 附录生成
|
||||
|
||||
### 附录A:跨模块分析
|
||||
|
||||
```javascript
|
||||
function extractAppendixA(crossModuleSummary) {
|
||||
// 从 cross-module-summary.md 提取关键内容
|
||||
return `
|
||||
## 附录A:跨模块分析
|
||||
|
||||
本附录汇总了文档生成过程中发现的跨模块问题和关联关系。
|
||||
|
||||
${extractSection(crossModuleSummary, '## 2. 发现的问题')}
|
||||
|
||||
${extractSection(crossModuleSummary, '## 3. 跨模块关联图')}
|
||||
`;
|
||||
}
|
||||
```
|
||||
|
||||
### 附录B:文档统计
|
||||
|
||||
```javascript
|
||||
function generateStats(sections) {
|
||||
const stats = sections.map((content, idx) => {
|
||||
const diagrams = (content.match(/```mermaid/g) || []).length;
|
||||
const words = content.length;
|
||||
const sectionNames = ['系统架构图', '功能模块设计', '核心算法与流程',
|
||||
'数据结构设计', '接口设计', '异常处理设计'];
|
||||
return { name: sectionNames[idx], diagrams, words };
|
||||
});
|
||||
|
||||
let table = `
|
||||
## 附录B:文档统计
|
||||
|
||||
| 章节 | 图表数 | 字数 |
|
||||
|------|--------|------|
|
||||
`;
|
||||
|
||||
stats.forEach(s => {
|
||||
table += `| ${s.name} | ${s.diagrams} | ${s.words} |\n`;
|
||||
});
|
||||
|
||||
const total = stats.reduce((acc, s) => ({
|
||||
diagrams: acc.diagrams + s.diagrams,
|
||||
words: acc.words + s.words
|
||||
}), { diagrams: 0, words: 0 });
|
||||
|
||||
table += `| **总计** | **${total.diagrams}** | **${total.words}** |\n`;
|
||||
|
||||
return table;
|
||||
}
|
||||
```
|
||||
|
||||
## 输出
|
||||
|
||||
- 最终文档: `{软件名称}-软件设计说明书.md`
|
||||
- 保留原始章节文件供追溯
|
||||
|
||||
200
.claude/skills/copyright-docs/templates/agent-base.md
Normal file
200
.claude/skills/copyright-docs/templates/agent-base.md
Normal file
@@ -0,0 +1,200 @@
|
||||
# Agent Base Template
|
||||
|
||||
所有分析 Agent 的基础模板,确保一致性和高效执行。
|
||||
|
||||
## 通用提示词结构
|
||||
|
||||
```
|
||||
[ROLE] 你是{角色},专注于{职责}。
|
||||
|
||||
[TASK]
|
||||
分析代码库,生成 CPCC 合规的章节文档。
|
||||
- 输出: {output_dir}/sections/{filename}
|
||||
- 格式: Markdown + Mermaid
|
||||
- 范围: {scope_path}
|
||||
|
||||
[CONSTRAINTS]
|
||||
- 只描述已实现的代码,不臆测
|
||||
- 中文输出,技术术语可用英文
|
||||
- Mermaid 图表必须可渲染
|
||||
- 文件/类/函数需包含路径引用
|
||||
|
||||
[OUTPUT_FORMAT]
|
||||
1. 直接写入 MD 文件
|
||||
2. 返回 JSON 简要信息
|
||||
|
||||
[QUALITY_CHECKLIST]
|
||||
- [ ] 包含至少1个 Mermaid 图表
|
||||
- [ ] 每个子章节有实质内容 (>100字)
|
||||
- [ ] 代码引用格式: `src/path/file.ts:line`
|
||||
- [ ] 图表编号正确 (图N-M)
|
||||
```
|
||||
|
||||
## 变量说明
|
||||
|
||||
| 变量 | 来源 | 示例 |
|
||||
|------|------|------|
|
||||
| {output_dir} | Phase 1 创建 | .workflow/.scratchpad/copyright-xxx |
|
||||
| {software_name} | metadata.software_name | 智能数据分析系统 |
|
||||
| {scope_path} | metadata.scope_path | src/ |
|
||||
| {tech_stack} | metadata.tech_stack | TypeScript/Node.js |
|
||||
|
||||
## Agent 提示词模板
|
||||
|
||||
### 精简版 (推荐)
|
||||
|
||||
```javascript
|
||||
const agentPrompt = (agent, meta, outDir) => `
|
||||
[ROLE] ${AGENT_ROLES[agent]}
|
||||
|
||||
[TASK]
|
||||
分析 ${meta.scope_path},生成 ${AGENT_SECTIONS[agent]}。
|
||||
输出: ${outDir}/sections/${AGENT_FILES[agent]}
|
||||
|
||||
[TEMPLATE]
|
||||
${AGENT_TEMPLATES[agent]}
|
||||
|
||||
[FOCUS]
|
||||
${AGENT_FOCUS[agent].join('\n')}
|
||||
|
||||
[RETURN]
|
||||
{"status":"completed","output_file":"${AGENT_FILES[agent]}","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`;
|
||||
```
|
||||
|
||||
### 配置映射
|
||||
|
||||
```javascript
|
||||
const AGENT_ROLES = {
|
||||
architecture: "系统架构师,专注于分层设计和模块依赖",
|
||||
functions: "功能分析师,专注于功能点识别和交互",
|
||||
algorithms: "算法工程师,专注于核心逻辑和复杂度",
|
||||
data_structures: "数据建模师,专注于实体关系和类型",
|
||||
interfaces: "API设计师,专注于接口契约和协议",
|
||||
exceptions: "可靠性工程师,专注于异常处理和恢复"
|
||||
};
|
||||
|
||||
const AGENT_SECTIONS = {
|
||||
architecture: "Section 2: 系统架构图",
|
||||
functions: "Section 3: 功能模块设计",
|
||||
algorithms: "Section 4: 核心算法与流程",
|
||||
data_structures: "Section 5: 数据结构设计",
|
||||
interfaces: "Section 6: 接口设计",
|
||||
exceptions: "Section 7: 异常处理设计"
|
||||
};
|
||||
|
||||
const AGENT_FILES = {
|
||||
architecture: "section-2-architecture.md",
|
||||
functions: "section-3-functions.md",
|
||||
algorithms: "section-4-algorithms.md",
|
||||
data_structures: "section-5-data-structures.md",
|
||||
interfaces: "section-6-interfaces.md",
|
||||
exceptions: "section-7-exceptions.md"
|
||||
};
|
||||
|
||||
const AGENT_FOCUS = {
|
||||
architecture: [
|
||||
"1. 分层: 识别代码层次 (Controller/Service/Repository)",
|
||||
"2. 模块: 核心模块及职责边界",
|
||||
"3. 依赖: 模块间依赖方向",
|
||||
"4. 数据流: 请求/数据的流动路径"
|
||||
],
|
||||
functions: [
|
||||
"1. 功能点: 枚举所有用户可见功能",
|
||||
"2. 模块分组: 按业务域分组",
|
||||
"3. 入口: 每个功能的代码入口",
|
||||
"4. 交互: 功能间的调用关系"
|
||||
],
|
||||
algorithms: [
|
||||
"1. 核心算法: 业务逻辑的关键算法",
|
||||
"2. 流程步骤: 分支/循环/条件",
|
||||
"3. 复杂度: 时间/空间复杂度",
|
||||
"4. 输入输出: 参数和返回值"
|
||||
],
|
||||
data_structures: [
|
||||
"1. 实体: class/interface/type 定义",
|
||||
"2. 属性: 字段类型和可见性",
|
||||
"3. 关系: 继承/组合/关联",
|
||||
"4. 枚举: 枚举类型及其值"
|
||||
],
|
||||
interfaces: [
|
||||
"1. API端点: 路径/方法/说明",
|
||||
"2. 参数: 请求参数类型和校验",
|
||||
"3. 响应: 响应格式和状态码",
|
||||
"4. 时序: 典型调用流程"
|
||||
],
|
||||
exceptions: [
|
||||
"1. 异常类型: 自定义异常类",
|
||||
"2. 错误码: 错误码定义和含义",
|
||||
"3. 处理模式: try-catch/中间件",
|
||||
"4. 恢复策略: 重试/降级/告警"
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
## 效率优化
|
||||
|
||||
### 1. 减少冗余
|
||||
|
||||
**Before (冗余)**:
|
||||
```
|
||||
你是一个专业的系统架构师,具有丰富的软件设计经验。
|
||||
你需要分析代码库,识别系统的分层结构...
|
||||
```
|
||||
|
||||
**After (精简)**:
|
||||
```
|
||||
[ROLE] 系统架构师,专注于分层设计和模块依赖。
|
||||
[TASK] 分析 src/,生成系统架构图章节。
|
||||
```
|
||||
|
||||
### 2. 模板驱动
|
||||
|
||||
**Before (描述性)**:
|
||||
```
|
||||
请按照以下格式输出:
|
||||
首先写一个二级标题...
|
||||
然后添加一个Mermaid图...
|
||||
```
|
||||
|
||||
**After (模板)**:
|
||||
```
|
||||
[TEMPLATE]
|
||||
## 2. 系统架构图
|
||||
{intro}
|
||||
\`\`\`mermaid
|
||||
{diagram}
|
||||
\`\`\`
|
||||
**图2-1 系统架构图**
|
||||
### 2.1 {subsection}
|
||||
{content}
|
||||
```
|
||||
|
||||
### 3. 焦点明确
|
||||
|
||||
**Before (模糊)**:
|
||||
```
|
||||
分析项目的各个方面,包括架构、模块、依赖等
|
||||
```
|
||||
|
||||
**After (具体)**:
|
||||
```
|
||||
[FOCUS]
|
||||
1. 分层: Controller/Service/Repository
|
||||
2. 模块: 职责边界
|
||||
3. 依赖: 方向性
|
||||
4. 数据流: 路径
|
||||
```
|
||||
|
||||
### 4. 返回简洁
|
||||
|
||||
**Before (冗长)**:
|
||||
```
|
||||
请返回详细的分析结果,包括所有发现的问题...
|
||||
```
|
||||
|
||||
**After (结构化)**:
|
||||
```
|
||||
[RETURN]
|
||||
{"status":"completed","output_file":"xxx.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
```
|
||||
@@ -8,82 +8,147 @@ allowed-tools: Task, AskUserQuestion, Read, Bash, Glob, Grep, Write
|
||||
|
||||
Generate comprehensive project analysis reports through multi-phase iterative workflow.
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Context-Optimized Architecture │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ Phase 1: Requirements → analysis-config.json │
|
||||
│ ↓ │
|
||||
│ Phase 2: Exploration → 初步探索,确定范围 │
|
||||
│ ↓ │
|
||||
│ Phase 3: Parallel Agents → sections/section-*.md (直接写MD) │
|
||||
│ ↓ 返回简要JSON │
|
||||
│ Phase 3.5: Consolidation → consolidation-summary.md │
|
||||
│ Agent ↓ 返回质量评分+问题列表 │
|
||||
│ ↓ │
|
||||
│ Phase 4: Assembly → 合并MD + 质量附录 │
|
||||
│ ↓ │
|
||||
│ Phase 5: Refinement → 最终报告 │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Key Design Principles
|
||||
|
||||
1. **Agent 直接输出 MD**: 避免 JSON → MD 转换的上下文开销
|
||||
2. **简要返回**: Agent 只返回路径+摘要,不返回完整内容
|
||||
3. **汇总 Agent**: 独立 Agent 负责跨章节问题检测和质量评分
|
||||
4. **引用合并**: Phase 4 读取文件合并,不在上下文中传递
|
||||
|
||||
## Execution Flow
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ Phase 1: Requirements Discovery │
|
||||
│ → Read: phases/01-requirements-discovery.md │
|
||||
│ → Collect: report type, depth level, scope │
|
||||
│ → Collect: report type, depth level, scope, focus areas │
|
||||
│ → Output: analysis-config.json │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 2: Project Exploration │
|
||||
│ → Read: phases/02-project-exploration.md │
|
||||
│ → Launch: parallel cli-explore-agents │
|
||||
│ → Launch: parallel exploration agents │
|
||||
│ → Output: exploration context for Phase 3 │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 3: Deep Analysis │
|
||||
│ Phase 3: Deep Analysis (Parallel Agents) │
|
||||
│ → Read: phases/03-deep-analysis.md │
|
||||
│ → Execute: Gemini CLI with exploration context │
|
||||
│ → Reference: specs/quality-standards.md │
|
||||
│ → Each Agent: 分析代码 → 直接写 sections/section-*.md │
|
||||
│ → Return: {"status", "output_file", "summary", "cross_notes"} │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 3.5: Diagram Generation │
|
||||
│ → Read: phases/03.5-diagram-generation.md │
|
||||
│ → Reference: ../_shared/mermaid-utils.md │
|
||||
│ → Generate: Mermaid diagrams based on report type │
|
||||
│ Phase 3.5: Consolidation (New!) │
|
||||
│ → Read: phases/03.5-consolidation.md │
|
||||
│ → Input: Agent 返回的简要信息 + cross_module_notes │
|
||||
│ → Analyze: 一致性/完整性/关联性/质量检查 │
|
||||
│ → Output: consolidation-summary.md │
|
||||
│ → Return: {"quality_score", "issues", "stats"} │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 4: Report Generation │
|
||||
│ → Read: phases/04-report-generation.md │
|
||||
│ → Reference: specs/quality-standards.md (Report Requirements) │
|
||||
│ → Assemble: Markdown report with embedded diagrams │
|
||||
│ → Check: 如有 errors,提示用户处理 │
|
||||
│ → Merge: Executive Summary + sections/*.md + 质量附录 │
|
||||
│ → Output: {TYPE}-REPORT.md │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ Phase 5: Iterative Refinement │
|
||||
│ → Read: phases/05-iterative-refinement.md │
|
||||
│ → Reference: specs/quality-standards.md (Quality Gates) │
|
||||
│ → Validate: run quality checks before each iteration │
|
||||
│ → Loop: discovery-driven questions until all gates pass │
|
||||
│ → Reference: specs/quality-standards.md │
|
||||
│ → Loop: 发现问题 → 提问 → 修复 → 重新检查 │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Report Types
|
||||
|
||||
| Type | Output | Focus |
|
||||
|------|--------|-------|
|
||||
| `architecture` | ARCHITECTURE-REPORT.md | System structure, modules, dependencies |
|
||||
| `design` | DESIGN-REPORT.md | Patterns, classes, interfaces |
|
||||
| `methods` | METHODS-REPORT.md | Algorithms, critical paths, APIs |
|
||||
| `comprehensive` | COMPREHENSIVE-REPORT.md | All above combined |
|
||||
| Type | Output | Agents | Focus |
|
||||
|------|--------|--------|-------|
|
||||
| `architecture` | ARCHITECTURE-REPORT.md | 5 | System structure, modules, dependencies |
|
||||
| `design` | DESIGN-REPORT.md | 4 | Patterns, classes, interfaces |
|
||||
| `methods` | METHODS-REPORT.md | 4 | Algorithms, critical paths, APIs |
|
||||
| `comprehensive` | COMPREHENSIVE-REPORT.md | All | All above combined |
|
||||
|
||||
## Agent Configuration by Report Type
|
||||
|
||||
### Architecture Report
|
||||
| Agent | Output File | Section |
|
||||
|-------|-------------|---------|
|
||||
| overview | section-overview.md | System Overview |
|
||||
| layers | section-layers.md | Layer Analysis |
|
||||
| dependencies | section-dependencies.md | Module Dependencies |
|
||||
| dataflow | section-dataflow.md | Data Flow |
|
||||
| entrypoints | section-entrypoints.md | Entry Points |
|
||||
|
||||
### Design Report
|
||||
| Agent | Output File | Section |
|
||||
|-------|-------------|---------|
|
||||
| patterns | section-patterns.md | Design Patterns |
|
||||
| classes | section-classes.md | Class Relationships |
|
||||
| interfaces | section-interfaces.md | Interface Contracts |
|
||||
| state | section-state.md | State Management |
|
||||
|
||||
### Methods Report
|
||||
| Agent | Output File | Section |
|
||||
|-------|-------------|---------|
|
||||
| algorithms | section-algorithms.md | Core Algorithms |
|
||||
| paths | section-paths.md | Critical Code Paths |
|
||||
| apis | section-apis.md | Public API Reference |
|
||||
| logic | section-logic.md | Complex Logic |
|
||||
|
||||
## Directory Setup
|
||||
|
||||
```bash
|
||||
timestamp=$(date +%Y%m%d-%H%M%S)
|
||||
dir=".workflow/.scratchpad/analyze-$timestamp"
|
||||
mkdir -p "$dir/diagrams" "$dir/iterations"
|
||||
mkdir -p "$dir/sections" "$dir/iterations"
|
||||
echo "$dir"
|
||||
```
|
||||
|
||||
## Output Structure
|
||||
|
||||
```
|
||||
.workflow/.scratchpad/analyze-{timestamp}/
|
||||
├── analysis-config.json # Phase 1
|
||||
├── sections/ # Phase 3 (Agent 直接写入)
|
||||
│ ├── section-overview.md
|
||||
│ ├── section-layers.md
|
||||
│ ├── section-dependencies.md
|
||||
│ └── ...
|
||||
├── consolidation-summary.md # Phase 3.5
|
||||
├── {TYPE}-REPORT.md # Final Output
|
||||
└── iterations/ # Phase 5
|
||||
├── v1.md
|
||||
└── v2.md
|
||||
```
|
||||
|
||||
## Reference Documents
|
||||
|
||||
| Document | Purpose |
|
||||
|----------|---------|
|
||||
| [phases/01-requirements-discovery.md](phases/01-requirements-discovery.md) | User interaction, config collection |
|
||||
| [phases/02-project-exploration.md](phases/02-project-exploration.md) | Parallel agent exploration |
|
||||
| [phases/03-deep-analysis.md](phases/03-deep-analysis.md) | Gemini CLI analysis |
|
||||
| [phases/03.5-diagram-generation.md](phases/03.5-diagram-generation.md) | Mermaid diagram generation |
|
||||
| [phases/02-project-exploration.md](phases/02-project-exploration.md) | Initial exploration |
|
||||
| [phases/03-deep-analysis.md](phases/03-deep-analysis.md) | Parallel agent analysis |
|
||||
| [phases/03.5-consolidation.md](phases/03.5-consolidation.md) | Cross-section consolidation |
|
||||
| [phases/04-report-generation.md](phases/04-report-generation.md) | Report assembly |
|
||||
| [phases/05-iterative-refinement.md](phases/05-iterative-refinement.md) | Discovery-driven refinement |
|
||||
| [specs/quality-standards.md](specs/quality-standards.md) | Quality gates, error handling |
|
||||
| [phases/05-iterative-refinement.md](phases/05-iterative-refinement.md) | Quality refinement |
|
||||
| [specs/quality-standards.md](specs/quality-standards.md) | Quality gates, standards |
|
||||
| [../_shared/mermaid-utils.md](../_shared/mermaid-utils.md) | Shared Mermaid utilities |
|
||||
|
||||
## Output Structure
|
||||
|
||||
```
|
||||
.workflow/.scratchpad/analyze-{timestamp}/
|
||||
├── analysis-config.json
|
||||
├── exploration-*.json
|
||||
├── deep-analysis.json
|
||||
├── diagrams/
|
||||
│ ├── manifest.json
|
||||
│ ├── validation.json
|
||||
│ └── *.mmd
|
||||
├── {TYPE}-REPORT.md
|
||||
└── iterations/
|
||||
```
|
||||
|
||||
@@ -1,58 +1,328 @@
|
||||
# Phase 3: Deep Analysis
|
||||
|
||||
Execute deep analysis using Gemini CLI with exploration context.
|
||||
并行 Agent 直接写入 MD 章节文件,返回简要信息。
|
||||
|
||||
## Execution
|
||||
> **规范参考**: [../specs/quality-standards.md](../specs/quality-standards.md)
|
||||
|
||||
### Step 1: Prepare CLI Prompt
|
||||
## Agent 配置
|
||||
|
||||
```bash
|
||||
ccw cli -p "
|
||||
PURPOSE: Generate ${type} analysis report for project
|
||||
TASK:
|
||||
• Analyze project structure and patterns from ${type} perspective
|
||||
• Focus on: ${focus_areas}
|
||||
• Depth level: ${depth}
|
||||
• Key files: ${key_files}
|
||||
MODE: analysis
|
||||
CONTEXT: @**/* | Exploration results
|
||||
EXPECTED:
|
||||
- Structured analysis
|
||||
- Code references (file:line format)
|
||||
- Mermaid diagram data
|
||||
- Actionable insights
|
||||
RULES: $(cat ~/.claude/workflows/cli-templates/protocols/analysis-protocol.md)
|
||||
" --tool gemini --mode analysis
|
||||
根据报告类型,使用不同的 Agent 配置:
|
||||
|
||||
### Architecture Report Agents
|
||||
|
||||
| Agent | 输出文件 | 章节 |
|
||||
|-------|----------|------|
|
||||
| overview | sections/section-overview.md | System Overview |
|
||||
| layers | sections/section-layers.md | Layer Analysis |
|
||||
| dependencies | sections/section-dependencies.md | Module Dependencies |
|
||||
| dataflow | sections/section-dataflow.md | Data Flow |
|
||||
| entrypoints | sections/section-entrypoints.md | Entry Points & Critical Paths |
|
||||
|
||||
### Design Report Agents
|
||||
|
||||
| Agent | 输出文件 | 章节 |
|
||||
|-------|----------|------|
|
||||
| patterns | sections/section-patterns.md | Design Patterns Used |
|
||||
| classes | sections/section-classes.md | Class Relationships |
|
||||
| interfaces | sections/section-interfaces.md | Interface Contracts |
|
||||
| state | sections/section-state.md | State Management |
|
||||
|
||||
### Methods Report Agents
|
||||
|
||||
| Agent | 输出文件 | 章节 |
|
||||
|-------|----------|------|
|
||||
| algorithms | sections/section-algorithms.md | Core Algorithms |
|
||||
| paths | sections/section-paths.md | Critical Code Paths |
|
||||
| apis | sections/section-apis.md | Public API Reference |
|
||||
| logic | sections/section-logic.md | Complex Logic Breakdown |
|
||||
|
||||
---
|
||||
|
||||
## 通用 Agent 返回格式
|
||||
|
||||
```typescript
|
||||
interface AgentReturn {
|
||||
status: "completed" | "partial" | "failed";
|
||||
output_file: string;
|
||||
summary: string; // 50字以内
|
||||
cross_module_notes: string[]; // 跨模块发现
|
||||
stats: {
|
||||
diagrams: number;
|
||||
code_refs: number;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Step 2: Parse Analysis Results
|
||||
---
|
||||
|
||||
Extract structured data from CLI response:
|
||||
## Agent 提示词模板
|
||||
|
||||
### Overview Agent (Architecture)
|
||||
|
||||
```javascript
|
||||
const deepAnalysis = {
|
||||
findings: [], // Analyzed findings with confidence scores
|
||||
patterns: [], // Identified patterns with consistency scores
|
||||
dependencies: [], // Dependency relationships
|
||||
recommendations: [], // Prioritized recommendations
|
||||
sections: [], // Report section data
|
||||
diagram_data: {} // Data for diagram generation
|
||||
};
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 系统架构师,专注于系统全貌和核心组件。
|
||||
|
||||
[TASK]
|
||||
分析 ${config.scope},生成 System Overview 章节。
|
||||
输出: ${outDir}/sections/section-overview.md
|
||||
|
||||
[QUALITY_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 代码引用格式: \`file:line\`
|
||||
- 每个子章节 ≥100字
|
||||
- 包含至少1个 Mermaid 图表
|
||||
|
||||
[TEMPLATE]
|
||||
## System Overview
|
||||
|
||||
### Project Summary
|
||||
{项目概述,技术栈,核心功能}
|
||||
|
||||
### Architecture Diagram
|
||||
\`\`\`mermaid
|
||||
graph TD
|
||||
subgraph Core["核心层"]
|
||||
A[组件A]
|
||||
end
|
||||
\`\`\`
|
||||
|
||||
### Key Components
|
||||
| 组件 | 职责 | 文件 |
|
||||
|------|------|------|
|
||||
|
||||
### Technology Stack
|
||||
| 技术 | 用途 | 版本 |
|
||||
|------|------|------|
|
||||
|
||||
[FOCUS]
|
||||
1. 项目定位和核心功能
|
||||
2. 技术栈和依赖
|
||||
3. 核心组件及职责
|
||||
4. 整体架构模式
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-overview.md","summary":"<50字>","cross_module_notes":[],"stats":{"diagrams":1,"code_refs":5}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
### Step 3: Validate Analysis Quality
|
||||
|
||||
Check analysis completeness:
|
||||
### Layers Agent (Architecture)
|
||||
|
||||
```javascript
|
||||
const qualityChecks = {
|
||||
has_executive_summary: Boolean,
|
||||
focus_areas_covered: config.focus_areas.every(area => analysis.covers(area)),
|
||||
code_references_valid: analysis.references.every(ref => fileExists(ref)),
|
||||
insights_actionable: analysis.insights.filter(i => i.actionable).length > 0
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 架构分析师,专注于分层结构。
|
||||
|
||||
[TASK]
|
||||
分析 ${config.scope},生成 Layer Analysis 章节。
|
||||
输出: ${outDir}/sections/section-layers.md
|
||||
|
||||
[QUALITY_SPEC]
|
||||
- 内容基于代码分析,无臆测
|
||||
- 代码引用格式: \`file:line\`
|
||||
- 每个子章节 ≥100字
|
||||
|
||||
[TEMPLATE]
|
||||
## Layer Analysis
|
||||
|
||||
### Layer Overview
|
||||
\`\`\`mermaid
|
||||
graph TD
|
||||
L1[表现层] --> L2[业务层]
|
||||
L2 --> L3[数据层]
|
||||
\`\`\`
|
||||
|
||||
### Layer Details
|
||||
| 层级 | 目录 | 职责 | 组件数 |
|
||||
|------|------|------|--------|
|
||||
|
||||
### Layer Interactions
|
||||
{层间交互说明}
|
||||
|
||||
### Violations & Recommendations
|
||||
{违反分层的情况和建议}
|
||||
|
||||
[FOCUS]
|
||||
1. 识别代码分层(按目录/命名空间)
|
||||
2. 每层职责和边界
|
||||
3. 层间依赖方向
|
||||
4. 违反分层原则的情况
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-layers.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
### Dependencies Agent (Architecture)
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 依赖分析师,专注于模块依赖关系。
|
||||
|
||||
[TASK]
|
||||
分析 ${config.scope},生成 Module Dependencies 章节。
|
||||
输出: ${outDir}/sections/section-dependencies.md
|
||||
|
||||
[TEMPLATE]
|
||||
## Module Dependencies
|
||||
|
||||
### Dependency Graph
|
||||
\`\`\`mermaid
|
||||
graph LR
|
||||
A[ModuleA] --> B[ModuleB]
|
||||
A --> C[ModuleC]
|
||||
B --> D[ModuleD]
|
||||
\`\`\`
|
||||
|
||||
### Module List
|
||||
| 模块 | 路径 | 依赖数 | 被依赖数 |
|
||||
|------|------|--------|----------|
|
||||
|
||||
### Critical Dependencies
|
||||
{核心依赖说明}
|
||||
|
||||
### Circular Dependencies
|
||||
{循环依赖检测结果}
|
||||
|
||||
[FOCUS]
|
||||
1. 模块间依赖关系
|
||||
2. 依赖方向(单向/双向)
|
||||
3. 循环依赖检测
|
||||
4. 核心模块识别
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-dependencies.md","summary":"<50字>","cross_module_notes":["发现循环依赖: A <-> B"],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
### Patterns Agent (Design)
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 设计模式专家,专注于识别和分析设计模式。
|
||||
|
||||
[TASK]
|
||||
分析 ${config.scope},生成 Design Patterns 章节。
|
||||
输出: ${outDir}/sections/section-patterns.md
|
||||
|
||||
[TEMPLATE]
|
||||
## Design Patterns Used
|
||||
|
||||
### Pattern Summary
|
||||
| 模式 | 类型 | 实现位置 | 说明 |
|
||||
|------|------|----------|------|
|
||||
|
||||
### Pattern Details
|
||||
|
||||
#### Singleton Pattern
|
||||
**位置**: \`src/core/config.ts:15\`
|
||||
**说明**: {实现说明}
|
||||
\`\`\`mermaid
|
||||
classDiagram
|
||||
class Singleton {
|
||||
-instance: Singleton
|
||||
+getInstance()
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Pattern Recommendations
|
||||
{模式使用建议}
|
||||
|
||||
[FOCUS]
|
||||
1. 识别使用的设计模式(GoF 23种 + 其他)
|
||||
2. 模式实现质量评估
|
||||
3. 模式使用建议
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-patterns.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
### Algorithms Agent (Methods)
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
[ROLE] 算法分析师,专注于核心算法和复杂度。
|
||||
|
||||
[TASK]
|
||||
分析 ${config.scope},生成 Core Algorithms 章节。
|
||||
输出: ${outDir}/sections/section-algorithms.md
|
||||
|
||||
[TEMPLATE]
|
||||
## Core Algorithms
|
||||
|
||||
### Algorithm Inventory
|
||||
| 算法 | 文件 | 复杂度 | 说明 |
|
||||
|------|------|--------|------|
|
||||
|
||||
### Algorithm Details
|
||||
|
||||
#### {算法名称}
|
||||
**位置**: \`src/algo/xxx.ts:42\`
|
||||
**复杂度**: 时间 O(n log n), 空间 O(n)
|
||||
|
||||
\`\`\`mermaid
|
||||
flowchart TD
|
||||
Start([开始]) --> Process[处理]
|
||||
Process --> End([结束])
|
||||
\`\`\`
|
||||
|
||||
**说明**: {算法说明,≥100字}
|
||||
|
||||
### Optimization Suggestions
|
||||
{优化建议}
|
||||
|
||||
[FOCUS]
|
||||
1. 核心业务算法
|
||||
2. 复杂度分析
|
||||
3. 算法流程图
|
||||
4. 优化建议
|
||||
|
||||
[RETURN JSON]
|
||||
{"status":"completed","output_file":"section-algorithms.md","summary":"<50字>","cross_module_notes":[],"stats":{}}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 执行流程
|
||||
|
||||
```javascript
|
||||
// 1. 根据报告类型选择 Agent 配置
|
||||
const agentConfigs = getAgentConfigs(config.type);
|
||||
|
||||
// 2. 准备目录
|
||||
Bash(`mkdir -p ${outputDir}/sections`);
|
||||
|
||||
// 3. 并行启动所有 Agent
|
||||
const results = await Promise.all(
|
||||
agentConfigs.map(agent => launchAgent(agent, config, outputDir))
|
||||
);
|
||||
|
||||
// 4. 收集简要返回信息
|
||||
const summaries = results.map(r => JSON.parse(r));
|
||||
|
||||
// 5. 传递给 Phase 3.5 汇总 Agent
|
||||
return {
|
||||
summaries,
|
||||
cross_notes: summaries.flatMap(s => s.cross_module_notes)
|
||||
};
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
Save analysis results to `deep-analysis.json`.
|
||||
各 Agent 写入 `sections/section-xxx.md`,返回简要 JSON 供 Phase 3.5 汇总。
|
||||
|
||||
198
.claude/skills/project-analyze/phases/03.5-consolidation.md
Normal file
198
.claude/skills/project-analyze/phases/03.5-consolidation.md
Normal file
@@ -0,0 +1,198 @@
|
||||
# Phase 3.5: Consolidation Agent
|
||||
|
||||
汇总所有分析 Agent 的产出,识别跨章节问题,生成汇总报告。
|
||||
|
||||
## 输入
|
||||
|
||||
```typescript
|
||||
interface ConsolidationInput {
|
||||
output_dir: string;
|
||||
config: AnalysisConfig;
|
||||
agent_summaries: AgentReturn[];
|
||||
cross_module_notes: string[];
|
||||
}
|
||||
```
|
||||
|
||||
## 执行
|
||||
|
||||
```javascript
|
||||
Task({
|
||||
subagent_type: "cli-explore-agent",
|
||||
prompt: `
|
||||
## 任务
|
||||
作为汇总 Agent,读取所有章节文件,执行跨章节分析,生成汇总报告。
|
||||
|
||||
## 输入
|
||||
- 章节文件: ${outputDir}/sections/section-*.md
|
||||
- Agent 摘要: ${JSON.stringify(agent_summaries)}
|
||||
- 跨模块备注: ${JSON.stringify(cross_module_notes)}
|
||||
- 报告类型: ${config.type}
|
||||
|
||||
## 分析维度
|
||||
|
||||
### 1. 一致性检查
|
||||
- 术语一致性:同一概念是否使用相同名称
|
||||
- 代码引用:file:line 格式是否正确
|
||||
- 图表编号:是否连续且正确
|
||||
|
||||
### 2. 完整性检查
|
||||
- 章节覆盖:是否涵盖所有必需章节
|
||||
- 内容深度:每章节是否达到 ${config.depth} 级别
|
||||
- 图表数量:是否每章节包含图表
|
||||
|
||||
### 3. 质量检查
|
||||
- Mermaid 语法:图表是否可渲染
|
||||
- 代码引用有效性:引用的文件是否存在
|
||||
- 建议可行性:推荐是否具体可操作
|
||||
|
||||
### 4. 关联性检查
|
||||
- 章节间引用:是否有交叉引用
|
||||
- 逻辑连贯:内容是否逻辑一致
|
||||
- 重复内容:是否有冗余描述
|
||||
|
||||
## 输出文件
|
||||
|
||||
写入: ${outputDir}/consolidation-summary.md
|
||||
|
||||
### 文件格式
|
||||
|
||||
\`\`\`markdown
|
||||
# 分析汇总报告
|
||||
|
||||
## 1. 章节统计
|
||||
|
||||
| 章节 | 状态 | 图表数 | 代码引用数 | 字数 |
|
||||
|------|------|--------|------------|------|
|
||||
| System Overview | completed | 1 | 5 | 450 |
|
||||
| ... | ... | ... | ... | ... |
|
||||
|
||||
## 2. 发现的问题
|
||||
|
||||
### 2.1 严重问题 (阻塞报告生成)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 | 建议 |
|
||||
|----|------|------|------|------|
|
||||
| E001 | missing | section-dataflow | 缺少数据流章节 | 补充数据流分析 |
|
||||
|
||||
### 2.2 警告 (影响报告质量)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 | 建议 |
|
||||
|----|------|------|------|------|
|
||||
| W001 | inconsistency | section-overview/layers | 架构描述不一致 | 统一术语 |
|
||||
|
||||
### 2.3 提示 (可选优化)
|
||||
|
||||
| ID | 类型 | 位置 | 描述 |
|
||||
|----|------|------|------|
|
||||
| I001 | enhancement | section-algorithms | 建议添加复杂度分析 |
|
||||
|
||||
## 3. 跨章节关联
|
||||
|
||||
\`\`\`mermaid
|
||||
graph LR
|
||||
S1[Overview] --> S2[Layers]
|
||||
S2 --> S3[Dependencies]
|
||||
S3 --> S4[DataFlow]
|
||||
|
||||
S2 -.->|不一致| S1
|
||||
\`\`\`
|
||||
|
||||
## 4. 报告质量评分
|
||||
|
||||
| 维度 | 得分 | 说明 |
|
||||
|------|------|------|
|
||||
| 完整性 | 85% | 缺少1个章节 |
|
||||
| 一致性 | 90% | 2处术语不一致 |
|
||||
| 深度 | 95% | 符合 ${config.depth} 级别 |
|
||||
| 可读性 | 88% | 图表清晰 |
|
||||
|
||||
## 5. 推荐操作
|
||||
|
||||
1. **[必须]** 补充 section-dataflow 章节
|
||||
2. **[建议]** 统一 Overview 和 Layers 中的架构术语
|
||||
3. **[可选]** 为算法章节添加复杂度分析
|
||||
\`\`\`
|
||||
|
||||
## 返回格式 (JSON)
|
||||
|
||||
{
|
||||
"status": "completed",
|
||||
"output_file": "consolidation-summary.md",
|
||||
"quality_score": {
|
||||
"completeness": 85,
|
||||
"consistency": 90,
|
||||
"depth": 95,
|
||||
"readability": 88,
|
||||
"overall": 89
|
||||
},
|
||||
"issues": {
|
||||
"errors": [
|
||||
{"id": "E001", "type": "missing", "section": "section-dataflow", "desc": "缺少数据流章节"}
|
||||
],
|
||||
"warnings": [
|
||||
{"id": "W001", "type": "inconsistency", "sections": ["section-overview", "section-layers"], "desc": "架构描述不一致"}
|
||||
],
|
||||
"info": [
|
||||
{"id": "I001", "type": "enhancement", "section": "section-algorithms", "desc": "建议添加复杂度分析"}
|
||||
]
|
||||
},
|
||||
"stats": {
|
||||
"total_sections": 5,
|
||||
"total_diagrams": 8,
|
||||
"total_code_refs": 42,
|
||||
"total_words": 3500
|
||||
}
|
||||
}
|
||||
`
|
||||
})
|
||||
```
|
||||
|
||||
## 问题分类
|
||||
|
||||
| 严重级别 | 前缀 | 含义 | 处理方式 |
|
||||
|----------|------|------|----------|
|
||||
| Error | E | 阻塞报告生成 | 必须修复 |
|
||||
| Warning | W | 影响报告质量 | 建议修复 |
|
||||
| Info | I | 可改进项 | 可选修复 |
|
||||
|
||||
## 问题类型
|
||||
|
||||
| 类型 | 说明 | 检查范围 |
|
||||
|------|------|----------|
|
||||
| missing | 缺失章节 | 必需章节列表 |
|
||||
| inconsistency | 不一致 | 术语、命名、描述 |
|
||||
| invalid_ref | 无效引用 | 代码引用、图表引用 |
|
||||
| syntax | 语法错误 | Mermaid 图表 |
|
||||
| shallow | 内容过浅 | 深度级别要求 |
|
||||
| enhancement | 增强建议 | 最佳实践 |
|
||||
|
||||
## 与 Phase 4 的集成
|
||||
|
||||
```javascript
|
||||
// Phase 4 装配时读取汇总报告
|
||||
const summary = JSON.parse(Read(`${outputDir}/consolidation-summary.md`));
|
||||
|
||||
if (summary.issues.errors.length > 0) {
|
||||
// 阻止装配,提示用户
|
||||
return AskUserQuestion({
|
||||
questions: [{
|
||||
question: `发现 ${summary.issues.errors.length} 个严重问题,如何处理?`,
|
||||
header: "质量检查",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{label: "查看并修复", description: "显示问题,手动修复"},
|
||||
{label: "忽略继续", description: "跳过检查,继续装配"},
|
||||
{label: "终止", description: "停止报告生成"}
|
||||
]
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
// 在报告中插入质量评分
|
||||
insertQualityScore(report, summary.quality_score);
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
- 文件: `consolidation-summary.md`
|
||||
- 返回: 质量评分 + 问题列表 + 统计信息
|
||||
@@ -1,86 +0,0 @@
|
||||
# Phase 3.5: Diagram Generation
|
||||
|
||||
Generate Mermaid diagrams based on report type and analysis data.
|
||||
|
||||
> **Reference**: See [mermaid-utils.md](../../_shared/mermaid-utils.md) for utility functions.
|
||||
|
||||
## Execution
|
||||
|
||||
### Step 1: Determine Required Diagrams
|
||||
|
||||
```javascript
|
||||
const diagramRequirements = {
|
||||
architecture: [
|
||||
{type: 'architecture', format: 'graph TD', file: 'architecture.mmd'},
|
||||
{type: 'layers', format: 'graph TD', file: 'layers.mmd'},
|
||||
{type: 'dependencies', format: 'graph LR', file: 'dependencies.mmd'},
|
||||
{type: 'dataflow', format: 'flowchart LR', file: 'dataflow.mmd'}
|
||||
],
|
||||
design: [
|
||||
{type: 'class', format: 'classDiagram', file: 'class-diagram.mmd'},
|
||||
{type: 'components', format: 'graph TD', file: 'components.mmd'},
|
||||
{type: 'patterns', format: 'graph TD', file: 'patterns.mmd'},
|
||||
{type: 'state', format: 'stateDiagram-v2', file: 'state.mmd'}
|
||||
],
|
||||
methods: [
|
||||
{type: 'algorithm', format: 'flowchart TD', file: 'algorithm-*.mmd'},
|
||||
{type: 'sequence', format: 'sequenceDiagram', file: 'sequence-*.mmd'},
|
||||
{type: 'critical_path', format: 'flowchart LR', file: 'critical-path.mmd'},
|
||||
{type: 'api', format: 'graph LR', file: 'api.mmd'}
|
||||
],
|
||||
comprehensive: [
|
||||
{type: 'architecture', format: 'graph TD', file: 'architecture.mmd'},
|
||||
{type: 'class', format: 'classDiagram', file: 'class-diagram.mmd'},
|
||||
{type: 'sequence', format: 'sequenceDiagram', file: 'sequence-main.mmd'},
|
||||
{type: 'dataflow', format: 'flowchart LR', file: 'dataflow.mmd'}
|
||||
]
|
||||
};
|
||||
|
||||
const required = diagramRequirements[config.type];
|
||||
```
|
||||
|
||||
### Step 2: Generate Each Diagram
|
||||
|
||||
Use shared utilities from `../_shared/mermaid-utils.md`:
|
||||
|
||||
```javascript
|
||||
// Import utilities
|
||||
const { sanitizeId, escapeLabel, generateClassDiagram, generateSequenceDiagram, validateMermaidSyntax } = require('../_shared/mermaid-utils.md');
|
||||
|
||||
for (const diagram of required) {
|
||||
const content = generateDiagram(diagram.type, diagram.format, analysisData);
|
||||
Write(`${outputDir}/diagrams/${diagram.file}`, content);
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Validate All Diagrams
|
||||
|
||||
```javascript
|
||||
const validationResults = validateDiagramDirectory(`${outputDir}/diagrams`);
|
||||
const failedDiagrams = validationResults.filter(r => !r.valid);
|
||||
|
||||
if (failedDiagrams.length > 0) {
|
||||
// Regenerate failed diagrams
|
||||
for (const failed of failedDiagrams) {
|
||||
regenerateDiagram(failed.file, failed.issues);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: Create Diagram Manifest
|
||||
|
||||
```javascript
|
||||
Write(`${outputDir}/diagrams/manifest.json`, JSON.stringify({
|
||||
generated_at: new Date().toISOString(),
|
||||
diagrams: required.map(d => ({
|
||||
type: d.type,
|
||||
file: d.file,
|
||||
format: d.format
|
||||
})),
|
||||
validation: validationResults
|
||||
}, null, 2));
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
Save diagrams to `diagrams/` folder with `manifest.json`.
|
||||
@@ -1,94 +1,302 @@
|
||||
# Phase 4: Report Generation
|
||||
|
||||
Assemble analysis and diagrams into structured Markdown report.
|
||||
合并所有章节文件,生成最终分析报告。
|
||||
|
||||
## Execution
|
||||
> **规范参考**: [../specs/quality-standards.md](../specs/quality-standards.md)
|
||||
|
||||
### Step 1: Determine Report Sections
|
||||
## 输入
|
||||
|
||||
```javascript
|
||||
const reportSections = {
|
||||
architecture: [
|
||||
"# Architecture Report",
|
||||
"## Executive Summary",
|
||||
"## System Overview",
|
||||
"## Layer Analysis",
|
||||
"## Module Dependencies",
|
||||
"## Data Flow",
|
||||
"## Entry Points & Critical Paths",
|
||||
"## Dependency Graph",
|
||||
"## Recommendations"
|
||||
],
|
||||
design: [
|
||||
"# Design Report",
|
||||
"## Executive Summary",
|
||||
"## Design Patterns Used",
|
||||
"## Class Relationships",
|
||||
"## Interface Contracts",
|
||||
"## State Management",
|
||||
"## Component Diagrams",
|
||||
"## Design Recommendations"
|
||||
],
|
||||
methods: [
|
||||
"# Key Methods Report",
|
||||
"## Executive Summary",
|
||||
"## Core Algorithms",
|
||||
"## Critical Code Paths",
|
||||
"## Public API Reference",
|
||||
"## Complex Logic Breakdown",
|
||||
"## Sequence Diagrams",
|
||||
"## Optimization Suggestions"
|
||||
],
|
||||
comprehensive: [
|
||||
"# Comprehensive Project Analysis",
|
||||
"## Executive Summary",
|
||||
"## Architecture Overview",
|
||||
"## Design Patterns & Principles",
|
||||
"## Key Methods & Algorithms",
|
||||
"## System Diagrams",
|
||||
"## Recommendations & Next Steps"
|
||||
]
|
||||
};
|
||||
|
||||
const sections = reportSections[config.type];
|
||||
```
|
||||
|
||||
### Step 2: Generate Report Content
|
||||
|
||||
```javascript
|
||||
let report = '';
|
||||
|
||||
for (const section of sections) {
|
||||
report += section + '\n\n';
|
||||
|
||||
// Add section content from analysis
|
||||
const sectionContent = generateSectionContent(section, deepAnalysis);
|
||||
report += sectionContent + '\n\n';
|
||||
|
||||
// Embed relevant diagrams
|
||||
const relatedDiagrams = findRelatedDiagrams(section, diagrams);
|
||||
for (const diagram of relatedDiagrams) {
|
||||
report += `\`\`\`mermaid\n${Read(diagram.path)}\n\`\`\`\n\n`;
|
||||
}
|
||||
```typescript
|
||||
interface ReportInput {
|
||||
output_dir: string;
|
||||
config: AnalysisConfig;
|
||||
consolidation: {
|
||||
quality_score: QualityScore;
|
||||
issues: { errors: Issue[], warnings: Issue[], info: Issue[] };
|
||||
stats: Stats;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Add Code References
|
||||
|
||||
Format all code references as `file:line`:
|
||||
## 执行流程
|
||||
|
||||
```javascript
|
||||
// Example: src/auth/login.ts:42
|
||||
const codeRef = `${finding.file}:${finding.line}`;
|
||||
// 1. 检查质量门禁
|
||||
if (consolidation.issues.errors.length > 0) {
|
||||
const response = await AskUserQuestion({
|
||||
questions: [{
|
||||
question: `发现 ${consolidation.issues.errors.length} 个严重问题,如何处理?`,
|
||||
header: "质量检查",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{label: "查看并修复", description: "显示问题列表,手动修复后重试"},
|
||||
{label: "忽略继续", description: "跳过问题检查,继续装配"},
|
||||
{label: "终止", description: "停止报告生成"}
|
||||
]
|
||||
}]
|
||||
});
|
||||
|
||||
if (response === "查看并修复") {
|
||||
return { action: "fix_required", errors: consolidation.issues.errors };
|
||||
}
|
||||
if (response === "终止") {
|
||||
return { action: "abort" };
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 读取章节文件
|
||||
const sectionFiles = Glob(`${outputDir}/sections/section-*.md`);
|
||||
const sections = sectionFiles.map(f => Read(f));
|
||||
|
||||
// 3. 读取汇总报告
|
||||
const summary = Read(`${outputDir}/consolidation-summary.md`);
|
||||
|
||||
// 4. 装配报告
|
||||
const report = assembleReport(config, sections, summary);
|
||||
|
||||
// 5. 写入最终文件
|
||||
const fileName = `${config.type.toUpperCase()}-REPORT.md`;
|
||||
Write(`${outputDir}/${fileName}`, report);
|
||||
```
|
||||
|
||||
### Step 4: Write Report
|
||||
## 报告结构
|
||||
|
||||
### Architecture Report
|
||||
|
||||
```markdown
|
||||
# Architecture Report
|
||||
|
||||
> Generated: {date}
|
||||
> Scope: {config.scope}
|
||||
> Quality Score: {overall}%
|
||||
|
||||
## Executive Summary
|
||||
|
||||
{3-5 key takeaways from consolidation-summary}
|
||||
|
||||
---
|
||||
|
||||
{section-overview.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-layers.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-dependencies.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-dataflow.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-entrypoints.md 内容}
|
||||
|
||||
---
|
||||
|
||||
## Recommendations
|
||||
|
||||
{从各章节汇总的建议}
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Quality Report
|
||||
|
||||
{consolidation-summary.md 的质量评分和问题列表}
|
||||
```
|
||||
|
||||
### Design Report
|
||||
|
||||
```markdown
|
||||
# Design Report
|
||||
|
||||
> Generated: {date}
|
||||
> Scope: {config.scope}
|
||||
> Quality Score: {overall}%
|
||||
|
||||
## Executive Summary
|
||||
|
||||
{3-5 key takeaways}
|
||||
|
||||
---
|
||||
|
||||
{section-patterns.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-classes.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-interfaces.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-state.md 内容}
|
||||
|
||||
---
|
||||
|
||||
## Design Recommendations
|
||||
|
||||
{汇总的设计建议}
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Quality Report
|
||||
|
||||
{质量评分}
|
||||
```
|
||||
|
||||
### Methods Report
|
||||
|
||||
```markdown
|
||||
# Key Methods Report
|
||||
|
||||
> Generated: {date}
|
||||
> Scope: {config.scope}
|
||||
> Quality Score: {overall}%
|
||||
|
||||
## Executive Summary
|
||||
|
||||
{3-5 key takeaways}
|
||||
|
||||
---
|
||||
|
||||
{section-algorithms.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-paths.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-apis.md 内容}
|
||||
|
||||
---
|
||||
|
||||
{section-logic.md 内容}
|
||||
|
||||
---
|
||||
|
||||
## Optimization Suggestions
|
||||
|
||||
{汇总的优化建议}
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Quality Report
|
||||
|
||||
{质量评分}
|
||||
```
|
||||
|
||||
## 装配函数
|
||||
|
||||
```javascript
|
||||
const reportFileName = `${config.type.toUpperCase()}-REPORT.md`;
|
||||
Write(`${outputDir}/${reportFileName}`, report);
|
||||
function assembleReport(config, sections, summary) {
|
||||
const reportTitles = {
|
||||
architecture: "Architecture Report",
|
||||
design: "Design Report",
|
||||
methods: "Key Methods Report",
|
||||
comprehensive: "Comprehensive Project Analysis"
|
||||
};
|
||||
|
||||
const header = `# ${reportTitles[config.type]}
|
||||
|
||||
> Generated: ${new Date().toLocaleDateString('zh-CN')}
|
||||
> Scope: ${config.scope}
|
||||
> Depth: ${config.depth}
|
||||
> Quality Score: ${summary.quality_score?.overall || 'N/A'}%
|
||||
|
||||
`;
|
||||
|
||||
// Executive Summary from consolidation
|
||||
const execSummary = generateExecutiveSummary(summary, config.type);
|
||||
|
||||
// Merge sections
|
||||
const mainContent = sections.join('\n\n---\n\n');
|
||||
|
||||
// Recommendations from sections
|
||||
const recommendations = extractRecommendations(sections, config.type);
|
||||
|
||||
// Quality appendix
|
||||
const appendix = generateQualityAppendix(summary);
|
||||
|
||||
return header + execSummary + '\n\n---\n\n' + mainContent + '\n\n' + recommendations + '\n\n' + appendix;
|
||||
}
|
||||
|
||||
function generateExecutiveSummary(summary, type) {
|
||||
return `## Executive Summary
|
||||
|
||||
### Key Findings
|
||||
${summary.key_findings?.map(f => `- ${f}`).join('\n') || '- See detailed sections below'}
|
||||
|
||||
### Quality Overview
|
||||
| Dimension | Score |
|
||||
|-----------|-------|
|
||||
| Completeness | ${summary.quality_score?.completeness || 'N/A'}% |
|
||||
| Consistency | ${summary.quality_score?.consistency || 'N/A'}% |
|
||||
| Depth | ${summary.quality_score?.depth || 'N/A'}% |
|
||||
|
||||
### Issues Summary
|
||||
- Errors: ${summary.issues?.errors?.length || 0}
|
||||
- Warnings: ${summary.issues?.warnings?.length || 0}
|
||||
- Suggestions: ${summary.issues?.info?.length || 0}
|
||||
`;
|
||||
}
|
||||
|
||||
function extractRecommendations(sections, type) {
|
||||
const recommendationTitles = {
|
||||
architecture: "## Architectural Recommendations",
|
||||
design: "## Design Recommendations",
|
||||
methods: "## Optimization Suggestions",
|
||||
comprehensive: "## Recommendations & Next Steps"
|
||||
};
|
||||
|
||||
// Extract recommendation sections from each section file
|
||||
let recommendations = `${recommendationTitles[type]}\n\n`;
|
||||
|
||||
// Aggregate from sections
|
||||
recommendations += "Based on the analysis, the following recommendations are prioritized:\n\n";
|
||||
recommendations += "1. **High Priority**: Address critical issues identified in the quality report\n";
|
||||
recommendations += "2. **Medium Priority**: Resolve warnings to improve code quality\n";
|
||||
recommendations += "3. **Low Priority**: Consider enhancement suggestions for future iterations\n";
|
||||
|
||||
return recommendations;
|
||||
}
|
||||
|
||||
function generateQualityAppendix(summary) {
|
||||
return `---
|
||||
|
||||
## Appendix: Quality Report
|
||||
|
||||
### Overall Score: ${summary.quality_score?.overall || 'N/A'}%
|
||||
|
||||
| Dimension | Score | Status |
|
||||
|-----------|-------|--------|
|
||||
| Completeness | ${summary.quality_score?.completeness || 'N/A'}% | ${getStatus(summary.quality_score?.completeness)} |
|
||||
| Consistency | ${summary.quality_score?.consistency || 'N/A'}% | ${getStatus(summary.quality_score?.consistency)} |
|
||||
| Depth | ${summary.quality_score?.depth || 'N/A'}% | ${getStatus(summary.quality_score?.depth)} |
|
||||
| Readability | ${summary.quality_score?.readability || 'N/A'}% | ${getStatus(summary.quality_score?.readability)} |
|
||||
|
||||
### Statistics
|
||||
- Total Sections: ${summary.stats?.total_sections || 'N/A'}
|
||||
- Total Diagrams: ${summary.stats?.total_diagrams || 'N/A'}
|
||||
- Total Code References: ${summary.stats?.total_code_refs || 'N/A'}
|
||||
- Total Words: ${summary.stats?.total_words || 'N/A'}
|
||||
`;
|
||||
}
|
||||
|
||||
function getStatus(score) {
|
||||
if (!score) return '?';
|
||||
if (score >= 90) return 'PASS';
|
||||
if (score >= 70) return 'WARNING';
|
||||
return 'FAIL';
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
||||
Generate `{TYPE}-REPORT.md` in output directory.
|
||||
- 最终报告: `{TYPE}-REPORT.md`
|
||||
- 保留原始章节文件供追溯
|
||||
|
||||
@@ -195,6 +195,7 @@ export function run(argv: string[]): void {
|
||||
.option('--output-type <type>', 'Output type: stdout, stderr, both', 'both')
|
||||
.option('--turn <n>', 'Turn number for cache (default: latest)')
|
||||
.option('--raw', 'Raw output only (no formatting)')
|
||||
.option('--final', 'Output final result only with usage hint')
|
||||
.action((subcommand, args, options) => cliCommand(subcommand, args, options));
|
||||
|
||||
// Memory command
|
||||
|
||||
@@ -111,6 +111,7 @@ interface OutputViewOptions {
|
||||
outputType?: 'stdout' | 'stderr' | 'both';
|
||||
turn?: string;
|
||||
raw?: boolean;
|
||||
final?: boolean; // Only output final result with usage hint
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,6 +329,21 @@ async function outputAction(conversationId: string | undefined, options: OutputV
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.final) {
|
||||
// Final result only with usage hint
|
||||
if (result.stdout) {
|
||||
console.log(result.stdout.content);
|
||||
}
|
||||
console.log();
|
||||
console.log(chalk.gray('─'.repeat(60)));
|
||||
console.log(chalk.dim(`Usage: ccw cli output ${conversationId} [options]`));
|
||||
console.log(chalk.dim(' --raw Raw output (no hint)'));
|
||||
console.log(chalk.dim(' --offset <n> Start from byte offset'));
|
||||
console.log(chalk.dim(' --limit <n> Limit output bytes'));
|
||||
console.log(chalk.dim(` --resume ccw cli -p "..." --resume ${conversationId}`));
|
||||
return;
|
||||
}
|
||||
|
||||
// Formatted output
|
||||
console.log(chalk.bold.cyan('Execution Output\n'));
|
||||
console.log(` ${chalk.gray('ID:')} ${result.conversationId}`);
|
||||
@@ -764,7 +780,8 @@ async function historyAction(options: HistoryOptions): Promise<void> {
|
||||
|
||||
console.log(chalk.bold.cyan('\n CLI Execution History\n'));
|
||||
|
||||
const history = await getExecutionHistoryAsync(process.cwd(), { limit: parseInt(limit, 10), tool, status });
|
||||
// Use recursive: true to aggregate history from parent and child projects (matches Dashboard behavior)
|
||||
const history = await getExecutionHistoryAsync(process.cwd(), { limit: parseInt(limit, 10), tool, status, recursive: true });
|
||||
|
||||
if (history.executions.length === 0) {
|
||||
console.log(chalk.gray(' No executions found.\n'));
|
||||
@@ -953,6 +970,12 @@ export async function cliCommand(
|
||||
console.log(chalk.gray(' full: inject all cached content (default for codex)'));
|
||||
console.log(chalk.gray(' progressive: inject first 64KB with MCP continuation hint'));
|
||||
console.log();
|
||||
console.log(' Output options (ccw cli output <id>):');
|
||||
console.log(chalk.gray(' --final Final result only with usage hint'));
|
||||
console.log(chalk.gray(' --raw Raw output only (no formatting, for piping)'));
|
||||
console.log(chalk.gray(' --offset <n> Start from byte offset'));
|
||||
console.log(chalk.gray(' --limit <n> Limit output bytes'));
|
||||
console.log();
|
||||
console.log(' Examples:');
|
||||
console.log(chalk.gray(' ccw cli -p "Analyze auth module" --tool gemini'));
|
||||
console.log(chalk.gray(' ccw cli -f prompt.txt --tool codex --mode write'));
|
||||
@@ -960,6 +983,7 @@ export async function cliCommand(
|
||||
console.log(chalk.gray(' ccw cli --resume --tool gemini'));
|
||||
console.log(chalk.gray(' ccw cli -p "..." --cache "@src/**/*.ts" --tool codex'));
|
||||
console.log(chalk.gray(' ccw cli -p "..." --cache "@src/**/*" --inject-mode progressive --tool gemini'));
|
||||
console.log(chalk.gray(' ccw cli output <id> --final # View result with usage hint'));
|
||||
console.log();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ async function loadCliHistory(options = {}) {
|
||||
const { limit = cliHistoryLimit, tool = cliHistoryFilter, status = null } = options;
|
||||
|
||||
// Use history-native endpoint to get native session info
|
||||
let url = `/api/cli/history-native?path=${encodeURIComponent(projectPath)}&limit=${limit}`;
|
||||
// Use recursiveQueryEnabled setting (from cli-status.js) to control recursive query
|
||||
const recursive = typeof recursiveQueryEnabled !== 'undefined' ? recursiveQueryEnabled : true;
|
||||
let url = `/api/cli/history-native?path=${encodeURIComponent(projectPath)}&limit=${limit}&recursive=${recursive}`;
|
||||
if (tool) url += `&tool=${tool}`;
|
||||
if (status) url += `&status=${status}`;
|
||||
if (cliHistorySearch) url += `&search=${encodeURIComponent(cliHistorySearch)}`;
|
||||
@@ -36,9 +38,12 @@ async function loadCliHistory(options = {}) {
|
||||
async function loadNativeSessionContent(executionId, sourceDir) {
|
||||
try {
|
||||
// If sourceDir provided, use it to build the correct path
|
||||
const basePath = sourceDir && sourceDir !== '.'
|
||||
? projectPath + '/' + sourceDir
|
||||
: projectPath;
|
||||
// Check if sourceDir is absolute path (contains : or starts with /)
|
||||
let basePath = projectPath;
|
||||
if (sourceDir && sourceDir !== '.') {
|
||||
const isAbsolute = sourceDir.includes(':') || sourceDir.startsWith('/');
|
||||
basePath = isAbsolute ? sourceDir : projectPath + '/' + sourceDir;
|
||||
}
|
||||
const url = `/api/cli/native-session?path=${encodeURIComponent(basePath)}&id=${encodeURIComponent(executionId)}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) return null;
|
||||
@@ -65,9 +70,12 @@ async function loadEnrichedConversation(executionId) {
|
||||
async function loadExecutionDetail(executionId, sourceDir) {
|
||||
try {
|
||||
// If sourceDir provided, use it to build the correct path
|
||||
const basePath = sourceDir && sourceDir !== '.'
|
||||
? projectPath + '/' + sourceDir
|
||||
: projectPath;
|
||||
// Check if sourceDir is absolute path (contains : or starts with /)
|
||||
let basePath = projectPath;
|
||||
if (sourceDir && sourceDir !== '.') {
|
||||
const isAbsolute = sourceDir.includes(':') || sourceDir.startsWith('/');
|
||||
basePath = isAbsolute ? sourceDir : projectPath + '/' + sourceDir;
|
||||
}
|
||||
const url = `/api/cli/execution?path=${encodeURIComponent(basePath)}&id=${encodeURIComponent(executionId)}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error('Execution not found');
|
||||
@@ -155,11 +163,14 @@ function renderCliHistory() {
|
||||
<div class="cli-history-meta">
|
||||
<span><i data-lucide="clock" class="w-3 h-3"></i> ${timeAgo}</span>
|
||||
<span><i data-lucide="timer" class="w-3 h-3"></i> ${duration}</span>
|
||||
<span><i data-lucide="hash" class="w-3 h-3"></i> ${exec.id.split('-')[0]}</span>
|
||||
<span title="${exec.id}"><i data-lucide="hash" class="w-3 h-3"></i> ${exec.id.substring(0, 13)}...${exec.id.split('-').pop()}</span>
|
||||
${turnBadge}
|
||||
</div>
|
||||
</div>
|
||||
<div class="cli-history-actions">
|
||||
<button class="btn-icon" onclick="event.stopPropagation(); copyCliExecutionId('${exec.id}')" title="Copy ID">
|
||||
<i data-lucide="copy" class="w-3.5 h-3.5"></i>
|
||||
</button>
|
||||
${hasNative ? `
|
||||
<button class="btn-icon" onclick="event.stopPropagation(); showNativeSessionDetail('${exec.id}', '${sourceDirEscaped}')" title="View Native Session">
|
||||
<i data-lucide="file-json" class="w-3.5 h-3.5"></i>
|
||||
@@ -431,9 +442,12 @@ function confirmDeleteExecution(executionId, sourceDir) {
|
||||
async function deleteExecution(executionId, sourceDir) {
|
||||
try {
|
||||
// Build correct path - use sourceDir if provided for recursive items
|
||||
const basePath = sourceDir && sourceDir !== '.'
|
||||
? projectPath + '/' + sourceDir
|
||||
: projectPath;
|
||||
// Check if sourceDir is absolute path (contains : or starts with /)
|
||||
let basePath = projectPath;
|
||||
if (sourceDir && sourceDir !== '.') {
|
||||
const isAbsolute = sourceDir.includes(':') || sourceDir.startsWith('/');
|
||||
basePath = isAbsolute ? sourceDir : projectPath + '/' + sourceDir;
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/cli/execution?path=${encodeURIComponent(basePath)}&id=${encodeURIComponent(executionId)}`, {
|
||||
method: 'DELETE'
|
||||
@@ -461,6 +475,18 @@ async function deleteExecution(executionId, sourceDir) {
|
||||
}
|
||||
|
||||
// ========== Copy Functions ==========
|
||||
async function copyCliExecutionId(executionId) {
|
||||
if (navigator.clipboard) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(executionId);
|
||||
showRefreshToast('ID copied: ' + executionId, 'success');
|
||||
} catch (err) {
|
||||
console.error('Failed to copy ID:', err);
|
||||
showRefreshToast('Failed to copy ID', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function copyExecutionPrompt(executionId) {
|
||||
const detail = await loadExecutionDetail(executionId);
|
||||
if (!detail) {
|
||||
|
||||
@@ -69,8 +69,10 @@ async function renderCliHistoryView() {
|
||||
'</div>'
|
||||
: '';
|
||||
|
||||
// Normalize sourceDir: convert backslashes to forward slashes for safe onclick handling
|
||||
var normalizedSourceDir = (exec.sourceDir || '').replace(/\\/g, '/');
|
||||
historyHtml += '<div class="history-item' + (isSelected ? ' history-item-selected' : '') + '" ' +
|
||||
'onclick="' + (isMultiSelectMode ? 'toggleExecutionSelection(\'' + exec.id + '\')' : 'showExecutionDetail(\'' + exec.id + '\', \'' + (exec.sourceDir || '').replace(/\'/g, "\\'") + '\')') + '">' +
|
||||
'onclick="' + (isMultiSelectMode ? 'toggleExecutionSelection(\'' + exec.id + '\')' : 'showExecutionDetail(\'' + exec.id + '\', \'' + normalizedSourceDir.replace(/'/g, "\\'") + '\')') + '">' +
|
||||
checkboxHtml +
|
||||
'<div class="history-item-main">' +
|
||||
'<div class="history-item-header">' +
|
||||
@@ -182,6 +184,16 @@ async function renderCliHistoryView() {
|
||||
}
|
||||
|
||||
// ========== Actions ==========
|
||||
async function copyExecutionId(executionId) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(executionId);
|
||||
showRefreshToast('ID copied: ' + executionId, 'success');
|
||||
} catch (err) {
|
||||
console.error('Failed to copy ID:', err);
|
||||
showRefreshToast('Failed to copy ID', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function filterCliHistoryView(tool) {
|
||||
cliHistoryFilter = tool || null;
|
||||
await loadCliHistory();
|
||||
|
||||
Reference in New Issue
Block a user