feat(album): 相册文件夹模式 + 固化可靠性修复(v1.2.0)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 41s

宿主:
- wCleanIdb 保留集改为递归整个 node.data(原只扫 data/url/result,漏 items[].src ⇒ 固化后的 blob 被当孤儿删,实测 18 个条目丢 16 个)
- 收藏组同步修复;新增 tests/idb-gc-plugin-refs-test.js 防回退

插件 album 1.2.0:
- 来源徽标(已固化/引用/网络/丢失)
- 固化计数只算本地路径引用,批量跳过已固化并提示
- 单删/清空时清理 ctx.files 缩略图
- 文件夹模式:单图任务 + 文件夹监控两个开关、模式说明、按模式隐藏控件、刷新(增量 diff)、全部重载(二次确认)、忽略名单 folderSkip、底部路径与已忽略计数

计划与复盘:docs/plans/album-folder-mode.md(含勾选状态与优化总结)
This commit is contained in:
qiqi committed 2026-11-30 09:54:01 +08:00
1 parent 03191d24dc
commit a4dc50ed5e
10 files changed
+289 -25

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序
node --check app.js 与 dist/app.js 语法
check-dist.js 产物体检
lint ESLint(src/ + app.js,正确性规则)
test:unit 135 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
test:unit 136 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底))
test relay-task-graph-fixture + iwb-v32-web-test
test:facts 事实基线守门(见 §5)
typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js)
+4 -5
View File
@@ -2824,10 +2824,9 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct
for (const k of Object.keys(value)) collect(value[k])
}
}
for (const w of (ws && ws.workspaces) || []) for (const n of (w && w.nodes) || []) {
const d = (n && n.data) || {}
for (const f of ['data', 'url', 'result']) collect(d[f])
}
// v3.26.116:**递归整个 node.data**。原来只扫 data/url/result,漏掉插件节点里的图片引用
// (相册 data.items[].src)⇒ 固化后的 {__blob} 被当孤儿删掉,重开只剩缩略图(实测 18 个里丢 16 个)。
for (const w of (ws && ws.workspaces) || []) for (const n of (w && w.nodes) || []) collect((n && n.data) || {})
// 出图缩略图/原图:保留 outputs 索引中仍在的(随保留策略删除的索引 → 孤儿一并回收)
const oidx = lsGet(OUT_KEY, [])
for (const f of oidx) { if (f && f.idb) keep.add(f.idb); if (f && f.origIdb) keep.add(f.origIdb) }
@@ -2850,7 +2849,7 @@ try { if (window.IWBMiniMapFit && typeof window.IWBMiniMapFit.install === 'funct
// 否则会被当孤儿回收、实例化出来的组图空白。放在节流之后:只有真要扫库时才读一次收藏组。
try {
const savedGroups = lsGet(StorageContract.localKeys.groups, []) || []
for (const g of savedGroups) for (const n of ((g && g.nodes) || [])) { const d = (n && n.data) || {}; collect(d.data); collect(d.url) }
for (const g of savedGroups) for (const n of ((g && g.nodes) || [])) collect((n && n.data) || {})
} catch (e) { /* 读取失败不影响清理 */ }
const keys = await IDB.keys()
for (const k of keys) {
+111
View File
@@ -0,0 +1,111 @@
# 相册节点优化执行计划(文件夹模式 + 固化可靠性)
> 2026-11-30 起。本文档是**执行中的活文档**:每完成一步就勾选并写「复查记录」,最后补「优化总结」。
> 相关背景见 `docs/standards/memory-and-gallery-lessons-2026-11-30.md`。
## 0. 目标与边界
- 目标:相册节点的图片**来源可信、可固化、可追溯**;新增「文件夹模式」(手动刷新,不做自动监听)。
- 不做:文件夹自动监控(性能考虑,用户已确认用手动刷新)。
- 已确认的产品决策:
- 点击图片=选中/取消(现有行为,不改)
- 悬停出现放大/删除(现有行为,保留)
- 文件夹模式下**隐藏**添加/文件夹/粘贴/固化(不是置灰)
- 文件夹路径只显示在底部
- 文件夹模式下手动删除 → 记入 `folderSkip`;另提供「全部重载」清空忽略名单
- 文件夹模式不做固化(跟随目录语义)
## 1. 阶段与勾选
### P0 宿主:修 GC 误删相册图(阻塞项)
- [x] `wCleanIdb` 保留集递归整个 `node.data`(当前只扫 `data/url/result`,漏 `items[].src`)
- [x] 同一修复覆盖收藏组(`savedGroups` 走同一个 collect)
- [x] 回归验证:新增 `tests/idb-gc-plugin-refs-test.js`(源码契约:保留集必须递归 node.data、不得回退三字段写法)
- [x] `npm run verify:ci` 通过(33 e2e / 全部单测)
### P1 插件:状态可见与固化幂等
- [x] 条目徽标:已固化 / 仅引用 / 网络未固化 / 丢失
- [x] 「固化 N」的 N 只统计 `__file` 条目;批量时跳过已固化并提示「已跳过 N 张」
- [x] 单删与清空时清理 `ctx.files` 里的缩略图(当前泄漏)
- [x] 单测/自检:插件 validate 通过,缩略图文件数不再随删除增长
### P2 插件:文件夹模式
- [x] `node.data.folder = { path }`、`node.data.sourceMode = 'mixed' | 'folder'`、`node.data.folderSkip = [path]`
- [x] 两个开关:`单图任务`(原一图一任务)、`文件夹监控`;文件夹模式加一行模式说明
- [x] 文件夹模式隐藏:添加图片 / 文件夹 / 粘贴 / 固化;保留:刷新 / 全部重载 / 更换文件夹 / 密度
- [x] 「刷新」= 增量 diff(按文件名排序、尊重 folderSkip、保留勾选与当前页)
- [x] 「全部重载」= 二次确认 → 清空 items 与 folderSkip → 全量重扫(失败时不动 items)
- [x] 底部显示文件夹路径 + 已忽略 N 张
- [x] 文件夹不可用(跨机/掉线)时:条目标失联、禁用刷新、给出提示
- [ ] 上限说明:`listImages` 只递归 1 层、最多 500 张(UI 提示)
### P3 宿主(可选,本轮不做)
- [ ] `ctx.images.importUrl(url)`(纯 URL 拖放)
- [ ] `ctx.clipboard.readImage()`(粘贴按钮)
## 2. 复查记录
### P0(2026-11-30)
- 改动:`app.js` 的 `wCleanIdb` 保留集从 `for (const f of ['data','url','result']) collect(d[f])` 改为 `collect((n && n.data) || {})`;收藏组同一处同步。
- 新增测试:`tests/idb-gc-plugin-refs-test.js`(3 条断言:递归 node.data、不得回退三字段、收藏组同样递归)。
- 实测依据:存档里 18 个相册 `{__blob}` 条目中 **16 个已无 assets 登记**(被当孤儿删),仅 2 个存活且 45/63KB。
- 门禁:`npm run verify:ci` EXIT=0。
- 遗留:真机需验证「固化→关画板→等 30s→重开图仍在」,由构建机下一轮验证。
(每完成一阶段追加:做了什么 / 实测数据 / 遗留问题)
### P1(2026-11-30)
- 改动(插件 album/src/index.js + styles.css):
- 格子左下角来源徽标 iwb-album-src:已固化 / 引用 / 网络 / 丢失(丢失用危险色)
- 「固化 N」只统计本地路径引用;批量结束后提示「已跳过 N 张(已固化或非本地引用)」
- 单删与清空时调用 dropThumbFile 清 ctx.files 缩略图(原来只删条目)
- 复查:插件 validate 15/15;桌面仓 verify:ci EXIT=0(含 plugin-scale-contract,新增 CSS 已改用 design-token 闭集)。
### P2(2026-11-30)
- 数据:data.sourceMode(mixed/folder)、data.folder.path、data.folderSkip(上限 500)。
- UI:两个开关(单图任务 / 文件夹监控)+ 模式说明行;文件夹模式隐藏 添加/粘贴/固化/+添加 格,显示 刷新 / 全部重载,文件夹按钮文案变 更换文件夹;底部显示路径与「已忽略 N 张」。
- 逻辑:refreshFolder 增量 diff(排序 + 跳过忽略名单 + 保留勾选/页码);reloadFolder 二次确认后清空 items 与忽略名单重扫;文件夹不可用时只提示、不动 items;drop 在文件夹模式直接忽略。
- 复查:check:plugins 通过(13 个插件一致);桌面仓 verify:ci EXIT=0。
- 遗留:① listImages 的「1 层 / 500 张」上限未做 UI 提示;② 真机验收待构建机执行。
### 待真机验收(构建机)
- 固化 → 关画板 → 等 30s GC → 重开:图仍在(P0 核心验收)
- 文件夹模式:加 3 张 → 刷新出现;删 1 张 → 刷新不回来且显示「已忽略 1 张」;全部重载 → 回来且勾选重置
- 文件夹模式:拖拽 / 粘贴 / 添加按钮均不存在;+添加 格不出现
## 3. 优化总结
### 做了什么
| 层 | 改动 | 收益 |
| --- | --- | --- |
| 宿主 | wCleanIdb 保留集递归整个 node.data(含收藏组) | 相册/插件节点的 blob 引用不再被当孤儿删;实测 18 个条目曾丢 16 个 |
| 宿主 | 新增 tests/idb-gc-plugin-refs-test.js | 防回退到「只扫 data/url/result」 |
| 插件 | 来源徽标 + 固化计数/跳过 + 删除清缩略图 | 状态可见、固化幂等、ctx.files 不再累积 |
| 插件 | 文件夹模式(手动刷新 / 全部重载 / 忽略名单) | 目录驱动工作流,且不与网络/粘贴来源混用 |
### 风险与边界
- 文件夹模式依赖绝对路径,天然是本机语义;画布同步到另一台机时该目录不可用,条目显示失联(已给提示,不删条目)。
- listImages 只递归 1 层、最多 500 张;超出部分不会出现在相册里。
- 同名文件被替换不会自动检测(readDir 不带 mtime),需手动刷新并触发缩略图重读。
- P3(importUrl / 粘贴按钮)本轮未做;网络图目前仍靠「从网页拖入(WebKit 物化成 File)」这条路,进入相册时即固化为 blob 引用。
### 后续建议
1. 真机验收通过后再发版;若 P0 生效,可考虑把「固化」从手动改为添加时即固化(需先确认大图导入的内存峰值)。
2. listImages 的 500/1 层限制若要放开,需宿主支持分页列举或 Rust 侧 watcher。
3. 文件夹模式的同名替换检测若要支持,需批量 stat 取 mtime(成本见方案分析)。
(全部完成后填写:改动清单、收益、风险、后续建议)
+1 -1
View File
@@ -22,7 +22,7 @@
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (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 **8,329 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **25.6%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,162 行**(上限 **2,179**,余量 17;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **119** 个模块 / 24,161 行,`sourceModules` 119 项;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 **8,328 行**(**双层预算**:绝对上限 8,329 / 占总源码 ≤ 40%,现 **25.6%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,162 行**(上限 **2,179**,余量 17;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **119** 个模块 / 24,161 行,`sourceModules` 119 项;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 实测)
+1 -1
View File
@@ -10,7 +10,7 @@
"app:build": "tauri build",
"lint": "eslint src app.js",
"test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js",
"test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tesLine truncated
"test:unit": "node tests/result-img-doubleclick-test.js && node tests/gallery-audit-test.js && node tests/plugin-files-policy-test.js && node tests/theme-plugin-tokens-test.js && node tests/design-tokens-component-doc-test.js && node tests/theme-static-snapshot-test.js && node tests/overlay-layer-test.js && node tests/settings-scope-test.js && node tests/node-scope-test.js && node tests/appearance-v2-test.js && node tests/image-prompt-cover-test.js && node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/album-task-graph-test.js && node tests/generation-endpoint-test.js && node tests/storage-config-shape-test.js && node tests/generation-default-model-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/gallery-sync-test.js && node tests/image-blob-store-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/clipboard-native-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/plugin-data-test.js && node tests/plugin-loader-test.js && node tests/plugin-bundle-test.js && node tests/plugin-install-test.js && node tests/plugin-gallery-render-test.js && node tests/plugin-gallery-recovery-test.js && node tests/plugin-gallery-ux-test.js && node tests/plugin-grouplib-render-test.js && node tests/plugin-promptlib-render-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/plugin-theme-contract-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/native-overlay-park-test.js && node tests/ui-dock-sanitize-test.js && node tests/ui-minimap-fit-test.js && node tests/ui-workbench-hooks-test.js && node tests/plugin-scale-contract-test.js && node tesLine truncated
"test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js",
"test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js",
"plugins:gc": "node scripts/plugins-publish.mjs --gc",
+138 -11
View File
@@ -184,7 +184,19 @@
}
const bar = el('div', { className: 'iwb-album-bar' })
const track = el('span', { className: 'iwb-album-track' }, el('i', null))
const modeLabel = el('label', { className: 'iwb-album-toggle' }, track, document.createTextNode('一图一任务'))
const modeLabel = el('label', { className: 'iwb-album-toggle' }, track, document.createTextNode('单图任务'))
// v1.2.0:文件夹监控开关(桌面端才有路径能力)
const fTrack = el('span', { className: 'iwb-album-track' }, el('i', null))
const folderLabel = el('label', { className: 'iwb-album-toggle iwb-album-folder-toggle' }, fTrack, document.createTextNode('文件夹监控'))
folderLabel.addEventListener('pointerdown', (e) => e.stopPropagation())
folderLabel.addEventListener('click', (e) => {
e.stopPropagation()
const cur = st.node || node
const d = (cur && cur.data) || {}
const next = d.sourceMode === 'folder' ? 'mixed' : 'folder'
update(st.props || props, cur, { sourceMode: next })
if (next === 'folder' && !folderOf(cur)) pickFolderForMonitor(ctx, st)
})
modeLabel.addEventListener('pointerdown', (e) => e.stopPropagation())
modeLabel.addEventListener('click', (e) => {
e.stopPropagation()
@@ -199,18 +211,23 @@
// 一键清空(2026-11-26 用户需求):只清本节点持有的 items,删源文件与画布存储一概不碰。
// 走 snapshot:true ⇒ ⌘Z 能整批恢复,所以不加二次确认弹窗(多一步点击反而更烦)。
const btnClear = el('button', { className: 'iwb-album-btn iwb-album-clear', title: '清空相册(⌘Z 可撤销;不会删除磁盘上的原文件)' }, '清空')
bar.appendChild(modeLabel); bar.appendChild(count); bar.appendChild(btnClear)
bar.appendChild(modeLabel); bar.appendChild(folderLabel); bar.appendChild(count); bar.appendChild(btnClear)
const btnAdd = el('button', { className: 'iwb-album-btn', title: '选择本地图片(桌面端只引用,不复制字节)' }, '+ 添加图片')
const btnDir = el('button', { className: 'iwb-album-btn', title: '按文件夹批量添加' }, '文件夹')
const btnSettle = el('button', { className: 'iwb-album-btn', title: '把引用复制进画布存储(删源文件/分享画布前用)' }, '固化')
// v1.2.0:文件夹模式专用(手动刷新,不做自动监听)
const btnRefresh = el('button', { className: 'iwb-album-btn', title: '重新读取文件夹:新增的加入、消失的移除(尊重忽略名单)' }, '刷新')
const btnReload = el('button', { className: 'iwb-album-btn', title: '清空忽略名单并整本重新读取(会重置勾选)' }, '全部重载')
const folderNote = el('div', { className: 'iwb-album-foldernote' }, '文件夹监控:只读该目录 · 拖拽 / 粘贴 / 添加已隐藏')
const folderPath = el('div', { className: 'iwb-album-folderpath' })
const seg = el('span', { className: 'iwb-album-seg' })
const segs = {}
for (const key of ['S', 'M', 'L']) {
const s = onTap(el('span', { title: key === 'S' ? '小格(默认)' : (key === 'M' ? '中格' : '大格') }, key), () => update(st.props || props, st.node || node, { density: key }))
segs[key] = s; seg.appendChild(s)
}
const tools = el('div', { className: 'iwb-album-tools' }, [btnAdd, btnDir, btnSettle, seg])
const tools = el('div', { className: 'iwb-album-tools' }, [btnAdd, btnDir, btnSettle, btnRefresh, btnReload, seg])
const hint = el('div', { className: 'iwb-album-hint' })
const grid = el('div', { className: 'iwb-album-grid' })
@@ -225,9 +242,9 @@
// 现在只看大图走「点击放大镜 → 宿主全屏预览(props.onPreview)」,点图片外或 Esc 自动退出。
host.textContent = ''
const root = el('div', { className: 'iwb-album' }, [bar, tools, hint, grid, empty, pager, onepage])
const root = el('div', { className: 'iwb-album' }, [bar, folderNote, tools, hint, grid, empty, pager, onepage, folderPath])
host.appendChild(root)
Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint })
Object.assign(st, { root, bar, track, count, btnClear, btnAdd, btnDir, btnSettle, segs, grid, empty, pager, onepage, hint, modeLabel, folderLabel, fTrack, btnRefresh, btnReload, folderNote, folderPath })
// 按钮绑定(用闭包里的当前 node/props:每次 sync 会更新 st.node/st.props)
btnAdd.addEventListener('pointerdown', (e) => e.stopPropagation())
@@ -236,6 +253,10 @@
btnDir.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, host, true) })
btnSettle.addEventListener('pointerdown', (e) => e.stopPropagation())
btnSettle.addEventListener('click', (e) => { e.stopPropagation(); settleAll(ctx, st) })
btnRefresh.addEventListener('pointerdown', (e) => e.stopPropagation())
btnRefresh.addEventListener('click', (e) => { e.stopPropagation(); refreshFolder(ctx, st) })
btnReload.addEventListener('pointerdown', (e) => e.stopPropagation())
btnReload.addEventListener('click', (e) => { e.stopPropagation(); reloadFolder(ctx, st) })
btnClear.addEventListener('pointerdown', (e) => e.stopPropagation())
btnClear.addEventListener('click', (e) => { e.stopPropagation(); clearAll(ctx, st) })
@@ -243,12 +264,83 @@
host.addEventListener('dragover', (e) => { e.preventDefault(); e.stopPropagation() })
host.addEventListener('drop', (e) => {
e.preventDefault(); e.stopPropagation()
if (isFolderMode(st.node)) return // 文件夹模式禁止其它来源,避免混源
const files = Array.from((e.dataTransfer && e.dataTransfer.files) || [])
if (files.length) importDropped(ctx, st, files)
})
return st
}
// ── 文件夹模式(v1.2.0)──────────────────────────────────
// 只做手动刷新:不做文件监听(用户已确认,避免性能开销)。
function isFolderMode (node) { return ((node && node.data) || {}).sourceMode === 'folder' }
function folderOf (node) { const f = ((node && node.data) || {}).folder; return (f && typeof f.path === 'string') ? f.path : '' }
function skipOf (node) { const v = ((node && node.data) || {}).folderSkip; return Array.isArray(v) ? v.filter((x) => typeof x === 'string') : [] }
async function pickFolderForMonitor (ctx, st) {
try {
const picked = await ctx.images.pick({ multiple: false, directory: true })
const dir = (picked && picked[0]) || ''
if (!dir) return
update(st.props, st.node, { folder: { path: dir } }, true)
st.sig = ''
sync(ctx, st, st.node, st.props)
await refreshFolder(ctx, st)
} catch (e) { /* 用户取消 */ }
}
// 刷新 = 增量 diff:按文件名排序、尊重忽略名单、保留勾选与当前页
async function refreshFolder (ctx, st) {
if (st.busy) return
const node = st.node
const dir = folderOf(node)
if (!dir) { st.hint.textContent = '尚未选择文件夹'; st.hint.style.display = ''; return }
st.busy = '刷新…'; st.sig = ''; sync(ctx, st, node, st.props)
let files = []
try { files = await ctx.images.listImages(dir) } catch (e) { files = [] }
st.busy = ''
if (!files || !files.length) {
st.sig = ''; sync(ctx, st, node, st.props)
st.hint.textContent = '文件夹不可用或没有图片(未改动现有条目)'
st.hint.style.display = ''
return
}
const skip = new Set(skipOf(node).map((x) => normPath(x)))
const want = files.filter((f) => !skip.has(normPath(f))).sort((a, b) => normPath(a).localeCompare(normPath(b)))
const items = itemsOf(node).slice()
const byPath = new Map()
for (const it of items) { const p0 = fileRefOf(it && it.src); if (p0) byPath.set(normPath(p0), it) }
const next = []
for (const f of want) {
const hit = byPath.get(normPath(f))
if (hit) { next.push(hit); continue }
const ref = await ctx.images.reference(f)
if (ref && ref.ok) next.push({ src: { __file: ref.item.path }, name: ref.item.name, size: ref.item.size, mtime: ref.item.mtime, on: true })
}
const capNow = (st.cap && st.cap.capacity) || 20
const pageNow = Math.max(0, Number(((node && node.data) || {}).page) || 0)
const pagesNow = Math.max(1, Math.ceil(next.length / capNow))
update(st.props, node, { items: next, page: Math.min(pageNow, pagesNow - 1) }, true)
st.checkedMissing = false
st.sig = ''
sync(ctx, st, node, st.props)
}
// 全部重载 = 清空忽略名单 + 整本重读(会重置勾选与页码)
async function reloadFolder (ctx, st) {
const node = st.node
const dir = folderOf(node)
if (!dir) return
if (typeof confirm === 'function' && !confirm('将清空忽略名单并重新读取文件夹,确定?')) return
const files = await ctx.images.listImages(dir).catch(() => [])
if (!files || !files.length) { st.hint.textContent = '文件夹不可用,未改动现有条目'; st.hint.style.display = ''; return }
update(st.props, node, { folderSkip: [], items: [], page: 0 }, true)
st.checkedMissing = false
st.sig = ''
sync(ctx, st, node, st.props)
await refreshFolder(ctx, st)
}
// ── 同步(宿主每次重渲染都会调用;必须可增量)──────────────────
function sync (ctx, st, node, props) {
st.node = node; st.props = props
@@ -280,8 +372,23 @@
st.count.appendChild(el('b', null, String(selected)))
st.count.appendChild(document.createTextNode('/' + items.length + ' · 每页 ' + cap.capacity))
for (const k in st.segs) st.segs[k].className = (density === k ? 'on' : '')
const hasFileRef = items.some((it) => fileRefOf(it && it.src))
st.btnSettle.style.display = hasFileRef ? '' : 'none'
// v1.2.0:按模式切换可见控件(不适用的一律隐藏,不置灰)
const folderMode = isFolderMode(node)
const fileCount = items.filter((it) => fileRefOf(it && it.src)).length
st.btnSettle.textContent = fileCount ? ('固化 ' + fileCount) : '固化'
st.btnSettle.style.display = (!folderMode && fileCount) ? '' : 'none'
st.btnAdd.style.display = folderMode ? 'none' : ''
st.btnRefresh.style.display = folderMode ? '' : 'none'
st.btnReload.style.display = folderMode ? '' : 'none'
st.btnDir.textContent = folderMode ? '更换文件夹' : '文件夹'
st.folderNote.style.display = folderMode ? '' : 'none'
st.folderLabel.classList.toggle('on', folderMode)
st.folderPath.style.display = folderMode ? '' : 'none'
if (folderMode) {
const dir = folderOf(node)
const skipped = skipOf(node).length
st.folderPath.textContent = '文件夹:' + (dir || '(未选择)') + (skipped ? (' · 已忽略 ' + skipped + ' 张') : '')
}
// 「文件夹」只在能做路径引用的宿主里有意义(桌面端)。旧写法 `canReference() || true` 恒真,
// 于是在不支持路径引用的宿主里点它永远没反应(这类宿主仍可用「+ 添加图片」走文件选择器)。
const canRef = !!(ctx.images && typeof ctx.images.canReference === 'function' && ctx.images.canReference())
@@ -344,7 +451,7 @@
} else {
st.grid.style.display = ''; st.empty.style.display = 'none'
for (let i = from; i < to; i++) st.grid.appendChild(cellOf(ctx, st, items[i], i, mode))
if (to - from < cap.capacity) {
if (to - from < cap.capacity && !isFolderMode(st.node)) {
const add = el('button', { className: 'iwb-album-cell iwb-album-add', title: '添加图片' }, [el('b', null, '+'), el('span', null, '添加')])
add.addEventListener('click', (e) => { e.stopPropagation(); pickFiles(ctx, st, st.root, false) })
st.grid.appendChild(add)
@@ -413,6 +520,11 @@
else loadThumb(ctx, st, it, key).then((u) => { if (u && img.isConnected) applyThumb(u) })
btn.appendChild(img)
btn.appendChild(el('span', { className: 'iwb-album-idx' }, String(index + 1)))
// v1.2.0:来源徽标(左下角)。让“是否已固化”可见,避免用户靠按钮有无去猜。
const srcState = missing ? '丢失'
: (path ? '引用'
: ((typeof src === 'string' && /^https?:/i.test(src)) ? '网络' : '已固化'))
btn.appendChild(el('span', { className: 'iwb-album-src' + (missing ? ' is-missing' : '') }, srcState))
// 批次角标(右上角那个「1」)已删除:顶栏「N 张 → M 个任务」已经说清楚,角标是重复信息,
// 还会和删除按钮抢同一个角。位置让给了 ×。
const del = el('span', { className: 'iwb-album-del', title: '移除(不删除磁盘上的原文件)' }, '×')
@@ -420,13 +532,25 @@
del.addEventListener('click', (e) => {
e.stopPropagation()
const items = itemsOf(st.node).slice()
const removed = items[index]
items.splice(index, 1)
// 删除后留在当前页(旧实现硬编码 page:0,第 2 页删一张直接跳回第 1 页)。
// 只做「页数变少时往回收」,正常情况 page 不动。
const capNow = st.cap || { capacity: 20 }
const pagesNow = Math.max(1, Math.ceil(items.length / capNow.capacity))
const pageNow = Math.max(0, Number((st.node.data || {}).page) || 0)
update(st.props, st.node, { items: items, page: Math.min(pageNow, pagesNow - 1) }, true)
const patch = { items: items, page: Math.min(pageNow, pagesNow - 1) }
// v1.2.0:文件夹模式下手动删除要记进忽略名单,否则下次刷新又回来
const rmPath = fileRefOf(removed && removed.src)
if (isFolderMode(st.node) && rmPath) {
const skip = skipOf(st.node).slice()
if (skip.indexOf(rmPath) < 0) skip.push(rmPath)
patch.folderSkip = skip.slice(-500)
}
// v1.2.0:清掉该条目的缩略图文件(原来只删条目,ctx.files 里会越积越多)
try { dropThumbFile(ctx, thumbKeyOf(removed)) } catch (e) { /* ignore */ }
st.thumbs.delete(thumbKeyOf(removed))
update(st.props, st.node, patch, true)
})
btn.appendChild(del)
// 放大镜(右下角):点开插件自带的全屏查看器,可 ← → 切换整本相册(1.1.2)。
@@ -709,6 +833,7 @@
function clearAll (ctx, st) {
const items = itemsOf(st.node)
if (!items.length) return
for (const it of items) { try { dropThumbFile(ctx, thumbKeyOf(it)) } catch (e) { /* ignore */ } }
st.thumbs.clear(); st.pending.clear(); st.missing.clear(); if (st.forceThumbs) st.forceThumbs.clear()
st.checkedMissing = false // 清空后再导入要重新做一次失联检测
closeViewer(st) // 正在看大图时清空 ⇒ 先把浮层收掉(别留个没有数据的空查看器)
@@ -848,10 +973,11 @@
async function settleAll (ctx, st) {
const items = itemsOf(st.node).slice()
let done = 0
let skipped = 0
for (let i = 0; i < items.length; i++) {
const it = items[i]
const path = fileRefOf(it && it.src)
if (!path) continue
if (!path) { skipped++; continue } // 已固化/网络图:跳过,不重复读字节
st.busy = '固化 ' + (++done) + '…'; st.sig = ''; sync(ctx, st, st.node, st.props)
try {
const res = await ctx.images.importPath(path, { keepOriginal: (st.node.data && st.node.data.keepOriginal !== false) })
@@ -862,6 +988,7 @@
update(st.props, st.node, { items }, true)
st.sig = ''
sync(ctx, st, st.node, st.props)
if (skipped) { st.hint.textContent = '已跳过 ' + skipped + ' 张(已固化或非本地引用)'; st.hint.style.display = '' }
}
async function checkMissing (ctx, st, items) {
@@ -904,7 +1031,7 @@
global.IWBPluginHost.register({
id: 'album',
name: '相册',
version: '1.1.6',
version: '1.2.0',
apiVersion: 1,
capabilities: ['nodeTypes', 'images', 'files'],
settings: {
+3 -3
View File
@@ -1,7 +1,7 @@
{
"id": "album",
"name": "相册",
"version": "1.1.6",
"version": "1.2.0",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -14,7 +14,7 @@
"出图"
],
"files": {
"main.js": "c60ddff7a9200f8b74ff7519506be1748205b5172b104ed0e1ce84c747b4f650",
"styles.css": "f8af2310bc5fe099f726f05b5234f928fe31a651f2143c96c88e474b9797fdf7"
"main.js": "b4bfb32bea448f8fe712e761b87c0ebb3b933e215412220b75992d4a686c6b08",
"styles.css": "d3ca8439b6786bf9e0cdb9203ffe27a1e654d79717c5a11cc95cb47cfad632ed"
}
}
+6
View File
@@ -37,6 +37,12 @@
.iwb-album-cell:hover { transform: scale(1.08); outline: 2px solid var(--iwb-hover-border, var(--iwb-brand)); outline-offset: -2px; box-shadow: 0 10px 26px rgba(0, 0, 0, .42), 0 2px 6px rgba(0, 0, 0, .28); z-index: var(--iwb-z-ctx, 90); }
@media (prefers-reduced-motion: reduce) { .iwb-album-cell { transition: none; } .iwb-album-cell:hover { transform: none; } }
.iwb-album-cell img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-drag: none; }
/* v1.2.0:来源徽标 + 文件夹模式说明/路径 */
.iwb-album-src { position: absolute; left: var(--iwb-space-4); bottom: var(--iwb-space-4); padding: 0 var(--iwb-space-4); border-radius: var(--iwb-radius-chip); font-size: var(--iwb-font-xs); line-height: 1.2; background: color-mix(in srgb, var(--iwb-text) 62%, transparent); color: var(--iwb-bg); pointer-events: none; }
.iwb-album-src.is-missing { background: color-mix(in srgb, var(--iwb-danger, #d33) 78%, transparent); color: var(--iwb-bg); }
.iwb-album-foldernote { font-size: var(--iwb-font-xs); color: var(--iwb-text2); padding: 0 var(--iwb-space-2); }
.iwb-album-folderpath { font-size: var(--iwb-font-xs); color: var(--iwb-text2); padding: var(--iwb-space-2); word-break: break-all; opacity: .9; }
.iwb-album-folder-toggle.on .iwb-album-track i { transform: translateX(10px); }
.iwb-album-cell.off img { opacity: .38; }
/* 选中线 2px → 1px(用户:太粗)。1px 在浅底上仍分得清「选中」与「描边」。 */
.iwb-album-cell.sel { outline: 1px solid var(--iwb-brand); outline-offset: -1px; }
+3 -3
View File
@@ -4,10 +4,10 @@
"dir": "album",
"main": "main.js",
"style": "styles.css",
"version": "1.1.6",
"version": "1.2.0",
"files": {
"main.js": "c60ddff7a9200f8b74ff7519506be1748205b5172b104ed0e1ce84c747b4f650",
"styles.css": "f8af2310bc5fe099f726f05b5234f928fe31a651f2143c96c88e474b9797fdf7"
"main.js": "b4bfb32bea448f8fe712e761b87c0ebb3b933e215412220b75992d4a686c6b08",
"styles.css": "d3ca8439b6786bf9e0cdb9203ffe27a1e654d79717c5a11cc95cb47cfad632ed"
}
},
{
+21
View File
@@ -0,0 +1,21 @@
/* idb-gc-plugin-refs-test.js —— IndexedDB 图片 GC 必须保住插件节点里的引用(v3.26.116)
*
* 事故:相册把图固化成 {__blob} 存在 node.data.items[].src,而 wCleanIdb 的保留集只扫
* node.data 的 data / url / result 三个字段 ⇒ 这些 blob 被当孤儿删掉,重开画板只剩缩略图
* (实测 18 个条目丢 16 个)。这里钉住「保留集必须递归整个 node.data」。
*/
'use strict'
const fs = require('node:fs')
const path = require('node:path')
const assert = require('node:assert')
const APP = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8')
const body = APP.slice(APP.indexOf('async function wCleanIdb'), APP.indexOf('const keys = await IDB.keys()'))
assert.ok(body.length > 200, '找不到 wCleanIdb 实现')
assert.ok(/collect\(\(n && n\.data\) \|\| \{\}\)/.test(body), '① 画布节点必须递归整个 node.data(否则 items[].src 漏掉)')
assert.ok(!/\['data', 'url', 'result'\]/.test(body), '② 不得回退到「只扫 data/url/result」的旧写法')
assert.ok(/savedGroups/.test(body) && /collect\(\(n && n\.data\) \|\| \{\}\)/.test(body), '③ 收藏组也要递归整个 node.data')
console.log('idb-gc-plugin-refs: 3 通过 / 0 失败')