cleanup(editor): remove dead path-base plumbing

This commit is contained in:
Tianyi Cui
2026-07-29 23:50:52 +08:00
parent 7f5aa2d053
commit 84394e596d

View File

@@ -105,15 +105,13 @@ class MutationPolicy {
async function resolveTarget(
ctx: Context,
path: string,
exec: ToolRunContext,
workspaceRoot?: string,
signal: AbortSignal,
): Promise<FsTarget> {
if (path.trim().length === 0) throw new Error('path must be a non-empty string')
if (!isAbsolute(path)) {
throw new Error(`The path ${path} is not an absolute path, it should start with \`/\`. Maybe you meant /${path}?`)
}
const cwd = exec.agent?.session.header.cwd ?? workspaceRoot
return ctx.fs.resolve(path, cwd === undefined ? { signal: exec.signal } : { cwd, signal: exec.signal })
return ctx.fs.resolve(path, { signal })
}
async function statExisting(
@@ -238,7 +236,7 @@ async function viewPath(
maxOutputChars: number,
exec: ToolRunContext,
): Promise<string> {
const target = await resolveTarget(ctx, path, exec)
const target = await resolveTarget(ctx, path, exec.signal)
const info = await statExisting(ctx, target, 'view', exec)
if (info.type === 'directory') {
if (viewRange !== undefined) {
@@ -263,7 +261,7 @@ async function createFile(
): Promise<string> {
const content = requiredForCommand(fileText, 'file_text', 'create')
const sandboxPolicy = policy.resolve(exec)
const target = await resolveTarget(ctx, path, exec, sandboxPolicy?.workspaceRoot)
const target = await resolveTarget(ctx, path, exec.signal)
if (await ctx.fs.stat(target, exec.signal) !== undefined) {
throw new Error(`File already exists at: ${target.displayPath}. Cannot overwrite files using command \`create\`.`)
}
@@ -298,7 +296,7 @@ async function replaceInFile(
exec: ToolRunContext,
): Promise<string> {
const sandboxPolicy = policy.resolve(exec)
const target = await resolveTarget(ctx, path, exec, sandboxPolicy?.workspaceRoot)
const target = await resolveTarget(ctx, path, exec.signal)
const intent = await ctx.waterfall('fs/edit-intent', target, exec, () => undefined)
const oldValue = requiredForCommand(oldStr, 'old_str', 'str_replace', false)
const newValue = newStr ?? ''
@@ -351,7 +349,7 @@ async function insertInFile(
if (insertLine === undefined) throw new Error('Parameter `insert_line` is required for command: insert')
const value = requiredForCommand(newStr, 'new_str', 'insert')
const sandboxPolicy = policy.resolve(exec)
const target = await resolveTarget(ctx, path, exec, sandboxPolicy?.workspaceRoot)
const target = await resolveTarget(ctx, path, exec.signal)
const intent = await ctx.waterfall('fs/edit-intent', target, exec, () => undefined)
const info = await statExisting(ctx, target, 'insert', exec)
if (info.type !== 'file') {