Skip to content

Commit 8d6d860

Browse files
committed
feat(tui): derive agent colors from id hash
1 parent 0075486 commit 8d6d860

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎PATCH.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ The model picker shows a `Free` footer for each model with `cost.input === 0`. T
6767

6868
Tab selects the next agent. Shift+Tab selects the previous agent. A colored list of agents shows for a short time. Click an agent in the list to select it.
6969

70+
## Agent Colors (TUI)
71+
72+
An agent without a `color` gets a stable color from its id.
73+
7074
## `/timeouts` Command
7175

7276
The plugins `custom.shell.timeouts` and `custom.timeouts` (TUI) remove the default timeout of foreground shell commands. The default timeout returns only after you toggle `/timeouts` for the session. A `timeout` set on a call still applies. Background calls are not affected. The contract is in `packages/schema/src/custom-timeouts.ts`.

‎bun.lock‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/tui/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@opentui/keymap": "catalog:",
6464
"@opentui/solid": "catalog:",
6565
"@solid-primitives/event-bus": "1.1.2",
66+
"color-hash": "2.0.2",
6667
"effect": "catalog:",
6768
"fuzzysort": "catalog:",
6869
"get-east-asian-width": "catalog:",
@@ -74,6 +75,7 @@
7475
"devDependencies": {
7576
"@tsconfig/bun": "catalog:",
7677
"@types/bun": "catalog:",
78+
"@types/color-hash": "2.0.0",
7779
"@typescript/native": "catalog:"
7880
}
7981
}

‎packages/tui/src/context/local.tsx‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createStore } from "solid-js/store"
2-
import { dedupeWith } from "effect/Array"
2+
import ColorHash from "color-hash"
33
import { createSimpleContext } from "./helper"
44
import { batch, createMemo, onCleanup } from "solid-js"
55
import { useEvent } from "./event"
@@ -18,22 +18,25 @@ import {
1818
type ModelPreference,
1919
type ModelPreferenceModel,
2020
} from "../model-preference"
21-
import { useTheme } from "./theme"
22-
import { useNewDesigns } from "../config"
21+
import { useThemes } from "./theme"
2322
import { useToast } from "../ui/toast"
2423
import { useRoute } from "./route"
2524
import { useData } from "./data"
2625
import { usePermission } from "./permission"
2726
import { useLocation } from "./location"
2827
import { parse } from "../util/model"
2928

29+
const agentColorHash = {
30+
dark: new ColorHash({ lightness: [0.6, 0.7], saturation: [0.55, 0.7] }),
31+
light: new ColorHash({ lightness: [0.35, 0.45], saturation: [0.6, 0.75] }),
32+
}
33+
3034
export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
3135
name: "Local",
3236
init: () => {
3337
const data = useData()
3438
const toast = useToast()
35-
const theme = useTheme()
36-
const newDesigns = useNewDesigns()
39+
const themes = useThemes()
3740
const route = useRoute()
3841
const paths = useTuiPaths()
3942
const args = useArgs()
@@ -83,14 +86,6 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
8386
setAgentStore("draftBySession", evt.data.sessionID, { agent: undefined })
8487
}),
8588
)
86-
const colors = createMemo(() => {
87-
// The new designs palette keeps its vivid accent at 400; 200 there is a muted tint.
88-
const step = newDesigns() ? 400 : 200
89-
return dedupeWith(
90-
theme.categorical.map((scale) => scale[step]),
91-
(first, second) => first.equals(second),
92-
)
93-
})
9489
return {
9590
list() {
9691
return agents()
@@ -143,12 +138,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
143138
settle()
144139
},
145140
color(id: string) {
146-
const index = visibleAgents().findIndex((agent) => agent.id === id)
147-
if (index === -1) return colors()[0]
148-
const agent = visibleAgents()[index]
149-
150-
if (agent?.color) return RGBA.fromHex(agent.color)
151-
return colors()[index % colors().length]
141+
const configured = visibleAgents().find((agent) => agent.id === id)?.color
142+
if (configured) return RGBA.fromHex(configured)
143+
return RGBA.fromHex(agentColorHash[themes.mode()].hex(id))
152144
},
153145
}
154146
}

0 commit comments

Comments
 (0)