Repository navigation
feat(core): add configurable editing tool selection - #63982
jacobEAdamson wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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
editingconfig, 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 staysummarywith 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 wholeexperimentalobject from the last config file that has one. A project config setting any other experimental key, such assubagent_depth, silently drops a globaleditingblock. - Absolute paths in
diffoutput.diffembedsfile.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.
| model: ModelRef | undefined, | ||
| editing: ConfigExperimental.Editing | undefined, | ||
| ): ConfigExperimental.EditingResult { | ||
| if (!editing) return "counts" |
There was a problem hiding this comment.
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?
| return | ||
| Effect.gen(function* () { | ||
| const entries = yield* config.entries() | ||
| const tools = selectEditingTools(event.model, Config.latest(entries, "experimental")?.editing) |
There was a problem hiding this comment.
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.
|
Addressed in 9ce09cd.
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 ( |
There was a problem hiding this comment.
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.
Issue for this PR
Closes #63981
Type of change
What does this PR do?
OpenCode currently picks between
patchandedit/writewith 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.editingconfig with:addandremovedeltas over the existing model heuristic, limited topatch,edit, andwriterulesmatched against${providerID}/${model.id}, with the last matching rule winningresult_style:summary,counts, ordiff, defaulting tosummaryadd/removeThe 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.
countsadds+N -M;diffadds 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.mdxandtools.mdx.How did you verify your code works?
cd packages/core && bun test test/tool-patch.test.ts: 52 pass, 0 failcd packages/core && bun test test/config/config.test.ts -t "experimental editing": 7 passSuccess. Updated the following files:\nA default-style.txtexperimental.editingplus a later config settingsubagent_depthbun typecheckinpackages/coreandpackages/schema: passoxlinton the changed TypeScript files: 0 problemsA default-gpt2.txtwith no countsresult_style: "diff"returned counts plus the hunk, with noIndex:line or absolute pathbun run checkdoes not pass at the base commit:script/check-greys.tsreports 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
Added by the opencode bot (AI-generated).
Public API: adds optional config key
experimental.editing(backwards compatible; default patch output unchanged)