abb-opencode-local-rag 0.1.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 +21 -0
- package/README.de.md +416 -0
- package/README.es.md +416 -0
- package/README.fr.md +416 -0
- package/README.md +491 -0
- package/README.pt-BR.md +416 -0
- package/README.zh-CN.md +416 -0
- package/dist/bin/install-skills.d.ts +20 -0
- package/dist/bin/install-skills.d.ts.map +1 -0
- package/dist/bin/install-skills.js +195 -0
- package/dist/bin/install-skills.js.map +1 -0
- package/dist/chunker/index.d.ts +24 -0
- package/dist/chunker/index.d.ts.map +1 -0
- package/dist/chunker/index.js +2 -0
- package/dist/chunker/index.js.map +1 -0
- package/dist/chunker/semantic-chunker.d.ts +97 -0
- package/dist/chunker/semantic-chunker.d.ts.map +1 -0
- package/dist/chunker/semantic-chunker.js +294 -0
- package/dist/chunker/semantic-chunker.js.map +1 -0
- package/dist/chunker/sentence-splitter.d.ts +28 -0
- package/dist/chunker/sentence-splitter.d.ts.map +1 -0
- package/dist/chunker/sentence-splitter.js +219 -0
- package/dist/chunker/sentence-splitter.js.map +1 -0
- package/dist/cli/common.d.ts +65 -0
- package/dist/cli/common.d.ts.map +1 -0
- package/dist/cli/common.js +138 -0
- package/dist/cli/common.js.map +1 -0
- package/dist/cli/delete.d.ts +8 -0
- package/dist/cli/delete.d.ts.map +1 -0
- package/dist/cli/delete.js +173 -0
- package/dist/cli/delete.js.map +1 -0
- package/dist/cli/file-collection.d.ts +2 -0
- package/dist/cli/file-collection.d.ts.map +1 -0
- package/dist/cli/file-collection.js +53 -0
- package/dist/cli/file-collection.js.map +1 -0
- package/dist/cli/ingest.d.ts +100 -0
- package/dist/cli/ingest.d.ts.map +1 -0
- package/dist/cli/ingest.js +363 -0
- package/dist/cli/ingest.js.map +1 -0
- package/dist/cli/list.d.ts +35 -0
- package/dist/cli/list.d.ts.map +1 -0
- package/dist/cli/list.js +210 -0
- package/dist/cli/list.js.map +1 -0
- package/dist/cli/options.d.ts +100 -0
- package/dist/cli/options.d.ts.map +1 -0
- package/dist/cli/options.js +241 -0
- package/dist/cli/options.js.map +1 -0
- package/dist/cli/query.d.ts +24 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +191 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/read-neighbors.d.ts +11 -0
- package/dist/cli/read-neighbors.d.ts.map +1 -0
- package/dist/cli/read-neighbors.js +224 -0
- package/dist/cli/read-neighbors.js.map +1 -0
- package/dist/cli/status.d.ts +8 -0
- package/dist/cli/status.d.ts.map +1 -0
- package/dist/cli/status.js +80 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/sync.d.ts +8 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +244 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/cli-main.d.ts +12 -0
- package/dist/cli-main.d.ts.map +1 -0
- package/dist/cli-main.js +63 -0
- package/dist/cli-main.js.map +1 -0
- package/dist/embedder/index.d.ts +85 -0
- package/dist/embedder/index.d.ts.map +1 -0
- package/dist/embedder/index.js +284 -0
- package/dist/embedder/index.js.map +1 -0
- package/dist/features/list.d.ts +37 -0
- package/dist/features/list.d.ts.map +1 -0
- package/dist/features/list.js +40 -0
- package/dist/features/list.js.map +1 -0
- package/dist/features/sync.d.ts +207 -0
- package/dist/features/sync.d.ts.map +1 -0
- package/dist/features/sync.js +380 -0
- package/dist/features/sync.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/compute.d.ts +86 -0
- package/dist/ingest/compute.d.ts.map +1 -0
- package/dist/ingest/compute.js +177 -0
- package/dist/ingest/compute.js.map +1 -0
- package/dist/ingest/file.d.ts +27 -0
- package/dist/ingest/file.d.ts.map +1 -0
- package/dist/ingest/file.js +67 -0
- package/dist/ingest/file.js.map +1 -0
- package/dist/ingest/visual.d.ts +45 -0
- package/dist/ingest/visual.d.ts.map +1 -0
- package/dist/ingest/visual.js +234 -0
- package/dist/ingest/visual.js.map +1 -0
- package/dist/parser/docx-parser.d.ts +12 -0
- package/dist/parser/docx-parser.d.ts.map +1 -0
- package/dist/parser/docx-parser.js +328 -0
- package/dist/parser/docx-parser.js.map +1 -0
- package/dist/parser/html-parser.d.ts +18 -0
- package/dist/parser/html-parser.d.ts.map +1 -0
- package/dist/parser/html-parser.js +102 -0
- package/dist/parser/html-parser.js.map +1 -0
- package/dist/parser/index.d.ts +214 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +454 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/pdf-extract.d.ts +81 -0
- package/dist/parser/pdf-extract.d.ts.map +1 -0
- package/dist/parser/pdf-extract.js +112 -0
- package/dist/parser/pdf-extract.js.map +1 -0
- package/dist/parser/pdf-filter.d.ts +117 -0
- package/dist/parser/pdf-filter.d.ts.map +1 -0
- package/dist/parser/pdf-filter.js +528 -0
- package/dist/parser/pdf-filter.js.map +1 -0
- package/dist/parser/title-extractor.d.ts +69 -0
- package/dist/parser/title-extractor.d.ts.map +1 -0
- package/dist/parser/title-extractor.js +145 -0
- package/dist/parser/title-extractor.js.map +1 -0
- package/dist/pdf-visual/captioner.d.ts +16 -0
- package/dist/pdf-visual/captioner.d.ts.map +1 -0
- package/dist/pdf-visual/captioner.js +63 -0
- package/dist/pdf-visual/captioner.js.map +1 -0
- package/dist/pdf-visual/captioners/fast.d.ts +7 -0
- package/dist/pdf-visual/captioners/fast.d.ts.map +1 -0
- package/dist/pdf-visual/captioners/fast.js +103 -0
- package/dist/pdf-visual/captioners/fast.js.map +1 -0
- package/dist/pdf-visual/captioners/quality.d.ts +7 -0
- package/dist/pdf-visual/captioners/quality.d.ts.map +1 -0
- package/dist/pdf-visual/captioners/quality.js +127 -0
- package/dist/pdf-visual/captioners/quality.js.map +1 -0
- package/dist/pdf-visual/captioners/shared.d.ts +44 -0
- package/dist/pdf-visual/captioners/shared.d.ts.map +1 -0
- package/dist/pdf-visual/captioners/shared.js +104 -0
- package/dist/pdf-visual/captioners/shared.js.map +1 -0
- package/dist/pdf-visual/detector.d.ts +9 -0
- package/dist/pdf-visual/detector.d.ts.map +1 -0
- package/dist/pdf-visual/detector.js +234 -0
- package/dist/pdf-visual/detector.js.map +1 -0
- package/dist/pdf-visual/index.d.ts +13 -0
- package/dist/pdf-visual/index.d.ts.map +1 -0
- package/dist/pdf-visual/index.js +45 -0
- package/dist/pdf-visual/index.js.map +1 -0
- package/dist/pdf-visual/renderer.d.ts +9 -0
- package/dist/pdf-visual/renderer.d.ts.map +1 -0
- package/dist/pdf-visual/renderer.js +177 -0
- package/dist/pdf-visual/renderer.js.map +1 -0
- package/dist/pdf-visual/types.d.ts +62 -0
- package/dist/pdf-visual/types.d.ts.map +1 -0
- package/dist/pdf-visual/types.js +32 -0
- package/dist/pdf-visual/types.js.map +1 -0
- package/dist/server/error-utils.d.ts +79 -0
- package/dist/server/error-utils.d.ts.map +1 -0
- package/dist/server/error-utils.js +148 -0
- package/dist/server/error-utils.js.map +1 -0
- package/dist/server/index.d.ts +258 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +1104 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/list-scanner.d.ts +52 -0
- package/dist/server/list-scanner.d.ts.map +1 -0
- package/dist/server/list-scanner.js +72 -0
- package/dist/server/list-scanner.js.map +1 -0
- package/dist/server/tool-definitions.d.ts +8 -0
- package/dist/server/tool-definitions.d.ts.map +1 -0
- package/dist/server/tool-definitions.js +181 -0
- package/dist/server/tool-definitions.js.map +1 -0
- package/dist/server/tool-input.d.ts +37 -0
- package/dist/server/tool-input.d.ts.map +1 -0
- package/dist/server/tool-input.js +216 -0
- package/dist/server/tool-input.js.map +1 -0
- package/dist/server/types.d.ts +331 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +3 -0
- package/dist/server/types.js.map +1 -0
- package/dist/server-main.d.ts +46 -0
- package/dist/server-main.d.ts.map +1 -0
- package/dist/server-main.js +242 -0
- package/dist/server-main.js.map +1 -0
- package/dist/utils/base-dirs.d.ts +212 -0
- package/dist/utils/base-dirs.d.ts.map +1 -0
- package/dist/utils/base-dirs.js +422 -0
- package/dist/utils/base-dirs.js.map +1 -0
- package/dist/utils/errors.d.ts +24 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +53 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/limits.d.ts +26 -0
- package/dist/utils/limits.d.ts.map +1 -0
- package/dist/utils/limits.js +28 -0
- package/dist/utils/limits.js.map +1 -0
- package/dist/utils/list-sources.d.ts +47 -0
- package/dist/utils/list-sources.d.ts.map +1 -0
- package/dist/utils/list-sources.js +50 -0
- package/dist/utils/list-sources.js.map +1 -0
- package/dist/utils/raw-data-utils.d.ts +131 -0
- package/dist/utils/raw-data-utils.d.ts.map +1 -0
- package/dist/utils/raw-data-utils.js +255 -0
- package/dist/utils/raw-data-utils.js.map +1 -0
- package/dist/utils/scan.d.ts +126 -0
- package/dist/utils/scan.d.ts.map +1 -0
- package/dist/utils/scan.js +221 -0
- package/dist/utils/scan.js.map +1 -0
- package/dist/utils/scope-match.d.ts +43 -0
- package/dist/utils/scope-match.d.ts.map +1 -0
- package/dist/utils/scope-match.js +87 -0
- package/dist/utils/scope-match.js.map +1 -0
- package/dist/utils/sensitive-path.d.ts +23 -0
- package/dist/utils/sensitive-path.d.ts.map +1 -0
- package/dist/utils/sensitive-path.js +91 -0
- package/dist/utils/sensitive-path.js.map +1 -0
- package/dist/utils/sync-path-key.d.ts +20 -0
- package/dist/utils/sync-path-key.d.ts.map +1 -0
- package/dist/utils/sync-path-key.js +33 -0
- package/dist/utils/sync-path-key.js.map +1 -0
- package/dist/vectordb/index.d.ts +168 -0
- package/dist/vectordb/index.d.ts.map +1 -0
- package/dist/vectordb/index.js +619 -0
- package/dist/vectordb/index.js.map +1 -0
- package/dist/vectordb/search-filters.d.ts +39 -0
- package/dist/vectordb/search-filters.d.ts.map +1 -0
- package/dist/vectordb/search-filters.js +136 -0
- package/dist/vectordb/search-filters.js.map +1 -0
- package/dist/vectordb/types.d.ts +196 -0
- package/dist/vectordb/types.d.ts.map +1 -0
- package/dist/vectordb/types.js +224 -0
- package/dist/vectordb/types.js.map +1 -0
- package/package.json +105 -0
- package/skills/mcp-local-rag/SKILL.md +308 -0
- package/skills/mcp-local-rag/references/cli-reference.md +175 -0
- package/skills/mcp-local-rag/references/html-ingestion.md +78 -0
- package/skills/mcp-local-rag/references/query-optimization.md +57 -0
- package/skills/mcp-local-rag/references/result-refinement.md +56 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// MCP Server entry point
|
|
2
|
+
import { resolveDevice, resolveDtype } from './cli/options.js';
|
|
3
|
+
import { RAGServer } from './server/index.js';
|
|
4
|
+
import { BaseDirsConfigError, parseBaseDirsEnv, resolveBaseDirs } from './utils/base-dirs.js';
|
|
5
|
+
import { DEFAULT_MAX_FILE_SIZE, MAX_CHUNK_MIN_LENGTH } from './utils/limits.js';
|
|
6
|
+
import { checkSensitivePath } from './utils/sensitive-path.js';
|
|
7
|
+
/**
|
|
8
|
+
* Parse grouping mode from environment variable
|
|
9
|
+
*/
|
|
10
|
+
export function parseGroupingMode(value) {
|
|
11
|
+
if (!value)
|
|
12
|
+
return { value: undefined };
|
|
13
|
+
const normalized = value.toLowerCase().trim();
|
|
14
|
+
if (normalized === 'similar' || normalized === 'related') {
|
|
15
|
+
return { value: normalized };
|
|
16
|
+
}
|
|
17
|
+
const warning = `Invalid RAG_GROUPING value: "${value.slice(0, 100)}". Expected "similar" or "related". Ignoring.`;
|
|
18
|
+
return { value: undefined, warning };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse max distance from environment variable
|
|
22
|
+
*/
|
|
23
|
+
export function parseMaxDistance(value) {
|
|
24
|
+
if (!value)
|
|
25
|
+
return { value: undefined };
|
|
26
|
+
const parsed = Number.parseFloat(value);
|
|
27
|
+
if (Number.isNaN(parsed) || parsed <= 0 || !Number.isFinite(parsed)) {
|
|
28
|
+
const warning = `Invalid RAG_MAX_DISTANCE value: "${value.slice(0, 100)}". Expected positive number. Ignoring.`;
|
|
29
|
+
return { value: undefined, warning };
|
|
30
|
+
}
|
|
31
|
+
return { value: parsed };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse max files from environment variable
|
|
35
|
+
*/
|
|
36
|
+
export function parseMaxFiles(value) {
|
|
37
|
+
if (!value)
|
|
38
|
+
return { value: undefined };
|
|
39
|
+
const parsed = Number.parseInt(value, 10);
|
|
40
|
+
if (Number.isNaN(parsed) || parsed < 1) {
|
|
41
|
+
const warning = `Invalid RAG_MAX_FILES value: "${value.slice(0, 100)}". Expected positive integer (>= 1). Ignoring.`;
|
|
42
|
+
return { value: undefined, warning };
|
|
43
|
+
}
|
|
44
|
+
return { value: parsed };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse hybrid weight from environment variable
|
|
48
|
+
*/
|
|
49
|
+
export function parseHybridWeight(value) {
|
|
50
|
+
if (!value)
|
|
51
|
+
return { value: undefined };
|
|
52
|
+
const parsed = Number.parseFloat(value);
|
|
53
|
+
if (Number.isNaN(parsed) || parsed < 0 || parsed > 1) {
|
|
54
|
+
const warning = `Invalid RAG_HYBRID_WEIGHT value: "${value.slice(0, 100)}". Expected 0.0-1.0. Using default (0.6).`;
|
|
55
|
+
return { value: undefined, warning };
|
|
56
|
+
}
|
|
57
|
+
return { value: parsed };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse chunk minimum length from environment variable
|
|
61
|
+
*/
|
|
62
|
+
export function parseChunkMinLength(value) {
|
|
63
|
+
if (!value)
|
|
64
|
+
return { value: undefined };
|
|
65
|
+
const parsed = Number.parseInt(value, 10);
|
|
66
|
+
if (Number.isNaN(parsed) || parsed < 1 || parsed > MAX_CHUNK_MIN_LENGTH) {
|
|
67
|
+
const warning = `Invalid CHUNK_MIN_LENGTH value: "${value.slice(0, 100)}". Expected integer between 1 and ${MAX_CHUNK_MIN_LENGTH}. Ignoring.`;
|
|
68
|
+
return { value: undefined, warning };
|
|
69
|
+
}
|
|
70
|
+
return { value: parsed };
|
|
71
|
+
}
|
|
72
|
+
/** Parse the independent PDF image-storage toggle. */
|
|
73
|
+
export function parseStoreImages(value) {
|
|
74
|
+
const normalized = value?.trim().toLowerCase() ?? '';
|
|
75
|
+
if (normalized.length === 0)
|
|
76
|
+
return { value: false };
|
|
77
|
+
if (['1', 'true', 'yes', 'on'].includes(normalized))
|
|
78
|
+
return { value: true };
|
|
79
|
+
if (['0', 'false', 'no', 'off'].includes(normalized))
|
|
80
|
+
return { value: false };
|
|
81
|
+
return {
|
|
82
|
+
value: false,
|
|
83
|
+
warning: `Invalid STORE_IMAGES value: "${value?.slice(0, 100)}". Expected one of 1, true, yes, on, 0, false, no, or off. Using false.`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// ============================================
|
|
87
|
+
// Server Startup
|
|
88
|
+
// ============================================
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the full RAGServer configuration from environment variables.
|
|
91
|
+
*
|
|
92
|
+
* Pure (no process.exit, no transport): `env` and `cwd` are passed in so the
|
|
93
|
+
* entry-point wiring can be exercised directly in tests instead of via a copy.
|
|
94
|
+
* Single source of truth for BASE_DIRS / BASE_DIR / cwd precedence, the
|
|
95
|
+
* sensitive-path policy on both raw and realpath-normalized roots, and the
|
|
96
|
+
* never-fall-back-to-cwd-on-error rule.
|
|
97
|
+
*/
|
|
98
|
+
export async function resolveServerConfig(env, cwd) {
|
|
99
|
+
const device = resolveDevice(env['RAG_DEVICE']);
|
|
100
|
+
// Undefined when RAG_DTYPE is unset — threaded into config only when defined
|
|
101
|
+
// (see below), preserving the unset signal for the embedder's fp32 default.
|
|
102
|
+
const dtype = resolveDtype(env['RAG_DTYPE']);
|
|
103
|
+
const configWarnings = [];
|
|
104
|
+
// Sensitive-path pre-check on the RAW user-supplied paths, before the
|
|
105
|
+
// resolver realpath-normalizes them (on macOS `/etc` → `/private/etc`, which
|
|
106
|
+
// a post-realpath-only check would miss).
|
|
107
|
+
const rawSensitiveErrors = [];
|
|
108
|
+
if (env['BASE_DIRS'] !== undefined && env['BASE_DIRS'].length > 0) {
|
|
109
|
+
const parsed = parseBaseDirsEnv(env['BASE_DIRS']);
|
|
110
|
+
if (parsed.ok) {
|
|
111
|
+
for (const raw of parsed.value) {
|
|
112
|
+
const sensitive = checkSensitivePath(raw, 'BASE_DIRS');
|
|
113
|
+
if (sensitive)
|
|
114
|
+
rawSensitiveErrors.push(sensitive);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (env['BASE_DIR'] !== undefined && env['BASE_DIR'].trim().length > 0) {
|
|
119
|
+
const sensitive = checkSensitivePath(env['BASE_DIR'], 'BASE_DIR');
|
|
120
|
+
if (sensitive)
|
|
121
|
+
rawSensitiveErrors.push(sensitive);
|
|
122
|
+
}
|
|
123
|
+
const baseDirsResult = await resolveBaseDirs({
|
|
124
|
+
envBaseDirs: env['BASE_DIRS'],
|
|
125
|
+
envBaseDir: env['BASE_DIR'],
|
|
126
|
+
cwd,
|
|
127
|
+
});
|
|
128
|
+
let baseDirsForServer;
|
|
129
|
+
// Normal-path roots, index-aligned with baseDirsForServer, for list_files
|
|
130
|
+
// scan/display (see BaseDirsConfig for the path policy).
|
|
131
|
+
let rawBaseDirsForServer;
|
|
132
|
+
let configError;
|
|
133
|
+
// Raw sensitive-path matches take precedence over resolver errors.
|
|
134
|
+
if (rawSensitiveErrors.length > 0) {
|
|
135
|
+
baseDirsForServer = [];
|
|
136
|
+
rawBaseDirsForServer = [];
|
|
137
|
+
configError = new BaseDirsConfigError([...new Set(rawSensitiveErrors)].join('; '));
|
|
138
|
+
configWarnings.push(configError.message);
|
|
139
|
+
}
|
|
140
|
+
else if (baseDirsResult.ok) {
|
|
141
|
+
const sourceFlag = env['BASE_DIRS'] !== undefined && env['BASE_DIRS'].length > 0 ? 'BASE_DIRS' : 'BASE_DIR';
|
|
142
|
+
const sensitiveErrors = [];
|
|
143
|
+
for (const root of baseDirsResult.config.baseDirs) {
|
|
144
|
+
const sensitive = checkSensitivePath(root, sourceFlag);
|
|
145
|
+
if (sensitive)
|
|
146
|
+
sensitiveErrors.push(sensitive);
|
|
147
|
+
}
|
|
148
|
+
if (sensitiveErrors.length > 0) {
|
|
149
|
+
baseDirsForServer = [];
|
|
150
|
+
rawBaseDirsForServer = [];
|
|
151
|
+
configError = new BaseDirsConfigError([...new Set(sensitiveErrors)].join('; '));
|
|
152
|
+
configWarnings.push(configError.message);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
baseDirsForServer = baseDirsResult.config.baseDirs;
|
|
156
|
+
rawBaseDirsForServer = baseDirsResult.config.rawBaseDirs;
|
|
157
|
+
for (const warning of baseDirsResult.warnings) {
|
|
158
|
+
configWarnings.push(warning.message);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
baseDirsForServer = [];
|
|
164
|
+
rawBaseDirsForServer = [];
|
|
165
|
+
configError = baseDirsResult.error;
|
|
166
|
+
configWarnings.push(baseDirsResult.error.message);
|
|
167
|
+
}
|
|
168
|
+
const config = {
|
|
169
|
+
dbPath: env['DB_PATH'] || './lancedb/',
|
|
170
|
+
modelName: env['MODEL_NAME'] || 'Xenova/all-MiniLM-L6-v2',
|
|
171
|
+
cacheDir: env['CACHE_DIR'] || './models/',
|
|
172
|
+
baseDirs: baseDirsForServer,
|
|
173
|
+
rawBaseDirs: rawBaseDirsForServer,
|
|
174
|
+
maxFileSize: Number.parseInt(env['MAX_FILE_SIZE'] || String(DEFAULT_MAX_FILE_SIZE), 10),
|
|
175
|
+
device,
|
|
176
|
+
storeImages: false,
|
|
177
|
+
};
|
|
178
|
+
// Quality-filter settings: applied only when defined; invalid values warn.
|
|
179
|
+
const maxDistance = parseMaxDistance(env['RAG_MAX_DISTANCE']);
|
|
180
|
+
const grouping = parseGroupingMode(env['RAG_GROUPING']);
|
|
181
|
+
const maxFiles = parseMaxFiles(env['RAG_MAX_FILES']);
|
|
182
|
+
const hybridWeight = parseHybridWeight(env['RAG_HYBRID_WEIGHT']);
|
|
183
|
+
const chunkMinLength = parseChunkMinLength(env['CHUNK_MIN_LENGTH']);
|
|
184
|
+
const storeImages = parseStoreImages(env['STORE_IMAGES']);
|
|
185
|
+
if (maxDistance.value !== undefined)
|
|
186
|
+
config.maxDistance = maxDistance.value;
|
|
187
|
+
if (maxDistance.warning)
|
|
188
|
+
configWarnings.push(maxDistance.warning);
|
|
189
|
+
if (grouping.value !== undefined)
|
|
190
|
+
config.grouping = grouping.value;
|
|
191
|
+
if (grouping.warning)
|
|
192
|
+
configWarnings.push(grouping.warning);
|
|
193
|
+
if (maxFiles.value !== undefined)
|
|
194
|
+
config.maxFiles = maxFiles.value;
|
|
195
|
+
if (maxFiles.warning)
|
|
196
|
+
configWarnings.push(maxFiles.warning);
|
|
197
|
+
if (hybridWeight.value !== undefined)
|
|
198
|
+
config.hybridWeight = hybridWeight.value;
|
|
199
|
+
if (hybridWeight.warning)
|
|
200
|
+
configWarnings.push(hybridWeight.warning);
|
|
201
|
+
if (chunkMinLength.value !== undefined)
|
|
202
|
+
config.chunkMinLength = chunkMinLength.value;
|
|
203
|
+
if (chunkMinLength.warning)
|
|
204
|
+
configWarnings.push(chunkMinLength.warning);
|
|
205
|
+
config.storeImages = storeImages.value ?? false;
|
|
206
|
+
if (storeImages.warning)
|
|
207
|
+
configWarnings.push(storeImages.warning);
|
|
208
|
+
// Set dtype only when defined, so config.dtype === undefined keeps meaning
|
|
209
|
+
// "RAG_DTYPE unset" (the embedder then applies its fp32 default).
|
|
210
|
+
if (dtype !== undefined)
|
|
211
|
+
config.dtype = dtype;
|
|
212
|
+
if (configWarnings.length > 0)
|
|
213
|
+
config.configWarnings = configWarnings;
|
|
214
|
+
if (configError !== undefined)
|
|
215
|
+
config.configError = configError;
|
|
216
|
+
return config;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Start the RAG MCP Server
|
|
220
|
+
* Configuration is read from environment variables only (no CLI flags).
|
|
221
|
+
* This ensures the bare `mcp-local-rag` launch is suitable for MCP clients.
|
|
222
|
+
*/
|
|
223
|
+
export async function startServer() {
|
|
224
|
+
try {
|
|
225
|
+
const config = await resolveServerConfig(process.env, process.cwd());
|
|
226
|
+
if (config.configWarnings && config.configWarnings.length > 0) {
|
|
227
|
+
console.error('Configuration warnings:', config.configWarnings.join(' | '));
|
|
228
|
+
}
|
|
229
|
+
console.error('Starting RAG MCP Server...');
|
|
230
|
+
console.error('Configuration:', config);
|
|
231
|
+
// Start RAGServer
|
|
232
|
+
const server = new RAGServer(config);
|
|
233
|
+
await server.initialize();
|
|
234
|
+
await server.run();
|
|
235
|
+
console.error('RAG MCP Server started successfully');
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
console.error('Failed to start RAG MCP Server:', error);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=server-main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-main.js","sourceRoot":"","sources":["../src/server-main.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7F,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAa9D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,K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AIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;QAEpE,IAAI,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9D,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAC7E,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;QAC3C,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;QAEvC,kBAAkB;QAClB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;QACzB,MAAM,MAAM,CAAC,GAAG,EAAE,CAAA;QAElB,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAA;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { AppError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Effective document roots, in two index-aligned forms.
|
|
4
|
+
*
|
|
5
|
+
* Path policy (the canonical statement; other sites just reference it):
|
|
6
|
+
* realpath is used ONLY for the security boundary; everything user-facing uses
|
|
7
|
+
* resolve() (normal) paths.
|
|
8
|
+
* - `baseDirs`: realpath-resolved, deduped, nested-pruned — the containment
|
|
9
|
+
* boundary passed to `DocumentParser`. Input order preserved (first = legacy
|
|
10
|
+
* single-root accessor; see {@link legacyBaseDir}).
|
|
11
|
+
* - `rawBaseDirs`: the SAME roots, same order, resolve()-only. The normal path
|
|
12
|
+
* space `list`/`list_files` scan + display, so paths match the
|
|
13
|
+
* resolve()-stored DB keys; otherwise a symlinked prefix (e.g. macOS
|
|
14
|
+
* /tmp → /private/tmp) would make ingested files show as not-ingested.
|
|
15
|
+
*/
|
|
16
|
+
export interface BaseDirsConfig {
|
|
17
|
+
baseDirs: string[];
|
|
18
|
+
rawBaseDirs: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Discriminated union of configuration warnings surfaced by helpers in this
|
|
22
|
+
* module. Both CLI (stderr) and MCP (tool response content block) paths
|
|
23
|
+
* consume these — the consumer decides how to render them.
|
|
24
|
+
*/
|
|
25
|
+
export type BaseDirsConfigWarning = {
|
|
26
|
+
kind: 'nested-root-pruned';
|
|
27
|
+
message: string;
|
|
28
|
+
parent: string;
|
|
29
|
+
pruned: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'base-dirs-overrides-base-dir';
|
|
32
|
+
message: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Configuration error raised by parsers and the realpath helper. Modeled as
|
|
36
|
+
* a dedicated subclass so consumers can distinguish configuration problems
|
|
37
|
+
* from other I/O errors (e.g. `ValidationError` from `DocumentParser`).
|
|
38
|
+
*/
|
|
39
|
+
export declare class BaseDirsConfigError extends AppError {
|
|
40
|
+
constructor(message: string, cause?: Error);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Result of {@link parseBaseDirsEnv}. A discriminated union avoids forcing
|
|
44
|
+
* callers to use `try/catch` for what is a routine configuration-validation
|
|
45
|
+
* branch (invalid input → structured error → user-facing message).
|
|
46
|
+
*/
|
|
47
|
+
export type ParseBaseDirsResult = {
|
|
48
|
+
ok: true;
|
|
49
|
+
value: string[];
|
|
50
|
+
} | {
|
|
51
|
+
ok: false;
|
|
52
|
+
error: BaseDirsConfigError;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Render an absolute path for inclusion in user-visible error/warning
|
|
56
|
+
* messages, substituting the current `$HOME` prefix with `~`. The substitution
|
|
57
|
+
* keeps the message useful for debugging while avoiding leaking the operating
|
|
58
|
+
* username when warnings/errors flow out through MCP responses to clients.
|
|
59
|
+
*
|
|
60
|
+
* `$HOME` resolution is read once at call time, so processes that mutate
|
|
61
|
+
* `HOME` between invocations still see the current value (no caching).
|
|
62
|
+
*
|
|
63
|
+
* Exact-match on the home directory itself (`/Users/me` → `~`) and prefix
|
|
64
|
+
* match with a trailing separator (`/Users/me/work` → `~/work`) are both
|
|
65
|
+
* supported; other paths pass through unchanged.
|
|
66
|
+
*/
|
|
67
|
+
export declare function displayPath(path: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Parse the `BASE_DIRS` environment variable.
|
|
70
|
+
*
|
|
71
|
+
* Accepts only a JSON array of one or more non-empty, non-whitespace-only
|
|
72
|
+
* strings — e.g. `'["/Users/me/work","/Users/me/specs"]'`. Anything else
|
|
73
|
+
* (delimiter syntax such as `'/a:/b'`, an empty array, an array containing
|
|
74
|
+
* empty strings, non-string elements, JSON scalars, JSON objects, ...)
|
|
75
|
+
* produces a {@link BaseDirsConfigError}.
|
|
76
|
+
*
|
|
77
|
+
* This helper performs only syntactic validation. It does not resolve
|
|
78
|
+
* realpaths or check that the directories exist — that is the job of
|
|
79
|
+
* {@link normalizeRealpath} after the resolver picks a source.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseBaseDirsEnv(raw: string): ParseBaseDirsResult;
|
|
82
|
+
/**
|
|
83
|
+
* Append a trailing path separator if the input does not already end with
|
|
84
|
+
* one. This is the prefix-safety pattern used throughout the parser
|
|
85
|
+
* (`/foo/bar` must not match `/foo/barista`).
|
|
86
|
+
*/
|
|
87
|
+
export declare function withTrailingSeparator(path: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Resolve a directory to its realpath form and append a trailing separator
|
|
90
|
+
* so the result can be used directly as a prefix in security checks.
|
|
91
|
+
*
|
|
92
|
+
* realpath here is the security boundary (see {@link BaseDirsConfig} for the
|
|
93
|
+
* path policy); user-facing surfaces use the resolve()-only `rawBaseDirs`.
|
|
94
|
+
*
|
|
95
|
+
* Throws {@link BaseDirsConfigError} when the directory does not exist or
|
|
96
|
+
* is not a directory — root configuration must point at real directories
|
|
97
|
+
* the process is allowed to read.
|
|
98
|
+
*/
|
|
99
|
+
export declare function normalizeRealpath(path: string): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Output of {@link dedupAndPruneRoots}.
|
|
102
|
+
*/
|
|
103
|
+
export interface DedupAndPruneResult {
|
|
104
|
+
/** Effective roots in input order, after exact dedup and nested pruning. */
|
|
105
|
+
roots: string[];
|
|
106
|
+
/** Warnings describing pruned nested roots, in pruning order. */
|
|
107
|
+
warnings: BaseDirsConfigWarning[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Reduce a list of realpath-normalized roots to the effective set.
|
|
111
|
+
*
|
|
112
|
+
* Behavior:
|
|
113
|
+
* - Exact duplicates (`A === B` after realpath normalization) are silently
|
|
114
|
+
* deduplicated. This is treated as user convenience rather than a
|
|
115
|
+
* configuration mistake, so no warning is emitted.
|
|
116
|
+
* - Nested roots (`B` lives under `A` after realpath normalization) are
|
|
117
|
+
* pruned: the parent `A` is kept, the child `B` is dropped, and a
|
|
118
|
+
* `nested-root-pruned` warning describes both paths. This avoids
|
|
119
|
+
* duplicate `list_files` / CLI scan output without widening the security
|
|
120
|
+
* boundary beyond the parent root the user already configured.
|
|
121
|
+
*
|
|
122
|
+
* Input order is preserved for the surviving roots so the first element
|
|
123
|
+
* remains a meaningful legacy `baseDir` (see {@link legacyBaseDir}).
|
|
124
|
+
*
|
|
125
|
+
* All inputs MUST already have a trailing separator (see
|
|
126
|
+
* {@link normalizeRealpath}) — that is what makes the `startsWith`-based
|
|
127
|
+
* nested check safe against sibling-prefix paths like `/foo/barista`.
|
|
128
|
+
*/
|
|
129
|
+
export declare function dedupAndPruneRoots(inputs: string[]): DedupAndPruneResult;
|
|
130
|
+
/**
|
|
131
|
+
* Input to {@link resolveBaseDirs}. Each axis maps directly to one of the
|
|
132
|
+
* configuration sources defined in the multi-base-dirs plan:
|
|
133
|
+
*
|
|
134
|
+
* - `cliRoots` — collected `--base-dir` flag occurrences (highest precedence)
|
|
135
|
+
* - `envBaseDirs` — raw `BASE_DIRS` env value (JSON array)
|
|
136
|
+
* - `envBaseDir` — raw `BASE_DIR` env value (single path string)
|
|
137
|
+
* - `cwd` — `process.cwd()` snapshot (lowest precedence, always required)
|
|
138
|
+
*
|
|
139
|
+
* The resolver is pure with respect to its inputs (no `process.env` reads,
|
|
140
|
+
* no `process.cwd()` calls) so it can be exercised under deterministic tests
|
|
141
|
+
* and reused from both the CLI entry and the MCP server entry without
|
|
142
|
+
* implicitly depending on process state.
|
|
143
|
+
*/
|
|
144
|
+
export interface ResolveBaseDirsInput {
|
|
145
|
+
cliRoots?: string[] | undefined;
|
|
146
|
+
envBaseDirs?: string | undefined;
|
|
147
|
+
envBaseDir?: string | undefined;
|
|
148
|
+
cwd: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Result of {@link resolveBaseDirs}. Discriminated by `ok` so callers can
|
|
152
|
+
* branch on configuration validity without try/catch — invalid `BASE_DIRS`
|
|
153
|
+
* is a routine user-facing error path, not an exceptional condition.
|
|
154
|
+
*
|
|
155
|
+
* On success, `warnings` aggregates every warning surfaced during resolution
|
|
156
|
+
* in display order:
|
|
157
|
+
* 1. `base-dirs-overrides-base-dir` (when applicable) — shown first so the
|
|
158
|
+
* precedence note is visible before per-root pruning notes.
|
|
159
|
+
* 2. `nested-root-pruned` — one warning per pruned child, in pruning order.
|
|
160
|
+
*/
|
|
161
|
+
export type ResolveBaseDirsResult = {
|
|
162
|
+
ok: true;
|
|
163
|
+
config: BaseDirsConfig;
|
|
164
|
+
warnings: BaseDirsConfigWarning[];
|
|
165
|
+
} | {
|
|
166
|
+
ok: false;
|
|
167
|
+
error: BaseDirsConfigError;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Resolve effective base directories from CLI / env / cwd inputs.
|
|
171
|
+
*
|
|
172
|
+
* Resolution order (per the multi-base-dirs plan):
|
|
173
|
+
* 1. `cliRoots` (one or more `--base-dir` flags) — when non-empty, replaces
|
|
174
|
+
* env roots. CLI and env are never merged.
|
|
175
|
+
* 2. `envBaseDirs` (JSON array) — when CLI roots are absent.
|
|
176
|
+
* 3. `envBaseDir` (single path) — when CLI and `BASE_DIRS` are absent.
|
|
177
|
+
* 4. `cwd` — when none of the above are set.
|
|
178
|
+
*
|
|
179
|
+
* Warning rules:
|
|
180
|
+
* - `BASE_DIRS > BASE_DIR` precedence warning fires only when CLI roots are
|
|
181
|
+
* absent AND both `BASE_DIRS` and `BASE_DIR` are set. CLI-driven runs do
|
|
182
|
+
* not produce this warning even if both env vars are also set.
|
|
183
|
+
* - Nested-root pruning warnings always fire when applicable, regardless
|
|
184
|
+
* of which source provided the roots.
|
|
185
|
+
*
|
|
186
|
+
* Error rules:
|
|
187
|
+
* - Invalid `BASE_DIRS` (malformed JSON, non-array, empty array, empty
|
|
188
|
+
* string element, ...) returns `{ ok: false, error }`. The resolver does
|
|
189
|
+
* NOT fall back to `BASE_DIR` or `cwd` — callers surface the error per
|
|
190
|
+
* their UI contract (CLI exit code, MCP tool error, `status` diagnostic).
|
|
191
|
+
* - A path that fails realpath resolution (does not exist, not a directory,
|
|
192
|
+
* permission denied) also returns `{ ok: false, error }`. Roots must
|
|
193
|
+
* point at real directories the process is allowed to read.
|
|
194
|
+
*
|
|
195
|
+
* Post-resolution normalization:
|
|
196
|
+
* - Every selected path is realpath-normalized and gets a trailing path
|
|
197
|
+
* separator (see {@link normalizeRealpath}) so it can be used as a prefix
|
|
198
|
+
* in security checks.
|
|
199
|
+
* - Exact duplicates are silently deduplicated.
|
|
200
|
+
* - Nested roots are pruned with a warning (see {@link dedupAndPruneRoots}).
|
|
201
|
+
*/
|
|
202
|
+
export declare function resolveBaseDirs(input: ResolveBaseDirsInput): Promise<ResolveBaseDirsResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Return the legacy single-root `baseDir` value for a {@link BaseDirsConfig}.
|
|
205
|
+
*
|
|
206
|
+
* Used for backward compatibility with consumers (and response fields) that
|
|
207
|
+
* pre-date the multi-root model. The contract is "first effective root after
|
|
208
|
+
* normalization and nested-root pruning"; callers must build the config via
|
|
209
|
+
* {@link dedupAndPruneRoots} for this to hold.
|
|
210
|
+
*/
|
|
211
|
+
export declare function legacyBaseDir(config: BaseDirsConfig): string;
|
|
212
|
+
//# sourceMappingURL=base-dirs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-dirs.d.ts","sourceRoot":"","sources":["../../src/utils/base-dirs.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAMtC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAC7B;IACE,IAAI,EAAE,oBAAoB,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf,GACD;IACE,IAAI,EAAE,8BAA8B,CAAA;IACpC,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAEL;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAGzC;CACF;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,KAAK,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