dsh-gallery 1.4.1 → 1.5.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/host/tools.js CHANGED
@@ -37,12 +37,20 @@ import { buildLinkedMaskIndex } from './frames.js'
37
37
  // 起因是实测:用户框选后说「把框里的字母改掉」,模型拿不到框的位置,
38
38
  // 只能翻 frames.json / 临时目录满地找,光找就花了 97 秒。
39
39
  import { readFeedback, setFeedback } from './feedback.js'
40
+ // v1.5.0:交付清单。与 op exportManifest 共用同一个内核,两边数字永远一致。
41
+ import { readLabels } from './labels.js'
42
+ import { readFrames } from './frames.js'
43
+ import { buildManifest } from './manifest.js'
40
44
  import { annotationsFor, latestAnnotationAt, materializeRegions, materializeMaskRegion } from './regions.js'
41
45
 
42
46
  const TOOL_NAME = 'gallery_find'
43
47
  const CONTEXT_TOOL_NAME = 'gallery_context'
44
48
  const REGIONS_TOOL_NAME = 'gallery_regions'
45
49
  const REPLY_TOOL_NAME = 'gallery_reply'
50
+ const MANIFEST_TOOL_NAME = 'gallery_manifest'
51
+ // 清单一次最多回多少条:默认 200 够写交付说明,上限 500 防止把上下文撑爆
52
+ const MANIFEST_LIMIT_DEFAULT = 200
53
+ const MANIFEST_LIMIT_MAX = 500
46
54
  const MAX_LIMIT = 100
47
55
  const DEFAULT_LIMIT = 20
48
56
  // 第二档:gallery_context 一次列多少张「最近看过的」。
@@ -67,7 +75,8 @@ function scanCacheKey(config, kind, scope, sid, opts) {
67
75
  try { stamp += `${statSync(path.join(home, name)).mtimeMs}|` } catch { stamp += "0|" }
68
76
  }
69
77
  } catch { stamp = "" }
70
- return [kind, scope, sid, JSON.stringify(config ?? {}), stamp].join("~")
78
+ // 键里必须带 maxItems:列表要 60 条、清单要 5000 条,共用一份缓存会互相投毒
79
+ return [kind, scope, sid, String(opts?.maxItems ?? ''), JSON.stringify(config ?? {}), stamp].join("~")
71
80
  }
72
81
  async function scanWithShortCache(config, kind, scope, sid, opts) {
73
82
  const key = scanCacheKey(config, kind, scope, sid, opts)
@@ -907,6 +916,200 @@ export function buildReplyToolDefinition(config) {
907
916
  }
908
917
  }
909
918
 
919
+
920
+ /**
921
+ * 取一批资产的结构化清单(v1.5.0)。
922
+ *
923
+ * 与 op `exportManifest` 走**同一个** buildManifest:模型读到的条数、分类计数、
924
+ * 来源视频,跟用户导出的 CSV 必须完全对得上 —— 这是「一个内核两个出口」的意义。
925
+ *
926
+ * 扫描口径也与导出相同:一次取全,不按页翻。当前对话视图每翻一页都要重解一次
927
+ * 会话日志,翻十几页能把工具调用拖到几十秒。
928
+ */
929
+ async function manifestOf(args, exec, config) {
930
+ const a = args ?? {}
931
+ try {
932
+ const opts = resolveOptions(config)
933
+ const kind = a.kind === 'file' || a.kind === 'media' ? a.kind : 'image'
934
+ const execSessionId = typeof exec?.agent?.session?.id === 'string' ? exec.agent.session.id : ''
935
+ const scope = a.scope === 'session' && execSessionId !== '' ? 'session' : 'global'
936
+ const limit = Math.max(1, Math.min(MANIFEST_LIMIT_MAX, Math.trunc(Number(a.limit)) || MANIFEST_LIMIT_DEFAULT))
937
+ const cats = Array.isArray(a.categories) && a.categories.length > 0
938
+ ? a.categories.map((c) => String(c ?? ''))
939
+ : (typeof a.category === 'string' && a.category !== '' ? [a.category] : [])
940
+ const selected = Array.isArray(a.selected) ? a.selected.map((v) => String(v ?? '')).filter((v) => v !== '') : []
941
+
942
+ // 走短缓存:全库扫描实测 8 秒,同一轮里连着问两次不该扫两遍
943
+ const full = await scanWithShortCache(config, kind, scope, execSessionId, { ...opts, maxItems: 5000 })
944
+ const entries = Array.isArray(full?.items) ? [...full.items] : []
945
+ for (const g of (Array.isArray(full?.groups) ? full.groups : [])) {
946
+ for (const f of (Array.isArray(g?.files) ? g.files : [])) entries.push(f)
947
+ }
948
+
949
+ const [labelsDoc, framesDoc, feedbackDoc, maskIndex] = await Promise.all([
950
+ readLabels(opts.settingsFile),
951
+ readFrames(opts.settingsFile),
952
+ readFeedback(opts.settingsFile, opts),
953
+ buildLinkedMaskIndex(opts.settingsFile),
954
+ ])
955
+
956
+ const manifest = await buildManifest({
957
+ entries,
958
+ relPaths: selected,
959
+ categories: cats,
960
+ frames: framesDoc?.frames ?? {},
961
+ labels: labelsDoc?.labels ?? {},
962
+ feedback: feedbackDoc?.feedback ?? {},
963
+ masks: Object.fromEntries(maskIndex ?? []),
964
+ scope,
965
+ kind,
966
+ includeNotes: a.includeNotes === true,
967
+ includeSize: a.includeSize !== false,
968
+ // 与 op exportManifest 同口径:显式选中就必须全给(含继承 / 共享),
969
+ // 仅按分类扫整批时排除,两个出口才不会各说各的。
970
+ includeInherited: selected.length > 0,
971
+ maxItems: limit,
972
+ })
973
+
974
+ return {
975
+ found: manifest.items.length > 0,
976
+ total: manifest.summary.total,
977
+ truncated: manifest.truncated,
978
+ summary: manifest.summary,
979
+ items: manifest.items,
980
+ error: '',
981
+ }
982
+ } catch (error) {
983
+ return {
984
+ found: false, total: 0, truncated: false, summary: null, items: [],
985
+ error: String(error?.message ?? error),
986
+ }
987
+ }
988
+ }
989
+
990
+ /** 把清单写成模型能直接照着干活的样子:先给总量分布,再每条一行。 */
991
+ function renderManifest(args, value) {
992
+ if (value?.error) return [{ type: 'text', text: `取交付清单失败:${value.error}` }]
993
+ const items = Array.isArray(value?.items) ? value.items : []
994
+ if (items.length === 0) {
995
+ return [{ type: 'text', text: '这一批里没有符合条件的资产(可能还没打分类)。' }]
996
+ }
997
+ const s = value.summary ?? {}
998
+ const by = s.byCategory ?? {}
999
+ const lines = []
1000
+ lines.push(`共 ${value.total} 条${value.truncated ? `(本次只列前 ${items.length} 条,完整清单让用户点面板「导出清单」)` : ''}:`
1001
+ + `定稿 ${by.final ?? 0} / 素材 ${by.input ?? 0} / 过程稿 ${by.intermediate ?? 0} / 未归类 ${by.unknown ?? 0};`
1002
+ + `有遮罩 ${s.withMask ?? 0} 条,截帧 ${s.fromVideo ?? 0} 条,合计 ${s.totalBytesText || '—'}。`)
1003
+ for (const it of items) {
1004
+ const bits = [it.categoryText || it.category]
1005
+ if (it.width > 0 && it.height > 0) bits.push(`${it.width}×${it.height}`)
1006
+ if (it.bytesText) bits.push(it.bytesText)
1007
+ if (it.sessionTitle) bits.push(`会话「${it.sessionTitle}」`)
1008
+ if (it.videoName) bits.push(`取自 ${it.videoName}${it.timecode ? ` @ ${it.timecode}` : ''}`)
1009
+ if (it.maskPath) bits.push('有遮罩')
1010
+ lines.push(`· ${it.relPath} | ${bits.join(' | ')}`)
1011
+ if (it.absPath) lines.push(` 图:${it.absPath}`)
1012
+ if (it.note) lines.push(` 备注:${it.note}`)
1013
+ }
1014
+ lines.push('以上是这一批的完整清单,可直接据此作答或接着做下一轮改动;'
1015
+ + '不要再用命令行 / 脚本重复扫描核对,也不要再调一次本工具确认。'
1016
+ + '要给客户的 CSV / JSON 文件请让用户在面板上点「导出清单」—— 本工具只读,不生成文件。')
1017
+ return [{ type: 'text', text: lines.join('\n') }]
1018
+ }
1019
+
1020
+ /** v1.5.0:交付清单(只读)。给 Agent 读,导出文件那半在 op exportManifest。 */
1021
+ export function buildManifestToolDefinition(config) {
1022
+ return {
1023
+ name: MANIFEST_TOOL_NAME,
1024
+ description: '按分类或选中范围取一份结构化清单:文件名、相对/绝对路径、分类、尺寸、体积、修改时间、'
1025
+ + '来源对话、来源视频与时间码(截帧才有)、有无遮罩、反馈备注。'
1026
+ + '当用户说「把这批的清单给我」「定稿都有哪些」「整理一份交付清单」「按这个清单接着改」'
1027
+ + '「哪些是定稿哪些是过程稿」时用本工具 —— 不要让用户手抄文件名,也不要自己扫盘。'
1028
+ + '只读:不落盘、不发送任何消息。要生成给客户的 CSV / JSON 文件,请用户在面板上点「导出清单」。',
1029
+ parameters: {
1030
+ type: 'object',
1031
+ properties: {
1032
+ category: {
1033
+ type: 'string',
1034
+ description: '只取一类:final=定稿 / input=素材 / intermediate=过程稿 / unknown=未归类;留空=全部',
1035
+ },
1036
+ categories: {
1037
+ type: 'array',
1038
+ description: '取多类(与 category 二选一,本项优先)',
1039
+ items: { type: 'string' },
1040
+ },
1041
+ scope: { type: 'string', description: 'session=当前对话 / global=全部对话;默认 global' },
1042
+ kind: { type: 'string', description: 'image / file / media;默认 image' },
1043
+ selected: {
1044
+ type: 'array',
1045
+ description: '只要这些相对路径(用户在面板上批量选中的那批,直接从 gallery_context 或用户描述里取)',
1046
+ items: { type: 'string' },
1047
+ },
1048
+ includeNotes: { type: 'boolean', description: '是否带反馈篮里的备注;默认 false' },
1049
+ includeSize: { type: 'boolean', description: '是否补宽高与体积;默认 true(条目自带字段时不读盘)' },
1050
+ limit: { type: 'number', description: `最多返回条数,默认 ${MANIFEST_LIMIT_DEFAULT},最大 ${MANIFEST_LIMIT_MAX}` },
1051
+ },
1052
+ },
1053
+ output: {
1054
+ schema: {
1055
+ type: 'object',
1056
+ properties: {
1057
+ found: { type: 'boolean', description: '有没有取到资产' },
1058
+ total: { type: 'number', description: '清单条数' },
1059
+ truncated: { type: 'boolean', description: '是否因为上限被截断' },
1060
+ summary: {
1061
+ type: 'object',
1062
+ description: '总量与分布',
1063
+ properties: {
1064
+ total: { type: 'number' },
1065
+ byCategory: {
1066
+ type: 'object',
1067
+ properties: {
1068
+ final: { type: 'number' }, input: { type: 'number' },
1069
+ intermediate: { type: 'number' }, unknown: { type: 'number' },
1070
+ },
1071
+ },
1072
+ withMask: { type: 'number', description: '有配套遮罩的条数' },
1073
+ fromVideo: { type: 'number', description: '从视频截出来的帧图条数' },
1074
+ totalBytesText: { type: 'string', description: '总体积,如「4985.5 MB」' },
1075
+ },
1076
+ },
1077
+ items: {
1078
+ type: 'array',
1079
+ description: '清单明细,按相对路径升序',
1080
+ items: {
1081
+ type: 'object',
1082
+ properties: {
1083
+ index: { type: 'number' },
1084
+ name: { type: 'string' },
1085
+ relPath: { type: 'string' },
1086
+ absPath: { type: 'string' },
1087
+ category: { type: 'string', description: 'final / input / intermediate / unknown' },
1088
+ categoryText: { type: 'string', description: '中文分类名' },
1089
+ categoryManual: { type: 'boolean', description: '分类是用户手动改过的' },
1090
+ width: { type: 'number' }, height: { type: 'number' },
1091
+ bytesText: { type: 'string' },
1092
+ mtimeText: { type: 'string' },
1093
+ sessionTitle: { type: 'string' },
1094
+ videoName: { type: 'string', description: '截帧的来源视频文件名;非截帧为空' },
1095
+ timecode: { type: 'string', description: '截帧时间码,如 00-02-17-892' },
1096
+ maskPath: { type: 'string', description: '配套遮罩的相对路径;没有则为空' },
1097
+ note: { type: 'string', description: '反馈篮里的备注;includeNotes 开启时才有' },
1098
+ },
1099
+ required: ['relPath'],
1100
+ },
1101
+ },
1102
+ error: { type: 'string' },
1103
+ },
1104
+ },
1105
+ render: renderManifest,
1106
+ },
1107
+ async execute(args, exec) {
1108
+ return manifestOf(args, exec, config)
1109
+ },
1110
+ }
1111
+ }
1112
+
910
1113
  /**
911
1114
  * 在插件 apply() 里调用。
912
1115
  * 返回 disposer;任何失败都吞掉并记日志 —— 绝不能因为 tool 注册失败
@@ -918,6 +1121,7 @@ export function registerTools(ctx, config) {
918
1121
  buildContextToolDefinition(config),
919
1122
  buildRegionsToolDefinition(config),
920
1123
  buildReplyToolDefinition(config),
1124
+ buildManifestToolDefinition(config),
921
1125
  ]
922
1126
  if (!ctx?.tools || typeof ctx.tools.register !== 'function') {
923
1127
  ctx?.logger?.warn?.('dsh-gallery: ctx.tools 不可用,Agent 工具未注册')
@@ -937,5 +1141,5 @@ export function registerTools(ctx, config) {
937
1141
  return () => { for (const d of disposers) { try { d() } catch { /* 忽略 */ } } }
938
1142
  }
939
1143
 
940
- export { TOOL_NAME, CONTEXT_TOOL_NAME, REGIONS_TOOL_NAME, REPLY_TOOL_NAME,
1144
+ export { TOOL_NAME, CONTEXT_TOOL_NAME, REGIONS_TOOL_NAME, REPLY_TOOL_NAME, MANIFEST_TOOL_NAME,
941
1145
  rootOf, toRow, renderRows, renderContext, renderRegions, renderReply }
package/index.js CHANGED
@@ -29,6 +29,7 @@ import { registerTools } from './host/tools.js'
29
29
  import os from 'node:os'
30
30
  import { sweepStaleTmp } from './host/atomic.js'
31
31
  import { sweepExpiredFeedback } from './host/feedback.js'
32
+ import { sweepContext } from './host/context.js'
32
33
 
33
34
  export const inject = ['connection', 'webServer', 'tools']
34
35
 
@@ -47,6 +48,15 @@ export function apply(ctx, config) {
47
48
  if (r.removed > 0) ctx?.logger?.info?.(`dsh-gallery: 清掉 ${r.removed} 个残留 tmp`)
48
49
  }).catch(() => {})
49
50
  } catch { /* 忽略 */ }
51
+ // v1.5.0:浏览记录按 TTL 清扫(默认 0=不自动清,用户开了才跑)
52
+ try {
53
+ const opts = resolveOptions(config)
54
+ if (Number(opts.contextTtlHours) > 0) {
55
+ void sweepContext(opts.settingsFile, opts.contextTtlHours).then((r) => {
56
+ if (r.removed > 0) ctx?.logger?.info?.(`dsh-gallery: 清掉 ${r.removed} 条过期浏览记录`)
57
+ }).catch(() => {})
58
+ }
59
+ } catch { /* 忽略 */ }
50
60
  try {
51
61
  const opts = resolveOptions(config)
52
62
  void sweepExpiredFeedback(opts.settingsFile, opts).then((r) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gallery",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
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": {