@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
44 lines • 1.94 kB
JavaScript
import { realpathWithoutOpen } from "../../../../utils/paths.js";
import { getBundledResourceRoots } from "../../../bundled-resources.js";
import { resolveReadPath } from "../../../tools/path-utils.js";
import { isExternalPath, resolveExternalPath, toParentDirectoryPattern } from "./external-dir.js";
/** Resolve the same file the read tool will open before classifying its ownership. */
export const parseReadPermission = (_toolName, input, cwd) => {
const filePath = typeof input.path === "string" ? input.path : typeof input.file_path === "string" ? input.file_path : undefined;
if (!filePath)
return [{ permission: "read", patterns: ["*"], always: ["*"] }];
const readPath = resolveReadPath(filePath, cwd);
const target = realpathWithoutOpen(readPath);
const request = {
permission: "read",
patterns: [filePath],
always: [filePath],
executed: [readPath],
};
if (getBundledResourceRoots().some((root) => !isExternalPath(target, root))) {
// The service still evaluates denial rules; only an ask result is auto-approved.
return [
{
...request,
patterns: [readPath],
always: [readPath],
autoApproveAsk: true,
ruleAliases: [...new Set([filePath, readPath, target])],
},
];
}
const externalTarget = resolveExternalPath(target, cwd);
if (externalTarget === undefined)
return [request];
return [
request,
{
permission: "external_directory",
patterns: [externalTarget],
always: [toParentDirectoryPattern(externalTarget, "file", filePath)],
...(readPath !== externalTarget ? { ruleAliases: [readPath] } : {}),
...(filePath !== externalTarget ? { originalPaths: [filePath] } : {}),
},
];
};
//# sourceMappingURL=read-permission.js.map