@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.
- package/LICENSE +22 -0
- package/README.md +364 -0
- package/README.zh-CN.md +361 -0
- package/assets/hooks/post-checkout +28 -0
- package/assets/hooks/post-merge +28 -0
- package/assets/hooks/pre-commit +17 -0
- package/assets/hooks/pre-push +29 -0
- package/dist/bin/git-ai.js +62 -0
- package/dist/src/commands/ai.js +30 -0
- package/dist/src/commands/checkIndex.js +19 -0
- package/dist/src/commands/dsr.js +156 -0
- package/dist/src/commands/graph.js +203 -0
- package/dist/src/commands/hooks.js +125 -0
- package/dist/src/commands/index.js +92 -0
- package/dist/src/commands/pack.js +31 -0
- package/dist/src/commands/query.js +139 -0
- package/dist/src/commands/semantic.js +134 -0
- package/dist/src/commands/serve.js +14 -0
- package/dist/src/commands/status.js +78 -0
- package/dist/src/commands/trae.js +75 -0
- package/dist/src/commands/unpack.js +28 -0
- package/dist/src/core/archive.js +91 -0
- package/dist/src/core/astGraph.js +127 -0
- package/dist/src/core/astGraphQuery.js +142 -0
- package/dist/src/core/cozo.js +266 -0
- package/dist/src/core/cpg/astLayer.js +56 -0
- package/dist/src/core/cpg/callGraph.js +483 -0
- package/dist/src/core/cpg/cfgLayer.js +490 -0
- package/dist/src/core/cpg/dfgLayer.js +237 -0
- package/dist/src/core/cpg/index.js +80 -0
- package/dist/src/core/cpg/types.js +108 -0
- package/dist/src/core/crypto.js +10 -0
- package/dist/src/core/dsr/generate.js +308 -0
- package/dist/src/core/dsr/gitContext.js +74 -0
- package/dist/src/core/dsr/indexMaterialize.js +106 -0
- package/dist/src/core/dsr/paths.js +26 -0
- package/dist/src/core/dsr/query.js +73 -0
- package/dist/src/core/dsr/snapshotParser.js +73 -0
- package/dist/src/core/dsr/state.js +27 -0
- package/dist/src/core/dsr/types.js +2 -0
- package/dist/src/core/embedding/fusion.js +52 -0
- package/dist/src/core/embedding/index.js +43 -0
- package/dist/src/core/embedding/parser.js +14 -0
- package/dist/src/core/embedding/semantic.js +254 -0
- package/dist/src/core/embedding/structural.js +97 -0
- package/dist/src/core/embedding/symbolic.js +117 -0
- package/dist/src/core/embedding/tokenizer.js +91 -0
- package/dist/src/core/embedding/types.js +2 -0
- package/dist/src/core/embedding.js +36 -0
- package/dist/src/core/git.js +49 -0
- package/dist/src/core/gitDiff.js +73 -0
- package/dist/src/core/indexCheck.js +131 -0
- package/dist/src/core/indexer.js +185 -0
- package/dist/src/core/indexerIncremental.js +303 -0
- package/dist/src/core/indexing/config.js +51 -0
- package/dist/src/core/indexing/hnsw.js +568 -0
- package/dist/src/core/indexing/index.js +17 -0
- package/dist/src/core/indexing/monitor.js +82 -0
- package/dist/src/core/indexing/parallel.js +252 -0
- package/dist/src/core/lancedb.js +111 -0
- package/dist/src/core/lfs.js +27 -0
- package/dist/src/core/log.js +62 -0
- package/dist/src/core/manifest.js +88 -0
- package/dist/src/core/parser/adapter.js +2 -0
- package/dist/src/core/parser/c.js +93 -0
- package/dist/src/core/parser/chunkRelations.js +178 -0
- package/dist/src/core/parser/chunker.js +274 -0
- package/dist/src/core/parser/go.js +98 -0
- package/dist/src/core/parser/java.js +80 -0
- package/dist/src/core/parser/markdown.js +76 -0
- package/dist/src/core/parser/python.js +81 -0
- package/dist/src/core/parser/rust.js +103 -0
- package/dist/src/core/parser/typescript.js +98 -0
- package/dist/src/core/parser/utils.js +62 -0
- package/dist/src/core/parser/yaml.js +53 -0
- package/dist/src/core/parser.js +75 -0
- package/dist/src/core/paths.js +10 -0
- package/dist/src/core/repoMap.js +164 -0
- package/dist/src/core/retrieval/cache.js +31 -0
- package/dist/src/core/retrieval/classifier.js +74 -0
- package/dist/src/core/retrieval/expander.js +80 -0
- package/dist/src/core/retrieval/fuser.js +40 -0
- package/dist/src/core/retrieval/index.js +32 -0
- package/dist/src/core/retrieval/reranker.js +304 -0
- package/dist/src/core/retrieval/types.js +2 -0
- package/dist/src/core/retrieval/weights.js +42 -0
- package/dist/src/core/search.js +41 -0
- package/dist/src/core/sq8.js +65 -0
- package/dist/src/core/symbolSearch.js +143 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/workspace.js +116 -0
- package/dist/src/mcp/server.js +794 -0
- package/docs/README.md +44 -0
- package/docs/cross-encoder.md +157 -0
- package/docs/embedding.md +158 -0
- package/docs/logo.png +0 -0
- package/docs/windows-setup.md +67 -0
- package/docs/zh-CN/DESIGN.md +102 -0
- package/docs/zh-CN/README.md +46 -0
- package/docs/zh-CN/advanced.md +26 -0
- package/docs/zh-CN/architecture_explained.md +116 -0
- package/docs/zh-CN/cli.md +109 -0
- package/docs/zh-CN/dsr.md +91 -0
- package/docs/zh-CN/graph_scenarios.md +173 -0
- package/docs/zh-CN/hooks.md +14 -0
- package/docs/zh-CN/manifests.md +136 -0
- package/docs/zh-CN/mcp.md +205 -0
- package/docs/zh-CN/quickstart.md +35 -0
- package/docs/zh-CN/rules.md +7 -0
- package/docs/zh-CN/technical-details.md +454 -0
- package/docs/zh-CN/troubleshooting.md +19 -0
- package/docs/zh-CN/windows-setup.md +67 -0
- package/install.sh +183 -0
- package/package.json +97 -0
- package/skills/git-ai-mcp/SKILL.md +86 -0
- package/skills/git-ai-mcp/references/constraints.md +143 -0
- package/skills/git-ai-mcp/references/tools.md +263 -0
- package/templates/agents/common/documents/Fix EISDIR error and enable multi-language indexing.md +14 -0
- package/templates/agents/common/documents/Fix git-ai index error in CodaGraph directory.md +13 -0
- package/templates/agents/common/skills/git-ai-mcp/SKILL.md +86 -0
- package/templates/agents/common/skills/git-ai-mcp/references/constraints.md +143 -0
- package/templates/agents/common/skills/git-ai-mcp/references/tools.md +263 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureProjectRepo = ensureProjectRepo;
|
|
7
|
+
exports.ensureRepoIndexReady = ensureRepoIndexReady;
|
|
8
|
+
exports.queryManifestWorkspace = queryManifestWorkspace;
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const simple_git_1 = __importDefault(require("simple-git"));
|
|
12
|
+
const git_1 = require("./git");
|
|
13
|
+
const archive_1 = require("./archive");
|
|
14
|
+
const lancedb_1 = require("./lancedb");
|
|
15
|
+
const indexer_1 = require("./indexer");
|
|
16
|
+
const manifest_1 = require("./manifest");
|
|
17
|
+
const indexCheck_1 = require("./indexCheck");
|
|
18
|
+
function sanitizeSegment(s) {
|
|
19
|
+
return s.replace(/[^a-zA-Z0-9._-]+/g, '_').slice(0, 120);
|
|
20
|
+
}
|
|
21
|
+
async function isGitRepo(dir) {
|
|
22
|
+
return fs_extra_1.default.pathExists(path_1.default.join(dir, '.git'));
|
|
23
|
+
}
|
|
24
|
+
async function ensureCheckedOut(repoDir, revision) {
|
|
25
|
+
if (!revision)
|
|
26
|
+
return;
|
|
27
|
+
const git = (0, simple_git_1.default)(repoDir);
|
|
28
|
+
await git.fetch(['--all', '--tags']).catch(() => undefined);
|
|
29
|
+
try {
|
|
30
|
+
await git.checkout(revision);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
await git.checkout(['-f', `origin/${revision}`]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function ensureProjectRepo(params) {
|
|
38
|
+
const workspaceRoot = (0, git_1.inferWorkspaceRoot)(params.manifestRepoRoot);
|
|
39
|
+
if (workspaceRoot) {
|
|
40
|
+
const direct = path_1.default.resolve(workspaceRoot, params.project.path);
|
|
41
|
+
if (await isGitRepo(direct)) {
|
|
42
|
+
await ensureCheckedOut(direct, params.revision);
|
|
43
|
+
return { repoDir: direct, from: 'workspace' };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const cacheBase = path_1.default.join(params.manifestRepoRoot, '.git-ai', 'workspace-cache');
|
|
47
|
+
const cacheDir = path_1.default.join(cacheBase, sanitizeSegment(params.project.path || params.project.name));
|
|
48
|
+
if (await isGitRepo(cacheDir)) {
|
|
49
|
+
await ensureCheckedOut(cacheDir, params.revision);
|
|
50
|
+
return { repoDir: cacheDir, from: 'cache' };
|
|
51
|
+
}
|
|
52
|
+
if (!params.fetch)
|
|
53
|
+
throw new Error(`No remote fetch configured for project: ${params.project.name}`);
|
|
54
|
+
await fs_extra_1.default.ensureDir(cacheBase);
|
|
55
|
+
const url = (0, manifest_1.buildCloneUrl)(params.fetch, params.project.name);
|
|
56
|
+
await (0, simple_git_1.default)().clone(url, cacheDir);
|
|
57
|
+
await ensureCheckedOut(cacheDir, params.revision);
|
|
58
|
+
return { repoDir: cacheDir, from: 'cloned' };
|
|
59
|
+
}
|
|
60
|
+
async function ensureRepoIndexReady(repoRoot, dim = 256) {
|
|
61
|
+
const dbDir = (0, lancedb_1.defaultDbDir)(repoRoot);
|
|
62
|
+
const lancedbDir = path_1.default.join(dbDir);
|
|
63
|
+
if (await fs_extra_1.default.pathExists(lancedbDir))
|
|
64
|
+
return { source: 'present' };
|
|
65
|
+
const archive = path_1.default.join(repoRoot, '.git-ai', 'lancedb.tar.gz');
|
|
66
|
+
if (await fs_extra_1.default.pathExists(archive)) {
|
|
67
|
+
await (0, archive_1.unpackLanceDb)(repoRoot);
|
|
68
|
+
return { source: 'unpacked' };
|
|
69
|
+
}
|
|
70
|
+
const indexer = new indexer_1.IndexerV2({ repoRoot, scanRoot: repoRoot, dim, overwrite: true });
|
|
71
|
+
await indexer.run();
|
|
72
|
+
return { source: 'built' };
|
|
73
|
+
}
|
|
74
|
+
async function queryManifestWorkspace(params) {
|
|
75
|
+
const workspaceRoot = (0, git_1.inferWorkspaceRoot)(params.manifestRepoRoot);
|
|
76
|
+
if (!workspaceRoot)
|
|
77
|
+
throw new Error('Not a manifests repo (.repo/manifests)');
|
|
78
|
+
const manifest = await (0, manifest_1.loadRepoManifestFromManifestsRepo)(params.manifestRepoRoot);
|
|
79
|
+
const q = params.keyword.replace(/'/g, "''");
|
|
80
|
+
const rows = [];
|
|
81
|
+
for (const project of manifest.projects) {
|
|
82
|
+
const fetch = (0, manifest_1.resolveProjectFetch)(project, manifest);
|
|
83
|
+
const revision = (0, manifest_1.resolveProjectRevision)(project, manifest);
|
|
84
|
+
const ensured = await ensureProjectRepo({ manifestRepoRoot: params.manifestRepoRoot, project, fetch, revision });
|
|
85
|
+
await ensureRepoIndexReady(ensured.repoDir, 256);
|
|
86
|
+
const status = await (0, indexCheck_1.checkIndex)(ensured.repoDir);
|
|
87
|
+
if (!status.ok) {
|
|
88
|
+
const indexer = new indexer_1.IndexerV2({ repoRoot: ensured.repoDir, scanRoot: ensured.repoDir, dim: 256, overwrite: true });
|
|
89
|
+
await indexer.run();
|
|
90
|
+
}
|
|
91
|
+
const dbDir = (0, lancedb_1.defaultDbDir)(ensured.repoDir);
|
|
92
|
+
const status2 = await (0, indexCheck_1.checkIndex)(ensured.repoDir);
|
|
93
|
+
const langs = (0, indexCheck_1.resolveLangs)(status2.found.meta ?? null, 'all');
|
|
94
|
+
const { byLang } = await (0, lancedb_1.openTablesByLang)({ dbDir, dim: 256, mode: 'open_only', languages: langs });
|
|
95
|
+
for (const lang of langs) {
|
|
96
|
+
const t = byLang[lang];
|
|
97
|
+
if (!t)
|
|
98
|
+
continue;
|
|
99
|
+
const projectRows = await t.refs.query().where(`symbol ILIKE '%${q}%'`).limit(params.limit).toArray();
|
|
100
|
+
for (const r of projectRows) {
|
|
101
|
+
rows.push({
|
|
102
|
+
project: { name: project.name, path: project.path, repoRoot: ensured.repoDir, from: ensured.from },
|
|
103
|
+
lang,
|
|
104
|
+
...r,
|
|
105
|
+
});
|
|
106
|
+
if (rows.length >= params.limit)
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (rows.length >= params.limit)
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (rows.length >= params.limit)
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
return { repoRoot: params.manifestRepoRoot, workspaceRoot, count: rows.length, rows };
|
|
116
|
+
}
|