mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
feat(core): enable editing tools in full Code Mode (#64386)
This commit is contained in:
committed by
GitHub
Unverified
parent
fb67e33a13
commit
edd81e580a
@@ -9,6 +9,9 @@ export * as EditTool from "./edit.js"
|
||||
import type { Context } from "@opencode/plugin/effect/plugin"
|
||||
import { ToolFailure } from "@opencode/ai/effect"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { Config } from "../../config.js"
|
||||
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
|
||||
import { Flag } from "../../flag.js"
|
||||
import { toolFailure } from "../runtime.js"
|
||||
import { Environment } from "../../environment/index.js"
|
||||
import { FileMutation } from "../../file-mutation.js"
|
||||
@@ -261,12 +264,15 @@ export const Plugin = {
|
||||
const environment = yield* Environment.Service
|
||||
const location = yield* Location.Service
|
||||
const permission = yield* Permission.Service
|
||||
const config = yield* Config.Service
|
||||
const loaded = yield* ConfigEntryObserver.observe(config, ctx.event, ctx.tool.reload())
|
||||
const flags = yield* Flag.Service
|
||||
|
||||
yield* ctx.tool
|
||||
.transform((editor) =>
|
||||
editor.add({
|
||||
name,
|
||||
options: { codemode: false, permission: "edit" },
|
||||
options: { codemode: flags.resolve(loaded.entries).full_codemode.enabled, permission: "edit" },
|
||||
description:
|
||||
"Edit the contents of a file by finding and replacing exact text. When editing text from Read output, preserve the exact indentation (tabs or spaces) and omit the line-number prefix, such as `1: `. Never include the prefix in oldString or newString. Write line breaks as \\n; the file's existing CRLF or LF line endings are matched and preserved. To change line endings themselves, make oldString and newString differ only in \\r; that edit applies to the exact bytes. If there is no exact match, the edit retries while ignoring typographic quote, dash, and space variants, then trailing whitespace on each line. The edit fails if oldString is not found. By default, oldString must identify a UNIQUE location. Multiple matches FAIL unless replaceAll is true. Add more surrounding context to disambiguate, or set replaceAll to true to replace every occurrence. Use replaceAll when the change should apply to every occurrence, such as renaming a variable.",
|
||||
input: Input,
|
||||
|
||||
@@ -6,6 +6,9 @@ import { ToolFailure } from "@opencode/ai/effect"
|
||||
import { FileDiff } from "@opencode/schema/file-diff"
|
||||
import { Effect, Result, Schema } from "effect"
|
||||
import { Bom } from "@opencode/util/bom"
|
||||
import { Config } from "../../config.js"
|
||||
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
|
||||
import { Flag } from "../../flag.js"
|
||||
import { toolFailure } from "../runtime.js"
|
||||
import { Environment } from "../../environment/index.js"
|
||||
import { Formatter } from "../../formatter.js"
|
||||
@@ -57,12 +60,15 @@ export const Plugin = {
|
||||
const formatter = yield* Formatter.Service
|
||||
const location = yield* Location.Service
|
||||
const permission = yield* Permission.Service
|
||||
const config = yield* Config.Service
|
||||
const loaded = yield* ConfigEntryObserver.observe(config, ctx.event, ctx.tool.reload())
|
||||
const flags = yield* Flag.Service
|
||||
|
||||
yield* ctx.tool
|
||||
.transform((editor) =>
|
||||
editor.add({
|
||||
name,
|
||||
options: { codemode: false, permission: "edit" },
|
||||
options: { codemode: flags.resolve(loaded.entries).full_codemode.enabled, permission: "edit" },
|
||||
description: DESCRIPTION,
|
||||
input: Input,
|
||||
freeform: { type: "lark", grammar: GRAMMAR },
|
||||
|
||||
@@ -9,7 +9,10 @@ export * as WriteTool from "./write.js"
|
||||
import type { Context } from "@opencode/plugin/effect/plugin"
|
||||
import { ToolFailure } from "@opencode/ai/effect"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { Config } from "../../config.js"
|
||||
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
|
||||
import { FileWrite } from "../../file-write.js"
|
||||
import { Flag } from "../../flag.js"
|
||||
|
||||
export const name = "write"
|
||||
|
||||
@@ -33,12 +36,15 @@ export const Plugin = {
|
||||
id: "opencode.tool.write",
|
||||
effect: Effect.fn("WriteTool.Plugin")(function* (ctx: Context) {
|
||||
const fileWrite = yield* FileWrite.Service
|
||||
const config = yield* Config.Service
|
||||
const loaded = yield* ConfigEntryObserver.observe(config, ctx.event, ctx.tool.reload())
|
||||
const flags = yield* Flag.Service
|
||||
|
||||
yield* ctx.tool
|
||||
.transform((editor) =>
|
||||
editor.add({
|
||||
name,
|
||||
options: { codemode: false, permission: "edit" },
|
||||
options: { codemode: flags.resolve(loaded.entries).full_codemode.enabled, permission: "edit" },
|
||||
description:
|
||||
"Writes a file to the local filesystem, overwriting if one exists.\n\nMissing parent directories are created automatically.\n\nUse this tool to create new files or overwrite existing files. For partial changes, use the edit tool instead.",
|
||||
input: Input,
|
||||
|
||||
@@ -7,6 +7,8 @@ import { LayerNode } from "@opencode/util/effect/layer-node"
|
||||
import { Environment } from "@opencode/core/environment/index"
|
||||
import { FileMutation } from "@opencode/core/file-mutation"
|
||||
import { FileWrite } from "@opencode/core/file-write"
|
||||
import { Config } from "@opencode/core/config"
|
||||
import { Flag } from "@opencode/core/flag"
|
||||
import { Formatter } from "@opencode/core/formatter"
|
||||
import { Location } from "@opencode/core/location"
|
||||
import { FileAccess } from "@opencode/core/file-access"
|
||||
@@ -26,7 +28,16 @@ import { toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "
|
||||
const editToolNode = makeLocationNode({
|
||||
name: "test/edit-tool-plugin",
|
||||
layer: Layer.effectDiscard(registerToolPlugin(EditTool.Plugin)),
|
||||
deps: [Tool.node, FileWrite.node, FileMutation.node, Environment.node, Location.node, Permission.node],
|
||||
deps: [
|
||||
Tool.node,
|
||||
FileWrite.node,
|
||||
FileMutation.node,
|
||||
Environment.node,
|
||||
Location.node,
|
||||
Permission.node,
|
||||
Config.node,
|
||||
Flag.node,
|
||||
],
|
||||
})
|
||||
|
||||
const sessionID = Session.ID.make("ses_edit_tool_test")
|
||||
@@ -103,6 +114,7 @@ const withTool = <A, E, R>(
|
||||
Location.node.replace(activeLocation),
|
||||
Formatter.node.replace(fixture.formatter),
|
||||
Permission.node.replace(fixture.permission),
|
||||
Config.node.replace(Config.testLayer()),
|
||||
]),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -5,6 +5,8 @@ import { Effect, Exit, Layer } from "effect"
|
||||
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
|
||||
import { LayerNode } from "@opencode/util/effect/layer-node"
|
||||
import { Environment } from "@opencode/core/environment/index"
|
||||
import { Config } from "@opencode/core/config"
|
||||
import { Flag } from "@opencode/core/flag"
|
||||
import { Formatter } from "@opencode/core/formatter"
|
||||
import { FileMutation } from "@opencode/core/file-mutation"
|
||||
import { Location } from "@opencode/core/location"
|
||||
@@ -47,6 +49,8 @@ const patchToolNode = makeLocationNode({
|
||||
Formatter.node,
|
||||
Location.node,
|
||||
Permission.node,
|
||||
Config.node,
|
||||
Flag.node,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -137,6 +141,7 @@ const withTool = <A, E, R>(
|
||||
Location.node.replace(activeLocation),
|
||||
Formatter.node.replace(formatter),
|
||||
Permission.node.replace(permission),
|
||||
Config.node.replace(Config.testLayer()),
|
||||
]),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -4,6 +4,8 @@ import { describe, expect } from "bun:test"
|
||||
import { Effect, Exit, Layer, Tracer } from "effect"
|
||||
import { FileMutation } from "@opencode/core/file-mutation"
|
||||
import { FileWrite } from "@opencode/core/file-write"
|
||||
import { Config } from "@opencode/core/config"
|
||||
import { Flag } from "@opencode/core/flag"
|
||||
import { Formatter } from "@opencode/core/formatter"
|
||||
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
|
||||
import { LayerNode } from "@opencode/util/effect/layer-node"
|
||||
@@ -26,7 +28,7 @@ import { toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "
|
||||
const writeToolNode = makeLocationNode({
|
||||
name: "test/write-tool-plugin",
|
||||
layer: Layer.effectDiscard(registerToolPlugin(WriteTool.Plugin)),
|
||||
deps: [Tool.node, FileWrite.node],
|
||||
deps: [Tool.node, FileWrite.node, Config.node, Flag.node],
|
||||
})
|
||||
|
||||
const sessionID = Session.ID.make("ses_write_tool_test")
|
||||
@@ -96,6 +98,7 @@ const withTool = <A, E, R>(
|
||||
Location.node.replace(activeLocation),
|
||||
Formatter.node.replace(fixture.formatter),
|
||||
Permission.node.replace(fixture.permission),
|
||||
Config.node.replace(Config.testLayer()),
|
||||
]),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user