refactor(tool): yield InstanceState context (#25199)

This commit is contained in:
Kit Langton
2026-04-30 21:01:06 -04:00
committed by GitHub
parent 5c2e06f353
commit 668d77bb4e
8 changed files with 51 additions and 36 deletions

View File

@@ -13,7 +13,7 @@ import { File } from "../file"
import { FileWatcher } from "../file/watcher"
import { Bus } from "../bus"
import { Format } from "../format"
import { Instance } from "../project/instance"
import { InstanceState } from "@/effect/instance-state"
import { Snapshot } from "@/snapshot"
import { assertExternalDirectoryEffect } from "./external-directory"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
@@ -76,9 +76,10 @@ export const EditTool = Tool.define(
throw new Error("No changes to apply: oldString and newString are identical.")
}
const instance = yield* InstanceState.context
const filePath = path.isAbsolute(params.filePath)
? params.filePath
: path.join(Instance.directory, params.filePath)
: path.join(instance.directory, params.filePath)
yield* assertExternalDirectoryEffect(ctx, filePath)
let diff = ""
@@ -96,7 +97,7 @@ export const EditTool = Tool.define(
diff = trimDiff(createTwoFilesPatch(filePath, filePath, contentOld, contentNew))
yield* ctx.ask({
permission: "edit",
patterns: [path.relative(Instance.worktree, filePath)],
patterns: [path.relative(instance.worktree, filePath)],
always: ["*"],
metadata: {
filepath: filePath,
@@ -139,7 +140,7 @@ export const EditTool = Tool.define(
)
yield* ctx.ask({
permission: "edit",
patterns: [path.relative(Instance.worktree, filePath)],
patterns: [path.relative(instance.worktree, filePath)],
always: ["*"],
metadata: {
filepath: filePath,
@@ -201,7 +202,7 @@ export const EditTool = Tool.define(
diff,
filediff,
},
title: `${path.relative(Instance.worktree, filePath)}`,
title: `${path.relative(instance.worktree, filePath)}`,
output,
}
}),