opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Add 'displayInput' to bash tool schema

Open Alb-O opened this issue 1 month ago • 7 comments

This keeps tool metadata callbacks in sync with the in-memory toolcall state so display inputs can be passed through to completion. processor.ts now prefers a metadata-updated input when finishing a tool call, allowing modified displays of commands without changing the actual execution.

  • packages/opencode/src/session/prompt.ts: metadata callback updates the live toolcall entry (input/metadata/title/time/displayInput) before persisting, keeping the processor’s map aligned.
  • packages/opencode/src/session/processor.ts: completion/error handling uses match.state.displayInput (from metadata), so the UI shows the plugin-provided display args.

Use case: nix develop bash wrapper plugin

A plugin can wrap the bash tool and modify the final displayed command via displayInput. This is shown to the user through the UI and also modifies the agent history:

"tool.execute.before": async ({ tool }, state) => {
  if (tool.toLowerCase() !== "bash") return
  const command = state.args?.command
  if (!command) return

  // Show the unwrapped command in the UI
  state.args.displayInput = { ...state.args }

  // Run the wrapped command for execution
  state.args.command = `nix develop --quiet -c bash -c "${command.replace(/"/g, '\\"')}"`
}

Before:

$ nix develop --quiet -c bash -c "echo \"hello\""

After:

$ echo "hello"

This has many use cases other than just nix, e.g. sandbox-esque wrappers where the full wrapped command is not relevant enough to be constantly showing to the user or agent, and would otherwise clutter history.

Alb-O avatar Dec 10 '25 11:12 Alb-O

/review

rekram1-node avatar Dec 10 '25 15:12 rekram1-node

/review

rekram1-node avatar Dec 13 '25 05:12 rekram1-node

idk if that was worth it edit: yeah that broke it

Alb-O avatar Dec 13 '25 07:12 Alb-O

should be good to go tmr if i forget just @ me or dm

rekram1-node avatar Dec 15 '25 06:12 rekram1-node