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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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<string, unknown> },
|
||||
patch: Record<string, unknown>,
|
||||
): void {
|
||||
output.args = { ...output.args, ...patch }
|
||||
}
|
||||
Reference in New Issue
Block a user