@hsingjui/contextweaver 0.0.1 → 0.0.2
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/README.md +2 -2
- package/dist/{SearchService-YLOUJF4S.js → SearchService-NM6J3XHC.js} +3 -3
- package/dist/{chunk-PN7DP6XL.js → chunk-2HG4HNNX.js} +6 -3
- package/dist/{chunk-5TV4JNTE.js → chunk-C7PBP6HL.js} +4 -4
- package/dist/{chunk-34YZ2U3O.js → chunk-JNMCEE3A.js} +3 -3
- package/dist/{chunk-5SRSUMKW.js → chunk-NHKBCYHN.js} +45 -11
- package/dist/{chunk-6C2D5Y4R.js → chunk-UWQSUTEL.js} +2 -2
- package/dist/{codebaseRetrieval-RDCNIUDM.js → codebaseRetrieval-GPSIAFSZ.js} +3 -3
- package/dist/{config-IEL3M4V5.js → config-BVORFWIO.js} +1 -1
- package/dist/index.js +6 -6
- package/dist/scanner-E52TXHEM.js +9 -0
- package/dist/{server-2SAFEAEY.js → server-Y4GFTGLG.js} +5 -6
- package/package.json +22 -10
- package/dist/scanner-66CLKCSZ.js +0 -9
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getIndexer,
|
|
3
3
|
getVectorStore
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UWQSUTEL.js";
|
|
5
5
|
import {
|
|
6
6
|
initDb,
|
|
7
7
|
isChunksFtsInitialized,
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
searchChunksFts,
|
|
12
12
|
searchFilesFts,
|
|
13
13
|
segmentQuery
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NHKBCYHN.js";
|
|
15
15
|
import {
|
|
16
16
|
getEmbeddingConfig,
|
|
17
17
|
getRerankerConfig
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-2HG4HNNX.js";
|
|
19
19
|
|
|
20
20
|
// src/api/reranker.ts
|
|
21
21
|
var RerankerClient = class {
|
|
@@ -3,7 +3,7 @@ import dotenv from "dotenv";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import os from "os";
|
|
5
5
|
import fs from "fs";
|
|
6
|
-
var isDev = process.env.NODE_ENV
|
|
6
|
+
var isDev = process.env.NODE_ENV === "dev";
|
|
7
7
|
function loadEnv() {
|
|
8
8
|
const candidates = isDev ? [
|
|
9
9
|
path.join(process.cwd(), ".env"),
|
|
@@ -24,9 +24,11 @@ function loadEnv() {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
loadEnv();
|
|
27
|
+
var DEFAULT_API_KEY_PLACEHOLDER = "your-api-key-here";
|
|
27
28
|
function checkEmbeddingEnv() {
|
|
28
29
|
const missingVars = [];
|
|
29
|
-
|
|
30
|
+
const apiKey = process.env.EMBEDDINGS_API_KEY;
|
|
31
|
+
if (!apiKey || apiKey === DEFAULT_API_KEY_PLACEHOLDER) {
|
|
30
32
|
missingVars.push("EMBEDDINGS_API_KEY");
|
|
31
33
|
}
|
|
32
34
|
if (!process.env.EMBEDDINGS_BASE_URL) {
|
|
@@ -42,7 +44,8 @@ function checkEmbeddingEnv() {
|
|
|
42
44
|
}
|
|
43
45
|
function checkRerankerEnv() {
|
|
44
46
|
const missingVars = [];
|
|
45
|
-
|
|
47
|
+
const apiKey = process.env.RERANK_API_KEY;
|
|
48
|
+
if (!apiKey || apiKey === DEFAULT_API_KEY_PLACEHOLDER) {
|
|
46
49
|
missingVars.push("RERANK_API_KEY");
|
|
47
50
|
}
|
|
48
51
|
if (!process.env.RERANK_BASE_URL) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generateProjectId,
|
|
3
3
|
logger
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NHKBCYHN.js";
|
|
5
5
|
|
|
6
6
|
// src/mcp/tools/codebaseRetrieval.ts
|
|
7
7
|
import { z } from "zod";
|
|
@@ -61,7 +61,7 @@ function isProjectIndexed(projectId) {
|
|
|
61
61
|
}
|
|
62
62
|
async function ensureIndexed(repoPath, projectId) {
|
|
63
63
|
const wasIndexed = isProjectIndexed(projectId);
|
|
64
|
-
const { scan } = await import("./scanner-
|
|
64
|
+
const { scan } = await import("./scanner-E52TXHEM.js");
|
|
65
65
|
if (!wasIndexed) {
|
|
66
66
|
logger.info({ repoPath, projectId: projectId.slice(0, 10) }, "\u4EE3\u7801\u5E93\u672A\u521D\u59CB\u5316\uFF0C\u5F00\u59CB\u9996\u6B21\u7D22\u5F15...");
|
|
67
67
|
} else {
|
|
@@ -88,7 +88,7 @@ async function handleCodebaseRetrieval(args, configOverride = ZEN_CONFIG_OVERRID
|
|
|
88
88
|
information_request,
|
|
89
89
|
technical_terms
|
|
90
90
|
}, "MCP codebase-retrieval \u8C03\u7528\u5F00\u59CB");
|
|
91
|
-
const { checkEmbeddingEnv, checkRerankerEnv } = await import("./config-
|
|
91
|
+
const { checkEmbeddingEnv, checkRerankerEnv } = await import("./config-BVORFWIO.js");
|
|
92
92
|
const embeddingCheck = checkEmbeddingEnv();
|
|
93
93
|
const rerankerCheck = checkRerankerEnv();
|
|
94
94
|
const allMissingVars = [...embeddingCheck.missingVars, ...rerankerCheck.missingVars];
|
|
@@ -108,7 +108,7 @@ async function handleCodebaseRetrieval(args, configOverride = ZEN_CONFIG_OVERRID
|
|
|
108
108
|
query,
|
|
109
109
|
zenConfig: configOverride
|
|
110
110
|
}, "MCP \u67E5\u8BE2\u6784\u5EFA");
|
|
111
|
-
const { SearchService } = await import("./SearchService-
|
|
111
|
+
const { SearchService } = await import("./SearchService-NM6J3XHC.js");
|
|
112
112
|
const service = new SearchService(projectId, repo_path, configOverride);
|
|
113
113
|
await service.init();
|
|
114
114
|
logger.debug("SearchService \u521D\u59CB\u5316\u5B8C\u6210");
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
closeAllIndexers,
|
|
3
3
|
closeAllVectorStores,
|
|
4
4
|
getIndexer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UWQSUTEL.js";
|
|
6
6
|
import {
|
|
7
7
|
batchDelete,
|
|
8
8
|
batchUpdateMtime,
|
|
@@ -17,11 +17,11 @@ import {
|
|
|
17
17
|
initDb,
|
|
18
18
|
logger,
|
|
19
19
|
setStoredEmbeddingDimensions
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-NHKBCYHN.js";
|
|
21
21
|
import {
|
|
22
22
|
getEmbeddingConfig,
|
|
23
23
|
getExcludePatterns
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-2HG4HNNX.js";
|
|
25
25
|
|
|
26
26
|
// src/scanner/crawler.ts
|
|
27
27
|
import { fdir } from "fdir";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDev
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2HG4HNNX.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/logger.ts
|
|
6
6
|
import pino from "pino";
|
|
@@ -85,19 +85,49 @@ function createFormattedStream(filePath) {
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
+
function createConsoleStream() {
|
|
89
|
+
const colors = {
|
|
90
|
+
10: "\x1B[90m",
|
|
91
|
+
// TRACE - 灰色
|
|
92
|
+
20: "\x1B[36m",
|
|
93
|
+
// DEBUG - 青色
|
|
94
|
+
30: "\x1B[32m",
|
|
95
|
+
// INFO - 绿色
|
|
96
|
+
40: "\x1B[33m",
|
|
97
|
+
// WARN - 黄色
|
|
98
|
+
50: "\x1B[31m",
|
|
99
|
+
// ERROR - 红色
|
|
100
|
+
60: "\x1B[35m"
|
|
101
|
+
// FATAL - 品红
|
|
102
|
+
};
|
|
103
|
+
const reset = "\x1B[0m";
|
|
104
|
+
return new Writable({
|
|
105
|
+
write(chunk, encoding, callback) {
|
|
106
|
+
try {
|
|
107
|
+
const log = JSON.parse(chunk.toString());
|
|
108
|
+
const time = formatTime();
|
|
109
|
+
const level = getLevelLabel(log.level);
|
|
110
|
+
const color = colors[log.level] || "";
|
|
111
|
+
const msg = log.msg || "";
|
|
112
|
+
const { level: _l, time: _t, pid: _p, hostname: _h, name: _n, msg: _m, ...extra } = log;
|
|
113
|
+
let line = `${color}${time} [${level}]${reset} ${msg}`;
|
|
114
|
+
if (Object.keys(extra).length > 0) {
|
|
115
|
+
const extraStr = JSON.stringify(extra);
|
|
116
|
+
line += ` ${color}${extraStr}${reset}`;
|
|
117
|
+
}
|
|
118
|
+
process.stdout.write(line + "\n", callback);
|
|
119
|
+
} catch {
|
|
120
|
+
process.stdout.write(chunk.toString(), callback);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
88
125
|
function createDevLogger() {
|
|
89
126
|
ensureLogDir(logDir);
|
|
90
127
|
cleanupOldLogs(logDir);
|
|
91
128
|
const logPath = path.join(logDir, getLogFileName());
|
|
92
129
|
const logStream = createFormattedStream(logPath);
|
|
93
|
-
const
|
|
94
|
-
target: "pino-pretty",
|
|
95
|
-
options: {
|
|
96
|
-
colorize: true,
|
|
97
|
-
translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
|
|
98
|
-
ignore: "pid,hostname"
|
|
99
|
-
}
|
|
100
|
-
});
|
|
130
|
+
const consoleStream = createConsoleStream();
|
|
101
131
|
return pino(
|
|
102
132
|
{
|
|
103
133
|
level: logLevel,
|
|
@@ -105,7 +135,7 @@ function createDevLogger() {
|
|
|
105
135
|
},
|
|
106
136
|
pino.multistream([
|
|
107
137
|
{ stream: logStream, level: logLevel },
|
|
108
|
-
{ stream:
|
|
138
|
+
{ stream: consoleStream, level: logLevel }
|
|
109
139
|
])
|
|
110
140
|
);
|
|
111
141
|
}
|
|
@@ -114,12 +144,16 @@ function createProdLogger() {
|
|
|
114
144
|
cleanupOldLogs(logDir);
|
|
115
145
|
const logPath = path.join(logDir, getLogFileName());
|
|
116
146
|
const logStream = createFormattedStream(logPath);
|
|
147
|
+
const consoleStream = createConsoleStream();
|
|
117
148
|
return pino(
|
|
118
149
|
{
|
|
119
150
|
level: logLevel,
|
|
120
151
|
name: "contextweaver"
|
|
121
152
|
},
|
|
122
|
-
|
|
153
|
+
pino.multistream([
|
|
154
|
+
{ stream: logStream, level: logLevel },
|
|
155
|
+
{ stream: consoleStream, level: logLevel }
|
|
156
|
+
])
|
|
123
157
|
);
|
|
124
158
|
}
|
|
125
159
|
var logger = isDev ? createDevLogger() : createProdLogger();
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
clearVectorIndexHash,
|
|
6
6
|
isChunksFtsInitialized,
|
|
7
7
|
logger
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NHKBCYHN.js";
|
|
9
9
|
import {
|
|
10
10
|
getEmbeddingConfig
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-2HG4HNNX.js";
|
|
12
12
|
|
|
13
13
|
// src/vectorStore/index.ts
|
|
14
14
|
import * as lancedb from "@lancedb/lancedb";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
codebaseRetrievalSchema,
|
|
3
3
|
handleCodebaseRetrieval
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-C7PBP6HL.js";
|
|
5
|
+
import "./chunk-NHKBCYHN.js";
|
|
6
|
+
import "./chunk-2HG4HNNX.js";
|
|
7
7
|
export {
|
|
8
8
|
codebaseRetrievalSchema,
|
|
9
9
|
handleCodebaseRetrieval
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
scan
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-JNMCEE3A.js";
|
|
5
|
+
import "./chunk-UWQSUTEL.js";
|
|
6
6
|
import {
|
|
7
7
|
generateProjectId,
|
|
8
8
|
logger
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-NHKBCYHN.js";
|
|
10
|
+
import "./chunk-2HG4HNNX.js";
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
import cac from "cac";
|
|
@@ -100,7 +100,7 @@ cli.command("index [path]", "\u626B\u63CF\u4EE3\u7801\u5E93\u5E76\u5EFA\u7ACB\u7
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
cli.command("mcp", "\u542F\u52A8 MCP \u670D\u52A1\u5668").action(async () => {
|
|
103
|
-
const { startMcpServer } = await import("./server-
|
|
103
|
+
const { startMcpServer } = await import("./server-Y4GFTGLG.js");
|
|
104
104
|
try {
|
|
105
105
|
await startMcpServer();
|
|
106
106
|
} catch (error) {
|
|
@@ -117,7 +117,7 @@ cli.command("search", "\u672C\u5730\u68C0\u7D22\uFF08\u53C2\u6570\u5BF9\u9F50 MC
|
|
|
117
117
|
}
|
|
118
118
|
const technicalTerms = (options.technicalTerms || "").split(",").map((t) => t.trim()).filter(Boolean);
|
|
119
119
|
const useZen = options.zen !== false;
|
|
120
|
-
const { handleCodebaseRetrieval } = await import("./codebaseRetrieval-
|
|
120
|
+
const { handleCodebaseRetrieval } = await import("./codebaseRetrieval-GPSIAFSZ.js");
|
|
121
121
|
const response = await handleCodebaseRetrieval({
|
|
122
122
|
repo_path: repoPath,
|
|
123
123
|
information_request: informationRequest,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
codebaseRetrievalSchema,
|
|
3
3
|
handleCodebaseRetrieval
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C7PBP6HL.js";
|
|
5
5
|
import {
|
|
6
6
|
logger
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-NHKBCYHN.js";
|
|
8
|
+
import "./chunk-2HG4HNNX.js";
|
|
9
9
|
|
|
10
10
|
// src/mcp/server.ts
|
|
11
11
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
ListToolsRequestSchema
|
|
16
16
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
17
17
|
var SERVER_NAME = "contextweaver";
|
|
18
|
-
var SERVER_VERSION = "0.1.0";
|
|
19
18
|
var TOOLS = [
|
|
20
19
|
{
|
|
21
20
|
name: "codebase-retrieval",
|
|
@@ -81,11 +80,11 @@ Examples of BAD queries:
|
|
|
81
80
|
}
|
|
82
81
|
];
|
|
83
82
|
async function startMcpServer() {
|
|
84
|
-
logger.info({ name: SERVER_NAME
|
|
83
|
+
logger.info({ name: SERVER_NAME }, "\u542F\u52A8 MCP \u670D\u52A1\u5668");
|
|
85
84
|
const server = new Server(
|
|
86
85
|
{
|
|
87
86
|
name: SERVER_NAME,
|
|
88
|
-
version:
|
|
87
|
+
version: "1.0.0"
|
|
89
88
|
},
|
|
90
89
|
{
|
|
91
90
|
capabilities: {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hsingjui/contextweaver",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A context weaving tool for LLMs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "hsingjui",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/hsingjui/
|
|
9
|
+
"url": "git+https://github.com/hsingjui/ContextWeaver.git"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/hsingjui/
|
|
11
|
+
"homepage": "https://github.com/hsingjui/ContextWeaver#readme",
|
|
12
12
|
"private": false,
|
|
13
13
|
"type": "module",
|
|
14
14
|
"bin": {
|
|
@@ -22,6 +22,12 @@
|
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --sourcemap --clean",
|
|
27
|
+
"build:release": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --clean",
|
|
28
|
+
"dev": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --sourcemap --watch",
|
|
29
|
+
"start": "node dist/index.js"
|
|
30
|
+
},
|
|
25
31
|
"dependencies": {
|
|
26
32
|
"@lancedb/lancedb": "^0.19.1",
|
|
27
33
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
@@ -46,14 +52,20 @@
|
|
|
46
52
|
"devDependencies": {
|
|
47
53
|
"@types/better-sqlite3": "^7.6.13",
|
|
48
54
|
"@types/node": "^25.0.3",
|
|
49
|
-
"pino-pretty": "^13.1.3",
|
|
50
55
|
"tsup": "^8.5.1",
|
|
51
56
|
"typescript": "^5.9.3"
|
|
52
57
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
"pnpm": {
|
|
59
|
+
"onlyBuiltDependencies": [
|
|
60
|
+
"better-sqlite3",
|
|
61
|
+
"esbuild",
|
|
62
|
+
"tree-sitter",
|
|
63
|
+
"tree-sitter-go",
|
|
64
|
+
"tree-sitter-java",
|
|
65
|
+
"tree-sitter-javascript",
|
|
66
|
+
"tree-sitter-python",
|
|
67
|
+
"tree-sitter-rust",
|
|
68
|
+
"tree-sitter-typescript"
|
|
69
|
+
]
|
|
58
70
|
}
|
|
59
|
-
}
|
|
71
|
+
}
|