@hsingjui/contextweaver 0.0.1 → 0.0.3

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 CHANGED
@@ -51,10 +51,10 @@
51
51
 
52
52
  ```bash
53
53
  # 全局安装
54
- npm install -g contextweaver
54
+ npm install -g @hsingjui/contextweaver
55
55
 
56
56
  # 或使用 pnpm
57
- pnpm add -g contextweaver
57
+ pnpm add -g @hsingjui/contextweaver
58
58
  ```
59
59
 
60
60
  ### 初始化配置
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getIndexer,
3
3
  getVectorStore
4
- } from "./chunk-6C2D5Y4R.js";
4
+ } from "./chunk-RU4OUBZS.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-5SRSUMKW.js";
14
+ } from "./chunk-AVBQ77MN.js";
15
15
  import {
16
16
  getEmbeddingConfig,
17
17
  getRerankerConfig
18
- } from "./chunk-PN7DP6XL.js";
18
+ } from "./chunk-ESTPBFCW.js";
19
19
 
20
20
  // src/api/reranker.ts
21
21
  var RerankerClient = class {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateProjectId,
3
3
  logger
4
- } from "./chunk-5SRSUMKW.js";
4
+ } from "./chunk-AVBQ77MN.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-66CLKCSZ.js");
64
+ const { scan } = await import("./scanner-CXUYLK56.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-IEL3M4V5.js");
91
+ const { checkEmbeddingEnv, checkRerankerEnv } = await import("./config-BQCFTZVY.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-YLOUJF4S.js");
111
+ const { SearchService } = await import("./SearchService-CMHVTNSM.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");
@@ -1,6 +1,7 @@
1
1
  import {
2
- isDev
3
- } from "./chunk-PN7DP6XL.js";
2
+ isDev,
3
+ isMcpMode
4
+ } from "./chunk-ESTPBFCW.js";
4
5
 
5
6
  // src/utils/logger.ts
6
7
  import pino from "pino";
@@ -54,7 +55,7 @@ function cleanupOldLogs(dir) {
54
55
  const filePath = path.join(dir, file);
55
56
  try {
56
57
  fs.unlinkSync(filePath);
57
- console.log(`[Logger] \u6E05\u7406\u8FC7\u671F\u65E5\u5FD7: ${file}`);
58
+ console.error(`[Logger] \u6E05\u7406\u8FC7\u671F\u65E5\u5FD7: ${file}`);
58
59
  } catch {
59
60
  }
60
61
  }
@@ -85,27 +86,58 @@ function createFormattedStream(filePath) {
85
86
  }
86
87
  });
87
88
  }
89
+ function createConsoleStream() {
90
+ const colors = {
91
+ 10: "\x1B[90m",
92
+ // TRACE - 灰色
93
+ 20: "\x1B[36m",
94
+ // DEBUG - 青色
95
+ 30: "\x1B[32m",
96
+ // INFO - 绿色
97
+ 40: "\x1B[33m",
98
+ // WARN - 黄色
99
+ 50: "\x1B[31m",
100
+ // ERROR - 红色
101
+ 60: "\x1B[35m"
102
+ // FATAL - 品红
103
+ };
104
+ const reset = "\x1B[0m";
105
+ return new Writable({
106
+ write(chunk, encoding, callback) {
107
+ try {
108
+ const log = JSON.parse(chunk.toString());
109
+ const time = formatTime();
110
+ const level = getLevelLabel(log.level);
111
+ const color = colors[log.level] || "";
112
+ const msg = log.msg || "";
113
+ const { level: _l, time: _t, pid: _p, hostname: _h, name: _n, msg: _m, ...extra } = log;
114
+ let line = `${color}${time} [${level}]${reset} ${msg}`;
115
+ if (Object.keys(extra).length > 0) {
116
+ const extraStr = JSON.stringify(extra);
117
+ line += ` ${color}${extraStr}${reset}`;
118
+ }
119
+ process.stdout.write(line + "\n", callback);
120
+ } catch {
121
+ process.stdout.write(chunk.toString(), callback);
122
+ }
123
+ }
124
+ });
125
+ }
88
126
  function createDevLogger() {
89
127
  ensureLogDir(logDir);
90
128
  cleanupOldLogs(logDir);
91
129
  const logPath = path.join(logDir, getLogFileName());
92
130
  const logStream = createFormattedStream(logPath);
93
- const consoleTransport = pino.transport({
94
- target: "pino-pretty",
95
- options: {
96
- colorize: true,
97
- translateTime: "SYS:yyyy-mm-dd HH:MM:ss",
98
- ignore: "pid,hostname"
99
- }
100
- });
131
+ const consoleStream = createConsoleStream();
101
132
  return pino(
102
133
  {
103
134
  level: logLevel,
104
135
  name: "contextweaver"
105
136
  },
106
- pino.multistream([
137
+ // MCP 模式下禁用控制台输出,避免污染 STDIO 协议流
138
+ isMcpMode ? logStream : pino.multistream([
107
139
  { stream: logStream, level: logLevel },
108
- { stream: consoleTransport, level: logLevel }
140
+ { stream: consoleStream, level: logLevel }
109
141
  ])
110
142
  );
111
143
  }
@@ -114,12 +146,17 @@ function createProdLogger() {
114
146
  cleanupOldLogs(logDir);
115
147
  const logPath = path.join(logDir, getLogFileName());
116
148
  const logStream = createFormattedStream(logPath);
149
+ const consoleStream = createConsoleStream();
117
150
  return pino(
118
151
  {
119
152
  level: logLevel,
120
153
  name: "contextweaver"
121
154
  },
122
- logStream
155
+ // MCP 模式下禁用控制台输出,避免污染 STDIO 协议流
156
+ isMcpMode ? logStream : pino.multistream([
157
+ { stream: logStream, level: logLevel },
158
+ { stream: consoleStream, level: logLevel }
159
+ ])
123
160
  );
124
161
  }
125
162
  var logger = isDev ? createDevLogger() : createProdLogger();
@@ -3,7 +3,8 @@ 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 !== "dev";
6
+ var isDev = process.env.NODE_ENV === "dev";
7
+ var isMcpMode = process.argv.includes("mcp");
7
8
  function loadEnv() {
8
9
  const candidates = isDev ? [
9
10
  path.join(process.cwd(), ".env"),
@@ -24,9 +25,11 @@ function loadEnv() {
24
25
  }
25
26
  }
26
27
  loadEnv();
28
+ var DEFAULT_API_KEY_PLACEHOLDER = "your-api-key-here";
27
29
  function checkEmbeddingEnv() {
28
30
  const missingVars = [];
29
- if (!process.env.EMBEDDINGS_API_KEY) {
31
+ const apiKey = process.env.EMBEDDINGS_API_KEY;
32
+ if (!apiKey || apiKey === DEFAULT_API_KEY_PLACEHOLDER) {
30
33
  missingVars.push("EMBEDDINGS_API_KEY");
31
34
  }
32
35
  if (!process.env.EMBEDDINGS_BASE_URL) {
@@ -42,7 +45,8 @@ function checkEmbeddingEnv() {
42
45
  }
43
46
  function checkRerankerEnv() {
44
47
  const missingVars = [];
45
- if (!process.env.RERANK_API_KEY) {
48
+ const apiKey = process.env.RERANK_API_KEY;
49
+ if (!apiKey || apiKey === DEFAULT_API_KEY_PLACEHOLDER) {
46
50
  missingVars.push("RERANK_API_KEY");
47
51
  }
48
52
  if (!process.env.RERANK_BASE_URL) {
@@ -149,6 +153,7 @@ function getExcludePatterns() {
149
153
 
150
154
  export {
151
155
  isDev,
156
+ isMcpMode,
152
157
  checkEmbeddingEnv,
153
158
  checkRerankerEnv,
154
159
  getEmbeddingConfig,
@@ -2,7 +2,7 @@ import {
2
2
  closeAllIndexers,
3
3
  closeAllVectorStores,
4
4
  getIndexer
5
- } from "./chunk-6C2D5Y4R.js";
5
+ } from "./chunk-RU4OUBZS.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-5SRSUMKW.js";
20
+ } from "./chunk-AVBQ77MN.js";
21
21
  import {
22
22
  getEmbeddingConfig,
23
23
  getExcludePatterns
24
- } from "./chunk-PN7DP6XL.js";
24
+ } from "./chunk-ESTPBFCW.js";
25
25
 
26
26
  // src/scanner/crawler.ts
27
27
  import { fdir } from "fdir";
@@ -5,10 +5,10 @@ import {
5
5
  clearVectorIndexHash,
6
6
  isChunksFtsInitialized,
7
7
  logger
8
- } from "./chunk-5SRSUMKW.js";
8
+ } from "./chunk-AVBQ77MN.js";
9
9
  import {
10
10
  getEmbeddingConfig
11
- } from "./chunk-PN7DP6XL.js";
11
+ } from "./chunk-ESTPBFCW.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-5TV4JNTE.js";
5
- import "./chunk-5SRSUMKW.js";
6
- import "./chunk-PN7DP6XL.js";
4
+ } from "./chunk-4XOWK7YZ.js";
5
+ import "./chunk-AVBQ77MN.js";
6
+ import "./chunk-ESTPBFCW.js";
7
7
  export {
8
8
  codebaseRetrievalSchema,
9
9
  handleCodebaseRetrieval
@@ -5,8 +5,9 @@ import {
5
5
  getEmbeddingConfig,
6
6
  getExcludePatterns,
7
7
  getRerankerConfig,
8
- isDev
9
- } from "./chunk-PN7DP6XL.js";
8
+ isDev,
9
+ isMcpMode
10
+ } from "./chunk-ESTPBFCW.js";
10
11
  export {
11
12
  DEFAULT_EXCLUDE_PATTERNS,
12
13
  checkEmbeddingEnv,
@@ -14,5 +15,6 @@ export {
14
15
  getEmbeddingConfig,
15
16
  getExcludePatterns,
16
17
  getRerankerConfig,
17
- isDev
18
+ isDev,
19
+ isMcpMode
18
20
  };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  scan
4
- } from "./chunk-34YZ2U3O.js";
5
- import "./chunk-6C2D5Y4R.js";
4
+ } from "./chunk-NHQE2IOY.js";
5
+ import "./chunk-RU4OUBZS.js";
6
6
  import {
7
7
  generateProjectId,
8
8
  logger
9
- } from "./chunk-5SRSUMKW.js";
10
- import "./chunk-PN7DP6XL.js";
9
+ } from "./chunk-AVBQ77MN.js";
10
+ import "./chunk-ESTPBFCW.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-2SAFEAEY.js");
103
+ const { startMcpServer } = await import("./server-LC4NWEGV.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-RDCNIUDM.js");
120
+ const { handleCodebaseRetrieval } = await import("./codebaseRetrieval-NLSYDBF4.js");
121
121
  const response = await handleCodebaseRetrieval({
122
122
  repo_path: repoPath,
123
123
  information_request: informationRequest,
@@ -0,0 +1,9 @@
1
+ import {
2
+ scan
3
+ } from "./chunk-NHQE2IOY.js";
4
+ import "./chunk-RU4OUBZS.js";
5
+ import "./chunk-AVBQ77MN.js";
6
+ import "./chunk-ESTPBFCW.js";
7
+ export {
8
+ scan
9
+ };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  codebaseRetrievalSchema,
3
3
  handleCodebaseRetrieval
4
- } from "./chunk-5TV4JNTE.js";
4
+ } from "./chunk-4XOWK7YZ.js";
5
5
  import {
6
6
  logger
7
- } from "./chunk-5SRSUMKW.js";
8
- import "./chunk-PN7DP6XL.js";
7
+ } from "./chunk-AVBQ77MN.js";
8
+ import "./chunk-ESTPBFCW.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, version: SERVER_VERSION }, "\u542F\u52A8 MCP \u670D\u52A1\u5668");
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: SERVER_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.1",
3
+ "version": "0.0.3",
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/contextweaver.git"
9
+ "url": "git+https://github.com/hsingjui/ContextWeaver.git"
10
10
  },
11
- "homepage": "https://github.com/hsingjui/contextweaver#readme",
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
- "scripts": {
54
- "build": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --sourcemap --clean",
55
- "build:release": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --clean",
56
- "dev": "tsup src/index.ts src/mcp/main.ts --format esm --dts --out-dir dist --sourcemap --watch",
57
- "start": "node dist/index.js"
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
+ }
@@ -1,9 +0,0 @@
1
- import {
2
- scan
3
- } from "./chunk-34YZ2U3O.js";
4
- import "./chunk-6C2D5Y4R.js";
5
- import "./chunk-5SRSUMKW.js";
6
- import "./chunk-PN7DP6XL.js";
7
- export {
8
- scan
9
- };