Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

Reorder and group channels in the sidebar (#77)

Rayanne B. Lima555548f63b70
diff --git a/src/renderer/src/components/Sidebar.tsx b/src/renderer/src/components/Sidebar.tsx
index 6f25ff7..8b599e1 100644
--- a/src/renderer/src/components/Sidebar.tsx
+++ b/src/renderer/src/components/Sidebar.tsx
@@ -1,5 +1,5 @@
import { L } from '../../../shared/lang'
-import { useCallback, useState, type ReactNode } from 'react'
+import { useCallback, useRef, useState, type HTMLAttributes, type ReactNode } from 'react'
import {
agentById,
archiveAgent,
@@ -18,6 +18,7 @@ import {
type Agent,
type View
} from '../store'
+import { addGroup, arrange, moveChannel, nudgeChannel, removeGroup, renameGroup, type ChannelLayout } from '../../../shared/channel-layout'
import { call } from '../rpc'
import { ContextMenu, type MenuItem, type MenuState } from './Dialogs'
import { FoldToggle, useFold } from './Fold'
@@ -67,6 +68,24 @@ function Section({ id, label, unread = 0, action, children }: { id: string; labe
)
}
+// A group folds like the sections, in the same list (Fold.tsx), and keeps showing the channel you're in.
+function GroupFold({ id, label, unread, head, naming, children }: { id: string; label: string; unread: number; head: HTMLAttributes<HTMLDivElement>; naming?: ReactNode; children: ReactNode }): ReactNode {
+ const { open, toggle } = useFold(`group:${id}`)
+ return (
+ <div className={`channel-group ${open ? '' : 'is-folded'}`}>
+ {naming || (
+ <div className="channel-group__head" {...head}>
+ <FoldToggle open={open} onToggle={toggle}>
+ {label}
+ </FoldToggle>
+ {!open && unread > 0 && <span className="badge badge--soft">{unread}</span>}
+ </div>
+ )}
+ {children}
+ </div>
+ )
+}
+
const unreadIn = (conversations: { unread?: number }[]): number => conversations.reduce((sum, c) => sum + (c.unread ?? 0), 0)
export function Sidebar(): ReactNode {
@@ -82,6 +101,49 @@ export function Sidebar(): ReactNode {
e.preventDefault()
setMenu({ x: e.clientX, y: e.clientY, items })
}
+ // The order and groups are the person's: the core only keeps them.
+ const layout = s.settings.channelLayout
+ const arranged = arrange(channels, layout)
+ const whole: ChannelLayout = { loose: arranged.loose.map((c) => c.id), groups: arranged.groups.map((g) => ({ ...g, channels: g.channels.map((c) => c.id) })) }
+ const saveLayout = (next: ChannelLayout): void => updateSettings({ channelLayout: next })
+ const [naming, setNaming] = useState<string | null>(null)
+ const newGroup = (channelId: string): void => {
+ const id = crypto.randomUUID()
+ saveLayout(moveChannel(channels, addGroup(layout, { id, name: L('Novo grupo', 'New group') }), channelId, { group: id }))
+ setNaming(id)
+ }
+ const dragged = useRef<string | null>(null)
+ const accept = (e: React.DragEvent): void => {
+ if (dragged.current) e.preventDefault()
+ }
+ const dropOn = (to: { group?: string; before?: string }) => ({
+ onDragEnter: accept,
+ onDragOver: accept,
+ onDrop: (e: React.DragEvent): void => {
+ const id = dragged.current
+ if (!id) return
+ e.preventDefault()
+ e.stopPropagation()
+ dragged.current = null
+ saveLayout(moveChannel(channels, layout, id, to))
+ }
+ })
+ const channelRow = (c: (typeof channels)[number], group?: string): ReactNode => (
+ <div
+ key={c.id}
+ draggable
+ onDragStart={(e) => {
+ dragged.current = c.id
+ e.dataTransfer.effectAllowed = 'move'
+ e.dataTransfer.setData('text/plain', c.name)
+ }}
+ onDragEnd={() => (dragged.current = null)}
+ onContextMenu={(e) => open(e, channelMenu(c))}
+ {...dropOn({ group, before: c.id })}
+ >
+ <ChannelItem id={c.id} name={c.name} unread={c.unread} />
+ </div>
+ )
// The wiki's curator reads every conversation; one can be kept out (a personal DM, say).
const wikiItem = (id: string, on: boolean): MenuItem => ({
label: on ? L('Não guardar na wiki', "Don't keep in the wiki") : L('Voltar a guardar na wiki', 'Keep in the wiki again'),
@@ -95,6 +157,12 @@ export function Sidebar(): ReactNode {
...(c.unread ? [{ label: L('Marcar como lido', 'Mark as read'), icon: 'check' as const, onClick: () => markRead(c.id) }] : []),
wikiItem(c.id, c.wikiCapture !== false),
'separator',
+ { label: L('Mover para cima', 'Move up'), onClick: () => saveLayout(nudgeChannel(channels, layout, c.id, -1)) },
+ { label: L('Mover para baixo', 'Move down'), onClick: () => saveLayout(nudgeChannel(channels, layout, c.id, 1)) },
+ ...arranged.groups.filter((g) => !g.channels.includes(c)).map((g): MenuItem => ({ label: L(`Mover para ${g.name}`, `Move to ${g.name}`), onClick: () => saveLayout(moveChannel(channels, layout, c.id, { group: g.id })) })),
+ ...(arranged.groups.some((g) => g.channels.includes(c)) ? [{ label: L('Tirar do grupo', 'Take out of the group'), onClick: () => saveLayout(moveChannel(channels, layout, c.id, {})) }] : []),
+ { label: L('Novo grupo com este canal', 'New group with this channel'), icon: 'plus', onClick: () => newGroup(c.id) },
+ 'separator',
{
label: L('Excluir canal…', 'Delete channel…'),
icon: 'trash',
@@ -181,10 +249,45 @@ export function Sidebar(): ReactNode {
</button>
}
>
- {channels.map((c) => (
- <div key={c.id} onContextMenu={(e) => open(e, channelMenu(c))}>
- <ChannelItem id={c.id} name={c.name} unread={c.unread} />
- </div>
+ {arranged.loose.map((c) => channelRow(c))}
+ {/* Dropped here, a channel goes last among those in no group. */}
+ <div className="channel-drop" {...dropOn({})} />
+ {arranged.groups.map((g) => (
+ <GroupFold
+ key={g.id}
+ id={g.id}
+ label={g.name}
+ unread={g.channels.reduce((n, c) => n + (c.unread ?? 0), 0)}
+ head={{
+ ...dropOn({ group: g.id }),
+ onContextMenu: (e) =>
+ open(e, [
+ { label: L('Renomear', 'Rename'), icon: 'edit', onClick: () => setNaming(g.id) },
+ { label: L('Desfazer o grupo', 'Ungroup'), icon: 'trash', onClick: () => saveLayout(removeGroup(whole, g.id)) }
+ ])
+ }}
+ naming={
+ naming === g.id && (
+ <input
+ className="channel-group__name"
+ autoFocus
+ defaultValue={g.name}
+ aria-label={L('Nome do grupo', 'Group name')}
+ onFocus={(e) => e.target.select()}
+ onBlur={(e) => {
+ saveLayout(renameGroup(whole, g.id, e.target.value.trim() || g.name))
+ setNaming(null)
+ }}
+ onKeyDown={(e) => {
+ if (e.key === 'Escape') e.currentTarget.value = g.name
+ if (e.key === 'Enter' || e.key === 'Escape') e.currentTarget.blur()
+ }}
+ />
+ )
+ }
+ >
+ {g.channels.map((c) => channelRow(c, g.id))}
+ </GroupFold>
))}
</Section>
diff --git a/src/renderer/src/styles.css b/src/renderer/src/styles.css
index bd44c6c..674271d 100644
--- a/src/renderer/src/styles.css
+++ b/src/renderer/src/styles.css
@@ -6620,6 +6620,7 @@ kbd {
}
[data-os='mac'] .lightbox__bar {
padding-left: 84px; /* the window's buttons are here */
+}
.local-link {
display: inline;
padding: 0;
@@ -6669,6 +6670,24 @@ kbd {
overflow: visible;
}
+/* Channel groups */
+.channel-group__head {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 6px 6px 4px 8px;
+ font-size: 12px;
+ font-weight: 600;
+}
+.channel-group__name {
+ width: calc(100% - 16px);
+ margin: 4px 8px;
+ font-size: 12px;
+}
+.channel-drop {
+ height: 6px;
+}
+
/* The wiki: what you and the team know, as linked pages */
@@ -6953,3 +6972,20 @@ button.wk-pill.is-on { box-shadow: 0 0 0 1.5px var(--k); background: color-mix(i
.wk-import__stats span { display: grid; gap: 2px; padding: 14px 16px; border-radius: 14px; background: var(--hover); color: var(--text-2); font-size: 12.5px; }
.wk-import__stats b { font-size: 26px; letter-spacing: -0.02em; color: var(--text); }
.wiki-link--file { cursor: default; }
+/* A group's channels sit a step in, along a thin line, so it's clear where the group ends. */
+.channel-group > [draggable] {
+ position: relative;
+ padding-left: 14px;
+}
+.channel-group > [draggable]::before {
+ content: '';
+ position: absolute;
+ left: 15px;
+ top: 3px;
+ bottom: 3px;
+ width: 1px;
+ background: var(--border-strong);
+}
+.channel-group > [draggable] .nav-item {
+ padding-left: 12px;
+}
diff --git a/src/shared/channel-layout.ts b/src/shared/channel-layout.ts
new file mode 100644
index 0000000..6eecf62
--- /dev/null
+++ b/src/shared/channel-layout.ts
@@ -0,0 +1,80 @@
+// How the person arranged the channels in the sidebar. Only names and order, so it lives in the
+// workspace's settings. A channel it doesn't know yet shows last, and one that's gone is forgotten.
+export interface ChannelGroup {
+ id: string
+ name: string
+ channels: string[]
+}
+
+export interface ChannelLayout {
+ groups: ChannelGroup[]
+ loose: string[] // the channels in no group, shown first
+}
+
+export const EMPTY_LAYOUT: ChannelLayout = { groups: [], loose: [] }
+
+// Settings keep whatever was saved: a bad value loses the arrangement, not the sidebar.
+const ids = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : [])
+function readable(saved: ChannelLayout | null | undefined): ChannelLayout {
+ if (!saved || typeof saved !== 'object') return EMPTY_LAYOUT
+ const groups = Array.isArray(saved.groups) ? saved.groups.filter((g) => g && typeof g.id === 'string' && typeof g.name === 'string') : []
+ return { loose: ids(saved.loose), groups: groups.map((g) => ({ ...g, channels: ids(g.channels) })) }
+}
+
+export function arrange<T extends { id: string }>(channels: T[], saved?: ChannelLayout | null): { loose: T[]; groups: (Omit<ChannelGroup, 'channels'> & { channels: T[] })[] } {
+ const layout = readable(saved)
+ const byId = new Map(channels.map((c) => [c.id, c]))
+ const placed = new Set<string>()
+ const take = (ids: string[]): T[] =>
+ ids.flatMap((id) => {
+ const c = byId.get(id)
+ if (!c || placed.has(id)) return []
+ placed.add(id)
+ return [c]
+ })
+ const groups = layout.groups.map((g) => ({ ...g, channels: take(g.channels) }))
+ const loose = take(layout.loose)
+ return { loose: [...loose, ...channels.filter((c) => !placed.has(c.id))], groups }
+}
+
+const without = (layout: ChannelLayout, channelId: string): ChannelLayout => ({
+ loose: layout.loose.filter((id) => id !== channelId),
+ groups: layout.groups.map((g) => ({ ...g, channels: g.channels.filter((id) => id !== channelId) }))
+})
+
+const inserted = (list: string[], id: string, before?: string): string[] => {
+ const at = before ? list.indexOf(before) : -1
+ return at < 0 ? [...list, id] : [...list.slice(0, at), id, ...list.slice(at)]
+}
+
+// Puts a channel in a group (or in none), before another channel or last. Starts from every
+// channel, so the order of those never moved stays what the person sees.
+export function moveChannel(channels: { id: string }[], layout: ChannelLayout | undefined, channelId: string, to: { group?: string; before?: string }): ChannelLayout {
+ const now = arrange(channels, layout)
+ const full: ChannelLayout = { loose: now.loose.map((c) => c.id), groups: now.groups.map((g) => ({ ...g, channels: g.channels.map((c) => c.id) })) }
+ if (to.before === channelId) return full
+ const rest = without(full, channelId)
+ if (!to.group) return { ...rest, loose: inserted(rest.loose, channelId, to.before) }
+ return { ...rest, groups: rest.groups.map((g) => (g.id === to.group ? { ...g, channels: inserted(g.channels, channelId, to.before) } : g)) }
+}
+
+// One place up or down, among its neighbors.
+export function nudgeChannel(channels: { id: string }[], layout: ChannelLayout | undefined, channelId: string, by: -1 | 1): ChannelLayout {
+ const now = arrange(channels, layout)
+ const group = now.groups.find((g) => g.channels.some((c) => c.id === channelId))
+ const list = (group?.channels ?? now.loose).map((c) => c.id)
+ const at = list.indexOf(channelId)
+ const neighbor = list[at + by]
+ if (!neighbor) return moveChannel(channels, layout, channelId, { group: group?.id, before: list[at + 1] })
+ return moveChannel(channels, layout, channelId, { group: group?.id, before: by < 0 ? neighbor : list[at + 2] })
+}
+
+export const addGroup = (layout: ChannelLayout = EMPTY_LAYOUT, group: { id: string; name: string }): ChannelLayout => ({ ...layout, groups: [...layout.groups, { ...group, channels: [] }] })
+
+export const renameGroup = (layout: ChannelLayout, id: string, name: string): ChannelLayout => ({ ...layout, groups: layout.groups.map((g) => (g.id === id ? { ...g, name } : g)) })
+
+// Its channels go back to the loose ones: deleting a group deletes no channel.
+export const removeGroup = (layout: ChannelLayout, id: string): ChannelLayout => ({
+ groups: layout.groups.filter((g) => g.id !== id),
+ loose: [...layout.loose, ...(layout.groups.find((g) => g.id === id)?.channels ?? [])]
+})
diff --git a/src/shared/types.ts b/src/shared/types.ts
index d80261d..22c6b1d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1,5 +1,6 @@
// Domain types shared by the core (utility process) and the renderer.
import type { AvatarDefinition } from 'open-bot-avatar'
+import type { ChannelLayout } from './channel-layout'
import { L, lang, type Lang } from './lang'
export type AgentColor = 'sky' | 'indigo' | 'violet' | 'rose' | 'amber' | 'green' | 'teal' | 'graphite'
@@ -210,6 +211,7 @@ export interface Settings {
engines: Record<EngineId, EngineStatus>
routerModel: string // a model id, or 'jev' for TypeSafe's Jev (falls back to Haiku)
jevKey?: boolean // a TypeSafe key is saved (the key itself never leaves the core)
+ channelLayout?: ChannelLayout // the person's order and groups in the sidebar
browserJev?: boolean // Jev finds what agents click in their browsers (each click sends the page to TypeSafe)
memoryModel: string // summarizes conversations and extracts memories
memoryLearning: 'approve' | 'auto' | 'off' // what extracted memories about me become
diff --git a/test/channel-layout.test.ts b/test/channel-layout.test.ts
new file mode 100644
index 0000000..c981c49
--- /dev/null
+++ b/test/channel-layout.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, it } from 'vitest'
+import { addGroup, arrange, EMPTY_LAYOUT, moveChannel, nudgeChannel, removeGroup, renameGroup, type ChannelLayout } from '../src/shared/channel-layout'
+
+const channels = ['a', 'b', 'c', 'd'].map((id) => ({ id }))
+const ids = (l: { id: string }[]): string[] => l.map((c) => c.id)
+
+describe('arrange', () => {
+ it('with nothing set, keeps the order they came in', () => {
+ expect(ids(arrange(channels).loose)).toEqual(['a', 'b', 'c', 'd'])
+ expect(arrange(channels).groups).toEqual([])
+ })
+ it('shows a new channel last, and forgets one that is gone', () => {
+ const layout: ChannelLayout = { loose: ['b', 'sumiu'], groups: [{ id: 'g', name: 'G', channels: ['c', 'sumiu'] }] }
+ const r = arrange(channels, layout)
+ expect(ids(r.loose)).toEqual(['b', 'a', 'd'])
+ expect(ids(r.groups[0]!.channels)).toEqual(['c'])
+ })
+ it('survives a bad saved value, showing every channel', () => {
+ for (const bad of [null, {}, { groups: 'x' }, { groups: [{ id: 'g' }], loose: 3 }, { groups: [{ id: 'g', name: 'G' }] }]) {
+ expect(ids(arrange(channels, bad as never).loose)).toEqual(['a', 'b', 'c', 'd'])
+ }
+ })
+ it('shows a channel listed twice only once', () => {
+ const r = arrange(channels, { loose: ['a'], groups: [{ id: 'g', name: 'G', channels: ['a', 'b'] }] })
+ expect(ids(r.groups[0]!.channels)).toEqual(['a', 'b'])
+ expect(ids(r.loose)).toEqual(['c', 'd'])
+ })
+})
+
+describe('moving', () => {
+ it('moves before another, keeping the rest as seen', () => {
+ expect(moveChannel(channels, undefined, 'd', { before: 'b' }).loose).toEqual(['a', 'd', 'b', 'c'])
+ expect(moveChannel(channels, undefined, 'a', {}).loose).toEqual(['b', 'c', 'd', 'a'])
+ expect(moveChannel(channels, undefined, 'b', { before: 'b' }).loose).toEqual(['a', 'b', 'c', 'd'])
+ })
+ it('into a group and out of it', () => {
+ const grouped = addGroup(EMPTY_LAYOUT, { id: 'g', name: 'Clientes' })
+ const inside = moveChannel(channels, grouped, 'b', { group: 'g' })
+ expect(inside.groups[0]!.channels).toEqual(['b'])
+ expect(inside.loose).toEqual(['a', 'c', 'd'])
+ const out = moveChannel(channels, inside, 'b', { before: 'c' })
+ expect(out.groups[0]!.channels).toEqual([])
+ expect(out.loose).toEqual(['a', 'b', 'c', 'd'])
+ })
+ it('one up or down, stopping at the ends, inside its group', () => {
+ expect(arrange(channels, nudgeChannel(channels, undefined, 'c', -1)).loose.map((c) => c.id)).toEqual(['a', 'c', 'b', 'd'])
+ expect(arrange(channels, nudgeChannel(channels, undefined, 'b', 1)).loose.map((c) => c.id)).toEqual(['a', 'c', 'b', 'd'])
+ expect(arrange(channels, nudgeChannel(channels, undefined, 'a', -1)).loose.map((c) => c.id)).toEqual(['a', 'b', 'c', 'd'])
+ expect(arrange(channels, nudgeChannel(channels, undefined, 'd', 1)).loose.map((c) => c.id)).toEqual(['a', 'b', 'c', 'd'])
+ const g: ChannelLayout = { loose: [], groups: [{ id: 'g', name: 'G', channels: ['a', 'b', 'c'] }] }
+ expect(arrange(channels, nudgeChannel(channels, g, 'c', -1)).groups[0]!.channels.map((c) => c.id)).toEqual(['a', 'c', 'b'])
+ })
+ it('renaming a group and removing it keeps its channels', () => {
+ const g: ChannelLayout = { loose: ['a'], groups: [{ id: 'g', name: 'G', channels: ['b', 'c'] }] }
+ expect(renameGroup(g, 'g', 'Novo').groups[0]!.name).toBe('Novo')
+ expect(removeGroup(g, 'g')).toEqual({ groups: [], loose: ['a', 'b', 'c'] })
+ })
+})