diff --git a/src/renderer/src/components/GitHubItemDialog.tsx b/src/renderer/src/components/GitHubItemDialog.tsx
index e3c6fb476..a598e2544 100644
--- a/src/renderer/src/components/GitHubItemDialog.tsx
+++ b/src/renderer/src/components/GitHubItemDialog.tsx
@@ -25,6 +25,7 @@ import {
Copy,
ExternalLink,
FileText,
+ FolderKanban,
GitMerge,
GitPullRequest,
GitPullRequestClosed,
@@ -34,6 +35,7 @@ import {
MessageSquarePlus,
PanelLeftOpen,
Pencil,
+ Plus,
RefreshCw,
Send,
UndoDot,
@@ -102,6 +104,7 @@ import {
type PRCommentGroup
} from '@/lib/pr-comment-groups'
import { useAppStore } from '@/store'
+import { useAllWorktrees } from '@/store/selectors'
import { callRuntimeRpc, getActiveRuntimeTarget } from '@/runtime/runtime-rpc-client'
import { useRepoLabels, useRepoAssignees, useImmediateMutation } from '@/hooks/useIssueMetadata'
import { useRepoLabelsBySlug, useRepoAssigneesBySlug } from '@/hooks/useGitHubSlugMetadata'
@@ -115,6 +118,11 @@ import { AGENT_CATALOG } from '@/lib/agent-catalog'
import { filterEnabledTuiAgents } from '../../../shared/tui-agent-selection'
import { getConnectionId } from '@/lib/connection-context'
import { focusTerminalTabSurface } from '@/lib/focus-terminal-tab-surface'
+import {
+ findGithubIssueWorkspaceAttachment,
+ findGithubPrWorkspaceAttachment,
+ getGithubWorkItemWorkspaceAttachmentLabel
+} from '@/lib/github-work-item-workspace-attachment'
import { launchAgentInNewTab } from '@/lib/launch-agent-in-new-tab'
import { launchWorkItemDirect } from '@/lib/launch-work-item-direct'
import { activateAndRevealWorktree } from '@/lib/worktree-activation'
@@ -132,8 +140,7 @@ import type {
PRCheckDetail,
PRCheckRunDetails,
PRComment,
- TuiAgent,
- Worktree
+ TuiAgent
} from '../../../shared/types'
import { PER_REPO_FETCH_LIMIT } from '../../../shared/work-items'
@@ -3317,19 +3324,6 @@ function buildFixBrokenChecksPrompt(item: GitHubWorkItem, checks: PRCheckDetail[
].join('\n')
}
-function findWorkspaceAttachedToPR(
- worktrees: Worktree[],
- repoId: string,
- prNumber: number
-): Worktree | null {
- return (
- worktrees.find(
- (worktree) =>
- worktree.repoId === repoId && worktree.linkedPR === prNumber && !worktree.isArchived
- ) ?? null
- )
-}
-
function pickDefaultAgent(
defaultAgent: TuiAgent | 'blank' | null | undefined,
detectedAgents: TuiAgent[],
@@ -3498,7 +3492,7 @@ function ChecksTab({
try {
const prompt = buildFixBrokenChecksPrompt(item, list)
const store = useAppStore.getState()
- const attachedWorkspace = findWorkspaceAttachedToPR(
+ const attachedWorkspace = findGithubPrWorkspaceAttachment(
store.allWorktrees(),
targetRepoId,
item.number
@@ -4352,6 +4346,8 @@ function GHEditSection({
onMutated,
assignees,
onUse,
+ onOpenOrUse,
+ attachedWorkspaceLabel,
layout = 'horizontal'
}: {
item: GitHubWorkItem
@@ -4368,6 +4364,8 @@ function GHEditSection({
onMutated: () => void
assignees: string[]
onUse: (item: GitHubWorkItem) => void
+ onOpenOrUse?: (item: GitHubWorkItem) => void
+ attachedWorkspaceLabel?: string | null
/** `'horizontal'` is the legacy strip rendered above the conversation; the
* `'sidebar'` layout matches the GitHub issue page's right rail with each
* metadata row stacked under a section heading. */
@@ -4412,6 +4410,15 @@ function GHEditSection({
)
const repoAssigneesBySlug = useRepoAssigneesBySlug(slugOwner, slugRepo, assignees)
const repoAssignees = projectOrigin ? repoAssigneesBySlug : repoAssigneesByPath
+ const hasAttachedWorkspace =
+ attachedWorkspaceLabel !== null && attachedWorkspaceLabel !== undefined
+ const handleOpenOrUseWorkspace = useCallback((): void => {
+ if (onOpenOrUse) {
+ onOpenOrUse(item)
+ return
+ }
+ onUse(item)
+ }, [item, onOpenOrUse, onUse])
// Why: sync local assignees when item changes or when the detail fetch
// resolves with real data — but skip if the user already made an
@@ -4846,6 +4853,56 @@ function GHEditSection({
)}
+
+
+
+ Workspace
+
+ {attachedWorkspaceLabel ? (
+
+
+ {attachedWorkspaceLabel}
+
+ ) : null}
+ {hasAttachedWorkspace ? (
+
+
+
+
+
+
+
+
+ onUse(item)}>
+
+ Start new workspace
+
+
+
+ ) : (
+
+ )}
+
)
}
@@ -5011,15 +5068,52 @@ function GHEditSection({
-
+
+ {attachedWorkspaceLabel ? (
+
+
+ {attachedWorkspaceLabel}
+
+ ) : null}
+ {hasAttachedWorkspace ? (
+
+
+
+
+
+
+
+
+ onUse(item)}>
+
+ Start new workspace
+
+
+
+ ) : (
+
+ )}
+
)
}
@@ -5224,6 +5318,37 @@ export default function GitHubItemDialog({
const workItemState = workItem?.state
const workItemLabels = workItem?.labels
const effectiveRepoId = repoId ?? workItem?.repoId ?? null
+ const allWorktrees = useAllWorktrees()
+ const issueAttachedWorkspace = useMemo(
+ () =>
+ workItem?.type === 'issue'
+ ? findGithubIssueWorkspaceAttachment(allWorktrees, effectiveRepoId, workItem.number)
+ : null,
+ [allWorktrees, effectiveRepoId, workItem]
+ )
+ const issueAttachedWorkspaceLabel = issueAttachedWorkspace
+ ? getGithubWorkItemWorkspaceAttachmentLabel(issueAttachedWorkspace)
+ : null
+
+ const handleOpenOrUseIssueWorkspace = useCallback(
+ (item: GitHubWorkItem): void => {
+ const currentAttached = findGithubIssueWorkspaceAttachment(
+ useAppStore.getState().allWorktrees(),
+ effectiveRepoId,
+ item.number
+ )
+ if (!currentAttached) {
+ onUse(item)
+ return
+ }
+
+ const result = activateAndRevealWorktree(currentAttached.id)
+ if (result === false) {
+ toast.error('Unable to open the workspace attached to this issue.')
+ }
+ },
+ [effectiveRepoId, onUse]
+ )
// Why: the cache key has to include the issue source preference so a user
// toggling between origin/upstream for the same issue number doesn't read
@@ -5687,16 +5812,52 @@ export default function GitHubItemDialog({
{/* Why: Orca's signature affordance — keep this primary so it
stands out against GitHub's familiar surface. */}
-
+ {issueAttachedWorkspace ? (
+
+
+
+
+
+
+
+
+ onUse(workItem)}>
+
+ Start new workspace
+
+ window.api.shell.openUrl(workItem.url)}>
+
+ Open on GitHub
+
+
+
+ ) : (
+
+ )}
@@ -5723,6 +5884,12 @@ export default function GitHubItemDialog({
+ {issueAttachedWorkspaceLabel ? (
+
+
+ {issueAttachedWorkspaceLabel}
+
+ ) : null}
>
@@ -5762,6 +5929,12 @@ export default function GitHubItemDialog({
{workItem.branchName}
)}
+ {issueAttachedWorkspaceLabel ? (
+
+
+ {issueAttachedWorkspaceLabel}
+
+ ) : null}
{workItem.type === 'issue' && (
@@ -5865,6 +6038,8 @@ export default function GitHubItemDialog({
}}
assignees={details?.assignees ?? []}
onUse={onUse}
+ onOpenOrUse={handleOpenOrUseIssueWorkspace}
+ attachedWorkspaceLabel={issueAttachedWorkspaceLabel}
/>
)}
@@ -5947,6 +6122,8 @@ export default function GitHubItemDialog({
}}
assignees={details?.assignees ?? []}
onUse={onUse}
+ onOpenOrUse={handleOpenOrUseIssueWorkspace}
+ attachedWorkspaceLabel={issueAttachedWorkspaceLabel}
layout="sidebar"
/>
diff --git a/src/renderer/src/components/PullRequestPage.tsx b/src/renderer/src/components/PullRequestPage.tsx
index ed8a93cc5..6de0c166b 100644
--- a/src/renderer/src/components/PullRequestPage.tsx
+++ b/src/renderer/src/components/PullRequestPage.tsx
@@ -119,7 +119,7 @@ import { focusTerminalTabSurface } from '@/lib/focus-terminal-tab-surface'
import {
findGithubPrWorkspaceAttachment,
getGithubPrWorkspaceAttachmentLabel
-} from '@/lib/github-pr-workspace-attachment'
+} from '@/lib/github-work-item-workspace-attachment'
import { launchAgentInNewTab } from '@/lib/launch-agent-in-new-tab'
import { launchWorkItemDirect } from '@/lib/launch-work-item-direct'
import { activateAndRevealWorktree } from '@/lib/worktree-activation'
diff --git a/src/renderer/src/components/TaskPage.tsx b/src/renderer/src/components/TaskPage.tsx
index 3408e8920..2586e90ef 100644
--- a/src/renderer/src/components/TaskPage.tsx
+++ b/src/renderer/src/components/TaskPage.tsx
@@ -100,9 +100,9 @@ import {
import PRFilterDropdowns, { type PRFilterChange } from '@/components/github/PRFilterDropdowns'
import { buildGitHubRepoUrl, parseGitHubIssueOrPRLink } from '@/lib/github-links'
import {
- findGithubPrWorkspaceAttachment,
- getGithubPrWorkspaceAttachmentLabel
-} from '@/lib/github-pr-workspace-attachment'
+ findGithubWorkItemWorkspaceAttachment,
+ getGithubWorkItemWorkspaceAttachmentLabel
+} from '@/lib/github-work-item-workspace-attachment'
import { activateAndRevealWorktree } from '@/lib/worktree-activation'
import { useRepoAssigneesBySlug } from '@/hooks/useGitHubSlugMetadata'
import GitHubItemDialog, { type ItemDialogTab } from '@/components/GitHubItemDialog'
@@ -3801,11 +3801,12 @@ export default function TaskPage(): React.JSX.Element {
[openComposerForItem]
)
- const handleOpenOrUseGitHubPR = useCallback(
+ const handleOpenOrUseGitHubWorkItem = useCallback(
(item: GitHubWorkItem): void => {
- const currentAttached = findGithubPrWorkspaceAttachment(
+ const currentAttached = findGithubWorkItemWorkspaceAttachment(
useAppStore.getState().allWorktrees(),
item.repoId,
+ item.type,
item.number
)
if (!currentAttached) {
@@ -3815,7 +3816,11 @@ export default function TaskPage(): React.JSX.Element {
const result = activateAndRevealWorktree(currentAttached.id)
if (result === false) {
- toast.error('Unable to open the workspace attached to this pull request.')
+ toast.error(
+ item.type === 'pr'
+ ? 'Unable to open the workspace attached to this pull request.'
+ : 'Unable to open the workspace attached to this issue.'
+ )
}
},
[handleUseWorkItem]
@@ -5173,12 +5178,14 @@ export default function TaskPage(): React.JSX.Element {
{!showGitHubTaskSkeletons &&
filteredWorkItems.map((item) => {
const itemRepo = repoMap.get(item.repoId) ?? null
- const attachedWorkspace =
- item.type === 'pr'
- ? findGithubPrWorkspaceAttachment(allWorktrees, item.repoId, item.number)
- : null
+ const attachedWorkspace = findGithubWorkItemWorkspaceAttachment(
+ allWorktrees,
+ item.repoId,
+ item.type,
+ item.number
+ )
const attachedWorkspaceLabel = attachedWorkspace
- ? getGithubPrWorkspaceAttachmentLabel(attachedWorkspace)
+ ? getGithubWorkItemWorkspaceAttachmentLabel(attachedWorkspace)
: null
return (
// Why: the row is a clickable container rather than a
@@ -5334,7 +5341,7 @@ export default function TaskPage(): React.JSX.Element {
size="xs"
onClick={(event) => {
event.stopPropagation()
- handleOpenOrUseGitHubPR(item)
+ handleOpenOrUseGitHubWorkItem(item)
}}
className={cn(
'min-w-[72px] gap-1 font-semibold',
@@ -5387,11 +5394,16 @@ export default function TaskPage(): React.JSX.Element {
type="button"
onClick={(event) => {
event.stopPropagation()
- handleUseWorkItem(item)
+ handleOpenOrUseGitHubWorkItem(item)
}}
+ aria-label={
+ attachedWorkspace
+ ? 'Open workspace attached to issue'
+ : 'Start workspace from issue'
+ }
className="inline-flex items-center gap-1 rounded-md border border-border/50 bg-background/80 px-2 py-1 text-[11px] text-foreground transition hover:bg-muted/60"
>
- Start
+ {attachedWorkspace ? 'Open' : 'Start'}
)}
@@ -5411,6 +5423,12 @@ export default function TaskPage(): React.JSX.Element {
align="end"
onClick={(e) => e.stopPropagation()}
>
+ {attachedWorkspace ? (
+ handleUseWorkItem(item)}>
+
+ Start new workspace
+
+ ) : null}
window.api.shell.openUrl(item.url)}
>
diff --git a/src/renderer/src/lib/github-pr-workspace-attachment.test.ts b/src/renderer/src/lib/github-pr-workspace-attachment.test.ts
deleted file mode 100644
index efc29c42a..000000000
--- a/src/renderer/src/lib/github-pr-workspace-attachment.test.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import { describe, expect, it } from 'vitest'
-
-import {
- findGithubPrWorkspaceAttachment,
- getGithubPrWorkspaceAttachmentLabel
-} from './github-pr-workspace-attachment'
-import type { Worktree } from '../../../shared/types'
-
-function worktree(overrides: Partial = {}): Worktree {
- return {
- id: overrides.id ?? 'wt-1',
- repoId: overrides.repoId ?? 'repo-1',
- path: overrides.path ?? '/tmp/repo-1/wt-1',
- head: 'abc123',
- branch: overrides.branch ?? 'refs/heads/feature/pr-workspace',
- isBare: false,
- isMainWorktree: false,
- displayName: overrides.displayName ?? 'PR workspace',
- comment: '',
- linkedIssue: null,
- linkedPR: null,
- linkedLinearIssue: null,
- isArchived: false,
- isUnread: false,
- isPinned: false,
- sortOrder: 0,
- lastActivityAt: 0,
- ...overrides
- }
-}
-
-describe('github PR workspace attachment', () => {
- it('finds the first non-archived workspace linked to the repo PR', () => {
- const first = worktree({ id: 'first', linkedPR: 42 })
- const second = worktree({ id: 'second', linkedPR: 42 })
-
- expect(findGithubPrWorkspaceAttachment([first, second], 'repo-1', 42)).toBe(first)
- })
-
- it('does not match workspaces from a different repo', () => {
- const attachedElsewhere = worktree({ repoId: 'repo-2', linkedPR: 42 })
-
- expect(findGithubPrWorkspaceAttachment([attachedElsewhere], 'repo-1', 42)).toBeNull()
- })
-
- it('does not match archived workspaces', () => {
- const archived = worktree({ linkedPR: 42, isArchived: true })
-
- expect(findGithubPrWorkspaceAttachment([archived], 'repo-1', 42)).toBeNull()
- })
-
- it('returns null when no GitHub PR attachment exists', () => {
- const unlinked = worktree({ linkedPR: null })
-
- expect(findGithubPrWorkspaceAttachment([unlinked], 'repo-1', 42)).toBeNull()
- })
-
- it('does not treat GitLab MR metadata as a GitHub PR attachment', () => {
- const gitlabOnly = worktree({ linkedPR: null, linkedGitLabMR: 42 })
-
- expect(findGithubPrWorkspaceAttachment([gitlabOnly], 'repo-1', 42)).toBeNull()
- })
-
- it('labels attachments without exposing a full path when display or branch is available', () => {
- expect(getGithubPrWorkspaceAttachmentLabel(worktree({ displayName: ' Named PR ' }))).toBe(
- 'Named PR'
- )
- expect(
- getGithubPrWorkspaceAttachmentLabel(
- worktree({ displayName: '', branch: 'refs/heads/fix-ci' })
- )
- ).toBe('fix-ci')
- expect(
- getGithubPrWorkspaceAttachmentLabel(
- worktree({ displayName: '', branch: '', path: 'C:\\repo\\workspace-tail' })
- )
- ).toBe('workspace-tail')
- })
-})
diff --git a/src/renderer/src/lib/github-pr-workspace-attachment.ts b/src/renderer/src/lib/github-pr-workspace-attachment.ts
deleted file mode 100644
index d820f5ba3..000000000
--- a/src/renderer/src/lib/github-pr-workspace-attachment.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import type { Worktree } from '../../../shared/types'
-import { basename } from './path'
-
-export function findGithubPrWorkspaceAttachment(
- worktrees: readonly Worktree[],
- repoId: string | null | undefined,
- prNumber: number
-): Worktree | null {
- if (!repoId) {
- return null
- }
-
- return (
- worktrees.find(
- (worktree) =>
- worktree.repoId === repoId && worktree.linkedPR === prNumber && !worktree.isArchived
- ) ?? null
- )
-}
-
-export function getGithubPrWorkspaceAttachmentLabel(worktree: Worktree): string {
- const displayName = worktree.displayName.trim()
- if (displayName) {
- return displayName
- }
-
- const branch = getBranchLabel(worktree.branch)
- if (branch) {
- return branch
- }
-
- return basename(worktree.path) || worktree.path
-}
-
-function getBranchLabel(branch: string | null | undefined): string | null {
- const trimmed = branch?.trim()
- if (!trimmed) {
- return null
- }
-
- if (trimmed.startsWith('refs/heads/')) {
- return trimmed.slice('refs/heads/'.length)
- }
-
- return trimmed
-}
diff --git a/src/renderer/src/lib/github-work-item-workspace-attachment.test.ts b/src/renderer/src/lib/github-work-item-workspace-attachment.test.ts
new file mode 100644
index 000000000..f0cae1ba2
--- /dev/null
+++ b/src/renderer/src/lib/github-work-item-workspace-attachment.test.ts
@@ -0,0 +1,114 @@
+import { describe, expect, it } from 'vitest'
+
+import {
+ findGithubIssueWorkspaceAttachment,
+ findGithubPrWorkspaceAttachment,
+ findGithubWorkItemWorkspaceAttachment,
+ getGithubWorkItemWorkspaceAttachmentLabel,
+ getGithubPrWorkspaceAttachmentLabel
+} from './github-work-item-workspace-attachment'
+import type { Worktree } from '../../../shared/types'
+
+function worktree(overrides: Partial = {}): Worktree {
+ return {
+ id: overrides.id ?? 'wt-1',
+ repoId: overrides.repoId ?? 'repo-1',
+ path: overrides.path ?? '/tmp/repo-1/wt-1',
+ head: 'abc123',
+ branch: overrides.branch ?? 'refs/heads/feature/workspace-attachment',
+ isBare: false,
+ isMainWorktree: false,
+ displayName: overrides.displayName ?? 'GitHub workspace',
+ comment: '',
+ linkedIssue: null,
+ linkedPR: null,
+ linkedLinearIssue: null,
+ isArchived: false,
+ isUnread: false,
+ isPinned: false,
+ sortOrder: 0,
+ lastActivityAt: 0,
+ ...overrides
+ }
+}
+
+describe('GitHub work-item workspace attachment', () => {
+ it('finds the first non-archived workspace linked to the repo PR', () => {
+ const first = worktree({ id: 'first', linkedPR: 42 })
+ const second = worktree({ id: 'second', linkedPR: 42 })
+
+ expect(findGithubPrWorkspaceAttachment([first, second], 'repo-1', 42)).toBe(first)
+ })
+
+ it('finds the first non-archived workspace linked to the repo issue', () => {
+ const first = worktree({ id: 'first', linkedIssue: 42 })
+ const second = worktree({ id: 'second', linkedIssue: 42 })
+
+ expect(findGithubIssueWorkspaceAttachment([first, second], 'repo-1', 42)).toBe(first)
+ })
+
+ it('matches PRs and issues through the generic helper', () => {
+ const pr = worktree({ id: 'pr', linkedPR: 42 })
+ const issue = worktree({ id: 'issue', linkedIssue: 42 })
+
+ expect(findGithubWorkItemWorkspaceAttachment([issue, pr], 'repo-1', 'pr', 42)).toBe(pr)
+ expect(findGithubWorkItemWorkspaceAttachment([pr, issue], 'repo-1', 'issue', 42)).toBe(issue)
+ })
+
+ it('does not match workspaces from a different repo', () => {
+ const attachedElsewhere = worktree({ repoId: 'repo-2', linkedIssue: 42, linkedPR: 42 })
+
+ expect(findGithubPrWorkspaceAttachment([attachedElsewhere], 'repo-1', 42)).toBeNull()
+ expect(findGithubIssueWorkspaceAttachment([attachedElsewhere], 'repo-1', 42)).toBeNull()
+ })
+
+ it('does not match archived workspaces', () => {
+ const archived = worktree({ linkedIssue: 42, linkedPR: 42, isArchived: true })
+
+ expect(findGithubPrWorkspaceAttachment([archived], 'repo-1', 42)).toBeNull()
+ expect(findGithubIssueWorkspaceAttachment([archived], 'repo-1', 42)).toBeNull()
+ })
+
+ it('returns null when no repo ID is available', () => {
+ const attached = worktree({ linkedIssue: 42, linkedPR: 42 })
+
+ expect(findGithubPrWorkspaceAttachment([attached], null, 42)).toBeNull()
+ expect(findGithubIssueWorkspaceAttachment([attached], undefined, 42)).toBeNull()
+ })
+
+ it('does not cross-match PR and issue slots with the same number', () => {
+ const prOnly = worktree({ id: 'pr', linkedPR: 42 })
+ const issueOnly = worktree({ id: 'issue', linkedIssue: 42 })
+
+ expect(findGithubIssueWorkspaceAttachment([prOnly], 'repo-1', 42)).toBeNull()
+ expect(findGithubPrWorkspaceAttachment([issueOnly], 'repo-1', 42)).toBeNull()
+ })
+
+ it('does not treat GitLab metadata as a GitHub work-item attachment', () => {
+ const gitlabOnly = worktree({
+ linkedIssue: null,
+ linkedPR: null,
+ linkedGitLabIssue: 42,
+ linkedGitLabMR: 42
+ })
+
+ expect(findGithubPrWorkspaceAttachment([gitlabOnly], 'repo-1', 42)).toBeNull()
+ expect(findGithubIssueWorkspaceAttachment([gitlabOnly], 'repo-1', 42)).toBeNull()
+ })
+
+ it('labels attachments without exposing a full path when display or branch is available', () => {
+ expect(
+ getGithubWorkItemWorkspaceAttachmentLabel(worktree({ displayName: ' Named GH ' }))
+ ).toBe('Named GH')
+ expect(
+ getGithubWorkItemWorkspaceAttachmentLabel(
+ worktree({ displayName: '', branch: 'refs/heads/fix-ci' })
+ )
+ ).toBe('fix-ci')
+ expect(
+ getGithubPrWorkspaceAttachmentLabel(
+ worktree({ displayName: '', branch: '', path: 'C:\\repo\\workspace-tail' })
+ )
+ ).toBe('workspace-tail')
+ })
+})
diff --git a/src/renderer/src/lib/github-work-item-workspace-attachment.ts b/src/renderer/src/lib/github-work-item-workspace-attachment.ts
new file mode 100644
index 000000000..a3ac4e3d9
--- /dev/null
+++ b/src/renderer/src/lib/github-work-item-workspace-attachment.ts
@@ -0,0 +1,72 @@
+import type { GitHubWorkItem, Worktree } from '../../../shared/types'
+import { basename } from './path'
+
+type GitHubWorkItemType = GitHubWorkItem['type']
+
+export function findGithubWorkItemWorkspaceAttachment(
+ worktrees: readonly Worktree[],
+ repoId: string | null | undefined,
+ type: GitHubWorkItemType,
+ number: number
+): Worktree | null {
+ if (!repoId) {
+ return null
+ }
+
+ return (
+ worktrees.find((worktree) => {
+ if (worktree.repoId !== repoId || worktree.isArchived) {
+ return false
+ }
+
+ return type === 'pr' ? worktree.linkedPR === number : worktree.linkedIssue === number
+ }) ?? null
+ )
+}
+
+export function findGithubPrWorkspaceAttachment(
+ worktrees: readonly Worktree[],
+ repoId: string | null | undefined,
+ prNumber: number
+): Worktree | null {
+ return findGithubWorkItemWorkspaceAttachment(worktrees, repoId, 'pr', prNumber)
+}
+
+export function findGithubIssueWorkspaceAttachment(
+ worktrees: readonly Worktree[],
+ repoId: string | null | undefined,
+ issueNumber: number
+): Worktree | null {
+ return findGithubWorkItemWorkspaceAttachment(worktrees, repoId, 'issue', issueNumber)
+}
+
+export function getGithubWorkItemWorkspaceAttachmentLabel(worktree: Worktree): string {
+ const displayName = worktree.displayName.trim()
+ if (displayName) {
+ return displayName
+ }
+
+ const branch = getBranchLabel(worktree.branch)
+ if (branch) {
+ return branch
+ }
+
+ return basename(worktree.path) || worktree.path
+}
+
+export function getGithubPrWorkspaceAttachmentLabel(worktree: Worktree): string {
+ return getGithubWorkItemWorkspaceAttachmentLabel(worktree)
+}
+
+function getBranchLabel(branch: string | null | undefined): string | null {
+ const trimmed = branch?.trim()
+ if (!trimmed) {
+ return null
+ }
+
+ if (trimmed.startsWith('refs/heads/')) {
+ return trimmed.slice('refs/heads/'.length)
+ }
+
+ return trimmed
+}