opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Add `short_description` field for agents and agent details dialog

Open dibenkobit opened this issue 3 weeks ago • 4 comments

Closes #4825

Summary

Previously, when you created an agent via opencode agent create, the description field was populated with a long prompt intended for the model. In /agents, this made the list view almost unreadable.

This PR introduces three changes:

  1. short_description field

    • New field used for displaying agents in /agents.
    • If short_description is not set, the UI falls back to a truncated version of description.
  2. Agent details dialog (Ctrl+E)

    • You can now open a scrollable details dialog for custom agents.
    • The dialog shows the whenToUse (description) text, so the list can stay compact while the full content is still accessible when needed.
  3. Dynamic description truncation

    • Descriptions in /agents are now truncated based on the current terminal width, so they fit neatly into the dialog without overflowing.

Why this approach

  • short_description gives us a dedicated, human‑readable summary for the UI instead of trying to reuse the full whenToUse text.
  • The details dialog preserves the ability to inspect the full prompt when needed without cluttering the main list.
  • Truncation based on terminal width keeps /agents readable across different environments and terminal sizes.

Focus bug fix

While implementing the details dialog, a focus bug surfaced: switching between dialogs (e.g., /agents ↔ agent details) caused the main input to lose focus.

Root cause:

  • There was a race between keyboard handlers when dialogs were opened/closed in quick succession.
  • replace() could overwrite an existing valid saved focus reference.
  • refocus() was being called even when a new dialog was about to open immediately after.

Fix:

  • Prevent replace() from clobbering a valid saved focus reference.
  • Skip refocus() when a new dialog is opened right after closing the previous one.

How to test

  • [x] Have an agent that was created before the update (to verify backward compatibility).

  • [x] Create a new agent with short_description set.

  • [x] Open /agents.

  • [x] Confirm both agents show a visible description:

    • New agent shows short_description.
    • Old agent shows a truncated description.
  • [x] Verify that text is truncated correctly according to the dialog/terminal width.

  • [x] Focus a native agent and verify the footer is not shown.

  • [x] Focus a custom agent and check that the Ctrl+E hotkey is shown in the footer.

  • [x] Press Ctrl+E on a custom agent and confirm the agent details dialog opens.

  • [x] In the details dialog, verify that the scrollbar works with both keyboard and mouse.

  • [x] Close the details dialog and confirm the /agents dialog reappears with the same selection preserved.

  • [x] Open other dialogs (e.g., /models, /sessions) and confirm their behavior and focus handling are unchanged.

Demo

Demo

dibenkobit avatar Dec 05 '25 13:12 dibenkobit