fix(tools): resolve Read/Write/Edit paths against workspace directory
Previously, Read/Write/Edit tools used the global tool instances from pi-coding-agent which had process.cwd() baked in at import time. Since the gateway starts from /root/dev/ai/clawdbot, relative paths like 'SOUL.md' would incorrectly resolve there instead of the agent's workspace (/root/clawd). This fix: - Adds workspaceDir option to createClawdbotCodingTools - Creates fresh Read/Write/Edit tools bound to workspaceDir - Adds cwd option to Bash tool defaults for consistency - Passes effectiveWorkspace from pi-embedded-runner Absolute paths and ~/... paths are unaffected. Sandboxed sessions continue to use sandbox root as before. Includes tests for Read/Write/Edit workspace path resolution.
This commit is contained in:
committed by
Peter Steinberger
parent
bf0184d0cf
commit
de5b75eff6
@@ -531,6 +531,7 @@ export function createClawdbotCodingTools(options?: {
|
||||
sandbox?: SandboxContext | null;
|
||||
sessionKey?: string;
|
||||
agentDir?: string;
|
||||
workspaceDir?: string;
|
||||
config?: ClawdbotConfig;
|
||||
abortSignal?: AbortSignal;
|
||||
/**
|
||||
@@ -571,20 +572,30 @@ export function createClawdbotCodingTools(options?: {
|
||||
]);
|
||||
const sandboxRoot = sandbox?.workspaceDir;
|
||||
const allowWorkspaceWrites = sandbox?.workspaceAccess !== "ro";
|
||||
const workspaceRoot = options?.workspaceDir ?? process.cwd();
|
||||
|
||||
const base = (codingTools as unknown as AnyAgentTool[]).flatMap((tool) => {
|
||||
if (tool.name === readTool.name) {
|
||||
return sandboxRoot
|
||||
? [createSandboxedReadTool(sandboxRoot)]
|
||||
: [createClawdbotReadTool(tool)];
|
||||
if (sandboxRoot) {
|
||||
return [createSandboxedReadTool(sandboxRoot)];
|
||||
}
|
||||
const freshReadTool = createReadTool(workspaceRoot);
|
||||
return [createClawdbotReadTool(freshReadTool)];
|
||||
}
|
||||
if (tool.name === bashToolName) return [];
|
||||
if (sandboxRoot && (tool.name === "write" || tool.name === "edit")) {
|
||||
return [];
|
||||
if (tool.name === "write") {
|
||||
if (sandboxRoot) return [];
|
||||
return [createWriteTool(workspaceRoot)];
|
||||
}
|
||||
if (tool.name === "edit") {
|
||||
if (sandboxRoot) return [];
|
||||
return [createEditTool(workspaceRoot)];
|
||||
}
|
||||
return [tool as AnyAgentTool];
|
||||
});
|
||||
const bashTool = createBashTool({
|
||||
...options?.bash,
|
||||
cwd: options?.workspaceDir,
|
||||
allowBackground,
|
||||
scopeKey,
|
||||
sandbox: sandbox
|
||||
|
||||
Reference in New Issue
Block a user