dsh-gallery 1.4.0 → 1.4.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/CHANGELOG.md +73 -0
- package/README.md +34 -3
- package/client.js +459 -53
- package/host/groups.js +3 -0
- package/host/http.js +183 -65
- package/host/scan.js +398 -6
- package/package.json +1 -1
package/host/scan.js
CHANGED
|
@@ -97,7 +97,7 @@ export function extractAssetInfo(logText, sessionStartMs = 0) {
|
|
|
97
97
|
|
|
98
98
|
const ensure = (abs) => {
|
|
99
99
|
if (!assets.has(abs)) {
|
|
100
|
-
assets.set(abs, { presented: false, written: false, viewed: false, bashMentioned: false })
|
|
100
|
+
assets.set(abs, { presented: false, written: false, viewed: false, bashMentioned: false, lastMs: 0 })
|
|
101
101
|
}
|
|
102
102
|
return assets.get(abs)
|
|
103
103
|
}
|
|
@@ -137,6 +137,8 @@ export function extractAssetInfo(logText, sessionStartMs = 0) {
|
|
|
137
137
|
try {
|
|
138
138
|
const info = ensure(path.resolve(candidate))
|
|
139
139
|
info.bashMentioned = true
|
|
140
|
+
const recMs = typeof record.time === 'number' ? record.time : 0
|
|
141
|
+
if (recMs > info.lastMs) info.lastMs = recMs
|
|
140
142
|
} catch {
|
|
141
143
|
// 解析失败就跳过
|
|
142
144
|
}
|
|
@@ -165,6 +167,8 @@ export function extractAssetInfo(logText, sessionStartMs = 0) {
|
|
|
165
167
|
if (!VIEW_IMAGE_EXTS.has(ext)) continue
|
|
166
168
|
}
|
|
167
169
|
const info = ensure(path.resolve(entry))
|
|
170
|
+
const recMs = typeof record.time === 'number' ? record.time : 0
|
|
171
|
+
if (recMs > info.lastMs) info.lastMs = recMs
|
|
168
172
|
if (isPresenter) info.presented = true
|
|
169
173
|
else if (isViewer) info.viewed = true
|
|
170
174
|
else info.written = true
|
|
@@ -179,6 +183,189 @@ export function extractAssetInfo(logText, sessionStartMs = 0) {
|
|
|
179
183
|
return assets
|
|
180
184
|
}
|
|
181
185
|
|
|
186
|
+
/**
|
|
187
|
+
* 解析宿主「分叉会话」的继承边界(2026-11-24)。
|
|
188
|
+
*
|
|
189
|
+
* 宿主分叉会话的日志 = 复制来源会话到分叉点为止的历史 + 之后自己的新事件:
|
|
190
|
+
* - 首行 isSeeded: true —— 这个会话含继承来的前缀;
|
|
191
|
+
* - 一条 session/end-seed 且 data.inherited: true —— 继承段到此结束,
|
|
192
|
+
* 它的 time 就是精确的分叉时刻(实测与主线会话停止写入的时间只差 2ms)。
|
|
193
|
+
* 非分叉会话返回 { isFork: false, forkAtMs: 0 }。
|
|
194
|
+
*
|
|
195
|
+
* @param logText - 解压后的日志文本。
|
|
196
|
+
*/
|
|
197
|
+
export function parseForkBoundary(logText) {
|
|
198
|
+
const result = { isFork: false, forkAtMs: 0 }
|
|
199
|
+
if (typeof logText !== 'string' || logText === '') return result
|
|
200
|
+
let isSeeded = false
|
|
201
|
+
let forkAtMs = 0
|
|
202
|
+
for (const line of logText.split('\n')) {
|
|
203
|
+
if (line === '') continue
|
|
204
|
+
if (!isSeeded && line.includes('"session"')) {
|
|
205
|
+
try {
|
|
206
|
+
const first = JSON.parse(line)
|
|
207
|
+
if (first.type === 'session' && first.isSeeded === true) isSeeded = true
|
|
208
|
+
} catch {
|
|
209
|
+
// 首行解析失败不影响后续扫描
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!line.includes('end-seed')) continue
|
|
213
|
+
try {
|
|
214
|
+
const o = JSON.parse(line)
|
|
215
|
+
if (o.type === 'session/end-seed' && o.data?.inherited === true && typeof o.time === 'number') {
|
|
216
|
+
forkAtMs = o.time
|
|
217
|
+
}
|
|
218
|
+
} catch {
|
|
219
|
+
// 坏行跳过
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return { isFork: isSeeded && forkAtMs > 0, forkAtMs }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 反查「从本会话分叉出去的子会话」在分叉点之后自己产出的资产(2026-11-24)。
|
|
227
|
+
*
|
|
228
|
+
* 宿主在分叉时刻意不留「我派生了谁」:主线日志到分叉点就停了;
|
|
229
|
+
* 子会话日志则把主线日志逐条复制过来(seq / type / time 完全一致),
|
|
230
|
+
* 以 session/end-seed{inherited:true} 收尾,之后才是自己的新事件。
|
|
231
|
+
* 所以反向关联靠两条证据:子会话首行的 parentSession,或继承段的记录指纹。
|
|
232
|
+
*
|
|
233
|
+
* 主线扫描时按这些精确路径排除(主线自己日志精确记录过的除外):
|
|
234
|
+
* 它们不在主线日志里,只靠「本对话用过的目录 + 新 mtime」放宽倒灌回主线,
|
|
235
|
+
* 不拦就会出现「分叉对话的产出全跑到主线」。
|
|
236
|
+
*
|
|
237
|
+
* 每个 child 带两类路径:paths(分叉后新产出,主线要挡掉)与 inheritedPaths
|
|
238
|
+
* (分叉前从主线继承,主线要标「共享」)。
|
|
239
|
+
* @returns {{ children: Array<{id:string,forkAtMs:number,paths:string[],inheritedPaths:string[]}> }}
|
|
240
|
+
*/
|
|
241
|
+
export async function findForkedChildren(sessionsDir, parentSessionId, parentLogText) {
|
|
242
|
+
const result = { children: [] }
|
|
243
|
+
if (typeof parentSessionId !== 'string' || parentSessionId === '') return result
|
|
244
|
+
if (typeof parentLogText !== 'string' || parentLogText === '') return result
|
|
245
|
+
|
|
246
|
+
const ownDir = await locateSessionDir(sessionsDir, parentSessionId)
|
|
247
|
+
if (ownDir === null) return result
|
|
248
|
+
const groupDir = path.dirname(ownDir)
|
|
249
|
+
|
|
250
|
+
// 主线日志的 (seq,type,time) 指纹。只比 seq / 类型 / 时间,不比内容,
|
|
251
|
+
// 宿主复制日志时这三项是逐条保留的(实测 2210 条全中)。
|
|
252
|
+
const parentFp = new Map()
|
|
253
|
+
for (const line of parentLogText.split('\n')) {
|
|
254
|
+
if (line === '') continue
|
|
255
|
+
let o
|
|
256
|
+
try { o = JSON.parse(line) } catch { continue }
|
|
257
|
+
if (typeof o?.seq === 'number') parentFp.set(o.seq, `${o.type}|${o.time}`)
|
|
258
|
+
}
|
|
259
|
+
if (parentFp.size < 10) return result
|
|
260
|
+
|
|
261
|
+
let entries
|
|
262
|
+
try { entries = await fsp.readdir(groupDir, { withFileTypes: true }) } catch { return result }
|
|
263
|
+
for (const dirent of entries) {
|
|
264
|
+
if (!dirent.isDirectory() || dirent.name === path.basename(ownDir)) continue
|
|
265
|
+
const logPath = path.join(groupDir, dirent.name, 'session.v4.jsonl.zstd')
|
|
266
|
+
const text = await readSessionLogText(logPath)
|
|
267
|
+
if (text === '') continue
|
|
268
|
+
let head = null
|
|
269
|
+
try { head = JSON.parse(text.split('\n')[0]) } catch { continue }
|
|
270
|
+
const fork = parseForkBoundary(text)
|
|
271
|
+
if (!fork.isFork) continue
|
|
272
|
+
|
|
273
|
+
let linked = false
|
|
274
|
+
if (head?.parentSession === parentSessionId) {
|
|
275
|
+
linked = true
|
|
276
|
+
} else if (head?.isSeeded === true) {
|
|
277
|
+
// 继承段(forkAtMs 之前)的记录应与主线逐条一致
|
|
278
|
+
let same = 0
|
|
279
|
+
let total = 0
|
|
280
|
+
for (const line of text.split('\n')) {
|
|
281
|
+
if (line === '') continue
|
|
282
|
+
let o
|
|
283
|
+
try { o = JSON.parse(line) } catch { continue }
|
|
284
|
+
if (typeof o?.seq !== 'number' || typeof o?.time !== 'number') continue
|
|
285
|
+
if (o.time >= fork.forkAtMs) continue
|
|
286
|
+
total += 1
|
|
287
|
+
if (parentFp.get(o.seq) === `${o.type}|${o.time}`) same += 1
|
|
288
|
+
}
|
|
289
|
+
linked = total >= 10 && same / total >= 0.95
|
|
290
|
+
}
|
|
291
|
+
if (!linked) continue
|
|
292
|
+
|
|
293
|
+
// 只收由 present / 写入类工具明确产出的绝对路径(bash 弱证据不收)。
|
|
294
|
+
// 分叉点之后 → paths(子会话新产出,主线挡掉);
|
|
295
|
+
// 分叉点之前 → inheritedPaths(从主线带走,主线标「共享」)。
|
|
296
|
+
const paths = new Set()
|
|
297
|
+
const inheritedPaths = new Set()
|
|
298
|
+
for (const line of text.split('\n')) {
|
|
299
|
+
if (line === '' || !line.includes('tool/call')) continue
|
|
300
|
+
let o
|
|
301
|
+
try { o = JSON.parse(line) } catch { continue }
|
|
302
|
+
if (o?.type !== 'tool/call' || typeof o.time !== 'number') continue
|
|
303
|
+
const name = o?.data?.name
|
|
304
|
+
if (typeof name !== 'string') continue
|
|
305
|
+
if (name !== 'present' && !OUTPUT_TOOLS.has(name)) continue
|
|
306
|
+
const rawArgs = o?.data?.arguments
|
|
307
|
+
if (typeof rawArgs !== 'string') continue
|
|
308
|
+
let args
|
|
309
|
+
try { args = JSON.parse(rawArgs) } catch { continue }
|
|
310
|
+
const found = []
|
|
311
|
+
if (name === 'present' && Array.isArray(args?.files)) {
|
|
312
|
+
for (const f of args.files) {
|
|
313
|
+
if (typeof f?.path === 'string') found.push(f.path)
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
collectAbsolutePaths(args, found)
|
|
317
|
+
}
|
|
318
|
+
const bucket = o.time >= fork.forkAtMs ? paths : inheritedPaths
|
|
319
|
+
for (const p of found) {
|
|
320
|
+
try { bucket.add(path.resolve(p)) } catch { /* 坏路径跳过 */ }
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (paths.size > 0 || inheritedPaths.size > 0) {
|
|
324
|
+
result.children.push({
|
|
325
|
+
id: String(head?.id ?? dirent.name),
|
|
326
|
+
forkAtMs: fork.forkAtMs,
|
|
327
|
+
paths: [...paths],
|
|
328
|
+
inheritedPaths: [...inheritedPaths],
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return result
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* 从 bash 命令里提取「脚本直接读写的媒体目录」(2026-11-24)。
|
|
337
|
+
*
|
|
338
|
+
* 脚本调接口下载 / ffmpeg 处理的产物(如配音 mp3)不经过 present/write,
|
|
339
|
+
* 日志里只在命令文本里以 `cd "绝对目录" + *.mp3` 的形式出现。
|
|
340
|
+
* 这类目录本身要登记成「本对话用过的目录」,BFS 才会放行目录里真实存在的媒体文件。
|
|
341
|
+
* 只认:命令类工具 + 命令里同时出现媒体通配符 + cd 到产出根内的绝对路径。
|
|
342
|
+
*
|
|
343
|
+
* @returns Map<lowercase abs, original abs>
|
|
344
|
+
*/
|
|
345
|
+
export function extractCommandMediaDirs(logText) {
|
|
346
|
+
const dirs = new Map()
|
|
347
|
+
if (typeof logText !== 'string' || logText === '') return dirs
|
|
348
|
+
const MEDIA_GLOB = /\*\.(mp4|webm|mov|m4v|mkv|avi|ogv|mp3|wav|m4a|aac|flac|ogg|oga|opus|wma)\b/i
|
|
349
|
+
const CD_RE = /\bcd\s+["']?([A-Za-z]:[\\/][^"'\s;|&]+)["']?/g
|
|
350
|
+
for (const line of logText.split('\n')) {
|
|
351
|
+
if (line === '' || !line.includes('tool/call')) continue
|
|
352
|
+
let record
|
|
353
|
+
try { record = JSON.parse(line) } catch { continue }
|
|
354
|
+
if (record?.type !== 'tool/call' || !BASH_TOOLS.has(record?.data?.name)) continue
|
|
355
|
+
let args
|
|
356
|
+
try { args = JSON.parse(record?.data?.arguments) } catch { continue }
|
|
357
|
+
const cmd = String(args?.command ?? '')
|
|
358
|
+
if (cmd === '' || !MEDIA_GLOB.test(cmd)) continue
|
|
359
|
+
for (const m of cmd.matchAll(CD_RE)) {
|
|
360
|
+
let dir = String(m[1] ?? '').replace(/[\\/]+$/, '')
|
|
361
|
+
try { dir = path.resolve(dir) } catch { continue }
|
|
362
|
+
const key = dir.toLowerCase()
|
|
363
|
+
if (!dirs.has(key)) dirs.set(key, dir)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return dirs
|
|
367
|
+
}
|
|
368
|
+
|
|
182
369
|
/**
|
|
183
370
|
* 从会话日志首行解析会话开始时间(createdAt)。
|
|
184
371
|
* @param logText - 解压后的日志文本。
|
|
@@ -250,7 +437,21 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
|
|
|
250
437
|
return { ok: false, reason: 'log-empty', taskDirs: [], paths: [], relPaths: [], subSessions: 0 }
|
|
251
438
|
}
|
|
252
439
|
// 会话开始时间:用于区分「用户素材」与「会话期间产出」
|
|
253
|
-
const
|
|
440
|
+
const createdAtMs = parseSessionStartMs(logText)
|
|
441
|
+
// 2026-11-24:脚本直接下载的媒体(配音 mp3 等)没有 present/write 记录,
|
|
442
|
+
// 只以 cd 目录 + *.mp3 出现在命令里;把这类目录登记进来,BFS 才会放行目录里的真实文件。
|
|
443
|
+
const commandMediaDirs = extractCommandMediaDirs(logText)
|
|
444
|
+
// 2026-11-24 分叉资产隔离:分叉会话的「有效开始时间」是分叉点,不是会话创建时间。
|
|
445
|
+
// 宿主会把来源会话到分叉点的历史整段复制过来(isSeeded + end-seed inherited),
|
|
446
|
+
// 若沿用 createdAt,继承段的产出会被算成「本对话」的,跟主线重复。
|
|
447
|
+
// sessionStartMs 同时掌管同目录放宽的时间门槛,改这里一处两条路径都干净。
|
|
448
|
+
const fork = parseForkBoundary(logText)
|
|
449
|
+
const sessionStartMs = fork.isFork && fork.forkAtMs > createdAtMs ? fork.forkAtMs : createdAtMs
|
|
450
|
+
// 2026-11-24:反向隔离。主线会话要认出「从它分叉出去的子会话」,
|
|
451
|
+
// 把子会话分叉后的新产出按绝对路径挡在主线之外;分叉会话自己不需要这一步。
|
|
452
|
+
const forkedChildren = fork.isFork
|
|
453
|
+
? { children: [] }
|
|
454
|
+
: await findForkedChildren(sessionsDir, sessionId, logText)
|
|
254
455
|
const allAssets = extractAssetInfo(logText, sessionStartMs)
|
|
255
456
|
|
|
256
457
|
// 修法 C:合并所有子会话(子智能体)的产出路径
|
|
@@ -280,6 +481,9 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
|
|
|
280
481
|
|
|
281
482
|
const normalized = []
|
|
282
483
|
const relPaths = []
|
|
484
|
+
// 2026-11-24:分叉会话里「继承自主线」的资产单独记录,不并入本分支的「当前对话」。
|
|
485
|
+
const inheritedPaths = []
|
|
486
|
+
const inheritedRelPaths = []
|
|
283
487
|
const taskDirs = new Set()
|
|
284
488
|
// v0.14.7:会话引用过的「精确目录」(相对 root、小写,空串表示 root 直属层)。
|
|
285
489
|
// 外部拷进同一目录、没被日志引用的图片,也要能在「当前对话」里看到并标为素材。
|
|
@@ -303,11 +507,23 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
|
|
|
303
507
|
if (isInside(r, absolute)) { ownerRoot = r; break }
|
|
304
508
|
}
|
|
305
509
|
if (ownerRoot === null) continue
|
|
306
|
-
normalized.push(absolute)
|
|
307
510
|
|
|
308
511
|
const rel = path.relative(ownerRoot, absolute)
|
|
309
512
|
const segs = rel.split(path.sep).filter((s) => s !== '')
|
|
310
513
|
const relPath = rel.split(path.sep).join('/')
|
|
514
|
+
|
|
515
|
+
// 分叉会话:最后被日志提及的时间早于分叉边界 → 继承自主线的资产。
|
|
516
|
+
// 2026-11-24 口径修正:照常进主列表(图片/文件/音视频混排),只额外记进
|
|
517
|
+
// inherited*,由 scanGallery 给条目打 inherited:true;前端加「继承」角标
|
|
518
|
+
// 区分来源,除删除提示外的交互与本对话产出完全一致。
|
|
519
|
+
// lastMs=0(事件没带 time)保守当作本对话,宁可多显示也不误删。
|
|
520
|
+
const isInherited = fork.isFork && info.lastMs > 0 && info.lastMs < fork.forkAtMs
|
|
521
|
+
if (isInherited) {
|
|
522
|
+
inheritedPaths.push(absolute)
|
|
523
|
+
inheritedRelPaths.push(relPath)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
normalized.push(absolute)
|
|
311
527
|
relPaths.push(relPath)
|
|
312
528
|
categoryByRel.set(relPath.toLowerCase(), info.category)
|
|
313
529
|
sessionDirs.add(parentDirOf(relPath))
|
|
@@ -317,9 +533,34 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
|
|
|
317
533
|
if (segs.length >= 2) taskDirs.add(segs[0])
|
|
318
534
|
}
|
|
319
535
|
|
|
536
|
+
// 2026-11-24:脚本直接下载的媒体目录(命令里 cd + 媒体通配符)也算会话用过的目录。
|
|
537
|
+
// 只收落在产出根内的、且确实存在的绝对路径;仍受 BFS 深度与 isFreshSince 门槛约束。
|
|
538
|
+
for (const absDir of commandMediaDirs.values()) {
|
|
539
|
+
let ownerRoot = null
|
|
540
|
+
for (const r of roots) {
|
|
541
|
+
if (isInside(r, absDir)) { ownerRoot = r; break }
|
|
542
|
+
}
|
|
543
|
+
if (ownerRoot === null) continue
|
|
544
|
+
try {
|
|
545
|
+
if (!statSync(absDir).isDirectory()) continue
|
|
546
|
+
} catch {
|
|
547
|
+
continue
|
|
548
|
+
}
|
|
549
|
+
const relDir = path.relative(ownerRoot, absDir).split(path.sep).join('/')
|
|
550
|
+
if (relDir === '' || relDir.startsWith('..')) continue
|
|
551
|
+
sessionDirs.add(relDir.toLowerCase())
|
|
552
|
+
sessionDirsAbs.add(absDir)
|
|
553
|
+
}
|
|
554
|
+
|
|
320
555
|
return {
|
|
321
556
|
ok: true,
|
|
322
557
|
reason: 'ok',
|
|
558
|
+
// 2026-11-24:分叉会话用分叉点当「会话开始」,同时掌管下面的放宽时间门槛
|
|
559
|
+
isFork: fork.isFork,
|
|
560
|
+
forkAtMs: fork.forkAtMs,
|
|
561
|
+
forkedChildren,
|
|
562
|
+
inheritedPaths,
|
|
563
|
+
inheritedRelPaths,
|
|
323
564
|
// 2026-11-15:同目录放宽只收本对话开始之后新出现 / 改动的文件
|
|
324
565
|
sessionStartMs,
|
|
325
566
|
taskDirs: [...taskDirs],
|
|
@@ -337,8 +578,14 @@ export async function resolveSessionScope(config, sessionId, allRoots) {
|
|
|
337
578
|
* 结果按修改时间倒序,只回传 maxItems 条,另外给出 total 供「还有 N 张」。
|
|
338
579
|
*/
|
|
339
580
|
|
|
340
|
-
export async function scanGallery(config, kind = 'image', scope = 'global', sessionId = '', page = 1) {
|
|
341
|
-
|
|
581
|
+
export async function scanGallery(config, kind = 'image', scope = 'global', sessionId = '', page = 1, optsOverride) {
|
|
582
|
+
// 2026-11-25:第 6 个参数只给内部「按分类取全量」用,且只认 maxItems。
|
|
583
|
+
// 把它抬到 5000,「按标签圈选」一次就能拿全,不必按页重扫 ——
|
|
584
|
+
// 当前对话视图每扫一页都要重解一次会话日志,翻十几页会让面板卡住好几秒。
|
|
585
|
+
const optsBase = resolveOptions(config)
|
|
586
|
+
const opts = optsOverride !== undefined && optsOverride !== null && Number(optsOverride.maxItems) > 0
|
|
587
|
+
? { ...optsBase, maxItems: Math.max(1, Math.trunc(Number(optsOverride.maxItems))) }
|
|
588
|
+
: optsBase
|
|
342
589
|
const now = Date.now()
|
|
343
590
|
const cutoff = now - opts.windowHours * 3600_000
|
|
344
591
|
const isFile = kind === 'file'
|
|
@@ -374,6 +621,15 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
374
621
|
// 当前对话范围:先解析会话日志(含子智能体会话),得到「本对话产出过的路径」
|
|
375
622
|
let scopeInfo = { ok: true, reason: 'global', taskDirs: [], paths: [], relPaths: [], subSessions: 0 }
|
|
376
623
|
let sessionRelSet = null
|
|
624
|
+
// 2026-11-24:继承自主线的资产绝对路径集合(分叉会话才有值;global 模式为 null)
|
|
625
|
+
let inheritedAbsSet = null
|
|
626
|
+
// 2026-11-24:主线视图要排除的「分叉子会话分叉后新产出」绝对路径集合
|
|
627
|
+
let childForkAbsSet = null
|
|
628
|
+
// 2026-11-24:主线里「被分叉会话带走的共享资产」——前端加同款虚线框 +「共享」角标
|
|
629
|
+
let sharedAbsSet = null
|
|
630
|
+
// 截帧 / 遮罩 / 填充预览只登记在 frames.json,不在会话日志里;
|
|
631
|
+
// 它们按相对路径登记,另外用相对路径集合挡一道(含 overlayRelPath)。
|
|
632
|
+
let childForkRelSet = null
|
|
377
633
|
// v0.14.7:会话引用过的目录集合。同目录下的外部图片也纳入「当前对话」,
|
|
378
634
|
// 但不在精确路径白名单里 —— 它们会被自动标为「素材」(input)。
|
|
379
635
|
let sessionDirSet = null
|
|
@@ -384,6 +640,40 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
384
640
|
// 修法 B:用「精确相对路径」集合判定,而不是只靠第一层目录名。
|
|
385
641
|
// 这样既能处理有子目录的情况,也能处理「文件直接躺在 root 根目录下」。
|
|
386
642
|
sessionRelSet = new Set((scopeInfo.relPaths ?? []).map((p) => p.toLowerCase()))
|
|
643
|
+
// 2026-11-24:继承自主线的资产绝对路径集合。用于给扫描条目打 inherited 标记——
|
|
644
|
+
// 这类文件常落在「本对话用过的目录」里,也可能被手工拷贝改新 mtime,
|
|
645
|
+
// 只有按日志算出的精确路径集合才认得准来源。
|
|
646
|
+
inheritedAbsSet = new Set(
|
|
647
|
+
(Array.isArray(scopeInfo.inheritedPaths) ? scopeInfo.inheritedPaths : []).map((x) => {
|
|
648
|
+
try { return path.resolve(String(x)).toLowerCase() } catch { return '' }
|
|
649
|
+
}),
|
|
650
|
+
)
|
|
651
|
+
const kids = Array.isArray(scopeInfo.forkedChildren?.children) ? scopeInfo.forkedChildren.children : []
|
|
652
|
+
if (kids.length > 0) {
|
|
653
|
+
childForkAbsSet = new Set()
|
|
654
|
+
childForkRelSet = new Set()
|
|
655
|
+
sharedAbsSet = new Set()
|
|
656
|
+
const kidIds = new Set(kids.map((kid) => String(kid?.id ?? '')))
|
|
657
|
+
for (const kid of kids) {
|
|
658
|
+
for (const abs of (Array.isArray(kid?.paths) ? kid.paths : [])) {
|
|
659
|
+
try { childForkAbsSet.add(path.resolve(String(abs)).toLowerCase()) } catch { /* 跳过 */ }
|
|
660
|
+
}
|
|
661
|
+
// 子会话的继承段(分叉点前)就是「从主线带走」的那批,主线侧标共享
|
|
662
|
+
for (const abs of (Array.isArray(kid?.inheritedPaths) ? kid.inheritedPaths : [])) {
|
|
663
|
+
try { sharedAbsSet.add(path.resolve(String(abs)).toLowerCase()) } catch { /* 跳过 */ }
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
// 分叉会话生成的遮罩图(kind:'mask')与半透明填充(overlayRelPath)
|
|
667
|
+
// 只在 frames.json 里登记,日志没有它们的影子;按会话 id 反查一并排除。
|
|
668
|
+
for (const [rel, f] of frameByRel) {
|
|
669
|
+
if (!kidIds.has(String(f?.sessionId ?? ''))) continue
|
|
670
|
+
childForkRelSet.add(rel)
|
|
671
|
+
const overlay = String(f?.overlayRelPath ?? '').toLowerCase()
|
|
672
|
+
if (overlay !== '') childForkRelSet.add(overlay)
|
|
673
|
+
}
|
|
674
|
+
if (childForkAbsSet.size === 0) childForkAbsSet = null
|
|
675
|
+
if (childForkRelSet.size === 0) childForkRelSet = null
|
|
676
|
+
}
|
|
387
677
|
sessionDirSet = new Set((scopeInfo.sessionDirs ?? []).map((d) => String(d).toLowerCase()))
|
|
388
678
|
// 会话日志缺失时 resolveSessionScope 可能不带分类表,补一个空的
|
|
389
679
|
if (!(scopeInfo.categoryByRel instanceof Map)) scopeInfo.categoryByRel = new Map()
|
|
@@ -439,6 +729,13 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
439
729
|
let globalCurrentExactRels = null
|
|
440
730
|
let globalCurrentCategory = null
|
|
441
731
|
let globalCurrentStartMs = 0
|
|
732
|
+
// 2026-11-24:全局视图里置顶的「当前对话」组同样不能吞进分叉子会话的新产出
|
|
733
|
+
let globalCurrentChildForkAbsSet = null
|
|
734
|
+
let globalCurrentChildForkRelSet = null
|
|
735
|
+
let globalCurrentSharedAbsSet = null
|
|
736
|
+
// 2026-11-25:全局视图里「子会话(分叉)继承自主线」的资产绝对路径集合。
|
|
737
|
+
// 分叉会话在资产台(全局视图)同样要看到「继承」角标,口径与当前对话视图一致。
|
|
738
|
+
let globalCurrentInheritedAbsSet = null
|
|
442
739
|
if (!isSession && sessionId !== '') {
|
|
443
740
|
const current = await resolveSessionScope(config, sessionId, opts.roots)
|
|
444
741
|
if (current.ok) {
|
|
@@ -456,6 +753,34 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
456
753
|
exactRels.add(String(rel).toLowerCase())
|
|
457
754
|
categoryByRel.set(String(rel).toLowerCase(), frameCategoryOf(f))
|
|
458
755
|
}
|
|
756
|
+
const kidAbs = new Set()
|
|
757
|
+
const kidRels = new Set()
|
|
758
|
+
const sharedAbs = new Set()
|
|
759
|
+
const kids = Array.isArray(current.forkedChildren?.children) ? current.forkedChildren.children : []
|
|
760
|
+
const kidIds = new Set(kids.map((kid) => String(kid?.id ?? '')))
|
|
761
|
+
for (const kid of kids) {
|
|
762
|
+
for (const abs of (Array.isArray(kid?.paths) ? kid.paths : [])) {
|
|
763
|
+
try { kidAbs.add(path.resolve(String(abs)).toLowerCase()) } catch { /* 跳过 */ }
|
|
764
|
+
}
|
|
765
|
+
for (const abs of (Array.isArray(kid?.inheritedPaths) ? kid.inheritedPaths : [])) {
|
|
766
|
+
try { sharedAbs.add(path.resolve(String(abs)).toLowerCase()) } catch { /* 跳过 */ }
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
if (sharedAbs.size > 0) globalCurrentSharedAbsSet = sharedAbs
|
|
770
|
+
const inhAbs = new Set()
|
|
771
|
+
for (const abs of (Array.isArray(current.inheritedPaths) ? current.inheritedPaths : [])) {
|
|
772
|
+
try { inhAbs.add(path.resolve(String(abs)).toLowerCase()) } catch { /* 跳过 */ }
|
|
773
|
+
}
|
|
774
|
+
if (inhAbs.size > 0) globalCurrentInheritedAbsSet = inhAbs
|
|
775
|
+
// 遮罩 / 填充预览只登记在 frames.json,按会话 id 一并排除出主线的当前对话组
|
|
776
|
+
for (const [rel, f] of frameByRel) {
|
|
777
|
+
if (!kidIds.has(String(f?.sessionId ?? ''))) continue
|
|
778
|
+
kidRels.add(rel)
|
|
779
|
+
const overlay = String(f?.overlayRelPath ?? '').toLowerCase()
|
|
780
|
+
if (overlay !== '') kidRels.add(overlay)
|
|
781
|
+
}
|
|
782
|
+
if (kidAbs.size > 0) globalCurrentChildForkAbsSet = kidAbs
|
|
783
|
+
if (kidRels.size > 0) globalCurrentChildForkRelSet = kidRels
|
|
459
784
|
globalCurrentDirs = dirs
|
|
460
785
|
globalCurrentExactRels = exactRels
|
|
461
786
|
globalCurrentCategory = categoryByRel
|
|
@@ -561,6 +886,41 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
561
886
|
}
|
|
562
887
|
}
|
|
563
888
|
|
|
889
|
+
// 2026-11-21:深层交付文件保底。
|
|
890
|
+
// BFS 受 opts.maxDepth(默认 3)限制,落在更深目录里的日志明确产出 / 交付
|
|
891
|
+
// 文件(例如 .../正式成片/film/outputs/xxx.mp4 在第 6 层)根本走不到,
|
|
892
|
+
// 于是「音视频」画廊里看不到 —— 但图片都在浅层,看起来就像"音视频丢了"。
|
|
893
|
+
// 这里把「本对话日志 present/write 过的精确绝对路径」直接补进候选,
|
|
894
|
+
// 不走 BFS 深度限制;仍照常经过下面的 stat(时间窗口 / 体积 / 隐藏)过滤。
|
|
895
|
+
// 只补"日志明确记录过"的路径,不猜、不递归扫深目录,避免拖慢全库或扫进无关文件。
|
|
896
|
+
if (isSession && Array.isArray(scopeInfo.paths) && scopeInfo.paths.length > 0) {
|
|
897
|
+
// 已在 BFS 候选里的绝对路径(小写)不重复添加
|
|
898
|
+
const have = new Set(candidates.map((c) => path.resolve(c.fullPath).toLowerCase()))
|
|
899
|
+
for (const abs of scopeInfo.paths) {
|
|
900
|
+
let absolute
|
|
901
|
+
try { absolute = path.resolve(String(abs)) } catch { continue }
|
|
902
|
+
if (have.has(absolute.toLowerCase())) continue
|
|
903
|
+
let ownerRoot = null
|
|
904
|
+
for (const r of opts.roots) {
|
|
905
|
+
if (isInside(r, absolute)) { ownerRoot = r; break }
|
|
906
|
+
}
|
|
907
|
+
if (ownerRoot === null) continue
|
|
908
|
+
const ext = path.extname(absolute).toLowerCase()
|
|
909
|
+
if (!extSet.has(ext)) continue
|
|
910
|
+
const relPath = path.relative(ownerRoot, absolute).split(path.sep).join('/')
|
|
911
|
+
if (hiddenSet.has(relPath)) continue
|
|
912
|
+
have.add(absolute.toLowerCase())
|
|
913
|
+
candidates.push({
|
|
914
|
+
fullPath: absolute,
|
|
915
|
+
relPath,
|
|
916
|
+
entryName: path.basename(absolute),
|
|
917
|
+
rootDir: ownerRoot,
|
|
918
|
+
rootIndex: opts.roots.indexOf(ownerRoot),
|
|
919
|
+
extension: ext,
|
|
920
|
+
looseDirHit: false,
|
|
921
|
+
})
|
|
922
|
+
}
|
|
923
|
+
}
|
|
564
924
|
// 2026-11-16 第一档:第二阶段限流并发读 stat。
|
|
565
925
|
// 全库五千多个文件逐个 await 要 7 秒左右,几十路并发能压到 1 秒内;
|
|
566
926
|
// 过滤条件(时间窗口 / 体积 / 隐藏 / 同目录新鲜度)与串行时完全一致,
|
|
@@ -572,6 +932,13 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
572
932
|
} catch {
|
|
573
933
|
return null
|
|
574
934
|
}
|
|
935
|
+
// 2026-11-24:分叉子会话分叉后的新产出不能倒灌回主线。
|
|
936
|
+
// 主线日志自己精确记录过的路径优先保留(那种文件本来就是主线的,
|
|
937
|
+
// 子会话可能再次 present 过),其余按绝对路径硬挡。
|
|
938
|
+
if ((childForkAbsSet !== null && childForkAbsSet.has(path.resolve(c.fullPath).toLowerCase())
|
|
939
|
+
|| (childForkRelSet !== null && childForkRelSet.has(c.relPath.toLowerCase())))
|
|
940
|
+
&& !sessionRelSet.has(c.relPath.toLowerCase())) return null
|
|
941
|
+
// 2026-11-24:继承资产照常走下面的过滤,只在返回条目上打 inherited 标记。
|
|
575
942
|
// 2026-11-15:同目录放宽只收本对话期间新出现 / 改动的图;
|
|
576
943
|
// 否则只读查一次图,就会把该目录里几百张历史图全算进这个新对话。
|
|
577
944
|
if (c.looseDirHit && !isFreshSince(stat, sessionStartMs)) return null
|
|
@@ -594,6 +961,14 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
594
961
|
...(c.looseDirHit ? { externalAsset: true } : {}),
|
|
595
962
|
// 音视频区分「视频 / 音频」,客户端据此选 <video> 还是 <audio>
|
|
596
963
|
...(isMedia ? { mediaType: VIDEO_EXTS.includes(c.extension) ? 'video' : 'audio' } : {}),
|
|
964
|
+
// 2026-11-24:分叉会话继承自主线的资产照常进主列表,只打标记供前端区分来源。
|
|
965
|
+
...(inheritedAbsSet !== null && inheritedAbsSet.has(path.resolve(c.fullPath).toLowerCase())
|
|
966
|
+
? { inherited: true }
|
|
967
|
+
: {}),
|
|
968
|
+
// 2026-11-24:主线里被分叉会话带走的文件打 shared,交互照常、只加共享标记。
|
|
969
|
+
...(sharedAbsSet !== null && sharedAbsSet.has(path.resolve(c.fullPath).toLowerCase())
|
|
970
|
+
? { shared: true }
|
|
971
|
+
: {}),
|
|
597
972
|
}
|
|
598
973
|
})
|
|
599
974
|
for (const item of statted) {
|
|
@@ -666,7 +1041,9 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
666
1041
|
} else if (globalCurrentExactRels !== null
|
|
667
1042
|
&& (globalCurrentExactRels.has(item.relPath.toLowerCase())
|
|
668
1043
|
|| (globalCurrentDirs !== null && globalCurrentDirs.has(parentDirOf(item.relPath))
|
|
669
|
-
&& isFreshSince({ mtimeMs: item.mtime, birthtimeMs: item.birthtimeMs }, globalCurrentStartMs)))
|
|
1044
|
+
&& isFreshSince({ mtimeMs: item.mtime, birthtimeMs: item.birthtimeMs }, globalCurrentStartMs)))
|
|
1045
|
+
&& !(globalCurrentChildForkAbsSet !== null && globalCurrentChildForkAbsSet.has(abs.toLowerCase())
|
|
1046
|
+
|| (globalCurrentChildForkRelSet !== null && globalCurrentChildForkRelSet.has(item.relPath.toLowerCase())))) {
|
|
670
1047
|
// 2026-11-15:本对话日志精确引用过、或落在本对话用过的目录里的资产,
|
|
671
1048
|
// 一律归到全局置顶的「当前对话」组;历史会话索引不能再把它抢走。
|
|
672
1049
|
// 分类与「当前对话」视图完全一致:精确命中用日志判定,目录命中按外部素材标 input。
|
|
@@ -677,6 +1054,14 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
677
1054
|
item.sessionId = sessionId
|
|
678
1055
|
item.sessionTitle = globalCurrentMeta?.title ?? ''
|
|
679
1056
|
item.sessionCreatedAt = globalCurrentMeta?.createdAt ?? 0
|
|
1057
|
+
// 2026-11-24:全局「当前对话」组里的共享文件同样加共享标记
|
|
1058
|
+
if (globalCurrentSharedAbsSet !== null && globalCurrentSharedAbsSet.has(abs.toLowerCase())) {
|
|
1059
|
+
item.shared = true
|
|
1060
|
+
}
|
|
1061
|
+
// 2026-11-25:全局「当前对话」组里的继承文件同样加继承标记(分叉会话视角)
|
|
1062
|
+
if (globalCurrentInheritedAbsSet !== null && globalCurrentInheritedAbsSet.has(abs.toLowerCase())) {
|
|
1063
|
+
item.inherited = true
|
|
1064
|
+
}
|
|
680
1065
|
} else if (owner !== undefined) {
|
|
681
1066
|
item.category = owner.category
|
|
682
1067
|
item.sessionId = owner.sessionId
|
|
@@ -754,6 +1139,9 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
754
1139
|
...(item.mediaType !== undefined ? { mediaType: item.mediaType } : {}),
|
|
755
1140
|
// 截帧来源:反馈篮与草稿正文据此写清取自哪段视频的哪一帧
|
|
756
1141
|
...(item.frameOf !== undefined ? { frameOf: item.frameOf } : {}),
|
|
1142
|
+
// 2026-11-25:来源标记必须透传给全局分组,否则资产台卡片看不到角标
|
|
1143
|
+
...(item.inherited ? { inherited: true } : {}),
|
|
1144
|
+
...(item.shared ? { shared: true } : {}),
|
|
757
1145
|
})
|
|
758
1146
|
}
|
|
759
1147
|
}
|
|
@@ -776,6 +1164,10 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
|
|
|
776
1164
|
externalDirs: sessionDirSet?.size ?? 0,
|
|
777
1165
|
globalExternalDirs: globalCurrentDirs?.size ?? 0,
|
|
778
1166
|
externalAssets: matches.reduce((n, i) => n + (i.externalAsset ? 1 : 0), 0),
|
|
1167
|
+
// 2026-11-24:分叉会话继承自主线的资产数(条目本身带 inherited 在 items 里)
|
|
1168
|
+
inheritedAssets: (inheritedAbsSet ?? globalCurrentInheritedAbsSet)?.size ?? 0,
|
|
1169
|
+
// 2026-11-24:主线里被分叉会话带走的共享资产数
|
|
1170
|
+
sharedAssets: (sharedAbsSet ?? globalCurrentSharedAbsSet)?.size ?? 0,
|
|
779
1171
|
},
|
|
780
1172
|
root: opts.root,
|
|
781
1173
|
roots: opts.roots,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-gallery",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "产出台:图片 / 文件 / 音视频实时可见、当场校验;原生产出标签(素材 / 过程稿 / 定稿 / 未归类)可手动改且持久生效,改标签动作与图上圈选批注攒进反馈篮,由人审核合并后发送,全程零自动发送;视频「截取当前帧」自动存入当前对话资产;图上左键拖矩形、左键逐点圈不规则区域直接进反馈篮、右键逐点闭合成实心多边形导出 ComfyUI 直接可用的 RGBA 遮罩(选区内 alpha=0、RGB 保留原图),另出红 / 绿 / 蓝纯色半透明填充预览供目视核对;同一张图可连框多处,每处各带说明一并交给助手;内置三个只读工具——按关键词或对话标题查资产、读到「你此刻正在看哪张」与最近看过的十几张、给出你框选区域的整图像素矩形与外扩裁剪图并可直接取用你已画好的遮罩;图片查看器带像素级放大镜裁剪(绿框八向手柄、裁剪尺寸、光标处坐标与色值);分类显隐按图片 / 文件 / 音视频各记各的,支持多个扫描目录;把图拖进对话框会自动带上文件名与绝对路径(含对应主遮罩名),助手不必扫目录找图;图片查看器带前后对比——两张图叠在同一处用滑块左右拖动、放大后仍像素级对齐、也能切平铺并排看,批量选两张即可进对比,候选按遮罩关系/同尺寸智能推荐配对。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 / multi-point polygon / irregular region selections, ComfyUI-ready RGBA mask export (alpha=0 inside the selection, original RGB kept) plus a colored translucent fill preview, three read-only agent tools (keyword or conversation search, what you are viewing right now, and pixel rects plus expanded crops of your selections with direct reuse of a mask you already painted), pixel-level magnifier crop in the viewer, multi-root scanning, and drag-to-chat that carries the file name and absolute path so agents need no directory scan; before/after comparison in the viewer — two images stacked with a draggable slider that stays pixel-aligned when zoomed, or side-by-side tiles, batch-select two or pick from smart-ranked candidates by mask relation and matching size.",
|
|
6
6
|
"repository": {
|