# Phase 2: Project Exploration

使用 `cli-explore-agent` 探索项目结构，生成文档所需的结构化数据。

## 探索角度

```javascript
const EXPLORATION_ANGLES = {
  web: ['architecture', 'ui-routes', 'api-endpoints', 'config'],
  cli: ['architecture', 'commands', 'config'],
  sdk: ['architecture', 'public-api', 'types', 'config'],
  desktop: ['architecture', 'ui-screens', 'config']
};
```

## 执行流程

```javascript
const config = JSON.parse(Read(`${workDir}/manual-config.json`));
const angles = EXPLORATION_ANGLES[config.software.type];

// 并行探索
const tasks = angles.map(angle => Task({
  subagent_type: 'cli-explore-agent',
  run_in_background: false,
  prompt: buildExplorationPrompt(angle, config, workDir)
}));

const results = await Promise.all(tasks);
```

## 探索配置

```javascript
const EXPLORATION_CONFIGS = {
  architecture: {
    task: '分析项目模块结构、入口点、依赖关系',
    patterns: ['src/*/', 'package.json', 'tsconfig.json'],
    output: 'exploration-architecture.json'
  },
  'ui-routes': {
    task: '提取 UI 路由、页面组件、导航结构',
    patterns: ['src/pages/**', 'src/views/**', 'app/**/page.*', 'src/router/**'],
    output: 'exploration-ui-routes.json'
  },
  'api-endpoints': {
    task: '提取 REST API 端点、请求/响应类型',
    patterns: ['src/**/*.controller.*', 'src/routes/**', 'openapi.*', 'swagger.*'],
    output: 'exploration-api-endpoints.json'
  },
  config: {
    task: '提取环境变量、配置文件选项',
    patterns: ['.env.example', 'config/**', 'docker-compose.yml'],
    output: 'exploration-config.json'
  },
  commands: {
    task: '提取 CLI 命令、选项、示例',
    patterns: ['src/cli*', 'bin/*', 'src/commands/**'],
    output: 'exploration-commands.json'
  }
};
```

## Prompt 构建

```javascript
function buildExplorationPrompt(angle, config, workDir) {
  const cfg = EXPLORATION_CONFIGS[angle];
  return `
[TASK]
${cfg.task}

[SCOPE]
项目类型: ${config.software.type}
扫描模式: deep-scan
文件模式: ${cfg.patterns.join(', ')}

[OUTPUT]
文件: ${workDir}/exploration/${cfg.output}
格式: JSON (schema-compliant)

[RETURN]
简要说明发现的内容数量和关键发现
`;
}
```

## 输出结构

```
exploration/
├── exploration-architecture.json   # 模块结构
├── exploration-ui-routes.json      # UI 路由
├── exploration-api-endpoints.json  # API 端点
├── exploration-config.json         # 配置选项
└── exploration-commands.json       # CLI 命令 (if CLI)
```

## 下一阶段

→ [Phase 3: Parallel Analysis](03-parallel-analysis.md)
