feat(vscode): webview 移交/接管按钮、选人弹窗与待接管角标

Claude-Session: https://claude.ai/code/session_011cEyL6k351U2BzX1Qmygph
This commit is contained in:
2026-08-26 16:41:35 +08:00
parent 6d3720d424
commit 6770570f09
6 changed files with 226 additions and 3 deletions
+25
View File
@@ -2,6 +2,7 @@ import type { PastedImage } from './components/NewIssueModal'
import type { Issue } from './types' import type { Issue } from './types'
import { useEffect, useMemo, useRef, useState } from 'react' import { useEffect, useMemo, useRef, useState } from 'react'
import { BottomTabs } from './components/BottomTabs' import { BottomTabs } from './components/BottomTabs'
import { HandoffModal } from './components/HandoffModal'
import { KanbanBoard } from './components/KanbanBoard' import { KanbanBoard } from './components/KanbanBoard'
import { LogModal } from './components/LogModal' import { LogModal } from './components/LogModal'
import { NewIssueModal } from './components/NewIssueModal' import { NewIssueModal } from './components/NewIssueModal'
@@ -76,6 +77,12 @@ export function App() {
envLockRunning, envLockRunning,
envLockTitle, envLockTitle,
toggleEnvLock, toggleEnvLock,
me,
handoffUsers,
requestHandoffUsers,
startHandoff,
acceptHandoff,
isHandoffRunning,
} = useIssues() } = useIssues()
const { profiles: profileData, saveProfiles, openProfileValue } = useProfiles() const { profiles: profileData, saveProfiles, openProfileValue } = useProfiles()
const { const {
@@ -92,6 +99,7 @@ export function App() {
} = useManagedSessions() } = useManagedSessions()
const [showNewIssueModal, setShowNewIssueModal] = useState(false) const [showNewIssueModal, setShowNewIssueModal] = useState(false)
const [showLogs, setShowLogs] = useState(false) const [showLogs, setShowLogs] = useState(false)
const [handoffIssue, setHandoffIssue] = useState<number | null>(null)
const [selectedId, setSelectedId] = useState<string | null>(null) const [selectedId, setSelectedId] = useState<string | null>(null)
// 程序化设置的选中(反向选中 / pendingSelectId)记在这里,让下面的自动聚焦 // 程序化设置的选中(反向选中 / pendingSelectId)记在这里,让下面的自动聚焦
// effect 跳过它——否则 选中→聚焦→终端激活→反向选中 会死循环、CPU 飙升。 // effect 跳过它——否则 选中→聚焦→终端激活→反向选中 会死循环、CPU 飙升。
@@ -374,6 +382,13 @@ export function App() {
onUpdateBrainstormProfilePath={updateIssueBrainstormProfilePath} onUpdateBrainstormProfilePath={updateIssueBrainstormProfilePath}
onUpdateTestProfilePath={updateIssueTestProfilePath} onUpdateTestProfilePath={updateIssueTestProfilePath}
onOpenLogs={() => setShowLogs(true)} onOpenLogs={() => setShowLogs(true)}
me={me}
onStartHandoff={(n) => {
setHandoffIssue(n)
requestHandoffUsers(n)
}}
onAcceptHandoff={acceptHandoff}
isHandoffRunning={isHandoffRunning}
profileData={profileData} profileData={profileData}
onProfileSave={saveProfiles} onProfileSave={saveProfiles}
onProfileOpen={openProfileValue} onProfileOpen={openProfileValue}
@@ -448,6 +463,16 @@ export function App() {
onSubmit={handleSubmitNewIssue} onSubmit={handleSubmitNewIssue}
profiles={profiles} profiles={profiles}
/> />
<HandoffModal
open={handoffIssue !== null}
issueNumber={handoffIssue}
users={handoffUsers && handoffUsers.issueNumber === handoffIssue ? handoffUsers.users : null}
onCancel={() => setHandoffIssue(null)}
onSubmit={(n, to) => {
startHandoff(n, to)
setHandoffIssue(null)
}}
/>
<LogModal <LogModal
open={showLogs} open={showLogs}
entries={logs} entries={logs}
@@ -50,6 +50,10 @@ interface BottomTabsProps {
onUpdateBrainstormProfilePath: (issueNumber: number, brainstormProfilePath: string) => void onUpdateBrainstormProfilePath: (issueNumber: number, brainstormProfilePath: string) => void
onUpdateTestProfilePath: (issueNumber: number, testProfilePath: string) => void onUpdateTestProfilePath: (issueNumber: number, testProfilePath: string) => void
onOpenLogs: () => void onOpenLogs: () => void
me?: string
onStartHandoff: (issueNumber: number) => void
onAcceptHandoff: (issueNumber: number) => void
isHandoffRunning: (issueNumber: number) => boolean
// Profile tab props // Profile tab props
profileData: ProfilesData profileData: ProfilesData
@@ -138,6 +142,10 @@ export function BottomTabs(props: BottomTabsProps) {
onUpdateTestProfilePath={props.onUpdateTestProfilePath} onUpdateTestProfilePath={props.onUpdateTestProfilePath}
profiles={props.profiles} profiles={props.profiles}
onOpenLogs={props.onOpenLogs} onOpenLogs={props.onOpenLogs}
me={props.me}
onStartHandoff={props.onStartHandoff}
onAcceptHandoff={props.onAcceptHandoff}
isHandoffRunning={props.isHandoffRunning}
/> />
</div> </div>
<div <div
@@ -0,0 +1,89 @@
import { Loader2, X } from 'lucide-react'
import { useEffect, useState } from 'react'
import { SelectMenu } from './ui/select-menu'
interface Props {
open: boolean
issueNumber: number | null
/** null = 候选列表还在加载 */
users: string[] | null
onCancel: () => void
onSubmit: (issueNumber: number, to: string) => void
}
export function HandoffModal({ open, issueNumber, users, onCancel, onSubmit }: Props) {
const [to, setTo] = useState<string>('')
useEffect(() => {
if (!open) {
setTo('')
return
}
function handleKey(e: KeyboardEvent): void {
if (e.key === 'Escape')
onCancel()
}
document.addEventListener('keydown', handleKey)
return () => document.removeEventListener('keydown', handleKey)
}, [open, onCancel])
useEffect(() => {
if (users && users.length > 0 && !to)
setTo(users[0])
}, [users, to])
if (!open || issueNumber === null)
return null
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60">
<div
role="dialog"
aria-modal="true"
className="w-[360px] rounded border border-[var(--vscode-panel-border)] bg-[var(--vscode-editor-background)] p-4 text-sm shadow-lg"
>
<div className="mb-3 flex items-center">
<h2 className="flex-1 font-medium">
#
{issueNumber}
</h2>
<button type="button" onClick={onCancel} aria-label="关闭" className="rounded p-1 hover:bg-white/10">
<X className="size-4" />
</button>
</div>
<p className="mb-3 text-xs opacity-70">
worktree push
</p>
{users === null
? (
<div className="flex items-center gap-2 text-xs opacity-70">
<Loader2 className="size-3.5 animate-spin" />
</div>
)
: users.length === 0
? <div className="text-xs text-red-400"></div>
: (
<SelectMenu
value={to}
options={users.map(u => ({ value: u, label: u }))}
onChange={setTo}
/>
)}
<div className="mt-4 flex justify-end gap-2">
<button type="button" onClick={onCancel} className="rounded border border-[var(--vscode-panel-border)] px-3 py-1 text-xs hover:bg-white/10">
</button>
<button
type="button"
disabled={!to}
onClick={() => onSubmit(issueNumber, to)}
className="rounded bg-[var(--vscode-button-background)] px-3 py-1 text-xs text-[var(--vscode-button-foreground)] disabled:opacity-50"
>
</button>
</div>
</div>
</div>
)
}
@@ -67,6 +67,16 @@ export const IssueCard = forwardRef<HTMLDivElement, IssueCardProps>(
</span> </span>
) )
: null} : null}
{issue.handoffAttachmentId
? (
<span
className="absolute bottom-1 right-1.5 rounded border border-blue-400/50 bg-blue-400/10 px-1 text-[9px] text-blue-400"
title={`${issue.handoffFrom ?? '?'} 已移交,待接管`}
>
</span>
)
: null}
<div className={cn('truncate', locked && 'pr-5')}> <div className={cn('truncate', locked && 'pr-5')}>
<span className="font-mono opacity-60"> <span className="font-mono opacity-60">
{issue.source === 'youtrack' ? issue.externalId : `#${issue.number}`} {issue.source === 'youtrack' ? issue.externalId : `#${issue.number}`}
@@ -1,6 +1,6 @@
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { useMemo, useRef } from 'react' import { useMemo, useRef } from 'react'
import { CircleSlash, ExternalLink, GitMerge, Play, RotateCcw, Terminal, Trash2, X } from 'lucide-react' import { ArrowRightLeft, CircleSlash, Download, ExternalLink, GitMerge, Loader2, Play, RotateCcw, Terminal, Trash2, X } from 'lucide-react'
import type { ClaudeProfile } from '../hooks/useIssues' import type { ClaudeProfile } from '../hooks/useIssues'
import type { Issue, IssueColumn } from '../types' import type { Issue, IssueColumn } from '../types'
import { COLUMN_LABELS, COLUMN_ORDER } from '../types' import { COLUMN_LABELS, COLUMN_ORDER } from '../types'
@@ -90,6 +90,11 @@ interface IssueDetailPanelProps {
onUpdateTestProfilePath: (issueNumber: number, testProfilePath: string) => void onUpdateTestProfilePath: (issueNumber: number, testProfilePath: string) => void
/** Open the in-webview log modal. */ /** Open the in-webview log modal. */
onOpenLogs: () => void onOpenLogs: () => void
/** 当前 Gitea loginundefined = 身份未知(接管按钮不显示)。 */
me?: string
onStartHandoff: (issueNumber: number) => void
onAcceptHandoff: (issueNumber: number) => void
isHandoffRunning: (issueNumber: number) => boolean
} }
/** /**
@@ -128,6 +133,10 @@ export function IssueDetailPanel({
onUpdateBrainstormProfilePath, onUpdateBrainstormProfilePath,
onUpdateTestProfilePath, onUpdateTestProfilePath,
onOpenLogs, onOpenLogs,
me,
onStartHandoff,
onAcceptHandoff,
isHandoffRunning,
}: IssueDetailPanelProps) { }: IssueDetailPanelProps) {
// 前置工单未完成 → 锁定。锁定时禁用"实施"等启动新工作的动作按钮, // 前置工单未完成 → 锁定。锁定时禁用"实施"等启动新工作的动作按钮,
// 但已存在的会话恢复链接保持可用(属于用户已操作过的入口)。 // 但已存在的会话恢复链接保持可用(属于用户已操作过的入口)。
@@ -575,6 +584,36 @@ export function IssueDetailPanel({
avoid acting on a gitea issue of the same number. */} avoid acting on a gitea issue of the same number. */}
{issue.source !== 'youtrack' && ( {issue.source !== 'youtrack' && (
<> <>
{issue.handoffAttachmentId && me !== undefined && (issue.assignees ?? []).includes(me) && (
<button
type="button"
disabled={isHandoffRunning(issue.number)}
onClick={() => onAcceptHandoff(issue.number)}
title={`接管(${issue.handoffFrom ?? '?'} 移交)`}
aria-label="接管"
className="inline-flex shrink-0 items-center gap-1 rounded border border-green-500/60 bg-green-500/10 px-2 py-1 text-xs text-green-500 hover:bg-green-500/20 disabled:opacity-50"
>
{isHandoffRunning(issue.number) ? <Loader2 className="size-3.5 animate-spin" /> : <Download className="size-3.5" />}
</button>
)}
{!issue.handoffAttachmentId && issue.column !== 'done' && (
<button
type="button"
disabled={isHandoffRunning(issue.number)}
onClick={() => onStartHandoff(issue.number)}
title="移交给同事"
aria-label="移交"
className="inline-flex shrink-0 items-center justify-center rounded border border-[var(--vscode-panel-border)] p-1 text-xs text-[var(--vscode-foreground)] hover:border-blue-500/60 hover:bg-blue-500/10 hover:text-blue-500 disabled:opacity-50"
>
{isHandoffRunning(issue.number) ? <Loader2 className="size-3.5 animate-spin" /> : <ArrowRightLeft className="size-3.5" />}
</button>
)}
{issue.handoffAttachmentId && !(me !== undefined && (issue.assignees ?? []).includes(me)) && (
<span className="inline-flex shrink-0 items-center rounded border border-[var(--vscode-panel-border)] px-1.5 py-0.5 text-[10px] opacity-70" title={`${issue.handoffFrom ?? '?'} 已移交,等待 ${(issue.assignees ?? []).join(', ') || '?'} 接管`}>
</span>
)}
{(issue.column === 'in-progress' || issue.column === 'review') && ( {(issue.column === 'in-progress' || issue.column === 'review') && (
<button <button
type="button" type="button"
+54 -2
View File
@@ -283,6 +283,18 @@ export interface UseIssuesResult {
*/ */
pendingSelectId: string | null pendingSelectId: string | null
clearPendingSelect: () => void clearPendingSelect: () => void
/** 当前 Gitea login,来自最近一次 `issues/update`undefined = 身份未知。 */
me: string | undefined
/** 最近一次 `requestHandoffUsers` 的结果;`null` = 仍在加载或尚未请求。 */
handoffUsers: { issueNumber: number, users: string[] } | null
/** 拉取某工单可移交的候选用户列表,结果通过 `handoffUsers` 返回。 */
requestHandoffUsers: (issueNumber: number) => void
/** 发起移交:删本机 worktree、打包会话记录挂到附件、把工单指派给对方。 */
startHandoff: (issueNumber: number, to: string) => void
/** 接管一个待接管工单:拉取移交附件、恢复会话与 worktree。 */
acceptHandoff: (issueNumber: number) => void
/** 是否有移交/接管流程正在该工单上跑,直到扩展端回 `handoff/done` 才清除。 */
isHandoffRunning: (issueNumber: number) => boolean
} }
export function useIssues(): UseIssuesResult { export function useIssues(): UseIssuesResult {
@@ -308,6 +320,10 @@ export function useIssues(): UseIssuesResult {
const [envLockTitle, setEnvLockTitle] = useState<string>('正在检查 .env 锁定状态…') const [envLockTitle, setEnvLockTitle] = useState<string>('正在检查 .env 锁定状态…')
const prDiffSummaryRunningRef = useRef<Set<number>>(new Set()) const prDiffSummaryRunningRef = useRef<Set<number>>(new Set())
const [prDiffSummaryRunning, setPrDiffSummaryRunning] = useState<ReadonlySet<number>>(() => new Set()) const [prDiffSummaryRunning, setPrDiffSummaryRunning] = useState<ReadonlySet<number>>(() => new Set())
const [me, setMe] = useState<string | undefined>(undefined)
const [handoffUsers, setHandoffUsers] = useState<{ issueNumber: number, users: string[] } | null>(null)
const handoffRunningRef = useRef<Set<number>>(new Set())
const [handoffRunning, setHandoffRunning] = useState<Set<number>>(new Set())
const clearPrDiffSummaryRunning = useCallback((issueNumber: number): void => { const clearPrDiffSummaryRunning = useCallback((issueNumber: number): void => {
if (!prDiffSummaryRunningRef.current.delete(issueNumber)) if (!prDiffSummaryRunningRef.current.delete(issueNumber))
@@ -454,6 +470,35 @@ export function useIssues(): UseIssuesResult {
return prDiffSummaryRunning.has(issueNumber) return prDiffSummaryRunning.has(issueNumber)
}, [prDiffSummaryRunning]) }, [prDiffSummaryRunning])
const requestHandoffUsers = useCallback((issueNumber: number): void => {
setHandoffUsers(null)
postMessage({ type: 'handoff/users', issueNumber })
}, [])
const markHandoffRunning = useCallback((issueNumber: number, running: boolean): void => {
if (running)
handoffRunningRef.current.add(issueNumber)
else
handoffRunningRef.current.delete(issueNumber)
setHandoffRunning(new Set(handoffRunningRef.current))
}, [])
const startHandoff = useCallback((issueNumber: number, to: string): void => {
if (handoffRunningRef.current.has(issueNumber))
return
markHandoffRunning(issueNumber, true)
postMessage({ type: 'handoff/start', issueNumber, to })
}, [markHandoffRunning])
const acceptHandoff = useCallback((issueNumber: number): void => {
if (handoffRunningRef.current.has(issueNumber))
return
markHandoffRunning(issueNumber, true)
postMessage({ type: 'handoff/accept', issueNumber })
}, [markHandoffRunning])
const isHandoffRunning = useCallback((issueNumber: number): boolean => handoffRunning.has(issueNumber), [handoffRunning])
const openPr = useCallback((pr: string): void => { const openPr = useCallback((pr: string): void => {
postMessage({ type: 'pr/open', pr }) postMessage({ type: 'pr/open', pr })
}, []) }, [])
@@ -615,6 +660,7 @@ export function useIssues(): UseIssuesResult {
setScope(msg.scope) setScope(msg.scope)
setGlobalAutoReview(msg.globalAutoReview) setGlobalAutoReview(msg.globalAutoReview)
setYoutrackConfigured(msg.youtrackConfigured) setYoutrackConfigured(msg.youtrackConfigured)
setMe(msg.me)
break break
case 'issues/error': case 'issues/error':
setState({ status: 'error', message: msg.message }) setState({ status: 'error', message: msg.message })
@@ -636,6 +682,12 @@ export function useIssues(): UseIssuesResult {
case 'issue/pr-diff-summary-done': case 'issue/pr-diff-summary-done':
clearPrDiffSummaryRunning(msg.issueNumber) clearPrDiffSummaryRunning(msg.issueNumber)
break break
case 'handoff/users-result':
setHandoffUsers({ issueNumber: msg.issueNumber, users: msg.users })
break
case 'handoff/done':
markHandoffRunning(msg.issueNumber, false)
break
case 'issue/remove': case 'issue/remove':
// 工单被删除或关闭 — 从 open issues 数组移除。如果它是当前选中的,挑下一张 // 工单被删除或关闭 — 从 open issues 数组移除。如果它是当前选中的,挑下一张
// 同列的卡片(按该列排序取首张近邻:完成列按合并时间,其余按 number 降序);同列没有则交给 App.tsx 的 // 同列的卡片(按该列排序取首张近邻:完成列按合并时间,其余按 number 降序);同列没有则交给 App.tsx 的
@@ -815,7 +867,7 @@ export function useIssues(): UseIssuesResult {
postMessage({ type: 'branch-sync/check' }) postMessage({ type: 'branch-sync/check' })
postMessage({ type: 'env-lock/check' }) postMessage({ type: 'env-lock/check' })
return cleanup return cleanup
}, [clearPrDiffSummaryRunning]) }, [clearPrDiffSummaryRunning, markHandoffRunning])
return { state, settings, globalAutoReview, youtrackConfigured, importYouTrack, toasts, profiles, setIssues, refresh, scope, toggleScope, saveSettings, listYouTrackProjects, youtrackProjects, dismissSettings, requestEditAuth, createIssue, dismissToast, openUrl, resumeSession, resumeReviewSession, startTestSession, resumeTestSession, focusSession, openFile, implement, generatePrDiffSummary, isPrDiffSummaryRunning, openPr, openWorktree, deleteWorktree, mergeBranch, deleteIssue, closeIssue, closeSessionTab, startBrainstormSession, changeColumn, setDependency, clearDependency, updateIssueAutoReview, updateIssueProfilePath, updateIssueBrainstormProfilePath, updateIssueTestProfilePath, logs, fetchLogs, clearLogs, pendingSelectId, clearPendingSelect, commitRunning, runCommit, hasChanges, branchSyncBehind, branchSyncRunning, branchSyncDisabled, branchSyncTitle, runBranchSync, envLocked, envFileCount, envLockRunning, envLockTitle, toggleEnvLock } return { state, settings, globalAutoReview, youtrackConfigured, importYouTrack, toasts, profiles, setIssues, refresh, scope, toggleScope, saveSettings, listYouTrackProjects, youtrackProjects, dismissSettings, requestEditAuth, createIssue, dismissToast, openUrl, resumeSession, resumeReviewSession, startTestSession, resumeTestSession, focusSession, openFile, implement, generatePrDiffSummary, isPrDiffSummaryRunning, openPr, openWorktree, deleteWorktree, mergeBranch, deleteIssue, closeIssue, closeSessionTab, startBrainstormSession, changeColumn, setDependency, clearDependency, updateIssueAutoReview, updateIssueProfilePath, updateIssueBrainstormProfilePath, updateIssueTestProfilePath, logs, fetchLogs, clearLogs, pendingSelectId, clearPendingSelect, commitRunning, runCommit, hasChanges, branchSyncBehind, branchSyncRunning, branchSyncDisabled, branchSyncTitle, runBranchSync, envLocked, envFileCount, envLockRunning, envLockTitle, toggleEnvLock, me, handoffUsers, requestHandoffUsers, startHandoff, acceptHandoff, isHandoffRunning }
} }