Skip to content

Commit c1824d4

Browse files
committed
chore: bump version to 1.4.5 and include recent changes
1 parent 0711ae5 commit c1824d4

File tree

3 files changed

+61
-60
lines changed

3 files changed

+61
-60
lines changed

.DS_Store

6 KB
Binary file not shown.

src/lib/server.ts

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -239,66 +239,67 @@ export async function startServer(repoPath: string): Promise<void> {
239239
}
240240
});
241241

242-
server.resource(
243-
"Repository File Content",
244-
new ResourceTemplate("repo://files/{filepath}", { list: undefined }),
245-
{}, // metadata
246-
async (uri: URL, variables: Variables, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {
247-
const rawFilepathValue = variables.filepath;
248-
let relativeFilepath = '';
249-
if (typeof rawFilepathValue === 'string') {
250-
relativeFilepath = rawFilepathValue.trim();
251-
} else if (Array.isArray(rawFilepathValue) && rawFilepathValue.length > 0 && typeof rawFilepathValue[0] === 'string') {
252-
logger.warn(`Filepath parameter '${JSON.stringify(rawFilepathValue)}' resolved to an array. Using the first element: '${rawFilepathValue[0]}'`);
253-
relativeFilepath = rawFilepathValue[0].trim();
254-
} else if (rawFilepathValue !== undefined) {
255-
logger.warn(`Filepath parameter '${Array.isArray(rawFilepathValue) ? JSON.stringify(rawFilepathValue) : rawFilepathValue}' resolved to an unexpected type: ${typeof rawFilepathValue}. Treating as empty.`);
256-
}
257-
// If rawFilepathValue is undefined, or an empty array, or an array not containing a string at index 0, relativeFilepath remains ''.
258-
259-
if (!relativeFilepath) {
260-
const errMsg = "File path cannot be empty.";
261-
logger.error(`Error accessing resource for URI ${uri.toString()}: ${errMsg}`);
262-
return { contents: [{ uri: uri.toString(), text: "", error: errMsg }] };
263-
}
264-
265-
try {
266-
const resolvedRepoPath = path.resolve(repoPath); // Normalized
267-
const requestedFullPath = path.resolve(repoPath, relativeFilepath); // Normalized
268-
269-
// Initial security check: Ensure the resolved path is within the repoPath
270-
if (!requestedFullPath.startsWith(resolvedRepoPath + path.sep) && requestedFullPath !== resolvedRepoPath) {
271-
throw new Error(`Access denied: Path '${relativeFilepath}' attempts to traverse outside the repository directory.`);
272-
}
242+
// Temporarily commented out to diagnose "resources/list" serialization error
243+
// server.resource(
244+
// "Repository File Content",
245+
// new ResourceTemplate("repo://files/{filepath}", { list: undefined }),
246+
// {}, // metadata
247+
// async (uri: URL, variables: Variables, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {
248+
// const rawFilepathValue = variables.filepath;
249+
// let relativeFilepath = '';
250+
// if (typeof rawFilepathValue === 'string') {
251+
// relativeFilepath = rawFilepathValue.trim();
252+
// } else if (Array.isArray(rawFilepathValue) && rawFilepathValue.length > 0 && typeof rawFilepathValue[0] === 'string') {
253+
// logger.warn(`Filepath parameter '${JSON.stringify(rawFilepathValue)}' resolved to an array. Using the first element: '${rawFilepathValue[0]}'`);
254+
// relativeFilepath = rawFilepathValue[0].trim();
255+
// } else if (rawFilepathValue !== undefined) {
256+
// logger.warn(`Filepath parameter '${Array.isArray(rawFilepathValue) ? JSON.stringify(rawFilepathValue) : rawFilepathValue}' resolved to an unexpected type: ${typeof rawFilepathValue}. Treating as empty.`);
257+
// }
258+
// // If rawFilepathValue is undefined, or an empty array, or an array not containing a string at index 0, relativeFilepath remains ''.
259+
260+
// if (!relativeFilepath) {
261+
// const errMsg = "File path cannot be empty.";
262+
// logger.error(`Error accessing resource for URI ${uri.toString()}: ${errMsg}`);
263+
// return { contents: [{ uri: uri.toString(), text: "", error: errMsg }] };
264+
// }
265+
266+
// try {
267+
// const resolvedRepoPath = path.resolve(repoPath); // Normalized
268+
// const requestedFullPath = path.resolve(repoPath, relativeFilepath); // Normalized
269+
270+
// // Initial security check: Ensure the resolved path is within the repoPath
271+
// if (!requestedFullPath.startsWith(resolvedRepoPath + path.sep) && requestedFullPath !== resolvedRepoPath) {
272+
// throw new Error(`Access denied: Path '${relativeFilepath}' attempts to traverse outside the repository directory.`);
273+
// }
273274

274-
let finalPathToRead = requestedFullPath;
275-
try {
276-
const stats = await fs.lstat(requestedFullPath);
277-
if (stats.isSymbolicLink()) {
278-
const symlinkTargetPath = await fs.realpath(requestedFullPath);
279-
// Ensure the resolved symlink target is also within the repository
280-
if (!path.resolve(symlinkTargetPath).startsWith(resolvedRepoPath + path.sep) && path.resolve(symlinkTargetPath) !== resolvedRepoPath) {
281-
throw new Error(`Access denied: Symbolic link '${relativeFilepath}' points outside the repository directory.`);
282-
}
283-
finalPathToRead = symlinkTargetPath; // Update path to read from the symlink's target
284-
} else if (!stats.isFile()) {
285-
throw new Error(`Access denied: Path '${relativeFilepath}' is not a file.`);
286-
}
287-
} catch (statError: unknown) {
288-
if ((statError as NodeJS.ErrnoException).code === 'ENOENT') {
289-
throw new Error(`File not found: ${relativeFilepath}`);
290-
}
291-
throw statError; // Re-throw other stat/realpath errors
292-
}
293-
294-
const content = await fs.readFile(finalPathToRead, "utf8");
295-
return { contents: [{ uri: uri.toString(), text: content }] };
296-
} catch (error: unknown) {
297-
const errorMessage = error instanceof Error ? error.message : String(error);
298-
logger.error(`Error accessing resource for URI ${uri.toString()} (relative path: ${relativeFilepath}): ${errorMessage}`);
299-
return { contents: [{ uri: uri.toString(), text: "", error: errorMessage }] };
300-
}
301-
});
275+
// let finalPathToRead = requestedFullPath;
276+
// try {
277+
// const stats = await fs.lstat(requestedFullPath);
278+
// if (stats.isSymbolicLink()) {
279+
// const symlinkTargetPath = await fs.realpath(requestedFullPath);
280+
// // Ensure the resolved symlink target is also within the repository
281+
// if (!path.resolve(symlinkTargetPath).startsWith(resolvedRepoPath + path.sep) && path.resolve(symlinkTargetPath) !== resolvedRepoPath) {
282+
// throw new Error(`Access denied: Symbolic link '${relativeFilepath}' points outside the repository directory.`);
283+
// }
284+
// finalPathToRead = symlinkTargetPath; // Update path to read from the symlink's target
285+
// } else if (!stats.isFile()) {
286+
// throw new Error(`Access denied: Path '${relativeFilepath}' is not a file.`);
287+
// }
288+
// } catch (statError: unknown) {
289+
// if ((statError as NodeJS.ErrnoException).code === 'ENOENT') {
290+
// throw new Error(`File not found: ${relativeFilepath}`);
291+
// }
292+
// throw statError; // Re-throw other stat/realpath errors
293+
// }
294+
295+
// const content = await fs.readFile(finalPathToRead, "utf8");
296+
// return { contents: [{ uri: uri.toString(), text: content }] };
297+
// } catch (error: unknown) {
298+
// const errorMessage = error instanceof Error ? error.message : String(error);
299+
// logger.error(`Error accessing resource for URI ${uri.toString()} (relative path: ${relativeFilepath}): ${errorMessage}`);
300+
// return { contents: [{ uri: uri.toString(), text: "", error: errorMessage }] };
301+
// }
302+
// });
302303

303304
registerTools(server, qdrantClient, repoPath, suggestionModelAvailable);
304305

src/utils/text-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Utility: Preprocess input text
22
export function preprocessText(text: string): string {
33
// eslint-disable-next-line no-control-regex
4-
text = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
4+
text = text.replace(/\x00/g, ""); // Only remove null characters
55
text = text.replace(/\s+/g, (match) => {
66
if (match.includes("\n")) return "\n";
77
return " ";

0 commit comments

Comments
 (0)