dsh-gallery 0.14.3 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cordis.patch.yml CHANGED
@@ -1,4 +1,4 @@
1
- # 产出画廊:右侧栏「产出画廊」tab 的 Host 半部(扫描 + /api 路由)。
1
+ # 产出台:右侧栏「产出台」tab 的 Host 半部(扫描 + /api 路由)。
2
2
  # 浏览器半部由 package.json 的 dsh.client 清单发现,并通过 ./client 导出。
3
3
  #
4
4
  # ⚠️ 顶层必须是「数组」,首项是 - insert:。写成对象(insert: 直接顶格)会导致 patch 无法加载,
@@ -102,6 +102,24 @@ export function makeItem(item) {
102
102
  frameMs: Number(item.frameOf.frameMs) || 0,
103
103
  }
104
104
  }
105
+ // v0.14.5 遮罩来源:由本条框选区域生成的 RGBA 遮罩资产,路径只随草稿带出
106
+ // v0.14.6 右键多边形:把外接框 / 顶点像素坐标 / 面积一并带出,供 Agent 精确回填。
107
+ if (item?.maskOf !== undefined && item?.maskOf !== null && typeof item.maskOf === 'object') {
108
+ out.maskOf = {
109
+ relPath: String(item.maskOf.relPath ?? ''),
110
+ sourceName: String(item.maskOf.sourceName ?? ''),
111
+ region: item.maskOf.region ?? null,
112
+ polygon: Array.isArray(item.maskOf.polygon) ? item.maskOf.polygon : null,
113
+ polygonPx: Array.isArray(item.maskOf.polygonPx) ? item.maskOf.polygonPx : null,
114
+ bboxPx: Array.isArray(item.maskOf.bboxPx) ? item.maskOf.bboxPx : null,
115
+ areaPx: Number(item.maskOf.areaPx) || 0,
116
+ imageWidth: Number(item.maskOf.imageWidth) || 0,
117
+ imageHeight: Number(item.maskOf.imageHeight) || 0,
118
+ // v0.14.7 彩色填充预览图:只用于目视核对,工作流仍用主 alpha 遮罩
119
+ overlayRelPath: String(item.maskOf.overlayRelPath ?? ''),
120
+ fillColor: String(item.maskOf.fillColor ?? ''),
121
+ }
122
+ }
105
123
  return out
106
124
  }
107
125
 
@@ -155,7 +173,7 @@ export function renderFeedbackText(feedback, options) {
155
173
  lines.push('Reply item by item using the `Annotation N:` prefix, so each decision maps to one annotation.')
156
174
  lines.push('')
157
175
  } else {
158
- lines.push(`【产出画廊反馈 · 共 ${items.length} 条】`)
176
+ lines.push(`【产出台反馈 · 共 ${items.length} 条】`)
159
177
  lines.push('')
160
178
  lines.push('请按 `Annotation 1:`、`Annotation 2:` … 逐条回应,让每条决定都对应到一个批注。')
161
179
  lines.push('')
@@ -178,6 +196,31 @@ export function renderFeedbackText(feedback, options) {
178
196
  ? `Frame source: taken from "${f.videoName}" at ${f.timecode} (${f.frameMs} ms)`
179
197
  : `帧来源:取自视频《${f.videoName}》${f.timecode}(第 ${f.frameMs} 毫秒)`)
180
198
  }
199
+ // 遮罩来源是「资产路径 + 编码说明」,不是自动指令:模型拿到后自行上传 / 回填 image 输入
200
+ if (item.maskOf !== undefined && item.maskOf !== null && String(item.maskOf.relPath ?? '') !== '') {
201
+ lines.push(locale === 'en'
202
+ ? `Mask source: ${item.maskOf.relPath} — RGBA mask from this box; alpha=0 inside the box, so ComfyUI LoadImage MASK (1 - alpha/255) marks only the area to inpaint`
203
+ : `遮罩来源:${item.maskOf.relPath} —— 由本条框选区域生成的 RGBA 遮罩,框内 alpha=0,ComfyUI LoadImage 的 MASK 输出(1 - alpha/255)即待重绘区域;可用于局部重绘 / 移除流回填 image 输入`)
204
+ const mp = item.maskOf
205
+ // v0.14.7 彩色填充预览图:只供人核对选区位置,别拿去回填工作流
206
+ if (String(mp.overlayRelPath ?? '') !== '') {
207
+ const fillName = { green: '绿', red: '红', blue: '蓝' }[String(mp.fillColor ?? '')] ?? '绿'
208
+ lines.push(locale === 'en'
209
+ ? `Mask preview: ${mp.overlayRelPath} — original image with a solid semi-transparent fill over the selection; visual check only, hand the RGBA mask above to the workflow`
210
+ : `遮罩预览:${mp.overlayRelPath} —— 原图上叠加${fillName}色半透明填充,仅用于目视核对选区位置;工作流请用上面的 RGBA 遮罩`)
211
+ }
212
+ if (Array.isArray(mp.polygonPx) && mp.polygonPx.length > 0) {
213
+ const b = Array.isArray(mp.bboxPx) ? mp.bboxPx : [0, 0, 0, 0]
214
+ const size = `${Number(mp.imageWidth) || 0}×${Number(mp.imageHeight) || 0}`
215
+ const verts = JSON.stringify(mp.polygonPx)
216
+ lines.push(locale === 'en'
217
+ ? `Mask region: ${size}px source · ${mp.polygonPx.length} vertices · bbox (${b[0]},${b[1]})-(${b[2]},${b[3]}) · ~${Number(mp.areaPx) || 0}px · vertex pixels ${verts}`
218
+ : `遮罩区域:原图 ${size}px · ${mp.polygonPx.length} 个顶点 · 外接框 (${b[0]},${b[1]})-(${b[2]},${b[3]}) · 面积约 ${Number(mp.areaPx) || 0}px · 顶点像素坐标 ${verts}`)
219
+ lines.push(locale === 'en'
220
+ ? 'Mask handoff: upload it, then replace the target workflow image input; use ONE short target phrase (e.g. change "X" to "Y", keep the original lettering), do not expand into a whole-word rewrite with extra constraints'
221
+ : '遮罩回填:上传后替换目标工作流的 image 入参;提示词用单目标短句(例如:将图中的「X」,改为「Y」,保持原有字体色调),不要扩写成整词替换加约束')
222
+ }
223
+ }
181
224
  if (item.reason !== undefined) {
182
225
  lines.push(`${locale === 'en' ? 'Reason' : '理由'}:${item.reason}`)
183
226
  }
package/host/frames.js CHANGED
@@ -113,3 +113,62 @@ export function makeFrameName(videoName, frameMs, suffix = '') {
113
113
  const safe = raw.replace(/[\\/:*?"<>|\r\n\t]/g, '_').replace(/\s+/g, ' ').trim().slice(0, 80) || 'video'
114
114
  return `${safe}_帧_${frameTimecode(frameMs)}${suffix}.png`
115
115
  }
116
+
117
+ /**
118
+ * 遮罩文件名(v0.14.5):`<原图名>_遮罩_x<左>-y<上>-w<宽>-h<高>.png`。
119
+ * 坐标用归一化百分比整数,肉眼就能看出框选位置;同框重复导出加 -2 / -3,不覆盖旧遮罩。
120
+ * 复用 frames.json 登记(kind:'mask'),扫描时据此把遮罩挂回产出它的当前对话。
121
+ */
122
+ export function makeMaskName(imageName, region, suffix = '') {
123
+ const raw = String(imageName ?? 'image').replace(/\.[^.]+$/, '')
124
+ const safe = raw.replace(/[\\/:*?"<>|\r\n\t]/g, '_').replace(/\s+/g, ' ').trim().slice(0, 60) || 'image'
125
+ const pct = (v) => {
126
+ const n = Number(v)
127
+ if (!Number.isFinite(n)) return 0
128
+ return Math.round(Math.min(1, Math.max(0, n)) * 100)
129
+ }
130
+ const r = region ?? {}
131
+ return `${safe}_遮罩_x${pct(r.x)}-y${pct(r.y)}-w${pct(r.w)}-h${pct(r.h)}${suffix}.png`
132
+ }
133
+
134
+ /**
135
+ * 多边形遮罩元数据(v0.14.6):校验归一化顶点(4–20 点),换算成原图像素坐标,
136
+ * 并给出外接框与选区面积。老板要的「记录这个区域在图片的准确位置」就落在这里——
137
+ * 像素坐标只在 Host 侧按原图真实尺寸计算,前端显示的百分比不作为准。
138
+ * 返回 null 表示不合法,调用方直接 400,绝不把脏坐标写进 frames.json。
139
+ */
140
+ export function maskPolygonMeta(polygon, width, height) {
141
+ if (!Array.isArray(polygon) || polygon.length < 4 || polygon.length > 20) return null
142
+ const w = Math.max(1, Math.round(Number(width) || 0))
143
+ const h = Math.max(1, Math.round(Number(height) || 0))
144
+ const pts = []
145
+ for (const p of polygon) {
146
+ const nx = Number(Array.isArray(p) ? p[0] : p?.x)
147
+ const ny = Number(Array.isArray(p) ? p[1] : p?.y)
148
+ if (!Number.isFinite(nx) || !Number.isFinite(ny)) return null
149
+ if (nx < 0 || nx > 1 || ny < 0 || ny > 1) return null
150
+ pts.push([Math.round(nx * w), Math.round(ny * h)])
151
+ }
152
+ const xs = pts.map((p) => p[0])
153
+ const ys = pts.map((p) => p[1])
154
+ // 右/下用开区间(与 PIL getbbox 一致),草稿里 (x0,y0)-(x1,y1) 才不会少算一列/一行。
155
+ const bboxPx = [
156
+ Math.min(...xs), Math.min(...ys),
157
+ Math.min(w, Math.max(...xs) + 1), Math.min(h, Math.max(...ys) + 1),
158
+ ]
159
+ let sum = 0
160
+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i, i += 1) {
161
+ sum += (pts[j][0] * pts[i][1]) - (pts[i][0] * pts[j][1])
162
+ }
163
+ return {
164
+ polygon: polygon.map((p) => [
165
+ Number(Array.isArray(p) ? p[0] : p.x),
166
+ Number(Array.isArray(p) ? p[1] : p.y),
167
+ ]),
168
+ polygonPx: pts,
169
+ bboxPx,
170
+ areaPx: Math.round(Math.abs(sum) / 2),
171
+ imageWidth: w,
172
+ imageHeight: h,
173
+ }
174
+ }
package/host/http.js CHANGED
@@ -34,7 +34,7 @@ import { resolveReadable, serveMedia, contentTypeFor } from './media.js'
34
34
  import { MARK_ACTIONS, readMarks, writeMarks, setMark, setMarksBatch, marksFilePath } from './marks.js'
35
35
  import { LABEL_CATEGORIES, readLabels, setLabel, setLabelsBatch, deleteLabels } from './labels.js'
36
36
  import {
37
- registerFrame, deleteFrames, frameTimecode, makeFrameName,
37
+ registerFrame, deleteFrames, frameTimecode, makeFrameName, makeMaskName, maskPolygonMeta,
38
38
  } from './frames.js'
39
39
 
40
40
  /** reveal 相关的排查日志(失败/异常时便于定位,不影响功能)。 */
@@ -687,6 +687,172 @@ export function registerOpsRoute(ctx, config) {
687
687
  })
688
688
  }
689
689
 
690
+ // ---- v0.14.5 矩形框选批注 → ComfyUI 可用 RGBA 遮罩 ----
691
+ // 前端已按「框内 alpha=0、框外 255、RGB 保留原图」编码好 PNG;
692
+ // 这里只负责安全落盘 + 登记当前对话,不解析像素、不请求 ComfyUI。
693
+ if (op === 'saveMask') {
694
+ const opts = resolveOptions(config)
695
+ const imageRel = String(body?.path ?? '').replace(/\\/g, '/')
696
+ const data = typeof body?.data === 'string' ? body.data : ''
697
+ const region = body?.region
698
+ if (imageRel === '' || data === '') {
699
+ return json({ ok: false, error: { code: 'bad-request', message: '缺少 path 或 data' } }, 400)
700
+ }
701
+ const keys = ['x', 'y', 'w', 'h']
702
+ const validRegion = region !== null && typeof region === 'object'
703
+ && keys.every((k) => {
704
+ const n = Number(region[k])
705
+ return Number.isFinite(n) && n >= 0 && n <= 1
706
+ })
707
+ && Number(region.w) > 0 && Number(region.h) > 0
708
+ if (!validRegion) {
709
+ return json({ ok: false, error: { code: 'bad-request', message: 'region 不合法' } }, 400)
710
+ }
711
+ const normRegion = {
712
+ x: Number(region.x), y: Number(region.y),
713
+ w: Number(region.w), h: Number(region.h),
714
+ }
715
+ // v0.14.6 右键多边形:多边形仍然保留 region bbox(兼容旧文件名与旧遮罩),
716
+ // 额外登记顶点像素坐标 / 外接框 / 面积;顶点不合法直接 400,不落脏数据。
717
+ const polygonMeta = body?.polygon === undefined || body?.polygon === null
718
+ ? null
719
+ : maskPolygonMeta(body.polygon, body?.width, body?.height)
720
+ if (body?.polygon !== undefined && body?.polygon !== null && polygonMeta === null) {
721
+ return json({ ok: false, error: { code: 'bad-request', message: 'polygon 不合法(需 4–20 个归一化顶点与有效原图尺寸)' } }, 400)
722
+ }
723
+
724
+ // 源图必须真实存在于扫描目录内;同时拿到它所属的 root 以反算 relPath。
725
+ let imageAbs = null
726
+ let ownerRoot = null
727
+ for (const root of opts.roots) {
728
+ if (typeof root !== 'string' || root === '') continue
729
+ const abs = path.resolve(root, imageRel)
730
+ if (!isInside(root, abs)) continue
731
+ try {
732
+ const st = await fsp.stat(abs)
733
+ if (st.isFile()) { imageAbs = abs; ownerRoot = root; break }
734
+ } catch { /* 换下一个 root */ }
735
+ }
736
+ if (imageAbs === null) {
737
+ return json({ ok: false, error: { code: 'image-not-found', message: '源图不在扫描目录内' } }, 404)
738
+ }
739
+
740
+ const buf = Buffer.from(data, 'base64')
741
+ if (buf.length < 8 || buf.length > 24 * 1024 * 1024) {
742
+ return json({ ok: false, error: { code: 'bad-png', message: 'PNG 数据为空或超过 24 MB' } }, 400)
743
+ }
744
+ // PNG 魔数:不允许把任意 base64 写进资产目录
745
+ if (!(buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47)) {
746
+ return json({ ok: false, error: { code: 'bad-png', message: '数据不是 PNG' } }, 400)
747
+ }
748
+
749
+ // v0.14.7 彩色填充预览图:与主遮罩同样只认 PNG / 24 MB。
750
+ // 颜色和中文标签都走白名单,避免把任意字符串拼进文件名。
751
+ const overlayData = typeof body?.overlay === 'string' ? body.overlay : ''
752
+ let overlayBuf = null
753
+ const overlayColor = ['green', 'red', 'blue'].includes(String(body?.fillColor ?? ''))
754
+ ? String(body.fillColor) : 'green'
755
+ const overlayLabel = ['绿', '红', '蓝'].includes(String(body?.fillLabel ?? ''))
756
+ ? String(body.fillLabel) : '绿'
757
+ if (overlayData !== '') {
758
+ overlayBuf = Buffer.from(overlayData, 'base64')
759
+ const isPng = overlayBuf[0] === 0x89 && overlayBuf[1] === 0x50
760
+ && overlayBuf[2] === 0x4e && overlayBuf[3] === 0x47
761
+ if (overlayBuf.length < 8 || overlayBuf.length > 24 * 1024 * 1024 || !isPng) {
762
+ return json({ ok: false, error: { code: 'bad-png', message: '预览图数据为空、不是 PNG 或超过 24 MB' } }, 400)
763
+ }
764
+ }
765
+
766
+ const dir = path.dirname(imageAbs)
767
+ const imageName = path.basename(imageAbs)
768
+ // 多边形遮罩文件名带「多边形」,与矩形遮罩一眼可分;重复导出仍加 -2 / -3。
769
+ const baseSuffix = polygonMeta === null ? '' : '-多边形'
770
+ let name = makeMaskName(imageName, normRegion, baseSuffix)
771
+ let abs = path.join(dir, name)
772
+ // 同一个框重复导出:不覆盖旧遮罩,依次加 -2 / -3 …
773
+ let n = 2
774
+ while (n <= 99) {
775
+ let exists = true
776
+ try { await fsp.access(abs) } catch { exists = false }
777
+ if (!exists) break
778
+ name = makeMaskName(imageName, normRegion, `${baseSuffix}-${n}`)
779
+ abs = path.join(dir, name)
780
+ n += 1
781
+ }
782
+ if (!isInside(ownerRoot, abs)) {
783
+ return json({ ok: false, error: { code: 'outside-roots', message: '目标路径越出扫描目录' } }, 400)
784
+ }
785
+
786
+ // 原子写:先落到 .tmp 再改名,避免扫描读到半截 PNG
787
+ const tmp = `${abs}.tmp-${process.pid}-${Date.now().toString(36)}`
788
+ try {
789
+ await fsp.mkdir(dir, { recursive: true })
790
+ await fsp.writeFile(tmp, buf)
791
+ await fsp.rename(tmp, abs)
792
+ } catch (error) {
793
+ try { await fsp.rm(tmp, { force: true }) } catch { /* 忽略 */ }
794
+ return json({ ok: false, error: { code: 'mask-write-failed', message: String(error?.message ?? error) } }, 500)
795
+ }
796
+
797
+ const relPath = path.relative(ownerRoot, abs).split(path.sep).join('/')
798
+
799
+ // v0.14.7 彩色填充预览:与主遮罩同目录、独立文件,不登记成遮罩帧。
800
+ // 它会按「同目录外部素材」规则自动出现在当前对话并标为素材,方便目视核对选区。
801
+ let overlayRelPath = ''
802
+ let overlayNameFinal = ''
803
+ if (overlayBuf !== null) {
804
+ const stem = name.replace(/\.png$/i, '')
805
+ let oName = `${stem}_${overlayLabel}填充预览.png`
806
+ let oAbs = path.join(dir, oName)
807
+ let k = 2
808
+ while (k <= 99) {
809
+ let exists = true
810
+ try { await fsp.access(oAbs) } catch { exists = false }
811
+ if (!exists) break
812
+ oName = `${stem}_${overlayLabel}填充预览-${k}.png`
813
+ oAbs = path.join(dir, oName)
814
+ k += 1
815
+ }
816
+ if (isInside(ownerRoot, oAbs)) {
817
+ const oTmp = `${oAbs}.tmp-${process.pid}-${Date.now().toString(36)}`
818
+ try {
819
+ await fsp.writeFile(oTmp, overlayBuf)
820
+ await fsp.rename(oTmp, oAbs)
821
+ overlayNameFinal = oName
822
+ overlayRelPath = path.relative(ownerRoot, oAbs).split(path.sep).join('/')
823
+ } catch {
824
+ try { await fsp.rm(oTmp, { force: true }) } catch { /* 忽略 */ }
825
+ // 预览图是附加产物,写失败不影响主遮罩成功
826
+ }
827
+ }
828
+ }
829
+
830
+ try {
831
+ await registerFrame(opts.settingsFile, {
832
+ kind: 'mask',
833
+ relPath,
834
+ sessionId: String(body?.sessionId ?? ''),
835
+ sessionTitle: String(body?.sessionTitle ?? ''),
836
+ sessionCreatedAt: Number(body?.sessionCreatedAt) || 0,
837
+ sourceRelPath: imageRel,
838
+ sourceName: imageName,
839
+ region: normRegion,
840
+ ...(polygonMeta ?? {}),
841
+ ...(overlayRelPath !== '' ? { overlayRelPath, fillColor: overlayColor } : {}),
842
+ })
843
+ } catch (error) {
844
+ return json({ ok: false, error: { code: 'mask-register-failed', message: String(error?.message ?? error) } }, 500)
845
+ }
846
+
847
+ // 新资产要立刻出现在列表里,不能等 4 秒缓存过期
848
+ listCache.clear()
849
+ return json({
850
+ ok: true, relPath, absPath: abs, name, region: normRegion,
851
+ ...(polygonMeta ?? {}),
852
+ ...(overlayRelPath !== '' ? { overlayRelPath, overlayName: overlayNameFinal } : {}),
853
+ })
854
+ }
855
+
690
856
  // ---- 标记(S3-a)----
691
857
  if (op === 'getMarks') {
692
858
  const settingsFile = resolveOptions(config).settingsFile
package/host/scan.js CHANGED
@@ -16,6 +16,20 @@ import { readLabels, LABEL_CATEGORIES } from './labels.js'
16
16
  import { readFrames } from './frames.js'
17
17
  import { buildSessionIndex, readSessionStates } from './session-index.js'
18
18
 
19
+ /**
20
+ * v0.14.7:相对路径的父目录(统一小写;空串表示文件直接躺在 root 下)。
21
+ * 当前对话据此判断「外部图片是否和本对话用过的资产在同一目录」。
22
+ */
23
+ export function parentDirOf(relPath) {
24
+ const p = String(relPath ?? '').replace(/\\/g, '/').toLowerCase()
25
+ return p.includes('/') ? p.slice(0, p.lastIndexOf('/')) : ''
26
+ }
27
+
28
+ /** v0.14.7:当前对话分类。日志/登记里没有的、同目录外部图片自动标「素材」(input)。 */
29
+ export function categoryForSessionAsset(autoCategory, externalAsset) {
30
+ return autoCategory ?? (externalAsset ? ASSET_CATEGORY.INPUT : null)
31
+ }
32
+
19
33
  export function extractAssetInfo(logText, sessionStartMs = 0) {
20
34
  const assets = new Map()
21
35
  if (typeof logText !== 'string' || logText === '') return assets
@@ -206,6 +220,9 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
206
220
  const normalized = []
207
221
  const relPaths = []
208
222
  const taskDirs = new Set()
223
+ // v0.14.7:会话引用过的「精确目录」(相对 root、小写,空串表示 root 直属层)。
224
+ // 外部拷进同一目录、没被日志引用的图片,也要能在「当前对话」里看到并标为素材。
225
+ const sessionDirs = new Set()
209
226
  // relPath(小写) → 分类,供扫描时标注
210
227
  const categoryByRel = new Map()
211
228
 
@@ -224,6 +241,7 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
224
241
  const relPath = rel.split(path.sep).join('/')
225
242
  relPaths.push(relPath)
226
243
  categoryByRel.set(relPath.toLowerCase(), info.category)
244
+ sessionDirs.add(parentDirOf(relPath))
227
245
  // 修法 B:有子目录时取第一层;没有子目录(文件直接在 root 下)时,
228
246
  // 用空字符串占位,表示「只在根目录层匹配」,不再直接丢弃
229
247
  if (segs.length >= 2) taskDirs.add(segs[0])
@@ -236,6 +254,7 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
236
254
  paths: normalized,
237
255
  relPaths,
238
256
  categoryByRel,
257
+ sessionDirs: [...sessionDirs],
239
258
  subSessions: subLogs.length,
240
259
  }
241
260
  }
@@ -282,11 +301,15 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
282
301
  // 当前对话范围:先解析会话日志(含子智能体会话),得到「本对话产出过的路径」
283
302
  let scopeInfo = { ok: true, reason: 'global', taskDirs: [], paths: [], relPaths: [], subSessions: 0 }
284
303
  let sessionRelSet = null
304
+ // v0.14.7:会话引用过的目录集合。同目录下的外部图片也纳入「当前对话」,
305
+ // 但不在精确路径白名单里 —— 它们会被自动标为「素材」(input)。
306
+ let sessionDirSet = null
285
307
  if (isSession) {
286
308
  scopeInfo = await resolveSessionScope(config, sessionId, opts.roots)
287
309
  // 修法 B:用「精确相对路径」集合判定,而不是只靠第一层目录名。
288
310
  // 这样既能处理有子目录的情况,也能处理「文件直接躺在 root 根目录下」。
289
311
  sessionRelSet = new Set((scopeInfo.relPaths ?? []).map((p) => p.toLowerCase()))
312
+ sessionDirSet = new Set((scopeInfo.sessionDirs ?? []).map((d) => String(d).toLowerCase()))
290
313
  // 会话日志缺失时 resolveSessionScope 可能不带分类表,补一个空的
291
314
  if (!(scopeInfo.categoryByRel instanceof Map)) scopeInfo.categoryByRel = new Map()
292
315
  // 本对话截出来的帧:让它通过范围过滤,并给一个明确标签
@@ -294,6 +317,7 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
294
317
  if (String(f.sessionId ?? '') === sessionId) {
295
318
  sessionRelSet.add(rel)
296
319
  scopeInfo.categoryByRel?.set(rel, ASSET_CATEGORY.INTERMEDIATE)
320
+ sessionDirSet.add(parentDirOf(rel))
297
321
  }
298
322
  }
299
323
  }
@@ -330,6 +354,38 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
330
354
  }
331
355
  }
332
356
 
357
+ // v0.14.8:全局资产下「当前对话」组也要认出外部素材。
358
+ // 旧逻辑只在 scope=session 算 sessionDirs;全局模式只认会话日志 / frames.json
359
+ // 精确引用过的文件,同目录里外部放进来、没被引用过的图全掉进「历史资产」
360
+ // 并标「未归类」——界面上就表现为「当前对话」组只有几张过程稿、素材数为 0。
361
+ // 这里复用与「当前对话」视图完全相同的目录判定,把无归属的同目录图片
362
+ // 挂回当前对话组并标 input(素材);其它对话 / 历史资产一律不动。
363
+ let globalCurrentDirs = null
364
+ let globalCurrentMeta = null
365
+ if (!isSession && sessionId !== '') {
366
+ const current = await resolveSessionScope(config, sessionId, opts.roots)
367
+ if (current.ok) {
368
+ const dirs = new Set((current.sessionDirs ?? []).map((d) => String(d).toLowerCase()))
369
+ // 本对话截帧 / 遮罩的登记目录也算(与 session 模式保持一致)
370
+ for (const [rel, f] of frameByRel) {
371
+ if (String(f.sessionId ?? '') === sessionId) dirs.add(parentDirOf(rel))
372
+ }
373
+ globalCurrentDirs = dirs
374
+ // 会话索引里可能没有该会话(日志里没有落在扫描目录内的产出),
375
+ // 这时组名会退化成 sessionId 前 8 位。frames.json 的登记带会话标题,补上。
376
+ const indexed = sessionIndex?.get(sessionId) ?? null
377
+ let title = String(indexed?.title ?? '')
378
+ let createdAt = Number(indexed?.createdAt) || 0
379
+ for (const [, f] of frameByRel) {
380
+ if (String(f.sessionId ?? '') !== sessionId) continue
381
+ if (title === '') title = String(f.sessionTitle ?? '')
382
+ if (createdAt === 0) createdAt = Number(f.sessionCreatedAt) || 0
383
+ if (title !== '' && createdAt !== 0) break
384
+ }
385
+ globalCurrentMeta = { title, createdAt }
386
+ }
387
+ }
388
+
333
389
  // 已隐藏的路径:扫描时直接跳过(不移动文件,只从列表里拿掉)
334
390
  const hiddenSet = new Set(await readHiddenList(opts.settingsFile))
335
391
 
@@ -392,7 +448,13 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
392
448
  if (!extSet.has(ext)) continue
393
449
  // 当前对话范围:按精确相对路径判定(支持根目录文件与多层子目录)
394
450
  const relPath = path.relative(rootDir, fullPath).split(path.sep).join('/')
395
- if (sessionRelSet !== null && !sessionRelSet.has(relPath.toLowerCase())) continue
451
+ // 当前对话:精确路径白名单优先;不在白名单但落在「本对话用过的目录」里,
452
+ // 视作外部放进来的素材放行(v0.14.7)。其它目录一律不进当前对话。
453
+ let externalAsset = false
454
+ if (sessionRelSet !== null && !sessionRelSet.has(relPath.toLowerCase())) {
455
+ if (sessionDirSet === null || !sessionDirSet.has(parentDirOf(relPath))) continue
456
+ externalAsset = true
457
+ }
396
458
  let stat
397
459
  try {
398
460
  stat = await fsp.stat(fullPath)
@@ -413,6 +475,8 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
413
475
  size: stat.size,
414
476
  mtime: stat.mtimeMs,
415
477
  extension: ext,
478
+ // v0.14.7:外部素材标记,扫描阶段据此给出「素材」标签
479
+ ...(externalAsset ? { externalAsset: true } : {}),
416
480
  // 音视频区分「视频 / 音频」,客户端据此选 <video> 还是 <audio>
417
481
  ...(isMedia ? { mediaType: VIDEO_EXTS.includes(ext) ? 'video' : 'audio' } : {}),
418
482
  })
@@ -433,8 +497,27 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
433
497
  for (const item of matches) {
434
498
  const abs = path.join(item.rootDir, ...item.relPath.split('/'))
435
499
  const frame = frameByRel.get(item.relPath.toLowerCase())
436
- // 帧来源元数据透传到卡片 / 反馈篮,草稿里才能写清「取自哪段视频的哪一帧」
437
- if (frame !== undefined) {
500
+ // 帧 / 遮罩来源元数据透传到卡片 / 反馈篮,草稿里才能写清来源。
501
+ // 遮罩是「由某张原图的框选区域生成」的新资产(kind:'mask'),
502
+ // 原图的反馈条目靠 maskOf.sourceRelPath 反查到它,路径随草稿带出、零自动发送。
503
+ if (frame?.kind === 'mask') {
504
+ item.maskOf = {
505
+ relPath: String(item.relPath ?? ''),
506
+ sourceRelPath: String(frame.sourceRelPath ?? ''),
507
+ sourceName: String(frame.sourceName ?? ''),
508
+ region: frame.region ?? null,
509
+ // v0.14.6 右键多边形:像素级位置信息透传到反馈草稿
510
+ polygon: Array.isArray(frame.polygon) ? frame.polygon : null,
511
+ polygonPx: Array.isArray(frame.polygonPx) ? frame.polygonPx : null,
512
+ bboxPx: Array.isArray(frame.bboxPx) ? frame.bboxPx : null,
513
+ areaPx: Number(frame.areaPx) || 0,
514
+ imageWidth: Number(frame.imageWidth) || 0,
515
+ imageHeight: Number(frame.imageHeight) || 0,
516
+ // v0.14.7 彩色填充预览图路径 + 颜色,随草稿带出(工作流仍用主遮罩)
517
+ overlayRelPath: String(frame.overlayRelPath ?? ''),
518
+ fillColor: String(frame.fillColor ?? ''),
519
+ }
520
+ } else if (frame !== undefined) {
438
521
  item.frameOf = {
439
522
  videoName: String(frame.videoName ?? ''),
440
523
  videoRelPath: String(frame.videoRelPath ?? ''),
@@ -456,16 +539,28 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
456
539
  const owner = ownerByAbs.get(abs) ?? virtualOwner
457
540
  item.absPath = abs
458
541
  if (isSession) {
459
- item.category = (scopeInfo.categoryByRel?.get(item.relPath.toLowerCase())) ?? null
542
+ const autoCategory = scopeInfo.categoryByRel?.get(item.relPath.toLowerCase())
543
+ // 外部放进本对话目录、日志里没引用的图 → 自动标「素材」(input)。
544
+ // 手动改过的标签在下面仍然优先覆盖,刷新/重扫/重启都不回退。
545
+ item.category = categoryForSessionAsset(autoCategory, item.externalAsset)
460
546
  item.sessionId = sessionId
461
547
  } else if (owner !== undefined) {
462
548
  item.category = owner.category
463
549
  item.sessionId = owner.sessionId
464
550
  item.sessionTitle = owner.title
465
551
  item.sessionCreatedAt = owner.createdAt
552
+ } else if (globalCurrentDirs !== null && globalCurrentDirs.has(parentDirOf(item.relPath))) {
553
+ // v0.14.8 全局模式:外部放进本对话目录、日志与登记都没引用的图片。
554
+ // 与「当前对话」视图同一口径:挂回当前对话组 + 自动标「素材」(input)。
555
+ // 只对「不属于任何已知对话」的条目生效,绝不抢别的对话已引用的文件。
556
+ item.category = ASSET_CATEGORY.INPUT
557
+ item.externalAsset = true
558
+ item.sessionId = sessionId
559
+ item.sessionTitle = globalCurrentMeta?.title ?? ''
560
+ item.sessionCreatedAt = globalCurrentMeta?.createdAt ?? 0
466
561
  } else {
467
- // 不属于任何已知对话的文件:归到「历史资产」,分类记为**未归类**
468
- // 不能兜底成 input —— 那会把 4995 个历史文件全标成「输入」
562
+ // 不属于任何已知对话、也不在当前对话目录里的文件:归到「历史资产」,
563
+ // 分类记为**未归类**。不能兜底成 input —— 那会把几千个历史文件全标成「输入」
469
564
  item.category = ASSET_CATEGORY.UNKNOWN
470
565
  item.sessionId = null
471
566
  }
@@ -546,6 +641,11 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
546
641
  relPaths: (scopeInfo.relPaths ?? []).length,
547
642
  // 子智能体会话数:> 0 表示已纳入它们的产出
548
643
  subSessions: scopeInfo.subSessions ?? 0,
644
+ // v0.14.7:本对话用过的目录数 / 自动纳入的外部素材数(诊断用)
645
+ // v0.14.8:全局模式另给一份目录数,两种视图口径是否一致一眼可查
646
+ externalDirs: sessionDirSet?.size ?? 0,
647
+ globalExternalDirs: globalCurrentDirs?.size ?? 0,
648
+ externalAssets: matches.reduce((n, i) => n + (i.externalAsset ? 1 : 0), 0),
549
649
  },
550
650
  root: opts.root,
551
651
  roots: opts.roots,
package/icon.svg CHANGED
@@ -1,7 +1,5 @@
1
- <!DOCTYPE html>
2
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="产出画廊">
3
- <rect x="4" y="10" width="56" height="44" rx="8" fill="none" stroke="currentColor" stroke-width="3"/>
4
- <circle cx="22" cy="24" r="4.5" fill="currentColor"/>
5
- <path d="M10 44l12-12 9 9 7-7 12 12" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
6
- <path d="M38 8l3 3 6 0 0 6 3 3-3 3 0 6-6 0-3 3-3-3-6 0 0-6-3-3 3-3 0-6 6 0z" fill="currentColor" opacity=".85"/>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="产出台">
2
+ <path d="M22 8h28a4 4 0 0 1 4 4v24" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" opacity=".55"/>
3
+ <rect x="6" y="16" width="42" height="38" rx="6" fill="none" stroke="currentColor" stroke-width="4"/>
4
+ <path d="M15 35l6 6 12-13" fill="none" stroke="currentColor" stroke-width="4.5" stroke-linecap="round" stroke-linejoin="round"/>
7
5
  </svg>
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 产出画廊 · DSH 插件 —— Host 半入口。
2
+ * 产出台 · DSH 插件 —— Host 半入口。
3
3
  *
4
4
  * S1 拆分后本文件只做三件事:
5
5
  * 1. 声明 inject
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "产出画廊",
3
+ "title": "产出台",
4
4
  "description": "解决 DSH 只在任务结尾才列出产出、过程不可见的问题:实时监控产出目录,图片自动刷新、文件原生预览、音视频面板内直接播放(支持 HTTP Range,任意大小都能拖进度条),任务进行中就能校验纠正。自动标签(成稿/过程稿/素材)之上还有一层人的表态(已定稿/要重做/留档),结论落盘、可筛可批量,且优先于机器预判;图上圈选批注并入反馈篮,攒成决策草稿由人确认后送回对话。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-gallery",
3
- "version": "0.14.3",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
- "description": "产出画廊:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产,反馈能精确指到某一帧。Output gallery for DeepSeek Harness: live image/file/audio/video preview, persistent manual asset labels, region annotations and label changes queued in a human-approved feedback basket, one-click video frame capture filed into the current session.",
5
+ "description": "产出台:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产;图上左键画矩形框、右键多点闭合成实心多边形,可导出 ComfyUI 直接可用的 RGBA 遮罩(选区内 alpha=0、RGB 保留原图),另出红 / 绿 / 蓝纯色半透明填充预览图供目视核对;把图拖进对话框会自动带上文件名与绝对路径(含对应主遮罩名),Agent 不必扫目录找图;批注框跟随图片缩放平移,标注态按住鼠标中键可平移且框不脱框。Output gallery for DeepSeek Harness: live image/file/audio/video preview, persistent manual asset labels, region annotations and label changes queued in a human-approved feedback basket, one-click video frame capture filed into the current session, rectangle and multi-point polygon selections exported as ComfyUI-ready RGBA masks (alpha=0 inside the selection, original RGB kept) plus a colored translucent fill preview, drag-to-chat that carries the file name and absolute path so agents need no directory scan; annotation boxes follow image zoom/pan, and holding the middle mouse button pans the image while annotating without losing the boxes.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
@@ -70,7 +70,16 @@
70
70
  "batch",
71
71
  "region-selection",
72
72
  "annotation",
73
- "frame-capture"
73
+ "frame-capture",
74
+ "annotation-follow",
75
+ "middle-mouse-pan",
76
+ "polygon-selection",
77
+ "mask-export",
78
+ "rgba-mask",
79
+ "comfyui",
80
+ "inpainting",
81
+ "drag-metadata",
82
+ "external-assets"
74
83
  ],
75
84
  "publishConfig": {
76
85
  "access": "public",