@mars167/git-ai 2.3.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.
Files changed (122) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +364 -0
  3. package/README.zh-CN.md +361 -0
  4. package/assets/hooks/post-checkout +28 -0
  5. package/assets/hooks/post-merge +28 -0
  6. package/assets/hooks/pre-commit +17 -0
  7. package/assets/hooks/pre-push +29 -0
  8. package/dist/bin/git-ai.js +62 -0
  9. package/dist/src/commands/ai.js +30 -0
  10. package/dist/src/commands/checkIndex.js +19 -0
  11. package/dist/src/commands/dsr.js +156 -0
  12. package/dist/src/commands/graph.js +203 -0
  13. package/dist/src/commands/hooks.js +125 -0
  14. package/dist/src/commands/index.js +92 -0
  15. package/dist/src/commands/pack.js +31 -0
  16. package/dist/src/commands/query.js +139 -0
  17. package/dist/src/commands/semantic.js +134 -0
  18. package/dist/src/commands/serve.js +14 -0
  19. package/dist/src/commands/status.js +78 -0
  20. package/dist/src/commands/trae.js +75 -0
  21. package/dist/src/commands/unpack.js +28 -0
  22. package/dist/src/core/archive.js +91 -0
  23. package/dist/src/core/astGraph.js +127 -0
  24. package/dist/src/core/astGraphQuery.js +142 -0
  25. package/dist/src/core/cozo.js +266 -0
  26. package/dist/src/core/cpg/astLayer.js +56 -0
  27. package/dist/src/core/cpg/callGraph.js +483 -0
  28. package/dist/src/core/cpg/cfgLayer.js +490 -0
  29. package/dist/src/core/cpg/dfgLayer.js +237 -0
  30. package/dist/src/core/cpg/index.js +80 -0
  31. package/dist/src/core/cpg/types.js +108 -0
  32. package/dist/src/core/crypto.js +10 -0
  33. package/dist/src/core/dsr/generate.js +308 -0
  34. package/dist/src/core/dsr/gitContext.js +74 -0
  35. package/dist/src/core/dsr/indexMaterialize.js +106 -0
  36. package/dist/src/core/dsr/paths.js +26 -0
  37. package/dist/src/core/dsr/query.js +73 -0
  38. package/dist/src/core/dsr/snapshotParser.js +73 -0
  39. package/dist/src/core/dsr/state.js +27 -0
  40. package/dist/src/core/dsr/types.js +2 -0
  41. package/dist/src/core/embedding/fusion.js +52 -0
  42. package/dist/src/core/embedding/index.js +43 -0
  43. package/dist/src/core/embedding/parser.js +14 -0
  44. package/dist/src/core/embedding/semantic.js +254 -0
  45. package/dist/src/core/embedding/structural.js +97 -0
  46. package/dist/src/core/embedding/symbolic.js +117 -0
  47. package/dist/src/core/embedding/tokenizer.js +91 -0
  48. package/dist/src/core/embedding/types.js +2 -0
  49. package/dist/src/core/embedding.js +36 -0
  50. package/dist/src/core/git.js +49 -0
  51. package/dist/src/core/gitDiff.js +73 -0
  52. package/dist/src/core/indexCheck.js +131 -0
  53. package/dist/src/core/indexer.js +185 -0
  54. package/dist/src/core/indexerIncremental.js +303 -0
  55. package/dist/src/core/indexing/config.js +51 -0
  56. package/dist/src/core/indexing/hnsw.js +568 -0
  57. package/dist/src/core/indexing/index.js +17 -0
  58. package/dist/src/core/indexing/monitor.js +82 -0
  59. package/dist/src/core/indexing/parallel.js +252 -0
  60. package/dist/src/core/lancedb.js +111 -0
  61. package/dist/src/core/lfs.js +27 -0
  62. package/dist/src/core/log.js +62 -0
  63. package/dist/src/core/manifest.js +88 -0
  64. package/dist/src/core/parser/adapter.js +2 -0
  65. package/dist/src/core/parser/c.js +93 -0
  66. package/dist/src/core/parser/chunkRelations.js +178 -0
  67. package/dist/src/core/parser/chunker.js +274 -0
  68. package/dist/src/core/parser/go.js +98 -0
  69. package/dist/src/core/parser/java.js +80 -0
  70. package/dist/src/core/parser/markdown.js +76 -0
  71. package/dist/src/core/parser/python.js +81 -0
  72. package/dist/src/core/parser/rust.js +103 -0
  73. package/dist/src/core/parser/typescript.js +98 -0
  74. package/dist/src/core/parser/utils.js +62 -0
  75. package/dist/src/core/parser/yaml.js +53 -0
  76. package/dist/src/core/parser.js +75 -0
  77. package/dist/src/core/paths.js +10 -0
  78. package/dist/src/core/repoMap.js +164 -0
  79. package/dist/src/core/retrieval/cache.js +31 -0
  80. package/dist/src/core/retrieval/classifier.js +74 -0
  81. package/dist/src/core/retrieval/expander.js +80 -0
  82. package/dist/src/core/retrieval/fuser.js +40 -0
  83. package/dist/src/core/retrieval/index.js +32 -0
  84. package/dist/src/core/retrieval/reranker.js +304 -0
  85. package/dist/src/core/retrieval/types.js +2 -0
  86. package/dist/src/core/retrieval/weights.js +42 -0
  87. package/dist/src/core/search.js +41 -0
  88. package/dist/src/core/sq8.js +65 -0
  89. package/dist/src/core/symbolSearch.js +143 -0
  90. package/dist/src/core/types.js +2 -0
  91. package/dist/src/core/workspace.js +116 -0
  92. package/dist/src/mcp/server.js +794 -0
  93. package/docs/README.md +44 -0
  94. package/docs/cross-encoder.md +157 -0
  95. package/docs/embedding.md +158 -0
  96. package/docs/logo.png +0 -0
  97. package/docs/windows-setup.md +67 -0
  98. package/docs/zh-CN/DESIGN.md +102 -0
  99. package/docs/zh-CN/README.md +46 -0
  100. package/docs/zh-CN/advanced.md +26 -0
  101. package/docs/zh-CN/architecture_explained.md +116 -0
  102. package/docs/zh-CN/cli.md +109 -0
  103. package/docs/zh-CN/dsr.md +91 -0
  104. package/docs/zh-CN/graph_scenarios.md +173 -0
  105. package/docs/zh-CN/hooks.md +14 -0
  106. package/docs/zh-CN/manifests.md +136 -0
  107. package/docs/zh-CN/mcp.md +205 -0
  108. package/docs/zh-CN/quickstart.md +35 -0
  109. package/docs/zh-CN/rules.md +7 -0
  110. package/docs/zh-CN/technical-details.md +454 -0
  111. package/docs/zh-CN/troubleshooting.md +19 -0
  112. package/docs/zh-CN/windows-setup.md +67 -0
  113. package/install.sh +183 -0
  114. package/package.json +97 -0
  115. package/skills/git-ai-mcp/SKILL.md +86 -0
  116. package/skills/git-ai-mcp/references/constraints.md +143 -0
  117. package/skills/git-ai-mcp/references/tools.md +263 -0
  118. package/templates/agents/common/documents/Fix EISDIR error and enable multi-language indexing.md +14 -0
  119. package/templates/agents/common/documents/Fix git-ai index error in CodaGraph directory.md +13 -0
  120. package/templates/agents/common/skills/git-ai-mcp/SKILL.md +86 -0
  121. package/templates/agents/common/skills/git-ai-mcp/references/constraints.md +143 -0
  122. package/templates/agents/common/skills/git-ai-mcp/references/tools.md +263 -0
@@ -0,0 +1,19 @@
1
+ # 排障
2
+
3
+ ## MCP 启动后无响应
4
+ stdio server 正常行为是“等待客户端连接”。如果你在终端直接运行,看起来像卡住是正常的。
5
+
6
+ ## search_symbols/semantic_search 查不到结果
7
+ - 先在仓库执行:`git-ai ai index --overwrite`(或仅更新变更:`git-ai ai index --incremental --staged`)
8
+ - 如果你是通过 MCP 客户端启动且 cwd 不在仓库目录:
9
+ - MCP tools 的 `path` 为必传:每次 MCP tool 调用都显式传 `path: "/ABS/PATH/TO/REPO"`(保证调用原子性)
10
+
11
+ ## Windows / Linux 安装失败
12
+ - Node 版本需 >= 18,且架构为 x64/arm64(LanceDB N-API 预编译包支持的范围)
13
+ - 若报 `node-gyp` / 编译错误,通常来自 `tree-sitter` 系列原生扩展:
14
+ - Windows:安装 Visual Studio Build Tools(C++)与 Python
15
+ - Linux:安装 build-essential 与 python3
16
+
17
+ ## hooks 没生效
18
+ - 运行 `git-ai ai hooks status` 确认 `core.hooksPath` 是 `.githooks`
19
+ - 确认 `.githooks/*` 在 macOS/Linux 上有可执行权限
@@ -0,0 +1,67 @@
1
+ # Windows 开发与安装指引
2
+
3
+ **简体中文** | [English](../windows-setup.md)
4
+
5
+ 本指引介绍如何在 Windows 上设置 `git-ai` 的开发环境,特别是针对多语言支持(C、Go、Python、Rust)。
6
+
7
+ ## 前置条件
8
+
9
+ 1. **Node.js**: 从 [nodejs.org](https://nodejs.org/) 安装 Node.js (推荐 LTS 版本)。
10
+ 2. **Git**: 从 [git-scm.com](https://git-scm.com/) 安装 Git for Windows。
11
+
12
+ ## 原生依赖构建工具
13
+
14
+ `git-ai` 依赖以下包含原生绑定的库:
15
+ * `tree-sitter`: 用于代码解析 (C++)
16
+ * `cozo-node`: 图数据库引擎 (Rust/C++)
17
+
18
+ 虽然这些库通常提供预编译二进制包,但在某些环境(如 Node 版本不匹配或特定系统架构)下可能需要从源码编译。因此建议准备好编译环境。
19
+
20
+ ### 选项 1: 通过管理员 PowerShell 安装 (推荐)
21
+
22
+ 以管理员身份打开 PowerShell 并运行:
23
+
24
+ ```powershell
25
+ npm install --global --production windows-build-tools
26
+ ```
27
+
28
+ *注意:此包有时会过时或有问题。如果卡住或失败,请使用选项 2。*
29
+
30
+ ### 选项 2: 手动安装
31
+
32
+ 1. **Python**: 从 [python.org](https://www.python.org/) 或 Microsoft Store 安装 Python 3。
33
+ 2. **Visual Studio Build Tools**:
34
+ * 下载 [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)。
35
+ * 运行安装程序并选择 **"Desktop development with C++" (使用 C++ 的桌面开发)** 工作负载。
36
+ * 确保选中 "MSVC ... C++ x64/x86 build tools" 和 "Windows 10/11 SDK"。
37
+
38
+ ## 安装
39
+
40
+ 满足前置条件后:
41
+
42
+ ```bash
43
+ git clone https://github.com/mars167/git-ai-cli.git
44
+ cd git-ai-cli-v2
45
+ npm install
46
+ npm run build
47
+ ```
48
+
49
+ ## 运行示例
50
+
51
+ 要验证对不同语言的支持,可以运行解析测试:
52
+
53
+ ```bash
54
+ npx ts-node test/verify_parsing.ts
55
+ ```
56
+
57
+ 要完整开发多语言示例,你可能需要安装各自的语言运行时:
58
+
59
+ * **C**: 安装 MinGW 或使用 MSVC (cl.exe)。
60
+ * **Go**: 从 [go.dev](https://go.dev/dl/) 安装。
61
+ * **Python**: [python.org](https://www.python.org/)。
62
+ * **Rust**: 通过 [rustup.rs](https://rustup.rs/) 安装。
63
+
64
+ ## 排障
65
+
66
+ * **node-gyp 错误**: 确保 Python 和 Visual Studio Build Tools 已正确安装并在 PATH 中。你可以配置 npm 使用特定 python 版本:`npm config set python python3`。
67
+ * **路径问题**: 如果全局运行,确保 `git-ai` 二进制文件或 `npm bin` 在你的 PATH 中。
package/install.sh ADDED
@@ -0,0 +1,183 @@
1
+ #!/bin/bash
2
+ #
3
+ # git-ai Quick Install Script
4
+ #
5
+ # Usage:
6
+ # curl -fsSL https://raw.githubusercontent.com/mars167/git-ai-cli/main/install.sh | bash
7
+ #
8
+ # Or with options:
9
+ # curl -fsSL https://raw.githubusercontent.com/mars167/git-ai-cli/main/install.sh | bash -s -- --with-skill
10
+ #
11
+ # This script installs:
12
+ # 1. git-ai CLI tool (via npm)
13
+ # 2. Optionally: git-ai-mcp skill for AI agents
14
+ #
15
+
16
+ set -e
17
+
18
+ # Colors for output
19
+ RED='\033[0;31m'
20
+ GREEN='\033[0;32m'
21
+ YELLOW='\033[1;33m'
22
+ BLUE='\033[0;34m'
23
+ CYAN='\033[0;36m'
24
+ NC='\033[0m' # No Color
25
+ BOLD='\033[1m'
26
+
27
+ # Banner
28
+ print_banner() {
29
+ echo -e "${CYAN}"
30
+ echo ' ____ _ _ _ ___ '
31
+ echo ' / ___| (_) | |_ / \ |_ _|'
32
+ echo ' | | _ | | | __| ___ / _ \ | | '
33
+ echo ' | |_| | | | | |_ |___| / ___ \ | | '
34
+ echo ' \____| |_| \__| /_/ \_\___|'
35
+ echo -e "${NC}"
36
+ echo -e "${BOLD}Semantic Code Understanding for AI Agents${NC}"
37
+ echo ""
38
+ }
39
+
40
+ # Logging functions
41
+ info() {
42
+ echo -e "${BLUE}[INFO]${NC} $1"
43
+ }
44
+
45
+ success() {
46
+ echo -e "${GREEN}[OK]${NC} $1"
47
+ }
48
+
49
+ warn() {
50
+ echo -e "${YELLOW}[WARN]${NC} $1"
51
+ }
52
+
53
+ error() {
54
+ echo -e "${RED}[ERROR]${NC} $1"
55
+ exit 1
56
+ }
57
+
58
+ # Check if command exists
59
+ command_exists() {
60
+ command -v "$1" >/dev/null 2>&1
61
+ }
62
+
63
+ # Parse arguments
64
+ INSTALL_SKILL=false
65
+ GLOBAL_INSTALL=true
66
+
67
+ while [[ $# -gt 0 ]]; do
68
+ case $1 in
69
+ --with-skill|-s)
70
+ INSTALL_SKILL=true
71
+ shift
72
+ ;;
73
+ --local|-l)
74
+ GLOBAL_INSTALL=false
75
+ shift
76
+ ;;
77
+ --help|-h)
78
+ echo "Usage: install.sh [OPTIONS]"
79
+ echo ""
80
+ echo "Options:"
81
+ echo " --with-skill, -s Also install git-ai-mcp skill for AI agents"
82
+ echo " --local, -l Install locally instead of globally"
83
+ echo " --help, -h Show this help message"
84
+ exit 0
85
+ ;;
86
+ *)
87
+ warn "Unknown option: $1"
88
+ shift
89
+ ;;
90
+ esac
91
+ done
92
+
93
+ # Main installation
94
+ main() {
95
+ print_banner
96
+
97
+ # Check prerequisites
98
+ info "Checking prerequisites..."
99
+
100
+ if ! command_exists node; then
101
+ error "Node.js is required but not installed. Please install Node.js 18+ first."
102
+ fi
103
+
104
+ NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
105
+ if [ "$NODE_VERSION" -lt 18 ]; then
106
+ error "Node.js 18+ is required. Current version: $(node -v)"
107
+ fi
108
+ success "Node.js $(node -v) detected"
109
+
110
+ if ! command_exists npm; then
111
+ error "npm is required but not installed."
112
+ fi
113
+ success "npm $(npm -v) detected"
114
+
115
+ # Install git-ai
116
+ info "Installing git-ai CLI..."
117
+
118
+ if [ "$GLOBAL_INSTALL" = true ]; then
119
+ npm install -g git-ai
120
+ success "git-ai installed globally"
121
+ else
122
+ npm install git-ai
123
+ success "git-ai installed locally"
124
+ fi
125
+
126
+ # Verify installation
127
+ if command_exists git-ai; then
128
+ success "git-ai $(git-ai --version 2>/dev/null || echo 'installed')"
129
+ else
130
+ warn "git-ai command not found in PATH. You may need to restart your terminal."
131
+ fi
132
+
133
+ # Install skill if requested
134
+ if [ "$INSTALL_SKILL" = true ]; then
135
+ info "Installing git-ai-mcp skill..."
136
+
137
+ if ! command_exists npx; then
138
+ warn "npx not found. Skipping skill installation."
139
+ else
140
+ # Check if skills CLI is available
141
+ if npx skills --version >/dev/null 2>&1; then
142
+ npx skills add mars167/git-ai-cli@git-ai-mcp -g -y
143
+ success "git-ai-mcp skill installed"
144
+ else
145
+ info "Installing skills CLI..."
146
+ npx skills add mars167/git-ai-cli@git-ai-mcp -g -y
147
+ success "git-ai-mcp skill installed"
148
+ fi
149
+ fi
150
+ fi
151
+
152
+ # Print next steps
153
+ echo ""
154
+ echo -e "${GREEN}${BOLD}Installation Complete!${NC}"
155
+ echo ""
156
+ echo -e "${BOLD}Quick Start:${NC}"
157
+ echo ""
158
+ echo " 1. Initialize index in your project:"
159
+ echo -e " ${CYAN}cd your-project${NC}"
160
+ echo -e " ${CYAN}git-ai ai index --overwrite${NC}"
161
+ echo ""
162
+ echo " 2. Search code semantically:"
163
+ echo -e " ${CYAN}git-ai ai semantic \"user authentication\"${NC}"
164
+ echo ""
165
+ echo " 3. Analyze call graphs:"
166
+ echo -e " ${CYAN}git-ai ai graph callers functionName${NC}"
167
+ echo ""
168
+
169
+ if [ "$INSTALL_SKILL" = false ]; then
170
+ echo -e "${BOLD}For AI Agent Integration:${NC}"
171
+ echo ""
172
+ echo " Install the MCP skill for Claude/Cursor/etc:"
173
+ echo -e " ${CYAN}curl -fsSL https://raw.githubusercontent.com/mars167/git-ai-cli/main/install.sh | bash -s -- --with-skill${NC}"
174
+ echo ""
175
+ fi
176
+
177
+ echo -e "${BOLD}Documentation:${NC}"
178
+ echo " https://github.com/mars167/git-ai-cli"
179
+ echo ""
180
+ }
181
+
182
+ # Run main
183
+ main
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@mars167/git-ai",
3
+ "version": "2.3.0",
4
+ "main": "dist/index.js",
5
+ "bin": {
6
+ "git-ai": "dist/bin/git-ai.js"
7
+ },
8
+ "directories": {
9
+ "doc": "docs"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "start": "ts-node bin/git-ai.ts",
14
+ "test": "npm run build && node --test test/*.test.mjs test/*.test.ts",
15
+ "test:parser": "ts-node test/verify_parsing.ts"
16
+ },
17
+ "files": [
18
+ "dist/**",
19
+ "docs/**",
20
+ "assets/**",
21
+ "templates/**",
22
+ "skills/**",
23
+ "install.sh",
24
+ "README.md"
25
+ ],
26
+ "keywords": [
27
+ "git",
28
+ "ai",
29
+ "semantic-search",
30
+ "mcp",
31
+ "code-search",
32
+ "code-understanding",
33
+ "vector-search",
34
+ "graph-database",
35
+ "cli",
36
+ "code-indexing",
37
+ "knowledge-graph"
38
+ ],
39
+ "author": "mars167",
40
+ "license": "MIT",
41
+ "description": "A git-compatible CLI with AI indexing/search and an MCP server.",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/mars167/git-ai-cli.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/mars167/git-ai-cli/issues"
48
+ },
49
+ "homepage": "https://github.com/mars167/git-ai-cli#readme",
50
+ "engines": {
51
+ "node": ">=18"
52
+ },
53
+ "os": [
54
+ "darwin",
55
+ "linux",
56
+ "win32"
57
+ ],
58
+ "funding": {
59
+ "type": "github",
60
+ "url": "https://github.com/sponsors/mars167"
61
+ },
62
+ "dependencies": {
63
+ "@lancedb/lancedb": "0.22.3",
64
+ "@modelcontextprotocol/sdk": "^1.25.2",
65
+ "@types/fs-extra": "^11.0.4",
66
+ "@types/node": "^25.0.9",
67
+ "apache-arrow": "18.1.0",
68
+ "commander": "^14.0.2",
69
+ "fs-extra": "^11.3.3",
70
+ "glob": "^13.0.0",
71
+ "onnxruntime-node": "^1.19.2",
72
+ "simple-git": "^3.30.0",
73
+ "tar": "^7.5.3",
74
+ "tree-sitter": "^0.21.1",
75
+ "tree-sitter-c": "^0.21.4",
76
+ "tree-sitter-go": "^0.21.2",
77
+ "tree-sitter-java": "^0.21.0",
78
+ "tree-sitter-python": "^0.21.0",
79
+ "tree-sitter-rust": "^0.21.0",
80
+ "tree-sitter-typescript": "^0.21.1",
81
+ "ts-node": "^10.9.2",
82
+ "typescript": "^5.9.3",
83
+ "zod": "^4.3.5"
84
+ },
85
+ "optionalDependencies": {
86
+ "@lancedb/lancedb-darwin-arm64": "0.22.3",
87
+ "@lancedb/lancedb-darwin-x64": "0.22.3",
88
+ "@lancedb/lancedb-linux-arm64-gnu": "0.22.3",
89
+ "@lancedb/lancedb-linux-arm64-musl": "0.22.3",
90
+ "@lancedb/lancedb-linux-x64-gnu": "0.22.3",
91
+ "@lancedb/lancedb-linux-x64-musl": "0.22.3",
92
+ "@lancedb/lancedb-win32-arm64-msvc": "0.22.3",
93
+ "@lancedb/lancedb-win32-x64-msvc": "0.22.3",
94
+ "cozo-lib-wasm": "^0.7.6",
95
+ "cozo-node": "^0.7.6"
96
+ }
97
+ }
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: git-ai-mcp
3
+ description: |
4
+ Efficient codebase understanding and navigation using git-ai MCP tools. Use when working with code repositories that have git-ai indexed, including: (1) Understanding project structure and architecture, (2) Searching for symbols, functions, or semantic concepts, (3) Analyzing code relationships and call graphs, (4) Tracking symbol evolution and change history via DSR, (5) Reading and navigating code files. Triggers: "understand this project", "find function X", "who calls X", "what does X call", "history of X", "where is X implemented".
5
+ ---
6
+
7
+ # git-ai MCP Skill
8
+
9
+ Guide for using git-ai MCP tools to understand and navigate codebases efficiently.
10
+
11
+ ## Overview
12
+
13
+ git-ai provides semantic code understanding through:
14
+
15
+ - **Hyper RAG**: Vector + Graph + DSR retrieval
16
+ - **AST Analysis**: Symbol relationships and call graphs
17
+ - **DSR**: Deterministic Semantic Records for change tracking
18
+
19
+ ## Workflow
20
+
21
+ Understanding a codebase involves these steps:
22
+
23
+ 1. Get global view (run `repo_map`)
24
+ 2. Check index status (run `check_index`, rebuild if needed)
25
+ 3. Locate code (run `search_symbols` or `semantic_search`)
26
+ 4. Analyze relationships (run `ast_graph_callers/callees/chain`)
27
+ 5. Trace history (run `dsr_symbol_evolution`)
28
+ 6. Read code (run `read_file`)
29
+
30
+ ## Tool Selection
31
+
32
+ | Task | Tool | Key Parameters |
33
+ |------|------|----------------|
34
+ | Project overview | `repo_map` | `path`, `max_files: 20` |
35
+ | Find by name | `search_symbols` | `path`, `query`, `mode: substring` |
36
+ | Find by meaning | `semantic_search` | `path`, `query`, `topk: 10` |
37
+ | Who calls X | `ast_graph_callers` | `path`, `name` |
38
+ | What X calls | `ast_graph_callees` | `path`, `name` |
39
+ | Call chain | `ast_graph_chain` | `path`, `name`, `direction`, `max_depth` |
40
+ | Symbol history | `dsr_symbol_evolution` | `path`, `symbol`, `limit` |
41
+ | Read code | `read_file` | `path`, `file`, `start_line`, `end_line` |
42
+ | Index health | `check_index` | `path` |
43
+ | Rebuild index | `rebuild_index` | `path` |
44
+
45
+ ## Critical Rules
46
+
47
+ **MUST follow:**
48
+
49
+ 1. **Always pass `path` explicitly** - Never rely on implicit working directory
50
+ 2. **Check index before search** - Run `check_index` before using search/graph tools
51
+ 3. **Read before modify** - Use `read_file` to understand code before making changes
52
+ 4. **Use DSR for history** - Never manually parse git log; use `dsr_symbol_evolution`
53
+
54
+ **NEVER do:**
55
+
56
+ - Assume symbol locations without searching
57
+ - Modify files without reading them first
58
+ - Search when index is missing or incompatible
59
+ - Ignore DSR risk levels (high risk = extra review needed)
60
+
61
+ ## Examples
62
+
63
+ **Find authentication code:**
64
+ ```js
65
+ semantic_search({ path: "/repo", query: "user authentication logic", topk: 10 })
66
+ ```
67
+
68
+ **Find who calls a function:**
69
+ ```js
70
+ ast_graph_callers({ path: "/repo", name: "handleRequest", limit: 50 })
71
+ ```
72
+
73
+ **Trace call chain upstream:**
74
+ ```js
75
+ ast_graph_chain({ path: "/repo", name: "processOrder", direction: "upstream", max_depth: 3 })
76
+ ```
77
+
78
+ **View symbol history:**
79
+ ```js
80
+ dsr_symbol_evolution({ path: "/repo", symbol: "authenticateUser", limit: 50 })
81
+ ```
82
+
83
+ ## References
84
+
85
+ - **Tool details**: See [references/tools.md](references/tools.md) for complete tool documentation
86
+ - **Constraints**: See [references/constraints.md](references/constraints.md) for behavioral rules
@@ -0,0 +1,143 @@
1
+ # git-ai MCP Behavioral Constraints
2
+
3
+ Rules and constraints for using git-ai MCP tools effectively and safely.
4
+
5
+ ## Must-Follow Rules (Error Level)
6
+
7
+ ### 1. explicit_path
8
+
9
+ **Rule:** Every MCP tool call MUST include an explicit `path` parameter.
10
+
11
+ **Why:** Ensures atomic, reproducible calls. Never rely on process state or working directory.
12
+
13
+ **Good:**
14
+ ```js
15
+ search_symbols({ path: "/abs/path/to/repo", query: "handleRequest" })
16
+ ```
17
+
18
+ **Bad:**
19
+ ```js
20
+ search_symbols({ query: "handleRequest" }) // Missing path!
21
+ ```
22
+
23
+ ### 2. check_index_first
24
+
25
+ **Rule:** Before using `search_symbols`, `semantic_search`, or any `ast_graph_*` tool, MUST call `check_index` to verify index is ready.
26
+
27
+ **Why:** These tools depend on the index. Searching with a missing/incompatible index gives unreliable results.
28
+
29
+ **Workflow:**
30
+ ```js
31
+ // Step 1: Check index
32
+ const status = check_index({ path: "/repo" })
33
+
34
+ // Step 2: Rebuild if needed
35
+ if (!status.compatible) {
36
+ rebuild_index({ path: "/repo" })
37
+ }
38
+
39
+ // Step 3: Now safe to search
40
+ search_symbols({ path: "/repo", query: "..." })
41
+ ```
42
+
43
+ ### 3. understand_before_modify
44
+
45
+ **Rule:** Before modifying any file, MUST:
46
+ 1. Use `search_symbols` to locate the code
47
+ 2. Use `read_file` to understand the implementation
48
+ 3. Use `ast_graph_callers` to assess impact
49
+ 4. Only then make changes
50
+
51
+ **Why:** Prevents breaking changes and ensures informed modifications.
52
+
53
+ ### 4. use_dsr_for_history
54
+
55
+ **Rule:** When tracing symbol history, MUST use `dsr_symbol_evolution`. NEVER manually parse git log or diff.
56
+
57
+ **Why:** DSR provides structured, semantic change information that raw git commands don't.
58
+
59
+ ## Warning-Level Rules
60
+
61
+ ### 5. repo_map_before_large_change
62
+
63
+ **Rule:** Before large refactoring or architectural changes, use `repo_map` to understand project structure.
64
+
65
+ **Why:** Provides context for planning changes and identifying affected areas.
66
+
67
+ ### 6. respect_dsr_risk
68
+
69
+ **Rule:** When DSR reports `risk_level: high`, exercise extra caution. Operations like `delete` and `rename` require additional review.
70
+
71
+ **Risk levels:**
72
+ - `low`: Safe, routine changes
73
+ - `medium`: Review recommended
74
+ - `high`: Extra scrutiny required
75
+
76
+ ## Recommended Practices
77
+
78
+ ### prefer_semantic_search
79
+
80
+ For understanding functional intent, prefer `semantic_search` over `search_symbols`.
81
+
82
+ **Use `semantic_search` when:**
83
+ - Looking for conceptual functionality
84
+ - Query is in natural language
85
+ - Exact name is unknown
86
+
87
+ **Use `search_symbols` when:**
88
+ - Exact or partial name is known
89
+ - Looking for specific identifiers
90
+
91
+ ### use_call_chain_for_complex_flow
92
+
93
+ For complex flows spanning multiple functions, use `ast_graph_chain` instead of manually chaining `callers`/`callees` calls.
94
+
95
+ ```js
96
+ // Good: Single call for complete chain
97
+ ast_graph_chain({ path: "/repo", name: "processPayment", direction: "upstream", max_depth: 5 })
98
+
99
+ // Avoid: Manual recursive calls
100
+ ast_graph_callers({ path: "/repo", name: "processPayment" })
101
+ // then for each result...
102
+ ast_graph_callers({ path: "/repo", name: result.name })
103
+ // etc.
104
+ ```
105
+
106
+ ### incremental_dsr_generation
107
+
108
+ Generate DSR on-demand for specific commits rather than batch-generating for entire history.
109
+
110
+ ```js
111
+ // Good: Generate for specific commit when needed
112
+ dsr_generate({ path: "/repo", commit: "abc123" })
113
+
114
+ // Avoid: Generating for all historical commits upfront
115
+ ```
116
+
117
+ ## Prohibited Actions
118
+
119
+ | Action | Reason |
120
+ |--------|--------|
121
+ | Assume symbol location without searching | Always confirm via search |
122
+ | Modify unread files | Must read and understand first |
123
+ | Manual git log parsing for history | Use DSR tools instead |
124
+ | Search with missing index | Rebuild index first |
125
+ | Ignore high risk DSR warnings | Requires extra review |
126
+ | Omit `path` parameter | Every call must be explicit |
127
+
128
+ ## Tool-Specific Constraints
129
+
130
+ | Tool | Precondition | Required Params |
131
+ |------|--------------|-----------------|
132
+ | `repo_map` | None | `path` |
133
+ | `check_index` | None | `path` |
134
+ | `rebuild_index` | None | `path` |
135
+ | `search_symbols` | `check_index` passed | `path`, `query` |
136
+ | `semantic_search` | `check_index` passed | `path`, `query` |
137
+ | `ast_graph_callers` | `check_index` passed | `path`, `name` |
138
+ | `ast_graph_callees` | `check_index` passed | `path`, `name` |
139
+ | `ast_graph_chain` | `check_index` passed | `path`, `name` |
140
+ | `dsr_context` | None | `path` |
141
+ | `dsr_generate` | None | `path`, `commit` |
142
+ | `dsr_symbol_evolution` | DSR exists for commits | `path`, `symbol` |
143
+ | `read_file` | None | `path`, `file` |