@sharc-code/mcp 0.2.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/README.md +134 -0
- package/dist/backend-client.d.ts +251 -0
- package/dist/backend-client.d.ts.map +1 -0
- package/dist/backend-client.js +269 -0
- package/dist/backend-client.js.map +1 -0
- package/dist/backend-handlers.d.ts +243 -0
- package/dist/backend-handlers.d.ts.map +1 -0
- package/dist/backend-handlers.js +1453 -0
- package/dist/backend-handlers.js.map +1 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +94 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +344 -0
- package/dist/index.js.map +1 -0
- package/dist/project-detector.d.ts +42 -0
- package/dist/project-detector.d.ts.map +1 -0
- package/dist/project-detector.js +135 -0
- package/dist/project-detector.js.map +1 -0
- package/dist/utils/env-manager.d.ts +19 -0
- package/dist/utils/env-manager.d.ts.map +1 -0
- package/dist/utils/env-manager.js +99 -0
- package/dist/utils/env-manager.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +27 -0
- package/dist/utils.js.map +1 -0
- package/dist/watcher/file-watcher.d.ts +64 -0
- package/dist/watcher/file-watcher.d.ts.map +1 -0
- package/dist/watcher/file-watcher.js +263 -0
- package/dist/watcher/file-watcher.js.map +1 -0
- package/dist/watcher/incremental-indexer.d.ts +68 -0
- package/dist/watcher/incremental-indexer.d.ts.map +1 -0
- package/dist/watcher/incremental-indexer.js +254 -0
- package/dist/watcher/incremental-indexer.js.map +1 -0
- package/dist/watcher/index.d.ts +10 -0
- package/dist/watcher/index.d.ts.map +1 -0
- package/dist/watcher/index.js +10 -0
- package/dist/watcher/index.js.map +1 -0
- package/dist/watcher/processing-queue.d.ts +79 -0
- package/dist/watcher/processing-queue.d.ts.map +1 -0
- package/dist/watcher/processing-queue.js +150 -0
- package/dist/watcher/processing-queue.js.map +1 -0
- package/dist/watcher/syntax-guard.d.ts +59 -0
- package/dist/watcher/syntax-guard.d.ts.map +1 -0
- package/dist/watcher/syntax-guard.js +136 -0
- package/dist/watcher/syntax-guard.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects if a path contains a valid software project using common markers.
|
|
5
|
+
* Used for:
|
|
6
|
+
* - Validating paths before sync/indexing
|
|
7
|
+
* - Generating helpful messages in tool descriptions
|
|
8
|
+
*/
|
|
9
|
+
export type ProjectType = 'git' | 'npm' | 'python' | 'rust' | 'go' | 'dotnet' | 'java' | 'unknown';
|
|
10
|
+
export interface ProjectInfo {
|
|
11
|
+
isValid: boolean;
|
|
12
|
+
type: ProjectType;
|
|
13
|
+
markers: string[];
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Detect if a directory contains a valid software project
|
|
18
|
+
*
|
|
19
|
+
* @param dirPath - Absolute path to the directory to check
|
|
20
|
+
* @returns ProjectInfo with detection results
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectProject(dirPath: string): Promise<ProjectInfo>;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a path exists and is a directory
|
|
25
|
+
*
|
|
26
|
+
* @param dirPath - Path to check
|
|
27
|
+
* @returns true if path exists and is a directory
|
|
28
|
+
*/
|
|
29
|
+
export declare function isValidDirectory(dirPath: string): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a human-readable description of the project type
|
|
32
|
+
*/
|
|
33
|
+
export declare function getProjectTypeDescription(type: ProjectType): string;
|
|
34
|
+
/**
|
|
35
|
+
* Check if CWD or any parent is inside an indexed codebase
|
|
36
|
+
*
|
|
37
|
+
* @param cwd - Current working directory
|
|
38
|
+
* @param indexedPaths - List of indexed codebase paths
|
|
39
|
+
* @returns The matching indexed path, or null if no match
|
|
40
|
+
*/
|
|
41
|
+
export declare function findMatchingIndexedPath(cwd: string, indexedPaths: string[]): string | null;
|
|
42
|
+
//# sourceMappingURL=project-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-detector.d.ts","sourceRoot":"","sources":["../src/project-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnG,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CAChB;AAqBD;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAuDzE;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAYnE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAqB1F"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects if a path contains a valid software project using common markers.
|
|
5
|
+
* Used for:
|
|
6
|
+
* - Validating paths before sync/indexing
|
|
7
|
+
* - Generating helpful messages in tool descriptions
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'fs/promises';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
const PROJECT_MARKERS = [
|
|
12
|
+
// Language-specific markers (higher priority)
|
|
13
|
+
{ type: 'npm', files: ['package.json'], priority: 10 },
|
|
14
|
+
{ type: 'python', files: ['pyproject.toml', 'setup.py', 'requirements.txt', 'Pipfile'], priority: 10 },
|
|
15
|
+
{ type: 'rust', files: ['Cargo.toml'], priority: 10 },
|
|
16
|
+
{ type: 'go', files: ['go.mod'], priority: 10 },
|
|
17
|
+
{ type: 'java', files: ['pom.xml', 'build.gradle', 'build.gradle.kts'], priority: 10 },
|
|
18
|
+
// .NET uses wildcards
|
|
19
|
+
{ type: 'dotnet', files: ['*.csproj', '*.sln', '*.fsproj', '*.vbproj'], priority: 10 },
|
|
20
|
+
// Git is a fallback (lower priority)
|
|
21
|
+
{ type: 'git', files: ['.git'], priority: 1 },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Detect if a directory contains a valid software project
|
|
25
|
+
*
|
|
26
|
+
* @param dirPath - Absolute path to the directory to check
|
|
27
|
+
* @returns ProjectInfo with detection results
|
|
28
|
+
*/
|
|
29
|
+
export async function detectProject(dirPath) {
|
|
30
|
+
const result = {
|
|
31
|
+
isValid: false,
|
|
32
|
+
type: 'unknown',
|
|
33
|
+
markers: [],
|
|
34
|
+
path: dirPath,
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
const entries = await fs.readdir(dirPath);
|
|
38
|
+
const entriesSet = new Set(entries);
|
|
39
|
+
let bestMatch = null;
|
|
40
|
+
for (const marker of PROJECT_MARKERS) {
|
|
41
|
+
const foundMarkers = [];
|
|
42
|
+
for (const file of marker.files) {
|
|
43
|
+
// Handle wildcard patterns like *.csproj
|
|
44
|
+
if (file.startsWith('*')) {
|
|
45
|
+
const ext = file.substring(1);
|
|
46
|
+
const match = entries.find((e) => e.endsWith(ext));
|
|
47
|
+
if (match) {
|
|
48
|
+
foundMarkers.push(match);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (entriesSet.has(file)) {
|
|
53
|
+
foundMarkers.push(file);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (foundMarkers.length > 0) {
|
|
58
|
+
// Keep the highest priority match
|
|
59
|
+
if (!bestMatch || marker.priority > bestMatch.priority) {
|
|
60
|
+
bestMatch = {
|
|
61
|
+
type: marker.type,
|
|
62
|
+
markers: foundMarkers,
|
|
63
|
+
priority: marker.priority,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (bestMatch) {
|
|
69
|
+
result.isValid = true;
|
|
70
|
+
result.type = bestMatch.type;
|
|
71
|
+
result.markers = bestMatch.markers;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Directory doesn't exist or can't be read
|
|
76
|
+
result.isValid = false;
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check if a path exists and is a directory
|
|
82
|
+
*
|
|
83
|
+
* @param dirPath - Path to check
|
|
84
|
+
* @returns true if path exists and is a directory
|
|
85
|
+
*/
|
|
86
|
+
export async function isValidDirectory(dirPath) {
|
|
87
|
+
try {
|
|
88
|
+
const stat = await fs.stat(dirPath);
|
|
89
|
+
return stat.isDirectory();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get a human-readable description of the project type
|
|
97
|
+
*/
|
|
98
|
+
export function getProjectTypeDescription(type) {
|
|
99
|
+
const descriptions = {
|
|
100
|
+
npm: 'Node.js/npm',
|
|
101
|
+
python: 'Python',
|
|
102
|
+
rust: 'Rust',
|
|
103
|
+
go: 'Go',
|
|
104
|
+
java: 'Java/Gradle/Maven',
|
|
105
|
+
dotnet: '.NET',
|
|
106
|
+
git: 'Git repository',
|
|
107
|
+
unknown: 'Unknown',
|
|
108
|
+
};
|
|
109
|
+
return descriptions[type];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if CWD or any parent is inside an indexed codebase
|
|
113
|
+
*
|
|
114
|
+
* @param cwd - Current working directory
|
|
115
|
+
* @param indexedPaths - List of indexed codebase paths
|
|
116
|
+
* @returns The matching indexed path, or null if no match
|
|
117
|
+
*/
|
|
118
|
+
export function findMatchingIndexedPath(cwd, indexedPaths) {
|
|
119
|
+
const normalizedCwd = path.resolve(cwd).toLowerCase();
|
|
120
|
+
for (const indexedPath of indexedPaths) {
|
|
121
|
+
const normalizedIndexed = path.resolve(indexedPath).toLowerCase();
|
|
122
|
+
// Check if CWD is inside or equal to indexed path
|
|
123
|
+
if (normalizedCwd.startsWith(normalizedIndexed)) {
|
|
124
|
+
// Ensure it's a proper path boundary (not just prefix match)
|
|
125
|
+
// e.g., /home/user/project should match /home/user/project/src
|
|
126
|
+
// but /home/user/project2 should NOT match /home/user/project
|
|
127
|
+
if (normalizedCwd === normalizedIndexed ||
|
|
128
|
+
normalizedCwd.charAt(normalizedIndexed.length) === path.sep.toLowerCase()) {
|
|
129
|
+
return indexedPath;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=project-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-detector.js","sourceRoot":"","sources":["../src/project-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAiB7B,MAAM,eAAe,GAAoB;IACrC,8CAA8C;IAC9C,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtD,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,gBAAgB,EAAE,UAAU,EAAE,kBAAkB,EAA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ePath;
|
|
3
|
+
constructor();
|
|
4
|
+
/**
|
|
5
|
+
* Get environment variable by name
|
|
6
|
+
* Priority: process.env > .env file > undefined
|
|
7
|
+
*/
|
|
8
|
+
get(name: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Set environment variable to the .env file
|
|
11
|
+
*/
|
|
12
|
+
set(name: string, value: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Get the path to the .env file
|
|
15
|
+
*/
|
|
16
|
+
getEnvFilePath(): string;
|
|
17
|
+
}
|
|
18
|
+
export declare const envManager: EnvManager;
|
|
19
|
+
//# sourceMappingURL=env-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-manager.d.ts","sourceRoot":"","sources":["../../src/utils/env-manager.ts"],"names":[],"mappings":"AASA,qBAAa,UAAU;IACnB,OAAO,CAAC,WAAW,CAAS;;IAO5B;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAgCrC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IA8CtC;;OAEG;IACH,cAAc,IAAI,MAAM;CAG3B;AAGD,eAAO,MAAM,UAAU,YAAmB,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnvManager - duplicated from @sharc/core to avoid circular dependencies.
|
|
3
|
+
* This allows @sharc/mcp to remain independent of @sharc/core.
|
|
4
|
+
* Changes should be kept in sync with packages/core/src/utils/env-manager.ts
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
export class EnvManager {
|
|
10
|
+
constructor() {
|
|
11
|
+
const homeDir = os.homedir();
|
|
12
|
+
this.envFilePath = path.join(homeDir, '.context', '.env');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get environment variable by name
|
|
16
|
+
* Priority: process.env > .env file > undefined
|
|
17
|
+
*/
|
|
18
|
+
get(name) {
|
|
19
|
+
// First try to get from process environment variables
|
|
20
|
+
if (process.env[name]) {
|
|
21
|
+
return process.env[name];
|
|
22
|
+
}
|
|
23
|
+
// If not found in process env, try to read from .env file
|
|
24
|
+
try {
|
|
25
|
+
if (fs.existsSync(this.envFilePath)) {
|
|
26
|
+
const content = fs.readFileSync(this.envFilePath, 'utf-8');
|
|
27
|
+
const lines = content.split('\n');
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
const trimmedLine = line.trim();
|
|
30
|
+
if (trimmedLine.startsWith(`${name}=`)) {
|
|
31
|
+
let value = trimmedLine.substring(name.length + 1);
|
|
32
|
+
// Remove surrounding quotes if present
|
|
33
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
34
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
35
|
+
value = value.slice(1, -1);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Ignore file read errors
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set environment variable to the .env file
|
|
49
|
+
*/
|
|
50
|
+
set(name, value) {
|
|
51
|
+
try {
|
|
52
|
+
// Ensure directory exists
|
|
53
|
+
const envDir = path.dirname(this.envFilePath);
|
|
54
|
+
if (!fs.existsSync(envDir)) {
|
|
55
|
+
fs.mkdirSync(envDir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
let content = '';
|
|
58
|
+
let found = false;
|
|
59
|
+
// Read existing content if file exists
|
|
60
|
+
if (fs.existsSync(this.envFilePath)) {
|
|
61
|
+
content = fs.readFileSync(this.envFilePath, 'utf-8');
|
|
62
|
+
// Update existing variable
|
|
63
|
+
const lines = content.split('\n');
|
|
64
|
+
for (let i = 0; i < lines.length; i++) {
|
|
65
|
+
if (lines[i].trim().startsWith(`${name}=`)) {
|
|
66
|
+
// Replace the existing value
|
|
67
|
+
lines[i] = `${name}=${value}`;
|
|
68
|
+
found = true;
|
|
69
|
+
console.log(`[EnvManager] Updated ${name} in ${this.envFilePath}`);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
content = lines.join('\n');
|
|
74
|
+
}
|
|
75
|
+
// If variable not found, append it
|
|
76
|
+
if (!found) {
|
|
77
|
+
if (content && !content.endsWith('\n')) {
|
|
78
|
+
content += '\n';
|
|
79
|
+
}
|
|
80
|
+
content += `${name}=${value}\n`;
|
|
81
|
+
console.log(`[EnvManager] Added ${name} to ${this.envFilePath}`);
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(this.envFilePath, content, 'utf-8');
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error(`[EnvManager] Failed to write env file: ${error}`);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the path to the .env file
|
|
92
|
+
*/
|
|
93
|
+
getEnvFilePath() {
|
|
94
|
+
return this.envFilePath;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Export a default instance for convenience
|
|
98
|
+
export const envManager = new EnvManager();
|
|
99
|
+
//# sourceMappingURL=env-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-manager.js","sourceRoot":"","sources":["../../src/utils/env-manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,OAAO,UAAU;IAGnB;QACI,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,IAA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nC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACrC,OAAO,IAAI,IAAI,CAAC;gBACpB,CAAC;gBACD,OAAO,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC;gBAChC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACrE,CAAC;YAED,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAEzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAC;YACjE,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAED;;OAEG;IACH,cAAc;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;CACJ;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate content to specified length
|
|
3
|
+
*/
|
|
4
|
+
export declare function truncateContent(content: string, maxLength: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* Ensure path is absolute. If relative path is provided, resolve it properly.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ensureAbsolutePath(inputPath: string): string;
|
|
9
|
+
export declare function trackCodebasePath(codebasePath: string): void;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAS5D;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAG5D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
/**
|
|
3
|
+
* Truncate content to specified length
|
|
4
|
+
*/
|
|
5
|
+
export function truncateContent(content, maxLength) {
|
|
6
|
+
if (content.length <= maxLength) {
|
|
7
|
+
return content;
|
|
8
|
+
}
|
|
9
|
+
return content.substring(0, maxLength) + '...';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ensure path is absolute. If relative path is provided, resolve it properly.
|
|
13
|
+
*/
|
|
14
|
+
export function ensureAbsolutePath(inputPath) {
|
|
15
|
+
// If already absolute, return as is
|
|
16
|
+
if (path.isAbsolute(inputPath)) {
|
|
17
|
+
return inputPath;
|
|
18
|
+
}
|
|
19
|
+
// For relative paths, resolve to absolute path
|
|
20
|
+
const resolved = path.resolve(inputPath);
|
|
21
|
+
return resolved;
|
|
22
|
+
}
|
|
23
|
+
export function trackCodebasePath(codebasePath) {
|
|
24
|
+
const absolutePath = ensureAbsolutePath(codebasePath);
|
|
25
|
+
console.log(`[TRACKING] Tracked codebase path: ${absolutePath} (not marked as indexed)`);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,SAAiB;IAC9D,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAChD,oCAAoC;IACpC,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IAClD,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,qCAAqC,YAAY,0BAA0B,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Watcher Service
|
|
3
|
+
*
|
|
4
|
+
* Uses chokidar to watch for file changes in codebases.
|
|
5
|
+
* Features:
|
|
6
|
+
* - Debounced batch processing (2 seconds after last change)
|
|
7
|
+
* - Per-codebase isolation
|
|
8
|
+
* - Configurable ignore patterns
|
|
9
|
+
* - Rename handling (delete + add)
|
|
10
|
+
*/
|
|
11
|
+
import { type FileChange, type ChangeProcessor } from './processing-queue.js';
|
|
12
|
+
export declare const SUPPORTED_EXTENSIONS: Set<string>;
|
|
13
|
+
export declare const DEFAULT_IGNORE_PATTERNS: string[];
|
|
14
|
+
export interface WatcherConfig {
|
|
15
|
+
debounceMs?: number;
|
|
16
|
+
ignorePatterns?: string[];
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type BatchChangeHandler = (changes: FileChange[]) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* File Watcher Service
|
|
22
|
+
*
|
|
23
|
+
* Watches codebases for file changes and triggers incremental indexing.
|
|
24
|
+
* Each codebase has its own watcher instance with isolated state.
|
|
25
|
+
*/
|
|
26
|
+
export declare class FileWatcherService {
|
|
27
|
+
private watchedCodebases;
|
|
28
|
+
private restartAttempts;
|
|
29
|
+
private debounceMs;
|
|
30
|
+
private ignorePatterns;
|
|
31
|
+
private verbose;
|
|
32
|
+
private changeProcessor;
|
|
33
|
+
private static readonly MAX_RESTART_ATTEMPTS;
|
|
34
|
+
constructor(changeProcessor: ChangeProcessor, config?: WatcherConfig);
|
|
35
|
+
/**
|
|
36
|
+
* Start watching a codebase for file changes
|
|
37
|
+
*/
|
|
38
|
+
watchCodebase(codebasePath: string, collectionName: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Stop watching a codebase
|
|
41
|
+
*/
|
|
42
|
+
unwatchCodebase(codebasePath: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get list of watched codebase paths
|
|
45
|
+
*/
|
|
46
|
+
getWatchedCodebases(): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Check if a codebase is being watched
|
|
49
|
+
*/
|
|
50
|
+
isWatching(codebasePath: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Handle a file event from chokidar
|
|
53
|
+
*/
|
|
54
|
+
private handleFileEvent;
|
|
55
|
+
/**
|
|
56
|
+
* Process all batched changes for a codebase
|
|
57
|
+
*/
|
|
58
|
+
private processBatchedChanges;
|
|
59
|
+
/**
|
|
60
|
+
* Graceful shutdown - stop all watchers
|
|
61
|
+
*/
|
|
62
|
+
shutdown(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=file-watcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-watcher.d.ts","sourceRoot":"","sources":["../../src/watcher/file-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAmB,KAAK,UAAU,EAAuB,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGpH,eAAO,MAAM,oBAAoB,aAiB/B,CAAC;AAGH,eAAO,MAAM,uBAA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