Skip to content

feat(core): add configurable editing tool selection - #63982

Open
jacobEAdamson wants to merge 2 commits into
anomalyco:devfrom
jacobEAdamson:patch-tool-config
Open

jacobEAdamson wants to merge 2 commits into
anomalyco:devfrom
jacobEAdamson:patch-tool-config

Conversation

@jacobEAdamson

@jacobEAdamson jacobEAdamson commented Nov 14, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #63981

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenCode currently picks between patch and edit/write with a hardcoded model-ID heuristic, and there is no supported way to change that choice or the amount of patch output returned to the model.

This adds experimental.editing config with:

  • add and remove deltas over the existing model heuristic, limited to patch, edit, and write
  • per-model rules matched against ${providerID}/${model.id}, with the last matching rule winning
  • result_style: summary, counts, or diff, defaulting to summary
  • decode-time validation for invalid regular expressions, unknown tools, and overlapping add/remove

The existing heuristic remains the base. A matching rule replaces the top-level delta rather than merging with it. Other tools are untouched. Without config, the patch result is unchanged. counts adds +N -M; diff adds the applied diff without file headers and caps very large output.

Example:

{
  "experimental": {
    "editing": {
      "rules": [
        {
          "match": "deepseek.*(?:v4|flash-latest|pro-latest)",
          "add": ["patch"],
          "remove": ["edit", "write"],
          "result_style": "diff"
        }
      ]
    }
  }
}

Docs are updated in config.mdx and tools.mdx.

How did you verify your code works?

  • cd packages/core && bun test test/tool-patch.test.ts: 52 pass, 0 fail
  • cd packages/core && bun test test/config/config.test.ts -t "experimental editing": 7 pass
  • Regression test asserts the exact base patch result with no config: Success. Updated the following files:\nA default-style.txt
  • Regression test covers experimental.editing plus a later config setting subagent_depth
  • bun typecheck in packages/core and packages/schema: pass
  • oxlint on the changed TypeScript files: 0 problems
  • Rebuilt a local Windows binary and ran it end-to-end:
    • GPT model with no matching editing rule returned A default-gpt2.txt with no counts
    • DeepSeek model with result_style: "diff" returned counts plus the hunk, with no Index: line or absolute path
  • OpenChamber VS Code extension is pointed at the rebuilt binary for a manual check

bun run check does not pass at the base commit: script/check-greys.ts reports 172 pre-existing greys off the shared scale. This diff does not touch CSS or any of those files. Targeted checks above pass.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds optional config key experimental.editing (backwards compatible; default patch output unchanged)

Add experimental.editing config with per-model add/remove rules and result_style. Rules apply over the existing model heuristic, last match wins, and non-editing tools are untouched.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool selection and result_style work as described, but two problems should be fixed before merge.

I drove OpenCode from source on the base and on this branch with the simulated model (gpt-sim-model, which gets patch by default). A rule removing patch and adding edit/write changed the offered tools as expected. result_style: "diff" returned the diff. The added tests pass, and tsc -b passes in packages/core.

Public API: adds the optional config key experimental.editing (add, remove, result_style, rules[].match/add/remove/result_style). Existing configs are unaffected. However, the patch tool's output to the model changes for every user, even without this key (see the inline comments).

Concerns, most important first:

  • Default output changes. With no editing config, results now include (+N -M) counts and a new "Trust this result…" line. That contradicts "default behavior remains unchanged" in #63981 and changes the prompt for every GPT user. The default should stay summary with no trust line; prompt wording changes can go in a separate PR.
  • Settings ignored when another config file sets experimental. Config.latest(entries, "experimental") returns the whole experimental object from the last config file that has one. A project config setting any other experimental key, such as subagent_depth, silently drops a global editing block.
  • Absolute paths in diff output. diff embeds file.patch, which carries the absolute file path in its headers (Index: /tmp/.../b.txt) and the full content of large added files. Consider trimming those before sending them to the model.

Comment thread packages/core/src/tool/plugin/patch.ts Outdated
model: ModelRef | undefined,
editing: ConfigExperimental.Editing | undefined,
): ConfigExperimental.EditingResult {
if (!editing) return "counts"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any experimental.editing config this returns counts, so every existing patch user now gets (+N -M) on each line. I confirmed this on a live run: the base returns A b.txt, this branch returns A b.txt (+1 -0). Defaulting to summary would keep today's output, as #63981 promises.

This line is added to every patch result, whatever the config, so it changes the model-facing prompt for all users. That is a separate behaviour change from making selection configurable. Could it be dropped here, or proposed on its own?

Comment thread packages/core/src/tool/plugin/patch.ts Outdated
return
Effect.gen(function* () {
const entries = yield* config.entries()
const tools = selectEditingTools(event.model, Config.latest(entries, "experimental")?.editing)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config.latest(entries, "experimental") takes the whole experimental object from the last config file that defines one. A global config with experimental.editing plus a project config with only experimental.subagent_depth gives editing === undefined; I checked this with two Documents. image-generate.ts reads per field for this reason ("Read per field so a later config that sets other experimental options doesn't hide this one"). The same applies to the read at line 283.

Default result_style to summary and drop the trust line, so patch results are unchanged without config. Read experimental.editing per field so unrelated experimental settings do not hide it. Trim diff headers and cap large diffs before returning them to the model.
@jacobEAdamson

Copy link
Copy Markdown
Author

Addressed in 9ce09cd.

  • Default result_style is now summary, and the trust line is gone. A regression test asserts the exact base output with no config: Success. Updated the following files:\nA default-style.txt.
  • experimental.editing is read per field, following the image-generate.ts pattern. A regression test covers an editing config followed by a config that sets experimental.subagent_depth.
  • diff output starts at the first hunk, so file headers and absolute paths are dropped, and it caps at 200 lines or 12,000 characters with ... diff truncated .... Tests cover both the missing headers and a large added file.

Re-verified: 52 tool tests pass, 7 config tests pass, core/schema typecheck pass, oxlint clean. Rebuilt the local binary and checked GPT default output (A default-gpt2.txt, no counts) and DeepSeek diff output (counts plus hunk, no Index: or absolute path).

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are fixed: with no editing config the patch result is back to the base output (no counts, no trust line), and editing is now read per field, so a later config setting another experimental key no longer hides it. The diff style now drops the Index:/absolute-path headers and caps the output.

I checked it by driving OpenCode from source with the simulated model. editing: {} returned A b.txt as on the base, and result_style: "diff" returned A b.txt (+1 -0) plus only the hunk. The patch and config tests pass, and tsc -b passes in packages/core.

Public API: adds the optional config key experimental.editing (add, remove, result_style, rules[]). It is backwards compatible, and the default patch output is unchanged.

No further concerns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Configurable editing tool selection and patch result style

1 participant