@mycodemap/mycodemap 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +138 -928
- package/README.zh-CN.md +1096 -0
- package/dist/cli/commands/analyze-options.d.ts.map +1 -1
- package/dist/cli/commands/analyze-options.js +8 -0
- package/dist/cli/commands/analyze-options.js.map +1 -1
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +60 -41
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/benchmark.d.ts +8 -0
- package/dist/cli/commands/benchmark.d.ts.map +1 -0
- package/dist/cli/commands/benchmark.js +150 -0
- package/dist/cli/commands/benchmark.js.map +1 -0
- package/dist/cli/commands/deps.d.ts +2 -1
- package/dist/cli/commands/deps.d.ts.map +1 -1
- package/dist/cli/commands/deps.js +107 -78
- package/dist/cli/commands/deps.js.map +1 -1
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +34 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/query.d.ts +1 -0
- package/dist/cli/commands/query.d.ts.map +1 -1
- package/dist/cli/commands/query.js +123 -140
- package/dist/cli/commands/query.js.map +1 -1
- package/dist/cli/doctor/check-agent.d.ts +3 -0
- package/dist/cli/doctor/check-agent.d.ts.map +1 -0
- package/dist/cli/doctor/check-agent.js +60 -0
- package/dist/cli/doctor/check-agent.js.map +1 -0
- package/dist/cli/doctor/check-ghost-commands.d.ts +3 -0
- package/dist/cli/doctor/check-ghost-commands.d.ts.map +1 -0
- package/dist/cli/doctor/check-ghost-commands.js +86 -0
- package/dist/cli/doctor/check-ghost-commands.js.map +1 -0
- package/dist/cli/doctor/check-native-deps.d.ts +3 -0
- package/dist/cli/doctor/check-native-deps.d.ts.map +1 -0
- package/dist/cli/doctor/check-native-deps.js +54 -0
- package/dist/cli/doctor/check-native-deps.js.map +1 -0
- package/dist/cli/doctor/check-workspace-drift.d.ts +3 -0
- package/dist/cli/doctor/check-workspace-drift.d.ts.map +1 -0
- package/dist/cli/doctor/check-workspace-drift.js +83 -0
- package/dist/cli/doctor/check-workspace-drift.js.map +1 -0
- package/dist/cli/doctor/formatter.d.ts +20 -0
- package/dist/cli/doctor/formatter.d.ts.map +1 -0
- package/dist/cli/doctor/formatter.js +91 -0
- package/dist/cli/doctor/formatter.js.map +1 -0
- package/dist/cli/doctor/index.d.ts +8 -0
- package/dist/cli/doctor/index.d.ts.map +1 -0
- package/dist/cli/doctor/index.js +9 -0
- package/dist/cli/doctor/index.js.map +1 -0
- package/dist/cli/doctor/orchestrator.d.ts +3 -0
- package/dist/cli/doctor/orchestrator.d.ts.map +1 -0
- package/dist/cli/doctor/orchestrator.js +37 -0
- package/dist/cli/doctor/orchestrator.js.map +1 -0
- package/dist/cli/doctor/types.d.ts +19 -0
- package/dist/cli/doctor/types.d.ts.map +1 -0
- package/dist/cli/doctor/types.js +4 -0
- package/dist/cli/doctor/types.js.map +1 -0
- package/dist/cli/index.js +72 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/interface-contract/commands/analyze.d.ts +3 -0
- package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/analyze.js +138 -0
- package/dist/cli/interface-contract/commands/analyze.js.map +1 -0
- package/dist/cli/interface-contract/commands/benchmark.d.ts +3 -0
- package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/benchmark.js +107 -0
- package/dist/cli/interface-contract/commands/benchmark.js.map +1 -0
- package/dist/cli/interface-contract/commands/deps.d.ts +3 -0
- package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/deps.js +129 -0
- package/dist/cli/interface-contract/commands/deps.js.map +1 -0
- package/dist/cli/interface-contract/commands/doctor.d.ts +3 -0
- package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/doctor.js +59 -0
- package/dist/cli/interface-contract/commands/doctor.js.map +1 -0
- package/dist/cli/interface-contract/commands/index.d.ts +9 -0
- package/dist/cli/interface-contract/commands/index.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/index.js +18 -0
- package/dist/cli/interface-contract/commands/index.js.map +1 -0
- package/dist/cli/interface-contract/commands/init.d.ts +3 -0
- package/dist/cli/interface-contract/commands/init.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/init.js +87 -0
- package/dist/cli/interface-contract/commands/init.js.map +1 -0
- package/dist/cli/interface-contract/commands/query.d.ts +3 -0
- package/dist/cli/interface-contract/commands/query.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/query.js +185 -0
- package/dist/cli/interface-contract/commands/query.js.map +1 -0
- package/dist/cli/interface-contract/index.d.ts +22 -0
- package/dist/cli/interface-contract/index.d.ts.map +1 -0
- package/dist/cli/interface-contract/index.js +41 -0
- package/dist/cli/interface-contract/index.js.map +1 -0
- package/dist/cli/interface-contract/schema.d.ts +30 -0
- package/dist/cli/interface-contract/schema.d.ts.map +1 -0
- package/dist/cli/interface-contract/schema.js +72 -0
- package/dist/cli/interface-contract/schema.js.map +1 -0
- package/dist/cli/interface-contract/types.d.ts +76 -0
- package/dist/cli/interface-contract/types.d.ts.map +1 -0
- package/dist/cli/interface-contract/types.js +4 -0
- package/dist/cli/interface-contract/types.js.map +1 -0
- package/dist/cli/output/apply-suggestion.d.ts +12 -0
- package/dist/cli/output/apply-suggestion.d.ts.map +1 -0
- package/dist/cli/output/apply-suggestion.js +29 -0
- package/dist/cli/output/apply-suggestion.js.map +1 -0
- package/dist/cli/output/error-codes.d.ts +22 -0
- package/dist/cli/output/error-codes.d.ts.map +1 -0
- package/dist/cli/output/error-codes.js +82 -0
- package/dist/cli/output/error-codes.js.map +1 -0
- package/dist/cli/output/errors.d.ts +14 -0
- package/dist/cli/output/errors.d.ts.map +1 -0
- package/dist/cli/output/errors.js +170 -0
- package/dist/cli/output/errors.js.map +1 -0
- package/dist/cli/output/index.d.ts +13 -0
- package/dist/cli/output/index.d.ts.map +1 -0
- package/dist/cli/output/index.js +11 -0
- package/dist/cli/output/index.js.map +1 -0
- package/dist/cli/output/mode.d.ts +12 -0
- package/dist/cli/output/mode.d.ts.map +1 -0
- package/dist/cli/output/mode.js +23 -0
- package/dist/cli/output/mode.js.map +1 -0
- package/dist/cli/output/progress.d.ts +9 -0
- package/dist/cli/output/progress.d.ts.map +1 -0
- package/dist/cli/output/progress.js +65 -0
- package/dist/cli/output/progress.js.map +1 -0
- package/dist/cli/output/render.d.ts +11 -0
- package/dist/cli/output/render.d.ts.map +1 -0
- package/dist/cli/output/render.js +18 -0
- package/dist/cli/output/render.js.map +1 -0
- package/dist/cli/output/types.d.ts +53 -0
- package/dist/cli/output/types.d.ts.map +1 -0
- package/dist/cli/output/types.js +14 -0
- package/dist/cli/output/types.js.map +1 -0
- package/dist/cli/output/wasm-fallback.d.ts +13 -0
- package/dist/cli/output/wasm-fallback.d.ts.map +1 -0
- package/dist/cli/output/wasm-fallback.js +92 -0
- package/dist/cli/output/wasm-fallback.js.map +1 -0
- package/dist/cli/tree-sitter-check.d.ts +6 -1
- package/dist/cli/tree-sitter-check.d.ts.map +1 -1
- package/dist/cli/tree-sitter-check.js +23 -1
- package/dist/cli/tree-sitter-check.js.map +1 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js +2 -2
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +23 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.js +210 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -0
- package/dist/orchestrator/types.d.ts +2 -0
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/parser/implementations/tree-sitter-loader.d.ts +16 -0
- package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -0
- package/dist/parser/implementations/tree-sitter-loader.js +105 -0
- package/dist/parser/implementations/tree-sitter-loader.js.map +1 -0
- package/dist/parser/implementations/tree-sitter-parser.d.ts +3 -0
- package/dist/parser/implementations/tree-sitter-parser.d.ts.map +1 -1
- package/dist/parser/implementations/tree-sitter-parser.js +8 -3
- package/dist/parser/implementations/tree-sitter-parser.js.map +1 -1
- package/dist/server/mcp/schema-adapter.d.ts +45 -0
- package/dist/server/mcp/schema-adapter.d.ts.map +1 -0
- package/dist/server/mcp/schema-adapter.js +290 -0
- package/dist/server/mcp/schema-adapter.js.map +1 -0
- package/dist/server/mcp/server.d.ts.map +1 -1
- package/dist/server/mcp/server.js +32 -2
- package/dist/server/mcp/server.js.map +1 -1
- package/docs/AI_ASSISTANT_SETUP.md +169 -12
- package/docs/README.md +40 -1
- package/docs/SETUP_GUIDE.md +11 -14
- package/docs/ai-guide/COMMANDS.md +68 -10
- package/docs/ai-guide/INTEGRATION.md +77 -10
- package/docs/ai-guide/OUTPUT.md +295 -2
- package/docs/ai-guide/PROMPTS.md +2 -2
- package/docs/ai-guide/QUICKSTART.md +28 -1
- package/docs/ai-guide/README.md +2 -2
- package/docs/archive/ideation/2026-04-15-executable-architecture-constitution-ideation-archive.md +70 -0
- package/docs/archive/ideation/2026-04-20-mycodemap-init-enhancements-ideation-archive.md +109 -0
- package/docs/archive/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation-archive.md +54 -0
- package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +10 -22
- package/docs/ideation/2026-04-20-mycodemap-init-enhancements-ideation.md +15 -60
- package/docs/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation.md +47 -52
- package/docs/ideation/2026-04-29-ux-install-agent-experience-ideation.md +256 -0
- package/docs/plans/2026-04-30-install-guide-and-repo-analyzer-design.md +394 -0
- package/docs/rules/README.md +1 -0
- package/docs/rules/architecture-guardrails.md +2 -1
- package/docs/rules/engineering-with-codex-openai.md +1 -1
- package/docs/rules/harness.md +106 -0
- package/docs/rules/pre-release-checklist.md +28 -0
- package/docs/rules/testing.md +51 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/SKILL.md +294 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/references/analysis-guide.md +166 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/references/module-analysis-guide.md +150 -0
- package/package.json +7 -4
- package/scripts/sync-analyze-docs.js +2 -2
- package/scripts/validate-docs.js +113 -16
- package/docs/references/tmp.md +0 -527
package/README.md
CHANGED
|
@@ -1,80 +1,98 @@
|
|
|
1
1
|
# CodeMap
|
|
2
2
|
|
|
3
|
-
> AI-
|
|
3
|
+
> AI-Native, Human-Friendly Code Architecture Governance Infrastructure — `v2.0` Milestone
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[中文版本](./README.zh-CN.md)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
CodeMap is an AI-Native-first, human-friendly code architecture governance infrastructure for TypeScript/JavaScript/Go projects. `v2.0` upgraded the CLI surface to a schema-driven self-describing unified interface: a single contract schema simultaneously generates the parser, MCP tool definitions, `--help-json`, and shell completions. `codemap doctor` provides continuous health diagnostics, the `Failure-to-Action Protocol` turns errors into structured state transitions, and the WASM-first build foundation eliminates the #1 installation drop-off caused by native dependency compilation failures. Human users get table/color output via `--human` or TTY auto-detection; AI/Agents receive JSON/NDJSON by default.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- **核心分析命令** - 提供 `generate`、`query`、`deps`、`impact`、`complexity`、`cycles`、`analyze`、`design`、`export`、`ci`,并提供 experimental `mcp`
|
|
11
|
-
- **机器可读优先** - 结构化输出是产品基线;当前 CLI 过渡期仍主要通过 `--json` 暴露机器可读结果
|
|
12
|
-
- **分层架构 (MVP3)** - 保持 `Interface → Infrastructure → Domain → Server → CLI` 的明确边界
|
|
13
|
-
- **双层解析模式** - 提供 `fast`(快速正则)和 `smart`(TypeScript AST)两种解析模式
|
|
14
|
-
- **多语言支持** - 支持 TypeScript/JavaScript、Go、Python(可扩展架构)
|
|
15
|
-
- **依赖/影响/复杂度分析** - 适合变更影响评估、重构盘点和架构回溯
|
|
16
|
-
- **CI 门禁与文档护栏** - 提供提交格式、文件头、风险评估、文档/输出契约检查
|
|
17
|
-
- **多格式导出与存储抽象** - 支持导出图数据,并保留文件系统/内存/图数据库后端接口
|
|
9
|
+
---
|
|
18
10
|
|
|
19
|
-
##
|
|
11
|
+
## Features
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
|------|----------|
|
|
23
|
-
| 产品是谁 | `CodeMap` 是 AI-first 代码地图工具,而不是泛化的实现/发布/HTTP 工具箱 |
|
|
24
|
-
| 主要消费者 | `AI/Agent 是主要消费者`;人类开发者负责配置、维护与按需阅读输出 |
|
|
25
|
-
| 输出契约 | 目标是机器可读优先;`当前 CLI 现实` 是多数命令通过 `--json` 提供结构化结果,`analyze` 额外支持 `--output-mode machine|human` |
|
|
26
|
-
| 架构边界 | `Server Layer` 是内部架构层,不等于公共 `mycodemap server` 命令 |
|
|
13
|
+
### v2.0 Core Features
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
- **Interface Contract Schema** — A single machine-readable schema defines the entire CLI surface; `codemap --schema` outputs the full contract JSON for agent introspection and dynamic adaptation
|
|
16
|
+
- **CLI-as-MCP Automatic Gateway** — All schema-defined CLI commands are automatically exposed as MCP tools with zero handwritten maintenance; new commands automatically get MCP exposure
|
|
17
|
+
- **AI-First Default Output** — JSON/NDJSON by default; `--human` flag renders tables/colors on demand; TTY auto-detection preserves interactive experience; progress events go to stderr
|
|
18
|
+
- **`codemap doctor`** — Continuous health diagnostics detecting ghost commands, native dependency issues, workspace drift, and agent connectivity
|
|
19
|
+
- **Failure-to-Action Protocol** — Every error returns structured `rootCause` + `remediationPlan` + `confidence` + `nextCommand`; agents can attempt automatic remediation
|
|
20
|
+
- **Validation Router** — Routes minimal verification by change type; docs guardrail validates that referenced commands are real and runnable
|
|
21
|
+
- **WASM-First Build Foundation** — `tree-sitter` / `better-sqlite3` provide WASM fallback paths; `--native` forces native mode; `codemap benchmark` compares WASM vs Native performance
|
|
29
22
|
|
|
30
|
-
|
|
23
|
+
### Core Capabilities
|
|
24
|
+
|
|
25
|
+
- **AI-first code map** — Generates `AI_MAP.md`, `CONTEXT.md`, `codemap.json`, and other AI/Agent-consumable context
|
|
26
|
+
- **Core analysis commands** — `generate`, `query`, `deps`, `impact`, `complexity`, `cycles`, `analyze`, `design`, `export`, `ci`
|
|
27
|
+
- **Layered architecture (MVP3)** — Clear boundaries: `Interface → Infrastructure → Domain → Server → CLI`
|
|
28
|
+
- **Dual parsing modes** — `fast` (regex) and `smart` (TypeScript AST)
|
|
29
|
+
- **Multi-language support** — TypeScript/JavaScript, Go, Python (extensible architecture)
|
|
30
|
+
- **Dependency / impact / complexity analysis** — For change impact assessment, refactoring inventory, and architecture retrospectives
|
|
31
|
+
- **CI gate and docs guardrail** — Commit format, file headers, risk assessment, docs/output contract checks
|
|
32
|
+
- **Multi-format export and storage abstraction** — Export graph data with filesystem / memory / sqlite backends
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
31
37
|
|
|
32
38
|
```bash
|
|
33
|
-
#
|
|
39
|
+
# Using npm
|
|
34
40
|
npm install @mycodemap/mycodemap
|
|
35
41
|
|
|
36
|
-
#
|
|
42
|
+
# Using yarn
|
|
37
43
|
yarn add @mycodemap/mycodemap
|
|
38
44
|
|
|
39
|
-
#
|
|
45
|
+
# Using pnpm
|
|
40
46
|
pnpm add @mycodemap/mycodemap
|
|
41
47
|
|
|
42
|
-
#
|
|
48
|
+
# Global install (recommended for CLI access)
|
|
43
49
|
npm install -g @mycodemap/mycodemap
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
**Requirements**: Node.js >= 20.0.0
|
|
53
|
+
|
|
54
|
+
### No Build Tools? No Problem
|
|
55
|
+
|
|
56
|
+
CodeMap ships with WASM-first fallback. If your system lacks `python`, `make`, or `gcc`:
|
|
57
|
+
- `tree-sitter` automatically falls back to `web-tree-sitter` (WASM)
|
|
58
|
+
- `better-sqlite3` automatically falls back to `node:sqlite` (Node.js 22+) or `sql.js` (WASM)
|
|
59
|
+
- No manual intervention required — fallback activates on first run
|
|
60
|
+
|
|
61
|
+
### Force Native (Performance)
|
|
62
|
+
|
|
63
|
+
If you have build tools installed and want maximum performance:
|
|
64
|
+
```bash
|
|
65
|
+
mycodemap --native <command>
|
|
66
|
+
```
|
|
47
67
|
|
|
48
|
-
|
|
49
|
-
- `hono` - HTTP 服务器框架
|
|
50
|
-
- `@hono/node-server` - Node.js 适配器
|
|
68
|
+
---
|
|
51
69
|
|
|
52
|
-
##
|
|
70
|
+
## Quick Start
|
|
53
71
|
|
|
54
72
|
```bash
|
|
55
|
-
# 1.
|
|
73
|
+
# 1. Initialize configuration in project root
|
|
56
74
|
mycodemap init
|
|
57
75
|
|
|
58
|
-
# 2.
|
|
76
|
+
# 2. Generate code map
|
|
59
77
|
mycodemap generate
|
|
60
78
|
|
|
61
|
-
# 3.
|
|
79
|
+
# 3. View generated files
|
|
62
80
|
ls .mycodemap/
|
|
63
|
-
# AI_MAP.md -
|
|
64
|
-
# CONTEXT.md -
|
|
65
|
-
# context/ -
|
|
66
|
-
# codemap.json -
|
|
67
|
-
# dependency-graph.md - Mermaid
|
|
81
|
+
# AI_MAP.md - Project overview (for AI)
|
|
82
|
+
# CONTEXT.md - Context entry (links to context/README.md)
|
|
83
|
+
# context/ - Detailed module contexts
|
|
84
|
+
# codemap.json - Structured JSON data
|
|
85
|
+
# dependency-graph.md - Mermaid dependency graph
|
|
68
86
|
```
|
|
69
87
|
|
|
70
88
|
```bash
|
|
71
|
-
# 4.
|
|
89
|
+
# 4. For AI/Agent: structured output is the default
|
|
72
90
|
mycodemap impact -f src/cli/index.ts -j
|
|
73
91
|
|
|
74
|
-
#
|
|
75
|
-
mycodemap analyze -i read -t src/cli/index.ts --
|
|
92
|
+
# Human-readable output on demand
|
|
93
|
+
mycodemap analyze -i read -t src/cli/index.ts --human
|
|
76
94
|
|
|
77
|
-
#
|
|
95
|
+
# Human design → design contract → AI/Agent consumption
|
|
78
96
|
cp docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md mycodemap.design.md
|
|
79
97
|
mycodemap design validate mycodemap.design.md --json
|
|
80
98
|
mycodemap design map mycodemap.design.md --json
|
|
@@ -82,950 +100,142 @@ mycodemap design handoff mycodemap.design.md --json
|
|
|
82
100
|
mycodemap design verify mycodemap.design.md --json
|
|
83
101
|
```
|
|
84
102
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
## 文档导航
|
|
88
|
-
|
|
89
|
-
### 人类用户
|
|
90
|
-
|
|
91
|
-
| 文档 | 目标读者 | 内容 |
|
|
92
|
-
|------|----------|------|
|
|
93
|
-
| [🧭 文档索引](docs/README.md) | 所有读者 | 文档分层、阅读顺序与迁移状态 |
|
|
94
|
-
| [🏗️ 架构总图](ARCHITECTURE.md) | 开发者 | 系统地图、模块边界、主执行流 |
|
|
95
|
-
| [📋 MVP3 实施路线图](docs/exec-plans/MVP3-IMPLEMENTATION-ROADMAP.md) | 开发者 | 分层架构重构完整计划与状态 |
|
|
96
|
-
| [📖 安装配置指南](docs/SETUP_GUIDE.md) | 人类开发者 | 完整的安装、配置和使用指南 |
|
|
97
|
-
| [📁 配置示例](examples/) | 所有用户 | 各平台的现成配置文件 |
|
|
98
|
-
|
|
99
|
-
### 🤖 AI / Agent 专属文档
|
|
100
|
-
|
|
101
|
-
> 如果你是 AI 助手或 Agent,**请优先阅读以下文档**:
|
|
102
|
-
|
|
103
|
-
| 文档 | 说明 |
|
|
104
|
-
|------|------|
|
|
105
|
-
| **[📘 AI_GUIDE.md](AI_GUIDE.md)** | **AI 主指南** - 快速参考、命令选择决策树、提示词模板速用 |
|
|
106
|
-
| **[🚀 docs/ai-guide/QUICKSTART.md](docs/ai-guide/QUICKSTART.md)** | 快速开始、场景-命令映射表 |
|
|
107
|
-
| **[📚 docs/ai-guide/COMMANDS.md](docs/ai-guide/COMMANDS.md)** | 完整 CLI 命令参考 |
|
|
108
|
-
| **[📊 docs/ai-guide/OUTPUT.md](docs/ai-guide/OUTPUT.md)** | JSON 输出结构解析 |
|
|
109
|
-
| **[🔄 docs/ai-guide/PATTERNS.md](docs/ai-guide/PATTERNS.md)** | 标准工作流模式 |
|
|
110
|
-
| **[💬 docs/ai-guide/PROMPTS.md](docs/ai-guide/PROMPTS.md)** | 即用型提示词模板 |
|
|
111
|
-
| **[🔧 docs/ai-guide/INTEGRATION.md](docs/ai-guide/INTEGRATION.md)** | 集成指南、错误处理 |
|
|
112
|
-
| **[🛡️ AGENTS.md](AGENTS.md)** | 仓库级强约束、任务分级、代码红线 |
|
|
113
|
-
| **[⚡ CLAUDE.md](CLAUDE.md)** | AI 入口路由、下一步阅读导航 |
|
|
114
|
-
| **[🤖 docs/AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md)** | AI 助手配置指引 |
|
|
115
|
-
| **[🛠️ docs/rules/engineering-with-codex-openai.md](docs/rules/engineering-with-codex-openai.md)** | 面向 agent 的工程约束 |
|
|
116
|
-
|
|
117
|
-
**AI 快速入口**: `.cursorrules` | `.github/copilot-instructions.md`
|
|
103
|
+
After generation, provide `.mycodemap/AI_MAP.md` to your AI assistant for rapid project understanding. For structured results, use JSON/machine mode.
|
|
118
104
|
|
|
119
|
-
|
|
105
|
+
---
|
|
120
106
|
|
|
121
|
-
|
|
107
|
+
## CLI Commands
|
|
122
108
|
|
|
123
109
|
### `mycodemap init`
|
|
124
110
|
|
|
125
|
-
|
|
111
|
+
Initialize and reconcile the project's CodeMap workspace / config / hooks / rules state.
|
|
126
112
|
|
|
127
113
|
```bash
|
|
128
|
-
mycodemap init #
|
|
129
|
-
mycodemap init --interactive #
|
|
130
|
-
mycodemap init -y #
|
|
131
|
-
|
|
132
|
-
# 别名:codemap init 也可以使用
|
|
114
|
+
mycodemap init # Show reconciliation preview (default: no write)
|
|
115
|
+
mycodemap init --interactive # Explicitly show preview (same as default)
|
|
116
|
+
mycodemap init -y # Write with defaults
|
|
133
117
|
```
|
|
134
118
|
|
|
135
|
-
| 选项 | 说明 |
|
|
136
|
-
|------|------|
|
|
137
|
-
| `-y, --yes` | 使用默认配置 |
|
|
138
|
-
| `--interactive` | 仅显示 reconciliation preview,不写入文件 |
|
|
139
|
-
|
|
140
|
-
默认显示 reconciliation preview;使用 `mycodemap init -y` 或 `mycodemap init --yes` 才会真正写入。
|
|
141
|
-
|
|
142
|
-
执行后会收敛 `.mycodemap/config.json`,并把 machine-readable receipt 写入 `.mycodemap/status/init-last.json`。
|
|
143
|
-
|
|
144
|
-
`init` 还会同步 `.mycodemap/hooks/` 与 `.mycodemap/rules/`;但不会自动改写团队自有的 `CLAUDE.md` / `AGENTS.md`,只会在 receipt 中输出可复制片段。
|
|
145
|
-
|
|
146
119
|
### `mycodemap generate`
|
|
147
120
|
|
|
148
|
-
|
|
121
|
+
Analyze the project and generate code map files.
|
|
149
122
|
|
|
150
123
|
```bash
|
|
151
|
-
mycodemap generate #
|
|
152
|
-
mycodemap generate -m smart #
|
|
153
|
-
mycodemap generate -o ./docs/codemap #
|
|
154
|
-
mycodemap generate --symbol-level #
|
|
155
|
-
|
|
156
|
-
# 别名:codemap generate 也可以使用
|
|
124
|
+
mycodemap generate # Default hybrid mode
|
|
125
|
+
mycodemap generate -m smart # Smart mode (AST deep analysis)
|
|
126
|
+
mycodemap generate -o ./docs/codemap # Custom output directory
|
|
127
|
+
mycodemap generate --symbol-level # Extra symbol-level call deps
|
|
157
128
|
```
|
|
158
129
|
|
|
159
|
-
|
|
|
160
|
-
|
|
161
|
-
| `-m, --mode <mode>` |
|
|
162
|
-
| `-o, --output <dir>` |
|
|
163
|
-
| `--symbol-level` |
|
|
164
|
-
| `--ai-context` | 为每个文件生成描述 | - |
|
|
165
|
-
|
|
166
|
-
- `codemap.json` 现在会显式写出 `graphStatus`、`failedFileCount` 与可选 `parseFailureFiles`。
|
|
167
|
-
- 当某些发现到的文件没有成功进入最终图时,`graphStatus` 会降级为 `partial`;不要把这种结果当成完整图继续做自动化决策。
|
|
168
|
-
|
|
169
|
-
**模式说明:**
|
|
170
|
-
|
|
171
|
-
| 模式 | 速度 | 精度 | 适用场景 |
|
|
172
|
-
|------|------|------|----------|
|
|
173
|
-
| `fast` | 极快 | 基本结构 | 日常开发、大型项目快速预览 |
|
|
174
|
-
| `smart` | 较慢 | 完整语义 | 深度分析、复杂度评估、类型推导 |
|
|
175
|
-
| `hybrid` | 自动 | 自适应 | **推荐** - 文件数<50用fast,≥50用smart |
|
|
130
|
+
| Option | Description | Default |
|
|
131
|
+
|--------|-------------|---------|
|
|
132
|
+
| `-m, --mode <mode>` | Analysis mode: `fast`, `smart`, or `hybrid` | `hybrid` |
|
|
133
|
+
| `-o, --output <dir>` | Output directory | `.mycodemap` |
|
|
134
|
+
| `--symbol-level` | Materialize symbol-level `call` deps | `false` |
|
|
176
135
|
|
|
177
136
|
### `mycodemap query`
|
|
178
137
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
mycodemap query -s "ModuleInfo" # 精确查询符号
|
|
183
|
-
mycodemap query -m "src/parser" # 查询模块信息
|
|
184
|
-
mycodemap query -d "analyzer" # 查询依赖关系
|
|
185
|
-
mycodemap query -S "cache" # 模糊搜索
|
|
186
|
-
mycodemap query -S "parse" -j # JSON 格式输出
|
|
187
|
-
mycodemap query -S "plugin" -l 5 # 限制结果数量
|
|
188
|
-
|
|
189
|
-
# 别名:codemap query 也可以使用
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
| 选项 | 说明 | 默认值 |
|
|
193
|
-
|------|------|------|
|
|
194
|
-
| `-s, --symbol <name>` | 精确查询符号 | - |
|
|
195
|
-
| `-m, --module <path>` | 查询模块信息 | - |
|
|
196
|
-
| `-d, --deps <name>` | 查询依赖关系 | - |
|
|
197
|
-
| `-S, --search <word>` | 模糊搜索 | - |
|
|
198
|
-
| `-l, --limit <number>` | 限制结果数量 | `50` |
|
|
199
|
-
| `-j, --json` | 以 JSON 格式输出 | - |
|
|
200
|
-
|
|
201
|
-
### `mycodemap deps`
|
|
202
|
-
|
|
203
|
-
分析并输出模块的依赖关系树。
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
mycodemap deps # 查看所有模块的依赖统计
|
|
207
|
-
mycodemap deps -m "src/parser" # 查看指定模块的依赖树
|
|
208
|
-
mycodemap deps -m "src/parser" -j # JSON 格式输出
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
| 选项 | 说明 | 默认值 |
|
|
212
|
-
|------|------|--------|
|
|
213
|
-
| `-m, --module <path>` | 查询指定模块的依赖 | - |
|
|
214
|
-
| `-j, --json` | 以 JSON 格式输出 | - |
|
|
215
|
-
|
|
216
|
-
### `mycodemap cycles`
|
|
217
|
-
|
|
218
|
-
检测项目中的循环依赖。
|
|
219
|
-
|
|
220
|
-
```bash
|
|
221
|
-
mycodemap cycles # 检测所有循环依赖
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
### `mycodemap complexity`
|
|
225
|
-
|
|
226
|
-
分析代码复杂度,输出圈复杂度、认知复杂度和可维护性指数。
|
|
227
|
-
|
|
228
|
-
```bash
|
|
229
|
-
mycodemap complexity # 分析整个项目的复杂度
|
|
230
|
-
mycodemap complexity -f src/cli/index.ts # 分析指定文件的复杂度
|
|
231
|
-
mycodemap complexity -j # JSON 格式输出
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
| 选项 | 说明 | 默认值 |
|
|
235
|
-
|------|------|--------|
|
|
236
|
-
| `-f, --file <path>` | 查看指定文件的复杂度 | - |
|
|
237
|
-
| `-j, --json` | 以 JSON 格式输出 | - |
|
|
238
|
-
|
|
239
|
-
### `mycodemap impact`
|
|
240
|
-
|
|
241
|
-
评估指定文件或模块变更的影响范围。
|
|
242
|
-
|
|
243
|
-
```bash
|
|
244
|
-
mycodemap impact -f src/cli/index.ts # 分析指定文件的变更影响
|
|
245
|
-
mycodemap impact -f src/cli/index.ts --transitive # 包含传递依赖
|
|
246
|
-
mycodemap impact -f src/cli/index.ts -j # JSON 格式输出
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
| 选项 | 说明 | 默认值 |
|
|
250
|
-
|------|------|------|
|
|
251
|
-
| `-f, --file <path>` | **必填** 指定要分析的文件 | - |
|
|
252
|
-
| `-t, --transitive` | 包含传递依赖(间接影响) | - |
|
|
253
|
-
| `-j, --json` | 以 JSON 格式输出 | - |
|
|
254
|
-
|
|
255
|
-
### `mycodemap mcp`(experimental)
|
|
256
|
-
|
|
257
|
-
本地只读的 stdio MCP 薄切片。当前只提供两个工具:`codemap_query`、`codemap_impact`。
|
|
258
|
-
|
|
259
|
-
```bash
|
|
260
|
-
# 先生成 symbol-level 图
|
|
261
|
-
mycodemap generate --symbol-level
|
|
262
|
-
|
|
263
|
-
# 把当前仓库写入本地 MCP host 配置
|
|
264
|
-
mycodemap mcp install
|
|
265
|
-
|
|
266
|
-
# 由 MCP host 启动 stdio server
|
|
267
|
-
mycodemap mcp start
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
| 子命令 | 说明 |
|
|
271
|
-
|--------|------|
|
|
272
|
-
| `mcp install` | 把 experimental 本地 server 写入当前仓库 `.mcp.json` |
|
|
273
|
-
| `mcp start` | 启动本地 stdio MCP server;`stdout` 仅承载协议帧 |
|
|
274
|
-
|
|
275
|
-
- `mcp` 当前是 **experimental / local-only / read-only** surface,不是稳定长期 public API。
|
|
276
|
-
- 使用前必须先执行 `mycodemap generate --symbol-level`;否则工具会返回 `GRAPH_NOT_FOUND`。
|
|
277
|
-
- canonical 集成文档见 `docs/ai-guide/INTEGRATION.md`;若宿主暂时不支持真正 MCP,可先回退到传统 CLI wrapper 方式。
|
|
278
|
-
|
|
279
|
-
### 已移除的公共 CLI 命令
|
|
280
|
-
|
|
281
|
-
以下命令已从 public CLI 移除;直接调用时,CLI 会显式失败并给出迁移提示,而不是继续执行旧功能。
|
|
282
|
-
|
|
283
|
-
| 已移除命令 | 当前迁移方式 |
|
|
284
|
-
|------------|--------------|
|
|
285
|
-
| `watch` | 改用一次性的 `mycodemap generate` 刷新代码地图 |
|
|
286
|
-
| `report` | 直接读取 `.mycodemap/AI_MAP.md`,或使用 `mycodemap export <format>` 导出结果 |
|
|
287
|
-
| `logs` | 直接读取 `.mycodemap/logs/` 下的日志文件 |
|
|
288
|
-
| `server` | 公共 CLI 已移除;`Server Layer` 仍是内部架构层,不等于公开 `mycodemap server` 命令 |
|
|
289
|
-
|
|
290
|
-
### `mycodemap export` (MVP3)
|
|
291
|
-
|
|
292
|
-
导出代码图到各种格式。
|
|
138
|
+
Query symbols, modules, and dependencies in the code map.
|
|
293
139
|
|
|
294
140
|
```bash
|
|
295
|
-
mycodemap
|
|
296
|
-
mycodemap
|
|
297
|
-
mycodemap
|
|
298
|
-
mycodemap
|
|
299
|
-
mycodemap export json -o ./out # 指定输出路径
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
| 选项 | 说明 | 默认值 |
|
|
303
|
-
|------|------|--------|
|
|
304
|
-
| `-o, --output <path>` | 输出文件路径 | 自动根据格式生成 |
|
|
305
|
-
|
|
306
|
-
## 工作流编排(分析型 workflow)
|
|
307
|
-
|
|
308
|
-
`workflow` 是公开的 analysis-only 工作流能力,只编排分析阶段:`find → read → link → show`。
|
|
309
|
-
代码实现、commit 检查和 CI 运行不再属于 workflow phase;这些职责分别回到常规开发流程、`mycodemap ci` 与 `mycodemap ship`。
|
|
310
|
-
|
|
311
|
-
### 工作流阶段
|
|
312
|
-
|
|
313
|
-
```
|
|
314
|
-
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
315
|
-
│ find │ → │ read │ → │ link │ → │ show │
|
|
316
|
-
│ 查找代码线索 │ │ 阅读影响范围 │ │ 关联依赖引用 │ │ 展示概览结果 │
|
|
317
|
-
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
| 阶段 | 对应意图 | 说明 | 典型产物 |
|
|
321
|
-
|------|----------|------|----------|
|
|
322
|
-
| **find** | `analyze --intent find` | 查找符号、关键词与候选文件 | 相关文件 / 符号列表 |
|
|
323
|
-
| **read** | `analyze --intent read` | 阅读影响范围、复杂度与上下文 | 影响与复杂度摘要 |
|
|
324
|
-
| **link** | `analyze --intent link` | 汇总依赖、引用与关联关系 | 依赖 / 引用结果 |
|
|
325
|
-
| **show** | `analyze --intent show` | 生成模块概览与展示型摘要 | overview / summary 输出 |
|
|
326
|
-
|
|
327
|
-
> 内置模板(`refactoring` / `bugfix` / `feature` / `hotfix`)共享同一 4 阶段顺序,只通过不同的阶段阈值和适用场景调整体验。
|
|
328
|
-
|
|
329
|
-
## 设计契约输入面
|
|
330
|
-
|
|
331
|
-
`design` 是给“人类负责设计、AI 负责执行”协作链路准备的正式输入面。
|
|
332
|
-
先把设计写成 `mycodemap.design.md`,再用 CLI 校验必填 sections、空段、重复 heading 和未知 heading。
|
|
333
|
-
|
|
334
|
-
```bash
|
|
335
|
-
# 从 canonical template 起步
|
|
336
|
-
cp docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md mycodemap.design.md
|
|
337
|
-
|
|
338
|
-
# 使用默认文件名校验
|
|
339
|
-
mycodemap design validate mycodemap.design.md --json
|
|
340
|
-
|
|
341
|
-
# 校验通过后生成 candidate scope
|
|
342
|
-
mycodemap design map mycodemap.design.md --json
|
|
343
|
-
|
|
344
|
-
# 把 scope 打包成 handoff artifact,供 reviewer / AI agent 消费
|
|
345
|
-
mycodemap design handoff mycodemap.design.md --json
|
|
346
|
-
|
|
347
|
-
# 基于 reviewed handoff truth 做 verification / drift 检查
|
|
348
|
-
mycodemap design verify mycodemap.design.md --json
|
|
349
|
-
|
|
350
|
-
# 也可以显式传入其他路径
|
|
351
|
-
mycodemap design validate docs/designs/login.design.md
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
必填 sections:
|
|
355
|
-
- `## Goal`
|
|
356
|
-
- `## Constraints`
|
|
357
|
-
- `## Acceptance Criteria`
|
|
358
|
-
- `## Non-Goals`
|
|
359
|
-
|
|
360
|
-
> 建议最小工作流:`design validate → design map → design handoff → design verify`。`design map --json` 会返回 `summary`、`candidates`、`diagnostics` 与 `unknowns`;`design handoff --json` 会继续返回 `readyForExecution`、`approvals`、`assumptions` 与 `openQuestions`,默认 artifact 路径为 `.mycodemap/handoffs/{stem}.handoff.md|json`;`design verify --json` 会返回 `checklist`、`drift`、`diagnostics` 与 `readyForExecution`,其中 review-needed 不会直接变成非零退出,只有 blocker diagnostics 才会阻断。
|
|
361
|
-
|
|
362
|
-
### 工作流 CLI 命令
|
|
363
|
-
|
|
364
|
-
```bash
|
|
365
|
-
# 启动工作流
|
|
366
|
-
mycodemap workflow start "实现用户认证模块"
|
|
367
|
-
# 启动工作流并指定模板(会保留 4 阶段顺序)
|
|
368
|
-
mycodemap workflow start "修复登录接口 500" --template bugfix
|
|
369
|
-
|
|
370
|
-
# 查看当前工作流状态
|
|
371
|
-
mycodemap workflow status
|
|
372
|
-
|
|
373
|
-
# 可视化当前工作流(支持 --timeline / --results)
|
|
374
|
-
mycodemap workflow visualize
|
|
375
|
-
|
|
376
|
-
# 推进到下一阶段
|
|
377
|
-
mycodemap workflow proceed
|
|
378
|
-
|
|
379
|
-
# 恢复当前活动工作流(可选传 workflow-id)
|
|
380
|
-
mycodemap workflow resume
|
|
381
|
-
mycodemap workflow resume <workflow-id>
|
|
382
|
-
|
|
383
|
-
# 创建检查点
|
|
384
|
-
mycodemap workflow checkpoint
|
|
385
|
-
|
|
386
|
-
# 列出所有工作流
|
|
387
|
-
mycodemap workflow list
|
|
388
|
-
|
|
389
|
-
# 删除工作流
|
|
390
|
-
mycodemap workflow delete <workflow-id>
|
|
391
|
-
|
|
392
|
-
# 模板管理
|
|
393
|
-
mycodemap workflow template list --all
|
|
394
|
-
mycodemap workflow template info bugfix
|
|
395
|
-
mycodemap workflow template apply bugfix
|
|
396
|
-
mycodemap workflow template recommend "紧急修复支付超时"
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### 工作流使用示例
|
|
400
|
-
|
|
401
|
-
```bash
|
|
402
|
-
# 示例:围绕一个模块逐步收敛上下文
|
|
403
|
-
$ mycodemap workflow start "梳理缓存模块上下文"
|
|
404
|
-
[WORKFLOW STARTED]
|
|
405
|
-
Task: 梳理缓存模块上下文
|
|
406
|
-
Phase: find
|
|
407
|
-
|
|
408
|
-
# 查看当前分析阶段与进度
|
|
409
|
-
$ mycodemap workflow status
|
|
410
|
-
Phase: find
|
|
411
|
-
|
|
412
|
-
# 可视化 4 阶段分析流水线
|
|
413
|
-
$ mycodemap workflow visualize
|
|
414
|
-
▶ 🔍 【Find】
|
|
415
|
-
↓
|
|
416
|
-
○ 📖 Read
|
|
417
|
-
↓
|
|
418
|
-
○ 🔗 Link
|
|
419
|
-
↓
|
|
420
|
-
○ 🧭 Show
|
|
421
|
-
|
|
422
|
-
# 当前阶段完成后推进到下一阶段
|
|
423
|
-
$ mycodemap workflow proceed
|
|
424
|
-
Next phase: read
|
|
425
|
-
|
|
426
|
-
# 示例:对当前活动工作流应用模板(阶段顺序不变)
|
|
427
|
-
$ mycodemap workflow template apply bugfix
|
|
428
|
-
Applied template: bugfix
|
|
429
|
-
Phases: find → read → link → show
|
|
430
|
-
Current phase: find
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
## CI 门禁 (v2.5)
|
|
434
|
-
|
|
435
|
-
CodeMap 提供 CI 阶段自动检查,确保代码质量。
|
|
436
|
-
|
|
437
|
-
```bash
|
|
438
|
-
# 检查 README / docs / CLI 示例是否与仓库事实同步
|
|
439
|
-
npm run docs:check
|
|
440
|
-
|
|
441
|
-
# 通过统一 CLI 护栏入口复用同一检查
|
|
442
|
-
mycodemap ci check-docs-sync
|
|
443
|
-
|
|
444
|
-
# 检查提交格式 ([TAG] scope: message)
|
|
445
|
-
mycodemap ci check-commits
|
|
446
|
-
|
|
447
|
-
# 检查文件头注释 ([META], [WHY])
|
|
448
|
-
mycodemap ci check-headers
|
|
449
|
-
|
|
450
|
-
# 评估变更风险
|
|
451
|
-
mycodemap ci assess-risk -f src/cache/lru-cache.ts
|
|
452
|
-
|
|
453
|
-
# 检查输出契约
|
|
454
|
-
mycodemap ci check-output-contract
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
> `ci assess-risk` 现在输出 `status/confidence/freshness/source` 与统一 risk level;若 Git history 不可用,会显式打印 `unavailable` / warning,并说明阈值未被应用。
|
|
458
|
-
|
|
459
|
-
## Validation quick truth
|
|
460
|
-
|
|
461
|
-
- 文档/入口变更先跑 `npm run docs:check`。
|
|
462
|
-
- 统一 docs/AI guardrail 入口:`node dist/cli/index.js ci check-docs-sync`(产品命令等价于 `mycodemap ci check-docs-sync`)。
|
|
463
|
-
- repo-local rules 预检:`python3 scripts/validate-rules.py code --report-only` 只报告,不阻断。
|
|
464
|
-
- CI / PR 超窗、fallback 或 false-positive 漂移时,`warn-only / fallback` 不是 hard gate success。
|
|
465
|
-
|
|
466
|
-
## 配置说明
|
|
467
|
-
|
|
468
|
-
通过 `mycodemap init` 收敛的 canonical 配置文件是 `.mycodemap/config.json`(根目录 `mycodemap.config.json` / `codemap.config.json` 只作为 legacy migration source)。
|
|
469
|
-
|
|
470
|
-
```jsonc
|
|
471
|
-
{
|
|
472
|
-
// JSON Schema(可选,提供编辑器智能提示)
|
|
473
|
-
"$schema": "https://mycodemap.dev/schema/config.json",
|
|
474
|
-
|
|
475
|
-
// 分析模式:"fast"、"smart" 或 "hybrid"
|
|
476
|
-
"mode": "hybrid",
|
|
477
|
-
|
|
478
|
-
// 包含的文件 glob 模式
|
|
479
|
-
"include": [
|
|
480
|
-
"src/**/*.ts"
|
|
481
|
-
],
|
|
482
|
-
|
|
483
|
-
// 排除的文件 glob 模式
|
|
484
|
-
"exclude": [
|
|
485
|
-
"node_modules/**",
|
|
486
|
-
"dist/**",
|
|
487
|
-
"build/**",
|
|
488
|
-
"coverage/**",
|
|
489
|
-
"**/*.test.ts",
|
|
490
|
-
"**/*.spec.ts",
|
|
491
|
-
"**/*.d.ts"
|
|
492
|
-
],
|
|
493
|
-
|
|
494
|
-
// 输出目录
|
|
495
|
-
"output": ".mycodemap",
|
|
496
|
-
|
|
497
|
-
// 监听模式预留配置
|
|
498
|
-
"watch": false,
|
|
499
|
-
|
|
500
|
-
// 图存储后端配置
|
|
501
|
-
"storage": {
|
|
502
|
-
"type": "filesystem",
|
|
503
|
-
"outputPath": ".mycodemap/storage"
|
|
504
|
-
},
|
|
505
|
-
|
|
506
|
-
// 插件加载配置
|
|
507
|
-
"plugins": {
|
|
508
|
-
"builtInPlugins": true,
|
|
509
|
-
"plugins": [],
|
|
510
|
-
"debug": false
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
```
|
|
514
|
-
|
|
515
|
-
| 配置项 | 类型 | 说明 | 默认值 |
|
|
516
|
-
|--------|------|------|--------|
|
|
517
|
-
| `mode` | `"fast" \| "smart" \| "hybrid"` | 分析模式 | `"hybrid"` |
|
|
518
|
-
| `include` | `string[]` | 包含的文件 glob 模式 | `["src/**/*.ts"]` |
|
|
519
|
-
| `exclude` | `string[]` | 排除的文件 glob 模式 | `["node_modules/**", "dist/**", ...]` |
|
|
520
|
-
| `output` | `string` | 输出目录路径 | `".mycodemap"` |
|
|
521
|
-
| `watch` | `boolean` | 监听模式预留配置 | `false` |
|
|
522
|
-
| `storage.type` | `"filesystem" \| "sqlite" \| "memory" \| "auto"` | 图存储后端类型 | `"filesystem"` |
|
|
523
|
-
| `storage.outputPath` | `string` | 文件系统存储目录 | `".mycodemap/storage"` |
|
|
524
|
-
| `storage.databasePath` | `string` | SQLite 数据目录(相对项目根目录,建议放在 `.mycodemap/` 下) | `".mycodemap/governance.sqlite"` |
|
|
525
|
-
| `storage.autoThresholds` | `object` | `auto` 后端选择阈值 | - |
|
|
526
|
-
| `plugins.builtInPlugins` | `boolean` | 是否启用内置插件 | `true` |
|
|
527
|
-
| `plugins.pluginDir` | `string` | 额外插件目录 | - |
|
|
528
|
-
| `plugins.plugins` | `string[]` | 显式加载的插件名称列表 | `[]` |
|
|
529
|
-
| `plugins.debug` | `boolean` | 是否输出插件调试日志 | `false` |
|
|
530
|
-
|
|
531
|
-
### 图存储后端说明
|
|
532
|
-
|
|
533
|
-
```jsonc
|
|
534
|
-
{
|
|
535
|
-
"storage": {
|
|
536
|
-
"type": "sqlite",
|
|
537
|
-
"databasePath": ".mycodemap/governance.sqlite"
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
- `generate` 会把 CodeGraph 写入配置的 `storage` 后端,`export` 与内部 `Server Layer` handler 会读取同一份后端数据。
|
|
543
|
-
- `neo4j` 与 `kuzudb` 已不再是正式支持的 backend;旧配置会返回显式迁移错误,不会静默 fallback 到 `filesystem`。
|
|
544
|
-
- 显式选择 `sqlite` 且运行时缺少 `better-sqlite3` 或 Node.js `<20` 时,会返回显式错误。
|
|
545
|
-
- `storage.type = "auto"` 当前优先选择 `sqlite`;若运行时缺少 `better-sqlite3` 或 Node.js `<20` 导致 SQLite 不可用,则 warning 后回退到 `filesystem`。
|
|
546
|
-
- 图存储后端生产化不等于重新开放公共 HTTP API 产品面;`Server Layer` 仍是内部架构层。
|
|
547
|
-
|
|
548
|
-
### 插件运行时说明
|
|
549
|
-
|
|
550
|
-
```jsonc
|
|
551
|
-
{
|
|
552
|
-
"plugins": {
|
|
553
|
-
"builtInPlugins": false,
|
|
554
|
-
"pluginDir": "./codemap-plugins",
|
|
555
|
-
"plugins": ["complexity-analyzer", "my-local-plugin"],
|
|
556
|
-
"debug": true
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
- 只有**显式声明了** `plugins` 段时,`generate` 才会启用插件 runtime;没有该段的旧项目保持原有行为。
|
|
562
|
-
- 插件加载结果、诊断信息和插件生成文件会写入 `AI_MAP.md` 的 `Plugin Summary` 与 `codemap.json` 的 `pluginReport`。
|
|
563
|
-
- 非法插件配置、插件初始化失败、generate hook 失败都会被收口为结构化 diagnostics,而不是静默忽略。
|
|
564
|
-
|
|
565
|
-
> 文件发现契约:`generate`、`analyze` 与 `ci check-headers -d` 等扫描类命令共享同一套 `.gitignore` 感知排除规则;若仓库没有 `.gitignore`,则回退到默认 `exclude`(即 `node_modules/dist/build/coverage/**` 与 `**/*.test.ts` / `**/*.spec.ts` / `**/*.d.ts`),并在 Git worktree 场景下避免误扫描 `.git` 目录。
|
|
566
|
-
|
|
567
|
-
## 输出文件说明
|
|
568
|
-
|
|
569
|
-
运行 `mycodemap generate` 后,会在输出目录(默认 `.mycodemap/`)中生成以下文件:
|
|
570
|
-
|
|
571
|
-
### `AI_MAP.md`
|
|
572
|
-
|
|
573
|
-
项目全局概览文件,专为 AI 助手设计,包含:
|
|
574
|
-
- 项目基本信息(文件数、代码行数、模块数等)
|
|
575
|
-
- 已加载插件、插件生成文件数量与插件诊断摘要(仅当显式启用 plugins runtime)
|
|
576
|
-
- 入口点列表
|
|
577
|
-
- 模块组织表(导出数、依赖数、类型)
|
|
578
|
-
- Mermaid 格式的依赖关系图
|
|
579
|
-
- 类型摘要和导出统计
|
|
580
|
-
|
|
581
|
-
### `CONTEXT.md` 与 `context/`
|
|
582
|
-
|
|
583
|
-
`CONTEXT.md` 是上下文入口文件,详细模块内容位于 `context/` 目录,包含:
|
|
584
|
-
- 模块概述(类型、代码行数)
|
|
585
|
-
- 导出列表(名称、类型、是否默认导出)
|
|
586
|
-
- 导入列表(来源、引入的符号)
|
|
587
|
-
- 符号列表(函数、类、接口等)
|
|
588
|
-
- 依赖和被依赖关系
|
|
589
|
-
|
|
590
|
-
### `codemap.json`
|
|
591
|
-
|
|
592
|
-
完整的结构化 JSON 数据,包含所有分析结果,适用于程序化消费。数据结构包括:
|
|
593
|
-
- `project` - 项目基本信息
|
|
594
|
-
- `summary` - 统计摘要
|
|
595
|
-
- `modules` - 模块详情数组(符号、导入、导出、复杂度等)
|
|
596
|
-
- `dependencies` - 依赖图(节点和边)
|
|
597
|
-
- `pluginReport` - 插件运行摘要(`loadedPlugins`、`generatedFiles`、`metrics`、`diagnostics`)
|
|
598
|
-
|
|
599
|
-
### `dependency-graph.md`
|
|
600
|
-
|
|
601
|
-
独立的 Mermaid 依赖关系图文件,可在支持 Mermaid 的 Markdown 渲染器中直接预览。
|
|
602
|
-
|
|
603
|
-
## MVP3 分层架构
|
|
604
|
-
|
|
605
|
-
CodeMap 采用清晰的分层架构设计(MVP3),各层职责明确:
|
|
606
|
-
|
|
607
|
-
```
|
|
608
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
609
|
-
│ CLI Layer │
|
|
610
|
-
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
|
|
611
|
-
│ │workflow/ship│ │ export │ │ 原有命令(generate..)│ │
|
|
612
|
-
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
|
|
613
|
-
├─────────────────────────────────────────────────────────────┤
|
|
614
|
-
│ Server Layer │
|
|
615
|
-
│ HTTP API / QueryHandler / AnalysisHandler │
|
|
616
|
-
├─────────────────────────────────────────────────────────────┤
|
|
617
|
-
│ Domain Layer │
|
|
618
|
-
│ Project / Module / Symbol / Dependency / CodeGraph │
|
|
619
|
-
├─────────────────────────────────────────────────────────────┤
|
|
620
|
-
│ Infrastructure Layer │
|
|
621
|
-
│ ┌──────────────────┐ ┌──────────────────┐ │
|
|
622
|
-
│ │ Storage │ │ Parser │ │
|
|
623
|
-
│ │ - FileSystem │ │ - TypeScript │ │
|
|
624
|
-
│ │ - Memory │ │ - Go │ │
|
|
625
|
-
│ │ - KùzuDB │ │ - Python │ │
|
|
626
|
-
│ │ - Auto Select │ │ - Registry │ │
|
|
627
|
-
│ └──────────────────┘ └──────────────────┘ │
|
|
628
|
-
│ ┌──────────────────┐ │
|
|
629
|
-
│ │ Repository │ CodeGraphRepositoryImpl │
|
|
630
|
-
│ └──────────────────┘ │
|
|
631
|
-
├─────────────────────────────────────────────────────────────┤
|
|
632
|
-
│ Interface Layer │
|
|
633
|
-
│ 类型定义与契约 (Types, ILanguageParser, IStorage) │
|
|
634
|
-
└─────────────────────────────────────────────────────────────┘
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
> 命名边界:`Server Layer` 是内部架构层,不等于公共 `mycodemap server` 命令。
|
|
638
|
-
|
|
639
|
-
### 架构层说明
|
|
640
|
-
|
|
641
|
-
| 层级 | 路径 | 职责 | 关键组件 |
|
|
642
|
-
|------|------|------|----------|
|
|
643
|
-
| **CLI** | `src/cli/` | 命令行接口(核心分析命令 + `workflow` / `ship` 扩展 surface) | `generate`, `query`, `impact`, `export` |
|
|
644
|
-
| **Server** | `src/server/` | 内部 Server Layer / HTTP transport | `CodeMapServer`, `QueryHandler` |
|
|
645
|
-
| **Domain** | `src/domain/` | 核心业务逻辑 | `Project`, `Module`, `CodeGraph` |
|
|
646
|
-
| **Infrastructure** | `src/infrastructure/` | 技术实现 | `Storage`, `Parser`, `Repository` |
|
|
647
|
-
| **Interface** | `src/interface/` | 类型契约 | `types/`, `config/` |
|
|
648
|
-
|
|
649
|
-
### 项目目录结构
|
|
650
|
-
|
|
651
|
-
```
|
|
652
|
-
src/
|
|
653
|
-
├── cli/ # CLI 命令入口 (原有 + MVP3 新增)
|
|
654
|
-
│ ├── commands/
|
|
655
|
-
│ │ ├── server.ts # MVP3: HTTP API 服务器
|
|
656
|
-
│ │ ├── export.ts # MVP3: 导出命令
|
|
657
|
-
│ │ ├── generate.ts # 生成代码地图
|
|
658
|
-
│ │ ├── query.ts # 查询命令
|
|
659
|
-
│ │ └── ... # 其他命令
|
|
660
|
-
│ └── index.ts
|
|
661
|
-
├── server/ # MVP3: HTTP API 服务器层
|
|
662
|
-
│ ├── CodeMapServer.ts # 主服务器类
|
|
663
|
-
│ ├── handlers/ # QueryHandler, AnalysisHandler
|
|
664
|
-
│ └── routes/ # API 路由
|
|
665
|
-
├── domain/ # MVP3: 领域层
|
|
666
|
-
│ ├── entities/ # Project, Module, Symbol, Dependency
|
|
667
|
-
│ ├── services/ # CodeGraphBuilder
|
|
668
|
-
│ ├── events/ # DomainEvent
|
|
669
|
-
│ └── repositories/ # 仓库接口
|
|
670
|
-
├── infrastructure/ # MVP3: 基础设施层
|
|
671
|
-
│ ├── storage/ # 存储适配器
|
|
672
|
-
│ │ ├── adapters/ # FileSystem, Memory, KùzuDB
|
|
673
|
-
│ │ └── StorageFactory.ts
|
|
674
|
-
│ ├── parser/ # 解析器
|
|
675
|
-
│ │ ├── interfaces/ # ParserBase
|
|
676
|
-
│ │ ├── implementations/# TypeScript, Go, Python
|
|
677
|
-
│ │ └── registry/ # ParserRegistry
|
|
678
|
-
│ └── repositories/ # 仓库实现
|
|
679
|
-
├── interface/ # MVP3: 接口层
|
|
680
|
-
│ ├── types/ # 核心类型定义
|
|
681
|
-
│ └── config/ # 配置类型
|
|
682
|
-
├── core/ # 核心分析引擎 (原有)
|
|
683
|
-
├── parser/ # 原有解析器 (逐步迁移到 infrastructure/parser)
|
|
684
|
-
├── orchestrator/ # 编排层 (v2.5)
|
|
685
|
-
└── ...
|
|
686
|
-
```
|
|
687
|
-
|
|
688
|
-
## AI 助手集成
|
|
689
|
-
|
|
690
|
-
MyCodeMap 可与多种 AI 编程助手深度集成,提供智能代码分析能力:
|
|
691
|
-
|
|
692
|
-
| AI 助手 | 配置方式 | 支持功能 |
|
|
693
|
-
|---------|----------|----------|
|
|
694
|
-
| **Kimi CLI** | Skill 配置 | 完整命令支持 |
|
|
695
|
-
| **Claude Code** | Skill 配置 | 完整命令支持 |
|
|
696
|
-
| **Codex CLI** | Agent 配置 | 完整命令支持 |
|
|
697
|
-
| **GitHub Copilot** | 提示词配置 | 基础查询支持 |
|
|
698
|
-
|
|
699
|
-
### 快速配置
|
|
700
|
-
|
|
701
|
-
```bash
|
|
702
|
-
# Kimi CLI
|
|
703
|
-
mkdir -p .kimi/skills/codemap
|
|
704
|
-
cp examples/kimi/codemap-skill.md .kimi/skills/codemap/SKILL.md
|
|
705
|
-
|
|
706
|
-
# Claude Code
|
|
707
|
-
mkdir -p .claude/skills/codemap
|
|
708
|
-
cp examples/claude/codemap-skill.md .claude/skills/codemap/SKILL.md
|
|
709
|
-
|
|
710
|
-
# Codex CLI
|
|
711
|
-
mkdir -p .agents/skills/codemap
|
|
712
|
-
cp examples/codex/codemap-agent.md .agents/skills/codemap/SKILL.md
|
|
713
|
-
```
|
|
714
|
-
|
|
715
|
-
详细配置请参考 [AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md),设计与规则入口请先看 [docs/README.md](docs/README.md)。
|
|
716
|
-
|
|
717
|
-
### CodeMap Skill 使用指南
|
|
718
|
-
|
|
719
|
-
CodeMap Skill 是一个预置的 AI 技能文件,让 Claude Code 等支持 Skill 机制的 AI 助手自动获得 CodeMap 的全部分析能力。当用户提到"分析代码结构"、"查找依赖"、"影响范围"、"代码地图"等意图时,AI 会自动加载该技能并调用 CodeMap CLI。
|
|
720
|
-
|
|
721
|
-
#### 工作原理
|
|
722
|
-
|
|
723
|
-
```
|
|
724
|
-
用户提问 → AI 识别意图 → 加载 CodeMap Skill → 调用 CLI 命令 → 返回结构化结果
|
|
725
|
-
```
|
|
726
|
-
|
|
727
|
-
Skill 文件由两部分组成:
|
|
728
|
-
|
|
729
|
-
| 文件 | 作用 |
|
|
730
|
-
|------|------|
|
|
731
|
-
| `.claude/skills/codemap/SKILL.md` | 主技能文件:触发条件、场景-命令映射、任务示例、错误处理 |
|
|
732
|
-
| `.claude/skills/codemap/references/commands.md` | 完整命令参考:所有命令的选项、参数和用法 |
|
|
733
|
-
|
|
734
|
-
#### 安装
|
|
735
|
-
|
|
736
|
-
Skill 文件已内置在本仓库中,无需额外安装。对于其他项目,复制即可:
|
|
737
|
-
|
|
738
|
-
```bash
|
|
739
|
-
# 复制到目标项目的 .claude/skills/ 目录
|
|
740
|
-
cp -r .claude/skills/codemap /path/to/target-project/.claude/skills/
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
#### 典型使用场景
|
|
744
|
-
|
|
745
|
-
在 Claude Code 对话中直接用自然语言触发,无需手动输入命令:
|
|
746
|
-
|
|
747
|
-
| 用户意图 | AI 自动执行的命令 |
|
|
748
|
-
|----------|-------------------|
|
|
749
|
-
| "这个项目有哪些模块?" | `mycodemap query -m "src/..."` 或查看 `AI_MAP.md` |
|
|
750
|
-
| "IntentRouter 在哪里定义的?" | `mycodemap query -s "IntentRouter"` |
|
|
751
|
-
| "修改这个文件会影响什么?" | `mycodemap impact -f <path> --transitive` |
|
|
752
|
-
| "项目有循环依赖吗?" | `mycodemap cycles` |
|
|
753
|
-
| "这个模块的复杂度如何?" | `mycodemap complexity -f <path> --detail` |
|
|
754
|
-
| "帮我检查提交格式" | `mycodemap ci check-commits` |
|
|
755
|
-
| "验证设计契约" | `mycodemap design validate` |
|
|
756
|
-
|
|
757
|
-
#### CLI 调用方式
|
|
758
|
-
|
|
759
|
-
标准用户通过全局安装的 `mycodemap` 调用;CodeMap 本体仓库的开发者使用 `node dist/cli/index.js`:
|
|
760
|
-
|
|
761
|
-
```bash
|
|
762
|
-
# 用户模式(全局安装后)
|
|
763
|
-
mycodemap query -s "SymbolName"
|
|
764
|
-
mycodemap impact -f src/file.ts
|
|
765
|
-
|
|
766
|
-
# 开发者模式(CodeMap 本体仓库内,需先 npm run build)
|
|
767
|
-
node dist/cli/index.js query -s "SymbolName"
|
|
768
|
-
```
|
|
769
|
-
|
|
770
|
-
#### 自定义与扩展
|
|
771
|
-
|
|
772
|
-
- **修改触发条件**:编辑 `SKILL.md` 头部的 `description` 字段,调整 AI 何时自动加载此技能
|
|
773
|
-
- **添加新命令**:在 `references/commands.md` 中补充新命令文档
|
|
774
|
-
- **添加新场景**:在 `SKILL.md` 的 "任务场景" 部分追加新的使用模式
|
|
775
|
-
|
|
776
|
-
详细配置请参考 [AI_ASSISTANT_SETUP.md](docs/AI_ASSISTANT_SETUP.md),设计与规则入口请先看 [docs/README.md](docs/README.md)。
|
|
777
|
-
|
|
778
|
-
## 新增 CLI 命令
|
|
779
|
-
|
|
780
|
-
### `mycodemap design`
|
|
781
|
-
|
|
782
|
-
校验、映射并验证 human-authored design contract,默认读取仓库根目录的 `mycodemap.design.md`。
|
|
783
|
-
|
|
784
|
-
```bash
|
|
785
|
-
# validate: 使用默认路径校验
|
|
786
|
-
mycodemap design validate mycodemap.design.md --json
|
|
787
|
-
|
|
788
|
-
# validate: 显式指定文件
|
|
789
|
-
mycodemap design validate docs/designs/login.design.md
|
|
790
|
-
|
|
791
|
-
# map: 生成 candidate code scope
|
|
792
|
-
mycodemap design map mycodemap.design.md --json
|
|
793
|
-
|
|
794
|
-
# handoff: 生成 reviewer + agent 共用的 handoff package
|
|
795
|
-
mycodemap design handoff mycodemap.design.md --json
|
|
796
|
-
|
|
797
|
-
# verify: 基于 reviewed handoff truth 做 checklist / drift 校验
|
|
798
|
-
mycodemap design verify mycodemap.design.md --json
|
|
799
|
-
```
|
|
800
|
-
|
|
801
|
-
| 选项 | 说明 |
|
|
802
|
-
|------|------|
|
|
803
|
-
| `-j, --json` | 输出纯 JSON diagnostics,适合 AI/CI 消费 |
|
|
804
|
-
|
|
805
|
-
> canonical 模板位于 `docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md`。
|
|
806
|
-
> 缺失必填 section、重复 section、空 section 或未知 heading 时,CLI 会返回结构化 diagnostics,而不是继续猜测设计意图。
|
|
807
|
-
> `design map` 会基于 design contract 返回 `candidates`、`diagnostics` 与 `unknowns`;若命中 `no-candidates`、`over-broad-scope` 或 `high-risk-scope`,命令会直接阻断。
|
|
808
|
-
> `design handoff` 会基于 validated design contract + mapping truth 返回 `readyForExecution`、`approvals`、`assumptions`、`openQuestions`;human mode 默认写出 `.mycodemap/handoffs/{stem}.handoff.md|json`。
|
|
809
|
-
> `design verify` 会把 `Acceptance Criteria` 固定映射为 `checklist`,并输出 `drift` / `diagnostics`;当结果只是 `needs-review` 时保持零退出码,只有 `ok=false` 或 blocker diagnostics 才返回非零 exit code。
|
|
810
|
-
|
|
811
|
-
### `mycodemap check`
|
|
812
|
-
|
|
813
|
-
执行 design contract contract gate,默认输出机器可读 JSON。
|
|
814
|
-
|
|
815
|
-
```bash
|
|
816
|
-
# 默认 full scan
|
|
817
|
-
mycodemap check --contract mycodemap.design.md --against src
|
|
818
|
-
|
|
819
|
-
# GitHub PR annotations
|
|
820
|
-
mycodemap check --contract mycodemap.design.md --against src --base origin/main --annotation-format github
|
|
821
|
-
|
|
822
|
-
# GitLab code quality artifact
|
|
823
|
-
mycodemap check --contract mycodemap.design.md --against src --base origin/main --annotation-format gitlab --annotation-file gl-code-quality-report.json
|
|
824
|
-
|
|
825
|
-
# 校准当前仓库是否允许默认 hard gate
|
|
826
|
-
node scripts/calibrate-contract-gate.mjs --max-changed-files 10 --max-false-positive-rate 0.10
|
|
827
|
-
```
|
|
828
|
-
|
|
829
|
-
> PR 默认 hard gate 只在 calibration 通过且 `changed files <= 10` 时开启;超窗、`diff-scope-fallback` 或 `false-positive rate >10%` 时必须显式切回 `warn-only / fallback`。
|
|
830
|
-
|
|
831
|
-
### `mycodemap history`
|
|
832
|
-
|
|
833
|
-
符号级 Git history / risk 查询:
|
|
834
|
-
|
|
835
|
-
```bash
|
|
836
|
-
# 默认输出 machine-first JSON
|
|
837
|
-
mycodemap history --symbol createCheckCommand
|
|
838
|
-
|
|
839
|
-
# 查询某个符号的历史轨迹与风险摘要
|
|
840
|
-
mycodemap history --symbol createCheckCommand
|
|
841
|
-
|
|
842
|
-
# 人类可读摘要
|
|
843
|
-
mycodemap history --symbol createCheckCommand --human
|
|
141
|
+
mycodemap query -s "ModuleInfo" # Exact symbol query
|
|
142
|
+
mycodemap query -m "src/parser" # Module info
|
|
143
|
+
mycodemap query -S "cache" # Fuzzy search
|
|
144
|
+
mycodemap query -S "parse" -j # JSON output
|
|
844
145
|
```
|
|
845
146
|
|
|
846
147
|
### `mycodemap analyze`
|
|
847
148
|
|
|
848
|
-
|
|
149
|
+
Unified analysis entry with four intents: `find`, `read`, `link`, `show`.
|
|
849
150
|
|
|
850
|
-
> 当前 public analyze contract 为 `find` / `read` / `link` / `show`;兼容期内 legacy intent 会在输出中通过 `warnings[]` 提示迁移,其中 `refactor` 已不再接受。
|
|
851
|
-
|
|
852
|
-
<!-- BEGIN GENERATED: analyze-readme-examples -->
|
|
853
151
|
```bash
|
|
854
|
-
# 查找符号 / 文本
|
|
855
152
|
mycodemap analyze -i find -k SourceLocation
|
|
856
|
-
mycodemap analyze -i find -t src/orchestrator -k IntentRouter --json
|
|
857
|
-
|
|
858
|
-
# 阅读文件(影响 + 复杂度聚合)
|
|
859
|
-
mycodemap analyze -i read -t src/cli/index.ts
|
|
860
153
|
mycodemap analyze -i read -t src/cli/index.ts --scope transitive
|
|
861
|
-
mycodemap analyze -i read -t src/cli/index.ts --include-tests --json
|
|
862
|
-
|
|
863
|
-
# 关联关系(依赖 + 引用聚合)
|
|
864
154
|
mycodemap analyze -i link -t src/cli/index.ts
|
|
865
|
-
mycodemap analyze -i link -t src/interface/types.ts --json
|
|
866
|
-
|
|
867
|
-
# 展示模块概览 / 文档
|
|
868
155
|
mycodemap analyze -i show -t src/orchestrator
|
|
869
|
-
mycodemap analyze -i show -t src/domain/services --output-mode human
|
|
870
|
-
|
|
871
|
-
# 机器可读输出(JSON / structured)
|
|
872
|
-
mycodemap analyze -i read -t src/index.ts --json
|
|
873
|
-
mycodemap analyze -i link -t src/index.ts --structured --json
|
|
874
156
|
```
|
|
875
|
-
<!-- END GENERATED: analyze-readme-examples -->
|
|
876
|
-
|
|
877
|
-
<!-- BEGIN GENERATED: analyze-readme-options -->
|
|
878
|
-
| 选项 | 说明 | 默认值 |
|
|
879
|
-
|------|------|--------|
|
|
880
|
-
| `-i, --intent <type>` | 分析类型:`find`/`read`/`link`/`show`(必填) | - |
|
|
881
|
-
| `-t, --targets <paths...>` | 目标路径(`read`/`link`/`show` 必填,`find` 可选) | - |
|
|
882
|
-
| `-k, --keywords <words...>` | 搜索关键词(主要用于 `find`) | - |
|
|
883
|
-
| `-s, --scope <scope>` | 范围:`direct`(直接)/`transitive`(传递) | `direct` |
|
|
884
|
-
| `-n, --topK <number>` | 返回结果数量 | `8` |
|
|
885
|
-
| `--include-tests` | 包含测试文件关联 | - |
|
|
886
|
-
| `--include-git-history` | 包含 Git 历史分析 | - |
|
|
887
|
-
| `--json` | JSON 格式输出 | - |
|
|
888
|
-
| `--structured` | 纯结构化输出(移除自然语言字段,配合 `--json` 使用) | - |
|
|
889
|
-
| `--output-mode <mode>` | 输出模式:`machine`/`human` | `human` |
|
|
890
|
-
<!-- END GENERATED: analyze-readme-options -->
|
|
891
157
|
|
|
892
|
-
|
|
893
|
-
>
|
|
894
|
-
> legacy 兼容映射:`search → find`、`impact/complexity → read`、`dependency/reference → link`、`overview/documentation → show`;`refactor` 会返回 `E0001_INVALID_INTENT`。
|
|
895
|
-
>
|
|
896
|
-
> `--include-git-history` 现在只会在 `read` intent 上附加统一的 Git history enrichment;其他 intent 会显式给出 warning,而不是 silent noop。
|
|
158
|
+
### `mycodemap --schema`
|
|
897
159
|
|
|
898
|
-
|
|
899
|
-
## 贡献指南
|
|
900
|
-
|
|
901
|
-
欢迎提交 Issue 和 Pull Request!
|
|
902
|
-
|
|
903
|
-
### 开发环境搭建
|
|
160
|
+
Output the full Interface Contract Schema JSON for agent introspection.
|
|
904
161
|
|
|
905
162
|
```bash
|
|
906
|
-
#
|
|
907
|
-
|
|
908
|
-
cd codemap
|
|
909
|
-
|
|
910
|
-
# 安装依赖
|
|
911
|
-
npm install
|
|
912
|
-
|
|
913
|
-
# 编译
|
|
914
|
-
npm run build
|
|
915
|
-
|
|
916
|
-
# 开发模式(监听编译)
|
|
917
|
-
npm run dev
|
|
918
|
-
|
|
919
|
-
# 运行测试
|
|
920
|
-
npm test # 功能测试(src/**/*.test.ts)
|
|
921
|
-
npm run benchmark # 性能基准测试(refer/benchmark-quality.test.ts)
|
|
922
|
-
npm run test:all # 功能 + 基准(串联执行)
|
|
923
|
-
|
|
924
|
-
# 文档 / CLI 示例护栏
|
|
925
|
-
npm run docs:check
|
|
926
|
-
# `ci check-docs-sync` 会额外校验 analyze generated block
|
|
927
|
-
node dist/cli/index.js ci check-docs-sync
|
|
928
|
-
|
|
929
|
-
# 类型检查
|
|
930
|
-
npm run typecheck
|
|
931
|
-
|
|
932
|
-
# 代码检查
|
|
933
|
-
npm run lint
|
|
163
|
+
mycodemap --schema # Full contract output
|
|
164
|
+
mycodemap --schema | jq '.' # Pretty-print with jq
|
|
934
165
|
```
|
|
935
166
|
|
|
936
|
-
###
|
|
167
|
+
### `mycodemap doctor`
|
|
937
168
|
|
|
938
|
-
|
|
169
|
+
Continuous health diagnostics for the CodeMap ecosystem.
|
|
939
170
|
|
|
940
|
-
```
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
BUGFIX Bug 修复
|
|
944
|
-
FEATURE 新功能
|
|
945
|
-
REFACTOR 代码重构
|
|
946
|
-
CONFIG 配置/构建变更
|
|
947
|
-
DOCS 文档变更
|
|
948
|
-
DELETE 删除代码/文件
|
|
171
|
+
```bash
|
|
172
|
+
mycodemap doctor # Human-readable report
|
|
173
|
+
mycodemap doctor --json # Machine-readable JSON
|
|
949
174
|
```
|
|
950
175
|
|
|
951
|
-
|
|
176
|
+
| Category | Checks |
|
|
177
|
+
|----------|--------|
|
|
178
|
+
| **install** | Native deps (`tree-sitter`, `better-sqlite3`) load status |
|
|
179
|
+
| **config** | `.mycodemap/` workspace configuration integrity |
|
|
180
|
+
| **runtime** | Ghost commands, command stubs, package.json consistency |
|
|
181
|
+
| **agent** | MCP connectivity, schema validity, tool registration |
|
|
952
182
|
|
|
953
|
-
###
|
|
183
|
+
### `mycodemap benchmark`
|
|
954
184
|
|
|
955
|
-
|
|
185
|
+
Compare WASM vs Native performance.
|
|
956
186
|
|
|
957
|
-
```
|
|
958
|
-
|
|
959
|
-
|
|
187
|
+
```bash
|
|
188
|
+
mycodemap benchmark # Default benchmark
|
|
189
|
+
mycodemap benchmark --wasm # Force WASM mode
|
|
190
|
+
mycodemap benchmark --native # Force Native mode
|
|
960
191
|
```
|
|
961
192
|
|
|
962
|
-
-
|
|
963
|
-
- `[WHY]`:解释文件存在的业务理由,帮助 AI 理解上下文
|
|
964
|
-
|
|
965
|
-
### 开发注意事项
|
|
966
|
-
|
|
967
|
-
- 项目使用 ESM 模块格式(`"type": "module"`)
|
|
968
|
-
- TypeScript 严格模式
|
|
969
|
-
- 使用 Vitest 作为测试框架
|
|
970
|
-
- **提交前会自动运行与变更相关的测试,失败将阻断提交**
|
|
971
|
-
- **提交前会检查文件头注释规范([META]/[WHY])**
|
|
972
|
-
- 新增功能请同步补充测试和文档
|
|
193
|
+
### MCP Integration (CLI-as-MCP Gateway)
|
|
973
194
|
|
|
974
|
-
|
|
195
|
+
v2.0 MCP integration has upgraded from an experimental 2-tool slice to the **CLI-as-MCP Automatic Gateway**: all schema-defined CLI commands are automatically exposed as MCP tools.
|
|
975
196
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
- `CODEMAP_RUNTIME_LOG_DIR=<dir>`:自定义日志目录
|
|
981
|
-
- `CODEMAP_RUNTIME_LOG_RETENTION_DAYS=<days>`:设置保留天数
|
|
982
|
-
- `CODEMAP_RUNTIME_LOG_MAX_FILES=<n>`:设置最大保留文件数
|
|
983
|
-
- `CODEMAP_RUNTIME_LOG_MAX_SIZE_MB=<mb>`:单个日志文件大小上限(超限后自动轮转并 gzip)
|
|
197
|
+
```bash
|
|
198
|
+
mycodemap mcp install # Write local server config to `.mcp.json`
|
|
199
|
+
mycodemap mcp start # Start local stdio MCP server
|
|
200
|
+
```
|
|
984
201
|
|
|
985
|
-
|
|
202
|
+
- All 20+ schema-defined CLI commands are callable via MCP
|
|
203
|
+
- Dynamic tool registration: add command to schema → restart MCP server → new tool appears automatically
|
|
204
|
+
- See `docs/ai-guide/INTEGRATION.md` for details
|
|
986
205
|
|
|
987
|
-
|
|
988
|
-
### `mycodemap ci`
|
|
206
|
+
---
|
|
989
207
|
|
|
990
|
-
|
|
208
|
+
## Documentation
|
|
991
209
|
|
|
992
|
-
|
|
993
|
-
# 验证工作区是否干净(ship 的发布前检查也复用这条规则)
|
|
994
|
-
mycodemap ci check-working-tree
|
|
210
|
+
### For Human Users
|
|
995
211
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
212
|
+
| Document | Audience | Content |
|
|
213
|
+
|----------|----------|---------|
|
|
214
|
+
| [🧭 Docs Index](docs/README.md) | All readers | Document layers, reading order, migration status |
|
|
215
|
+
| [🏗️ Architecture](ARCHITECTURE.md) | Developers | System map, module boundaries, main execution flows |
|
|
216
|
+
| [📖 Setup Guide](docs/SETUP_GUIDE.md) | Human developers | Full installation, configuration, and usage guide |
|
|
217
|
+
| [📁 Examples](examples/) | All users | Ready-to-use configuration files |
|
|
999
218
|
|
|
1000
|
-
|
|
1001
|
-
mycodemap ci check-scripts
|
|
219
|
+
### 🤖 AI / Agent Docs
|
|
1002
220
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
221
|
+
| Document | Description |
|
|
222
|
+
|----------|-------------|
|
|
223
|
+
| **[📘 AI_GUIDE.md](AI_GUIDE.md)** | **AI main guide** — quick reference, command decision tree, prompt templates |
|
|
224
|
+
| **[🚀 Quick Start](docs/ai-guide/QUICKSTART.md)** | Scenario-to-command mapping |
|
|
225
|
+
| **[📚 Commands](docs/ai-guide/COMMANDS.md)** | Full CLI command reference |
|
|
226
|
+
| **[📊 Output Schema](docs/ai-guide/OUTPUT.md)** | JSON output structure parsing |
|
|
227
|
+
| **[🔧 Integration](docs/ai-guide/INTEGRATION.md)** | MCP/Agent integration, error handling |
|
|
228
|
+
| **[🛡️ AGENTS.md](AGENTS.md)** | Repository-level constraints |
|
|
229
|
+
| **[⚡ CLAUDE.md](CLAUDE.md)** | AI entry routing |
|
|
1007
230
|
|
|
1008
|
-
|
|
1009
|
-
mycodemap ci check-headers
|
|
1010
|
-
mycodemap ci check-headers -d src/domain
|
|
1011
|
-
mycodemap ci check-headers -f "src/index.ts,src/cli/index.ts"
|
|
231
|
+
---
|
|
1012
232
|
|
|
1013
|
-
|
|
1014
|
-
mycodemap ci assess-risk
|
|
1015
|
-
mycodemap ci assess-risk -t 0.5
|
|
233
|
+
## Contributing
|
|
1016
234
|
|
|
1017
|
-
|
|
1018
|
-
mycodemap ci check-docs-sync
|
|
235
|
+
See [README.zh-CN.md](./README.zh-CN.md) for full development setup, commit conventions, and coding standards (中文版本包含完整的开发环境搭建、提交规范和代码规范).
|
|
1019
236
|
|
|
1020
|
-
|
|
1021
|
-
mycodemap ci check-output-contract
|
|
237
|
+
---
|
|
1022
238
|
|
|
1023
|
-
|
|
1024
|
-
mycodemap ci check-commit-size
|
|
1025
|
-
mycodemap ci check-commit-size -m 15
|
|
1026
|
-
```
|
|
1027
|
-
|
|
1028
|
-
> `mycodemap ship` 的 CHECK 阶段现在复用 `ci check-working-tree`、`ci check-branch`、`ci check-scripts` 作为 must-pass 事实源,而不是重复实现这些检查。
|
|
1029
|
-
> `mycodemap ci check-headers -d <dir>` 与 `generate` / `analyze` 共享同一套 `.gitignore` 感知排除模块;若仓库没有 `.gitignore`,则回退到默认 `exclude` 列表。
|
|
239
|
+
## License
|
|
1030
240
|
|
|
1031
|
-
|
|
241
|
+
[MIT](LICENSE)
|