The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Name worktree branches in one or two words (#327)
Dee3f8f96a6b7b3
diff --git a/cli/src/lib/agentNames.ts b/cli/src/lib/agentNames.tsindex dbdf0e0b5..d4cad7b6c 100644--- a/cli/src/lib/agentNames.ts+++ b/cli/src/lib/agentNames.ts@@ -98,12 +98,94 @@ export function worktreeFolderName(branch: string): string {return name ? name.slice(0, 64) : 'worktree'}-/** A session's name as a branch's last part: `Worktree and branches organization` →- * `worktree-and-branches-organization`, cut at a word to 48 characters. Null when nothing is left. */-export function sessionBranchSlug(title: string | null | undefined): string | null {- let slug = (title ?? '').normalize('NFKD').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')- if (slug.length > 48) slug = slug.slice(0, 48).replace(/-[^-]*$/, '') || slug.slice(0, 48)- return slug || null+/** Words a branch name can do without: they join a title's words, point at something, or grade it —+ * none of them tell branches apart. Measured against this repo's session and PR titles. */+const BRANCH_FILLER = new Set([+ // Joining words.+ 'a', 'an', 'the', 'and', 'or', 'but', 'so', 'of', 'to', 'for', 'in', 'on', 'at', 'by', 'with', 'from',+ 'into', 'onto', 'as', 'is', 'are', 'be', 'up', 'about', 'after', 'before', 'then', 'than', 'via', 'per',+ 'out', 'off', 'over', 'under', 'through', 'across', 'between', 'without', 'instead', 'not', 'only',+ // Pointing words, people and questions.+ 'this', 'that', 'these', 'those', 'it', 'its', 'my', 'me', 'our', 'we', 'us', 'your', 'you', 'i',+ 'they', 'them', 'their', 'what', 'how', 'why', 'when', 'where', 'which', 'who', 'can', 'should',+ 'will', 'would', 'may', 'ok', 'okay', 'please', 'lets', 'just', 'also', 'now', 'here', 'there',+ 'all', 'any', 'some', 'every', 'each', 'more', 'most', 'very', 'whether', 'whose', 'another', 'other',+ 'never', 'no', 'longer', 'own', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',+ 'nine', 'ten',+ // Grading words.+ 'simple', 'basic', 'quick', 'small', 'latest', 'exact', 'exactly', 'extra', 'bold', 'iconic', 'better',+])++/** What a title's first word usually is, and what every branch would otherwise start with. The PR title+ * keeps the verb; the branch keeps what it is about. */+const BRANCH_VERBS = new Set([+ 'fix', 'add', 'update', 'make', 'improve', 'refine', 'build', 'rebuild', 'implement', 'support', 'handle',+ 'remove', 'change', 'move', 'allow', 'create', 'use', 'show', 'hide', 'let', 'set', 'get', 'enable',+ 'disable', 'rename', 'refactor', 'clean', 'debug', 'investigate', 'review', 'help', 'write', 'rewrite',+ 'test', 'discuss', 'explore', 'plan', 'research', 'try', 'check', 'catch', 'look', 'pull', 'push', 'run',+ 'open', 'close', 'start', 'stop', 'keep', 'give', 'guide', 'simplify', 'tighten', 'restore', 'reject',+ 'prevent', 'measure', 'defer', 'reduce', 'retire', 'preserve', 'detect', 'expose', 'guard', 'surface',+ 'reorganize', 'organize', 'respond', 'reply', 'return', 'provide', 'greet', 'define', 'choose', 'study',+ 'diagnose', 'summarize', 'clarify', 'explain', 'document', 'describe', 'compare', 'find', 'ask',+ 'answer', 'draft', 'prepare', 'generate', 'tune', 'polish', 'redesign', 'migrate', 'upgrade', 'bump',+ 'drop', 'delete', 'replace', 'revert', 'wire', 'port', 'sync', 'load', 'save', 'install', 'uninstall',+ 'publish', 'deploy', 'speed', 'trim', 'shorten', 'split', 'merge', 'center', 'align', 'unpack', 'say',+ 'read', 'mark', 'name', 'tell', 'avoid', 'reuse', 'reveal', 'adopt', 'treat', 'refresh', 'recover',+ 'unify', 'activate', 'record', 'unblock', 'lead', 'ship', 'select',+])++/** Words that say what kind of thing a change touches, not which: `login page` is the login, `onboarding+ * experience` is onboarding. As a second word they add length and no meaning. */+const BRANCH_GENERIC = new Set([+ 'page', 'pages', 'screen', 'screens', 'view', 'views', 'flow', 'flows', 'experience', 'ui', 'ux',+ 'issue', 'issues', 'bug', 'bugs', 'problem', 'problems', 'error', 'errors', 'fix', 'fixes',+ 'feature', 'features', 'support', 'setup', 'logic', 'code', 'handling', 'behavior', 'behaviour',+ 'stuff', 'thing', 'things', 'work', 'change', 'changes', 'update', 'updates', 'improvement',+ 'improvements', 'cleanup', 'polish', 'tweak', 'tweaks', 'part', 'section',+])++/** The names a session's branch may take, best first: as few words as carry the meaning — one or two+ * — then, only for a clash, the fuller two-word name and then a third word of the title.+ * `Harness monitor DDOS requests` → `harness-monitor`, then `harness-monitor-ddos`; `Fix the login+ * page` → `login`, then `login-page`; `Onboarding` → `onboarding`. Filler words, a leading verb and+ * lone numbers go first (a title that is only a verb keeps it). Each word is capped at 24+ * characters. Empty when nothing meaningful is left, and the placeholder branch stays. */+export function sessionBranchNames(title: string | null | undefined): string[] {+ // NFKD splits `é` into `e` and its accent; the accent goes, or it would split the word in two.+ // A commit-style `feat(desktop):` names the kind of change, which the branch leaves to the PR.+ const words = (title ?? '').normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase()+ .replace(/^\s*(feat|fix|perf|test|tests|docs|doc|ci|chore|refactor|style|build|revert|wip)(\([^)]*\))?!?:\s*/, '')+ // The first sentence: a title that runs on (`Look at my Chrome. Open the file…`) is a prompt.+ .split(/[.!?](?:\s|$)/)[0]!+ // `sign-in`, `8-bit`, `autonomous-code`: a two-part hyphenated word is one word and stays whole —+ // split, `sign-in came` loses its `in` and names the branch `sign-came`. Longer chains split.+ .split(/[^a-z0-9-]+/).flatMap(token => {+ const parts = token.split('-').filter(Boolean)+ return parts.length === 2 ? [parts.join('-')] : parts+ })+ .filter((word, i, all) => word && word !== all[i - 1])+ const meaningful = words.filter(word => !BRANCH_FILLER.has(word))+ while (meaningful.length > 1 && BRANCH_VERBS.has(meaningful[0]!)) meaningful.shift()+ // A lone number (`0` of 0.3.1, `2` of "Part 2") says nothing beside a word that does.+ const worded = meaningful.filter(word => !/^\d+$/.test(word))+ const cap = (word: string) => word.split('-').map(part => part.slice(0, 24)).join('-')+ const source = (worded.length ? worded : meaningful).map(cap)+ if (!source.length) return []+ const first = source[0]!+ // The words after the first, one at a time: `app auto-opening` goes on with `auto`, and `desktop+ // on-screen` with `screen` — never a filler half.+ const after = source.slice(1).flatMap(word => word.split('-')).filter(part => !BRANCH_FILLER.has(part))+ // A clash's third word says what sets this session apart, so a generic one is passed over.+ const third = (base: string, rest: string[]) => {+ const word = rest.find(part => !BRANCH_GENERIC.has(part))+ return word ? [`${base}-${word}`] : []+ }+ // A hyphenated pair already is two words.+ if (first.includes('-')) return [first, ...third(first, after)]+ const [second, ...more] = after+ if (!second) return [first]+ const two = `${first}-${second}`+ return [...BRANCH_GENERIC.has(second) ? [first] : [], two, ...third(two, more)]}/** A name Git might accept for a new branch, checked before Git is asked. */diff --git a/cli/src/lib/branchNaming.ts b/cli/src/lib/branchNaming.tsindex e601108d8..71e779546 100644--- a/cli/src/lib/branchNaming.ts+++ b/cli/src/lib/branchNaming.ts@@ -1,6 +1,6 @@import { execFile } from 'node:child_process'import { promisify } from 'node:util'-import { sessionBranchSlug } from './agentNames.js'+import { sessionBranchNames } from './agentNames.js'import { HARNESS_BRANCH_KEY } from './gitProject.js'const exec = promisify(execFile)@@ -12,30 +12,37 @@ async function git(cwd: string, args: string[]): Promise<string> {.stdout.replace(/\r?\n$/, '')}+/** Names that read as a repository's own branches or remotes. A session is never named one of them. */+const RESERVED_BRANCHES = ['main', 'master', 'head', 'origin', 'upstream', 'develop', 'development', 'trunk',+ 'staging', 'production', 'prod', 'gh-pages']+/*** Names a worktree's branch after its session, once: `brave-otter`, made up at Start, becomes- * `worktree-and-branches-organization` when the session first has a name. A name a local or remote- * branch already has gets `-2`. Only a branch Harness+ * `harness-list` for `Fix the harness list order`, or `login` for `Fix the login page`, when the+ * session first has a name. A taken name falls back to the fuller ones `sessionBranchNames` offers —+ * `login-page`, then a third word of the title — and only then to the shortest with `-2`, `-3`…+ * Names are compared without case: on macOS `Login` and `login` are one file. Only a branch Harness* marked as a placeholder, with no upstream, is renamed; the mark goes with it, so a later session name,* a push, or a rename by the person or the agent is never overridden. Returns the new name, if any.*/export async function nameBranchAfterSession(cwd: string, title: string | null): Promise<string | null> {- const slug = sessionBranchSlug(title)- if (!slug) return null+ const names = sessionBranchNames(title)+ if (!names.length) return nullconst branch = await git(cwd, ['symbolic-ref', '--quiet', '--short', 'HEAD']).catch(() => null)if (!branch) return nullconst mark = await git(cwd, ['config', '--get', `branch.${branch}.${HARNESS_BRANCH_KEY}`]).catch(() => null)if (mark !== 'placeholder') return nullif (await git(cwd, ['config', '--get', `branch.${branch}.remote`]).then(() => true, () => false)) return null- const base = slug+ const base = names[0]!// Taken here, or on a remote: a name somebody else pushed is not one to push over.- const known = new Set((await git(cwd, ['for-each-ref', '--format=%(refname)', 'refs/heads', 'refs/remotes']).catch(() => ''))+ const known = new Set([...RESERVED_BRANCHES, ...(await git(cwd, ['for-each-ref', '--format=%(refname)', 'refs/heads', 'refs/remotes']).catch(() => '')).split('\n').flatMap(ref => ref.startsWith('refs/heads/') ? [ref.slice(11)]- : ref.startsWith('refs/remotes/') ? [ref.split('/').slice(3).join('/')] : []))- for (let attempt = 1; attempt <= 50; attempt++) {- const name = attempt === 1 ? base : `${base}-${attempt}`+ : ref.startsWith('refs/remotes/') ? [ref.split('/').slice(3).join('/')] : [])+ .map(name => name.toLowerCase())])+ const candidates = [...names, ...Array.from({ length: 49 }, (_, i) => `${base}-${i + 2}`)]+ for (const name of candidates) {if (name === branch) return null- if (known.has(name)) continue+ if (known.has(name.toLowerCase())) continuetry { await git(cwd, ['check-ref-format', '--branch', name]) } catch { return null }await git(cwd, ['branch', '-m', branch, name])await git(cwd, ['config', `branch.${name}.${HARNESS_BRANCH_KEY}`, 'created']).catch(() => '')diff --git a/cli/src/lib/gitProject.spec.ts b/cli/src/lib/gitProject.spec.tsindex 4655d86e6..be3ec9f78 100644--- a/cli/src/lib/gitProject.spec.ts+++ b/cli/src/lib/gitProject.spec.ts@@ -5,7 +5,7 @@ import { join } from 'node:path'import { promisify } from 'node:util'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { encryptDownFrame, encryptRpcResult } from './e2ee/applicationFrames.js'-import { placeholderBranch, sessionBranchSlug, worktreeFolderName } from './agentNames.js'+import { placeholderBranch, sessionBranchNames, worktreeFolderName } from './agentNames.js'import { nameBranchAfterSession } from './branchNaming.js'import { prepareGitProject, readGitProject, validGitPath } from './gitProject.js'import { parseProjectFolder, prepareProjectFolder } from './projectFolder.js'@@ -131,10 +131,57 @@ describe('launch Git preparation', { timeout: 30_000 }, () => {expect(placeholderBranch(['refs/heads/amber-badger', 'amber-badger-2'], () => 0)).toBe('amber-badger-3')expect(worktreeFolderName('deehw/brave-otter')).toBe('brave-otter')expect(worktreeFolderName('fix/login page')).toBe('loginpage')- expect(sessionBranchSlug('Worktree and branches organization')).toBe('worktree-and-branches-organization')- expect(sessionBranchSlug('✳ Fix: the login page — redirects twice?')).toBe('fix-the-login-page-redirects-twice')- expect(sessionBranchSlug('a'.repeat(30) + ' ' + 'b'.repeat(30))).toBe('a'.repeat(30))- expect(sessionBranchSlug('✳ ✳')).toBeNull()+ // Two words when both carry the meaning.+ expect(sessionBranchNames('Worktree and branches organization')).toEqual(['worktree-branches', 'worktree-branches-organization'])+ expect(sessionBranchNames('Fix the harness list order')).toEqual(['harness-list', 'harness-list-order'])+ expect(sessionBranchNames('Add dark mode to settings')).toEqual(['dark-mode', 'dark-mode-settings'])+ expect(sessionBranchNames('Review and fix flaky tests')).toEqual(['flaky-tests'])+ expect(sessionBranchNames('Portable harnesses, launch models')).toEqual(['portable-harnesses', 'portable-harnesses-launch'])+ expect(sessionBranchNames('Release 0.3.1 notes')).toEqual(['release-notes'])+ expect(sessionBranchNames('Café résumé')).toEqual(['cafe-resume'])+ // One word when the second is generic, the two-word name kept for a clash.+ expect(sessionBranchNames('✳ Fix: the login page — redirects twice?')).toEqual(['login', 'login-page', 'login-page-redirects'])+ expect(sessionBranchNames('Onboarding experience')).toEqual(['onboarding', 'onboarding-experience'])+ expect(sessionBranchNames('UI polish')).toEqual(['ui', 'ui-polish'])+ // One word when that is all the title has.+ expect(sessionBranchNames('Onboarding')).toEqual(['onboarding'])+ expect(sessionBranchNames('Fix')).toEqual(['fix'])+ expect(sessionBranchNames('0.3.1')).toEqual(['0-3', '0-3-1'])+ expect(sessionBranchNames('a'.repeat(30) + ' ' + 'b'.repeat(30))).toEqual(['a'.repeat(24) + '-' + 'b'.repeat(24)])+ // Real session titles from Claude Code, Codex and this repository's PRs (2026-09-25).+ for (const [title, name] of [+ ['Catch up on autonomous-grid', 'autonomous-grid'],+ ['ok catch up on this landing page. we', 'landing'],+ ['Look at my Chrome. Open the file, au', 'chrome'],+ ['What time is it', 'time'],+ ['Build simple Pacman game', 'pacman-game'],+ ['Respond to greeting', 'greeting'],+ ['Define GPU Pod concept', 'gpu-pod'],+ ['Research roleplay app names', 'roleplay-app'],+ ['Device stuck issue', 'device-stuck'],+ ['Harness landing page redesign', 'harness-landing'],+ ['Review inventory protection', 'inventory-protection'],+ ['Remove Grid desktop app', 'grid-desktop'],+ ['feat(cli): add a Requesty preset to saved APIs', 'requesty-preset'],+ ['perf(desktop): redraw only terminal lines that changed', 'redraw-terminal'],+ ['fix(cli): unlink a linked dsh on remove instead of rmSync', 'unlink-linked'],+ ['feat(harnesses): add eight interactive experiences', 'interactive-experiences'],+ ['feat(login): record whether a sign-in came from the terminal', 'sign-in'],+ ['Study autonomous-code repo', 'autonomous-code'],+ ['8-bit CPU Fibonacci on iCEBreaker', '8-bit'],+ ['Restore split-right and split-down pane controls', 'split-right'],+ ['App auto-opening extra tabs', 'app-auto'],+ ['Explore print-in-place uses', 'print-place'],+ ['desktop: an on-screen banner for the same two moments', 'desktop'],+ ['Harness on-off switch', 'harness-switch'],+ ['Simplify Cmd-P with single-line results', 'cmd-p'],+ ['Give Harness Monitor its stacked-terminal identity', 'harness-monitor'],+ ['ci: CI and release workflows', 'ci-release'],+ ['catch up', 'catch'],+ ] as const) expect(sessionBranchNames(title)[0], title).toBe(name)+ expect(sessionBranchNames('The and of')).toEqual([])+ expect(sessionBranchNames('✳ ✳')).toEqual([])+ expect(sessionBranchNames(null)).toEqual([])const made = [await prepare('worktree'), await prepare('worktree')]expect(new Set(made).size).toBe(2)for (const path of made) {@@ -174,17 +221,38 @@ describe('launch Git preparation', { timeout: 30_000 }, () => {it('names a made-up worktree branch after its session once, and never a pushed or chosen one', async () => {const path = await prepare('worktree', 'refs/heads/feature', repo, { branchName: 'quiet-owl', branchMode: 'placeholder' })expect(await nameBranchAfterSession(path, null)).toBeNull()- expect(await nameBranchAfterSession(path, 'Worktree and branches organization')).toBe('worktree-and-branches-organization')- expect(await current(path)).toBe('worktree-and-branches-organization')- expect(await git('config', '--get', 'branch.worktree-and-branches-organization.harness')).toBe('created')+ expect(await nameBranchAfterSession(path, 'Worktree and branches organization')).toBe('worktree-branches')+ expect(await current(path)).toBe('worktree-branches')+ expect(await git('config', '--get', 'branch.worktree-branches.harness')).toBe('created')expect(await nameBranchAfterSession(path, 'A later name')).toBeNull()- expect(await current(path)).toBe('worktree-and-branches-organization')+ expect(await current(path)).toBe('worktree-branches')+ // Taken, with no third word to add: a number.const second = await prepare('worktree', 'refs/heads/feature', repo, { branchName: 'calm-fox', branchMode: 'placeholder' })- expect(await nameBranchAfterSession(second, 'Worktree and branches organization')).toBe('worktree-and-branches-organization-2')+ expect(await nameBranchAfterSession(second, 'Fix the worktree branches')).toBe('worktree-branches-2')+ // A clash takes the fuller name, then a third word, then numbers the shortest.+ const named = async (title: string, placeholders: string[]) => {+ const out = []+ for (const branchName of placeholders) {+ const at = await prepare('worktree', 'refs/heads/feature', repo, { branchName, branchMode: 'placeholder' })+ out.push(await nameBranchAfterSession(at, title))+ }+ return out+ }+ expect(await named('Fix the login page', ['keen-lynx', 'tidy-heron', 'rosy-finch']))+ .toEqual(['login', 'login-page', 'login-2'])+ expect(await named('Harness monitor DDOS requests', ['warm-ibis', 'glad-crane', 'bold-lark']))+ .toEqual(['harness-monitor', 'harness-monitor-ddos', 'harness-monitor-2'])+ // A repository's own names are never taken, whatever the title says.+ // This repository has no `master`: only the reserved list keeps a session from taking it.+ expect(await git('branch', '--list', 'master')).toBe('')+ expect(await named('Master', ['sunny-moose'])).toEqual(['master-2'])+ // Case does not tell names apart: on macOS `Deploy` and `deploy` are one ref file.+ await git('update-ref', 'refs/remotes/origin/Deploy', 'main')+ expect(await named('Deploy', ['noble-reef'])).toEqual(['deploy-2'])// A name a remote has is taken too.const third = await prepare('worktree', 'refs/heads/feature', repo, { branchName: 'quiet-fox', branchMode: 'placeholder' })- await git('update-ref', 'refs/remotes/origin/onboarding-experience', 'main')- expect(await nameBranchAfterSession(third, 'Onboarding experience')).toBe('onboarding-experience-2')+ await git('update-ref', 'refs/remotes/origin/onboarding', 'main')+ expect(await nameBranchAfterSession(third, 'Onboarding experience')).toBe('onboarding-experience')const chosen = await prepare('worktree', 'refs/heads/feature', repo, { branchName: 'fix/mine' })expect(await nameBranchAfterSession(chosen, 'Anything')).toBeNull()const pushed = await prepare('worktree', 'refs/heads/feature', repo, { branchName: 'sunny-owl', branchMode: 'placeholder' })@@ -209,13 +277,13 @@ describe('launch Git preparation', { timeout: 30_000 }, () => {id: session.sessionId, thread_name: 'Discuss configurable harness agents',}) + '\n')const title = namingTitle(engineSessionTitle(session, 'renaming... ⠴'), session)- expect(await nameBranchAfterSession(path, title)).toBe('discuss-configurable-harness-agents')- expect(await current(path)).toBe('discuss-configurable-harness-agents')- expect(await git('config', '--get', 'branch.discuss-configurable-harness-agents.harness')).toBe('created')- expect(await git('rev-parse', 'discuss-configurable-harness-agents')).toBe(await git('rev-parse', 'feature'))+ expect(await nameBranchAfterSession(path, title)).toBe('configurable-harness')+ expect(await current(path)).toBe('configurable-harness')+ expect(await git('config', '--get', 'branch.configurable-harness.harness')).toBe('created')+ expect(await git('rev-parse', 'configurable-harness')).toBe(await git('rev-parse', 'feature'))expect(await readFile(join(path, 'src', 'value'), 'utf8')).toBe('work in progress')expect(await nameBranchAfterSession(path, 'A later conversation title')).toBeNull()- expect(await current(path)).toBe('discuss-configurable-harness-agents')+ expect(await current(path)).toBe('configurable-harness')})it('checks out an existing branch as it is in a new worktree, once', async () => {diff --git a/desktop/design/new-harness-entry-rules.md b/desktop/design/new-harness-entry-rules.mdindex cd384676b..4e8a639ba 100644--- a/desktop/design/new-harness-entry-rules.md+++ b/desktop/design/new-harness-entry-rules.md@@ -163,8 +163,15 @@ dropped.A session has no name at Start, so that branch starts as a made-up`<word>-<word>`, marked `branch.<name>.harness = placeholder` in therepository's config and left out of the pane header. The daemon renames it once,-to the session's name (`-2` when a local or remote branch has it), when the-session first has a name, and never again:+to one or two words of the session's name, when the session first has a name.+Filler words and a leading verb are dropped, and a generic second word (page,+flow, experience, issue…) is too: `Fix the harness list order` becomes+`harness-list`, `Fix the login page` becomes `login`. A taken name falls back to+the two-word one (`login-page`), then adds the title's next telling word+(`harness-monitor-ddos`), and only then numbers the shortest (`login-2`). Local+and remote branches both count, without regard to case, and a repository's own+names (`main`, `master`, `head`, `origin`, `develop`…) are always taken. It is+renamed only that once, and never again:not after a later session name, a push, or a rename by the person or the agent.A picked or created branch keeps its name. The worktree is checked out in`~/harnesses/worktrees/<repository>/<branch>`, and ignored files listed in the