feat: lock mounted results as the window's permanent content (lockPane replaces tabs and persists across sessions)

This commit is contained in:
Aisland
2026-08-20 22:03:10 +08:00
parent 54bfcccd67
commit 6720b4dfab
5 changed files with 153 additions and 6 deletions
+11 -6
View File
@@ -455,7 +455,7 @@ function buildWindowTaskText(projectId: string, projectName: string, windowLabel
' - 视频 / 动画 → 生成 .mp4 / .gif(或 Lottie JSON)文件放进项目文件夹;',
' - 工作台已有内置窗能力(资源管理器 / 终端 / 浏览器 / 动画站)→ 不要重复造轮子,直接建议用户改用内置窗。',
'5. 完成内容后,用一两句话说明用户把它放进窗口的步骤。该窗口位于「' + projectName + '」项目内,如需要也可协助该项目后续的其他自定义工作。',
'6. 完成后写入「产物清单」文件:在项目文件夹里创建 widget-result.json,内容示例 {\"window\":\"' + win + '\",\"path\":\"产物相对路径\",\"kind\":\"html\"};kind 可选 html(本地页面,path 相对项目文件夹)/ url(外部链接,path 为完整 URL)/ file(其他文件,path 相对项目文件夹)。写完这个文件,工作台会自动把产物挂载进「' + win + '」窗口,用户无需手动操作。',
'6. 完成后写入「产物清单」文件:在项目文件夹里创建 widget-result.json,内容示例 {\"window\":\"' + win + '\",\"path\":\"产物相对路径\",\"kind\":\"html\"};kind 可选 html(本地页面,path 相对项目文件夹)/ url(外部链接,path 为完整 URL)/ file(其他文件,path 相对项目文件夹)。写完这个文件,工作台会自动把产物挂载进「' + win + '」窗口,用户无需手动操作;挂载后该产物会作为「' + win + '」窗口的固定内容锁定保存,用户下次打开工作台时窗口直接显示它,不会丢失或重置。',
KNOWLEDGE_PACK,
]
return lines.join('\n')
@@ -1021,7 +1021,10 @@ function buildCustomLayoutPrompt(req: string): string {
// 补挂:此前项目未打开时暂存的产物,现在自动挂进主行第一格
const pending = pendingMountRef.current[spec.id]
if (pending) {
try { splitStore.openTab('main', 0, pending) } catch {}
try {
if (pending.content && typeof pending.row === 'string') splitStore.lockPane(pending.row, pending.index ?? 0, pending.content)
else splitStore.openTab('main', 0, pending)
} catch {}
delete pendingMountRef.current[spec.id]
try { localStorage.setItem('dsh.worktable.pendingMount.v1', JSON.stringify(pendingMountRef.current)) } catch {}
}
@@ -1114,12 +1117,14 @@ function buildCustomLayoutPrompt(req: string): string {
const content = buildMountContent(folder, d)
if (!content) return
if (splitStore.active && splitStore.spec?.id === projectId) {
// 项目开着:直接挂进「窗口N」对应窗格(找不到就落主行第一格)
// 项目开着:锁死挂进「窗口N」对应窗格(清空原内容、唯一标签;找不到就落主行第一格)
const pane = windowLabelToPane(splitStore.spec, d.window)
splitStore.openTab(pane?.row ?? 'main', pane?.index ?? 0, content)
splitStore.lockPane(pane?.row ?? 'main', pane?.index ?? 0, content)
} else {
// 项目没开:暂存,打开项目时补挂
pendingMountRef.current[projectId] = content
// 项目没开:按项目已保存的 spec 解析目标窗格,暂存,打开项目时锁死补挂
const saved = projectsRef.current.projects.views[projectId] ?? projectsRef.current.projects.layouts.find((l) => l.id === projectId)
const pane = windowLabelToPane(saved, d.window)
pendingMountRef.current[projectId] = { content, row: pane?.row ?? 'main', index: pane?.index ?? 0 }
try { localStorage.setItem('dsh.worktable.pendingMount.v1', JSON.stringify(pendingMountRef.current)) } catch {}
}
} catch { /* 无清单文件 = 不挂载 */ }
+26
View File
@@ -105,6 +105,8 @@ type SplitState = {
setTopW(i: number, w: number): void
setPaneContent(row: PaneRow, i: number, content: SplitContent | null): void
openTab(row: PaneRow, i: number, content: SplitContent): void
/** 锁定窗格:清空原有标签,把内容作为该窗唯一的固定标签(挂载产物的「锁死」语义) */
lockPane(row: PaneRow, i: number, content: SplitContent): void
closeTab(row: PaneRow, i: number, tabId: string): void
setActiveTab(row: PaneRow, i: number, tabId: string): void
moveTab(fromRow: PaneRow, fromI: number, tabId: string, toRow: PaneRow, toI: number): void
@@ -586,6 +588,30 @@ export const splitStore: SplitState = {
if (content) this.openTab(row, i, content)
},
lockPane(row, i, content) {
const spec = this.spec
if (!spec) return
const tab: PaneTab = { id: 't' + Date.now().toString(36), title: tabTitleOf(content), content, active: 0 }
const mutate = (pane: SplitPane): SplitPane => ({ ...pane, content: null, tabs: [tab], active: 0 })
if (row === 'left') {
if (!spec.left || i !== 0) return
this.spec = { ...spec, left: mutate(spec.left) }
} else if (row === 'top') {
const top = [...(spec.top ?? [])]
if (!top[i]) return
top[i] = mutate(top[i])
this.spec = { ...spec, top }
} else {
const main = [...spec.main]
if (!main[i]) return
main[i] = mutate(main[i])
this.spec = { ...spec, main }
}
this.onSpecMutated?.(this.spec)
this.persist()
this.notify()
},
openTab(row, i, content) {
const spec = this.spec
if (!spec) return
@@ -1054,6 +1054,20 @@
重开项目 mountedAfterReopen ✓;宿主重启后 functional-diag 全 20 STEP ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效;夹具目录已清理。
## 补记(挂载锁死:产物成为窗口固定内容)
- 用户要求:用户已明确用 HTML 时,挂载完成后产物必须与该窗口「锁死」——下次进入工作台
窗口直接显示页面,不能丢失或重置。
- 实现:splitStore 新增 lockPane(row,index,content)——清空该窗格原有标签、产物作为唯一标签
(active 0)并 onSpecMutated 持久化;tryAutoMount 改用 lockPane;待挂载记录带
{content,row,index}(用项目已保存 spec 解析「窗口N」),补挂同样 lockPane;提示词第 6 条
增加锁定语义说明。
- 验证(probe-batch12.cjs):窗口先放浏览器标签 → 完成事件 → tabsAfterLock=1 且唯一内容为
产物 iframe(原标签被替换)✓;lockedPersisted=true(写回 projects.v1)✓;关掉重开
reopenKeepsLock=true ✓;functional-diag 全 20 STEP ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效;夹具目录已清理。
+99
View File
@@ -0,0 +1,99 @@
// probe-batch12.cjs — 锁死挂载:完成后窗口被替换为唯一标签;重开项目(模拟下次进入)仍在
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9368;
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-batch12',
'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:'\u7a97\u53e31',min:200,content:null}],chatWidth:{default:320,min:240,max:600},chatSide:'right',chatFullHeight:false}],bindings:{},folders:{'t-layout':'C:\\\\Users\\\\SJL\\\\AppData\\\\Local\\\\Temp\\\\wt-mount-fixture'}})); localStorage.removeItem('dsh.worktable.notifyAck.v1'); localStorage.removeItem('dsh.worktable.pendingMount.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); }); };
var postJson = async function(url, body){ return await fetch(url, { method:'POST', headers:{'content-type':'application/json'}, body: JSON.stringify(body) }); };
try {
var fix = 'C:\\\\Users\\\\SJL\\\\AppData\\\\Local\\\\Temp\\\\wt-mount-fixture';
await postJson('/api/worktable/mkdir', { path: fix });
await postJson('/api/worktable/write', { path: fix + '\\\\page.html', content: '<html><body><h1>FLOWER</h1></body></html>' });
await postJson('/api/worktable/write', { path: fix + '\\\\widget-result.json', content: JSON.stringify({ window: '\u7a97\u53e31', path: 'page.html', kind: 'html' }) });
var S = window.__dshSessions;
var card = document.querySelector('.dsh-wt_layout');
var bbtn = 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'];
// 先给窗口1 放一个已有标签(应被锁死替换掉)
var st = window.__dshWorktable.splitStore;
card.click();
await sleep(1200);
st.openTab('main', 0, { kind: 'builtin', type: 'browser' });
await sleep(400);
out.tabsBeforeLock = st.spec.main[0].tabs.length;
// 完成事件 → 锁死挂载
var listStore = S.list;
var orig = listStore.getSnapshot.bind(listStore);
listStore.getSnapshot = 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, { completed: true, running: false }); } return s; };
window.__dshSyncSessionScope();
await sleep(2000);
var tabs = st.spec.main[0].tabs;
out.tabsAfterLock = tabs.length;
out.onlyContent = tabs.length === 1 ? { kind: tabs[0].content.kind, url: tabs[0].content.url ? tabs[0].content.url.slice(0, 80) : null, active: st.spec.main[0].active } : null;
out.lockedPersisted = (function(){ var j = JSON.parse(localStorage.getItem('dsh.worktable.projects.v1')); var l = (j.layouts||[]).find(function(x){ return x.id === 't-layout'; }); return l && l.main[0].tabs && l.main[0].tabs.length === 1 && l.main[0].tabs[0].content.url && l.main[0].tabs[0].content.url.indexOf('wt-mount-fixture') >= 0; })();
// 模拟下次进入:关掉 → 重开
st.close();
await sleep(400);
card.click();
await sleep(1400);
var tabs2 = st.spec.main[0].tabs;
out.reopenKeepsLock = tabs2.length === 1 && tabs2[0].content.url && tabs2[0].content.url.indexOf('wt-mount-fixture') >= 0;
// 清理
listStore.getSnapshot = orig;
st.close();
await sleep(400);
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.pendingMount.v1');
} catch(e) { out.err = String(e); }
return JSON.stringify(out);
})()`);
console.log('BATCH12:', 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); });
+3
View File
@@ -51,6 +51,9 @@ node --check lib/index.js
buildMountContent 转换产物 → 项目开着直接 openTab 进「窗口N」(windowLabelToPane 按窗口
编号规则定位),项目没开暂存 pendingMountRef(localStorage,打开项目时补挂);
mountConsumedRef 保证一次完成只消费一次。
**锁死语义**:挂载用 splitStore.lockPane——清空该窗格原有标签,把产物作为唯一固定标签
(active 0),onSpecMutated 立即持久化;用户下次打开工作台窗口直接显示产物,不丢失不重置。
待挂载记录带 {content,row,index},补挂同样 lockPane。
- **原生皮肤模板**:01_content/template/dshell.css + dshell.html(esbuild text loader 嵌入服务端
bundle,/api/worktable/template 路由下发);知识包要求产出 HTML 一律引用该样式表,组件类
参考模板。新增组件样式只加到 dshell.css,保持单一来源。