From 22fa2af5f92b304e864c5dbdf344e3d30803de7a Mon Sep 17 00:00:00 2001 From: moreih29 Date: Fri, 20 Nov 2026 01:05:11 +0900 Subject: [PATCH 1/2] feat: rename and color workspaces from the sidebar and CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the unused colorTone enum with a workspace color: "auto" or one of the theme's lane colors (red, amber, lime, green, cyan, blue, violet, pink). Migration v10 adds the color column (every workspace starts as "auto") and drops color_tone. - Sidebar row menu: Rename… (inline) and Color ›. The color tints the row's folder icon, so it is not mistaken for the connection status dot. - Agent view uses the chosen color, falling back to the id-hash lane color for "auto". - CLI: `nexus workspace edit --name/--color`, `workspace add --color`, `color` in --json. New consent kind workspaceEdit. - docs/CLI.md and the agent context note updated. Co-Authored-By: Claude Sonnet 5.5 --- docs/CLI.md | 12 +- .../features/cli/commands/agent-context.ts | 2 +- src/main/features/cli/commands/workspace.ts | 74 ++++++++++++- src/main/features/cli/context.ts | 4 + src/main/features/cli/index.ts | 21 +++- src/main/features/workspace/manager.ts | 7 +- src/main/infra/storage/global-storage.ts | 13 ++- src/main/infra/storage/migrations.ts | 14 +++ .../components/agent-view/agent-pane.tsx | 3 +- .../components/agent-view/agent-sidebar.tsx | 4 +- src/renderer/components/workbench/sidebar.tsx | 103 +++++++++++++++++- .../workbench/workspace-color-menu.tsx | 53 +++++++++ src/renderer/services/agent-view/agents.ts | 18 ++- src/shared/cli/ui.ts | 1 + src/shared/i18n/locales/en/common.json | 16 ++- src/shared/i18n/locales/en/settings.json | 1 + src/shared/i18n/locales/ko/common.json | 16 ++- src/shared/i18n/locales/ko/settings.json | 1 + src/shared/ipc/contract.ts | 4 +- src/shared/types/color-tone.ts | 5 - src/shared/types/workspace-color.ts | 37 +++++++ src/shared/types/workspace.ts | 7 +- tests/integration/storage/restart.test.ts | 2 +- .../workspace-reorder.test.ts | 12 +- tests/unit/main/cli/fake-services.ts | 23 +++- tests/unit/main/cli/workspace-sidebar.test.ts | 80 ++++++++++++++ .../features/fs/bridge/fs-provider.test.ts | 2 +- .../main/features/fs/trash-handler.test.ts | 2 +- .../features/git/domain/git-registry.test.ts | 2 +- .../storage/storage-entry-points.test.ts | 2 +- .../main/infra/storage/storage-global.test.ts | 76 ++++++++++--- .../ipc/channels/fs/search-handlers.test.ts | 2 +- tests/unit/main/tasks/naming.test.ts | 2 +- tests/unit/main/tasks/service.test.ts | 2 +- .../files/file-tree-actions.test.ts | 2 +- .../renderer/keybindings/file-delete.test.ts | 2 +- .../services/agent-sessions/inbox.test.ts | 2 +- .../services/agent-sessions/model.test.ts | 2 +- .../agent-sessions/session-changes.test.ts | 2 +- .../encoding/decode-file-content.test.ts | 2 +- .../model/model-cache-reconnect.test.ts | 2 +- .../fs-mutations/confirm-delete-batch.test.ts | 2 +- .../workspace/workspace-start-task.test.ts | 2 +- .../state/operations/focus-resync.test.ts | 2 +- .../operations/workspace-selection.test.ts | 2 +- .../workspace-status-reopen.test.ts | 2 +- .../state/stores/tabs/new-tab-types.test.ts | 2 +- .../renderer/state/stores/workspaces.test.ts | 2 +- .../shared/types/workspace-location.test.ts | 2 +- 49 files changed, 566 insertions(+), 87 deletions(-) create mode 100644 src/renderer/components/workbench/workspace-color-menu.tsx delete mode 100644 src/shared/types/color-tone.ts create mode 100644 src/shared/types/workspace-color.ts diff --git a/docs/CLI.md b/docs/CLI.md index 899a0491d..c06ef6138 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -238,11 +238,12 @@ codex exec resume <세션 id> "이어서 문서도" # codex 도 같 - 다른 터미널의 세션은 `--tab`(다른 워크스페이스면 `--workspace` 도)으로 고릅니다. - 앱을 업데이트하기 전부터 돌던 Claude · Codex 탭의 프로그램은 예전 환경 그대로라, 그 탭이 띄운 실행은 탭의 프로그램이 다시 시작된 뒤부터 보입니다. -## 워크스페이스 추가 · 제거 · 정리 +## 워크스페이스 추가 · 제거 · 이름 · 색 · 정리 ```bash nexus workspace add ../lib --name 라이브러리 --show # 이 터미널 위치 기준 폴더를 사이드바 끝에 추가 nexus workspace remove 라이브러리 # 앱 목록에서 제거(폴더는 그대로) +nexus workspace edit lib --name 라이브러리 --color blue # 이름 바꾸기 · 색 지정 (--color auto 는 앱이 고름) nexus workspace pin lib # 사이드바 위쪽에 고정 (workspace unpin 으로 해제) nexus workspace move lib --before api # api 바로 위로 (--after · --top · --bottom) ``` @@ -251,17 +252,22 @@ nexus workspace move lib --before api # api 바로 위로 (--after - 폴더 이름이 사이드바 이름이 됩니다. `--name` 으로 바꿀 수 있습니다. - SSH · WSL 터미널에서 실행하면 그 터미널과 같은 호스트(같은 접속 방법)의 폴더를 추가합니다. - 처음 보여줄 때 연결합니다. `--show` 면 바로 그 워크스페이스로 전환합니다. + - `--color` 로 색을 정해 추가할 수 있습니다. - 이미 목록에 있는 폴더면 새로 만들지 않고 그 워크스페이스를 알려줍니다. 묻지 않습니다. - `workspace remove` 는 사이드바 메뉴의 **목록에서 제거** 와 같습니다. - 그 워크스페이스와 작업들의 터미널을 닫고(실행 중인 프로그램 포함) 사이드바에서 뺍니다. 폴더는 지우지 않습니다. 작업의 워크트리 폴더와 브랜치도 디스크에 남습니다. - 저장하지 않은 파일이 있거나, 명령을 실행한 터미널이 그 워크스페이스(또는 그 작업) 안에 있으면 거절합니다. - 작업 하나만 지우려면 `worktree remove` 를 씁니다. - 항상 다른 워크스페이스라서 아래 "다른 워크스페이스 바꾸기" 설정을 따릅니다. +- `workspace edit` 는 사이드바 메뉴의 **이름 바꾸기** · **색** 과 같습니다. `--name` · `--color` 중 하나 이상을 줍니다. + - 색은 `red` · `amber` · `lime` · `green` · `cyan` · `blue` · `violet` · `pink` 이거나 `auto` 입니다. 사이드바 행의 폴더 아이콘과 에이전트 뷰에서 그 워크스페이스를 가르는 색이 되고, `auto` 는 앱이 워크스페이스마다 골라 줍니다. 새로 추가한 워크스페이스는 `auto` 입니다. + - 워크스페이스의 작업(워크트리)은 그 워크스페이스의 색을 따르므로 따로 바꾸지 않습니다. + - 지금 값과 같으면 아무것도 바꾸지 않고 묻지도 않습니다. `workspace list --json` 에 `color` 가 나옵니다. - `workspace pin` 은 사이드바의 고정 버튼과 같습니다. 고정한 것들의 맨 아래로 갑니다. - `workspace move` 는 사이드바에서 끌어 옮기는 것과 같습니다. `--before` · `--after` 로 다른 묶음(고정 · 고정 안 함)의 워크스페이스 옆에 두면 그 묶음으로 고정되거나 풀립니다. `--top` · `--bottom` 은 지금 묶음 안에서 맨 위 · 맨 아래로 옮깁니다. -- 작업(워크트리)은 사이드바에서 워크스페이스 아래에 보여서 이름 · 고정 · 순서를 바꾸지 않습니다. +- 작업(워크트리)은 사이드바에서 워크스페이스 아래에 보여서 이름 · 색 · 고정 · 순서를 바꾸지 않습니다. - `workspace list` 는 사이드바 순서(고정한 것 먼저)이고, 고정한 것에 `pinned` 가 붙습니다. -- 다른 워크스페이스의 이름 · 고정 · 순서 바꾸기는 "다른 워크스페이스 바꾸기" 설정을 따릅니다. +- 다른 워크스페이스의 이름 · 색 · 고정 · 순서 바꾸기는 "다른 워크스페이스 바꾸기" 설정을 따릅니다. ## 작업(워크트리) 만들기 · 지우기 diff --git a/src/main/features/cli/commands/agent-context.ts b/src/main/features/cli/commands/agent-context.ts index 5734bd165..d4f2087a5 100644 --- a/src/main/features/cli/commands/agent-context.ts +++ b/src/main/features/cli/commands/agent-context.ts @@ -88,7 +88,7 @@ function agentContextNote(heading: string, inRoom: boolean): string { "listens on, as nexus port list shows), then snapshot (the page with element refs), click e12,", "fill e3 TEXT, press Enter, screenshot, console and eval. The workbench can be arranged", "too: nexus layout show/split/resize, tab move/rename/pin, panel show/hide, reveal,", - "workspace move/pin (the sidebar's rows),", + "workspace move/pin/edit (the sidebar's rows: order, pin, name and color),", "and nexus view agents|workspaces, view layout/open/split for the agent view's panels;", "nexus problems lists the language servers' errors in open files.", "The user's notes are the app's (its Notes panel): a note they speak of is one of these,", diff --git a/src/main/features/cli/commands/workspace.ts b/src/main/features/cli/commands/workspace.ts index 3ee3127c9..04df1a422 100644 --- a/src/main/features/cli/commands/workspace.ts +++ b/src/main/features/cli/commands/workspace.ts @@ -1,6 +1,12 @@ /** nexus status, nexus workspace ... and nexus worktree ... (the app's tasks). */ import type { CliTaskStart, CliView } from "../../../../shared/cli/ui"; import type { WorkspaceLocation, WorkspaceMeta } from "../../../../shared/types/workspace"; +import { + WORKSPACE_COLOR_AUTO, + WORKSPACE_COLORS, + type WorkspaceColor, + WorkspaceColorSchema, +} from "../../../../shared/types/workspace-color"; import { compareWorkspaceOrder } from "../../../../shared/workspace-order"; import { CliUsageError, exactArgs } from "../args"; import { @@ -31,6 +37,7 @@ export function workspaceJson(ctx: CliContext, workspace: WorkspaceMeta) { name: workspace.name, location: workspace.location, pinned: workspace.pinned, + color: workspace.color, current: workspace.id === ctx.caller.workspaceId, shown: shown?.workspaceId === workspace.id, ...(workspace.task @@ -526,6 +533,24 @@ function locationBeside(beside: WorkspaceLocation, folder: string): WorkspaceLoc : { ...beside, remotePath: folder }; } +const COLOR_FLAG = { + type: "string", + value: "COLOR", + description: `One of ${WORKSPACE_COLORS.join(", ")}, or ${WORKSPACE_COLOR_AUTO} for the app's own pick`, +} as const; + +/** The color a --color flag names; undefined when it is not given. */ +export function colorFlag(value: unknown): WorkspaceColor | undefined { + if (value === undefined) return undefined; + const parsed = WorkspaceColorSchema.safeParse(String(value).trim().toLowerCase()); + if (!parsed.success) { + throw new CliUsageError( + `--color is one of ${WORKSPACE_COLORS.join(", ")}, or ${WORKSPACE_COLOR_AUTO}`, + ); + } + return parsed.data; +} + const workspaceAdd: CliCommand = { path: ["workspace", "add"], summary: "Add a folder to the app as a workspace, on this terminal's host", @@ -534,9 +559,11 @@ const workspaceAdd: CliCommand = { "As Add Workspace in the app: the folder, from this terminal's directory, goes at the end\n" + "of the sidebar, named after it unless --name. An SSH or WSL terminal adds a folder on its\n" + "own host, reached as its workspace is. It connects once it is first shown, so --show it\n" + - "or click it. A folder already in the list gives that workspace.", + "or click it. --color gives it a color, as the sidebar's menu does. A folder already in\n" + + "the list gives that workspace as it is.", flags: { name: { type: "string", value: "NAME", description: "The name the sidebar shows" }, + color: COLOR_FLAG, show: { type: "boolean", description: "Show it to the user" }, }, async run(ctx, { positionals, flags }) { @@ -544,7 +571,8 @@ const workspaceAdd: CliCommand = { const caller = resolveWorkspace(ctx, undefined); const location = locationBeside(caller.location, absolutePath(ctx, caller, input)); const name = (flags.name as string | undefined)?.trim() || undefined; - const { workspace, added } = await ctx.services.addWorkspace(location, name); + const color = colorFlag(flags.color); + const { workspace, added } = await ctx.services.addWorkspace(location, name, color); if (flags.show === true) await ctx.services.ui("workspace.show", { workspaceId: workspace.id }); const what = added ? "Added" : "Already listed"; return output( @@ -632,6 +660,47 @@ function workspacePinCommand(pinned: boolean): CliCommand { }; } +const workspaceEdit: CliCommand = { + path: ["workspace", "edit"], + summary: "Rename a workspace or change its color, as the sidebar's menu does", + args: "", + details: + "Give --name, --color or both. The color marks the workspace in the sidebar and the agent\n" + + `view; ${WORKSPACE_COLOR_AUTO} leaves it to the app. A worktree is shown under its workspace and\n` + + "takes its color, so it is not edited here. Another workspace's is changed with the user's leave.", + flags: { + name: { type: "string", value: "NAME", description: "The name the sidebar shows" }, + color: COLOR_FLAG, + }, + async run(ctx, { positionals, flags }) { + const [selector] = exactArgs(positionals, "workspace") as [string]; + const name = (flags.name as string | undefined)?.trim(); + const color = colorFlag(flags.color); + if (flags.name !== undefined && !name) throw new CliUsageError("--name is empty"); + if (name === undefined && color === undefined) { + throw new CliUsageError("give --name, --color or both"); + } + const target = sidebarWorkspace(ctx, selector); + const edit = { + ...(name !== undefined && name !== target.name ? { name } : {}), + ...(color !== undefined && color !== target.color ? { color } : {}), + }; + if (Object.keys(edit).length === 0) { + return output(`${target.name} is as asked.`, workspaceJson(ctx, target)); + } + await mayChange(ctx, target, { kind: "workspaceEdit" }); + const changed = ctx.services.editWorkspace(target.id, edit); + const parts = [ + ...(edit.name !== undefined ? [`renamed from ${target.name}`] : []), + ...(edit.color !== undefined ? [`color ${changed.color}`] : []), + ]; + return output( + `${changed.name} (${shortId(changed.id)}): ${parts.join(", ")}.`, + workspaceJson(ctx, changed), + ); + }, +}; + /** What a group of the sidebar is called. */ const GROUP_NAMES = { pinned: "pinned workspaces", unpinned: "workspaces not pinned" } as const; @@ -696,6 +765,7 @@ export const workspaceCommands: CliCommand[] = [ workspaceSwitch, workspaceAdd, workspaceRemove, + workspaceEdit, workspacePinCommand(true), workspacePinCommand(false), workspaceMove, diff --git a/src/main/features/cli/context.ts b/src/main/features/cli/context.ts index 81509d40a..2a4527128 100644 --- a/src/main/features/cli/context.ts +++ b/src/main/features/cli/context.ts @@ -19,6 +19,7 @@ import type { TranscriptFile } from "../../../shared/notes/transcript"; import type { NoteAsset, NoteContent, NoteSummary } from "../../../shared/notes/types"; import type { ListeningPort, PortForward } from "../../../shared/pty/ports"; import type { WorkspaceLocation, WorkspaceMeta } from "../../../shared/types/workspace"; +import type { WorkspaceColor } from "../../../shared/types/workspace-color"; import type { TabActivity } from "./activity"; import type { BrowserDriver } from "./browser/driver"; import type { ChangeRequest } from "./consent"; @@ -115,7 +116,10 @@ export interface CliServices { addWorkspace( location: WorkspaceLocation, name: string | undefined, + color?: WorkspaceColor, ): Promise<{ workspace: WorkspaceMeta; added: boolean }>; + /** Renames a workspace and sets its color, as the sidebar's menu does; the workspace as it is now. */ + editWorkspace(id: string, edit: { name?: string; color?: WorkspaceColor }): WorkspaceMeta; /** * Pins or unpins a workspace as the sidebar's pin does (to the end of its * new group); the workspace as it is now. diff --git a/src/main/features/cli/index.ts b/src/main/features/cli/index.ts index 497ea7f3d..351508cef 100644 --- a/src/main/features/cli/index.ts +++ b/src/main/features/cli/index.ts @@ -21,6 +21,7 @@ import { createLogger } from "../../../shared/log/main"; import { redactLogSecrets } from "../../../shared/log/redact-secrets"; import type { ListeningPort } from "../../../shared/pty/ports"; import type { WorkspaceLocation, WorkspaceMeta } from "../../../shared/types/workspace"; +import type { WorkspaceColor } from "../../../shared/types/workspace-color"; import type { AgentChannel } from "../../infra/agent/channel"; import { register, validateArgs } from "../../infra/ipc-router"; import { getBrowserRegistry, onBrowserTabCreated } from "../browser"; @@ -71,8 +72,15 @@ export interface SetupCliFeatureOptions { agentHost: ActivitySource & { call(method: string, args: unknown): Promise }; workspaceManager: { list(): WorkspaceMeta[]; - create(opts: { location: WorkspaceLocation; name?: string }): WorkspaceMeta; - update(id: string, partial: { pinned?: boolean }): WorkspaceMeta; + create(opts: { + location: WorkspaceLocation; + name?: string; + color?: WorkspaceColor; + }): WorkspaceMeta; + update( + id: string, + partial: { pinned?: boolean; name?: string; color?: WorkspaceColor }, + ): WorkspaceMeta; reorder( id: string, opts: { beforeId?: string; afterId?: string; targetGroup: "pinned" | "unpinned" }, @@ -244,7 +252,7 @@ export function setupCliFeature(options: SetupCliFeatureOptions): CliFeature { const services: CliServices = { appVersion: options.appVersion, listWorkspaces: () => workspaceManager.list(), - addWorkspace: async (location, name) => { + addWorkspace: async (location, name, color) => { const listed = await listedAt(workspaceManager.list(), location); if (listed) return { workspace: listed, added: false }; if (location.kind === "local") { @@ -252,10 +260,15 @@ export function setupCliFeature(options: SetupCliFeatureOptions): CliFeature { if (!found?.isDirectory()) throw new CliError(`no folder at ${location.rootPath}`); } return { - workspace: workspaceManager.create({ location, ...(name ? { name } : {}) }), + workspace: workspaceManager.create({ + location, + ...(name ? { name } : {}), + ...(color ? { color } : {}), + }), added: true, }; }, + editWorkspace: (id, edit) => workspaceManager.update(id, edit), pinWorkspace: (id, pinned) => workspaceManager.update(id, { pinned }), moveWorkspace: (id, { group, ...anchor }) => workspaceManager.reorder(id, { ...anchor, targetGroup: group }), diff --git a/src/main/features/workspace/manager.ts b/src/main/features/workspace/manager.ts index a3d6e6c2b..3ae2ec5b5 100644 --- a/src/main/features/workspace/manager.ts +++ b/src/main/features/workspace/manager.ts @@ -12,6 +12,7 @@ import { type WorkspaceTask, workspaceLocationKey, } from "../../../shared/types/workspace"; +import type { WorkspaceColor } from "../../../shared/types/workspace-color"; import type { AgentChannel } from "../../infra/agent/channel"; import { type CreateLocalChannelOptions, @@ -82,8 +83,8 @@ const log = createLogger("workspace"); export type BroadcastFn = (channelName: string, event: string, args: unknown) => void; export type WorkspaceCreateOptions = - | { location: WorkspaceLocation; name?: string; task?: WorkspaceTask } - | { rootPath: string; name?: string; task?: WorkspaceTask }; + | { location: WorkspaceLocation; name?: string; color?: WorkspaceColor; task?: WorkspaceTask } + | { rootPath: string; name?: string; color?: WorkspaceColor; task?: WorkspaceTask }; export type WorkspaceSshChannelFactory = (options: CreateSshChannelOptions) => SshChannel; export type WorkspaceSshBootstrap = ( options: EnsureRemoteAgentOptions, @@ -729,7 +730,7 @@ export class WorkspaceManager { name, location, rootPath, - colorTone: "default", + color: opts.color ?? "auto", pinned: false, lastOpenedAt: new Date().toISOString(), tabs: [], diff --git a/src/main/infra/storage/global-storage.ts b/src/main/infra/storage/global-storage.ts index f81db7dc9..32da1d4ca 100644 --- a/src/main/infra/storage/global-storage.ts +++ b/src/main/infra/storage/global-storage.ts @@ -10,6 +10,7 @@ import { type WorkspaceTask, WorkspaceTaskSchema, } from "../../../shared/types/workspace"; +import { toWorkspaceColor } from "../../../shared/types/workspace-color"; import { applyMigrations, type SqliteDb } from "./migrations"; // --------------------------------------------------------------------------- @@ -132,7 +133,7 @@ interface WorkspaceRow { name: string; root_path: string; location: string | null; - color_tone: string; + color: string; pinned: number; last_opened_at: number; sort_order: number; @@ -231,7 +232,7 @@ function rowToMeta(row: WorkspaceRow): WorkspaceMeta { name: row.name, location, rootPath: rootPathFromLocation(location), - colorTone: row.color_tone as WorkspaceMeta["colorTone"], + color: toWorkspaceColor(row.color), pinned: row.pinned === 1, lastOpenedAt: new Date(row.last_opened_at).toISOString(), tabs: [], @@ -293,7 +294,7 @@ export class GlobalStorage { this.db .prepare( `INSERT INTO workspaces - (id, name, root_path, location, color_tone, pinned, last_opened_at, + (id, name, root_path, location, color, pinned, last_opened_at, sort_order, pinned_sort_order, task) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, ) @@ -302,7 +303,7 @@ export class GlobalStorage { normalized.name, rootPath, JSON.stringify(location), - normalized.colorTone ?? "default", + normalized.color, normalized.pinned ? 1 : 0, normalized.lastOpenedAt ? new Date(normalized.lastOpenedAt).getTime() : Date.now(), normalized.sortOrder, @@ -334,14 +335,14 @@ export class GlobalStorage { this.db .prepare( `UPDATE workspaces - SET name = ?, root_path = ?, location = ?, color_tone = ?, pinned = ?, last_opened_at = ? + SET name = ?, root_path = ?, location = ?, color = ?, pinned = ?, last_opened_at = ? WHERE id = ?`, ) .run( partial.name ?? row.name, rootPath, locationJson, - (partial.colorTone ?? row.color_tone) as string, + partial.color ?? toWorkspaceColor(row.color), partial.pinned !== undefined ? (partial.pinned ? 1 : 0) : row.pinned, partial.lastOpenedAt ? new Date(partial.lastOpenedAt).getTime() : row.last_opened_at, id, diff --git a/src/main/infra/storage/migrations.ts b/src/main/infra/storage/migrations.ts index d3a3c2555..f766ec3be 100644 --- a/src/main/infra/storage/migrations.ts +++ b/src/main/infra/storage/migrations.ts @@ -289,6 +289,20 @@ export const MIGRATIONS: Migration[] = [ db.exec(`ALTER TABLE session_spans ADD COLUMN agent TEXT`); }, }, + // A workspace's color replaces its tone (subdued, default, prominent, pinned), + // which no screen used: every workspace starts as "auto", whatever its tone + // was. Idempotent: a half-run migration resumes where it stopped. + { + version: 10, + up: (db) => { + if (!hasColumn(db, "workspaces", "color")) { + db.exec("ALTER TABLE workspaces ADD COLUMN color TEXT NOT NULL DEFAULT 'auto';"); + } + if (hasColumn(db, "workspaces", "color_tone")) { + db.exec("ALTER TABLE workspaces DROP COLUMN color_tone;"); + } + }, + }, ]; export function applyMigrations(db: SqliteDb): void { diff --git a/src/renderer/components/agent-view/agent-pane.tsx b/src/renderer/components/agent-view/agent-pane.tsx index eeeef572e..60957ab63 100644 --- a/src/renderer/components/agent-view/agent-pane.tsx +++ b/src/renderer/components/agent-view/agent-pane.tsx @@ -376,6 +376,7 @@ export const AgentPane = memo(function AgentPane({ function WorkspaceChip({ workspaceId, className }: { workspaceId: string; className?: string }) { const name = useWorkspacesStore((s) => s.workspaces.find((w) => w.id === workspaceId)?.name); const rootId = useWorkspacesStore((s) => rootWorkspaceId(s.workspaces, workspaceId)); + const color = useWorkspacesStore((s) => s.workspaces.find((w) => w.id === rootId)?.color); return ( {name} diff --git a/src/renderer/components/agent-view/agent-sidebar.tsx b/src/renderer/components/agent-view/agent-sidebar.tsx index 3baba5ac6..ac086e779 100644 --- a/src/renderer/components/agent-view/agent-sidebar.tsx +++ b/src/renderer/components/agent-view/agent-sidebar.tsx @@ -421,7 +421,7 @@ function FamilyGroup({ {root.name} @@ -693,7 +693,7 @@ function WorkspaceTag({ workspace, root }: { workspace: WorkspaceMeta; root: Wor {workspace.name} diff --git a/src/renderer/components/workbench/sidebar.tsx b/src/renderer/components/workbench/sidebar.tsx index 9385f32ed..bb27d06df 100644 --- a/src/renderer/components/workbench/sidebar.tsx +++ b/src/renderer/components/workbench/sidebar.tsx @@ -1,11 +1,12 @@ import { Folder, GitBranch, Server, SquareTerminal, X } from "lucide-react"; -import React, { memo, useMemo } from "react"; +import React, { memo, useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useShallow } from "zustand/shallow"; import { cn } from "@/utils/cn"; import type { ClaudeStatus, StatusEntry } from "../../../shared/claude/status"; import { appErrorFailed } from "../../../shared/error/app-error"; import type { WorkspaceMeta } from "../../../shared/types/workspace"; +import { type WorkspaceColor, workspaceColorToken } from "../../../shared/types/workspace-color"; import { useIpcAction } from "../../hooks/use-ipc-action"; import { ipcCallResult } from "../../ipc/client"; import type { EstimatedGlyph } from "../../services/agent-sessions/model"; @@ -27,6 +28,7 @@ import { useWorkspacesStore, visibleWorkspaces, } from "../../state/stores/workspaces"; +import { isImeComposing } from "../../utils/ime"; import { WorkspaceProfileMenu } from "../agent-profiles/workspace-profile-menu"; import { WorkspaceStatusGlyph } from "../sidebar/workspace-status-glyph"; import { @@ -37,11 +39,13 @@ import { ContextMenuTrigger, } from "../ui/context-menu"; import { IconButton } from "../ui/icon-button"; +import { useContextMenuHandoff } from "../ui/use-context-menu-handoff"; import { formatSshSecondaryLine, formatSshTooltip } from "../workspace/add-workspace/ssh-helpers"; import { RowDropSlot } from "./dnd/row-drop-slot"; import { buildSlotsForGroup, type SlotInfo, useWorkspaceRowDnd } from "./dnd/use-workspace-row-dnd"; import { PinToggle } from "./pin-toggle"; import { SidebarResizeHandle } from "./sidebar-resize-handle"; +import { WorkspaceColorMenu } from "./workspace-color-menu"; // --------------------------------------------------------------------------- // Constants @@ -227,6 +231,56 @@ function WorkspaceRow({ }); } + // Rename and color go through workspace.update; the store follows its broadcast. + const { run: runUpdate } = useIpcAction({}); + function updateWorkspace(patch: { name?: string; color?: WorkspaceColor }) { + runUpdate(async (signal) => { + const result = await ipcCallResult( + "workspace", + "update", + { id: ws.id, ...patch }, + { signal }, + ); + if (!result.ok) { + const err = appErrorFailed(result.message); + surfaceError(err, { surface: "auto" }); + throw err; + } + return result.value; + }); + } + + // Inline rename: the name line becomes a field. Enter or leaving it commits (an empty name + // or the same one changes nothing), Escape cancels. The menu hands focus over to the field. + const handoff = useContextMenuHandoff(); + const [renaming, setRenaming] = useState(false); + const [nameDraft, setNameDraft] = useState(""); + const nameInputRef = useRef(null); + const renameSettled = useRef(true); + function startRename() { + renameSettled.current = false; + setNameDraft(ws.name); + setRenaming(true); + } + function endRename(commit: boolean) { + if (renameSettled.current) return; + renameSettled.current = true; + setRenaming(false); + const name = nameDraft.trim(); + if (commit && name !== "" && name !== ws.name) updateWorkspace({ name }); + } + useEffect(() => { + if (!renaming) return; + const id = requestAnimationFrame(() => { + nameInputRef.current?.focus(); + nameInputRef.current?.select(); + }); + return () => cancelAnimationFrame(id); + }, [renaming]); + + // The workspace's own color tints its icon; "auto" keeps the row as it was. + const colorToken = workspaceColorToken(ws.color); + // "Clear" only makes sense when there is a glyph or a preview message. const hasStatusToReset = glyphStatus !== null || previewMessage !== null; @@ -247,6 +301,8 @@ function WorkspaceRow({ isDragSource && "cursor-grabbing opacity-40", )} {...(rowDragProps as React.HTMLAttributes)} + // Dragging would take the mouse from the name being typed. + {...(renaming ? { draggable: false } : {})} >