diff --git a/src/shared/index.ts b/src/shared/index.ts index 07103d094..17ebfd0c9 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -84,3 +84,4 @@ export * from "./task-system-enabled" export * from "./parse-tools-config" export { parseModelString } from "./model-string-parser" export { EXCLUDED_DIRS } from "./excluded-dirs" +export * from "./replace-tool-args" diff --git a/src/shared/replace-tool-args.ts b/src/shared/replace-tool-args.ts new file mode 100644 index 000000000..0a0566ad3 --- /dev/null +++ b/src/shared/replace-tool-args.ts @@ -0,0 +1,16 @@ +/** + * Safely replace tool arguments without mutating frozen objects. + * + * opencode >=1.14 may freeze `output.args` via Immer before plugin hooks run. + * Direct property assignment (`output.args.key = value`) or `Object.assign(output.args, patch)` + * throws `TypeError: Attempted to assign to readonly property` on a frozen object. + * + * This helper replaces `output.args` with a shallow clone containing the patch, + * which works regardless of whether the original args object is frozen. + */ +export function replaceToolArgs( + output: { args: Record }, + patch: Record, +): void { + output.args = { ...output.args, ...patch } +}