dsh-gallery 0.12.1 → 0.13.7

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/marks.js ADDED
@@ -0,0 +1,136 @@
1
+ /**
2
+ * 标记存储(S3-a):独立的 dsh-gallery-marks.json,与 settings 分离。
3
+ *
4
+ * 为什么独立:主插件里有两个写者 —— 设置(roots / hidden)和标记(用户对卡片的判定)。
5
+ * 放同一文件会互相覆盖:A 读 → B 读 → A 写 → B 写,A 的改动就被 B 的旧快照冲掉。
6
+ * 拆成两个文件后,两个写者各管一份,配合 tmp → rename 原子写,不会丢写。
7
+ *
8
+ * 文件形态:
9
+ * {
10
+ * "schema": 1,
11
+ * "marks": {
12
+ * "<relPath>": {
13
+ * "action": "approve|reject|finalize|redo-one-dim|regenerate-selected|set-reference",
14
+ * "reason": "...", // 可选
15
+ * "changeOnly": ["色调"], // 可选:只改这些
16
+ * "keep": ["构图", "人物"], // 可选:这些锁死
17
+ * "preserve": ["..."] , // 可选:额外保留项
18
+ * "markedAt": 1700000000000
19
+ * }
20
+ * }
21
+ * }
22
+ */
23
+
24
+ import { promises as fsp } from 'node:fs'
25
+ import path from 'node:path'
26
+
27
+ /**
28
+ * 进程内写队列:把「读-改-写」串起来,避免并发 setMark 互相覆盖。
29
+ * 每个写操作追加到链尾,前一个失败也不阻断后续。
30
+ */
31
+ let writeChain = Promise.resolve()
32
+
33
+ function enqueue(fn) {
34
+ const next = writeChain.then(fn, fn)
35
+ // 吞掉失败,避免一个拒绝让整条链断掉
36
+ writeChain = next.catch(() => {})
37
+ return next
38
+ }
39
+
40
+ /** 允许的动作(与 src/shared/feedback-text.js 的 ACTIONS 保持一致)。 */
41
+ export const MARK_ACTIONS = [
42
+ 'approve',
43
+ 'reject',
44
+ 'finalize',
45
+ 'redo-one-dim',
46
+ 'regenerate-selected',
47
+ 'set-reference',
48
+ ]
49
+
50
+ const MARKS_FILENAME = 'dsh-gallery-marks.json'
51
+
52
+ /** marks 文件的绝对路径(与 settings 同目录)。 */
53
+ export function marksFilePath(settingsFile) {
54
+ return path.join(path.dirname(settingsFile), MARKS_FILENAME)
55
+ }
56
+
57
+ /**
58
+ * 读 marks。文件不存在 / 格式坏都返回空对象(不抛错,避免首次使用就报错)。
59
+ * @returns {Promise<{schema:number, marks:Object}>}
60
+ */
61
+ export async function readMarks(settingsFile) {
62
+ const file = marksFilePath(settingsFile)
63
+ try {
64
+ const raw = await fsp.readFile(file, 'utf8')
65
+ const parsed = JSON.parse(raw)
66
+ const marks = (parsed !== null && typeof parsed === 'object' && typeof parsed.marks === 'object' && parsed.marks !== null)
67
+ ? parsed.marks
68
+ : {}
69
+ return { schema: 1, marks }
70
+ } catch {
71
+ return { schema: 1, marks: {} }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * 写 marks —— 原子写(tmp → rename),避免半截文件。
77
+ * 使用独立 tmp 名(带 pid),并发写不会互相踩。
78
+ */
79
+ export async function writeMarks(settingsFile, marks) {
80
+ const file = marksFilePath(settingsFile)
81
+ // tmp 名必须唯一:并发写者若共用同一 tmp,第二个会撞上已被重命名的路径 → EPERM。
82
+ const tmp = `${file}.tmp-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
83
+ const payload = { schema: 1, marks: marks ?? {} }
84
+ await fsp.mkdir(path.dirname(file), { recursive: true })
85
+ await fsp.writeFile(tmp, JSON.stringify(payload, null, 2))
86
+ await fsp.rename(tmp, file)
87
+ }
88
+
89
+ /**
90
+ * 设/清一条标记。
91
+ * @param relPath - 卡片对应的相对路径(唯一键)。
92
+ * @param mark - 标记对象;传 null 表示清除。
93
+ * @returns 更新后的 marks
94
+ */
95
+ export async function setMark(settingsFile, relPath, mark) {
96
+ // 串行化:并发调用按顺序执行,后一个能读到前一个的写入结果
97
+ return enqueue(async () => {
98
+ const current = await readMarks(settingsFile)
99
+ const next = { ...current.marks }
100
+ if (mark === null || mark === undefined) {
101
+ delete next[relPath]
102
+ } else {
103
+ next[relPath] = { ...mark, markedAt: mark.markedAt ?? Date.now() }
104
+ }
105
+ await writeMarks(settingsFile, next)
106
+ return next
107
+ })
108
+ }
109
+
110
+ /**
111
+ * 批量设 / 清标记(v0.13.7)—— 一次读改写 + 一次原子写。
112
+ *
113
+ * 为什么批量:批量确认 20 张卡时,逐个 setMark 会触发 20 次「读文件 → 改 → 写」,
114
+ * 既慢又增加并发写窗口。这里串行化一次搞定。
115
+ *
116
+ * @param updates - [{ path: string, mark: object|null }] mark=null 表示清除
117
+ * @returns 更新后的 marks 对象
118
+ */
119
+ export async function setMarksBatch(settingsFile, updates) {
120
+ return enqueue(async () => {
121
+ const current = await readMarks(settingsFile)
122
+ const next = { ...current.marks }
123
+ for (const u of updates) {
124
+ const relPath = String(u?.path ?? "")
125
+ if (relPath === "") continue
126
+ const mark = u?.mark
127
+ if (mark === null || mark === undefined) {
128
+ delete next[relPath]
129
+ } else {
130
+ next[relPath] = { ...mark, markedAt: mark.markedAt ?? Date.now() }
131
+ }
132
+ }
133
+ await writeMarks(settingsFile, next)
134
+ return next
135
+ })
136
+ }
package/host/settings.js CHANGED
@@ -178,7 +178,9 @@ export async function writeSettingsFile(settingsFile, patch) {
178
178
  const current = readSettingsFile(settingsFile)
179
179
  const next = { ...current, ...patch }
180
180
  await fsp.mkdir(path.dirname(settingsFile), { recursive: true })
181
- await fsp.writeFile(settingsFile, JSON.stringify(next, null, 2), 'utf8')
181
+ const tmp = settingsFile + '.tmp-' + String(process.pid)
182
+ await fsp.writeFile(tmp, JSON.stringify(next, null, 2))
183
+ await fsp.rename(tmp, settingsFile)
182
184
  return next
183
185
  }
184
186
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-gallery",
3
- "version": "0.12.1",
3
+ "version": "0.13.7",
4
4
  "type": "module",
5
- "description": "产出画廊:解决 DSH 只在任务结尾才列出产出、过程不可见的问题。实时监控产出目录,图片自动刷新、文件原生预览、音视频面板内直接播放(blob 播放,任意大小都能拖进度条),还能一键截取视频当前帧,任务进行中即可校验纠正。",
5
+ "description": "产出画廊:图片 / 文件 / 音视频实时可见与当场校验;按标记筛选、把「定版」真正锁住、批量处置;图上圈选批注攒成决策草稿,人工确认后送回对话。Output gallery for DeepSeek Harness: live image, file and media gallery with marker filters, persisted confirmation, batch actions, region annotation and human-approved decision drafts.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/Hope2023Dcr/dsh-gallery.git"
@@ -58,7 +58,13 @@
58
58
  "media-gallery",
59
59
  "video-preview",
60
60
  "audio-preview",
61
- "range-seek"
61
+ "range-seek",
62
+ "filter",
63
+ "deliverable",
64
+ "confirm",
65
+ "batch",
66
+ "region-selection",
67
+ "annotation"
62
68
  ],
63
69
  "publishConfig": {
64
70
  "access": "public",