From 6bffb2c40f178713d8ed0f577e7cd2c4368cbe95 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 12:32:10 +0900 Subject: [PATCH] feat(shared): add replaceToolArgs helper for safe tool-args mutation opencode >=1.14 freezes output.args via Immer before plugin hooks run. Direct property assignment or Object.assign on a frozen object throws TypeError. This helper replaces output.args with a shallow clone containing the patch, avoiding mutation of the frozen original. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/shared/index.ts | 1 + src/shared/replace-tool-args.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/shared/replace-tool-args.ts 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 } +}