feat: mirror bound conversation task state (completed/pending) onto project cards as glowing green/yellow dots with click-to-ack
This commit is contained in:
@@ -525,6 +525,32 @@ const sessionScopeStore: {
|
||||
snapshot: { sessionId: string; cwd: string; jobs: any[]; subagents: any[] } | null
|
||||
} = { snapshot: null }
|
||||
|
||||
/** 完整会话快照(模块级):项目卡片的任务完成/待决提醒镜像数据源 */
|
||||
const sessionsSnapshotStore: { snapshot: any | null; listeners: Set<() => void> } = { snapshot: null, listeners: new Set() }
|
||||
|
||||
/** 提醒确认(ack)持久化:会话 id → 已确认的状态('done' | 'need') */
|
||||
function loadNotifyAck(): Record<string, string> {
|
||||
try {
|
||||
const raw = localStorage.getItem('dsh.worktable.notifyAck.v1')
|
||||
const p = raw ? JSON.parse(raw) : {}
|
||||
return p && typeof p === 'object' ? p : {}
|
||||
} catch { return {} }
|
||||
}
|
||||
function saveNotifyAck(sid: string, state: string) {
|
||||
try {
|
||||
const ack = loadNotifyAck()
|
||||
ack[sid] = state
|
||||
localStorage.setItem('dsh.worktable.notifyAck.v1', JSON.stringify(ack))
|
||||
} catch {}
|
||||
}
|
||||
/** 会话状态 → 提醒类型:completed=完成(绿) / pendingInteraction=待决(黄) */
|
||||
function sessionNotifyState(entry: any): 'done' | 'need' | null {
|
||||
if (!entry) return null
|
||||
if (entry.completed === true) return 'done'
|
||||
if (entry.pendingInteraction != null) return 'need'
|
||||
return null
|
||||
}
|
||||
|
||||
function syncSessionScope(list: any) {
|
||||
try {
|
||||
const snap = list.getSnapshot()
|
||||
@@ -542,6 +568,11 @@ function syncSessionScope(list: any) {
|
||||
jobs: (snap?.jobsBySession?.[current] ?? []) as any[],
|
||||
subagents,
|
||||
}
|
||||
// 完整快照 + 通知监听(项目卡片提醒镜像)
|
||||
try {
|
||||
sessionsSnapshotStore.snapshot = snap
|
||||
sessionsSnapshotStore.listeners.forEach((l) => { try { l() } catch {} })
|
||||
} catch {}
|
||||
// 项目×对话联动:项目打开期间切到「非该项目绑定」的会话 → 自动关项目(保留用户新选的会话)
|
||||
try {
|
||||
if (current !== lastSessionScopeId) {
|
||||
@@ -605,6 +636,7 @@ function WorktableSection(props: any) {
|
||||
}
|
||||
|
||||
const [view, setView] = useState<ViewState>(loadView)
|
||||
const [notifyTick, setNotifyTick] = useState(0)
|
||||
const [projects, setProjects] = useState<ProjectsState>(loadProjects)
|
||||
const [metas, setMetas] = useState<Record<string, ProjectMeta>>({})
|
||||
const [registeredIds, setRegisteredIds] = useState<string[]>(() => [...registryStore.ids])
|
||||
@@ -925,6 +957,7 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
projectAttachRef.attached = projectsRef.current.projects.bindings[spec.id] ?? prev
|
||||
const bound = projectsRef.current.projects.bindings[spec.id]
|
||||
if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} }
|
||||
ackProjectNotify(spec.id)
|
||||
}
|
||||
}, [projects.views])
|
||||
|
||||
@@ -995,6 +1028,34 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
copyToastTimerRef.current = window.setTimeout(() => setCopiedToast(null), 6000)
|
||||
}
|
||||
|
||||
// 会话快照变化 → 重渲染(驱动项目卡片的完成/待决提醒镜像)
|
||||
useEffect(() => {
|
||||
const l = () => setNotifyTick((t) => t + 1)
|
||||
sessionsSnapshotStore.listeners.add(l)
|
||||
return () => { sessionsSnapshotStore.listeners.delete(l) }
|
||||
}, [])
|
||||
|
||||
/** 项目 → 提醒态:绑定会话 completed=done / pendingInteraction=need(ack 过则不亮) */
|
||||
const bindNotifyMap: Record<string, 'done' | 'need'> = useMemo(() => {
|
||||
const map: Record<string, 'done' | 'need'> = {}
|
||||
const byId = sessionsSnapshotStore.snapshot?.byId ?? {}
|
||||
const ack = loadNotifyAck()
|
||||
for (const [pid, sid] of Object.entries(projects.bindings)) {
|
||||
const state = sessionNotifyState(byId[sid])
|
||||
if (state && ack[sid] !== state) map[pid] = state
|
||||
}
|
||||
return map
|
||||
}, [projects.bindings, notifyTick])
|
||||
|
||||
/** 点开项目 = 确认提醒:ack 当前会话状态,圆点恢复常态实心 */
|
||||
const ackProjectNotify = (projectId: string) => {
|
||||
const sid = projectsRef.current.projects.bindings[projectId]
|
||||
if (!sid) return
|
||||
const byId = sessionsSnapshotStore.snapshot?.byId ?? {}
|
||||
const state = sessionNotifyState(byId[sid])
|
||||
if (state) saveNotifyAck(sid, state)
|
||||
}
|
||||
|
||||
// ── 有效排序 ──
|
||||
// 手动:持久化 order(过滤已卸载 id)→ 新注册 id 与布局 id 追加尾部;
|
||||
// 最近:有 lastUsed 的按时间降序在前,其余按手动序在后。
|
||||
@@ -1287,12 +1348,14 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
}
|
||||
bindBtn.setAttribute('data-wt-bind', id)
|
||||
const bound = projects.bindings[id]
|
||||
bindBtn.setAttribute('data-bound', bound ? 'true' : 'false')
|
||||
bindBtn.setAttribute('data-bound', bindNotifyMap[id] ?? (bound ? 'true' : 'false'))
|
||||
// 入驻卡自带箭头(文本 ›):加统一对齐类,视觉居中(字面框偏下补偿 1px)
|
||||
const kids = Array.from(el.children)
|
||||
const arrow = kids.find((k: any) => k.tagName === 'SPAN' && String((k as HTMLElement).textContent ?? '').trim() === '›')
|
||||
if (arrow) (arrow as HTMLElement).classList.add('dsh-wt_resArrow')
|
||||
const tip = bound ? t('bind.tipBound', { name: boundSessionTitle(bound) }) : t('bind.tipUnbound')
|
||||
const tip = bound
|
||||
? t('bind.tipBound', { name: boundSessionTitle(bound) }) + (bindNotifyMap[id] === 'done' ? t('bind.tipDone') : bindNotifyMap[id] === 'need' ? t('bind.tipNeed') : '')
|
||||
: t('bind.tipUnbound')
|
||||
bindBtn.setAttribute('data-tip', tip)
|
||||
bindBtn.setAttribute('aria-label', tip)
|
||||
const icon = el.children[0] as HTMLElement | null
|
||||
@@ -1321,7 +1384,7 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
const mo = new MutationObserver(sync)
|
||||
mo.observe(document.body, { childList: true, subtree: true })
|
||||
return () => mo.disconnect()
|
||||
}, [aliveRegisteredIds, projects.iconOverrides, projects.views, activeSplitId, projects.bindings])
|
||||
}, [aliveRegisteredIds, projects.iconOverrides, projects.views, activeSplitId, projects.bindings, bindNotifyMap])
|
||||
|
||||
useEffect(() => {
|
||||
const onDocClick = (e: MouseEvent) => {
|
||||
@@ -1360,6 +1423,7 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
// 无视图覆盖:项目自带打开行为照旧,仅当绑定了会话时切换右侧对话窗
|
||||
const bound = projectsRef.current.projects.bindings[pid]
|
||||
if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} }
|
||||
ackProjectNotify(pid)
|
||||
}
|
||||
document.addEventListener('click', onDocClick, true)
|
||||
return () => document.removeEventListener('click', onDocClick, true)
|
||||
@@ -1866,8 +1930,10 @@ function buildCustomLayoutPrompt(req: string): string {
|
||||
className={'dsh-wt_bindBtn'}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
data-bound={projects.bindings[l.id] ? 'true' : 'false'}
|
||||
data-tip={projects.bindings[l.id] ? t('bind.tipBound', { name: boundSessionTitle(projects.bindings[l.id]) }) : t('bind.tipUnbound')}
|
||||
data-bound={bindNotifyMap[l.id] ?? (projects.bindings[l.id] ? 'true' : 'false')}
|
||||
data-tip={projects.bindings[l.id]
|
||||
? t('bind.tipBound', { name: boundSessionTitle(projects.bindings[l.id]) }) + (bindNotifyMap[l.id] === 'done' ? t('bind.tipDone') : bindNotifyMap[l.id] === 'need' ? t('bind.tipNeed') : '')
|
||||
: t('bind.tipUnbound')}
|
||||
aria-label={projects.bindings[l.id] ? t('bind.tipBound', { name: boundSessionTitle(projects.bindings[l.id]) }) : t('bind.tipUnbound')}
|
||||
onClick={(e) => { e.stopPropagation(); openBindPick(l.id, e.currentTarget as HTMLElement) }}
|
||||
><span className="dsh-wt_bindCircles" aria-hidden /></span>
|
||||
@@ -1909,7 +1975,7 @@ export const inject = ['slots', 'locale', 'sessions', 'conversation', 'workspace
|
||||
export function apply(ctx: any) {
|
||||
// 自定义窗口 → 宿主会话桥:保存 sessions/conversation/list 服务引用(模块级)
|
||||
sessionBridge = { sessions: ctx.sessions ?? null, conversation: ctx.conversation ?? null, list: ctx.sessions?.list ?? null, workspaces: ctx.workspaces ?? null }
|
||||
try { (window as any).__dshOpenSession = (id: string) => ctx.sessions?.open?.(id); (window as any).__dshSessions = ctx.sessions; (window as any).__dshPromptIntoSession = (id: string, text: string) => promptIntoSession(id, text); (window as any).__dshWorkspaces = ctx.workspaces; (window as any).__dshBuildWindowTaskText = buildWindowTaskText } catch {}
|
||||
try { (window as any).__dshOpenSession = (id: string) => ctx.sessions?.open?.(id); (window as any).__dshSessions = ctx.sessions; (window as any).__dshPromptIntoSession = (id: string, text: string) => promptIntoSession(id, text); (window as any).__dshWorkspaces = ctx.workspaces; (window as any).__dshBuildWindowTaskText = buildWindowTaskText; (window as any).__dshSyncSessionScope = () => syncSessionScope(sessionBridge?.list) } catch {}
|
||||
|
||||
|
||||
ctx.effect(() => {
|
||||
|
||||
@@ -93,6 +93,8 @@ export const zh = {
|
||||
'bind.titleUnbound': '绑定对话(未绑定 ○○):点击选择要跟随的对话',
|
||||
'bind.titleBound': '已绑定对话(●●):点击更换或解绑',
|
||||
'bind.tipUnbound': '未绑定对话:点击选择要跟随的对话',
|
||||
'bind.tipDone': '(任务已完成,点击项目查看)',
|
||||
'bind.tipNeed': '(需要你的决定,点击项目处理)',
|
||||
'bind.folder': '项目文件夹',
|
||||
'bind.folderChange': '更改',
|
||||
'bind.folderNone': '未设置(建议设置:项目产出文件都会放进这里)',
|
||||
@@ -223,6 +225,8 @@ export const en = {
|
||||
'bind.titleUnbound': 'Bind conversation (unbound ○○): pick the conversation to follow',
|
||||
'bind.titleBound': 'Conversation bound (●●): click to change or unbind',
|
||||
'bind.tipUnbound': 'No conversation bound — click to pick one',
|
||||
'bind.tipDone': ' (task completed — click the project to view)',
|
||||
'bind.tipNeed': ' (needs your decision — click the project to handle)',
|
||||
'bind.folder': 'Project folder',
|
||||
'bind.folderChange': 'Change',
|
||||
'bind.folderNone': 'Not set (recommended: project outputs go here)',
|
||||
|
||||
@@ -159,13 +159,17 @@ export const css = [
|
||||
'.dsh-wt_bindBtn{position:absolute;right:26px;top:50%;transform:translateY(-50%);width:22px;height:22px;margin:0;display:block;border-radius:6px;color:var(--dsw-alias-label-secondary,#9aa4b2);cursor:pointer;user-select:none}',
|
||||
'.dsh-wt_bindBtn:hover{background:var(--dsw-alias-fill-l2,rgba(255,255,255,.09));color:var(--dsw-alias-label-primary,#e6e8eb)}',
|
||||
'.dsh-wt_bindBtn[data-bound=true]{color:var(--dsw-alias-label-primary,#e6e8eb)}',
|
||||
// 任务完成提醒镜像:绿色发光 / 待决提醒:黄色发光(点击项目即 ack 恢复常态实心)
|
||||
'.dsh-wt_bindBtn[data-bound=done]{color:#3fb950}',
|
||||
'.dsh-wt_bindBtn[data-bound=need]{color:#d29922}',
|
||||
'.dsh-wt_bindBtn[data-bound=done] .dsh-wt_bindCircles,.dsh-wt_bindBtn[data-bound=need] .dsh-wt_bindCircles{filter:drop-shadow(0 0 3px currentColor)}',
|
||||
// 气泡为 body 级独立元素(.dsh-wt_bindTip),此处只保留按钮本体样式
|
||||
'.dsh-wt_bindTip{position:fixed;transform:translateY(-50%);padding:5px 9px;border:1px solid var(--dsw-alias-border-l2,#3a4150);border-radius:6px;background:var(--dsw-alias-fill-l2,#171b22);color:var(--dsw-alias-label-primary,#e6e8eb);font-size:11px;line-height:15px;white-space:nowrap;pointer-events:none;z-index:1200;box-shadow:0 4px 12px rgba(0,0,0,.35);display:none}',
|
||||
'.dsh-wt_bindCircles{position:absolute;left:50%;top:50%;width:17px;height:7px;transform:translate(-50%,-50%)}',
|
||||
'.dsh-wt_bindCircles::before,.dsh-wt_bindCircles::after{content:\'\';position:absolute;top:50%;width:6px;height:6px;margin-top:-3px;border-radius:50%;box-sizing:border-box;border:1.2px solid currentColor;background:transparent}',
|
||||
'.dsh-wt_bindCircles::before{left:0}',
|
||||
'.dsh-wt_bindCircles::after{left:10px}',
|
||||
'.dsh-wt_bindBtn[data-bound=true] .dsh-wt_bindCircles::before,.dsh-wt_bindBtn[data-bound=true] .dsh-wt_bindCircles::after{background:currentColor}',
|
||||
'.dsh-wt_bindBtn[data-bound=true] .dsh-wt_bindCircles::before,.dsh-wt_bindBtn[data-bound=true] .dsh-wt_bindCircles::after,.dsh-wt_bindBtn[data-bound=done] .dsh-wt_bindCircles::before,.dsh-wt_bindBtn[data-bound=done] .dsh-wt_bindCircles::after,.dsh-wt_bindBtn[data-bound=need] .dsh-wt_bindCircles::before,.dsh-wt_bindBtn[data-bound=need] .dsh-wt_bindCircles::after{background:currentColor}',
|
||||
|
||||
// 布局条目卡片
|
||||
'.dsh-wt_layout{display:flex;align-items:center;gap:7px;padding:6px 8px;border:1px solid var(--dsw-alias-border-l1,#262b36);border-radius:8px;background:var(--dsw-alias-fill-l1,rgba(255,255,255,.02));color:var(--dsw-alias-label-primary,#e6e8eb);font:inherit;font-size:12px;line-height:18px;cursor:pointer;text-align:left}',
|
||||
|
||||
Reference in New Issue
Block a user