@justsilver/opencode-team 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +126 -0
- package/LICENSE +21 -0
- package/README.md +116 -3
- package/package.json +48 -4
- package/plugin/opencode-team/index.ts +41 -0
- package/plugin/opencode-team/legacy.ts +48 -0
- package/plugin/opencode-team/model-ref.ts +28 -0
- package/plugin/opencode-team/policy.ts +638 -0
- package/plugin/opencode-team/prompts.ts +138 -0
- package/plugin/opencode-team/rpc.ts +90 -0
- package/plugin/opencode-team/team-agents.ts +104 -0
- package/plugin/opencode-team/team-ids.ts +2 -0
- package/plugin/opencode-team/tui.ts +22 -0
- package/plugin/opencode-team/view/configure.tsx +71 -0
- package/plugin/opencode-team/view/dashboard.tsx +889 -0
- package/plugin/opencode-team/view/model-config.tsx +976 -0
- package/plugin/opencode-team/view/model.ts +502 -0
- package/plugin/opencode-team/view/team.ts +267 -0
- package/plugin/opencode-team/view/ui.tsx +165 -0
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { TextAttributes, type InputRenderable, type Renderable, type ScrollBoxRenderable } from "@opentui/core"
|
|
3
|
+
import { useTerminalDimensions } from "@opentui/solid"
|
|
4
|
+
import type { ModelInfo, ProviderInfo } from "@opencode/client"
|
|
5
|
+
import {
|
|
6
|
+
createEffect,
|
|
7
|
+
createMemo,
|
|
8
|
+
createSignal,
|
|
9
|
+
For,
|
|
10
|
+
on,
|
|
11
|
+
onCleanup,
|
|
12
|
+
Show,
|
|
13
|
+
} from "solid-js"
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
buildDashboardGroups,
|
|
17
|
+
feedbackDismissMs,
|
|
18
|
+
filterDashboardGroups,
|
|
19
|
+
layoutFor,
|
|
20
|
+
roleLabel,
|
|
21
|
+
type DashboardAgent,
|
|
22
|
+
type DashboardAgentInput,
|
|
23
|
+
type DashboardGroup,
|
|
24
|
+
type Feedback,
|
|
25
|
+
type PermissionEffect,
|
|
26
|
+
} from "./model.ts"
|
|
27
|
+
import { ModelConfigView } from "./model-config.tsx"
|
|
28
|
+
import type { ModelSelectionResult } from "./team.ts"
|
|
29
|
+
import {
|
|
30
|
+
Badge,
|
|
31
|
+
ConfirmBar,
|
|
32
|
+
Divider,
|
|
33
|
+
effectTone,
|
|
34
|
+
FeedbackBar,
|
|
35
|
+
Hints,
|
|
36
|
+
rowBackground,
|
|
37
|
+
rowForeground,
|
|
38
|
+
rowMarker,
|
|
39
|
+
rowSecondary,
|
|
40
|
+
scrollbarOptions,
|
|
41
|
+
Section,
|
|
42
|
+
selectedRowAccent,
|
|
43
|
+
statusTone,
|
|
44
|
+
toneColor,
|
|
45
|
+
type KeymapLayer,
|
|
46
|
+
type Theme,
|
|
47
|
+
} from "./ui.tsx"
|
|
48
|
+
|
|
49
|
+
export interface TeamDashboardProps {
|
|
50
|
+
readonly agents: readonly DashboardAgentInput[]
|
|
51
|
+
readonly overrides: Readonly<Record<string, string>>
|
|
52
|
+
readonly models: readonly ModelInfo[]
|
|
53
|
+
readonly providers: readonly ProviderInfo[]
|
|
54
|
+
readonly modelError?: string
|
|
55
|
+
readonly warning?: string
|
|
56
|
+
readonly agentsSupported: boolean
|
|
57
|
+
readonly agentsError?: string
|
|
58
|
+
readonly refreshModels: () => Promise<{
|
|
59
|
+
readonly models: readonly ModelInfo[]
|
|
60
|
+
readonly error?: string
|
|
61
|
+
}>
|
|
62
|
+
readonly theme: Theme
|
|
63
|
+
readonly layer: (factory: () => KeymapLayer) => void
|
|
64
|
+
readonly clearDialog: () => void
|
|
65
|
+
readonly saveModel: (
|
|
66
|
+
agent: DashboardAgent,
|
|
67
|
+
model: string | null,
|
|
68
|
+
) => Promise<ModelSelectionResult>
|
|
69
|
+
readonly restoreModel: (agent: DashboardAgent) => Promise<ModelSelectionResult>
|
|
70
|
+
readonly close: () => void
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function TeamDashboard(props: TeamDashboardProps) {
|
|
74
|
+
const theme = () => props.theme.surface("dialog")
|
|
75
|
+
const dimensions = useTerminalDimensions()
|
|
76
|
+
const layout = createMemo(() => layoutFor(dimensions().width, dimensions().height))
|
|
77
|
+
|
|
78
|
+
const [overrides, setOverrides] = createSignal(props.overrides)
|
|
79
|
+
const [models, setModels] = createSignal(props.models)
|
|
80
|
+
const [modelError, setModelError] = createSignal(props.modelError)
|
|
81
|
+
const [refreshingModels, setRefreshingModels] = createSignal(false)
|
|
82
|
+
const initialGroups = buildDashboardGroups(props.agents, props.overrides, props.models, props.providers)
|
|
83
|
+
const initialRows = initialGroups.flatMap((group) => group.agents)
|
|
84
|
+
const initialID = initialRows[0]?.id ?? ""
|
|
85
|
+
const [selectedID, setSelectedID] = createSignal(initialID)
|
|
86
|
+
const [query, setQuery] = createSignal("")
|
|
87
|
+
const [pane, setPane] = createSignal<"list" | "detail">("list")
|
|
88
|
+
const [modelOpen, setModelOpen] = createSignal(false)
|
|
89
|
+
const [configAgentID, setConfigAgentID] = createSignal<string>()
|
|
90
|
+
const [feedback, setFeedback] = createSignal<Feedback>()
|
|
91
|
+
const [pendingRestore, setPendingRestore] = createSignal<DashboardAgent>()
|
|
92
|
+
const [restoring, setRestoring] = createSignal(false)
|
|
93
|
+
let disposed = false
|
|
94
|
+
let feedbackTimer: ReturnType<typeof setTimeout> | undefined
|
|
95
|
+
|
|
96
|
+
function showFeedback(next: Feedback): void {
|
|
97
|
+
if (disposed) return
|
|
98
|
+
setFeedback(next)
|
|
99
|
+
if (feedbackTimer !== undefined) clearTimeout(feedbackTimer)
|
|
100
|
+
feedbackTimer = undefined
|
|
101
|
+
const delay = feedbackDismissMs(next.tone)
|
|
102
|
+
if (delay === 0) return
|
|
103
|
+
feedbackTimer = setTimeout(() => {
|
|
104
|
+
if (!disposed) setFeedback(undefined)
|
|
105
|
+
}, delay)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const allGroups = () => buildDashboardGroups(props.agents, overrides(), models(), props.providers)
|
|
109
|
+
const groups = () => filterDashboardGroups(allGroups(), query())
|
|
110
|
+
const rows = () => groups().flatMap((group) => group.agents)
|
|
111
|
+
const selected = () =>
|
|
112
|
+
rows().find((agent) => agent.id === selectedID()) ?? rows()[0]
|
|
113
|
+
|
|
114
|
+
// 配置视图跟着 overrides 重新计算,保存/恢复后顶部状态与“当前模型”立即更新。
|
|
115
|
+
const configAgent = createMemo(() => {
|
|
116
|
+
const id = configAgentID()
|
|
117
|
+
if (id === undefined) return undefined
|
|
118
|
+
return allGroups()
|
|
119
|
+
.flatMap((group) => group.agents)
|
|
120
|
+
.find((agent) => agent.id === id)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
createEffect(() => {
|
|
124
|
+
const agent = selected()
|
|
125
|
+
if (agent !== undefined && agent.id !== selectedID()) setSelectedID(agent.id)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
let listScroll: ScrollBoxRenderable | undefined
|
|
129
|
+
let detailScroll: ScrollBoxRenderable | undefined
|
|
130
|
+
let searchInput: InputRenderable | undefined
|
|
131
|
+
let focusTimer: ReturnType<typeof setTimeout> | undefined
|
|
132
|
+
let scrollTimer: ReturnType<typeof setTimeout> | undefined
|
|
133
|
+
const rowNodes = new Map<string, Renderable>()
|
|
134
|
+
|
|
135
|
+
function focusSearch(): void {
|
|
136
|
+
if (pendingRestore() !== undefined || restoring()) return
|
|
137
|
+
if (searchInput === undefined || searchInput.isDestroyed) return
|
|
138
|
+
searchInput.focus()
|
|
139
|
+
searchInput.cursorOffset = searchInput.value.length
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function scheduleFocusSearch(): void {
|
|
143
|
+
if (focusTimer !== undefined) clearTimeout(focusTimer)
|
|
144
|
+
focusTimer = setTimeout(focusSearch, 1)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
createEffect(
|
|
148
|
+
on(
|
|
149
|
+
() => selected()?.id,
|
|
150
|
+
(id) => {
|
|
151
|
+
if (id !== undefined) ensureVisible(id)
|
|
152
|
+
detailScroll?.scrollTo(0)
|
|
153
|
+
},
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
onCleanup(() => {
|
|
158
|
+
disposed = true
|
|
159
|
+
if (focusTimer !== undefined) clearTimeout(focusTimer)
|
|
160
|
+
if (scrollTimer !== undefined) clearTimeout(scrollTimer)
|
|
161
|
+
if (feedbackTimer !== undefined) clearTimeout(feedbackTimer)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
function ensureVisible(id: string): void {
|
|
165
|
+
const scroll = listScroll
|
|
166
|
+
const node = rowNodes.get(id)
|
|
167
|
+
if (scroll === undefined || node === undefined || node.isDestroyed) return
|
|
168
|
+
if (scrollTimer !== undefined) clearTimeout(scrollTimer)
|
|
169
|
+
scrollTimer = setTimeout(() => {
|
|
170
|
+
if (scroll.isDestroyed || node.isDestroyed) return
|
|
171
|
+
const top = node.y - scroll.y
|
|
172
|
+
if (top < 0) scroll.scrollBy(top - 1)
|
|
173
|
+
else if (top + node.height > scroll.height) {
|
|
174
|
+
scroll.scrollBy(top + node.height - scroll.height + 1)
|
|
175
|
+
}
|
|
176
|
+
}, 0)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function move(delta: number): void {
|
|
180
|
+
const list = rows()
|
|
181
|
+
if (list.length === 0) return
|
|
182
|
+
const index = list.findIndex((agent) => agent.id === selectedID())
|
|
183
|
+
const next = index < 0 ? 0 : (index + delta + list.length) % list.length
|
|
184
|
+
setSelectedID(list[next]!.id)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function first(): void {
|
|
188
|
+
const list = rows()
|
|
189
|
+
if (list.length > 0) setSelectedID(list[0]!.id)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function last(): void {
|
|
193
|
+
const list = rows()
|
|
194
|
+
if (list.length > 0) setSelectedID(list[list.length - 1]!.id)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function page(delta: number): void {
|
|
198
|
+
const target = layout().split || pane() === "detail" ? detailScroll : listScroll
|
|
199
|
+
target?.scrollBy(delta * 10)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async function choose(): Promise<void> {
|
|
203
|
+
const agent = selected()
|
|
204
|
+
if (agent === undefined) return
|
|
205
|
+
if (!layout().split && pane() === "list") {
|
|
206
|
+
setPane("detail")
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
if (!agent.known) {
|
|
210
|
+
showFeedback({ tone: "warning", message: "该 Agent 当前目录不可用,只能清除旧覆盖。" })
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
if (agent.mode === "primary") {
|
|
214
|
+
showFeedback({
|
|
215
|
+
tone: "info",
|
|
216
|
+
message: "主代理模型由 OpenCode 会话选择,团队策略只覆盖子代理。",
|
|
217
|
+
})
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
if (!refreshingModels() && (modelError() !== undefined || models().length === 0)) {
|
|
221
|
+
setRefreshingModels(true)
|
|
222
|
+
showFeedback({ tone: "info", message: "正在重新读取模型目录…" })
|
|
223
|
+
try {
|
|
224
|
+
const next = await props.refreshModels()
|
|
225
|
+
if (disposed) return
|
|
226
|
+
setModels(next.models)
|
|
227
|
+
setModelError(next.error)
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (disposed) return
|
|
230
|
+
showFeedback({
|
|
231
|
+
tone: "warning",
|
|
232
|
+
message: `模型目录刷新失败:${error instanceof Error ? error.message : String(error)}`,
|
|
233
|
+
})
|
|
234
|
+
} finally {
|
|
235
|
+
if (!disposed) setRefreshingModels(false)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
setConfigAgentID(agent.id)
|
|
239
|
+
setModelOpen(true)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function requestRestore(): void {
|
|
243
|
+
const agent = selected()
|
|
244
|
+
if (agent === undefined) return
|
|
245
|
+
if (!agent.canRestore) {
|
|
246
|
+
showFeedback({ tone: "info", message: `${agent.name} 没有团队模型覆盖,无需恢复。` })
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
if (restoring()) return
|
|
250
|
+
setFeedback(undefined)
|
|
251
|
+
setPendingRestore(agent)
|
|
252
|
+
if (searchInput !== undefined && !searchInput.isDestroyed) searchInput.blur()
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function confirmRestoreNow(): Promise<void> {
|
|
256
|
+
const agent = pendingRestore()
|
|
257
|
+
if (agent === undefined || restoring()) return
|
|
258
|
+
setPendingRestore(undefined)
|
|
259
|
+
setRestoring(true)
|
|
260
|
+
showFeedback({ tone: "info", message: `正在恢复 ${agent.name}…` })
|
|
261
|
+
try {
|
|
262
|
+
const result = await props.restoreModel(agent)
|
|
263
|
+
if (disposed) return
|
|
264
|
+
setRestoring(false)
|
|
265
|
+
showFeedback({ tone: result.tone, message: result.message })
|
|
266
|
+
if (result.saved && result.models !== undefined) setOverrides(result.models)
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (disposed) return
|
|
269
|
+
setRestoring(false)
|
|
270
|
+
showFeedback({
|
|
271
|
+
tone: "error",
|
|
272
|
+
message: `恢复原生模型失败:${error instanceof Error ? error.message : String(error)}`,
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
scheduleFocusSearch()
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function close(): void {
|
|
279
|
+
props.close()
|
|
280
|
+
props.clearDialog()
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
props.layer(() => ({
|
|
284
|
+
mode: "modal",
|
|
285
|
+
priority: 10,
|
|
286
|
+
enabled: () => !modelOpen(),
|
|
287
|
+
commands: [
|
|
288
|
+
{
|
|
289
|
+
id: "opencode-team.dashboard.up",
|
|
290
|
+
bind: "up",
|
|
291
|
+
enabled: () => pendingRestore() === undefined,
|
|
292
|
+
run: () => move(-1),
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: "opencode-team.dashboard.down",
|
|
296
|
+
bind: "down",
|
|
297
|
+
enabled: () => pendingRestore() === undefined,
|
|
298
|
+
run: () => move(1),
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
id: "opencode-team.dashboard.first",
|
|
302
|
+
bind: "home",
|
|
303
|
+
enabled: () => pendingRestore() === undefined,
|
|
304
|
+
run: first,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: "opencode-team.dashboard.last",
|
|
308
|
+
bind: "end",
|
|
309
|
+
enabled: () => pendingRestore() === undefined,
|
|
310
|
+
run: last,
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
id: "opencode-team.dashboard.page_up",
|
|
314
|
+
bind: "pageup",
|
|
315
|
+
enabled: () => pendingRestore() === undefined,
|
|
316
|
+
run: () => page(-1),
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
id: "opencode-team.dashboard.page_down",
|
|
320
|
+
bind: "pagedown",
|
|
321
|
+
enabled: () => pendingRestore() === undefined,
|
|
322
|
+
run: () => page(1),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
id: "opencode-team.dashboard.choose",
|
|
326
|
+
bind: "enter",
|
|
327
|
+
run: () => {
|
|
328
|
+
if (pendingRestore() !== undefined) void confirmRestoreNow()
|
|
329
|
+
else void choose()
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: "opencode-team.dashboard.restore",
|
|
334
|
+
bind: "ctrl+r",
|
|
335
|
+
enabled: () => pendingRestore() === undefined,
|
|
336
|
+
run: requestRestore,
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
id: "opencode-team.dashboard.escape",
|
|
340
|
+
bind: "escape",
|
|
341
|
+
run: () => {
|
|
342
|
+
if (pendingRestore() !== undefined) {
|
|
343
|
+
setPendingRestore(undefined)
|
|
344
|
+
scheduleFocusSearch()
|
|
345
|
+
return
|
|
346
|
+
}
|
|
347
|
+
if (!layout().split && pane() === "detail") {
|
|
348
|
+
setPane("list")
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
close()
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
}))
|
|
356
|
+
|
|
357
|
+
const split = () => layout().split
|
|
358
|
+
const showList = () => split() || pane() === "list"
|
|
359
|
+
const showDetail = () => split() || pane() === "detail"
|
|
360
|
+
const agent = () => selected()
|
|
361
|
+
|
|
362
|
+
return (
|
|
363
|
+
<box
|
|
364
|
+
width="100%"
|
|
365
|
+
height={layout().dialogHeight}
|
|
366
|
+
flexDirection="column"
|
|
367
|
+
paddingLeft={2}
|
|
368
|
+
paddingRight={2}
|
|
369
|
+
paddingBottom={1}
|
|
370
|
+
>
|
|
371
|
+
<Show
|
|
372
|
+
when={!modelOpen()}
|
|
373
|
+
fallback={
|
|
374
|
+
<Show when={configAgent()}>
|
|
375
|
+
{(agent) => (
|
|
376
|
+
<ModelConfigView
|
|
377
|
+
agent={agent()}
|
|
378
|
+
models={models()}
|
|
379
|
+
providers={props.providers}
|
|
380
|
+
currentOverride={overrides()[agent().id]}
|
|
381
|
+
{...(modelError() === undefined ? {} : { modelError: modelError() })}
|
|
382
|
+
theme={theme()}
|
|
383
|
+
layer={props.layer}
|
|
384
|
+
feedback={feedback()}
|
|
385
|
+
onClose={() => {
|
|
386
|
+
setModelOpen(false)
|
|
387
|
+
setConfigAgentID(undefined)
|
|
388
|
+
}}
|
|
389
|
+
onSave={async (model) => {
|
|
390
|
+
const result = await props.saveModel(agent(), model)
|
|
391
|
+
if (disposed) return result
|
|
392
|
+
if (result.saved && result.models !== undefined) setOverrides(result.models)
|
|
393
|
+
showFeedback({ tone: result.tone, message: result.message })
|
|
394
|
+
return result
|
|
395
|
+
}}
|
|
396
|
+
onRestore={async () => {
|
|
397
|
+
const result = await props.restoreModel(agent())
|
|
398
|
+
if (disposed) return result
|
|
399
|
+
if (result.saved && result.models !== undefined) setOverrides(result.models)
|
|
400
|
+
showFeedback({ tone: result.tone, message: result.message })
|
|
401
|
+
return result
|
|
402
|
+
}}
|
|
403
|
+
notify={showFeedback}
|
|
404
|
+
/>
|
|
405
|
+
)}
|
|
406
|
+
</Show>
|
|
407
|
+
}
|
|
408
|
+
>
|
|
409
|
+
<Header
|
|
410
|
+
theme={theme()}
|
|
411
|
+
layout={layout()}
|
|
412
|
+
pane={pane()}
|
|
413
|
+
confirming={pendingRestore() !== undefined}
|
|
414
|
+
/>
|
|
415
|
+
<Show when={!layout().minimal}>
|
|
416
|
+
<box height={1} />
|
|
417
|
+
<Divider theme={theme()} />
|
|
418
|
+
</Show>
|
|
419
|
+
|
|
420
|
+
<Banners
|
|
421
|
+
theme={theme()}
|
|
422
|
+
agentsSupported={props.agentsSupported}
|
|
423
|
+
{...(props.agentsError === undefined ? {} : { agentsError: props.agentsError })}
|
|
424
|
+
modelError={modelError()}
|
|
425
|
+
warning={props.warning}
|
|
426
|
+
/>
|
|
427
|
+
|
|
428
|
+
<box paddingTop={1} paddingBottom={1} paddingLeft={1} paddingRight={1} flexShrink={0}>
|
|
429
|
+
<SearchField
|
|
430
|
+
theme={theme()}
|
|
431
|
+
query={query()}
|
|
432
|
+
inputRef={(value) => {
|
|
433
|
+
searchInput = value
|
|
434
|
+
scheduleFocusSearch()
|
|
435
|
+
}}
|
|
436
|
+
onFocus={focusSearch}
|
|
437
|
+
onInput={(value) => setQuery(value)}
|
|
438
|
+
/>
|
|
439
|
+
</box>
|
|
440
|
+
|
|
441
|
+
<box flexGrow={1} minHeight={0} flexDirection="row">
|
|
442
|
+
<Show when={showList()}>
|
|
443
|
+
<ListPane
|
|
444
|
+
theme={theme()}
|
|
445
|
+
groups={groups()}
|
|
446
|
+
selectedID={selected()?.id}
|
|
447
|
+
compact={layout().compact}
|
|
448
|
+
width={split() ? layout().listWidth : undefined}
|
|
449
|
+
onSelect={(id) => {
|
|
450
|
+
if (pendingRestore() !== undefined) return
|
|
451
|
+
setSelectedID(id)
|
|
452
|
+
scheduleFocusSearch()
|
|
453
|
+
}}
|
|
454
|
+
onRef={(id, node) => rowNodes.set(id, node)}
|
|
455
|
+
onScrollRef={(value) => (listScroll = value)}
|
|
456
|
+
/>
|
|
457
|
+
</Show>
|
|
458
|
+
<Show when={split()}>
|
|
459
|
+
<box width={1} flexShrink={0} backgroundColor={theme().border.base} />
|
|
460
|
+
</Show>
|
|
461
|
+
<Show when={showDetail()}>
|
|
462
|
+
<DetailPane
|
|
463
|
+
theme={theme()}
|
|
464
|
+
agent={agent()}
|
|
465
|
+
compact={layout().compact}
|
|
466
|
+
onScrollRef={(value) => (detailScroll = value)}
|
|
467
|
+
/>
|
|
468
|
+
</Show>
|
|
469
|
+
</box>
|
|
470
|
+
|
|
471
|
+
<Show when={pendingRestore()}>
|
|
472
|
+
{(pending) => (
|
|
473
|
+
<ConfirmBar
|
|
474
|
+
theme={theme()}
|
|
475
|
+
message={
|
|
476
|
+
pending().hostModel === undefined
|
|
477
|
+
? `清除 ${pending().name} 的团队模型覆盖并恢复 OpenCode 原生选择?`
|
|
478
|
+
: `清除 ${pending().name} 的团队模型覆盖,回到 Agent 配置的 ${pending().hostModel}?`
|
|
479
|
+
}
|
|
480
|
+
/>
|
|
481
|
+
)}
|
|
482
|
+
</Show>
|
|
483
|
+
<Show when={feedback()}>
|
|
484
|
+
{(value) => <FeedbackBar theme={theme()} feedback={value()} />}
|
|
485
|
+
</Show>
|
|
486
|
+
|
|
487
|
+
<Footer
|
|
488
|
+
theme={theme()}
|
|
489
|
+
minimal={layout().minimal}
|
|
490
|
+
split={split()}
|
|
491
|
+
pane={pane()}
|
|
492
|
+
agent={agent()}
|
|
493
|
+
confirming={pendingRestore() !== undefined}
|
|
494
|
+
/>
|
|
495
|
+
</Show>
|
|
496
|
+
</box>
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function Header(props: {
|
|
501
|
+
readonly theme: Theme
|
|
502
|
+
readonly layout: ReturnType<typeof layoutFor>
|
|
503
|
+
readonly pane: "list" | "detail"
|
|
504
|
+
readonly confirming: boolean
|
|
505
|
+
}) {
|
|
506
|
+
const escapeLabel = () => {
|
|
507
|
+
if (props.confirming) return "ESC 取消"
|
|
508
|
+
if (!props.layout.split && props.pane === "detail") return "ESC 返回"
|
|
509
|
+
return "ESC 关闭"
|
|
510
|
+
}
|
|
511
|
+
return (
|
|
512
|
+
<box flexDirection="column" flexShrink={0}>
|
|
513
|
+
<box flexDirection="row" justifyContent="space-between" gap={2}>
|
|
514
|
+
<box flexDirection="row" gap={2}>
|
|
515
|
+
<text fg={props.theme.text.base} attributes={TextAttributes.BOLD}>
|
|
516
|
+
Agent Team
|
|
517
|
+
</text>
|
|
518
|
+
<text fg={props.theme.text.muted}>团队管理</text>
|
|
519
|
+
</box>
|
|
520
|
+
<text fg={props.theme.text.muted}>{escapeLabel()}</text>
|
|
521
|
+
</box>
|
|
522
|
+
<Show when={!props.layout.minimal}>
|
|
523
|
+
<text fg={props.theme.text.muted}>模型策略只覆盖子代理</text>
|
|
524
|
+
</Show>
|
|
525
|
+
</box>
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function Banners(props: {
|
|
530
|
+
readonly theme: Theme
|
|
531
|
+
readonly agentsSupported: boolean
|
|
532
|
+
readonly agentsError?: string
|
|
533
|
+
readonly modelError?: string
|
|
534
|
+
readonly warning?: string
|
|
535
|
+
}) {
|
|
536
|
+
const messages = () => {
|
|
537
|
+
const list: string[] = []
|
|
538
|
+
if (!props.agentsSupported) {
|
|
539
|
+
list.push(
|
|
540
|
+
props.agentsError === undefined
|
|
541
|
+
? "宿主不能动态注册团队 Agent;Orchestrator、QA、Reviewer 可能不可用。"
|
|
542
|
+
: `团队 Agent 注册失败:${props.agentsError}`,
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
if (props.warning !== undefined) list.push(props.warning)
|
|
546
|
+
if (props.modelError !== undefined) {
|
|
547
|
+
list.push(`${props.modelError};模型名称回退为引用,打开模型配置时会重试。`)
|
|
548
|
+
}
|
|
549
|
+
return list
|
|
550
|
+
}
|
|
551
|
+
return (
|
|
552
|
+
<Show when={messages().length > 0}>
|
|
553
|
+
<box flexDirection="column" flexShrink={0} paddingTop={1}>
|
|
554
|
+
<For each={messages()}>
|
|
555
|
+
{(message) => (
|
|
556
|
+
<text fg={props.theme.text.feedback.warning.base} wrapMode="word">
|
|
557
|
+
! {message}
|
|
558
|
+
</text>
|
|
559
|
+
)}
|
|
560
|
+
</For>
|
|
561
|
+
</box>
|
|
562
|
+
</Show>
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function ListPane(props: {
|
|
567
|
+
readonly theme: Theme
|
|
568
|
+
readonly groups: readonly DashboardGroup[]
|
|
569
|
+
readonly selectedID?: string
|
|
570
|
+
readonly compact: boolean
|
|
571
|
+
readonly width?: number
|
|
572
|
+
readonly onSelect: (id: string) => void
|
|
573
|
+
readonly onRef: (id: string, node: Renderable) => void
|
|
574
|
+
readonly onScrollRef: (value: ScrollBoxRenderable) => void
|
|
575
|
+
}) {
|
|
576
|
+
return (
|
|
577
|
+
<box
|
|
578
|
+
width={props.width}
|
|
579
|
+
flexGrow={props.width === undefined ? 1 : undefined}
|
|
580
|
+
flexShrink={0}
|
|
581
|
+
minWidth={0}
|
|
582
|
+
backgroundColor={props.theme.background.raised.base}
|
|
583
|
+
paddingLeft={1}
|
|
584
|
+
paddingRight={1}
|
|
585
|
+
>
|
|
586
|
+
<Show
|
|
587
|
+
when={props.groups.length > 0}
|
|
588
|
+
fallback={
|
|
589
|
+
<box paddingTop={1}>
|
|
590
|
+
<text fg={props.theme.text.muted}>没有匹配的 Agent。</text>
|
|
591
|
+
</box>
|
|
592
|
+
}
|
|
593
|
+
>
|
|
594
|
+
<scrollbox
|
|
595
|
+
flexGrow={1}
|
|
596
|
+
minHeight={0}
|
|
597
|
+
verticalScrollbarOptions={scrollbarOptions(props.theme)}
|
|
598
|
+
horizontalScrollbarOptions={{ visible: false }}
|
|
599
|
+
ref={props.onScrollRef}
|
|
600
|
+
>
|
|
601
|
+
<For each={props.groups}>
|
|
602
|
+
{(group, index) => (
|
|
603
|
+
<box flexDirection="column">
|
|
604
|
+
<box paddingTop={index() === 0 ? 0 : 1} paddingLeft={1}>
|
|
605
|
+
<text fg={props.theme.text.muted} attributes={TextAttributes.BOLD}>
|
|
606
|
+
{group.title}
|
|
607
|
+
</text>
|
|
608
|
+
</box>
|
|
609
|
+
<For each={group.agents}>
|
|
610
|
+
{(agent) => {
|
|
611
|
+
const active = () => agent.id === props.selectedID
|
|
612
|
+
return (
|
|
613
|
+
<box
|
|
614
|
+
flexDirection="column"
|
|
615
|
+
paddingLeft={1}
|
|
616
|
+
paddingRight={1}
|
|
617
|
+
backgroundColor={rowBackground(props.theme, active())}
|
|
618
|
+
onMouseUp={() => props.onSelect(agent.id)}
|
|
619
|
+
ref={(node: Renderable) => props.onRef(agent.id, node)}
|
|
620
|
+
>
|
|
621
|
+
<box flexDirection="row" gap={1}>
|
|
622
|
+
<text flexShrink={0} fg={rowMarker(props.theme, active())}>
|
|
623
|
+
{active() ? "▌" : " "}
|
|
624
|
+
</text>
|
|
625
|
+
<text
|
|
626
|
+
flexGrow={1}
|
|
627
|
+
overflow="hidden"
|
|
628
|
+
wrapMode="none"
|
|
629
|
+
fg={rowForeground(props.theme)}
|
|
630
|
+
attributes={active() ? TextAttributes.BOLD : undefined}
|
|
631
|
+
>
|
|
632
|
+
{agent.name}
|
|
633
|
+
</text>
|
|
634
|
+
<text
|
|
635
|
+
flexShrink={0}
|
|
636
|
+
fg={
|
|
637
|
+
active()
|
|
638
|
+
? props.theme.text.base
|
|
639
|
+
: toneColor(props.theme, statusTone(agent.status))
|
|
640
|
+
}
|
|
641
|
+
>
|
|
642
|
+
{agent.statusLabel}
|
|
643
|
+
</text>
|
|
644
|
+
</box>
|
|
645
|
+
<Show when={!props.compact && agent.status === "custom"}>
|
|
646
|
+
<box flexDirection="row" gap={1} paddingLeft={2}>
|
|
647
|
+
<text
|
|
648
|
+
flexGrow={1}
|
|
649
|
+
wrapMode="word"
|
|
650
|
+
fg={rowSecondary(props.theme, active())}
|
|
651
|
+
>
|
|
652
|
+
{agent.modelLabel}
|
|
653
|
+
</text>
|
|
654
|
+
</box>
|
|
655
|
+
</Show>
|
|
656
|
+
</box>
|
|
657
|
+
)
|
|
658
|
+
}}
|
|
659
|
+
</For>
|
|
660
|
+
</box>
|
|
661
|
+
)}
|
|
662
|
+
</For>
|
|
663
|
+
</scrollbox>
|
|
664
|
+
</Show>
|
|
665
|
+
</box>
|
|
666
|
+
)
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function DetailPane(props: {
|
|
670
|
+
readonly theme: Theme
|
|
671
|
+
readonly agent?: DashboardAgent
|
|
672
|
+
readonly compact: boolean
|
|
673
|
+
readonly onScrollRef: (value: ScrollBoxRenderable) => void
|
|
674
|
+
}) {
|
|
675
|
+
return (
|
|
676
|
+
<box flexGrow={1} minWidth={0} minHeight={0} paddingLeft={2}>
|
|
677
|
+
<Show
|
|
678
|
+
when={props.agent}
|
|
679
|
+
fallback={
|
|
680
|
+
<box paddingTop={1}>
|
|
681
|
+
<text fg={props.theme.text.muted}>没有可显示的 Agent。</text>
|
|
682
|
+
</box>
|
|
683
|
+
}
|
|
684
|
+
>
|
|
685
|
+
{(agent) => (
|
|
686
|
+
<scrollbox
|
|
687
|
+
flexGrow={1}
|
|
688
|
+
minHeight={0}
|
|
689
|
+
verticalScrollbarOptions={scrollbarOptions(props.theme)}
|
|
690
|
+
horizontalScrollbarOptions={{ visible: false }}
|
|
691
|
+
ref={props.onScrollRef}
|
|
692
|
+
>
|
|
693
|
+
<box flexDirection="column" gap={1} paddingRight={1}>
|
|
694
|
+
<box flexDirection="row" justifyContent="space-between" gap={2}>
|
|
695
|
+
<text
|
|
696
|
+
flexGrow={1}
|
|
697
|
+
overflow="hidden"
|
|
698
|
+
wrapMode="none"
|
|
699
|
+
fg={props.theme.text.base}
|
|
700
|
+
attributes={TextAttributes.BOLD}
|
|
701
|
+
>
|
|
702
|
+
{agent().name}
|
|
703
|
+
</text>
|
|
704
|
+
<box flexDirection="row" gap={1} flexShrink={0}>
|
|
705
|
+
<Badge theme={props.theme} text={roleLabel(agent().mode)} tone="neutral" />
|
|
706
|
+
<Badge
|
|
707
|
+
theme={props.theme}
|
|
708
|
+
text={agent().statusLabel}
|
|
709
|
+
tone={statusTone(agent().status)}
|
|
710
|
+
/>
|
|
711
|
+
</box>
|
|
712
|
+
</box>
|
|
713
|
+
|
|
714
|
+
<box
|
|
715
|
+
flexDirection="column"
|
|
716
|
+
backgroundColor={props.theme.background.raised.high}
|
|
717
|
+
border={["left"]}
|
|
718
|
+
borderColor={selectedRowAccent(props.theme)}
|
|
719
|
+
paddingLeft={1}
|
|
720
|
+
paddingRight={1}
|
|
721
|
+
paddingTop={1}
|
|
722
|
+
paddingBottom={1}
|
|
723
|
+
>
|
|
724
|
+
<text fg={selectedRowAccent(props.theme)} attributes={TextAttributes.BOLD}>
|
|
725
|
+
当前模型
|
|
726
|
+
</text>
|
|
727
|
+
<text fg={props.theme.text.base} attributes={TextAttributes.BOLD} wrapMode="word">
|
|
728
|
+
{agent().modelLabel}
|
|
729
|
+
</text>
|
|
730
|
+
<text fg={props.theme.text.muted} wrapMode="word">
|
|
731
|
+
来源:{agent().sourceLabel}
|
|
732
|
+
{agent().source === "none"
|
|
733
|
+
? ""
|
|
734
|
+
: ` · ${agent().teamModel ?? agent().hostModel ?? ""}`}
|
|
735
|
+
{" · "}变体:{agent().variantLabel}
|
|
736
|
+
</text>
|
|
737
|
+
<Show when={agent().mode === "primary"}>
|
|
738
|
+
<text fg={props.theme.text.muted} wrapMode="word">
|
|
739
|
+
主代理模型由 OpenCode 会话选择,团队策略不能覆盖;此处只读展示。
|
|
740
|
+
</text>
|
|
741
|
+
</Show>
|
|
742
|
+
</box>
|
|
743
|
+
|
|
744
|
+
<Show when={!props.compact}>
|
|
745
|
+
<text fg={props.theme.text.muted} wrapMode="word">
|
|
746
|
+
{agent().description ?? "宿主未提供角色说明。"}
|
|
747
|
+
</text>
|
|
748
|
+
</Show>
|
|
749
|
+
|
|
750
|
+
<Divider theme={props.theme} />
|
|
751
|
+
|
|
752
|
+
<Section theme={props.theme} title="权限 / PERMISSIONS">
|
|
753
|
+
<text fg={props.theme.text.muted} wrapMode="word">允许 <span style={{ fg: toneColor(props.theme, "neutral") }}>{agent().permissions.allow}</span> · 询问 <span style={{ fg: props.theme.text.feedback.warning.base }}>{agent().permissions.ask}</span> · 拒绝 <span style={{ fg: props.theme.text.feedback.error.base }}>{agent().permissions.deny}</span>(共 {agent().permissions.total} 条生效规则)</text>
|
|
754
|
+
<text fg={props.theme.text.muted} wrapMode="word">
|
|
755
|
+
默认:
|
|
756
|
+
{agent().permissions.defaultEffect === undefined
|
|
757
|
+
? "未设置(宿主按 ask 处理)"
|
|
758
|
+
: `*/* ${effectLabel(agent().permissions.defaultEffect!)}`}
|
|
759
|
+
</text>
|
|
760
|
+
<For each={agent().permissions.highlights}>
|
|
761
|
+
{(rule) => (
|
|
762
|
+
<text fg={toneColor(props.theme, effectTone(rule.effect))} wrapMode="word">
|
|
763
|
+
{effectLabel(rule.effect)} {rule.action} {rule.resource}
|
|
764
|
+
</text>
|
|
765
|
+
)}
|
|
766
|
+
</For>
|
|
767
|
+
<text fg={props.theme.text.muted} wrapMode="word">
|
|
768
|
+
规则效果摘要,不代表沙箱;Shell 仍可能写文件。完整合并顺序见宿主策略。
|
|
769
|
+
</text>
|
|
770
|
+
</Section>
|
|
771
|
+
|
|
772
|
+
<Section theme={props.theme} title="SYSTEM PROMPT · 只读">
|
|
773
|
+
<Show
|
|
774
|
+
when={agent().prompt.available}
|
|
775
|
+
fallback={
|
|
776
|
+
<text fg={props.theme.text.feedback.warning.base} wrapMode="word">
|
|
777
|
+
{agent().prompt.reason}
|
|
778
|
+
</text>
|
|
779
|
+
}
|
|
780
|
+
>
|
|
781
|
+
<text fg={props.theme.text.base} wrapMode="word">
|
|
782
|
+
{agent().prompt.text}
|
|
783
|
+
</text>
|
|
784
|
+
</Show>
|
|
785
|
+
</Section>
|
|
786
|
+
</box>
|
|
787
|
+
</scrollbox>
|
|
788
|
+
)}
|
|
789
|
+
</Show>
|
|
790
|
+
</box>
|
|
791
|
+
)
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function Footer(props: {
|
|
795
|
+
readonly theme: Theme
|
|
796
|
+
readonly minimal: boolean
|
|
797
|
+
readonly split: boolean
|
|
798
|
+
readonly pane: "list" | "detail"
|
|
799
|
+
readonly agent?: DashboardAgent
|
|
800
|
+
readonly confirming: boolean
|
|
801
|
+
}) {
|
|
802
|
+
const enter = () => (props.agent?.canConfigure === true ? "模型" : "说明")
|
|
803
|
+
const hints = () => {
|
|
804
|
+
if (props.confirming) {
|
|
805
|
+
return [
|
|
806
|
+
{ key: "Enter", label: "确认" },
|
|
807
|
+
{ key: "ESC", label: "取消" },
|
|
808
|
+
]
|
|
809
|
+
}
|
|
810
|
+
if (props.minimal) {
|
|
811
|
+
return [
|
|
812
|
+
{ key: "↑↓", label: "选择" },
|
|
813
|
+
{ key: "ESC", label: "关闭" },
|
|
814
|
+
]
|
|
815
|
+
}
|
|
816
|
+
if (!props.split && props.pane === "list") {
|
|
817
|
+
return [
|
|
818
|
+
{ key: "↑↓", label: "选择" },
|
|
819
|
+
{ key: "Enter", label: "详情" },
|
|
820
|
+
{ key: "ESC", label: "关闭" },
|
|
821
|
+
]
|
|
822
|
+
}
|
|
823
|
+
if (!props.split) {
|
|
824
|
+
return [
|
|
825
|
+
{ key: "Enter", label: enter() },
|
|
826
|
+
{ key: "Ctrl+R", label: "恢复原生" },
|
|
827
|
+
{ key: "ESC", label: "返回" },
|
|
828
|
+
]
|
|
829
|
+
}
|
|
830
|
+
return [
|
|
831
|
+
{ key: "↑↓", label: "选择" },
|
|
832
|
+
{ key: "Enter", label: enter() },
|
|
833
|
+
{ key: "Ctrl+R", label: "恢复原生" },
|
|
834
|
+
{ key: "ESC", label: "关闭" },
|
|
835
|
+
]
|
|
836
|
+
}
|
|
837
|
+
return (
|
|
838
|
+
<box
|
|
839
|
+
flexShrink={0}
|
|
840
|
+
border={["top"]}
|
|
841
|
+
borderColor={props.theme.border.base}
|
|
842
|
+
paddingTop={1}
|
|
843
|
+
>
|
|
844
|
+
<Hints theme={props.theme} hints={hints()} />
|
|
845
|
+
</box>
|
|
846
|
+
)
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* 搜索框常驻并默认聚焦,直接输入即过滤;不再有进入/退出搜索的模式,
|
|
851
|
+
* 因此列表导航只保留方向键,单字母按键都作为查询输入。
|
|
852
|
+
*/
|
|
853
|
+
function SearchField(props: {
|
|
854
|
+
readonly query: string
|
|
855
|
+
readonly theme: Theme
|
|
856
|
+
readonly inputRef: (value: InputRenderable) => void
|
|
857
|
+
readonly onFocus: () => void
|
|
858
|
+
readonly onInput: (value: string) => void
|
|
859
|
+
}) {
|
|
860
|
+
return (
|
|
861
|
+
<box
|
|
862
|
+
flexDirection="row"
|
|
863
|
+
gap={1}
|
|
864
|
+
paddingLeft={1}
|
|
865
|
+
paddingRight={1}
|
|
866
|
+
backgroundColor={props.theme.background.formfield.focused}
|
|
867
|
+
onMouseDown={props.onFocus}
|
|
868
|
+
>
|
|
869
|
+
<text fg={props.theme.text.formfield.focused}>搜索</text>
|
|
870
|
+
<input
|
|
871
|
+
flexGrow={1}
|
|
872
|
+
value={props.query}
|
|
873
|
+
onInput={props.onInput}
|
|
874
|
+
placeholder="Agent 名称 / 角色 / 模型…"
|
|
875
|
+
placeholderColor={props.theme.text.muted}
|
|
876
|
+
focusedBackgroundColor={props.theme.background.formfield.focused}
|
|
877
|
+
focusedTextColor={props.theme.text.formfield.focused}
|
|
878
|
+
cursorColor={props.theme.text.formfield.focused}
|
|
879
|
+
ref={props.inputRef}
|
|
880
|
+
/>
|
|
881
|
+
</box>
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function effectLabel(effect: PermissionEffect): string {
|
|
886
|
+
if (effect === "allow") return "允许"
|
|
887
|
+
if (effect === "deny") return "拒绝"
|
|
888
|
+
return "询问"
|
|
889
|
+
}
|