π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ feat(worktree): default new worktree branches to lobehub/ (#23173)
Bryanec3b74b63d4a
diff --git a/packages/const/src/worktreeName.test.ts b/packages/const/src/worktreeName.test.tsindex 365af6eed70..8fdff1a8f8d 100644--- a/packages/const/src/worktreeName.test.ts+++ b/packages/const/src/worktreeName.test.ts@@ -32,6 +32,13 @@ describe('formatWorktreeTimestamp', () => {});describe('generateWorktreeBranchName', () => {+ it('namespaces generated branches under lobehub/ by default', () => {+ expect(WORKTREE_BRANCH_PREFIX).toBe('lobehub');+ expect(generateWorktreeBranchName({ now: NOW, random: () => 0 })).toBe(+ `lobehub/202610020308-${WORKTREE_ADJECTIVES[0]}-${WORKTREE_NOUNS[0]}`,+ );+ });+it('yields <prefix>/<YYYYMMDDHHmm>-<adjective>-<noun>', () => {const shape = new RegExp(`^${WORKTREE_BRANCH_PREFIX}/\\d{12}-[a-z]+-[a-z]+$`);@@ -45,7 +52,7 @@ describe('generateWorktreeBranchName', () => {const nouns = new Set<string>(WORKTREE_NOUNS);for (const name of sample()) {- // `wt/202610020308-quiet-hill` β ['wt/202610020308', 'quiet', 'hill']+ // `lobehub/202610020308-quiet-hill` β ['lobehub/202610020308', 'quiet', 'hill']const [, adjective, noun] = name.split('-');expect(adjectives.has(adjective)).toBe(true);expect(nouns.has(noun)).toBe(true);@@ -72,42 +79,45 @@ describe('generateWorktreeBranchName', () => {it('keeps the first draw when nothing it drew is taken', () => {expect(- generateWorktreeBranchName({ exclude: ['wt/202001010000-other-name'], now: NOW }),- ).toMatch(/^wt\/202610020308-/);+ generateWorktreeBranchName({ exclude: ['lobehub/202001010000-other-name'], now: NOW }),+ ).toMatch(/^lobehub\/202610020308-/);});it('spreads across the pool so repeats are rare', () => {expect(new Set(sample(200)).size).toBeGreaterThan(150);});- // Git refuses `refs/heads/wt/x` while a ref `refs/heads/wt` exists, and every+ // Git refuses `refs/heads/lobehub/x` while a ref `refs/heads/lobehub` exists, and every// namespaced draw shares that segment β so the namespace, not the word pair,// is what has to give.describe('when a ref occupies the namespace path', () => {it('falls back to the flat form instead of handing out a ref git will refuse', () => {- expect(generateWorktreeBranchName({ exclude: ['wt'], now: NOW, random: () => 0 })).toMatch(- /^wt-\d{12}-[a-z]+-[a-z]+$/,- );+ expect(+ generateWorktreeBranchName({ exclude: ['lobehub'], now: NOW, random: () => 0 }),+ ).toMatch(/^lobehub-\d{12}-[a-z]+-[a-z]+$/);});it('ignores the case of the occupying ref, like git refs do', () => {- expect(generateWorktreeBranchName({ exclude: ['WT'], now: NOW, random: () => 0 })).toMatch(- /^wt-\d{12}-/,- );+ expect(+ generateWorktreeBranchName({ exclude: ['LOBEHUB'], now: NOW, random: () => 0 }),+ ).toMatch(/^lobehub-\d{12}-/);});it('keeps the namespace for taken names that are unrelated', () => {expect(- generateWorktreeBranchName({ exclude: ['main', 'wt/202001010000-other-name'], now: NOW }),- ).toMatch(/^wt\//);+ generateWorktreeBranchName({+ exclude: ['main', 'lobehub/202001010000-other-name'],+ now: NOW,+ }),+ ).toMatch(/^lobehub\//);});it('redraws the flat form when the drawn flat name is taken too', () => {- const taken = generateWorktreeBranchName({ exclude: ['wt'], now: NOW, random: () => 0 });+ const taken = generateWorktreeBranchName({ exclude: ['lobehub'], now: NOW, random: () => 0 });expect(generateWorktreeBranchName({- exclude: ['wt', taken],+ exclude: ['lobehub', taken],now: NOW,random: sequence([0, 0, 0.5, 0.5]),}),diff --git a/packages/const/src/worktreeName.ts b/packages/const/src/worktreeName.tsindex 5198bef8470..ac97ff307b1 100644--- a/packages/const/src/worktreeName.ts+++ b/packages/const/src/worktreeName.ts@@ -1,16 +1,16 @@/*** Auto-generated branch names for a freshly created worktree.*- * Shape: `wt/<YYYYMMDDHHmm>-<adjective>-<noun>` β e.g. `wt/202610020308-quiet-hill`.+ * Shape: `lobehub/<YYYYMMDDHHmm>-<adjective>-<noun>` β e.g. `lobehub/202610020308-quiet-hill`.* The minutes-precision timestamp keeps the branch list chronological when sorted* by name; the word pair keeps the name human-readable and, together with the* timestamp, makes a collision unlikely. Only lowercase ASCII and `-` are used,* so the name is always a valid git ref, and it folds cleanly into the worktree- * folder name (`deriveWorktreePath` turns it into `wt-202610020308-quiet-hill`).+ * folder name (`deriveWorktreePath` turns it into `lobehub-202610020308-quiet-hill`).*//** Namespace prefix, so worktrees created by the app group together in the branch list. */-export const WORKTREE_BRANCH_PREFIX = 'wt';+export const WORKTREE_BRANCH_PREFIX = 'lobehub';export const WORKTREE_ADJECTIVES = ['amber',@@ -139,8 +139,8 @@ const pick = <T>(pool: readonly T[], random: () => number): T =>/*** Whether a ref already occupies the candidate's path. Git stores refs as paths,- * so `refs/heads/wt` and `refs/heads/wt/x` cannot coexist β creating the second- * fails with `cannot lock ref β¦ 'refs/heads/wt' exists`. Matching names exactly+ * so `refs/heads/lobehub` and `refs/heads/lobehub/x` cannot coexist β creating the second+ * fails with `cannot lock ref β¦ 'refs/heads/lobehub' exists`. Matching names exactly* cannot see that, and the reverse (the candidate becoming an ancestor of an* existing ref) is refused the same way, so every path segment is checked.*/@@ -161,8 +161,8 @@ const refPathConflict = (candidate: string, taken: ReadonlySet<string>): booleanexport interface GenerateWorktreeBranchNameOptions {/*** Refs the caller already has in view. Branch names count, including one that- * names a path SEGMENT rather than a leaf (a branch literally called `wt`- * blocks the whole `wt/` namespace). The draw retries a bounded number of+ * names a path SEGMENT rather than a leaf (a branch literally called `lobehub`+ * blocks the whole `lobehub/` namespace). The draw retries a bounded number of* times against them, and a repeat beats no name (mirrors `randomAgentName`).*/exclude?: Iterable<string>;@@ -180,10 +180,10 @@ const drawWith = (shape: () => string, taken: ReadonlySet<string>): string => {* Draw a branch name for a new worktree, with the timestamp taken from `now`* and the word pair from `random`. Both are injectable so callers stay testable.*- * Names are namespaced (`wt/<timestamp>-β¦`) so app-created worktrees group- * together in the branch list. Every namespaced draw shares the `wt` segment, so+ * Names are namespaced (`lobehub/<timestamp>-β¦`) so app-created worktrees group+ * together in the branch list. Every namespaced draw shares the `lobehub` segment, so* a ref living there can never be drawn around β that namespace is unusable, and- * the flat `wt-<timestamp>-β¦` form takes over rather than handing the user a+ * the flat `lobehub-<timestamp>-β¦` form takes over rather than handing the user a* name git is guaranteed to refuse.*/export const generateWorktreeBranchName = ({diff --git a/packages/types/src/device.test.ts b/packages/types/src/device.test.tsindex d0f94ff3dc1..1ea8724226f 100644--- a/packages/types/src/device.test.ts+++ b/packages/types/src/device.test.ts@@ -171,12 +171,12 @@ describe('deriveWorktreePath', () => {deriveWorktreePath(sourcePath, 'b', { homeDir: home }).split(/[/\\]/).at(-2) as string;// The folder the worktree modal previews for a generated branch- // (`wt/<timestamp>-<adjective>-<noun>`): the `/` folds to `-`, and the+ // (`lobehub/<timestamp>-<adjective>-<noun>`): the `/` folds to `-`, and the// checkout lands under the central root, keyed by repo name + path hash.it('folds a generated branch into the central worktree root', () => {expect(- deriveWorktreePath('/code/lobehub', 'wt/202610020308-quiet-hill', { homeDir: home }),- ).toBe(`/Users/me/.lobehub/worktrees/${key('/code/lobehub')}/wt-202610020308-quiet-hill`);+ deriveWorktreePath('/code/lobehub', 'lobehub/202610020308-quiet-hill', { homeDir: home }),+ ).toBe(`/Users/me/.lobehub/worktrees/${key('/code/lobehub')}/lobehub-202610020308-quiet-hill`);expect(key('/code/lobehub')).toMatch(/^lobehub-[\da-f]{8}$/);// Trailing separators on either input don't change the result.expect(deriveWorktreePath('/code/lobehub/', 'feat/x', { homeDir: '/Users/me/' })).toBe(@@ -184,11 +184,20 @@ describe('deriveWorktreePath', () => {);});+ // The `lobehub/` namespace of a generated branch survives as the leaf's+ // `lobehub-` prefix; the parent folder is still the repo name + path hash.+ it('keeps the lobehub/ namespace as the lobehub- leaf prefix', () => {+ expect(+ deriveWorktreePath('/code/my-app', 'lobehub/202610020308-quiet-hill', { homeDir: home }),+ ).toBe(`/Users/me/.lobehub/worktrees/${key('/code/my-app')}/lobehub-202610020308-quiet-hill`);+ expect(key('/code/my-app')).toMatch(/^my-app-[\da-f]{8}$/);+ });+it('keeps the source path separator on Windows', () => {const source = 'C:\\code\\lobehub';expect(- deriveWorktreePath(source, 'wt/202610020308-quiet-hill', { homeDir: 'C:\\Users\\me' }),- ).toBe(`C:\\Users\\me\\.lobehub\\worktrees\\${key(source)}\\wt-202610020308-quiet-hill`);+ deriveWorktreePath(source, 'lobehub/202610020308-quiet-hill', { homeDir: 'C:\\Users\\me' }),+ ).toBe(`C:\\Users\\me\\.lobehub\\worktrees\\${key(source)}\\lobehub-202610020308-quiet-hill`);});it('keeps same-named repos at different paths apart', () => {@@ -216,11 +225,11 @@ describe('deriveWorktreePath', () => {// Without a known home (a device that does not report one) the previous// sibling layout is kept, so released devices still get an absolute path.it('falls back to a sibling folder without a home directory', () => {- expect(deriveWorktreePath('/code/lobehub', 'wt/202610020308-quiet-hill')).toBe(- '/code/lobehub-wt-202610020308-quiet-hill',+ expect(deriveWorktreePath('/code/lobehub', 'lobehub/202610020308-quiet-hill')).toBe(+ '/code/lobehub-lobehub-202610020308-quiet-hill',);- expect(deriveWorktreePath('C:\\code\\lobehub', 'wt/x', { homeDir: ' ' })).toBe(- 'C:\\code\\lobehub-wt-x',+ expect(deriveWorktreePath('C:\\code\\lobehub', 'lobehub/x', { homeDir: ' ' })).toBe(+ 'C:\\code\\lobehub-lobehub-x',);expect(deriveWorktreePath('/code/lobehub', '')).toBe('/code/lobehub');});diff --git a/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx b/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsxindex df895684383..6ba0cda45b8 100644--- a/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx+++ b/src/features/ChatInput/ControlBar/WorktreeSwitcher.tsx@@ -541,7 +541,7 @@ const WorktreeSwitcher = memo<WorktreeSwitcherProps>(openCreateWorktreeModal({// The modal reads the repo's full local branch list itself and draws the// generated default from it, so a name is not handed out twice and does- // not collide with a ref on the `wt` namespace path (see+ // not collide with a ref on the `lobehub` namespace path (see// `generateWorktreeBranchName`). It lives there rather than here so the// list can be awaited: snapshotting an in-flight (empty) list would hand// out a name git is guaranteed to refuse.diff --git a/src/features/ChatInput/ControlBar/__tests__/useBranchList.test.ts b/src/features/ChatInput/ControlBar/__tests__/useBranchList.test.tsindex 89c5bc46260..b8c6f0033f6 100644--- a/src/features/ChatInput/ControlBar/__tests__/useBranchList.test.ts+++ b/src/features/ChatInput/ControlBar/__tests__/useBranchList.test.ts@@ -202,7 +202,7 @@ describe('useBranchList', () => {it('draws no worktree name from a persisted list the device has not confirmed', async () => {// A branch made since last session would be missing from this list, and a- // name drawn against it could collide (`refs/heads/wt` blocks `wt/β¦`).+ // name drawn against it could collide (`refs/heads/lobehub` blocks `lobehub/β¦`).await seed([branch('main', true)]);vi.mocked(gitService.listGitBranches).mockImplementation(pending);diff --git a/src/features/ChatInput/ControlBar/__tests__/useWorktreeBranchSeed.test.ts b/src/features/ChatInput/ControlBar/__tests__/useWorktreeBranchSeed.test.tsindex ddb97f07c84..509f786a873 100644--- a/src/features/ChatInput/ControlBar/__tests__/useWorktreeBranchSeed.test.ts+++ b/src/features/ChatInput/ControlBar/__tests__/useWorktreeBranchSeed.test.ts@@ -24,8 +24,8 @@ describe('useWorktreeBranchSeed', () => {// Regression: the default name is drawn against the repo's branch list, and// that list arrives asynchronously. Drawing while the read is still in flight// makes it look like "no branches", so a repo whose refs include a branch- // literally called `wt` was handed `wt/...` and git refused creation with- // `cannot lock ref 'refs/heads/wt/...': 'refs/heads/wt' exists`.+ // literally called `lobehub` was handed `lobehub/...` and git refused creation with+ // `cannot lock ref 'refs/heads/lobehub/...': 'refs/heads/lobehub' exists`.it('hands out no name while the branch list is still being read', () => {listGitBranches.mockImplementation(() => new Promise(() => {}));@@ -35,23 +35,23 @@ describe('useWorktreeBranchSeed', () => {expect(result.current.name).toBeUndefined();});- it('avoids the wt/ namespace once a ref on it has been seen', async () => {- listGitBranches.mockResolvedValue([branch('main'), branch('wt')]);+ it('avoids the lobehub/ namespace once a ref on it has been seen', async () => {+ listGitBranches.mockResolvedValue([branch('main'), branch('lobehub')]);const result = seed('/repo/taken-namespace');await waitFor(() => expect(result.current.isReady).toBe(true));- // Only a list that actually contains `wt` produces the flat form, so this+ // Only a list that actually contains `lobehub` produces the flat form, so this// value proves the occupying ref reached the draw.- expect(result.current.name).toMatch(/^wt-\d{12}-[a-z]+-[a-z]+$/);+ expect(result.current.name).toMatch(/^lobehub-\d{12}-[a-z]+-[a-z]+$/);});- it('keeps the wt/ namespace when nothing occupies it', async () => {+ it('keeps the lobehub/ namespace when nothing occupies it', async () => {listGitBranches.mockResolvedValue([branch('main'), branch('canary')]);const result = seed('/repo/free-namespace');await waitFor(() => expect(result.current.isReady).toBe(true));- expect(result.current.name).toMatch(/^wt\/\d{12}-[a-z]+-[a-z]+$/);+ expect(result.current.name).toMatch(/^lobehub\/\d{12}-[a-z]+-[a-z]+$/);});});diff --git a/src/features/ChatInput/ControlBar/useWorktreeBranchSeed.ts b/src/features/ChatInput/ControlBar/useWorktreeBranchSeed.tsindex 3a59b608280..bb026e3e169 100644--- a/src/features/ChatInput/ControlBar/useWorktreeBranchSeed.ts+++ b/src/features/ChatInput/ControlBar/useWorktreeBranchSeed.ts@@ -17,10 +17,10 @@ export interface WorktreeBranchSeed {* directory's full local branch list.** Waiting for that list to settle is the point of this hook. Git stores refs as- * paths, so a branch literally called `wt` blocks the whole `wt/` namespace β+ * paths, so a branch literally called `lobehub` blocks the whole `lobehub/` namespace β* and a name drawn from a list that is still in flight reads as "no branches",* handing out a ref git is guaranteed to refuse (`cannot lock ref- * 'refs/heads/wt/β¦': 'refs/heads/wt' exists`). The modal snapshots the name when+ * 'refs/heads/lobehub/β¦': 'refs/heads/lobehub' exists`). The modal snapshots the name when* it opens, so a late result could never repair that. For the same reason the* list persisted from an earlier session does not count as settled: it may miss* a branch made since. Shares the branch switcher's replica, so a dropdown