From 630949eac78fed7df9434541fb7ff151d2a3678b Mon Sep 17 00:00:00 2001 From: qiqi Date: Thu, 3 Dec 2026 09:51:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(queue):=20=E5=AE=9A=E4=BD=8D=E5=9B=9E?= =?UTF-8?q?=E7=94=BB=E5=B8=83=20/=20=E5=B7=B2=E5=9C=A8=E5=9B=BE=E5=BA=93?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=20/=20=E4=B8=8A=E9=99=90=E4=BF=9D=E6=8A=A4?= =?UTF-8?q?=20/=20=E7=BC=A9=E7=95=A5=E5=9B=BE=E4=B8=8E=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 4 ++-- app.js | 6 +++++- docs/standards/architecture-current-state.md | 2 +- plugins/index.json | 2 +- plugins/taskqueue/main.js | 19 ++++++++++--------- plugins/taskqueue/manifest.json | 2 +- src/image-ingest-store.js | 6 ++++-- tests/source-text-ratchet-test.js | 4 ++-- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 613fed9..42bbfdc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -105,8 +105,8 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js # | 守卫 | 位置 | 现在的上限 | |---|---|---| -| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,309**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | -| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,652** | +| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **9,313**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) | +| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,656** | | 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** | 三条都是**只减不增**。确需在 app.js 增长时,必须**同步上调上限并在 commit 里写理由**(等于显式记账,不会悄悄发生)。 diff --git a/app.js b/app.js index 0f4e880..848f565 100644 --- a/app.js +++ b/app.js @@ -6449,6 +6449,7 @@ const tbCenterSeed = (type, refs) => { const saved = store.load() view.hydrate(saved) ing.restore(saved) + try { store.trim() } catch (eTrim) { /* 上限收紧后启动即裁剪 */ } // 启动先对一次账,之后每 30s 一次(幂等;不阻塞启动) try { setTimeout(() => { try { wDedupeOutputs() } catch (eD0) { /* ignore */ } try { wIngestReconcile() } catch (eR0) { /* ignore */ } }, 3000) } catch (eR1) { /* ignore */ } // 2026-12-02:不做常驻轮询(用户要求不占空闲 CPU)。改成「窗口重新获得焦点时」跑一次: @@ -8284,6 +8285,7 @@ const tbCenterSeed = (type, refs) => { const want = String(opt.status || '') const limit = Math.max(1, Math.min(5000, Number(opt.limit) || 500)) const q = String(opt.query || '').toLowerCase() + const idxNow = lsGet(OUT_KEY, []) || [] let items = qList().map((e) => { const v = qView(e.url) const meta = e.meta || {} @@ -8293,7 +8295,8 @@ const tbCenterSeed = (type, refs) => { w: Number(e.w) || 0, h: Number(e.h) || 0, error: String(e.lastError || ''), retries: Number(e.retries) || 0, createdAt: Number(e.createdAt) || 0, updatedAt: Number(e.updatedAt) || 0, meta, - thumbUrl: (v && v.localUrl) ? v.localUrl : '', + thumbUrl: (v && v.localUrl) ? v.localUrl : (outThumbCache.get(e.url) || ''), + inGallery: (() => { const row = idxNow.find((f) => f && String(f.url) === String(e.url)); return !!(row && (row.orig === 'ok' || row.origIdb)) })(), } }) if (want && want !== 'all') items = items.filter((x) => x.kind === want) @@ -8352,6 +8355,7 @@ const tbCenterSeed = (type, refs) => { const target = (refs.workspaces || []).find((w) => w.id === bid) if (!target) return Promise.resolve({ ok: false, error: 'board-missing' }) if (bid !== activeWsId) { try { switchWs(bid) } catch (e2) { /* ignore */ } } + else { try { setShellView('canvas') } catch (e3) { /* ignore */ } } return pick(0) }, stats: () => { diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index 9199cf6..9537ab0 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **9,309 行**(**双层预算**:绝对上限 9,309 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,652 行**(上限 **2,652**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **128** 个模块 / 26,185 行,`sourceModules` 128 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **9,313 行**(**双层预算**:绝对上限 9,313 / 占总源码 ≤ 40%,现 **26.2%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,656 行**(上限 **2,656**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **128** 个模块 / 26,187 行,`sourceModules` 128 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 1.5 内存基线(2026-11-30,v3.26.115,Windows / WebView2 实测) diff --git a/plugins/index.json b/plugins/index.json index 8a900fc..7afdb25 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -104,7 +104,7 @@ "style": "styles.css", "version": "1.0.0", "files": { - "main.js": "f0f6d0e5426dca62e2f7130da2870ad6acc7321c62301ff27d0cc4d4b6243883", + "main.js": "b307c2fdf70d87c5128bd730294c0d3f381f24d5d249e403ce92a8c42ff5cf9a", "styles.css": "322e5b2336a87a796bd9c3fcfef99754e19833091d0bc0567ea8afe9d5d61a80" } } diff --git a/plugins/taskqueue/main.js b/plugins/taskqueue/main.js index 57b1225..3783eed 100644 --- a/plugins/taskqueue/main.js +++ b/plugins/taskqueue/main.js @@ -9,7 +9,7 @@ var PAGE_ID = 'taskqueue-page' var TABS = [['all', '全部'], ['ok', '已完成'], ['down', '下载中'], ['fail', '失败'], ['only', '仅记录']] var STATUS = { ok: '已完成', down: '下载中', fail: '失败', only: '仅记录' } - var LIMITS = [200, 500, 1000, 2000, 5000] + var LIMITS = [100, 200, 500, 1000, 2000, 5000] function el (tag, attrs) { var node = document.createElement(tag) @@ -43,6 +43,7 @@ function mount (host, ctx) { clear(host) + if (!ctx || !ctx.queue) { host.textContent = '任务队列能力未就绪(请更新客户端)'; return function () {} } host.classList.add('iwb-plugin-node-body', 'iwb-tq') var state = { filter: 'all', limit: 500, items: [], total: 0, loading: true, msg: '' } var timer = 0 @@ -117,7 +118,7 @@ function rowOf (it) { var meta = it.meta || {} var thumb = el('div', { class: 'iwb-tq-thumb', title: '点击预览' }, thumbOf(it)) - thumb.addEventListener('click', function () { ctx.queue.preview(it.id) }) + thumb.addEventListener('click', function () { try { Promise.resolve(ctx.queue.preview(it.id)).catch(function () { setMsg('预览失败') }) } catch (e) { setMsg('预览失败') } }) var line1 = el('div', { class: 'iwb-tq-line1' }, el('span', { class: 'iwb-tq-name', text: String(meta.prompt || '生成结果') }), badgeOf(it)) var bits = [] if (meta.boardName) bits.push(meta.boardName) @@ -128,12 +129,12 @@ var main = el('div', { class: 'iwb-tq-main' }, line1, metaLine) if (it.kind === 'fail' && it.error) main.appendChild(el('div', { class: 'iwb-tq-err', text: it.error + (it.retries ? (' · 已重试 ' + it.retries + ' 次') : '') })) var acts = el('div', { class: 'iwb-tq-actions' }) - if (it.kind === 'ok') acts.appendChild(el('button', { class: 'iwb-btn iwb-btn-sm iwb-tq-btn', text: '已在图库', disabled: 'disabled' })) + if (it.kind === 'ok' && it.inGallery) acts.appendChild(el('button', { class: 'iwb-btn iwb-btn-sm iwb-tq-btn', text: '已在图库', disabled: 'disabled' })) else if (it.kind === 'down') acts.appendChild(el('button', { class: 'iwb-btn iwb-btn-sm iwb-tq-btn', text: '下载中…', disabled: 'disabled' })) - else if (it.kind === 'fail') acts.appendChild(btn('重试', 'iwb-tq-primary', function () { ctx.queue.retry(it.id); setMsg('已重新排队'); schedule() })) - else acts.appendChild(btn('下载', 'iwb-tq-primary', function (b) { b.disabled = true; ctx.queue.land(it.id).then(function (r) { b.disabled = false; setMsg(r && r.already ? '已在图库' : (r && r.ok ? '已加入落地队列,图库会自动刷新' : '下载失败')) ; schedule() }) })) - acts.appendChild(btn('复制原始链接', '', function () { ctx.queue.copyLink(it.id).then(function (r) { setMsg(r && r.ok ? '链接已复制' : '复制失败') }) })) - var loc = btn('定位', '', function (b) { b.disabled = true; ctx.queue.locate(it.id).then(function (r) { b.disabled = false; setMsg(r && r.ok ? '已定位到节点' : ({ 'board-missing': '画布已删除', 'node-missing': '节点已删除', 'missing-meta': '没有定位信息' }[r && r.error] || '定位失败')) }) }) + else if (it.kind === 'fail') acts.appendChild(btn('重试', 'iwb-tq-primary', function () { Promise.resolve(ctx.queue.retry(it.id)).then(function () { setMsg('已重新排队'); schedule() }).catch(function () { setMsg('重试失败') }) })) + else acts.appendChild(btn('下载', 'iwb-tq-primary', function (b) { b.disabled = true; ctx.queue.land(it.id).then(function (r) { b.disabled = false; setMsg(r && r.already ? '已在图库' : (r && r.ok ? '已加入落地队列,图库会自动刷新' : '下载失败')) ; schedule() }).catch(function () { b.disabled = false; setMsg('下载失败') }) })) + acts.appendChild(btn('复制原始链接', '', function () { ctx.queue.copyLink(it.id).then(function (r) { setMsg(r && r.ok ? '链接已复制' : '复制失败') }).catch(function () { setMsg('复制失败') }) })) + var loc = btn('定位', '', function (b) { b.disabled = true; ctx.queue.locate(it.id).then(function (r) { b.disabled = false; setMsg(r && r.ok ? '已定位到节点' : ({ 'board-missing': '画布已删除', 'node-missing': '节点已删除', 'missing-meta': '没有定位信息' }[r && r.error] || '定位失败')) }).catch(function () { b.disabled = false; setMsg('定位失败') }) }) if (!(meta.boardId && meta.nodeId)) { loc.disabled = true; loc.title = '没有画布/节点信息' } acts.appendChild(loc) return el('div', { class: 'iwb-tq-row ' + (it.kind || '') }, thumb, main, acts) @@ -182,11 +183,11 @@ limitSel.addEventListener('change', function () { var n = Number(limitSel.value) || 500 state.limit = n - ctx.queue.setLimit(n).then(function () { setMsg('记录上限已改为 ' + n) ; load() }) + ctx.queue.setLimit(n).then(function () { setMsg('记录上限已改为 ' + n) ; load() }).catch(function () { setMsg('修改上限失败') }) }) clearBtn.addEventListener('click', function () { if (!global.confirm('清空已完成/失败的记录?不会删除图库文件。')) return - ctx.queue.clear().then(function () { setMsg('已清空记录'); load() }) + ctx.queue.clear().then(function () { setMsg('已清空记录'); load() }).catch(function () { setMsg('清空失败') }) }) refreshBtn.addEventListener('click', function () { load() }) diff --git a/plugins/taskqueue/manifest.json b/plugins/taskqueue/manifest.json index 8a69b82..9b7a853 100644 --- a/plugins/taskqueue/manifest.json +++ b/plugins/taskqueue/manifest.json @@ -13,7 +13,7 @@ "记录" ], "files": { - "main.js": "f0f6d0e5426dca62e2f7130da2870ad6acc7321c62301ff27d0cc4d4b6243883", + "main.js": "b307c2fdf70d87c5128bd730294c0d3f381f24d5d249e403ce92a8c42ff5cf9a", "styles.css": "322e5b2336a87a796bd9c3fcfef99754e19833091d0bc0567ea8afe9d5d61a80" } } diff --git a/src/image-ingest-store.js b/src/image-ingest-store.js index 30c7ea2..c54b2a5 100644 --- a/src/image-ingest-store.js +++ b/src/image-ingest-store.js @@ -43,7 +43,8 @@ const max = maxOf() if (arr.length > max) { // 淘汰最旧的非 pinned 记录(pinned = 被画布/图库引用) - const drop = arr.filter((x) => !x.pinned).sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0)) + const isActive = (x) => !!(x && (x.status === 'queued' || x.status === 'downloading')) + const drop = arr.filter((x) => !x.pinned && !isActive(x) && x.id !== entry.id).sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0)) while (arr.length > max && drop.length) { const victim = drop.shift() const i = arr.indexOf(victim) @@ -64,7 +65,8 @@ const arr = load() const max = maxOf() if (arr.length <= max) return 0 - const drop = arr.filter((x) => !x.pinned).sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0)) + const isActive = (x) => !!(x && (x.status === 'queued' || x.status === 'downloading')) + const drop = arr.filter((x) => !x.pinned && !isActive(x)).sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0)) let removed = 0 while (arr.length > max && drop.length) { const victim = drop.shift() diff --git a/tests/source-text-ratchet-test.js b/tests/source-text-ratchet-test.js index 306e013..1b4bb0d 100644 --- a/tests/source-text-ratchet-test.js +++ b/tests/source-text-ratchet-test.js @@ -175,7 +175,7 @@ const MAX_SRC_GLOBALS = 124 // 2026-12-03 +1(123→124):新增 IWBPlugin // · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2 // 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js // 与 src/plugin-api-images.js,app.js 只做装配。 -const MAX_APP_JS_LINES = 9309 // +162(9,146→9,308)2026-12-03:任务队列(queue/pages 能力 + 整页容器 + 左栏入口 + land/preview/locate/limit 装配)。之后只减不增。 +const MAX_APP_JS_LINES = 9313 // +167(9,146→9,313)2026-12-03:任务队列(queue/pages 能力 + 整页容器 + 左栏入口 + land/preview/locate/limit 装配)。之后只减不增。 const MAX_APP_JS_SHARE = 0.40 // ── 历史记账(供回溯,逐条保留)────────────────────────────────────────────── @@ -218,7 +218,7 @@ const MAX_APP_JS_SHARE = 0.40 // 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取, // 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈); // 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js -const MAX_WORKBENCH_LINES = 2652 // +118(2,533→2,651)2026-12-03:同上(任务队列 queue/pages 装配与页面容器)。之后只减不增。 +const MAX_WORKBENCH_LINES = 2656 // +123(2,533→2,656)2026-12-03:同上(任务队列 queue/pages 装配与页面容器)。之后只减不增。 // 2026-11-18 v3.25.21:模态层指针守卫(2 行) // 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs // → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族