dsh-gallery 0.14.4 → 0.16.2

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/host/scan.js CHANGED
@@ -16,6 +16,35 @@ 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
+ }
33
+
34
+ /**
35
+ * 登记条目自带分类(v0.16.1)。
36
+ *
37
+ * frames.json 原本只登记截帧,截帧一律算「过程稿」(intermediate)。v0.16.1 起
38
+ * 粘贴 / 裁剪也登记——它们是从外部拿进来的素材或切出来的片段,必须算「素材」
39
+ * (input),否则界面上跟截帧混成一堆过程稿,老板分不清哪个能直接喂给工作流。
40
+ * 未知/缺省值仍回落到 intermediate,保持截帧原有行为不变。
41
+ */
42
+ function frameCategoryOf(frame) {
43
+ const c = String(frame?.category ?? '')
44
+ if (c === ASSET_CATEGORY.INPUT || c === ASSET_CATEGORY.FINAL || c === ASSET_CATEGORY.UNKNOWN) return c
45
+ return ASSET_CATEGORY.INTERMEDIATE
46
+ }
47
+
19
48
  export function extractAssetInfo(logText, sessionStartMs = 0) {
20
49
  const assets = new Map()
21
50
  if (typeof logText !== 'string' || logText === '') return assets
@@ -206,6 +235,17 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
206
235
  const normalized = []
207
236
  const relPaths = []
208
237
  const taskDirs = new Set()
238
+ // v0.14.7:会话引用过的「精确目录」(相对 root、小写,空串表示 root 直属层)。
239
+ // 外部拷进同一目录、没被日志引用的图片,也要能在「当前对话」里看到并标为素材。
240
+ const sessionDirs = new Set()
241
+ /**
242
+ * v0.16.2:同一批目录的**绝对路径**(保留原始大小写)。
243
+ *
244
+ * 只留相对路径时,Host 拼目录只能赌「属于第一个 root」—— 本机有两个产出根
245
+ * (G:/DSH产出、G:/DSH任务文件),会话只用了第二个时就会拼到第一个根下,
246
+ * mkdir 造出一个空目录,粘贴的资产凭空消失。这里把根一起记下来。
247
+ */
248
+ const sessionDirsAbs = new Set()
209
249
  // relPath(小写) → 分类,供扫描时标注
210
250
  const categoryByRel = new Map()
211
251
 
@@ -224,6 +264,8 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
224
264
  const relPath = rel.split(path.sep).join('/')
225
265
  relPaths.push(relPath)
226
266
  categoryByRel.set(relPath.toLowerCase(), info.category)
267
+ sessionDirs.add(parentDirOf(relPath))
268
+ sessionDirsAbs.add(path.dirname(absolute))
227
269
  // 修法 B:有子目录时取第一层;没有子目录(文件直接在 root 下)时,
228
270
  // 用空字符串占位,表示「只在根目录层匹配」,不再直接丢弃
229
271
  if (segs.length >= 2) taskDirs.add(segs[0])
@@ -236,6 +278,8 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
236
278
  paths: normalized,
237
279
  relPaths,
238
280
  categoryByRel,
281
+ sessionDirs: [...sessionDirs],
282
+ sessionDirsAbs: [...sessionDirsAbs],
239
283
  subSessions: subLogs.length,
240
284
  }
241
285
  }
@@ -282,18 +326,23 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
282
326
  // 当前对话范围:先解析会话日志(含子智能体会话),得到「本对话产出过的路径」
283
327
  let scopeInfo = { ok: true, reason: 'global', taskDirs: [], paths: [], relPaths: [], subSessions: 0 }
284
328
  let sessionRelSet = null
329
+ // v0.14.7:会话引用过的目录集合。同目录下的外部图片也纳入「当前对话」,
330
+ // 但不在精确路径白名单里 —— 它们会被自动标为「素材」(input)。
331
+ let sessionDirSet = null
285
332
  if (isSession) {
286
333
  scopeInfo = await resolveSessionScope(config, sessionId, opts.roots)
287
334
  // 修法 B:用「精确相对路径」集合判定,而不是只靠第一层目录名。
288
335
  // 这样既能处理有子目录的情况,也能处理「文件直接躺在 root 根目录下」。
289
336
  sessionRelSet = new Set((scopeInfo.relPaths ?? []).map((p) => p.toLowerCase()))
337
+ sessionDirSet = new Set((scopeInfo.sessionDirs ?? []).map((d) => String(d).toLowerCase()))
290
338
  // 会话日志缺失时 resolveSessionScope 可能不带分类表,补一个空的
291
339
  if (!(scopeInfo.categoryByRel instanceof Map)) scopeInfo.categoryByRel = new Map()
292
- // 本对话截出来的帧:让它通过范围过滤,并给一个明确标签
340
+ // 本对话派生出来的资产(截帧 / 粘贴 / 裁剪):让它通过范围过滤,并给一个明确标签
293
341
  for (const [rel, f] of frameByRel) {
294
342
  if (String(f.sessionId ?? '') === sessionId) {
295
343
  sessionRelSet.add(rel)
296
- scopeInfo.categoryByRel?.set(rel, ASSET_CATEGORY.INTERMEDIATE)
344
+ scopeInfo.categoryByRel?.set(rel, frameCategoryOf(f))
345
+ sessionDirSet.add(parentDirOf(rel))
297
346
  }
298
347
  }
299
348
  }
@@ -330,6 +379,38 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
330
379
  }
331
380
  }
332
381
 
382
+ // v0.14.8:全局资产下「当前对话」组也要认出外部素材。
383
+ // 旧逻辑只在 scope=session 算 sessionDirs;全局模式只认会话日志 / frames.json
384
+ // 精确引用过的文件,同目录里外部放进来、没被引用过的图全掉进「历史资产」
385
+ // 并标「未归类」——界面上就表现为「当前对话」组只有几张过程稿、素材数为 0。
386
+ // 这里复用与「当前对话」视图完全相同的目录判定,把无归属的同目录图片
387
+ // 挂回当前对话组并标 input(素材);其它对话 / 历史资产一律不动。
388
+ let globalCurrentDirs = null
389
+ let globalCurrentMeta = null
390
+ if (!isSession && sessionId !== '') {
391
+ const current = await resolveSessionScope(config, sessionId, opts.roots)
392
+ if (current.ok) {
393
+ const dirs = new Set((current.sessionDirs ?? []).map((d) => String(d).toLowerCase()))
394
+ // 本对话截帧 / 遮罩的登记目录也算(与 session 模式保持一致)
395
+ for (const [rel, f] of frameByRel) {
396
+ if (String(f.sessionId ?? '') === sessionId) dirs.add(parentDirOf(rel))
397
+ }
398
+ globalCurrentDirs = dirs
399
+ // 会话索引里可能没有该会话(日志里没有落在扫描目录内的产出),
400
+ // 这时组名会退化成 sessionId 前 8 位。frames.json 的登记带会话标题,补上。
401
+ const indexed = sessionIndex?.get(sessionId) ?? null
402
+ let title = String(indexed?.title ?? '')
403
+ let createdAt = Number(indexed?.createdAt) || 0
404
+ for (const [, f] of frameByRel) {
405
+ if (String(f.sessionId ?? '') !== sessionId) continue
406
+ if (title === '') title = String(f.sessionTitle ?? '')
407
+ if (createdAt === 0) createdAt = Number(f.sessionCreatedAt) || 0
408
+ if (title !== '' && createdAt !== 0) break
409
+ }
410
+ globalCurrentMeta = { title, createdAt }
411
+ }
412
+ }
413
+
333
414
  // 已隐藏的路径:扫描时直接跳过(不移动文件,只从列表里拿掉)
334
415
  const hiddenSet = new Set(await readHiddenList(opts.settingsFile))
335
416
 
@@ -392,7 +473,13 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
392
473
  if (!extSet.has(ext)) continue
393
474
  // 当前对话范围:按精确相对路径判定(支持根目录文件与多层子目录)
394
475
  const relPath = path.relative(rootDir, fullPath).split(path.sep).join('/')
395
- if (sessionRelSet !== null && !sessionRelSet.has(relPath.toLowerCase())) continue
476
+ // 当前对话:精确路径白名单优先;不在白名单但落在「本对话用过的目录」里,
477
+ // 视作外部放进来的素材放行(v0.14.7)。其它目录一律不进当前对话。
478
+ let externalAsset = false
479
+ if (sessionRelSet !== null && !sessionRelSet.has(relPath.toLowerCase())) {
480
+ if (sessionDirSet === null || !sessionDirSet.has(parentDirOf(relPath))) continue
481
+ externalAsset = true
482
+ }
396
483
  let stat
397
484
  try {
398
485
  stat = await fsp.stat(fullPath)
@@ -413,6 +500,8 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
413
500
  size: stat.size,
414
501
  mtime: stat.mtimeMs,
415
502
  extension: ext,
503
+ // v0.14.7:外部素材标记,扫描阶段据此给出「素材」标签
504
+ ...(externalAsset ? { externalAsset: true } : {}),
416
505
  // 音视频区分「视频 / 音频」,客户端据此选 <video> 还是 <audio>
417
506
  ...(isMedia ? { mediaType: VIDEO_EXTS.includes(ext) ? 'video' : 'audio' } : {}),
418
507
  })
@@ -433,8 +522,29 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
433
522
  for (const item of matches) {
434
523
  const abs = path.join(item.rootDir, ...item.relPath.split('/'))
435
524
  const frame = frameByRel.get(item.relPath.toLowerCase())
436
- // 帧来源元数据透传到卡片 / 反馈篮,草稿里才能写清「取自哪段视频的哪一帧」
437
- if (frame !== undefined) {
525
+ // 帧 / 遮罩来源元数据透传到卡片 / 反馈篮,草稿里才能写清来源。
526
+ // 遮罩是「由某张原图的框选区域生成」的新资产(kind:'mask'),
527
+ // 原图的反馈条目靠 maskOf.sourceRelPath 反查到它,路径随草稿带出、零自动发送。
528
+ if (frame?.kind === 'mask') {
529
+ item.maskOf = {
530
+ relPath: String(item.relPath ?? ''),
531
+ sourceRelPath: String(frame.sourceRelPath ?? ''),
532
+ sourceName: String(frame.sourceName ?? ''),
533
+ region: frame.region ?? null,
534
+ // v0.14.6 右键多边形:像素级位置信息透传到反馈草稿
535
+ polygon: Array.isArray(frame.polygon) ? frame.polygon : null,
536
+ polygonPx: Array.isArray(frame.polygonPx) ? frame.polygonPx : null,
537
+ bboxPx: Array.isArray(frame.bboxPx) ? frame.bboxPx : null,
538
+ areaPx: Number(frame.areaPx) || 0,
539
+ imageWidth: Number(frame.imageWidth) || 0,
540
+ imageHeight: Number(frame.imageHeight) || 0,
541
+ // v0.14.7 彩色填充预览图路径 + 颜色,随草稿带出(工作流仍用主遮罩)
542
+ overlayRelPath: String(frame.overlayRelPath ?? ''),
543
+ fillColor: String(frame.fillColor ?? ''),
544
+ }
545
+ } else if (frame !== undefined && (frame.kind === undefined || frame.kind === 'frame')) {
546
+ // 只有「视频截帧」才带来源视频/时间码。粘贴 / 裁剪(v0.16.1 起也登记)
547
+ // 没有取自哪一帧的概念,误设 frameOf 会让卡片显示「取自《…》」的假来源。
438
548
  item.frameOf = {
439
549
  videoName: String(frame.videoName ?? ''),
440
550
  videoRelPath: String(frame.videoRelPath ?? ''),
@@ -442,7 +552,7 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
442
552
  frameMs: Number(frame.frameMs) || 0,
443
553
  }
444
554
  }
445
- // 截帧不在会话日志里:ownerByAbs 查不到时,用登记里的会话信息补一个虚拟归属。
555
+ // 登记不在会话日志里:ownerByAbs 查不到时,用登记里的会话信息补一个虚拟归属。
446
556
  // 日志里已有归属的文件(例如视频本身)一律沿用原归属,不受影响。
447
557
  const frameSid = String(frame?.sessionId ?? '')
448
558
  const virtualOwner = frame !== undefined && frameSid !== ''
@@ -450,22 +560,35 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
450
560
  sessionId: frameSid,
451
561
  title: String(frame.sessionTitle ?? '') || sessionIndex?.get(frameSid)?.title || '',
452
562
  createdAt: Number(frame.sessionCreatedAt) || sessionIndex?.get(frameSid)?.createdAt || 0,
453
- category: ASSET_CATEGORY.INTERMEDIATE,
563
+ // 截帧 = 过程稿;粘贴 / 裁剪 = 素材(登记里带着 category,缺省回落过程稿)
564
+ category: frameCategoryOf(frame),
454
565
  }
455
566
  : undefined
456
567
  const owner = ownerByAbs.get(abs) ?? virtualOwner
457
568
  item.absPath = abs
458
569
  if (isSession) {
459
- item.category = (scopeInfo.categoryByRel?.get(item.relPath.toLowerCase())) ?? null
570
+ const autoCategory = scopeInfo.categoryByRel?.get(item.relPath.toLowerCase())
571
+ // 外部放进本对话目录、日志里没引用的图 → 自动标「素材」(input)。
572
+ // 手动改过的标签在下面仍然优先覆盖,刷新/重扫/重启都不回退。
573
+ item.category = categoryForSessionAsset(autoCategory, item.externalAsset)
460
574
  item.sessionId = sessionId
461
575
  } else if (owner !== undefined) {
462
576
  item.category = owner.category
463
577
  item.sessionId = owner.sessionId
464
578
  item.sessionTitle = owner.title
465
579
  item.sessionCreatedAt = owner.createdAt
580
+ } else if (globalCurrentDirs !== null && globalCurrentDirs.has(parentDirOf(item.relPath))) {
581
+ // v0.14.8 全局模式:外部放进本对话目录、日志与登记都没引用的图片。
582
+ // 与「当前对话」视图同一口径:挂回当前对话组 + 自动标「素材」(input)。
583
+ // 只对「不属于任何已知对话」的条目生效,绝不抢别的对话已引用的文件。
584
+ item.category = ASSET_CATEGORY.INPUT
585
+ item.externalAsset = true
586
+ item.sessionId = sessionId
587
+ item.sessionTitle = globalCurrentMeta?.title ?? ''
588
+ item.sessionCreatedAt = globalCurrentMeta?.createdAt ?? 0
466
589
  } else {
467
- // 不属于任何已知对话的文件:归到「历史资产」,分类记为**未归类**
468
- // 不能兜底成 input —— 那会把 4995 个历史文件全标成「输入」
590
+ // 不属于任何已知对话、也不在当前对话目录里的文件:归到「历史资产」,
591
+ // 分类记为**未归类**。不能兜底成 input —— 那会把几千个历史文件全标成「输入」
469
592
  item.category = ASSET_CATEGORY.UNKNOWN
470
593
  item.sessionId = null
471
594
  }
@@ -546,6 +669,11 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
546
669
  relPaths: (scopeInfo.relPaths ?? []).length,
547
670
  // 子智能体会话数:> 0 表示已纳入它们的产出
548
671
  subSessions: scopeInfo.subSessions ?? 0,
672
+ // v0.14.7:本对话用过的目录数 / 自动纳入的外部素材数(诊断用)
673
+ // v0.14.8:全局模式另给一份目录数,两种视图口径是否一致一眼可查
674
+ externalDirs: sessionDirSet?.size ?? 0,
675
+ globalExternalDirs: globalCurrentDirs?.size ?? 0,
676
+ externalAssets: matches.reduce((n, i) => n + (i.externalAsset ? 1 : 0), 0),
549
677
  },
550
678
  root: opts.root,
551
679
  roots: opts.roots,
@@ -77,7 +77,7 @@ async function listSessionDirs(sessionsDir) {
77
77
  * @param logText - 解压后的日志文本。
78
78
  * @returns 标题字符串;没有则空串。
79
79
  */
80
- function extractSessionTitle(logText) {
80
+ export function extractSessionTitle(logText) {
81
81
  if (typeof logText !== 'string' || logText === '') return ''
82
82
  // 取最后一个 title(用户可能改过标题)
83
83
  let title = ''
@@ -92,6 +92,39 @@ function extractSessionTitle(logText) {
92
92
  return title
93
93
  }
94
94
 
95
+ /**
96
+ * 同上的省内存版:不 split 全文,只按 `session/title` 命中位置切片。
97
+ *
98
+ * 为什么要它:单个会话日志解压后实测 390 万字符(约 4 MB 字符串),
99
+ * `split('\n')` 会造出十几万个小字符串,在「粘贴一次就读一次标题」这种
100
+ * 热路径上纯属白烧内存。标题事件的位置也不固定(实测出现在第 98121 字符,
101
+ * 既不在开头也不在末尾),所以不能靠截头尾。
102
+ *
103
+ * 语义与 extractSessionTitle 一致:取最后一次出现的标题。
104
+ */
105
+ export function extractSessionTitleFast(logText) {
106
+ if (typeof logText !== 'string' || logText === '') return ''
107
+ const MARK = 'session/title'
108
+ let title = ''
109
+ let pos = 0
110
+ while (pos < logText.length) {
111
+ const hit = logText.indexOf(MARK, pos)
112
+ if (hit < 0) break
113
+ const lineStart = logText.lastIndexOf('\n', hit) + 1
114
+ let lineEnd = logText.indexOf('\n', hit)
115
+ if (lineEnd < 0) lineEnd = logText.length
116
+ pos = lineEnd + 1
117
+ // 一整个会话序列化成一行时该行可能极大,直接跳过,避免解析几 MB 的单行
118
+ if (lineEnd - lineStart > 8192) continue
119
+ let o
120
+ try { o = JSON.parse(logText.slice(lineStart, lineEnd)) } catch { continue }
121
+ if (o?.type !== 'session/title') continue
122
+ const t = o?.data?.title
123
+ if (typeof t === 'string' && t.trim() !== '') title = t.trim()
124
+ }
125
+ return title
126
+ }
127
+
95
128
  /**
96
129
  * 从会话日志首行读元信息(创建时间、cwd、父会话)。
97
130
  * @param logText - 解压后的日志文本。
package/host/trim.js ADDED
@@ -0,0 +1,134 @@
1
+ /**
2
+ * v0.16.0 音视频裁剪核心(从 host/http.js 抽出来,便于真机单测)。
3
+ *
4
+ * 关键事实(实测得出,别凭直觉改):
5
+ * · `-c copy` 只能从**关键帧**起切。6 秒 25fps 的测试片切 1.5–4s,
6
+ * 实际得到 0–4s(时长 4.0 而非 2.5)——起点被拉回到上一个关键帧。
7
+ * · 音频流通常每个包都可切,所以纯音频 copy 基本准确,问题集中在视频。
8
+ * · 因此策略是「先 copy,再用 ffprobe 量真实时长,偏差 > 0.5s 才重编码」:
9
+ * 常见情况仍是秒级无损裁剪,少数少关键帧素材才付重编码代价。
10
+ */
11
+ import { spawn } from 'node:child_process'
12
+ import fsp from 'node:fs/promises'
13
+ import path from 'node:path'
14
+
15
+ const FFMPEG_CANDIDATES = [
16
+ 'G:/Program Files/ffmpeg/bin/ffmpeg.exe',
17
+ 'G:/Program Files (x86)/ffmpeg/bin/ffmpeg.exe',
18
+ ]
19
+
20
+ /** 找 ffmpeg;找不到返回 'ffmpeg',交给 PATH 兜底。 */
21
+ export async function findFfmpeg() {
22
+ for (const c of FFMPEG_CANDIDATES) {
23
+ try {
24
+ const abs = path.resolve(c)
25
+ await fsp.access(abs, 0)
26
+ return abs
27
+ } catch { /* 换下一个 */ }
28
+ }
29
+ return 'ffmpeg'
30
+ }
31
+
32
+ /** 找同目录 ffprobe;找不到返回 null(退化为不做精度校验)。 */
33
+ export async function findFfprobe(ffmpeg) {
34
+ const candidates = []
35
+ if (typeof ffmpeg === 'string' && ffmpeg !== '' && ffmpeg !== 'ffmpeg') {
36
+ const dir = path.dirname(ffmpeg)
37
+ candidates.push(path.join(dir, 'ffprobe.exe'), path.join(dir, 'ffprobe'))
38
+ }
39
+ candidates.push('G:/Program Files/ffmpeg/bin/ffprobe.exe', 'G:/Program Files (x86)/ffmpeg/bin/ffprobe.exe')
40
+ for (const c of candidates) {
41
+ try { await fsp.access(c, 0); return c } catch { /* 换下一个 */ }
42
+ }
43
+ return null
44
+ }
45
+
46
+ /** 跑一次 ffmpeg;收集 stderr,非 0 退出视为失败。 */
47
+ export function runFfmpeg(ffmpeg, args) {
48
+ return new Promise((resolve, reject) => {
49
+ let child
50
+ try { child = spawn(ffmpeg, args, { windowsHide: true }) } catch (err) { reject(err); return }
51
+ let stderr = ''
52
+ child.stderr?.on('data', (d) => { stderr += String(d) })
53
+ child.on('error', (err) => reject(err))
54
+ child.on('close', (code) => {
55
+ if (code === 0) resolve()
56
+ else reject(new Error('ffmpeg exit ' + code + ': ' + stderr.slice(-800)))
57
+ })
58
+ })
59
+ }
60
+
61
+ /** 读媒体时长(秒);任何异常都返回 null,不抛。 */
62
+ export function probeDuration(ffprobe, file) {
63
+ return new Promise((resolve) => {
64
+ let child
65
+ try {
66
+ child = spawn(ffprobe, [
67
+ '-v', 'error', '-show_entries', 'format=duration',
68
+ '-of', 'default=noprint_wrappers=1:nokey=1', file,
69
+ ], { windowsHide: true })
70
+ } catch { resolve(null); return }
71
+ let out = ''
72
+ child.stdout?.on('data', (d) => { out += String(d) })
73
+ child.on('error', () => resolve(null))
74
+ child.on('close', (code) => {
75
+ if (code !== 0) { resolve(null); return }
76
+ const n = Number(String(out).trim())
77
+ resolve(Number.isFinite(n) && n > 0 ? n : null)
78
+ })
79
+ })
80
+ }
81
+
82
+ const AUDIO_EXTS = new Set(['mp3', 'wav', 'm4a', 'aac', 'flac', 'ogg', 'opus'])
83
+
84
+ /** 精度兜底用的重编码参数(按输出容器选编码器,保证扩展名与流匹配)。 */
85
+ export function reencodeArgs(src, start, end, out, outExt, kind) {
86
+ const base = ['-y', '-hide_banner', '-loglevel', 'error', '-ss', String(start), '-to', String(end), '-i', src]
87
+ const ext = String(outExt ?? '').toLowerCase()
88
+ if (AUDIO_EXTS.has(ext) || kind === 'audio') {
89
+ const codec = ext === 'wav' ? ['-c:a', 'pcm_s16le']
90
+ : ext === 'flac' ? ['-c:a', 'flac']
91
+ : (ext === 'ogg' || ext === 'opus') ? ['-c:a', 'libopus', '-b:a', '128k']
92
+ : ext === 'mp3' ? ['-c:a', 'libmp3lame', '-b:a', '192k']
93
+ : ['-c:a', 'aac', '-b:a', '192k']
94
+ return [...base, '-vn', ...codec, out]
95
+ }
96
+ if (ext === 'webm') {
97
+ return [...base, '-c:v', 'libvpx-vp9', '-crf', '32', '-b:v', '0', '-c:a', 'libopus', out]
98
+ }
99
+ return [...base, '-c:v', 'libx264', '-preset', 'veryfast', '-crf', '20',
100
+ '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '160k', '-movflags', '+faststart', out]
101
+ }
102
+
103
+ /**
104
+ * 裁一段音视频并写进 `out`。
105
+ *
106
+ * @returns {{ mode: 'copy'|'reencode'|'copy-keyframe', duration: number|null }}
107
+ * - copy:流拷贝且时长与期望相符(最理想)
108
+ * - reencode:copy 偏差过大,已重编码到精确切点
109
+ * - copy-keyframe:copy 有偏差且重编码失败,保留了可用但不精确的片段
110
+ */
111
+ export async function cropMediaFile({ ffmpeg, src, start, end, out, outExt, kind }) {
112
+ const expected = end - start
113
+ await runFfmpeg(ffmpeg, [
114
+ '-y', '-hide_banner', '-loglevel', 'error',
115
+ '-ss', String(start), '-to', String(end),
116
+ '-i', src,
117
+ '-c', 'copy', '-avoid_negative_ts', 'make_zero',
118
+ out,
119
+ ])
120
+
121
+ const ffprobe = await findFfprobe(ffmpeg)
122
+ if (ffprobe === null || !(expected > 0)) return { mode: 'copy', duration: null }
123
+
124
+ const got = await probeDuration(ffprobe, out)
125
+ if (got === null || Math.abs(got - expected) <= 0.5) return { mode: 'copy', duration: got }
126
+
127
+ try {
128
+ await runFfmpeg(ffmpeg, reencodeArgs(src, start, end, out, outExt, kind))
129
+ const fixed = await probeDuration(ffprobe, out)
130
+ return { mode: 'reencode', duration: fixed }
131
+ } catch {
132
+ return { mode: 'copy-keyframe', duration: got }
133
+ }
134
+ }
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,84 +1,98 @@
1
- {
2
- "name": "dsh-gallery",
3
- "version": "0.14.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; region annotation boxes follow image zoom/pan, and holding the middle mouse button pans the image while annotating without losing the boxes.",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
9
- },
10
- "bugs": {
11
- "url": "https://github.com/Hope2023Dcr/dsh-gallery/issues"
12
- },
13
- "homepage": "https://github.com/Hope2023Dcr/dsh-gallery#readme",
14
- "exports": {
15
- ".": "./index.js",
16
- "./client": "./client.js",
17
- "./locale/*.json": "./locale/*.json",
18
- "./icon": "./icon.svg"
19
- },
20
- "files": [
21
- "install.mjs",
22
- "index.js",
23
- "client.js",
24
- "session-index.js",
25
- "host/*.js",
26
- "cordis.patch.yml",
27
- "locale/*.json",
28
- "icon.svg",
29
- "README.md",
30
- "LICENSE",
31
- "CHANGELOG.md",
32
- "docs/screenshots/*.png"
33
- ],
34
- "dsh": {
35
- "bundle": {
36
- "patch": "./cordis.patch.yml"
37
- },
38
- "client": {
39
- "platform": "web",
40
- "immediately": true,
41
- "inject": [
42
- "@deepseek-ai/dsh-client-ui-sidebar-right",
43
- "@deepseek-ai/dsh-client-locale"
44
- ]
45
- }
46
- },
47
- "author": {
48
- "name": "Hope2023Dcr"
49
- },
50
- "license": "MIT",
51
- "keywords": [
52
- "dsh-plugin",
53
- "deepseek-harness",
54
- "dsh",
55
- "output-gallery",
56
- "image-gallery",
57
- "file-preview",
58
- "sidebar-plugin",
59
- "agent-tools",
60
- "media-gallery",
61
- "video-preview",
62
- "audio-preview",
63
- "range-seek",
64
- "filter",
65
- "deliverable",
66
- "human-in-the-loop",
67
- "asset-tags",
68
- "manual-label",
69
- "feedback-basket",
70
- "batch",
71
- "region-selection",
72
- "annotation",
73
- "frame-capture",
74
- "annotation-follow",
75
- "middle-mouse-pan"
76
- ],
77
- "publishConfig": {
78
- "access": "public",
79
- "registry": "https://registry.npmjs.org/"
80
- },
81
- "engines": {
82
- "node": ">=20"
83
- }
84
- }
1
+ {
2
+ "name": "dsh-gallery",
3
+ "version": "0.16.2",
4
+ "type": "module",
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
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/Hope2023Dcr/dsh-gallery/issues"
12
+ },
13
+ "homepage": "https://github.com/Hope2023Dcr/dsh-gallery#readme",
14
+ "exports": {
15
+ ".": "./index.js",
16
+ "./client": "./client.js",
17
+ "./locale/*.json": "./locale/*.json",
18
+ "./icon": "./icon.svg"
19
+ },
20
+ "files": [
21
+ "install.mjs",
22
+ "index.js",
23
+ "client.js",
24
+ "session-index.js",
25
+ "host/*.js",
26
+ "cordis.patch.yml",
27
+ "locale/*.json",
28
+ "icon.svg",
29
+ "README.md",
30
+ "LICENSE",
31
+ "CHANGELOG.md",
32
+ "docs/screenshots/*.png"
33
+ ],
34
+ "dsh": {
35
+ "bundle": {
36
+ "patch": "./cordis.patch.yml"
37
+ },
38
+ "client": {
39
+ "platform": "web",
40
+ "immediately": true,
41
+ "inject": [
42
+ "@deepseek-ai/dsh-client-ui-sidebar-right",
43
+ "@deepseek-ai/dsh-client-locale"
44
+ ]
45
+ }
46
+ },
47
+ "author": {
48
+ "name": "Hope2023Dcr"
49
+ },
50
+ "license": "MIT",
51
+ "keywords": [
52
+ "dsh-plugin",
53
+ "deepseek-harness",
54
+ "dsh",
55
+ "output-gallery",
56
+ "image-gallery",
57
+ "file-preview",
58
+ "sidebar-plugin",
59
+ "agent-tools",
60
+ "media-gallery",
61
+ "video-preview",
62
+ "audio-preview",
63
+ "range-seek",
64
+ "filter",
65
+ "deliverable",
66
+ "human-in-the-loop",
67
+ "asset-tags",
68
+ "manual-label",
69
+ "feedback-basket",
70
+ "batch",
71
+ "region-selection",
72
+ "annotation",
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",
83
+ "clipboard-paste",
84
+ "image-crop",
85
+ "magnifier",
86
+ "media-trim",
87
+ "ffmpeg",
88
+ "audio-trim",
89
+ "video-trim"
90
+ ],
91
+ "publishConfig": {
92
+ "access": "public",
93
+ "registry": "https://registry.npmjs.org/"
94
+ },
95
+ "engines": {
96
+ "node": ">=20"
97
+ }
98
+ }