Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(project-icons): icon picker (color/emoji/lucide/upload) in the identity section

enesa4c85c646650
diff --git a/package-lock.json b/package-lock.json
index dafa98eff..9c9bca6eb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "node-terminal",
- "version": "0.3.0",
+ "version": "0.3.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "node-terminal",
- "version": "0.3.0",
+ "version": "0.3.2",
"hasInstallScript": true,
"license": "BUSL-1.1",
"dependencies": {
@@ -14,10 +14,13 @@
"@xterm/addon-web-links": "^0.11.0",
"dompurify": "^3.4.13",
"electron-updater": "^6.8.9",
+ "emoji-picker-react": "^4.19.1",
+ "lucide-react": "^0.545.0",
"marked": "^12.0.2",
"monaco-editor": "^0.52.2",
"node-pty": "^1.0.0",
"qrcode": "^1.5.4",
+ "sharp": "^0.35.3",
"smart-whisper": "^0.8.1",
"tweetnacl": "^1.0.3",
"ws": "^8.21.0",
@@ -44,7 +47,6 @@
"jsdom": "^30.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "sharp": "^0.35.3",
"tailwindcss": "^4.3.1",
"typescript": "^7.0.2",
"vite": "^7.3.6",
@@ -883,7 +885,6 @@
"version": "1.11.2",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.2.tgz",
"integrity": "sha512-kyOl3X0DuTiT1h2ft8r2fYO8JYtU9a9Xis/zBSiGArNaagCOWx90N1k2wxp18czFDH+OgcWGb5ZP/XMt3dcyPA==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -1354,7 +1355,6 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz",
"integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=18"
@@ -1367,7 +1367,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1390,7 +1389,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1410,7 +1408,6 @@
"version": "0.35.3",
"resolved": "https://registry.npmjs.org/@img/sharp-freebsd-wasm32/-/sharp-freebsd-wasm32-0.35.3.tgz",
"integrity": "sha512-lUxcqWIj2wMQ9BrwNjngcr1gWUr5xgaGThBRqPPalIC2n67Cqj1uPh8NnA/ZhAg8hUbKl+kVHKwgUIwe6ZYPrg==",
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1433,7 +1430,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1450,7 +1446,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1467,7 +1462,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1484,7 +1478,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1501,7 +1494,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1518,7 +1510,6 @@
"cpu": [
"riscv64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1535,7 +1526,6 @@
"cpu": [
"s390x"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1552,7 +1542,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1569,7 +1558,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1586,7 +1574,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1603,7 +1590,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1626,7 +1612,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1649,7 +1634,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1672,7 +1656,6 @@
"cpu": [
"riscv64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1695,7 +1678,6 @@
"cpu": [
"s390x"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1718,7 +1700,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1741,7 +1722,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1764,7 +1744,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"os": [
@@ -1784,7 +1763,6 @@
"version": "0.35.3",
"resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.3.tgz",
"integrity": "sha512-cZ0XkcYGpHZkqW6iCkqTcmUC0CD9DhD5d/qeZlZkfRBn6GnHniZXLUo5+9xw8Iv76YE6LQFN9YNBlKREcCG76w==",
- "dev": true,
"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
"optional": true,
"dependencies": {
@@ -1804,7 +1782,6 @@
"cpu": [
"wasm32"
],
- "dev": true,
"license": "Apache-2.0",
"optional": true,
"dependencies": {
@@ -1824,7 +1801,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "Apache-2.0 AND LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1844,7 +1820,6 @@
"cpu": [
"ia32"
],
- "dev": true,
"license": "Apache-2.0 AND LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -1864,7 +1839,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "Apache-2.0 AND LGPL-3.0-or-later",
"optional": true,
"os": [
@@ -4675,7 +4649,6 @@
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
- "dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=8"
@@ -5531,6 +5504,21 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/emoji-picker-react": {
+ "version": "4.19.1",
+ "resolved": "https://registry.npmjs.org/emoji-picker-react/-/emoji-picker-react-4.19.1.tgz",
+ "integrity": "sha512-BmDdqInKFVYJpv7qS9WI6L9656cDAC+FkDvUjJds56nKHbaVTBNeDmLwKBytRnzu37zWHs9Isg7gt5PT43y6xA==",
+ "license": "MIT",
+ "dependencies": {
+ "flairup": "1.0.0"
+ },
+ "engines": {
+ "node": ">=10"
+ },
+ "peerDependencies": {
+ "react": ">=16"
+ }
+ },
"node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
@@ -5846,6 +5834,12 @@
"node": ">=8"
}
},
+ "node_modules/flairup": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/flairup/-/flairup-1.0.0.tgz",
+ "integrity": "sha512-IKlE+pNvL2R+kVL1kEhUYqRxVqeFnjiIvHWDMLFXNaqyUdFXQM2wte44EfMYJNHkW16X991t2Zg8apKkhv7OBA==",
+ "license": "MIT"
+ },
"node_modules/form-data": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz",
@@ -6859,6 +6853,15 @@
"yallist": "^3.0.2"
}
},
+ "node_modules/lucide-react": {
+ "version": "0.545.0",
+ "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.545.0.tgz",
+ "integrity": "sha512-7r1/yUuflQDSt4f1bpn5ZAocyIxcTyVyBBChSVtBKn5M+392cPmI5YJMWOJKk/HUWGm5wg83chlAZtCcGbEZtw==",
+ "license": "ISC",
+ "peerDependencies": {
+ "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
+ }
+ },
"node_modules/magic-string": {
"version": "0.30.21",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
@@ -7963,7 +7966,6 @@
"version": "7.8.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
"integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
- "dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@@ -8007,7 +8009,6 @@
"version": "0.35.3",
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.3.tgz",
"integrity": "sha512-ej0zVHuZGHCiABXcNxeYhpRnPNPAcvbG8RMdBAhDAxLKkCRVSpK3Iyu7qbqw3JMzoj0REeM6f3tJLtVwl0023Q==",
- "dev": true,
"license": "Apache-2.0",
"dependencies": {
"@img/colour": "^1.1.0",
@@ -8469,7 +8470,7 @@
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
- "dev": true,
+ "devOptional": true,
"license": "0BSD"
},
"node_modules/tweetnacl": {
diff --git a/package.json b/package.json
index 1beefe9cb..d2504957b 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,9 @@
],
"asarUnpack": [
"**/node_modules/node-pty/**",
- "**/node_modules/smart-whisper/**"
+ "**/node_modules/smart-whisper/**",
+ "**/node_modules/sharp/**",
+ "**/node_modules/@img/**"
],
"extraResources": [
{
@@ -117,10 +119,13 @@
"@xterm/addon-web-links": "^0.11.0",
"dompurify": "^3.4.13",
"electron-updater": "^6.8.9",
+ "emoji-picker-react": "^4.19.1",
+ "lucide-react": "^0.545.0",
"marked": "^12.0.2",
"monaco-editor": "^0.52.2",
"node-pty": "^1.0.0",
"qrcode": "^1.5.4",
+ "sharp": "^0.35.3",
"smart-whisper": "^0.8.1",
"tweetnacl": "^1.0.3",
"ws": "^8.21.0",
@@ -147,7 +152,6 @@
"jsdom": "^30.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "sharp": "^0.35.3",
"tailwindcss": "^4.3.1",
"typescript": "^7.0.2",
"vite": "^7.3.6",
diff --git a/src/main/index.ts b/src/main/index.ts
index 6cfa7a060..083645d27 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -14,6 +14,7 @@ import { IPC } from '../shared/ipc'
const logBuffer = new LogBuffer()
installLogSink(logBuffer)
import { writeFilesToClipboard } from './clipboard-files'
+import { pickProjectIcon } from './project-icon-upload'
import { allowGuestNavigation } from './webview-nav'
import { BrowserControlLedger } from './browser-control-ledger'
import { BrowserLeaseManager, BrowserSession } from './browser-lease'
@@ -1461,6 +1462,12 @@ app.whenReady().then(async () => {
if (isSafeExternalUrl(url)) void shell.openExternal(url)
})
+ // Project-icon upload: open a file dialog and re-encode the pick to a bounded PNG data URL, main
+ // side (never trust a user file straight onto Project.icon — see project-icon-upload.ts).
+ ipcMain.handle(IPC.shellPickProjectIcon, (e) =>
+ pickProjectIcon(BrowserWindow.fromWebContents(e.sender))
+ )
+
// The Explorer/Editor fs surface: ONE registrar (core/fs-handlers.ts) shared by this shell and
// the Server Edition, over the same pure core/fs-ops — so local, browser and peer filesystem
// behaviour cannot drift. Registered on the platform, so a remote tab's Explorer/editor works.
diff --git a/src/main/project-icon-upload.test.ts b/src/main/project-icon-upload.test.ts
new file mode 100644
index 000000000..b84f1074e
--- /dev/null
+++ b/src/main/project-icon-upload.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, it } from 'vitest'
+import sharp from 'sharp'
+import { PROJECT_ICON_MAX_BYTES } from '@shared/project-icon'
+import { encodeProjectIconImage } from './project-icon-upload'
+
+/** A solid-colour PNG of the given size — a stand-in for a user-chosen file. */
+async function png(width: number, height: number): Promise<Buffer> {
+ return sharp({
+ create: { width, height, channels: 3, background: { r: 200, g: 40, b: 90 } }
+ })
+ .png()
+ .toBuffer()
+}
+
+describe('encodeProjectIconImage (sharp-bound)', () => {
+ it('re-encodes a real image to a PNG data URL', async () => {
+ const out = await encodeProjectIconImage(await png(300, 200))
+ expect('dataUrl' in out).toBe(true)
+ if (!('dataUrl' in out)) return
+ expect(out.dataUrl.startsWith('data:image/png;base64,')).toBe(true)
+ })
+
+ it('bounds the longest edge to 128px, preserving aspect ratio', async () => {
+ const out = await encodeProjectIconImage(await png(512, 256))
+ if (!('dataUrl' in out)) throw new Error('expected a dataUrl')
+ const base64 = out.dataUrl.slice(out.dataUrl.indexOf(',') + 1)
+ const meta = await sharp(Buffer.from(base64, 'base64')).metadata()
+ expect(meta.width).toBe(128)
+ expect(meta.height).toBe(64)
+ })
+
+ it('does not enlarge a source already under the bound', async () => {
+ const out = await encodeProjectIconImage(await png(40, 40))
+ if (!('dataUrl' in out)) throw new Error('expected a dataUrl')
+ const base64 = out.dataUrl.slice(out.dataUrl.indexOf(',') + 1)
+ const meta = await sharp(Buffer.from(base64, 'base64')).metadata()
+ expect(meta.width).toBe(40)
+ expect(meta.height).toBe(40)
+ })
+
+ it('rejects with an error when the encoded image exceeds the byte cap', async () => {
+ // A 128px PNG is always well under 256 KB in practice, so force the cap tiny to exercise the
+ // guard: the SAME arithmetic (dataUrlByteLength) that sanitizeProjectIcon re-checks on load.
+ const out = await encodeProjectIconImage(await png(128, 128), 100)
+ expect('error' in out).toBe(true)
+ if ('error' in out) expect(out.error).toMatch(/too large/i)
+ })
+
+ it('surfaces an error (never throws) for a buffer that is not an image', async () => {
+ const out = await encodeProjectIconImage(Buffer.from('not an image at all'))
+ expect('error' in out).toBe(true)
+ })
+
+ it('a normally-encoded icon is within the real cap', async () => {
+ const out = await encodeProjectIconImage(await png(128, 128), PROJECT_ICON_MAX_BYTES)
+ expect('dataUrl' in out).toBe(true)
+ })
+})
diff --git a/src/main/project-icon-upload.ts b/src/main/project-icon-upload.ts
new file mode 100644
index 000000000..d5dd5030a
--- /dev/null
+++ b/src/main/project-icon-upload.ts
@@ -0,0 +1,79 @@
+import { promises as fsp } from 'node:fs'
+import sharp from 'sharp'
+import {
+ dataUrlByteLength,
+ PROJECT_ICON_MAX_BYTES,
+ type ProjectIconPickResult
+} from '@shared/project-icon'
+
+/**
+ * Project-icon upload, main side. The renderer must never trust a user-chosen file straight onto
+ * `Project.icon` (it ships to every clone and re-renders on every load), so main is the boundary
+ * that RE-ENCODES it: whatever the user picked — a 12MP photo, an animated GIF, an SVG — is decoded
+ * by sharp and re-emitted as a small, square-bounded PNG. That normalises the format (no SVG script
+ * surface, one MIME), caps the pixel size, and — with the byte-cap below — the file size, exactly
+ * the guarantees `sanitizeProjectIcon` re-checks when the value is later read back from project.json.
+ *
+ * `sharp` is a native module: it is a runtime `dependencies` entry (electron.vite externalises deps,
+ * so main `require`s it from node_modules) and is listed in electron-builder `asarUnpack`, so its
+ * platform binary sits unpacked beside the app. Both are required for this to work in a packaged
+ * build — without them the require would fail and the upload would be dead.
+ */
+
+/** The longest edge (px) a re-encoded icon is bounded to. Square box, `fit: 'inside'` preserves
+ * aspect ratio, and no enlargement so a tiny source is never blown up. */
+const ICON_MAX_DIMENSION = 128
+
+/**
+ * Decode `input` as an image and re-encode it to a bounded PNG `data:` URL. Never throws: an
+ * un-decodable buffer, or one that is still over `maxBytes` after re-encoding, comes back as an
+ * `{ error }` the caller can surface. `maxBytes` is injectable purely so the cap path is testable
+ * (a 128px PNG is in practice always well under 256 KB).
+ */
+export async function encodeProjectIconImage(
+ input: Buffer,
+ maxBytes: number = PROJECT_ICON_MAX_BYTES
+): Promise<{ dataUrl: string } | { error: string }> {
+ let png: Buffer
+ try {
+ png = await sharp(input)
+ .resize(ICON_MAX_DIMENSION, ICON_MAX_DIMENSION, { fit: 'inside', withoutEnlargement: true })
+ .png()
+ .toBuffer()
+ } catch {
+ return { error: 'That file could not be read as an image.' }
+ }
+ const dataUrl = `data:image/png;base64,${png.toString('base64')}`
+ if (dataUrlByteLength(dataUrl) > maxBytes) {
+ return { error: 'That image is too large even after resizing. Try a smaller one.' }
+ }
+ return { dataUrl }
+}
+
+/**
+ * Open a file dialog for an image, then re-encode the chosen file via `encodeProjectIconImage`.
+ * Returns `null` when the user cancels. Electron is required lazily so this module can be unit-
+ * tested (against real sharp) without an Electron runtime.
+ */
+export async function pickProjectIcon(parentWindow?: unknown): Promise<ProjectIconPickResult> {
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const { dialog, BrowserWindow } = require('electron') as typeof import('electron')
+ const win =
+ parentWindow instanceof BrowserWindow && !parentWindow.isDestroyed() ? parentWindow : null
+ const opts: Electron.OpenDialogOptions = {
+ title: 'Choose a project icon',
+ properties: ['openFile'],
+ filters: [{ name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp'] }]
+ }
+ const result = win
+ ? await dialog.showOpenDialog(win, opts)
+ : await dialog.showOpenDialog(opts)
+ if (result.canceled || result.filePaths.length === 0) return null
+ let buf: Buffer
+ try {
+ buf = await fsp.readFile(result.filePaths[0])
+ } catch {
+ return { error: 'That file could not be opened.' }
+ }
+ return encodeProjectIconImage(buf)
+}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 60e96d4c9..237c9890c 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -354,7 +354,8 @@ const api: NodeTerminalApi = {
shell: {
reveal: (path: string) => ipcRenderer.send(IPC.shellReveal, path),
openPath: (path: string) => ipcRenderer.send(IPC.shellOpenPath, path),
- openExternal: (url: string) => ipcRenderer.send(IPC.shellOpenExternal, url)
+ openExternal: (url: string) => ipcRenderer.send(IPC.shellOpenExternal, url),
+ pickProjectIcon: () => ipcRenderer.invoke(IPC.shellPickProjectIcon)
},
fs: {
list: (dirPath: string) => ipcRenderer.invoke(IPC.fsList, dirPath),
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index a52d6e89e..02c16bc6d 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -180,7 +180,10 @@ export function buildStubApi(): Omit<
// The one browser-native member: open the URL in a new tab.
openExternal: (url: string): void => {
window.open(url, '_blank', 'noopener')
- }
+ },
+ // Picking + re-encoding an icon needs the main process (native dialog + sharp); a browser
+ // client has neither, so this degrades to "cancelled" rather than opening anything.
+ pickProjectIcon: async () => null
},
media: {
allow: U('media.allow'),
diff --git a/src/renderer/components/ProjectGlyph.test.tsx b/src/renderer/components/ProjectGlyph.test.tsx
index 0a7cec9b8..0db356b4e 100644
--- a/src/renderer/components/ProjectGlyph.test.tsx
+++ b/src/renderer/components/ProjectGlyph.test.tsx
@@ -32,20 +32,23 @@ describe('ProjectGlyph', () => {
expect(host.textContent).toBe('🚀')
})
- it('renders a lucide icon as the Task-4 placeholder, tinted with color', async () => {
+ // Task 4 swapped the placeholder for the real curated lucide-react map. lucide renders an <svg>
+ // whose `stroke` is the `color` prop, so these two pin the same thing 1:1 (tinted / currentColor)
+ // against the real glyph instead of the former placeholder rect.
+ it('renders a lucide icon as a tinted lucide <svg>', async () => {
await render(
<ProjectGlyph icon={{ type: 'lucide', name: 'folder' }} color="#3355ff" name="Folder Project" />
)
- const svg = host.querySelector('[data-testid="lucide-placeholder"]')
+ const svg = host.querySelector('svg')
expect(svg).not.toBeNull()
- const rect = svg!.querySelector('rect')
- expect(rect?.getAttribute('stroke')).toBe('#3355ff')
+ expect(svg?.getAttribute('stroke')).toBe('#3355ff')
+ expect(svg?.classList.contains('lucide-folder')).toBe(true)
})
- it('falls back to currentColor for the lucide placeholder when no color is given', async () => {
+ it('falls back to currentColor for the lucide glyph when no color is given', async () => {
await render(<ProjectGlyph icon={{ type: 'lucide', name: 'folder' }} name="No Color" />)
- const rect = host.querySelector('[data-testid="lucide-placeholder"] rect')
- expect(rect?.getAttribute('stroke')).toBe('currentColor')
+ const svg = host.querySelector('svg')
+ expect(svg?.getAttribute('stroke')).toBe('currentColor')
})
it('renders an image icon as an <img> with the given src', async () => {
diff --git a/src/renderer/components/ProjectGlyph.tsx b/src/renderer/components/ProjectGlyph.tsx
index 8dc63c174..949caad9d 100644
--- a/src/renderer/components/ProjectGlyph.tsx
+++ b/src/renderer/components/ProjectGlyph.tsx
@@ -1,4 +1,97 @@
import type { ProjectIcon } from '@shared/project-icon'
+import {
+ Folder,
+ FolderGit,
+ Code,
+ Terminal,
+ Rocket,
+ Box,
+ Package,
+ Database,
+ Server,
+ Cloud,
+ Globe,
+ Star,
+ Heart,
+ Flag,
+ Bookmark,
+ Zap,
+ Flame,
+ Cpu,
+ Layers,
+ LayoutGrid,
+ Hash,
+ Braces,
+ Bug,
+ Wrench,
+ Hammer,
+ Beaker,
+ Palette,
+ Paintbrush,
+ Camera,
+ Image as ImageIcon,
+ Music,
+ Video,
+ Book,
+ FileText,
+ Shield,
+ Key,
+ Lock,
+ Users,
+ Bot,
+ Sparkles,
+ type LucideIcon
+} from 'lucide-react'
+
+/**
+ * The curated lucide map (Task 4's swap-in for the former placeholder). One named import per icon
+ * so the bundler tree-shakes the rest of lucide's ~1k glyphs out; keyed by the same kebab ids as
+ * `LUCIDE_ICON_IDS` (@shared/project-icon), which is the closed allowlist `sanitizeProjectIcon`
+ * enforces AND the picker grid. An `icon.name` that isn't a key here degrades to the fallback
+ * (belt-and-braces — a sanitized icon's name is always a key).
+ */
+const LUCIDE_ICONS: Record<string, LucideIcon> = {
+ folder: Folder,
+ 'folder-git': FolderGit,
+ code: Code,
+ terminal: Terminal,
+ rocket: Rocket,
+ box: Box,
+ package: Package,
+ database: Database,
+ server: Server,
+ cloud: Cloud,
+ globe: Globe,
+ star: Star,
+ heart: Heart,
+ flag: Flag,
+ bookmark: Bookmark,
+ zap: Zap,
+ flame: Flame,
+ cpu: Cpu,
+ layers: Layers,
+ 'layout-grid': LayoutGrid,
+ hash: Hash,
+ braces: Braces,
+ bug: Bug,
+ wrench: Wrench,
+ hammer: Hammer,
+ beaker: Beaker,
+ palette: Palette,
+ paintbrush: Paintbrush,
+ camera: Camera,
+ image: ImageIcon,
+ music: Music,
+ video: Video,
+ book: Book,
+ 'file-text': FileText,
+ shield: Shield,
+ key: Key,
+ lock: Lock,
+ users: Users,
+ bot: Bot,
+ sparkles: Sparkles
+}
export interface ProjectGlyphProps {
/** The project's icon, when it has one. Absent → render the site's pre-icon fallback. */
@@ -24,32 +117,6 @@ export interface ProjectGlyphProps {
const DEFAULT_SIZE = 16
-/**
- * TODO(Task 4): lucide-react is not yet a dependency of this package — Task 4 adds it, plus the
- * real curated map (`Record<string, LucideIcon>` built from `LUCIDE_ICON_IDS`, one import per
- * icon so unused ones tree-shake out). Until then a lucide icon renders as this tinted, bordered
- * placeholder so the branch is exercised (by tests and by real data) without blocking Task 2 on
- * the new dependency. Task 4's swap-in point is exactly here: replace `LucidePlaceholder`'s body
- * (or the call site below) with `const Icon = LUCIDE_ICONS[icon.name]; <Icon color={color} .../>`
- * and delete this function — no other call site in this file needs to change.
- */
-function LucidePlaceholder({ color }: { color?: string }): JSX.Element {
- return (
- <svg viewBox="0 0 16 16" width="100%" height="100%" aria-hidden="true" data-testid="lucide-placeholder">
- <rect
- x="2.5"
- y="2.5"
- width="11"
- height="11"
- rx="3"
- fill="none"
- stroke={color || 'currentColor'}
- strokeWidth="1.5"
- />
- </svg>
- )
-}
-
/**
* A project's small badge, used wherever the UI shows one beside a project's name: its custom
* icon when it has one (emoji, a curated lucide glyph, or an image — GitHub avatar/upload/
@@ -86,15 +153,19 @@ export function ProjectGlyph({
}
if (icon?.type === 'lucide') {
- return (
- <span
- className={className}
- title={title}
- style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
- >
- <LucidePlaceholder color={color} />
- </span>
- )
+ const Icon = LUCIDE_ICONS[icon.name]
+ if (Icon) {
+ return (
+ <span
+ className={className}
+ title={title}
+ style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}
+ >
+ <Icon color={color || 'currentColor'} width="100%" height="100%" aria-hidden="true" />
+ </span>
+ )
+ }
+ // Unknown name (never happens for a sanitized icon) → fall through to the fallback below.
}
if (icon?.type === 'image') {
diff --git a/src/renderer/components/settings/EmojiPickerLazy.tsx b/src/renderer/components/settings/EmojiPickerLazy.tsx
new file mode 100644
index 000000000..e235b62d5
--- /dev/null
+++ b/src/renderer/components/settings/EmojiPickerLazy.tsx
@@ -0,0 +1,44 @@
+import { lazy, Suspense } from 'react'
+
+/**
+ * The emoji tab's picker, isolated behind `React.lazy` so `emoji-picker-react` (~500 KB) is a
+ * dynamic chunk that loads ONLY when this component first renders — i.e. only when the user opens
+ * the Emoji tab. ProjectIconPicker statically imports THIS wrapper (cheap), never the library, so
+ * the heavy module stays out of the settings bundle until it is asked for. A test pins that: the
+ * module's mock factory does not run until the Emoji tab is active.
+ *
+ * The library's props are typed loosely here on purpose — casting the lazy component avoids
+ * importing anything from `emoji-picker-react` at module scope (even a type import can tempt a
+ * bundler), and its `theme` accepts the plain strings its `Theme` enum resolves to at runtime.
+ */
+const EmojiPicker = lazy(() => import('emoji-picker-react')) as React.LazyExoticComponent<
+ React.ComponentType<{
+ autoFocusSearch?: boolean
+ theme?: 'dark' | 'light' | 'auto'
+ lazyLoadEmojis?: boolean
+ onEmojiClick?: (data: { emoji: string }) => void
+ width?: string | number
+ height?: string | number
+ }>
+>
+
+export interface EmojiPickerLazyProps {
+ /** Force the picker's palette to the app's resolved appearance rather than its own auto. */
+ dark: boolean
+ onEmoji: (emoji: string) => void
+}
+
+export default function EmojiPickerLazy({ dark, onEmoji }: EmojiPickerLazyProps): React.JSX.Element {
+ return (
+ <Suspense fallback={<div className="px-2 py-4 text-[13px] text-muted">Loading emoji…</div>}>
+ <EmojiPicker
+ autoFocusSearch={false}
+ theme={dark ? 'dark' : 'light'}
+ lazyLoadEmojis
+ width="100%"
+ height={340}
+ onEmojiClick={(data) => onEmoji(data.emoji)}
+ />
+ </Suspense>
+ )
+}
diff --git a/src/renderer/components/settings/ProjectIconPicker.test.tsx b/src/renderer/components/settings/ProjectIconPicker.test.tsx
new file mode 100644
index 000000000..180090439
--- /dev/null
+++ b/src/renderer/components/settings/ProjectIconPicker.test.tsx
@@ -0,0 +1,163 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ProjectIcon } from '@shared/project-icon'
+import { ProjectIconPicker } from './ProjectIconPicker'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+// The heavy library is mocked with a factory that counts how many times it is EVALUATED. Because
+// EmojiPickerLazy imports it dynamically (React.lazy), the factory does not run until the Emoji tab
+// is actually rendered — which is exactly the laziness this pins.
+const H = vi.hoisted(() => ({ emojiLoads: 0 }))
+vi.mock('emoji-picker-react', () => {
+ H.emojiLoads++
+ return {
+ default: ({ onEmojiClick }: { onEmojiClick?: (d: { emoji: string }) => void }) => (
+ <button data-testid="fake-emoji" onClick={() => onEmojiClick?.({ emoji: '🚀' })}>
+ pick
+ </button>
+ )
+ }
+})
+
+const COLORS = ['#0a84ff', '#32d74b', '#ff375f'] as const
+
+describe('ProjectIconPicker', () => {
+ let root: Root
+ let host: HTMLElement
+ let onIcon: ReturnType<typeof vi.fn<(i: ProjectIcon | undefined) => void>>
+ let onColor: ReturnType<typeof vi.fn<(c: string) => void>>
+ let pickProjectIcon: ReturnType<typeof vi.fn>
+
+ const mount = async (icon?: ProjectIcon): Promise<void> => {
+ root = createRoot(host)
+ await act(async () => {
+ root.render(
+ <ProjectIconPicker
+ projectId="p1"
+ name="Alpha"
+ icon={icon}
+ color="#0a84ff"
+ colors={COLORS}
+ dark
+ onIcon={onIcon}
+ onColor={onColor}
+ />
+ )
+ })
+ }
+
+ const click = async (el: Element | null): Promise<void> => {
+ await act(async () => {
+ el!.dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ })
+ }
+
+ /** Flush the lazy dynamic import + Suspense re-render. */
+ const flush = async (): Promise<void> => {
+ for (let i = 0; i < 3; i++) await act(async () => await Promise.resolve())
+ }
+
+ const tab = (label: string): HTMLButtonElement =>
+ [...host.querySelectorAll<HTMLButtonElement>('[role="tab"]')].find(
+ (b) => b.textContent === label
+ )!
+
+ beforeEach(() => {
+ H.emojiLoads = 0
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ onIcon = vi.fn()
+ onColor = vi.fn()
+ pickProjectIcon = vi.fn(async () => ({ dataUrl: 'data:image/png;base64,AA==' }))
+ ;(window as unknown as { nodeTerminal: any }).nodeTerminal = {
+ shell: { pickProjectIcon }
+ }
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+ })
+
+ it('defaults to the Lucide tab and does NOT load the emoji module', async () => {
+ await mount()
+ expect(tab('Lucide').getAttribute('aria-selected')).toBe('true')
+ expect(H.emojiLoads).toBe(0)
+ })
+
+ it('picks a lucide glyph, sanitized, via its grid button', async () => {
+ await mount()
+ await click(host.querySelector('[data-lucide-id="rocket"]'))
+ expect(onIcon).toHaveBeenCalledWith({ type: 'lucide', name: 'rocket' })
+ })
+
+ it('loads the emoji module only when the Emoji tab is opened, then emits the picked emoji', async () => {
+ await mount()
+ expect(H.emojiLoads).toBe(0)
+ await click(tab('Emoji'))
+ await flush()
+ expect(H.emojiLoads).toBe(1)
+ await click(host.querySelector('[data-testid="fake-emoji"]'))
+ expect(onIcon).toHaveBeenCalledWith({ type: 'emoji', emoji: '🚀' })
+ })
+
+ it('re-encodes an uploaded image into an image icon via the main IPC', async () => {
+ await mount()
+ await click(tab('Upload'))
+ await click([...host.querySelectorAll('button')].find((b) => b.textContent === 'Choose image…')!)
+ await flush()
+ expect(pickProjectIcon).toHaveBeenCalledTimes(1)
+ expect(onIcon).toHaveBeenCalledWith({
+ type: 'image',
+ src: 'data:image/png;base64,AA==',
+ source: 'upload'
+ })
+ })
+
+ it('surfaces an upload error and commits nothing', async () => {
+ pickProjectIcon.mockResolvedValue({ error: 'That image is too large even after resizing.' })
+ await mount()
+ await click(tab('Upload'))
+ await click([...host.querySelectorAll('button')].find((b) => b.textContent === 'Choose image…')!)
+ await flush()
+ expect(host.querySelector('[role="alert"]')?.textContent).toContain('too large')
+ expect(onIcon).not.toHaveBeenCalled()
+ })
+
+ it('does nothing when the upload dialog is cancelled (null)', async () => {
+ pickProjectIcon.mockResolvedValue(null)
+ await mount()
+ await click(tab('Upload'))
+ await click([...host.querySelectorAll('button')].find((b) => b.textContent === 'Choose image…')!)
+ await flush()
+ expect(onIcon).not.toHaveBeenCalled()
+ expect(host.querySelector('[role="alert"]')).toBeNull()
+ })
+
+ it('Reset clears the icon back to undefined (the colour monogram)', async () => {
+ await mount({ type: 'emoji', emoji: '🚀' })
+ const reset = host.querySelector<HTMLButtonElement>('[aria-label="Remove icon"]')!
+ expect(reset.disabled).toBe(false)
+ await click(reset)
+ expect(onIcon).toHaveBeenCalledWith(undefined)
+ })
+
+ it('disables Reset when there is no icon to clear', async () => {
+ await mount()
+ expect(host.querySelector<HTMLButtonElement>('[aria-label="Remove icon"]')!.disabled).toBe(true)
+ })
+
+ it('offers Avatar as a disabled stub (Task 5)', async () => {
+ await mount()
+ expect(tab('Avatar').disabled).toBe(true)
+ })
+
+ it('picks a colour through the swatches', async () => {
+ await mount()
+ await click(host.querySelector('button[data-project-color="#32d74b"]'))
+ expect(onColor).toHaveBeenCalledWith('#32d74b')
+ })
+})
diff --git a/src/renderer/components/settings/ProjectIconPicker.tsx b/src/renderer/components/settings/ProjectIconPicker.tsx
new file mode 100644
index 000000000..a7d526325
--- /dev/null
+++ b/src/renderer/components/settings/ProjectIconPicker.tsx
@@ -0,0 +1,199 @@
+import { useState } from 'react'
+import {
+ LUCIDE_ICON_IDS,
+ sanitizeProjectIcon,
+ type ProjectIcon
+} from '@shared/project-icon'
+import { cn } from '@renderer/ui/cn'
+import { ProjectGlyph } from '../ProjectGlyph'
+import EmojiPickerLazy from './EmojiPickerLazy'
+
+/**
+ * The project-icon picker: a live preview + Reset over four tabs (Avatar — a disabled stub Task 5
+ * fills in — / Emoji / Lucide / Upload) plus the project's colour swatches. Every choice is run
+ * through `sanitizeProjectIcon` before it leaves — the same boundary the stored value crosses on
+ * load — so the picker can only ever emit a value the rest of the app will accept, and Reset emits
+ * `undefined` (back to the colour monogram).
+ *
+ * The component is presentational: it owns only which tab is open and the upload error. Persistence
+ * (setProjectIcon / setProjectColor + the workspace-dirty commit) lives in the caller via `onIcon`
+ * / `onColor`, exactly like the identity rows around it.
+ */
+export interface ProjectIconPickerProps {
+ projectId: string
+ name: string
+ icon?: ProjectIcon
+ color?: string
+ colors: readonly string[]
+ /** App's resolved appearance — forced onto the emoji picker rather than its own auto. */
+ dark: boolean
+ onIcon: (icon: ProjectIcon | undefined) => void
+ onColor: (color: string) => void
+}
+
+type Tab = 'avatar' | 'emoji' | 'lucide' | 'upload'
+
+const TABS: { id: Tab; label: string; disabled?: boolean }[] = [
+ { id: 'avatar', label: 'Avatar', disabled: true },
+ { id: 'emoji', label: 'Emoji' },
+ { id: 'lucide', label: 'Lucide' },
+ { id: 'upload', label: 'Upload' }
+]
+
+export function ProjectIconPicker({
+ projectId,
+ name,
+ icon,
+ color,
+ colors,
+ dark,
+ onIcon,
+ onColor
+}: ProjectIconPickerProps): React.JSX.Element {
+ // Default to a functional, non-lazy tab: never Emoji (that would pull the ~500 KB chunk the
+ // moment the picker mounts, defeating the whole lazy split).
+ const [tab, setTab] = useState<Tab>('lucide')
+ const [uploadError, setUploadError] = useState<string | undefined>(undefined)
+
+ const commit = (raw: ProjectIcon): void => onIcon(sanitizeProjectIcon(raw))
+
+ const onUpload = async (): Promise<void> => {
+ setUploadError(undefined)
+ const res = await window.nodeTerminal.shell.pickProjectIcon()
+ if (!res) return // cancelled
+ if ('error' in res) {
+ setUploadError(res.error)
+ return
+ }
+ commit({ type: 'image', src: res.dataUrl, source: 'upload' })
+ }
+
+ return (
+ <div className="flex flex-col gap-3" data-project-icon-picker={projectId}>
+ {/* Preview + Reset */}
+ <div className="flex items-center gap-3">
+ <span
+ className="flex size-11 items-center justify-center overflow-hidden rounded-xl bg-black/10 text-[18px] font-semibold text-white"
+ aria-label="Current icon"
+ >
+ <ProjectGlyph icon={icon} color={color} name={name} size={28} />
+ </span>
+ <button
+ type="button"
+ className="rounded-lg border border-white/15 px-2.5 py-1 text-[13px] text-muted transition-colors hover:text-text disabled:opacity-40"
+ onClick={() => {
+ setUploadError(undefined)
+ onIcon(undefined)
+ }}
+ disabled={!icon}
+ aria-label="Remove icon"
+ >
+ Reset
+ </button>
+ </div>
+
+ {/* Colour swatches — the accent for this project's tab and monogram. */}
+ <div className="flex items-center gap-1.5" role="group" aria-label="Color">
+ {colors.map((c) => (
+ <button
+ key={c}
+ type="button"
+ data-project-color={c}
+ aria-label={`Color ${c}`}
+ aria-pressed={color === c}
+ style={{ background: c }}
+ className={cn(
+ 'size-5 rounded-full border-0 outline-none transition-transform hover:scale-110',
+ color === c && 'ring-2 ring-white/80 ring-offset-2 ring-offset-transparent'
+ )}
+ onClick={() => onColor(c)}
+ />
+ ))}
+ </div>
+
+ {/* Tabs */}
+ <div className="flex items-center gap-1" role="tablist" aria-label="Icon source">
+ {TABS.map((t) => (
+ <button
+ key={t.id}
+ type="button"
+ role="tab"
+ aria-selected={tab === t.id}
+ disabled={t.disabled}
+ className={cn(
+ 'rounded-lg px-2.5 py-1 text-[13px] transition-colors disabled:opacity-40',
+ tab === t.id ? 'bg-white/15 text-text' : 'text-muted hover:text-text'
+ )}
+ onClick={() => t.disabled || setTab(t.id)}
+ >
+ {t.label}
+ </button>
+ ))}
+ </div>
+
+ {/* Panel */}
+ <div className="rounded-xl border border-white/10 p-2" role="tabpanel">
+ {tab === 'avatar' ? (
+ <p className="px-1 py-3 text-[13px] text-muted">
+ Avatars are coming soon — pick an emoji, a glyph, or upload an image for now.
+ </p>
+ ) : null}
+
+ {tab === 'emoji' ? (
+ <EmojiPickerLazy dark={dark} onEmoji={(emoji) => commit({ type: 'emoji', emoji })} />
+ ) : null}
+
+ {tab === 'lucide' ? (
+ <div
+ className="grid gap-1"
+ style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(2.25rem, 1fr))' }}
+ >
+ {LUCIDE_ICON_IDS.map((n) => {
+ const selected = icon?.type === 'lucide' && icon.name === n
+ return (
+ <button
+ key={n}
+ type="button"
+ data-lucide-id={n}
+ aria-label={n}
+ aria-pressed={selected}
+ title={n}
+ className={cn(
+ 'flex size-9 items-center justify-center rounded-lg text-muted transition-colors hover:bg-white/10 hover:text-text',
+ selected && 'bg-white/15 text-text'
+ )}
+ onClick={() => commit({ type: 'lucide', name: n })}
+ >
+ <span className="flex size-5 items-center justify-center">
+ <ProjectGlyph icon={{ type: 'lucide', name: n }} color={color} name={name} size={20} />
+ </span>
+ </button>
+ )
+ })}
+ </div>
+ ) : null}
+
+ {tab === 'upload' ? (
+ <div className="flex flex-col gap-2 px-1 py-2">
+ <button
+ type="button"
+ className="w-fit rounded-lg border border-white/15 px-3 py-1.5 text-[13px] text-text transition-colors hover:bg-white/10"
+ onClick={() => void onUpload()}
+ >
+ Choose image…
+ </button>
+ <p className="text-[12px] leading-relaxed text-muted">
+ The image is resized and re-encoded as a small PNG, then shared with the repo like the
+ name and colour.
+ </p>
+ {uploadError ? (
+ <p role="alert" className="text-[12px] text-[color:var(--warn)]">
+ {uploadError}
+ </p>
+ ) : null}
+ </div>
+ ) : null}
+ </div>
+ </div>
+ )
+}
diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx
index 919249c68..193e57fd1 100644
--- a/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx
+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.test.tsx
@@ -138,6 +138,27 @@ describe('ProjectSettingsSection', () => {
expect(dirty).toHaveBeenCalledTimes(1)
})
+ it('picks a lucide icon and persists it (Task 4 icon picker)', async () => {
+ await mountSection()
+ const btn = host.querySelector<HTMLButtonElement>('[data-lucide-id="rocket"]')!
+ await act(async () => {
+ btn.dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ })
+ expect(useProjects.getState().getProject('p1')?.icon).toEqual({ type: 'lucide', name: 'rocket' })
+ expect(dirty).toHaveBeenCalledTimes(1)
+ })
+
+ it('resets a set icon back to undefined via the picker Reset', async () => {
+ await mountSection(project({ icon: { type: 'emoji', emoji: '🚀' } }))
+ const reset = host.querySelector<HTMLButtonElement>('[aria-label="Remove icon"]')!
+ expect(reset.disabled).toBe(false)
+ await act(async () => {
+ reset.dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ })
+ expect(useProjects.getState().getProject('p1')?.icon).toBeUndefined()
+ expect(dirty).toHaveBeenCalledTimes(1)
+ })
+
it('sets the default permission mode and clears it back to the global default', async () => {
await mountSection()
const select = host.querySelector<HTMLSelectElement>('#project-permission-mode-p1')!
diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
index 0df8e6980..9187515ae 100644
--- a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx
@@ -5,10 +5,11 @@ import {
PERMISSION_MODE_LABELS,
type AgentPermissionMode
} from '@shared/agents/config'
+import type { ProjectIcon } from '@shared/project-icon'
import { Input } from '@renderer/ui/Input'
import { Select } from '@renderer/ui/Select'
-import { cn } from '@renderer/ui/cn'
import { useProjects } from '../../../state/projects'
+import { useAppTheme } from '../../../state/useAppTheme'
import { useSettings } from '../../../state/settings'
import { useSystemAccount } from '../../../state/systemAccount'
import { markWorkspaceDirty } from '../../../state/workspaceDirty'
@@ -21,6 +22,7 @@ import {
import { FieldRow } from '../FieldRow'
import { FAMILY_SEARCH_ENTRIES, ProjectFamilyEditors } from '../ProjectSettingsFamilies'
import { SearchableRow } from '../SearchableRow'
+import { ProjectIconPicker } from '../ProjectIconPicker'
import { SettingsSection, sectionVisible } from '../SettingsSection'
import { useSettingsSearch } from '../context'
import { projectSectionId } from '../project-settings-targets'
@@ -49,7 +51,13 @@ function persistIdentityEdit(): void {
const ROWS = {
name: { title: 'Project name', keywords: ['rename', 'project', 'title'] },
folder: { title: 'Folder', keywords: ['cwd', 'path', 'directory', 'ssh', 'server'] },
- color: { title: 'Color', keywords: ['accent', 'swatch', 'tab', 'monogram'] },
+ color: {
+ title: 'Icon & color',
+ keywords: [
+ 'accent', 'swatch', 'tab', 'monogram', 'color',
+ 'icon', 'emoji', 'glyph', 'lucide', 'avatar', 'image', 'logo', 'upload'
+ ]
+ },
permission: {
title: 'Default permission mode',
keywords: ['claude', 'plan', 'accept edits', 'bypass', 'approval']
@@ -160,6 +168,7 @@ function EditableProjectSection({
forceVisible: boolean
}): React.JSX.Element {
const settings = useProjectSettings(project.id)
+ const appTheme = useAppTheme()
const claudeAccounts = useSettings((s) => s.settings.claudeAccounts)
const globalMode = useSettings((s) => s.settings.claudePermissionMode)
const systemLabelSetting = useSettings((s) => s.settings.systemAccountLabel)
@@ -243,29 +252,25 @@ function EditableProjectSection({
</SearchableRow>
<SearchableRow {...ROWS.color}>
<FieldRow
- label="Color"
- description="Accent for this project's tab and monogram."
+ label="Icon & color"
+ description="How this project shows on its tab and in the switcher: a custom icon (emoji, glyph, or image) plus an accent colour. Both live in the shared project file, so they travel to everyone who clones the repo."
control={
- <div className="flex items-center gap-1.5">
- {NODE_COLORS.map((c) => (
- <button
- key={c}
- type="button"
- data-project-color={c}
- aria-label={`Color ${c}`}
- aria-pressed={project.color === c}
- style={{ background: c }}
- className={cn(
- 'size-5 rounded-full border-0 outline-none transition-transform hover:scale-110',
- project.color === c && 'ring-2 ring-white/80 ring-offset-2 ring-offset-transparent'
- )}
- onClick={() => {
- useProjects.getState().setProjectColor(project.id, c)
- persistIdentityEdit()
- }}
- />
- ))}
- </div>
+ <ProjectIconPicker
+ projectId={project.id}
+ name={project.name}
+ icon={project.icon}
+ color={project.color}
+ colors={NODE_COLORS}
+ dark={appTheme === 'dark'}
+ onIcon={(icon: ProjectIcon | undefined) => {
+ useProjects.getState().setProjectIcon(project.id, icon)
+ persistIdentityEdit()
+ }}
+ onColor={(c: string) => {
+ useProjects.getState().setProjectColor(project.id, c)
+ persistIdentityEdit()
+ }}
+ />
}
/>
</SearchableRow>
diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.ts
index edcb95e0e..f12be87a6 100644
--- a/src/renderer/state/projects.ts
+++ b/src/renderer/state/projects.ts
@@ -11,6 +11,7 @@ import type {
} from '@shared/types'
import { collisionSeed, derivedProjectId } from '@shared/project-id'
import type { ProjectCapability } from '@shared/project-capabilities'
+import type { ProjectIcon } from '@shared/project-icon'
import { recordCapabilityAck, type CapabilityAnswer } from '@shared/project-capability-consent'
import { applyCanvasMutation, createProject, reorderGroupWithinParent } from './workspace'
@@ -58,6 +59,9 @@ interface ProjectsState {
renameProject(id: string, name: string): void
/** Sets a project's sidebar/monogram accent color. No-op for an unknown id. */
setProjectColor(id: string, color: string): void
+ /** Sets (or clears, with undefined = fall back to the color monogram) the project's icon. Stored
+ * on `Project.icon` and git-shared via project.json like name/color. No-op for an unknown id. */
+ setProjectIcon(id: string, icon: ProjectIcon | undefined): void
setProjectCwd(id: string, cwd: string): void
/** Grey (or un-grey) a project tab as "unavailable" WITHOUT dropping it — runtime-only, never
* persisted (see the toWorkspace tripwire). Set true when a relay tab's socket drops (Stage 4
@@ -325,6 +329,12 @@ export const useProjects = create<ProjectsState>((set, get) => ({
}))
},
+ setProjectIcon(id, icon) {
+ set((s) => ({
+ projects: s.projects.map((p) => (p.id === id ? { ...p, icon } : p))
+ }))
+ },
+
setProjectCwd(id, cwd) {
set((s) => ({
projects: s.projects.map((p) => (p.id === id ? { ...p, cwd } : p))
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index ac65f43be..7945632e3 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -336,6 +336,7 @@ export const IPC = {
dialogSelectFile: 'dialog:select-file',
shellReveal: 'shell:reveal',
shellOpenPath: 'shell:open-path',
+ shellPickProjectIcon: 'shell:pick-project-icon',
fsList: 'fs:list',
fsRead: 'fs:read',
fsReadBinary: 'fs:read-binary',
diff --git a/src/shared/project-icon.ts b/src/shared/project-icon.ts
index d2c22c1c2..a5c6d39a9 100644
--- a/src/shared/project-icon.ts
+++ b/src/shared/project-icon.ts
@@ -28,6 +28,13 @@ export const LUCIDE_ICON_IDS = [
'lock', 'users', 'bot', 'sparkles'
] as const
+/**
+ * Result of the main-process "pick a project icon image" flow (`shell.pickProjectIcon`): a re-
+ * encoded PNG `data:` URL on success, an `error` message to surface, or `null` when the user
+ * cancelled the file dialog. Shared so main, preload and the renderer agree on the shape.
+ */
+export type ProjectIconPickResult = { dataUrl: string } | { error: string } | null
+
/** MIME types an `image` icon's `data:` URL may declare. Closed set — no `image/svg+xml` (script
* execution risk on render), no video/other types. */
const IMAGE_ICON_MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'] as const
diff --git a/src/shared/types.ts b/src/shared/types.ts
index a2ee72c74..2a4a2636d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -12,7 +12,7 @@ import type { ClientId, DinoSnapshot, PeerDiff, PeerIdentity, PeerState } from '
import type { WhisperModelInfo } from './speech'
import type { ProjectKanbanGitHub } from './github-issues'
import type { CodexAccount } from './codex-account'
-import type { ProjectIcon } from './project-icon'
+import type { ProjectIcon, ProjectIconPickResult } from './project-icon'
import type {
ModelDiscoveryResult,
ModelGatewayCredentialStatus,
@@ -871,6 +871,9 @@ export interface ShellApi {
openPath(path: string): void
/** Open an http(s) URL in the OS default browser. */
openExternal(url: string): void
+ /** Open a file dialog for a project-icon image; main re-encodes the pick to a bounded PNG data
+ * URL (or an error), or returns null when cancelled. See `pickProjectIcon` (main). */
+ pickProjectIcon(): Promise<ProjectIconPickResult>
}
export interface DirEntry {