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:
Aisland
2026-08-19 22:30:25 +08:00
parent 9975e889f8
commit ca88b6840d
8 changed files with 266 additions and 7 deletions
+72 -6
View File
@@ -525,6 +525,32 @@ const sessionScopeStore: {
snapshot: { sessionId: string; cwd: string; jobs: any[]; subagents: any[] } | null snapshot: { sessionId: string; cwd: string; jobs: any[]; subagents: any[] } | null
} = { snapshot: 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) { function syncSessionScope(list: any) {
try { try {
const snap = list.getSnapshot() const snap = list.getSnapshot()
@@ -542,6 +568,11 @@ function syncSessionScope(list: any) {
jobs: (snap?.jobsBySession?.[current] ?? []) as any[], jobs: (snap?.jobsBySession?.[current] ?? []) as any[],
subagents, subagents,
} }
// 完整快照 + 通知监听(项目卡片提醒镜像)
try {
sessionsSnapshotStore.snapshot = snap
sessionsSnapshotStore.listeners.forEach((l) => { try { l() } catch {} })
} catch {}
// 项目×对话联动:项目打开期间切到「非该项目绑定」的会话 → 自动关项目(保留用户新选的会话) // 项目×对话联动:项目打开期间切到「非该项目绑定」的会话 → 自动关项目(保留用户新选的会话)
try { try {
if (current !== lastSessionScopeId) { if (current !== lastSessionScopeId) {
@@ -605,6 +636,7 @@ function WorktableSection(props: any) {
} }
const [view, setView] = useState<ViewState>(loadView) const [view, setView] = useState<ViewState>(loadView)
const [notifyTick, setNotifyTick] = useState(0)
const [projects, setProjects] = useState<ProjectsState>(loadProjects) const [projects, setProjects] = useState<ProjectsState>(loadProjects)
const [metas, setMetas] = useState<Record<string, ProjectMeta>>({}) const [metas, setMetas] = useState<Record<string, ProjectMeta>>({})
const [registeredIds, setRegisteredIds] = useState<string[]>(() => [...registryStore.ids]) 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 projectAttachRef.attached = projectsRef.current.projects.bindings[spec.id] ?? prev
const bound = projectsRef.current.projects.bindings[spec.id] const bound = projectsRef.current.projects.bindings[spec.id]
if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} } if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} }
ackProjectNotify(spec.id)
} }
}, [projects.views]) }, [projects.views])
@@ -995,6 +1028,34 @@ function buildCustomLayoutPrompt(req: string): string {
copyToastTimerRef.current = window.setTimeout(() => setCopiedToast(null), 6000) 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 追加尾部; // 手动:持久化 order(过滤已卸载 id)→ 新注册 id 与布局 id 追加尾部;
// 最近:有 lastUsed 的按时间降序在前,其余按手动序在后。 // 最近:有 lastUsed 的按时间降序在前,其余按手动序在后。
@@ -1287,12 +1348,14 @@ function buildCustomLayoutPrompt(req: string): string {
} }
bindBtn.setAttribute('data-wt-bind', id) bindBtn.setAttribute('data-wt-bind', id)
const bound = projects.bindings[id] const bound = projects.bindings[id]
bindBtn.setAttribute('data-bound', bound ? 'true' : 'false') bindBtn.setAttribute('data-bound', bindNotifyMap[id] ?? (bound ? 'true' : 'false'))
// 入驻卡自带箭头(文本 ›):加统一对齐类,视觉居中(字面框偏下补偿 1px) // 入驻卡自带箭头(文本 ›):加统一对齐类,视觉居中(字面框偏下补偿 1px)
const kids = Array.from(el.children) const kids = Array.from(el.children)
const arrow = kids.find((k: any) => k.tagName === 'SPAN' && String((k as HTMLElement).textContent ?? '').trim() === '›') 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') 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('data-tip', tip)
bindBtn.setAttribute('aria-label', tip) bindBtn.setAttribute('aria-label', tip)
const icon = el.children[0] as HTMLElement | null const icon = el.children[0] as HTMLElement | null
@@ -1321,7 +1384,7 @@ function buildCustomLayoutPrompt(req: string): string {
const mo = new MutationObserver(sync) const mo = new MutationObserver(sync)
mo.observe(document.body, { childList: true, subtree: true }) mo.observe(document.body, { childList: true, subtree: true })
return () => mo.disconnect() return () => mo.disconnect()
}, [aliveRegisteredIds, projects.iconOverrides, projects.views, activeSplitId, projects.bindings]) }, [aliveRegisteredIds, projects.iconOverrides, projects.views, activeSplitId, projects.bindings, bindNotifyMap])
useEffect(() => { useEffect(() => {
const onDocClick = (e: MouseEvent) => { const onDocClick = (e: MouseEvent) => {
@@ -1360,6 +1423,7 @@ function buildCustomLayoutPrompt(req: string): string {
// 无视图覆盖:项目自带打开行为照旧,仅当绑定了会话时切换右侧对话窗 // 无视图覆盖:项目自带打开行为照旧,仅当绑定了会话时切换右侧对话窗
const bound = projectsRef.current.projects.bindings[pid] const bound = projectsRef.current.projects.bindings[pid]
if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} } if (bound) { try { sessionBridge?.sessions?.open?.(bound) } catch {} }
ackProjectNotify(pid)
} }
document.addEventListener('click', onDocClick, true) document.addEventListener('click', onDocClick, true)
return () => document.removeEventListener('click', onDocClick, true) return () => document.removeEventListener('click', onDocClick, true)
@@ -1866,8 +1930,10 @@ function buildCustomLayoutPrompt(req: string): string {
className={'dsh-wt_bindBtn'} className={'dsh-wt_bindBtn'}
role="button" role="button"
tabIndex={0} tabIndex={0}
data-bound={projects.bindings[l.id] ? 'true' : 'false'} 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]) }) : t('bind.tipUnbound')} 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')} 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) }} onClick={(e) => { e.stopPropagation(); openBindPick(l.id, e.currentTarget as HTMLElement) }}
><span className="dsh-wt_bindCircles" aria-hidden /></span> ><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) { export function apply(ctx: any) {
// 自定义窗口 → 宿主会话桥:保存 sessions/conversation/list 服务引用(模块级) // 自定义窗口 → 宿主会话桥:保存 sessions/conversation/list 服务引用(模块级)
sessionBridge = { sessions: ctx.sessions ?? null, conversation: ctx.conversation ?? null, list: ctx.sessions?.list ?? null, workspaces: ctx.workspaces ?? null } 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(() => { ctx.effect(() => {
+4
View File
@@ -93,6 +93,8 @@ export const zh = {
'bind.titleUnbound': '绑定对话(未绑定 ○○):点击选择要跟随的对话', 'bind.titleUnbound': '绑定对话(未绑定 ○○):点击选择要跟随的对话',
'bind.titleBound': '已绑定对话(●●):点击更换或解绑', 'bind.titleBound': '已绑定对话(●●):点击更换或解绑',
'bind.tipUnbound': '未绑定对话:点击选择要跟随的对话', 'bind.tipUnbound': '未绑定对话:点击选择要跟随的对话',
'bind.tipDone': '(任务已完成,点击项目查看)',
'bind.tipNeed': '(需要你的决定,点击项目处理)',
'bind.folder': '项目文件夹', 'bind.folder': '项目文件夹',
'bind.folderChange': '更改', 'bind.folderChange': '更改',
'bind.folderNone': '未设置(建议设置:项目产出文件都会放进这里)', 'bind.folderNone': '未设置(建议设置:项目产出文件都会放进这里)',
@@ -223,6 +225,8 @@ export const en = {
'bind.titleUnbound': 'Bind conversation (unbound ○○): pick the conversation to follow', 'bind.titleUnbound': 'Bind conversation (unbound ○○): pick the conversation to follow',
'bind.titleBound': 'Conversation bound (●●): click to change or unbind', 'bind.titleBound': 'Conversation bound (●●): click to change or unbind',
'bind.tipUnbound': 'No conversation bound — click to pick one', '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.folder': 'Project folder',
'bind.folderChange': 'Change', 'bind.folderChange': 'Change',
'bind.folderNone': 'Not set (recommended: project outputs go here)', 'bind.folderNone': 'Not set (recommended: project outputs go here)',
+5 -1
View File
@@ -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{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: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)}', '.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),此处只保留按钮本体样式 // 气泡为 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_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{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,.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::before{left:0}',
'.dsh-wt_bindCircles::after{left:10px}', '.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}', '.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}',
+5
View File
@@ -354,6 +354,11 @@ type SplitPane = {
- **对话绑定**:每个项目卡片(布局卡 + 入驻卡)中间偏右有 ○○/●● 按钮,点击弹面板(按工作区 - **对话绑定**:每个项目卡片(布局卡 + 入驻卡)中间偏右有 ○○/●● 按钮,点击弹面板(按工作区
分组、与发送到会话同源),绑定后打开该项目时右侧对话窗自动切换(sessions.open);解绑即 分组、与发送到会话同源),绑定后打开该项目时右侧对话窗自动切换(sessions.open);解绑即
不再切换;绑定关系存 projects.v1.bindings(项目 id → 会话 id)。 不再切换;绑定关系存 projects.v1.bindings(项目 id → 会话 id)。
- **任务完成/待决提醒镜像**(2026-08-18):绑定会话在宿主快照 byId 里 completed=true → 项目卡
双圆点绿色发光(data-bound=done);pendingInteraction != null → 黄色发光(data-bound=need),
与原生对话小绿点/小黄点同步;点开项目即确认(ack,notifyAck.v1 按会话存状态)恢复常态实心;
状态切换(完成↔待决)会重新点亮。数据源 sessionsSnapshotStore(syncSessionScope 推送完整
快照并通知监听)。
- **项目×对话联动**(2026-08-18):① 打开项目时记录「打开前会话」;② 项目打开期间切到非该 - **项目×对话联动**(2026-08-18):① 打开项目时记录「打开前会话」;② 项目打开期间切到非该
项目绑定的会话 → 自动关闭项目(保留用户新选的会话);③ ✕/反选关闭项目 → 自动回切「打开前 项目绑定的会话 → 自动关闭项目(保留用户新选的会话);③ ✕/反选关闭项目 → 自动回切「打开前
会话」。未绑定项目以「打开前会话」为归属会话(任何切换都会关掉它)。 会话」。未绑定项目以「打开前会话」为归属会话(任何切换都会关掉它)。
@@ -927,6 +927,22 @@
functional-diag 全 20 STEP(groupHeaders 3 / itemCount 19)ERROR_COUNT: 0。 functional-diag 全 20 STEP(groupHeaders 3 / itemCount 19)ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效。 - 备注:纯客户端改动,F5 即生效。
## 补记(任务完成/待决提醒镜像到项目卡)
- 用户要求:绑定对话出现原生小绿点(任务完成)/小黄点(需要判断)时,项目卡上的两个圆点
同步变绿/变黄并发光;点一下项目恢复常态实心。
- 实现:syncSessionScope 额外把完整会话快照写入 sessionsSnapshotStore 并通知监听;
组件按 bindings × byId.completed/pendingInteraction(含 notifyAck.v1 ack 过滤)算出
bindNotifyMap;卡片 data-bound 扩展 done/need 两态(CSS 绿 #3fb950 / 黄 #d29922 + 实心 +
drop-shadow 发光);点开项目(openSplit / DOM 桥)ack 当前状态恢复实心;hover 气泡追加
「任务已完成,点击项目查看」「需要你的决定,点击项目处理」。
- 验证(probe-batch10.cjs,桩注入快照状态):completed→data-bound=done、色 rgb(63,185,80)、
实心、drop-shadow 发光、tip 含「已完成」✓;点项目→ack=done、恢复 data-bound=true ✓;
pendingInteraction→need、黄 rgb(210,153,34)、发光、tip 含「决定」✓;functional-diag
全 20 STEP ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效。
+107
View File
@@ -0,0 +1,107 @@
// probe-batch10.cjs — 任务完成/待决提醒镜像:绿点发光 → 点项目 ack 恢复实心;黄点同理
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9355;
const proc = spawn('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', [
'--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
'--window-size=1440,900', '--force-device-scale-factor=1',
'--remote-debugging-port=' + PORT,
'--user-data-dir=C:\\Users\\SJL\\AppData\\Local\\Temp\\wt-chrome-batch10',
'about:blank',
], { stdio: 'ignore' });
const getJSON = (p) => new Promise((res, rej) => {
http.get({ host: '127.0.0.1', port: PORT, path: p }, (r) => { let d=''; r.on('data',c=>d+=c); r.on('end',()=>{try{res(JSON.parse(d))}catch(e){rej(e)}}) }).on('error', rej);
});
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
(async () => {
let list = null;
for (let i = 0; i < 40; i++) { try { list = await getJSON('/json/list'); if (list && list.length) break; } catch {} await sleep(500); }
const target = list.find((t) => t.type === 'page') || list[0];
const ws = new WebSocket(target.webSocketDebuggerUrl);
let id = 0; const pending = new Map();
const send = (method, params) => new Promise((res) => { const mid = ++id; pending.set(mid, res); ws.send(JSON.stringify({ id: mid, method, params })); });
ws.on('message', (raw) => { const m = JSON.parse(String(raw)); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } });
await new Promise((r) => ws.on('open', r));
await send('Runtime.enable');
await send('Page.enable');
await send('Page.addScriptToEvaluateOnNewDocument', {
source: "try{ if(window===window.top && location.origin==='http://127.0.0.1:3080'){ localStorage.setItem('dsh.worktable.projects.v1', JSON.stringify({order:[],lastUsed:{},hidden:[],nameOverrides:{},shortcuts:[],layouts:[{id:'t-layout',title:'L',top:null,left:null,main:[{id:'p1',title:'W',min:200,content:null}],chatWidth:{default:320,min:240,max:600},chatSide:'right',chatFullHeight:false}],bindings:{},folders:{}})); localStorage.removeItem('dsh.worktable.notifyAck.v1'); } }catch(e){}",
});
await send('Page.navigate', { url: 'http://127.0.0.1:3080/' });
const evaluate = async (expr) => {
const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true });
if (r.result && r.result.exceptionDetails) return { __error: (r.result.exceptionDetails.exception || {}).description || r.result.exceptionDetails.text };
return r.result && r.result.result ? r.result.result.value : undefined;
};
let ready = null;
for (let i = 0; i < 30; i++) { await sleep(1000); ready = await evaluate("!!window.__dshWorktable && !!window.__dshSyncSessionScope"); if (ready === true) break; }
await sleep(1500);
const step = await evaluate(`(async function(){
var out = {};
var sleep = function(ms){ return new Promise(function(r){ setTimeout(r, ms); }); };
var vis = function(sel){ return [].slice.call(document.querySelectorAll(sel)).find(function(el){ return (getComputedStyle(el).visibility!=='hidden'&&el.getBoundingClientRect().height>0); }); };
try {
var S = window.__dshSessions;
var card = document.querySelector('.dsh-wt_layout');
var bbtn = card && card.querySelector('.dsh-wt_bindBtn');
// 绑定到一个真实会话
bbtn.click();
await sleep(900);
var items = [].slice.call(document.querySelectorAll('.dsh-wt_bindList .dsh-wt_selectItem'));
if (items[0]) { items[0].click(); }
await sleep(800);
var boundId = JSON.parse(localStorage.getItem('dsh.worktable.projects.v1')).bindings['t-layout'];
out.boundId = boundId ? boundId.slice(0, 12) : null;
// 桩:给绑定会话注入 completed=true,手动触发同步
var listStore = S.list;
var orig = listStore.getSnapshot.bind(listStore);
var fake = function(patch){ return function(){ var s = orig(); var e = s.byId && s.byId[boundId]; if (e) { s.byId = Object.assign({}, s.byId); s.byId[boundId] = Object.assign({}, e, patch); } return s; }; };
listStore.getSnapshot = fake({ completed: true });
window.__dshSyncSessionScope();
await sleep(600);
var btn2 = card.querySelector('.dsh-wt_bindBtn');
out.boundAttrDone = btn2.getAttribute('data-bound');
var cs = getComputedStyle(btn2);
out.doneColor = cs.color;
var c4 = getComputedStyle(btn2.querySelector('.dsh-wt_bindCircles'), '::before');
out.doneFill = c4.backgroundColor;
var cir = getComputedStyle(btn2.querySelector('.dsh-wt_bindCircles'));
out.doneGlow = cir.filter;
out.tipHasDone = (btn2.getAttribute('data-tip')||'').indexOf('\u5df2\u5b8c\u6210') >= 0;
// 点击项目 = ack → 恢复常态实心
card.click();
await sleep(900);
var btn3 = card.querySelector('.dsh-wt_bindBtn');
out.afterAckAttr = btn3.getAttribute('data-bound');
out.ackSaved = (JSON.parse(localStorage.getItem('dsh.worktable.notifyAck.v1')||'{}')[boundId]) || null;
// 恢复快照桩
listStore.getSnapshot = orig;
var st = window.__dshWorktable.splitStore;
st.close();
await sleep(400);
// 待决(黄)同理:注入 pendingInteraction
listStore.getSnapshot = fake({ pendingInteraction: { kind: 'question' } });
window.__dshSyncSessionScope();
await sleep(600);
var btn4 = card.querySelector('.dsh-wt_bindBtn');
out.needAttr = btn4.getAttribute('data-bound');
out.needColor = getComputedStyle(btn4).color;
var cir2 = getComputedStyle(btn4.querySelector('.dsh-wt_bindCircles'));
out.needGlow = cir2.filter;
out.tipHasNeed = (btn4.getAttribute('data-tip')||'').indexOf('\u51b3\u5b9a') >= 0;
// 清理:解绑 + 恢复
listStore.getSnapshot = orig;
bbtn = card.querySelector('.dsh-wt_bindBtn');
bbtn.click();
await sleep(900);
var unbind = vis('.dsh-wt_bindUnbind');
if (unbind) { unbind.click(); }
await sleep(500);
localStorage.removeItem('dsh.worktable.notifyAck.v1');
} catch(e) { out.err = String(e); }
return JSON.stringify(out);
})()`);
console.log('BATCH10:', JSON.stringify(step));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+53
View File
@@ -0,0 +1,53 @@
// snapstate-mini.cjs — 检查会话快照 byId 里的 completed / pendingInteraction 字段
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9354;
const proc = spawn('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', [
'--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
'--window-size=1440,900', '--force-device-scale-factor=1',
'--remote-debugging-port=' + PORT,
'--user-data-dir=C:\\Users\\SJL\\AppData\\Local\\Temp\\wt-chrome-snapstate',
'about:blank',
], { stdio: 'ignore' });
const getJSON = (p) => new Promise((res, rej) => {
http.get({ host: '127.0.0.1', port: PORT, path: p }, (r) => { let d=''; r.on('data',c=>d+=c); r.on('end',()=>{try{res(JSON.parse(d))}catch(e){rej(e)}}) }).on('error', rej);
});
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
(async () => {
let list = null;
for (let i = 0; i < 40; i++) { try { list = await getJSON('/json/list'); if (list && list.length) break; } catch {} await sleep(500); }
const target = list.find((t) => t.type === 'page') || list[0];
const ws = new WebSocket(target.webSocketDebuggerUrl);
let id = 0; const pending = new Map();
const send = (method, params) => new Promise((res) => { const mid = ++id; pending.set(mid, res); ws.send(JSON.stringify({ id: mid, method, params })); });
ws.on('message', (raw) => { const m = JSON.parse(String(raw)); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } });
await new Promise((r) => ws.on('open', r));
await send('Runtime.enable');
await send('Page.enable');
await send('Page.navigate', { url: 'http://127.0.0.1:3080/' });
const evaluate = async (expr) => {
const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true });
if (r.result && r.result.exceptionDetails) return { __error: (r.result.exceptionDetails.exception || {}).description || r.result.exceptionDetails.text };
return r.result && r.result.result ? r.result.result.value : undefined;
};
let ready = null;
for (let i = 0; i < 30; i++) { await sleep(1000); ready = await evaluate("!!window.__dshSessions"); if (ready === true) break; }
await sleep(800);
const step = await evaluate(`(function(){
var snap = window.__dshSessions.list.getSnapshot();
var byId = snap.byId || {};
var out = { ids: (snap.ids||[]).length, keys: null, samples: [] };
var first = Object.keys(byId)[0];
out.keys = first ? Object.keys(byId[first]) : [];
var n = 0;
Object.keys(byId).forEach(function(k){
var e = byId[k];
if ((e.completed || e.pendingInteraction != null) && n < 4) { out.samples.push({ id: k.slice(0, 20), completed: e.completed, pending: e.pendingInteraction, running: e.running }); n++; }
});
out.statefulCount = n;
return JSON.stringify(out);
})()`);
console.log('SNAPSTATE:', JSON.stringify(step));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+4
View File
@@ -51,6 +51,10 @@ node --check lib/index.js
DeepseekHarness)、其他用户的项目名与私人路径。剪贴板提示词会发给别人的 DSH,必须只含 DeepseekHarness)、其他用户的项目名与私人路径。剪贴板提示词会发给别人的 DSH,必须只含
插件通用知识;窗口任务提示词只发用户自己的会话,允许携带该项目自己的文件夹路径。 插件通用知识;窗口任务提示词只发用户自己的会话,允许携带该项目自己的文件夹路径。
分组下拉只是会话创建工作区的选择,绝不进入任何提示词文本。 分组下拉只是会话创建工作区的选择,绝不进入任何提示词文本。
- **任务完成/待决提醒镜像**:绑定会话在宿主快照 byId 里 completed=true → 项目卡双圆点变
绿色发光(data-bound=done);pendingInteraction != null → 黄色发光(data-bound=need);
点开项目 = ack(notifyAck.v1 按会话存状态)恢复常态实心。数据源 = sessionsSnapshotStore
(syncSessionScope 写入完整快照并通知监听者);跨状态(done↔need)会重新点亮。
## 安装 / 重启 ## 安装 / 重启