Skip to content

Commit 1ef332b

Browse files
committed
feat(agents): add shortDescription and agent details modal (anomalyco#4825)
1 parent f1138b9 commit 1ef332b

9 files changed

Lines changed: 151 additions & 16 deletions

File tree

‎packages/opencode/src/agent/agent.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export namespace Agent {
1212
.object({
1313
name: z.string(),
1414
description: z.string().optional(),
15+
shortDescription: z.string().optional(),
1516
mode: z.enum(["subagent", "primary", "all"]),
1617
builtIn: z.boolean(),
1718
topP: z.number().optional(),
@@ -182,7 +183,7 @@ export namespace Agent {
182183
tools: {},
183184
builtIn: false,
184185
}
185-
const { name, model, prompt, tools, description, temperature, top_p, mode, permission, color, ...extra } = value
186+
const { name, model, prompt, tools, description, short_description, temperature, top_p, mode, permission, color, ...extra } = value
186187
item.options = {
187188
...item.options,
188189
...extra,
@@ -199,6 +200,7 @@ export namespace Agent {
199200
...item.tools,
200201
}
201202
if (description) item.description = description
203+
if (short_description) item.shortDescription = short_description
202204
if (temperature != undefined) item.temperature = temperature
203205
if (top_p != undefined) item.topP = top_p
204206
if (mode) item.mode = mode
@@ -244,6 +246,7 @@ export namespace Agent {
244246
model: model.language,
245247
schema: z.object({
246248
identifier: z.string(),
249+
shortSummary: z.string(),
247250
whenToUse: z.string(),
248251
systemPrompt: z.string(),
249252
}),

‎packages/opencode/src/agent/generate.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ When a user describes what they want an agent to do, you will:
5959
Your output must be a valid JSON object with exactly these fields:
6060
{
6161
"identifier": "A unique, descriptive identifier using lowercase letters, numbers, and hyphens (e.g., 'code-reviewer', 'api-docs-writer', 'test-generator')",
62+
"shortSummary": "A brief, human-readable summary of the agent's purpose (max 40 characters) for display in agent listings. Should be concise and descriptive, e.g., 'Reviews code for best practices and potential issues'",
6263
"whenToUse": "A precise, actionable description starting with 'Use this agent when...' that clearly defines the triggering conditions and use cases. Ensure you include examples as described above.",
6364
"systemPrompt": "The complete system prompt that will govern the agent's behavior, written in second person ('You are...', 'You will...') and structured for maximum clarity and effectiveness"
6465
}

‎packages/opencode/src/cli/cmd/agent.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const AgentCreateCommand = cmd({
112112

113113
const frontmatter: any = {
114114
description: generated.whenToUse,
115+
short_description: generated.shortSummary,
115116
mode: modeResult,
116117
}
117118
if (Object.keys(tools).length > 0) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { createMemo, onMount } from "solid-js"
2+
import { useLocal } from "@tui/context/local"
3+
import { useDialog } from "@tui/ui/dialog"
4+
import { useKeyboard, useTerminalDimensions } from "@opentui/solid"
5+
import { useTheme } from "@tui/context/theme"
6+
import { ScrollBoxRenderable, TextAttributes } from "@opentui/core"
7+
import { DialogAgent } from "./dialog-agent"
8+
9+
export function DialogAgentDetails(props: { agentName: string }) {
10+
const local = useLocal()
11+
const dialog = useDialog()
12+
const { theme } = useTheme()
13+
const dimensions = useTerminalDimensions()
14+
15+
const agent = createMemo(() => local.agent.list().find((a) => a.name === props.agentName))
16+
const description = createMemo(() => agent()?.description ?? "No description available")
17+
const maxHeight = createMemo(() => Math.floor(dimensions().height / 2) - 4)
18+
19+
let scroll: ScrollBoxRenderable
20+
21+
onMount(() => {
22+
dialog.setSize("large")
23+
})
24+
25+
useKeyboard((evt) => {
26+
if (evt.name === "escape" || evt.name === "return") {
27+
evt.preventDefault()
28+
dialog.replace(() => <DialogAgent initialAgent={props.agentName} />)
29+
return
30+
}
31+
if (evt.name === "up" || (evt.ctrl && evt.name === "p")) {
32+
scroll?.scrollBy(-1)
33+
}
34+
if (evt.name === "down" || (evt.ctrl && evt.name === "n")) {
35+
scroll?.scrollBy(1)
36+
}
37+
if (evt.name === "pageup") {
38+
scroll?.scrollBy(-10)
39+
}
40+
if (evt.name === "pagedown") {
41+
scroll?.scrollBy(10)
42+
}
43+
})
44+
45+
return (
46+
<box gap={1} paddingBottom={1}>
47+
<box paddingLeft={4} paddingRight={4}>
48+
<box flexDirection="row" justifyContent="space-between">
49+
<text fg={theme.text} attributes={TextAttributes.BOLD}>
50+
{props.agentName}
51+
</text>
52+
<text fg={theme.textMuted}>esc</text>
53+
</box>
54+
</box>
55+
<scrollbox
56+
ref={(r: ScrollBoxRenderable) => (scroll = r)}
57+
paddingLeft={4}
58+
paddingRight={4}
59+
paddingTop={1}
60+
maxHeight={maxHeight()}
61+
>
62+
<text fg={theme.text} wrapMode="word">
63+
{description()}
64+
</text>
65+
</scrollbox>
66+
<box paddingLeft={4} paddingRight={4} paddingTop={1}>
67+
<text fg={theme.textMuted}>Press esc or enter to go back</text>
68+
</box>
69+
</box>
70+
)
71+
}
Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
import { createMemo } from "solid-js"
1+
import { createMemo, createSignal } from "solid-js"
22
import { useLocal } from "@tui/context/local"
33
import { DialogSelect } from "@tui/ui/dialog-select"
44
import { useDialog } from "@tui/ui/dialog"
5+
import { Keybind } from "@/util/keybind"
6+
import { DialogAgentDetails } from "./dialog-agent-details"
57

6-
export function DialogAgent() {
8+
export function DialogAgent(props: { initialAgent?: string }) {
79
const local = useLocal()
810
const dialog = useDialog()
911

12+
const [selectedAgentName, setSelectedAgentName] = createSignal(props.initialAgent ?? local.agent.current().name)
13+
14+
const selectedAgentHasPrompt = createMemo(() => {
15+
const agent = local.agent.list().find((a) => a.name === selectedAgentName())
16+
return agent && !agent.builtIn && !!agent.description
17+
})
18+
1019
const options = createMemo(() =>
1120
local.agent.list().map((item) => {
21+
let description: string | undefined
22+
23+
if (item.builtIn) {
24+
description = "native"
25+
} else if (item.shortDescription) {
26+
description = item.shortDescription
27+
} else if (item.description) {
28+
description = item.description
29+
}
30+
31+
description = description ? description.length > 35 ? description.slice(0, 32) + "..." : description : undefined
32+
1233
return {
1334
value: item.name,
1435
title: item.name,
15-
description: item.builtIn ? "native" : item.description,
36+
description
1637
}
1738
}),
1839
)
@@ -21,11 +42,25 @@ export function DialogAgent() {
2142
<DialogSelect
2243
title="Select agent"
2344
current={local.agent.current().name}
45+
defaultSelected={props.initialAgent}
2446
options={options()}
47+
onMove={(option) => setSelectedAgentName(option.value)}
2548
onSelect={(option) => {
2649
local.agent.set(option.value)
2750
dialog.clear()
2851
}}
52+
keybind={[
53+
{
54+
keybind: Keybind.parse("ctrl+e")[0],
55+
title: "show details",
56+
get disabled() {
57+
return !selectedAgentHasPrompt()
58+
},
59+
onTrigger: (option) => {
60+
dialog.replace(() => <DialogAgentDetails agentName={option.value} />)
61+
},
62+
},
63+
]}
2964
/>
3065
)
3166
}

‎packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface DialogSelectProps<T> {
2626
onTrigger: (option: DialogSelectOption<T>) => void
2727
}[]
2828
current?: T
29+
defaultSelected?: T
2930
}
3031

3132
export interface DialogSelectOption<T = any> {
@@ -53,10 +54,11 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
5354
})
5455

5556
createEffect(() => {
56-
if (props.current) {
57-
const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, props.current))
58-
if (currentIndex >= 0) {
59-
setStore("selected", currentIndex)
57+
const initialValue = props.defaultSelected ?? props.current
58+
if (initialValue) {
59+
const initialIndex = flat().findIndex((opt) => isDeepEqual(opt.value, initialValue))
60+
if (initialIndex >= 0) {
61+
setStore("selected", initialIndex)
6062
}
6163
}
6264
})
@@ -101,10 +103,13 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
101103
store.filter
102104
if (store.filter.length > 0) {
103105
setStore("selected", 0)
104-
} else if (props.current) {
105-
const currentIndex = flat().findIndex((opt) => isDeepEqual(opt.value, props.current))
106-
if (currentIndex >= 0) {
107-
setStore("selected", currentIndex)
106+
} else {
107+
const initialValue = props.defaultSelected ?? props.current
108+
if (initialValue) {
109+
const initialIndex = flat().findIndex((opt) => isDeepEqual(opt.value, initialValue))
110+
if (initialIndex >= 0) {
111+
setStore("selected", initialIndex)
112+
}
108113
}
109114
}
110115
scroll.scrollTo(0)

‎packages/opencode/src/cli/cmd/tui/ui/dialog.tsx‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function init() {
5757
})
5858

5959
useKeyboard((evt) => {
60-
if (evt.name === "escape" && store.stack.length > 0) {
60+
if (evt.name === "escape" && store.stack.length > 0 && !evt.defaultPrevented) {
6161
const current = store.stack.at(-1)!
6262
current.onClose?.()
6363
setStore("stack", store.stack.slice(0, -1))
@@ -70,8 +70,14 @@ function init() {
7070
let focus: Renderable | null
7171
function refocus() {
7272
setTimeout(() => {
73+
// A new dialog was opened in the meantime (e.g., navigating between dialogs)
74+
if (store.stack.length > 0) return
75+
7376
if (!focus) return
74-
if (focus.isDestroyed) return
77+
if (focus.isDestroyed) {
78+
focus = null
79+
return
80+
}
7581
function find(item: Renderable) {
7682
for (const child of item.getChildren()) {
7783
if (child === focus) return true
@@ -80,8 +86,12 @@ function init() {
8086
return false
8187
}
8288
const found = find(renderer.root)
83-
if (!found) return
89+
if (!found) {
90+
focus = null
91+
return
92+
}
8493
focus.focus()
94+
focus = null
8595
}, 1)
8696
}
8797

@@ -97,7 +107,7 @@ function init() {
97107
refocus()
98108
},
99109
replace(input: any, onClose?: () => void) {
100-
if (store.stack.length === 0) {
110+
if (store.stack.length === 0 && (!focus || focus.isDestroyed)) {
101111
focus = renderer.currentFocusedRenderable
102112
}
103113
for (const item of store.stack) {

‎packages/opencode/src/config/config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ export namespace Config {
369369
tools: z.record(z.string(), z.boolean()).optional(),
370370
disable: z.boolean().optional(),
371371
description: z.string().optional().describe("Description of when to use the agent"),
372+
short_description: z
373+
.string()
374+
.optional()
375+
.describe("Short description for display in agent listings (defaults to truncated description)"),
372376
mode: z.enum(["subagent", "primary", "all"]).optional(),
373377
color: z
374378
.string()

‎packages/sdk/js/src/gen/types.gen.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ export type AgentConfig = {
895895
* Description of when to use the agent
896896
*/
897897
description?: string
898+
/**
899+
* Short description for display in agent listings (defaults to truncated description)
900+
*/
901+
short_description?: string
898902
mode?: "subagent" | "primary" | "all"
899903
/**
900904
* Hex color code for the agent (e.g., #FF5733)
@@ -1452,6 +1456,7 @@ export type File = {
14521456
export type Agent = {
14531457
name: string
14541458
description?: string
1459+
shortDescription?: string
14551460
mode: "subagent" | "primary" | "all"
14561461
builtIn: boolean
14571462
topP?: number

0 commit comments

Comments
 (0)