prettier
This commit is contained in:
parent
ecbb4e272d
commit
71f97dba8f
4 changed files with 26 additions and 24 deletions
|
|
@ -66,7 +66,10 @@ export const readFileRangeTool: Tool = {
|
|||
basePolicy: ToolPolicy,
|
||||
parsedArgs: Record<string, unknown>,
|
||||
): ToolPolicy => {
|
||||
const resolvedPath = parsedArgs._resolvedPath as ResolvedPath | null | undefined;
|
||||
const resolvedPath = parsedArgs._resolvedPath as
|
||||
| ResolvedPath
|
||||
| null
|
||||
| undefined;
|
||||
if (!resolvedPath) return basePolicy;
|
||||
|
||||
return evaluateFileAccessPolicy(basePolicy, resolvedPath.isWithinWorkspace);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { ToolPolicy } from "@continuedev/terminal-security";
|
|||
*/
|
||||
export function evaluateFileAccessPolicy(
|
||||
basePolicy: ToolPolicy,
|
||||
isWithinWorkspace: boolean
|
||||
isWithinWorkspace: boolean,
|
||||
): ToolPolicy {
|
||||
// If tool is disabled, keep it disabled
|
||||
if (basePolicy === "disabled") {
|
||||
|
|
@ -23,4 +23,4 @@ export function evaluateFileAccessPolicy(
|
|||
|
||||
// Files outside workspace always require permission for security
|
||||
return "allowedWithPermission";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { IDE } from "..";
|
||||
import { normalizeDisplayPath, resolveInputPath } from "./pathResolver";
|
||||
import * as ideUtils from "./ideUtils";
|
||||
import { normalizeDisplayPath, resolveInputPath } from "./pathResolver";
|
||||
import * as uri from "./uri";
|
||||
|
||||
// Mock the resolveRelativePathInDir function
|
||||
|
|
@ -29,26 +29,28 @@ describe("resolveUserProvidedPath", () => {
|
|||
return `${workspaceUri}/${path}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Setup the mock for findUriInDirs
|
||||
(uri.findUriInDirs as jest.Mock).mockImplementation((uri, dirUriCandidates) => {
|
||||
for (const dir of dirUriCandidates) {
|
||||
if (uri.startsWith(dir)) {
|
||||
return {
|
||||
uri,
|
||||
relativePathOrBasename: uri.slice(dir.length + 1),
|
||||
foundInDir: dir,
|
||||
};
|
||||
(uri.findUriInDirs as jest.Mock).mockImplementation(
|
||||
(uri, dirUriCandidates) => {
|
||||
for (const dir of dirUriCandidates) {
|
||||
if (uri.startsWith(dir)) {
|
||||
return {
|
||||
uri,
|
||||
relativePathOrBasename: uri.slice(dir.length + 1),
|
||||
foundInDir: dir,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
uri,
|
||||
relativePathOrBasename: uri.split('/').pop() || '',
|
||||
foundInDir: null,
|
||||
};
|
||||
});
|
||||
return {
|
||||
uri,
|
||||
relativePathOrBasename: uri.split("/").pop() || "",
|
||||
foundInDir: null,
|
||||
};
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("file:// URIs", () => {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@ export interface ResolvedPath {
|
|||
/**
|
||||
* Checks if a URI is within any of the workspace directories
|
||||
*/
|
||||
async function isUriWithinWorkspace(
|
||||
ide: IDE,
|
||||
uri: string
|
||||
): Promise<boolean> {
|
||||
async function isUriWithinWorkspace(ide: IDE, uri: string): Promise<boolean> {
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
const { foundInDir } = findUriInDirs(uri, workspaceDirs);
|
||||
return foundInDir !== null;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue