@chiway/contextweaver 1.1.0 → 1.5.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 (37) hide show
  1. package/README.md +138 -28
  2. package/dist/{SearchService-MYPOCM3B.js → SearchService-WVD6THR3.js} +170 -82
  3. package/dist/chunk-3BNHQV5W.js +373 -0
  4. package/dist/chunk-BFCIZ52F.js +102 -0
  5. package/dist/{chunk-NQR4CGQ6.js → chunk-GDVB6PJ4.js} +58 -10
  6. package/dist/{lock-DVY3KJSK.js → chunk-HHYPQA3X.js} +2 -3
  7. package/dist/chunk-ISVCQFB4.js +223 -0
  8. package/dist/chunk-IZ6IUHNN.js +77 -0
  9. package/dist/{chunk-AMQQK4P7.js → chunk-JVKVSTQ3.js} +1 -2
  10. package/dist/chunk-LB42CZEB.js +18 -0
  11. package/dist/{chunk-6Z4JEEVJ.js → chunk-PPLFJGO3.js} +303 -58
  12. package/dist/chunk-R6CNZXZ7.js +143 -0
  13. package/dist/{chunk-RJURH22T.js → chunk-SKBAE26T.js} +0 -1
  14. package/dist/chunk-TPM6YP43.js +38 -0
  15. package/dist/{chunk-7G5V7YT5.js → chunk-V3K4YVAR.js} +12 -120
  16. package/dist/chunk-VWBKZ6QL.js +115 -0
  17. package/dist/chunk-XFIM2T6S.js +57 -0
  18. package/dist/{chunk-6QMYML5V.js → chunk-XMZZZKG7.js} +361 -295
  19. package/dist/chunk-XTWNT7KP.js +156 -0
  20. package/dist/chunk-Y6H7C3NA.js +85 -0
  21. package/dist/codebaseRetrieval-DIS5RH2C.js +14 -0
  22. package/dist/{config-BWZ6CU3W.js → config-LCOJHTCF.js} +1 -2
  23. package/dist/db-GBCLP4GG.js +68 -0
  24. package/dist/findReferences-N7ML7TUP.js +16 -0
  25. package/dist/getSymbolDefinition-6KMY4H33.js +17 -0
  26. package/dist/index.js +271 -40
  27. package/dist/listFiles-4VT2TPJD.js +14 -0
  28. package/dist/loadConfig-XTVT2OWW.js +9 -0
  29. package/dist/lock-HNKQ6X5B.js +8 -0
  30. package/dist/scanner-QDFZJLP7.js +13 -0
  31. package/dist/server-UAI3U7AB.js +347 -0
  32. package/dist/stats-AGKUCJQI.js +12 -0
  33. package/dist/vectorStore-4ODCERRO.js +12 -0
  34. package/package.json +9 -23
  35. package/dist/codebaseRetrieval-NLAMGOA2.js +0 -12
  36. package/dist/scanner-RFG4YWYI.js +0 -11
  37. package/dist/server-27HI7WZO.js +0 -147
@@ -0,0 +1,156 @@
1
+ import {
2
+ getVectorStore
3
+ } from "./chunk-3BNHQV5W.js";
4
+ import {
5
+ closeDb,
6
+ collectHealthSnapshot,
7
+ getAllStats,
8
+ getStatJson,
9
+ initDb
10
+ } from "./chunk-PPLFJGO3.js";
11
+ import {
12
+ logger
13
+ } from "./chunk-JVKVSTQ3.js";
14
+ import {
15
+ getEmbeddingConfig
16
+ } from "./chunk-SKBAE26T.js";
17
+
18
+ // src/stats/index.ts
19
+ function num(stats, key) {
20
+ const v = stats[key];
21
+ if (v === void 0) return 0;
22
+ const parsed = Number.parseInt(v, 10);
23
+ return Number.isNaN(parsed) ? 0 : parsed;
24
+ }
25
+ function avg(sum, count) {
26
+ if (count <= 0) return null;
27
+ return sum / count;
28
+ }
29
+ async function collectStats(projectId) {
30
+ const db = initDb(projectId);
31
+ try {
32
+ const health = collectHealthSnapshot(db);
33
+ const stats = getAllStats(db);
34
+ let lancedbRows = 0;
35
+ try {
36
+ const store = await getVectorStore(projectId, getEmbeddingConfig().dimensions);
37
+ lancedbRows = await store.count();
38
+ } catch (err) {
39
+ logger.warn({ error: err.message }, "\u8BFB\u53D6 LanceDB \u884C\u6570\u5931\u8D25");
40
+ }
41
+ const computeRuns = num(stats, "stats.search.compute_runs");
42
+ const totalQueries = num(stats, "stats.search.total_queries");
43
+ const cacheHits = num(stats, "stats.search.cache_hits");
44
+ const index = {
45
+ totalRuns: num(stats, "stats.index.total_runs"),
46
+ lastRun: getStatJson(db, "stats.index.last_run_json"),
47
+ lastRunAt: getStatJson(db, "stats.index.last_run_at")
48
+ };
49
+ const search = {
50
+ totalQueries,
51
+ cacheHits,
52
+ cacheHitRate: totalQueries > 0 ? cacheHits / totalQueries : null,
53
+ computeRuns,
54
+ avgRetrieveMs: avg(num(stats, "stats.search.sum_retrieve_ms"), computeRuns),
55
+ avgRerankMs: avg(num(stats, "stats.search.sum_rerank_ms"), computeRuns),
56
+ avgExpandMs: avg(num(stats, "stats.search.sum_expand_ms"), computeRuns),
57
+ avgPackMs: avg(num(stats, "stats.search.sum_pack_ms"), computeRuns),
58
+ avgSeedCount: avg(num(stats, "stats.search.sum_seed_count"), computeRuns)
59
+ };
60
+ const diagnostics = buildDiagnostics(health, lancedbRows);
61
+ return { projectId, health, lancedbRows, index, search, diagnostics };
62
+ } finally {
63
+ closeDb(db);
64
+ }
65
+ }
66
+ function buildDiagnostics(health, lancedbRows) {
67
+ const out = [];
68
+ if (health.migrationState === "aborted") {
69
+ out.push(
70
+ "LanceDB \u8FC1\u79FB\u72B6\u6001\u4E3A aborted\uFF0C\u7D22\u5F15\u5199\u5165\u88AB\u62D2\u7EDD\u3002\u8FD0\u884C `contextweaver migrate --reset` \u89E3\u9664\u3002"
71
+ );
72
+ }
73
+ if (health.migrationState === "pending") {
74
+ out.push("LanceDB \u8FC1\u79FB\u72B6\u6001\u4E3A pending\uFF0C\u53EF\u80FD\u4E0A\u6B21\u8FC1\u79FB\u672A\u5B8C\u6210\u3002");
75
+ }
76
+ if (health.pendingMarks > 0) {
77
+ out.push(`pending_marks \u79EF\u538B ${health.pendingMarks} \u6761\uFF0C\u4E0B\u6B21\u542F\u52A8\u5C06\u91CD\u653E\u3002\u82E5\u6301\u7EED\u4E0D\u51CF\u9700\u6392\u67E5\u3002`);
78
+ }
79
+ if (health.totalFiles > 0 && lancedbRows === 0) {
80
+ out.push(
81
+ `\u5DF2\u7D22\u5F15 ${health.totalFiles} \u4E2A\u6587\u4EF6\u4F46 LanceDB \u65E0\u5411\u91CF\u884C\uFF0C\u5411\u91CF\u7D22\u5F15\u53EF\u80FD\u672A\u5EFA\u7ACB\u3002\u8FD0\u884C \`contextweaver index\` \u91CD\u5EFA\u3002`
82
+ );
83
+ }
84
+ if (health.embeddingDimensions === null && health.totalFiles > 0) {
85
+ out.push("\u672A\u8BB0\u5F55 embedding \u7EF4\u5EA6\uFF0C\u7D22\u5F15\u5143\u6570\u636E\u53EF\u80FD\u4E0D\u5B8C\u6574\u3002");
86
+ }
87
+ return out;
88
+ }
89
+ function renderStatsText(report) {
90
+ const fmt = (v, suffix = "") => v === null ? "\u2014" : `${Number.isInteger(v) ? v : v.toFixed(1)}${suffix}`;
91
+ const pct = (v) => v === null ? "\u2014" : `${(v * 100).toFixed(1)}%`;
92
+ const bytes = (n) => {
93
+ if (n < 1024) return `${n} B`;
94
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
95
+ return `${(n / 1024 / 1024).toFixed(1)} MB`;
96
+ };
97
+ const lines = [];
98
+ lines.push(`ContextWeaver \u7EDF\u8BA1 (projectId: ${report.projectId})`);
99
+ lines.push("");
100
+ const ix = report.index;
101
+ lines.push("\u3010\u7D22\u5F15\u8FC7\u7A0B\u3011");
102
+ lines.push(` \u7D2F\u8BA1\u7D22\u5F15\u8FD0\u884C: ${ix.totalRuns} \u6B21`);
103
+ if (ix.lastRunAt) {
104
+ lines.push(` \u4E0A\u6B21\u7D22\u5F15\u65F6\u95F4: ${new Date(ix.lastRunAt).toLocaleString()}`);
105
+ }
106
+ if (ix.lastRun) {
107
+ const r = ix.lastRun;
108
+ lines.push(
109
+ ` \u4E0A\u6B21\u7ED3\u679C: \u603B\u6570=${r.totalFiles} \u65B0\u589E=${r.added} \u4FEE\u6539=${r.modified} \u672A\u53D8=${r.unchanged} \u5220\u9664=${r.deleted} \u8DF3\u8FC7=${r.skipped} \u9519\u8BEF=${r.errors}`
110
+ );
111
+ if (r.vectorIndex) {
112
+ lines.push(
113
+ ` \u5411\u91CF\u7D22\u5F15: \u5DF2\u7D22\u5F15=${r.vectorIndex.indexed} \u5220\u9664=${r.vectorIndex.deleted} \u9519\u8BEF=${r.vectorIndex.errors}`
114
+ );
115
+ }
116
+ } else {
117
+ lines.push(" \u4E0A\u6B21\u7ED3\u679C: \u6682\u65E0\uFF08\u5C1A\u672A\u7D22\u5F15\uFF09");
118
+ }
119
+ lines.push("");
120
+ const s = report.search;
121
+ lines.push("\u3010\u641C\u7D22\u8D28\u91CF/\u884C\u4E3A\u3011");
122
+ lines.push(
123
+ ` \u7D2F\u8BA1\u67E5\u8BE2: ${s.totalQueries} \u6B21 (\u7F13\u5B58\u547D\u4E2D ${s.cacheHits}\uFF0C\u547D\u4E2D\u7387 ${pct(s.cacheHitRate)})`
124
+ );
125
+ lines.push(` \u5B9E\u9645\u8BA1\u7B97: ${s.computeRuns} \u6B21\uFF08\u672A\u547D\u4E2D\u7F13\u5B58\uFF0C\u4F5C\u4E3A\u4E0B\u5217\u5747\u503C\u5206\u6BCD\uFF09`);
126
+ lines.push(
127
+ ` \u5E73\u5747\u8017\u65F6: retrieve=${fmt(s.avgRetrieveMs, "ms")} rerank=${fmt(s.avgRerankMs, "ms")} expand=${fmt(s.avgExpandMs, "ms")} pack=${fmt(s.avgPackMs, "ms")}`
128
+ );
129
+ lines.push(` \u5E73\u5747\u53EC\u56DE: ${fmt(s.avgSeedCount)} \u4E2A seed`);
130
+ lines.push("");
131
+ const h = report.health;
132
+ lines.push("\u3010\u5065\u5EB7/\u4E00\u81F4\u6027\u3011");
133
+ lines.push(` \u6587\u4EF6: ${h.totalFiles} \u4E2A\uFF0C\u6B63\u6587\u603B\u91CF ${bytes(h.totalBytes)}`);
134
+ lines.push(` LanceDB \u5411\u91CF\u884C: ${report.lancedbRows}`);
135
+ lines.push(
136
+ ` embedding \u7EF4\u5EA6: ${h.embeddingDimensions ?? "\u2014"} \u7D22\u5F15\u7248\u672C: ${h.indexVersion} \u8FC1\u79FB\u72B6\u6001: ${h.migrationState ?? "\u672A\u8BBE\u7F6E"} pending_marks: ${h.pendingMarks}`
137
+ );
138
+ const langs = Object.entries(h.byLanguage).sort((a, b) => b[1] - a[1]);
139
+ if (langs.length > 0) {
140
+ const langStr = langs.map(([lang, c]) => `${lang}=${c}`).join(" ");
141
+ lines.push(` \u8BED\u8A00\u5360\u6BD4: ${langStr}`);
142
+ }
143
+ lines.push("");
144
+ if (report.diagnostics.length > 0) {
145
+ lines.push("\u3010\u8BCA\u65AD\u544A\u8B66\u3011");
146
+ for (const d of report.diagnostics) lines.push(` \u26A0 ${d}`);
147
+ } else {
148
+ lines.push("\u3010\u8BCA\u65AD\u3011\u65E0\u5F02\u5E38");
149
+ }
150
+ return lines.join("\n");
151
+ }
152
+
153
+ export {
154
+ collectStats,
155
+ renderStatsText
156
+ };
@@ -0,0 +1,85 @@
1
+ import {
2
+ ensureIndexed,
3
+ formatTextResponse
4
+ } from "./chunk-VWBKZ6QL.js";
5
+ import {
6
+ generateProjectId,
7
+ initDb
8
+ } from "./chunk-PPLFJGO3.js";
9
+ import {
10
+ logger
11
+ } from "./chunk-JVKVSTQ3.js";
12
+
13
+ // src/mcp/tools/listFiles.ts
14
+ import { z } from "zod";
15
+ var listFilesSchema = z.object({
16
+ repo_path: z.string().describe(
17
+ "The absolute file system path to the repository root. (e.g., '/Users/dev/my-project')"
18
+ ),
19
+ glob: z.string().optional().describe("Optional glob pattern to filter returned file paths."),
20
+ language: z.string().optional().describe("Optional language filter matched against files.language."),
21
+ max_results: z.number().int().positive().max(1e3).optional().describe("Maximum number of files to return. Defaults to 200.")
22
+ });
23
+ function escapeRegexCharacter(char) {
24
+ return char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
25
+ }
26
+ function globToRegExp(glob) {
27
+ const normalized = glob.replace(/\\/g, "/");
28
+ let pattern = "^";
29
+ for (let i = 0; i < normalized.length; ) {
30
+ if (normalized.slice(i, i + 3) === "**/") {
31
+ pattern += "(?:.*/)?";
32
+ i += 3;
33
+ continue;
34
+ }
35
+ if (normalized.slice(i, i + 2) === "**") {
36
+ pattern += ".*";
37
+ i += 2;
38
+ continue;
39
+ }
40
+ const char = normalized[i];
41
+ if (char === "*") {
42
+ pattern += "[^/]*";
43
+ } else if (char === "?") {
44
+ pattern += "[^/]";
45
+ } else {
46
+ pattern += escapeRegexCharacter(char);
47
+ }
48
+ i += 1;
49
+ }
50
+ return new RegExp(`${pattern}$`);
51
+ }
52
+ function formatSize(size) {
53
+ if (size < 1024) {
54
+ return `${size}B`;
55
+ }
56
+ const kb = size / 1024;
57
+ if (kb < 1024) {
58
+ return `${kb.toFixed(1)}KB`;
59
+ }
60
+ return `${(kb / 1024).toFixed(1)}MB`;
61
+ }
62
+ async function handleListFiles(args, onProgress) {
63
+ const { repo_path, glob, language, max_results = 200 } = args;
64
+ const projectId = generateProjectId(repo_path);
65
+ logger.info({ repo_path, glob, language, max_results }, "MCP list-files \u8C03\u7528\u5F00\u59CB");
66
+ await ensureIndexed(repo_path, projectId, { onProgress, vectorIndex: false });
67
+ const db = initDb(projectId);
68
+ try {
69
+ const rows = language ? db.prepare("SELECT path, language, size FROM files WHERE language = ? ORDER BY path").all(language) : db.prepare("SELECT path, language, size FROM files ORDER BY path").all();
70
+ const matcher = glob ? globToRegExp(glob) : null;
71
+ const filtered = matcher ? rows.filter((row) => matcher.test(row.path)) : rows;
72
+ const limited = filtered.slice(0, max_results);
73
+ const body = limited.length > 0 ? limited.map((row) => `- ${row.path} (${row.language}, ${formatSize(row.size)})`).join("\n") : "No files matched the requested filters.";
74
+ return formatTextResponse(`Found ${limited.length} files
75
+
76
+ ${body}`);
77
+ } finally {
78
+ db.close();
79
+ }
80
+ }
81
+
82
+ export {
83
+ listFilesSchema,
84
+ handleListFiles
85
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ codebaseRetrievalSchema,
3
+ handleCodebaseRetrieval
4
+ } from "./chunk-V3K4YVAR.js";
5
+ import "./chunk-VWBKZ6QL.js";
6
+ import "./chunk-TPM6YP43.js";
7
+ import "./chunk-BFCIZ52F.js";
8
+ import "./chunk-PPLFJGO3.js";
9
+ import "./chunk-JVKVSTQ3.js";
10
+ import "./chunk-SKBAE26T.js";
11
+ export {
12
+ codebaseRetrievalSchema,
13
+ handleCodebaseRetrieval
14
+ };
@@ -6,7 +6,7 @@ import {
6
6
  getRerankerConfig,
7
7
  isDev,
8
8
  isMcpMode
9
- } from "./chunk-RJURH22T.js";
9
+ } from "./chunk-SKBAE26T.js";
10
10
  export {
11
11
  checkEmbeddingEnv,
12
12
  checkRerankerEnv,
@@ -16,4 +16,3 @@ export {
16
16
  isDev,
17
17
  isMcpMode
18
18
  };
19
- //# sourceMappingURL=config-BWZ6CU3W.js.map
@@ -0,0 +1,68 @@
1
+ import {
2
+ batchDelete,
3
+ batchUpdateMtime,
4
+ batchUpdateVectorIndexHash,
5
+ batchUpsert,
6
+ clear,
7
+ clearAllVectorIndexHash,
8
+ clearVectorIndexHash,
9
+ closeDb,
10
+ collectHealthSnapshot,
11
+ countPendingMarks,
12
+ deletePendingMarks,
13
+ generateProjectId,
14
+ getAllFileMeta,
15
+ getAllPaths,
16
+ getAllStats,
17
+ getFilesNeedingVectorIndex,
18
+ getIndexVersion,
19
+ getLanceDbMigrationState,
20
+ getStatJson,
21
+ getStoredEmbeddingDimensions,
22
+ incrementIndexVersion,
23
+ incrementStat,
24
+ initDb,
25
+ insertPendingMarks,
26
+ migrateSchema,
27
+ releaseLanceDbMigrationLock,
28
+ replayPendingMarks,
29
+ setLanceDbMigrationState,
30
+ setStatJson,
31
+ setStoredEmbeddingDimensions,
32
+ tryAcquireLanceDbMigrationLock
33
+ } from "./chunk-PPLFJGO3.js";
34
+ import "./chunk-JVKVSTQ3.js";
35
+ import "./chunk-SKBAE26T.js";
36
+ export {
37
+ batchDelete,
38
+ batchUpdateMtime,
39
+ batchUpdateVectorIndexHash,
40
+ batchUpsert,
41
+ clear,
42
+ clearAllVectorIndexHash,
43
+ clearVectorIndexHash,
44
+ closeDb,
45
+ collectHealthSnapshot,
46
+ countPendingMarks,
47
+ deletePendingMarks,
48
+ generateProjectId,
49
+ getAllFileMeta,
50
+ getAllPaths,
51
+ getAllStats,
52
+ getFilesNeedingVectorIndex,
53
+ getIndexVersion,
54
+ getLanceDbMigrationState,
55
+ getStatJson,
56
+ getStoredEmbeddingDimensions,
57
+ incrementIndexVersion,
58
+ incrementStat,
59
+ initDb,
60
+ insertPendingMarks,
61
+ migrateSchema,
62
+ releaseLanceDbMigrationLock,
63
+ replayPendingMarks,
64
+ setLanceDbMigrationState,
65
+ setStatJson,
66
+ setStoredEmbeddingDimensions,
67
+ tryAcquireLanceDbMigrationLock
68
+ };
@@ -0,0 +1,16 @@
1
+ import {
2
+ findReferencesSchema,
3
+ handleFindReferences
4
+ } from "./chunk-R6CNZXZ7.js";
5
+ import "./chunk-XFIM2T6S.js";
6
+ import "./chunk-3BNHQV5W.js";
7
+ import "./chunk-VWBKZ6QL.js";
8
+ import "./chunk-TPM6YP43.js";
9
+ import "./chunk-BFCIZ52F.js";
10
+ import "./chunk-PPLFJGO3.js";
11
+ import "./chunk-JVKVSTQ3.js";
12
+ import "./chunk-SKBAE26T.js";
13
+ export {
14
+ findReferencesSchema,
15
+ handleFindReferences
16
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ getSymbolDefinitionSchema,
3
+ handleGetSymbolDefinition
4
+ } from "./chunk-ISVCQFB4.js";
5
+ import "./chunk-LB42CZEB.js";
6
+ import "./chunk-XFIM2T6S.js";
7
+ import "./chunk-3BNHQV5W.js";
8
+ import "./chunk-VWBKZ6QL.js";
9
+ import "./chunk-TPM6YP43.js";
10
+ import "./chunk-BFCIZ52F.js";
11
+ import "./chunk-PPLFJGO3.js";
12
+ import "./chunk-JVKVSTQ3.js";
13
+ import "./chunk-SKBAE26T.js";
14
+ export {
15
+ getSymbolDefinitionSchema,
16
+ handleGetSymbolDefinition
17
+ };