Add `short_description` field for agents and agent details dialog
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:
-
short_descriptionfield- New field used for displaying agents in
/agents. - If
short_descriptionis not set, the UI falls back to a truncated version ofdescription.
- New field used for displaying agents in
-
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.
-
Dynamic description truncation
- Descriptions in
/agentsare now truncated based on the current terminal width, so they fit neatly into the dialog without overflowing.
- Descriptions in
Why this approach
short_descriptiongives us a dedicated, human‑readable summary for the UI instead of trying to reuse the fullwhenToUsetext.- The details dialog preserves the ability to inspect the full prompt when needed without cluttering the main list.
- Truncation based on terminal width keeps
/agentsreadable 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_descriptionset. -
[x] Open
/agents. -
[x] Confirm both agents show a visible description:
- New agent shows
short_description. - Old agent shows a truncated
description.
- New agent shows
-
[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+Ehotkey is shown in the footer. -
[x] Press
Ctrl+Eon 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
/agentsdialog reappears with the same selection preserved. -
[x] Open other dialogs (e.g.,
/models,/sessions) and confirm their behavior and focus handling are unchanged.