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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(projects): cap project names at 100 characters
Erik Zwep142d94180bba
diff --git a/src/core/canvas-control-core.ts b/src/core/canvas-control-core.tsindex 91e8494e1..b72bb6156 100644--- a/src/core/canvas-control-core.ts+++ b/src/core/canvas-control-core.ts@@ -595,6 +595,7 @@ import {SETTINGS_VERB_KEY_LIST,parseSettingsRequest} from '../shared/settings-verb'+import { PROJECT_NAME_MAX } from '../shared/project-name'import {githubReadArgsRefusal,GITHUB_READ_LIMIT_DEFAULT,@@ -927,7 +928,8 @@ export function buildCanvasControlInstructions(shimPath: string): string {...reportOutcomeDocLines(),'- `open-project --cwd </abs/path> [--name N] [--color C]` — register (or find) the project for a',' local directory; the reply carries `{ projectId, name, cwd, created }`. Idempotent: the same',- ' cwd always returns the same project, never a duplicate. Creating/adding asks the user to',+ ` cwd always returns the same project, never a duplicate. A \`--name\` over ${PROJECT_NAME_MAX} characters is`,+ ' cut to that length when the project is created. Creating/adding asks the user to',' confirm (your first open of an already-registered project asks once too) and may be denied —',' a denial is final, do not retry it. Local only (refused from an SSH project), and it never',' focuses the new project\'s tab. The returned id is what `--project` accepts.',@@ -1506,7 +1508,8 @@ ${reportOutcomeDocLines().join('\n')}local directory; the reply carries \`{ projectId, name, cwd, created }\`. Idempotent: the samecwd always returns the same project, never a duplicate — and \`--name\`/\`--color\` apply onlywhen the project is created (an existing project's name is never changed; the reply tells you- its real name). Creating/adding asks the user to confirm (your first open of an+ its real name). A \`--name\` over ${PROJECT_NAME_MAX} characters is cut to that length when the+ project is created. Creating/adding asks the user to confirm (your first open of analready-registered project asks once too) and may be denied — a denial is final, do not retryit. Local only (refused from an SSH project), and it never focuses the new project's tab: usethe returned id with \`--project\` to open sessions there.diff --git a/src/main/canvas-control-core.test.ts b/src/main/canvas-control-core.test.tsindex 0116f7743..d7a6ecb2a 100644--- a/src/main/canvas-control-core.test.ts+++ b/src/main/canvas-control-core.test.ts@@ -48,6 +48,7 @@ import {} from '../shared/settings-verb'import { CONTROL_REQUEST_TIMEOUT_MS, decideControlConfirm, isWaivableVerb } from '../shared/control-confirm'import { DEFAULT_SETTINGS } from '../shared/types'+import { PROJECT_NAME_MAX } from '../shared/project-name'import { serverSettingsControl } from '../server/settings-control'import {REPORT_CAP_PER_DAY,@@ -1607,3 +1608,12 @@ describe('the read-only GitHub lane verbs (issues, prs) in both agent-facing bodexpect(PROJECT_TARGETABLE_VERBS.has('prs')).toBe(true)})})++describe('open-project --name limit in the agent-facing text (issue #940)', () => {+ it('both bodies name the limit, rendered from PROJECT_NAME_MAX', () => {+ const sentence = `\`--name\` over ${PROJECT_NAME_MAX} characters`+ const squash = (s: string): string => s.replace(/\s+/g, ' ')+ expect(squash(buildCanvasSkillBody('/tmp/nodeterm.sh'))).toContain(sentence)+ expect(squash(buildCanvasControlInstructions('/tmp/nodeterm.sh'))).toContain(sentence)+ })+})diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 72a50b0d8..4f93c66a0 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -828,6 +828,7 @@ import { canvasTeamStations, useTeamStations } from '../state/teamStations'import { applyPullAutoMove } from '../lib/pullAutoMove'import { useWallpaperBackground, wallpaperLayers } from '../state/wallpaper'import { showCanvasDots } from '../lib/canvasDots'+import { PROJECT_NAME_MAX, clampProjectName } from '@shared/project-name'const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)@@ -12289,7 +12290,8 @@ export function Canvas() {srcTitle: opTitle,resolvedCwd,probedName: opProbed?.name,- requestedName: args.name+ // Cut as registerProject will cut it (issue #940); blank still means "no --name".+ requestedName: args.name === undefined ? undefined : clampProjectName(args.name) || undefined})if (opPlan.kind === 'silent') {// This caller already passed a human decision for this project (Q1): idempotent, quiet.@@ -16548,8 +16550,15 @@ export function Canvas() {label: 'Rename',icon: <IconEditor />,onClick: () => {- void promptDialog({ message: 'Rename project', initialValue: project.name }).then((t) => {- if (t && t.trim()) renameProject(projectId, t.trim())+ void promptDialog({+ message: 'Rename project',+ // Shown cut to what a rename would store (issue #940).+ initialValue: clampProjectName(project.name),+ maxLength: PROJECT_NAME_MAX+ }).then((t) => {+ // Confirming the cut name shown for an over-long one stores that cut (issue #940).+ const next = t?.trim()+ if (next && next !== project.name) renameProject(projectId, next)})}},diff --git a/src/renderer/components/InputDialog.tsx b/src/renderer/components/InputDialog.tsxindex 9d32d2f4a..53da55b36 100644--- a/src/renderer/components/InputDialog.tsx+++ b/src/renderer/components/InputDialog.tsx@@ -8,6 +8,8 @@ interface InputDialogProps {placeholder?: stringconfirmLabel?: stringcancelLabel?: string+ /** Longest value the field accepts (the HTML attribute: typing and pasting stop there). */+ maxLength?: numberonSubmit: (value: string) => voidonCancel: () => void}@@ -23,6 +25,7 @@ export function InputDialog({placeholder,confirmLabel = 'OK',cancelLabel = 'Cancel',+ maxLength,onSubmit,onCancel}: InputDialogProps) {@@ -47,6 +50,7 @@ export function InputDialog({className="confirm__input"value={value}placeholder={placeholder}+ maxLength={maxLength}spellCheck={false}onChange={(e) => setValue(e.target.value)}onKeyDown={(e) => {diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsxindex fc40c0755..8a226c948 100644--- a/src/renderer/components/TabBar.tsx+++ b/src/renderer/components/TabBar.tsx@@ -22,6 +22,7 @@ import {} from '@shared/agents/config'import { bypassSandboxCaveat, permissionModeAgentsLabel } from '@shared/agents/approval-mode'import { codexApprovalCaps } from '@renderer/state/codexCli'+import { PROJECT_NAME_MAX, clampProjectName } from '@shared/project-name'interface TabBarProps {onSwitch: (id: string) => void@@ -111,6 +112,9 @@ export function TabBar({)const [editingId, setEditingId] = useState<string | null>(null)const [draft, setDraft] = useState('')+ // The stored name the editor opened on. Committing the cut draft of an over-long one+ // (issue #940) stores that cut: the user asked to rename and sees what will be stored.+ const [draftStart, setDraftStart] = useState('')// Tab drag-reorder: the project id being dragged + the current drop target ('' = end zone).const [dragId, setDragId] = useState<string | null>(null)const [dropId, setDropId] = useState<string | null>(null)@@ -181,14 +185,16 @@ export function TabBar({const startRename = (id: string, current: string) => {setEditingId(id)- setDraft(current)+ // Start from what a rename would store, so an over-long name (issue #940) is shown cut.+ setDraft(clampProjectName(current))+ setDraftStart(current)closeMenu()}const commitRename = () => {if (editingId) {const name = draft.trim()- if (name) onRename(editingId, name)+ if (name && name !== draftStart) onRename(editingId, name)}setEditingId(null)}@@ -402,6 +408,7 @@ export function TabBar({<inputclassName="tab__edit"value={draft}+ maxLength={PROJECT_NAME_MAX}autoFocusspellCheck={false}onChange={(e) => setDraft(e.target.value)}diff --git a/src/renderer/components/promptDialog.tsx b/src/renderer/components/promptDialog.tsxindex d71a07da6..3d3d4dfe5 100644--- a/src/renderer/components/promptDialog.tsx+++ b/src/renderer/components/promptDialog.tsx@@ -10,6 +10,7 @@ interface PromptOptions {initialValue?: stringplaceholder?: stringconfirmLabel?: string+ maxLength?: number}interface PromptState {@@ -61,6 +62,7 @@ export function PromptDialogHost() {initialValue={current.initialValue}placeholder={current.placeholder}confirmLabel={current.confirmLabel}+ maxLength={current.maxLength}onSubmit={submit}onCancel={cancel}/>diff --git a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx b/src/renderer/components/settings/sections/ProjectSettingsSection.tsxindex ec6818875..613b7ab37 100644--- a/src/renderer/components/settings/sections/ProjectSettingsSection.tsx+++ b/src/renderer/components/settings/sections/ProjectSettingsSection.tsx@@ -28,6 +28,7 @@ import { useSettingsSearch } from '../context'import { projectSectionId } from '../project-settings-targets'import { matchesQuery, type SettingsSearchEntry } from '../search'import { useProjectSettings } from '../useProjectSettings'+import { PROJECT_NAME_MAX, clampProjectName } from '@shared/project-name'/*** Persists an identity/defaults edit. The store setters (`renameProject`, `setProjectColor`,@@ -178,8 +179,11 @@ function EditableProjectSection({const accountsHint = sshAccountsHint(project, accounts)// Editors commit on BLUR, never per keystroke: each commit is a disk write.- const [nameDraft, setNameDraft] = useState(project.name)- useEffect(() => setNameDraft(project.name), [project.name])+ // Shown cut to what a rename would store (issue #940); an unedited field writes nothing, so+ // merely visiting it does not cut an existing over-long name.+ const shownName = clampProjectName(project.name)+ const [nameDraft, setNameDraft] = useState(shownName)+ useEffect(() => setNameDraft(shownName), [shownName])const snapshot = settings.snapshot// A git-conflicted settings.json is left untouched for the user to resolve, so every editor of@@ -189,8 +193,8 @@ function EditableProjectSection({const commitName = (): void => {const next = nameDraft.trim()- if (!next || next === project.name) {- setNameDraft(project.name)+ if (!next || next === shownName) {+ setNameDraft(shownName)return}useProjects.getState().renameProject(project.id, next)@@ -228,12 +232,13 @@ function EditableProjectSection({id={`project-name-${project.id}`}className="w-72"value={nameDraft}+ maxLength={PROJECT_NAME_MAX}aria-label="Project name"onChange={(e) => setNameDraft(e.target.value)}onBlur={commitName}onKeyDown={(e) => {if (e.key === 'Enter') e.currentTarget.blur()- if (e.key === 'Escape') setNameDraft(project.name)+ if (e.key === 'Escape') setNameDraft(shownName)}}/>}diff --git a/src/renderer/state/projects.register.test.ts b/src/renderer/state/projects.register.test.tsindex 0dac2a548..468f80cde 100644--- a/src/renderer/state/projects.register.test.ts+++ b/src/renderer/state/projects.register.test.ts@@ -1,6 +1,7 @@import { describe, it, expect, beforeEach } from 'vitest'import { useProjects } from './projects'import type { Project } from '@shared/types'+import { PROJECT_NAME_MAX } from '@shared/project-name'/*** Issue #338 Task 2.1 — `registerProject`, the NON-ACTIVATING create/find used by the@@ -135,3 +136,28 @@ describe('registerProject — adopt (spec §2.1 step 3)', () => {expect(new Set(ids).size).toBe(ids.length)})})++describe('registerProject — the name an agent passes (issue #940)', () => {+ it('cuts an over-long --name to PROJECT_NAME_MAX', () => {+ const long = 'x'.repeat(PROJECT_NAME_MAX * 5)+ const { project } = useProjects+ .getState()+ .registerProject({ resolvedCwd: '/Users/me/dev/long-name', name: long })+ expect(project.name).toBe('x'.repeat(PROJECT_NAME_MAX))+ })++ it('caps the folder name it falls back to when no --name is given', () => {+ const folder = 'f'.repeat(PROJECT_NAME_MAX + 20)+ const { project } = useProjects+ .getState()+ .registerProject({ resolvedCwd: `/Users/me/dev/${folder}` })+ expect(project.name).toBe('f'.repeat(PROJECT_NAME_MAX))+ })++ it('falls back to the folder name for a blank --name', () => {+ const { project } = useProjects+ .getState()+ .registerProject({ resolvedCwd: '/Users/me/dev/blank-name', name: ' ' })+ expect(project.name).toBe('blank-name')+ })+})diff --git a/src/renderer/state/projects.test.ts b/src/renderer/state/projects.test.tsindex 0ef9f5c78..c17ccff70 100644--- a/src/renderer/state/projects.test.ts+++ b/src/renderer/state/projects.test.ts@@ -1,5 +1,6 @@import { describe, it, expect, beforeEach } from 'vitest'import { useProjects } from './projects'+import { PROJECT_NAME_MAX } from '@shared/project-name'beforeEach(() => {useProjects.getState().hydrate({ version: 2, activeProjectId: '', projects: [] })@@ -330,3 +331,34 @@ describe('rebindNode', () => {expect(stored('p1', 'n1')?.accountId).toBe('a')})})++describe('renameProject', () => {+ it('cuts a pasted wall of text to PROJECT_NAME_MAX (issue #940)', () => {+ const p = useProjects.getState().addProject('my-app', '/Users/me/dev/my-app')+ const pasted = 'Please refactor the session sidebar so that '.repeat(64)+ useProjects.getState().renameProject(p.id, pasted)+ const name = useProjects.getState().projects.find((q) => q.id === p.id)!.name+ expect(name.length).toBeLessThanOrEqual(PROJECT_NAME_MAX)+ expect(pasted.startsWith(name)).toBe(true)+ })++ it('trims the name, and leaves the project alone for a blank one', () => {+ const p = useProjects.getState().addProject('my-app', '/Users/me/dev/my-app')+ useProjects.getState().renameProject(p.id, ' renamed ')+ expect(useProjects.getState().projects.find((q) => q.id === p.id)!.name).toBe('renamed')+ useProjects.getState().renameProject(p.id, ' ')+ expect(useProjects.getState().projects.find((q) => q.id === p.id)!.name).toBe('renamed')+ })+})++describe('addProject — the name a new project gets (issue #940)', () => {+ it('cuts an over-long name, as a rename does', () => {+ const p = useProjects.getState().addProject('y'.repeat(PROJECT_NAME_MAX * 3), '/Users/me/dev/x')+ expect(p.name).toBe('y'.repeat(PROJECT_NAME_MAX))+ })++ it('keeps the default name when none, or a blank one, is given', () => {+ expect(useProjects.getState().addProject().name).toMatch(/^Project \d+$/)+ expect(useProjects.getState().addProject(' ').name).toMatch(/^Project \d+$/)+ })+})diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.tsindex f88170583..c08363cde 100644--- a/src/renderer/state/projects.ts+++ b/src/renderer/state/projects.ts@@ -23,6 +23,7 @@ import {pruneLayoutViewports,type CanvasLayout} from '@shared/canvas-layout'+import { clampProjectName } from '@shared/project-name'import { applyCanvasOp as applyCanvasOpTo, contentOf } from '@shared/canvas-content'import { diffToMutations, type CanvasScene } from '@shared/canvas-mutations'import { applyOwnCanvasMutation, createProject, reorderGroupWithinParent } from './workspace'@@ -488,7 +489,10 @@ export const useProjects = create<ProjectsState>((set, get) => ({},addProject(name, cwd, ssh) {- const project = createProject(get().projects.length, name, cwd, ssh)+ // Every new project's name — a folder's own name, an SSH label, a relay host's project+ // name — gets the same cap as a rename (issue #940). A blank one keeps createProject's default.+ const clean = name === undefined ? undefined : clampProjectName(name) || undefined+ const project = createProject(get().projects.length, clean, cwd, ssh)set((s) => ({ projects: [...s.projects, project] }))return project},@@ -551,8 +555,12 @@ export const useProjects = create<ProjectsState>((set, get) => ({},renameProject(id, name) {+ // Every rename surface funnels through here, so the cap holds even for input that bypassed a+ // field's maxLength (issue #940). A blank name is not a rename.+ const clean = clampProjectName(name)+ if (!clean) returnset((s) => ({- projects: s.projects.map((p) => (p.id === id ? { ...p, name } : p))+ projects: s.projects.map((p) => (p.id === id ? { ...p, name: clean } : p))}))},@@ -1076,9 +1084,10 @@ export const useProjects = create<ProjectsState>((set, get) => ({set((s) => ({ projects: [...s.projects, adopted] }))return { project: adopted, created: false, adopted: true }}- const fallbackName = folderName(cwd) || 'Project'+ const fallbackName = clampProjectName(folderName(cwd)) || 'Project'+ // `name` is the agent's `--name`, free text like a rename: same cap (issue #940).const project = {- ...createProject(get().projects.length, name ?? fallbackName, cwd),+ ...createProject(get().projects.length, clampProjectName(name ?? '') || fallbackName, cwd),...(color ? { color } : {})}set((s) => ({ projects: [...s.projects, project] }))diff --git a/src/shared/project-name.test.ts b/src/shared/project-name.test.tsindex 412b3e383..8fcbbe5c8 100644--- a/src/shared/project-name.test.ts+++ b/src/shared/project-name.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { folderName, healPathAsName } from './project-name'+import { PROJECT_NAME_MAX, clampProjectName, folderName, healPathAsName } from './project-name'describe('folderName', () => {it('takes the last segment of a POSIX path', () => {@@ -63,3 +63,45 @@ describe('healPathAsName', () => {expect(healPathAsName('', cwd)).toBe('')})})++describe('clampProjectName', () => {+ it('trims and keeps a name within the limit unchanged', () => {+ expect(clampProjectName(' nodeterm ')).toBe('nodeterm')+ const exact = 'x'.repeat(PROJECT_NAME_MAX)+ expect(clampProjectName(exact)).toBe(exact)+ })++ it('cuts a pasted wall of text to the limit (issue #940: a 2,798-character prompt)', () => {+ const pasted = 'Please refactor the session sidebar so that '.repeat(64)+ expect(pasted.length).toBeGreaterThan(2_000)+ const clamped = clampProjectName(pasted)+ expect(clamped.length).toBeLessThanOrEqual(PROJECT_NAME_MAX)+ expect(pasted.startsWith(clamped)).toBe(true)+ })++ it('does not leave trailing whitespace where the cut landed', () => {+ const name = `${'a'.repeat(PROJECT_NAME_MAX - 1)} tail`+ expect(clampProjectName(name)).toBe('a'.repeat(PROJECT_NAME_MAX - 1))+ })++ it('counts UTF-16 units like an input maxLength, and drops an emoji the cut would halve', () => {+ // Same unit as the HTML maxLength on the rename fields, so a field and the store agree.+ const fits = `${'a'.repeat(PROJECT_NAME_MAX - 2)}😀`+ expect(clampProjectName(fits)).toBe(fits)+ const name = `${'a'.repeat(PROJECT_NAME_MAX - 1)}😀`+ const clamped = clampProjectName(name)+ expect(clamped).toBe('a'.repeat(PROJECT_NAME_MAX - 1))+ // A lone surrogate would be invalid UTF-16 in project.json.+ expect(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/.test(clamped)).toBe(false)+ })++ it('drops a lone high surrogate left at the end by a field maxLength', () => {+ const halved = `${'a'.repeat(PROJECT_NAME_MAX - 1)}\uD83D`+ expect(halved.length).toBe(PROJECT_NAME_MAX)+ expect(clampProjectName(halved)).toBe('a'.repeat(PROJECT_NAME_MAX - 1))+ })++ it('answers empty for a blank name', () => {+ expect(clampProjectName(' ')).toBe('')+ })+})diff --git a/src/shared/project-name.ts b/src/shared/project-name.tsindex 1c8faedb7..24f8781a7 100644--- a/src/shared/project-name.ts+++ b/src/shared/project-name.ts@@ -65,3 +65,27 @@ export function healPathAsName(name: string, cwd: string | undefined): string {if (!cwd || !name || !samePath(name, cwd)) return namereturn folderName(cwd) || name}++/**+ * The longest name a project may be given by a rename (issue #940). A project name is drawn in+ * the tab strip, the sessions sidebar and the welcome screen, and it is stored in both+ * workspace.json and the git-shared `.nodeterm/project.json` — so a prompt pasted into a rename+ * field by mistake (2,798 characters in the report) was kept everywhere until renamed by hand.+ * Canvas layout names have the same kind of cap (`CANVAS_LAYOUT_NAME_MAX`).+ */+export const PROJECT_NAME_MAX = 100++/**+ * Trim a candidate project name and cut it to `PROJECT_NAME_MAX` UTF-16 units — the unit the+ * inputs' HTML `maxLength` counts in, so a name typed into a field and a name passed with+ * `open-project --name` get the same limit. An emoji straddling the cut is dropped rather than+ * split into a lone surrogate (a multi-code-point sequence such as a flag can still be cut+ * between its code points). Whitespace left at the cut is trimmed too. Returns '' for a blank+ * name; callers treat that as "no name given".+ */+export function clampProjectName(name: string): string {+ let cut = name.trim().slice(0, PROJECT_NAME_MAX)+ // Also when the name was not cut here: a field's maxLength can itself stop halfway an emoji.+ if (/[\uD800-\uDBFF]$/.test(cut)) cut = cut.slice(0, -1)+ return cut.trimEnd()+}