dsh-gallery 1.2.0 → 1.4.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/atomic.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 原子写 + 残留清理(2026-11-19)
3
+ *
4
+ * 为什么单独抽出来:
5
+ * 原先 context / feedback / marks / labels / frames 五个文件各写一遍
6
+ * 「writeFile(tmp) → rename(tmp, file)」,五处都**没有失败清理**。
7
+ * 2026-11-19 实测:~/.dsh 里积了 54 个 .tmp-* 文件、680 KB,
8
+ * 最久的从 11-14 留到 11-19 —— 每次进程被杀 / rename 被占用就漏一个。
9
+ *
10
+ * 这里的纪律:
11
+ * · 写 tmp 或 rename 任一步失败,立刻删掉 tmp;
12
+ * · 删 tmp 本身失败也不能盖住原始错误(原始错误才是要报给调用方的);
13
+ * · sweepStaleTmp 只在插件启动时跑一次,只清「本模块命名格式」的旧残留,
14
+ * 且只清超过 1 小时的(避免误删正在写的)。
15
+ */
16
+
17
+ import { promises as fsp } from 'node:fs'
18
+ import path from 'node:path'
19
+
20
+ /** tmp 文件名格式:<目标文件>.tmp-<pid>-<ts36>-<rand>;清洗时靠它识别 */
21
+ const TMP_RE = /\.tmp-\d+-[a-z0-9]+-[a-z0-9]+$/
22
+
23
+ /** 只清超过这个年龄的残留 */
24
+ const STALE_MS = 60 * 60 * 1000
25
+
26
+ function tmpNameFor(file) {
27
+ return `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
28
+ }
29
+
30
+ /**
31
+ * 原子写:写临时文件 → rename 覆盖。
32
+ * 任一步失败都会尝试删掉临时文件,然后把原始错误抛出去。
33
+ *
34
+ * @param file - 目标绝对路径
35
+ * @param content - 字符串(按 utf8 写)
36
+ */
37
+ export async function writeFileAtomic(file, content) {
38
+ const tmp = tmpNameFor(file)
39
+ let wrote = false
40
+ try {
41
+ await fsp.mkdir(path.dirname(file), { recursive: true })
42
+ await fsp.writeFile(tmp, content, 'utf8')
43
+ wrote = true
44
+ await fsp.rename(tmp, file)
45
+ wrote = false // rename 成功,tmp 已不存在
46
+ } catch (error) {
47
+ if (wrote) {
48
+ try { await fsp.rm(tmp, { force: true }) } catch { /* 删不掉也不能盖住原始错误 */ }
49
+ }
50
+ throw error
51
+ }
52
+ }
53
+
54
+ /**
55
+ * 清掉目录里「本模块命名格式」且已过期的残留 tmp。只扫一层,只清超龄的。
56
+ * 供插件启动时调用一次,用来收拾历史泄漏(修复前留下的那批)。
57
+ */
58
+ export async function sweepStaleTmp(dir) {
59
+ const out = { scanned: 0, removed: 0 }
60
+ let names
61
+ try { names = await fsp.readdir(dir) } catch { return out }
62
+ const now = Date.now()
63
+ for (const name of names) {
64
+ if (!TMP_RE.test(name)) continue
65
+ out.scanned += 1
66
+ const full = path.join(dir, name)
67
+ try {
68
+ const st = await fsp.stat(full)
69
+ if (now - st.mtimeMs < STALE_MS) continue
70
+ await fsp.unlink(full)
71
+ out.removed += 1
72
+ } catch { /* 单个失败不影响其它 */ }
73
+ }
74
+ return out
75
+ }
package/host/context.js CHANGED
@@ -25,6 +25,7 @@
25
25
  */
26
26
  import { promises as fsp } from 'node:fs'
27
27
  import path from 'node:path'
28
+ import { writeFileAtomic } from './atomic.js'
28
29
 
29
30
  const CONTEXT_FILENAME = 'dsh-gallery-context.json'
30
31
  export const MAX_RECENT = 20
@@ -145,10 +146,7 @@ async function writeStateFile(file, state) {
145
146
  // 万一有旧代码、或版本回滚后读这个文件,也不至于完全瞎掉。
146
147
  item: state.recent.length > 0 ? state.recent[0] : null,
147
148
  }
148
- await fsp.mkdir(path.dirname(file), { recursive: true })
149
- const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
150
- await fsp.writeFile(tmp, JSON.stringify(record, null, 2), 'utf8')
151
- await fsp.rename(tmp, file)
149
+ await writeFileAtomic(file, JSON.stringify(record, null, 2))
152
150
  return state
153
151
  }
154
152
 
package/host/feedback.js CHANGED
@@ -35,6 +35,7 @@
35
35
 
36
36
  import { promises as fsp } from 'node:fs'
37
37
  import path from 'node:path'
38
+ import { writeFileAtomic } from './atomic.js'
38
39
 
39
40
  const FEEDBACK_FILENAME = 'dsh-gallery-feedback.json'
40
41
 
@@ -51,27 +52,71 @@ export function feedbackFilePath(settingsFile) {
51
52
  return path.join(path.dirname(settingsFile), FEEDBACK_FILENAME)
52
53
  }
53
54
 
54
- /** 读待处理反馈。文件不存在 / 格式坏都返回空对象,绝不抛错。 */
55
- export async function readFeedback(settingsFile) {
55
+ /** 默认保留 7 天的待处理反馈;settings.feedbackTtlHours 可覆盖(<=0 表示永不过期)。 */
56
+ const DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1000
57
+
58
+ /** 把配置换成毫秒 TTL;0 表示关闭过期过滤。 */
59
+ function ttlMsOf(settings) {
60
+ const hours = Number(settings?.feedbackTtlHours)
61
+ if (Number.isFinite(hours)) {
62
+ if (hours <= 0) return 0
63
+ return Math.min(hours, 24 * 365) * 3600_000
64
+ }
65
+ return DEFAULT_TTL_MS
66
+ }
67
+
68
+ /**
69
+ * 一条反馈是否已过期。
70
+ * ⚠️ 没有 markedAt(或 markedAt 不是正数)的记录**一律保留** ——
71
+ * 老数据缺字段时宁可多留,也不该无故吞掉用户标过的意见(regions-tool R9 钉死)。
72
+ */
73
+ function isExpired(item, ttl, now) {
74
+ if (ttl <= 0) return false
75
+ const at = Number(item?.markedAt)
76
+ if (!Number.isFinite(at) || at <= 0) return false
77
+ return now - at > ttl
78
+ }
79
+
80
+ /** 读原始全量(不做过期过滤)。只给启动清扫用,别在业务路径上调。 */
81
+ async function readFeedbackRaw(settingsFile) {
56
82
  try {
57
83
  const raw = await fsp.readFile(feedbackFilePath(settingsFile), 'utf8')
58
84
  const parsed = JSON.parse(raw)
59
- const feedback = (parsed !== null && typeof parsed === 'object' &&
85
+ return (parsed !== null && typeof parsed === 'object' &&
60
86
  typeof parsed.feedback === 'object' && parsed.feedback !== null) ? parsed.feedback : {}
61
- return { schema: 1, feedback }
62
87
  } catch {
63
- return { schema: 1, feedback: {} }
88
+ return {}
89
+ }
90
+ }
91
+
92
+ /**
93
+ * 读待处理反馈。文件不存在 / 格式坏都返回空对象,绝不抛错。
94
+ *
95
+ * **纯读**:只过滤内存里的过期项,绝不写盘
96
+ * (getPendingFeedback 的红线:连续两次读一致 + 落盘文件不变)。
97
+ * 真正把过期项从盘上抹掉的是 sweepExpiredFeedback,只在插件启动时跑一次。
98
+ *
99
+ * @param settings - 可选;不传按默认 7 天过滤
100
+ */
101
+ export async function readFeedback(settingsFile, settings) {
102
+ const all = await readFeedbackRaw(settingsFile)
103
+ const ttl = ttlMsOf(settings)
104
+ if (ttl <= 0) return { schema: 1, feedback: all }
105
+ const now = Date.now()
106
+ const kept = {}
107
+ for (const [relPath, item] of Object.entries(all)) {
108
+ if (item === null || typeof item !== 'object') continue
109
+ if (isExpired(item, ttl, now)) continue
110
+ kept[relPath] = item
64
111
  }
112
+ return { schema: 1, feedback: kept }
65
113
  }
66
114
 
67
- /** 原子写(tmp → rename),tmp 名带 pid + 随机数,并发不互踩。 */
115
+ /** 原子写(见 atomic.js):失败自动清掉 tmp,不留残留。 */
68
116
  async function writeFeedback(settingsFile, feedback) {
69
117
  const file = feedbackFilePath(settingsFile)
70
- const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
71
118
  const payload = { schema: 1, feedback: feedback ?? {} }
72
- await fsp.mkdir(path.dirname(file), { recursive: true })
73
- await fsp.writeFile(tmp, JSON.stringify(payload, null, 2))
74
- await fsp.rename(tmp, file)
119
+ await writeFileAtomic(file, JSON.stringify(payload, null, 2))
75
120
  }
76
121
 
77
122
  /**
@@ -136,3 +181,29 @@ export async function clearFeedback(settingsFile) {
136
181
  return {}
137
182
  })
138
183
  }
184
+
185
+ /**
186
+ * 清掉盘上已过期的反馈 —— **只在插件启动时调一次**。
187
+ *
188
+ * 为什么不放在读路径:读一次就改一次盘,既有测试钉死了「读操作不得改动落盘文件」。
189
+ * 这里走写队列,和 setFeedback / ackFeedback 共用同一把串行锁,不会互相覆盖。
190
+ */
191
+ export async function sweepExpiredFeedback(settingsFile, settings) {
192
+ const ttl = ttlMsOf(settings)
193
+ if (ttl <= 0) return { removed: 0 }
194
+ return enqueue(async () => {
195
+ const all = await readFeedbackRaw(settingsFile)
196
+ const now = Date.now()
197
+ const kept = {}
198
+ let removed = 0
199
+ for (const [relPath, item] of Object.entries(all)) {
200
+ if (item === null || typeof item !== 'object' || isExpired(item, ttl, now)) {
201
+ removed += 1
202
+ continue
203
+ }
204
+ kept[relPath] = item
205
+ }
206
+ if (removed > 0) await writeFeedback(settingsFile, kept)
207
+ return { removed }
208
+ })
209
+ }
package/host/frames.js CHANGED
@@ -29,6 +29,7 @@
29
29
 
30
30
  import { promises as fsp } from 'node:fs'
31
31
  import path from 'node:path'
32
+ import { writeFileAtomic } from './atomic.js'
32
33
 
33
34
  const FRAMES_FILENAME = 'dsh-gallery-frames.json'
34
35
 
@@ -92,13 +93,10 @@ export async function buildLinkedMaskIndex(settingsFile) {
92
93
  }
93
94
  return index
94
95
  }
95
- /** 原子写(tmp → rename),tmp 名带 pid + 随机数,并发不互踩。 */
96
+ /** 原子写(见 atomic.js):失败自动清掉 tmp,不留残留。 */
96
97
  async function writeFrames(settingsFile, frames) {
97
98
  const file = framesFilePath(settingsFile)
98
- const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
99
- await fsp.mkdir(path.dirname(file), { recursive: true })
100
- await fsp.writeFile(tmp, JSON.stringify({ schema: 1, frames: frames ?? {} }, null, 2))
101
- await fsp.rename(tmp, file)
99
+ await writeFileAtomic(file, JSON.stringify({ schema: 1, frames: frames ?? {} }, null, 2))
102
100
  }
103
101
 
104
102
  /** 登记一帧(同 relPath 覆盖,避免重复截同一帧留下多条)。 */
package/host/http.js CHANGED
@@ -1400,8 +1400,10 @@ export function registerOpsRoute(ctx, config) {
1400
1400
  * 清零的时机是「人点发送」或「人点清空反馈篮」,走 ackFeedback。
1401
1401
  */
1402
1402
  try {
1403
- const settingsFile = resolveOptions(config).settingsFile
1404
- const fb = await readFeedback(settingsFile)
1403
+ const opts = resolveOptions(config)
1404
+ const settingsFile = opts.settingsFile
1405
+ // 传 settings:让 feedbackTtlHours 生效;不传则按默认 7 天过滤
1406
+ const fb = await readFeedback(settingsFile, opts)
1405
1407
  const marks = (await readMarks(settingsFile)).marks ?? {}
1406
1408
  /**
1407
1409
  * v0.16.5:一条落盘记录可能带**多条框选批注**(annotations 数组)。
@@ -1431,6 +1433,11 @@ export function registerOpsRoute(ctx, config) {
1431
1433
  // v0.16.4:带上分类与归属会话 —— Agent 拿到就能判断该改哪个文件、归哪条对话
1432
1434
  category: String(item.category ?? 'unknown'),
1433
1435
  sessionId: String(item.sessionId ?? ''),
1436
+ // v1.3.0:Agent 批示(gallery_reply 写入)。前端据此在反馈栏渲染批示卡片;
1437
+ // 不是批示的条目这些字段为空字符串,不影响既有渲染与草稿。
1438
+ kind: String(item.kind ?? ''),
1439
+ replyText: String(item.text ?? ''),
1440
+ replyOf: String(item.replyOf ?? ''),
1434
1441
  }
1435
1442
  const flatAction = String(item.action ?? '')
1436
1443
  const annots = Array.isArray(item.annotations)
@@ -1472,7 +1479,9 @@ export function registerOpsRoute(ctx, config) {
1472
1479
  let draft = ''
1473
1480
  try {
1474
1481
  const locale = body?.locale === 'en' ? 'en' : 'zh'
1475
- draft = renderFeedbackText(makeFeedback({ sessionId: '', items }), { locale })
1482
+ // v1.3.0:Agent 批示只在反馈栏给人看,不进「发给 Agent」的草稿 —— 否则等于把它自己的话再发回去。
1483
+ const draftItems = items.filter((it) => String(it?.kind ?? '') !== 'agent-reply')
1484
+ draft = renderFeedbackText(makeFeedback({ sessionId: '', items: draftItems }), { locale })
1476
1485
  } catch { draft = '' }
1477
1486
  return json({ ok: true, schema: 1, count: items.length, items, draft })
1478
1487
  } catch (error) {
package/host/labels.js CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { promises as fsp } from 'node:fs'
22
22
  import path from 'node:path'
23
+ import { writeFileAtomic } from './atomic.js'
23
24
 
24
25
  /** 允许手动指定的标签;与 classify.js 的 ASSET_CATEGORY 对齐(不含 unknown)。 */
25
26
  export const LABEL_CATEGORIES = ['input', 'intermediate', 'final']
@@ -52,14 +53,11 @@ export async function readLabels(settingsFile) {
52
53
  }
53
54
  }
54
55
 
55
- /** 原子写(tmp → rename),tmp 名带 pid + 随机数,并发不互踩。 */
56
+ /** 原子写(见 atomic.js):失败自动清掉 tmp,不留残留。 */
56
57
  async function writeLabels(settingsFile, labels) {
57
58
  const file = labelsFilePath(settingsFile)
58
- const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
59
59
  const payload = { schema: 1, labels: labels ?? {} }
60
- await fsp.mkdir(path.dirname(file), { recursive: true })
61
- await fsp.writeFile(tmp, JSON.stringify(payload, null, 2))
62
- await fsp.rename(tmp, file)
60
+ await writeFileAtomic(file, JSON.stringify(payload, null, 2))
63
61
  }
64
62
 
65
63
  /** 设 / 清一条标签覆写;label 为 null 表示「恢复自动判定」。 */
package/host/marks.js CHANGED
@@ -23,6 +23,7 @@
23
23
 
24
24
  import { promises as fsp } from 'node:fs'
25
25
  import path from 'node:path'
26
+ import { writeFileAtomic } from './atomic.js'
26
27
 
27
28
  /**
28
29
  * 进程内写队列:把「读-改-写」串起来,避免并发 setMark 互相覆盖。
@@ -83,12 +84,8 @@ export async function readMarks(settingsFile) {
83
84
  */
84
85
  export async function writeMarks(settingsFile, marks) {
85
86
  const file = marksFilePath(settingsFile)
86
- // tmp 名必须唯一:并发写者若共用同一 tmp,第二个会撞上已被重命名的路径 → EPERM。
87
- const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
88
87
  const payload = { schema: 1, marks: marks ?? {} }
89
- await fsp.mkdir(path.dirname(file), { recursive: true })
90
- await fsp.writeFile(tmp, JSON.stringify(payload, null, 2))
91
- await fsp.rename(tmp, file)
88
+ await writeFileAtomic(file, JSON.stringify(payload, null, 2))
92
89
  }
93
90
 
94
91
  /**
package/host/tools.js CHANGED
@@ -16,10 +16,13 @@
16
16
  * · 同名 tool 在同一层重复注册会抛错 —— 未捕获会让整个插件不激活,
17
17
  * 所以注册必须包 try/catch(deep-view 源码注释里踩过这个坑)
18
18
  *
19
- * 红线:本工具**只读**。不改资产、不写反馈、不替用户发送任何东西。
19
+ * 红线:gallery_find / gallery_context / gallery_regions 三个**只读**,不改资产、不替用户发送。
20
+ * 第四个工具 gallery_reply(2026-11-19)是唯一的写入口:只往反馈篮写一条「Agent 批示」,
21
+ * 仍然不碰资产、不 ack、不替用户发送任何东西 —— 人确认闸门不变。
20
22
  */
21
23
  import path from 'node:path'
22
24
  import { statSync } from 'node:fs'
25
+ import { isInside } from './fsutil.js'
23
26
  import { scanGallery } from './scan.js'
24
27
  import { applyAssetFilter, sortByRelevance } from './http.js'
25
28
  import { resolveOptions } from './settings.js'
@@ -33,12 +36,13 @@ import { buildLinkedMaskIndex } from './frames.js'
33
36
  // 区域感知(2026-11-16):把「人在这张图上框了哪儿」直接告诉模型。
34
37
  // 起因是实测:用户框选后说「把框里的字母改掉」,模型拿不到框的位置,
35
38
  // 只能翻 frames.json / 临时目录满地找,光找就花了 97 秒。
36
- import { readFeedback } from './feedback.js'
39
+ import { readFeedback, setFeedback } from './feedback.js'
37
40
  import { annotationsFor, latestAnnotationAt, materializeRegions, materializeMaskRegion } from './regions.js'
38
41
 
39
42
  const TOOL_NAME = 'gallery_find'
40
43
  const CONTEXT_TOOL_NAME = 'gallery_context'
41
44
  const REGIONS_TOOL_NAME = 'gallery_regions'
45
+ const REPLY_TOOL_NAME = 'gallery_reply'
42
46
  const MAX_LIMIT = 100
43
47
  const DEFAULT_LIMIT = 20
44
48
  // 第二档:gallery_context 一次列多少张「最近看过的」。
@@ -784,6 +788,125 @@ export function buildRegionsToolDefinition(config) {
784
788
  }
785
789
  }
786
790
 
791
+ /**
792
+ * renderReply:把写入确认渲染成给模型的一段话。
793
+ * 与另外三个工具一样是纯渲染,不触发任何副作用。
794
+ */
795
+ function renderReply(args, value) {
796
+ if (value?.error) return [{ type: 'text', text: `批示写回反馈栏失败:${value.error}` }]
797
+ const name = String(value?.relPath ?? '').split('/').pop() ?? String(value?.relPath ?? '')
798
+ const lines = []
799
+ lines.push(`已把批示写回反馈栏,针对的资产:${name}`)
800
+ lines.push(`批示:${value?.text ?? ''}`)
801
+ lines.push('这条批示现在显示在用户的反馈栏里,资产台也会高亮这张新图。')
802
+ lines.push('用户点头核准前不要当作已完成;如用户驳回,会带着补充意见再次回来。')
803
+ if (value?.hint) lines.push(value.hint)
804
+ return [{ type: 'text', text: lines.join('\n') }]
805
+ }
806
+
807
+ /**
808
+ * gallery_reply(2026-11-19):Agent 执行完改图后,把「批示」写回反馈栏。
809
+ *
810
+ * 为什么需要:前三个工具全只读,Agent 干完活没有任何通道把结果告诉人 ——
811
+ * 人得自己去资产台找新图、重新框、重新说一遍。本工具让 Agent 显式报一句批示,
812
+ * 结构化地落进反馈篮(kind:'agent-reply'),人点头核准才闭环。
813
+ *
814
+ * 红线:
815
+ * · 只往 feedback.json 写一条待处理批示,绝不 ack(不替人清)、绝不 cancel、绝不发送
816
+ * · 写之前校验 relPath 非空 + 落在产出根内 + 文件真实存在 —— 防止批示挂到错图
817
+ * · 同一路径再次写会覆盖旧批示(沿用 setFeedback 语义):一件事只留一条当前批示
818
+ */
819
+ export function buildReplyToolDefinition(config) {
820
+ return {
821
+ name: REPLY_TOOL_NAME,
822
+ description: 'Agent 执行完图片修改后,用本工具把「做了什么、请验收」的批示写回用户的反馈栏。'
823
+ + '凡是改完图需要用户看结果、点头确认时使用;写完后用户反馈栏会出现这条批示、资产台会高亮这张新图。'
824
+ + 'relPath 必须填写这次实际产出(改好)的那张图的相对路径 —— 只写真实存在的资产,'
825
+ + '写错路径会报错。本工具只写一条待用户核准的批示,不会替用户确认、清空或发送任何东西。',
826
+ parameters: {
827
+ type: 'object',
828
+ properties: {
829
+ relPath: {
830
+ type: 'string',
831
+ description: '这次改好、需要用户验收的新图相对路径(相对某个产出根,用 / 分隔)',
832
+ },
833
+ text: {
834
+ type: 'string',
835
+ description: '批示正文:简述做了哪些改动、哪些按「锁死」保持原样,请用户验收',
836
+ },
837
+ replyOf: {
838
+ type: 'string',
839
+ description: '可选:这条批示回应的是用户哪条原意见的相对路径,便于用户对照',
840
+ },
841
+ },
842
+ required: ['relPath', 'text'],
843
+ },
844
+ output: {
845
+ schema: {
846
+ type: 'object',
847
+ properties: {
848
+ ok: { type: 'boolean' },
849
+ relPath: { type: 'string' },
850
+ text: { type: 'string' },
851
+ hint: { type: 'string' },
852
+ error: { type: 'string' },
853
+ },
854
+ required: ['ok', 'relPath', 'text'],
855
+ },
856
+ render: renderReply,
857
+ },
858
+ async execute(args) {
859
+ const relPath = String(args?.relPath ?? '').replace(/\\/g, '/').trim()
860
+ const text = String(args?.text ?? '').trim().slice(0, 2000)
861
+ if (relPath === '') {
862
+ return { ok: false, relPath: '', text: '', error: '缺少 relPath(要验收的新图路径)' }
863
+ }
864
+ if (text === '') {
865
+ return { ok: false, relPath, text: '', error: '批示正文 text 不能为空' }
866
+ }
867
+ try {
868
+ const opts = resolveOptions(config)
869
+ const roots = Array.isArray(opts.roots) ? opts.roots : []
870
+ // 校验 relPath:必须落在某个产出根内且文件真实存在,防止批示挂到错图/恶意路径
871
+ let absPath = ''
872
+ let verified = false
873
+ for (const root of roots) {
874
+ const base = path.resolve(String(root ?? ''))
875
+ if (base === '') continue
876
+ const candidate = path.resolve(base, relPath)
877
+ if (!isInside(base, candidate)) continue
878
+ try {
879
+ if (statSync(candidate).isFile()) { absPath = candidate; verified = true; break }
880
+ } catch { /* 这个文件不在本根下,试下一个 */ }
881
+ }
882
+ if (!verified) {
883
+ return {
884
+ ok: false, relPath, text,
885
+ error: `找不到这张资产或路径越界:${relPath}(请确认是这次实际产出的图)`,
886
+ }
887
+ }
888
+ const replyOf = String(args?.replyOf ?? '').replace(/\\/g, '/').trim()
889
+ const item = {
890
+ kind: 'agent-reply',
891
+ action: 'review-reply',
892
+ text,
893
+ reason: text,
894
+ status: 'pending',
895
+ markedAt: Date.now(),
896
+ }
897
+ if (replyOf !== '') item.replyOf = replyOf
898
+ await setFeedback(opts.settingsFile, relPath, item)
899
+ return {
900
+ ok: true, relPath, text,
901
+ hint: `已写到反馈栏,指向 ${absPath}`,
902
+ }
903
+ } catch (error) {
904
+ return { ok: false, relPath, text, error: String(error?.message ?? error) }
905
+ }
906
+ },
907
+ }
908
+ }
909
+
787
910
  /**
788
911
  * 在插件 apply() 里调用。
789
912
  * 返回 disposer;任何失败都吞掉并记日志 —— 绝不能因为 tool 注册失败
@@ -794,6 +917,7 @@ export function registerTools(ctx, config) {
794
917
  buildToolDefinition(config),
795
918
  buildContextToolDefinition(config),
796
919
  buildRegionsToolDefinition(config),
920
+ buildReplyToolDefinition(config),
797
921
  ]
798
922
  if (!ctx?.tools || typeof ctx.tools.register !== 'function') {
799
923
  ctx?.logger?.warn?.('dsh-gallery: ctx.tools 不可用,Agent 工具未注册')
@@ -813,4 +937,5 @@ export function registerTools(ctx, config) {
813
937
  return () => { for (const d of disposers) { try { d() } catch { /* 忽略 */ } } }
814
938
  }
815
939
 
816
- export { TOOL_NAME, CONTEXT_TOOL_NAME, REGIONS_TOOL_NAME, rootOf, toRow, renderRows, renderContext, renderRegions }
940
+ export { TOOL_NAME, CONTEXT_TOOL_NAME, REGIONS_TOOL_NAME, REPLY_TOOL_NAME,
941
+ rootOf, toRow, renderRows, renderContext, renderRegions, renderReply }
package/index.js CHANGED
@@ -26,6 +26,9 @@ import { readFileSync } from 'node:fs'
26
26
  import path from 'node:path'
27
27
  import { resolveOptions } from './host/settings.js'
28
28
  import { registerTools } from './host/tools.js'
29
+ import os from 'node:os'
30
+ import { sweepStaleTmp } from './host/atomic.js'
31
+ import { sweepExpiredFeedback } from './host/feedback.js'
29
32
 
30
33
  export const inject = ['connection', 'webServer', 'tools']
31
34
 
@@ -34,6 +37,23 @@ export function apply(ctx, config) {
34
37
  registerOpsRoute(ctx, config)
35
38
  registerTools(ctx, config)
36
39
 
40
+ // ---- 启动时清一次历史残留(2026-11-19)----
41
+ // 修复前五处「写 tmp → rename」都没有失败清理,~/.dsh 下积了 54 个 .tmp-* 残留。
42
+ // 这里只清「本模块命名格式」且超过 1 小时的,避免误删正在写的;
43
+ // 过期反馈同理,只在这里删,读路径永远纯读。
44
+ // 全程 best-effort:失败绝不影响插件启动。
45
+ try {
46
+ void sweepStaleTmp(path.join(os.homedir(), '.dsh')).then((r) => {
47
+ if (r.removed > 0) ctx?.logger?.info?.(`dsh-gallery: 清掉 ${r.removed} 个残留 tmp`)
48
+ }).catch(() => {})
49
+ } catch { /* 忽略 */ }
50
+ try {
51
+ const opts = resolveOptions(config)
52
+ void sweepExpiredFeedback(opts.settingsFile, opts).then((r) => {
53
+ if (r.removed > 0) ctx?.logger?.info?.(`dsh-gallery: 清掉 ${r.removed} 条过期反馈`)
54
+ }).catch(() => {})
55
+ } catch { /* 忽略 */ }
56
+
37
57
  // ---- 资产变动追踪(增量刷新,2026-11-16)----
38
58
  // 任何进程往产出根里写资产,都会被 fs.watch 感知;前端凭版本号做增量刷新。
39
59
  // 全程 best-effort:失败只记日志,绝不影响面板本身。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-gallery",
3
- "version": "1.2.0",
3
+ "version": "1.4.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": {