summaryrefslogtreecommitdiffhomepage
path: root/packages/tool-read-file/src/read-file.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-05 21:20:12 +0900
committerAdam Malczewski <[email protected]>2026-06-05 21:20:12 +0900
commit7fb3269c698ae583ea7997ce206c4ae252fd3218 (patch)
tree247d03408ecccd633290ea56b1b08811ebe460ec /packages/tool-read-file/src/read-file.ts
parent4283d1f8a0bc3953e65962a2364c903d0015f047 (diff)
downloaddispatch-7fb3269c698ae583ea7997ce206c4ae252fd3218.tar.gz
dispatch-7fb3269c698ae583ea7997ce206c4ae252fd3218.zip
feat(backend): credential-store + model selection/catalog (GET /models) + per-turn cwd through orchestrator/transport/host-bin
Diffstat (limited to 'packages/tool-read-file/src/read-file.ts')
-rw-r--r--packages/tool-read-file/src/read-file.ts21
1 files changed, 12 insertions, 9 deletions
diff --git a/packages/tool-read-file/src/read-file.ts b/packages/tool-read-file/src/read-file.ts
index b5bb0f1..d4a4de8 100644
--- a/packages/tool-read-file/src/read-file.ts
+++ b/packages/tool-read-file/src/read-file.ts
@@ -103,7 +103,7 @@ export function createReadFileTool(workingDirectory: string): ToolContract {
required: ["path"],
},
concurrencySafe: true,
- async execute(args: unknown, _ctx): Promise<ToolResult> {
+ async execute(args: unknown, ctx): Promise<ToolResult> {
const validated = validateArgs(args);
if ("error" in validated) {
return { content: validated.error, isError: true };
@@ -111,11 +111,14 @@ export function createReadFileTool(workingDirectory: string): ToolContract {
const { path: relPath, offset, limit } = validated;
- // Resolve the requested path against the working directory.
- const resolvedPath = resolve(workdir, relPath);
+ // Effective base: per-turn ctx.cwd overrides the baked workdir.
+ const effectiveBase = ctx.cwd ? resolve(ctx.cwd) : workdir;
- // Basic prefix check (catches ".." and absolute paths outside workdir).
- if (!isPathWithinWorkdir(resolvedPath, workdir)) {
+ // Resolve the requested path against the effective base.
+ const resolvedPath = resolve(effectiveBase, relPath);
+
+ // Basic prefix check (catches ".." and absolute paths outside effectiveBase).
+ if (!isPathWithinWorkdir(resolvedPath, effectiveBase)) {
return {
content: `Error: Path "${relPath}" is outside the working directory.`,
isError: true,
@@ -124,11 +127,11 @@ export function createReadFileTool(workingDirectory: string): ToolContract {
// Symlink hardening: realpath both and re-check containment.
let realResolved: string;
- let realWorkdir: string;
+ let realBase: string;
try {
- [realResolved, realWorkdir] = await Promise.all([
+ [realResolved, realBase] = await Promise.all([
realpath(resolvedPath),
- realpath(workdir),
+ realpath(effectiveBase),
]);
} catch (err: unknown) {
const code = (err as NodeJS.ErrnoException).code;
@@ -141,7 +144,7 @@ export function createReadFileTool(workingDirectory: string): ToolContract {
};
}
- if (!isPathWithinWorkdir(realResolved, realWorkdir)) {
+ if (!isPathWithinWorkdir(realResolved, realBase)) {
return {
content: `Error: Path "${relPath}" is outside the working directory.`,
isError: true,