dsh-gallery 0.16.2 → 0.16.6

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/client.js CHANGED
@@ -544,8 +544,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
544
544
  refresh: '刷新',
545
545
  preview: '预览',
546
546
  previewInSidebar: '在 DSH 右侧栏预览该文件',
547
- copy: '复制路径',
548
- copyPath: '复制该文件的绝对路径',
547
+ copy: '带路径复制',
548
+ copyPath: '复制文件名+绝对路径+关联遮罩(可直接粘进对话框)',
549
549
  copied: '已复制',
550
550
  openFolder: '打开所在文件夹',
551
551
  kindImage: '图片',
@@ -736,7 +736,7 @@ async function encodeMaskPngBytes(imageData, width, height) {
736
736
  ctxHide: '隐藏(不再列出)',
737
737
  ctxUnhide: '取消隐藏',
738
738
  ctxReveal: '打开所在文件夹',
739
- ctxCopy: '复制路径',
739
+ ctxCopy: '带路径复制',
740
740
  ctxDelete: '删除文件',
741
741
  ctxDeleteConfirm: '确认删除?此操作不可恢复',
742
742
  ctxDeleteYes: '确认删除',
@@ -770,6 +770,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
770
770
  feedbackBasketToggleHint: '打开/关闭反馈篮,可在此生成决策草稿',
771
771
  feedbackBasketTitleN: '反馈篮 · {n} 条',
772
772
  feedbackBasketEmpty: '还没有可发的条目。在卡片上右键选择动作,或在图片上框选批注,都会进这里。',
773
+ pendingFeedbackBadge: '{n} 条待处理',
774
+ pendingFeedbackBadgeHint: '有 {n} 条反馈还没处理。点这里打开反馈篮;生成草稿或清空后归零。',
773
775
  feedbackTargetSession: '将发往会话:{title}',
774
776
  feedbackForeignWarn: '有 {n} 条来自其他会话,不能一起提交(请先切到那个会话)。',
775
777
  feedbackForeignWarnShort: '含其他会话的条目,已禁用提交',
@@ -892,6 +894,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
892
894
  // v0.16.2 粘贴落点:全局视图下按「鼠标所在的对话组」决定,不是永远当前对话
893
895
  pasteTargetCurrent: '当前对话',
894
896
  pasteTo: '粘贴到「{target}」',
897
+ viewerCopyFile: '复制',
898
+ viewerCopyFileHint: 'Ctrl+C 复制当前文件(剪贴板里是文件本身,可直接在资源管理器或其他对话粘贴)',
895
899
  cropEnter: '裁剪',
896
900
  cropExit: '退出裁剪',
897
901
  cropConfirm: '确认裁剪',
@@ -924,8 +928,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
924
928
  refresh: 'Refresh',
925
929
  preview: 'Preview',
926
930
  previewInSidebar: 'Preview this file in the DSH sidebar',
927
- copy: 'Copy path',
928
- copyPath: 'Copy the absolute path of this file',
931
+ copy: 'Copy with path',
932
+ copyPath: 'Copy file name + absolute path + linked mask (pasteable into chat)',
929
933
  copied: 'Copied',
930
934
  openFolder: 'Open containing folder',
931
935
  kindImage: 'Images',
@@ -1115,7 +1119,7 @@ async function encodeMaskPngBytes(imageData, width, height) {
1115
1119
  ctxHide: 'Hide (stop listing)',
1116
1120
  ctxUnhide: 'Unhide',
1117
1121
  ctxReveal: 'Open containing folder',
1118
- ctxCopy: 'Copy path',
1122
+ ctxCopy: 'Copy with path',
1119
1123
  ctxDelete: 'Delete file',
1120
1124
  ctxDeleteConfirm: 'Delete permanently? This cannot be undone',
1121
1125
  ctxDeleteYes: 'Delete',
@@ -1147,6 +1151,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
1147
1151
  feedbackBasketToggleHint: 'Toggle the feedback basket to generate a draft',
1148
1152
  feedbackBasketTitleN: 'Feedback basket · {n} item(s)',
1149
1153
  feedbackBasketEmpty: 'Nothing to send yet. Right-click a card for an action, or box an area on an image — both land here.',
1154
+ pendingFeedbackBadge: '{n} pending',
1155
+ pendingFeedbackBadgeHint: '{n} feedback item(s) waiting. Click to open the basket; it clears after you generate a draft or empty it.',
1150
1156
  feedbackTargetSession: 'Will be sent to session: {title}',
1151
1157
  feedbackForeignWarn: '{n} item(s) belong to another session and cannot be sent together.',
1152
1158
  feedbackForeignWarnShort: 'Contains items from another session — submit disabled',
@@ -1267,6 +1273,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
1267
1273
  // v0.16.2 paste destination follows the hovered chat group in the global view
1268
1274
  pasteTargetCurrent: 'this chat',
1269
1275
  pasteTo: 'Paste into "{target}"',
1276
+ viewerCopyFile: 'Copy',
1277
+ viewerCopyFileHint: 'Ctrl+C copies this file to the clipboard (paste it in Explorer or another chat)',
1270
1278
  cropEnter: 'Crop',
1271
1279
  cropExit: 'Exit crop',
1272
1280
  cropConfirm: 'Apply crop',
@@ -2889,6 +2897,24 @@ async function encodeMaskPngBytes(imageData, width, height) {
2889
2897
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
2890
2898
  }
2891
2899
  .dg-basketToggle[data-gallery-basket-count="0"] { color: #a9b1bd; }
2900
+ /* v0.16.4 · B 档:待处理反馈角标(挂在反馈篮入口旁,点它=打开反馈篮) */
2901
+ .dg-pendingBadge {
2902
+ /* 反馈篮按钮是 fixed right:16px bottom:16px;角标放它正上方,不抢点击 */
2903
+ position: fixed; right: 16px; bottom: 56px; z-index: 45;
2904
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
2905
+ border: 0;
2906
+ border-radius: 999px;
2907
+ padding: 1px 8px;
2908
+ margin-left: 6px;
2909
+ font-size: 11px;
2910
+ line-height: 18px;
2911
+ font-weight: 600;
2912
+ cursor: pointer;
2913
+ color: #7a3d00;
2914
+ background: #ffe1b8;
2915
+ }
2916
+ .dg-pendingBadge:hover { background: #ffd39a; }
2917
+ .dg-pendingBadge:focus-visible { outline: 2px solid #ff9f43; outline-offset: 1px; }
2892
2918
 
2893
2919
  /* ---------- v0.13.7:分类开关 / 确认角标 / 批量 / 删除对话框 ---------- */
2894
2920
 
@@ -4035,7 +4061,7 @@ function serializeFeedback(feedback) {
4035
4061
  */
4036
4062
  function FeedbackBasket({ t, items, currentSessionId, targetSessionTitle,
4037
4063
  onClose, onRemove, onEdit, onClear, onEditSave,
4038
- onRemoveAnnotation, onClearAll }) {
4064
+ onRemoveAnnotation, onClearAll, onAck }) {
4039
4065
  // 语言判断:用 t 探测一个已知键 —— 命中中文就按 zh 渲染,否则 en。
4040
4066
  // (不引入 detectLocale,插件没有这个工具函数)
4041
4067
  const [locale] = React.useState(() => {
@@ -4118,6 +4144,16 @@ function serializeFeedback(feedback) {
4118
4144
  ? t('feedbackDraftReady')
4119
4145
  : t('feedbackDraftInClipboard'),
4120
4146
  })
4147
+ /**
4148
+ * v0.16.4:草稿已经写进 composer —— 这批反馈交到人手里了。
4149
+ * 此时才把「待处理」清掉(B 档角标归零)。
4150
+ * 注意:marks / labels 一个都不动,人还能继续看、继续改。
4151
+ */
4152
+ if (typeof onAck === 'function') {
4153
+ try {
4154
+ await onAck(items.map((it) => it.relPath))
4155
+ } catch { /* ack 失败不影响草稿已经写进去这个事实 */ }
4156
+ }
4121
4157
  } else {
4122
4158
  setNotice({ kind: 'failed', text: t('feedbackDraftFailed') })
4123
4159
  }
@@ -4126,7 +4162,7 @@ function serializeFeedback(feedback) {
4126
4162
  } finally {
4127
4163
  setBusy(false)
4128
4164
  }
4129
- }, [canSubmit, items, currentSessionId, locale, targetSessionTitle, t])
4165
+ }, [canSubmit, items, currentSessionId, locale, targetSessionTitle, t, onAck])
4130
4166
 
4131
4167
  return h('div', { className: 'dg-feedbackLayer', key: 'feedbackLayer' }, [
4132
4168
  h('div', {
@@ -5350,7 +5386,10 @@ function serializeFeedback(feedback) {
5350
5386
 
5351
5387
  const onCopy = async (event) => {
5352
5388
  event.stopPropagation()
5353
- const ok = await copyText(absPath)
5389
+ // v0.17.0:复制【结构化信息】而不是裸路径 —— 与拖图带的信息同格式,
5390
+ // 粘到对话框里,Agent 一次就拿到 文件名 / 绝对路径 / 主遮罩。
5391
+ const name = dragNameOf(item, absPath)
5392
+ const ok = await copyText(name)
5354
5393
  setCopied(ok)
5355
5394
  }
5356
5395
  const onEye = (event) => {
@@ -5823,7 +5862,7 @@ ${absPath}
5823
5862
  ])
5824
5863
  }
5825
5864
 
5826
- function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop }) {
5865
+ function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
5827
5866
  const item = items[index]
5828
5867
  // 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
5829
5868
  // 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
@@ -6210,11 +6249,20 @@ ${absPath}
6210
6249
  // 原图/预览切换:保留当前 zoom 与 pan,方便对比同一点细节
6211
6250
  event.preventDefault()
6212
6251
  toggleOriginal()
6252
+ } else if ((event.ctrlKey || event.metaKey) && (key === 'c' || key === 'C')) {
6253
+ // v0.16.3:Ctrl+C 复制**当前查看的这一份文件**(不是画面截图)。
6254
+ // 剪贴板里是文件对象,能直接粘到资源管理器 / 其他对话。
6255
+ // 有选中文本时让位给浏览器默认复制,别抢用户想复制的批注文字。
6256
+ const sel = typeof window.getSelection === 'function' ? window.getSelection() : null
6257
+ if (sel !== null && String(sel).trim() !== '') return
6258
+ if (typeof onCopyFile !== 'function') return
6259
+ event.preventDefault()
6260
+ onCopyFile(item.relPath)
6213
6261
  }
6214
6262
  }
6215
6263
  window.addEventListener('keydown', onKey)
6216
6264
  return () => window.removeEventListener('keydown', onKey)
6217
- }, [onClose, onStep, panStep, zoomBy, toggleOriginal])
6265
+ }, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath])
6218
6266
 
6219
6267
  const sliderDragRef = React.useRef(null)
6220
6268
  const onSliderPointerDown = (event) => {
@@ -6388,20 +6436,24 @@ ${absPath}
6388
6436
  },
6389
6437
  }, cropActive ? `✂ ${t('cropExit')}` : `✂ ${t('cropEnter')}`)
6390
6438
  : null,
6391
- // 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
6392
- // (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
6393
- // 这个按钮同时是「新 client.js 已加载」的可见标记 —— 看到它就说明面板不是旧模块。
6439
+ // v0.17.0:删掉查看器顶部的「⇥ 拖到对话」按钮。
6440
+ // 原来它存在是因为 Viewer 大图本身 draggable:false + pointerEvents:none
6441
+ // (标注态的中键平移 / 右键多边形都依赖它),需要一个可拖的把手。
6442
+ // 现在:列表卡片本身就能拖(dragstart 拦截照旧,会带绝对路径 / 主遮罩),
6443
+ // 查看器里改用工具条「⧉ 复制」或右键「带路径复制」拿同样信息。
6444
+ // v0.16.3:Ctrl+C 复制当前文件;按钮是这条快捷键的可见入口(远程控制也能点)
6394
6445
  h('button', {
6395
6446
  type: 'button',
6396
6447
  className: 'dg-btn',
6397
- key: 'dragAsset',
6398
- draggable: true,
6399
- 'data-gallery-relpath': item.relPath,
6400
- 'data-gallery-dragviewer': true,
6401
- title: '拖到对话:附带绝对路径 / 主遮罩 / 填充预览文件名',
6402
- 'aria-label': '拖到对话',
6403
- onClick: (event) => event.stopPropagation(),
6404
- }, '⇥ 拖到对话'),
6448
+ key: 'copyFile',
6449
+ 'data-gallery-copy-file': item.relPath,
6450
+ title: t('viewerCopyFileHint'),
6451
+ 'aria-label': t('viewerCopyFile'),
6452
+ onClick: (event) => {
6453
+ event.stopPropagation()
6454
+ if (typeof onCopyFile === 'function') onCopyFile(item.relPath)
6455
+ },
6456
+ }, `⧉ ${t('viewerCopyFile')}`),
6405
6457
  h('button', { type: 'button', className: 'dg-btn', key: 'prev', onClick: () => onStep(-1), 'aria-label': t('prev') }, '‹'),
6406
6458
  h('button', { type: 'button', className: 'dg-btn', key: 'next', onClick: () => onStep(1), 'aria-label': t('next') }, '›'),
6407
6459
  h('button', { type: 'button', className: 'dg-btn', key: 'close', onClick: onClose, 'aria-label': t('close') }, '✕'),
@@ -7603,12 +7655,24 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7603
7655
  * unknown —— 未归类
7604
7656
  */
7605
7657
  // v0.14.2:表态层下线,只剩 4 个原生标签(定稿 / 素材 / 过程稿 / 未归类)
7606
- const [categoryFilter, setCategoryFilter] = React.useState({
7607
- final: true,
7608
- input: true,
7609
- intermediate: true,
7610
- unknown: true,
7611
- })
7658
+ /**
7659
+ * v0.16.5:分类显隐**按看板类型分开记**(老板 2026-11-13 报)。
7660
+ *
7661
+ * 原来的坑:一份 categoryFilter 三类共用。在「文件」里关掉过程稿 / 素材
7662
+ * (文件一般只看终稿),切回「图片」时图片的过程稿和素材也跟着没了 ——
7663
+ * 得来回点开关。两类资产的正常看法本来就不同,开关不该互相牵连。
7664
+ *
7665
+ * 现在按 kind 各存一份:image / file / media 互不影响。
7666
+ * 「只记本次使用、不持久化」这条不变 —— 重开面板仍从全显示开始
7667
+ * (用户若忘了自己关过哪一类,会以为文件丢了)。
7668
+ */
7669
+ const [categoryFilterMap, setCategoryFilterMap] = React.useState(() => ({
7670
+ image: { final: true, input: true, intermediate: true, unknown: true },
7671
+ file: { final: true, input: true, intermediate: true, unknown: true },
7672
+ media: { final: true, input: true, intermediate: true, unknown: true },
7673
+ }))
7674
+ // 取值失败兜底到 image 那份(正常情况三种 kind 都建过桶,走不到这里)
7675
+ const categoryFilter = categoryFilterMap[kind] ?? categoryFilterMap.image
7612
7676
  /** 批量选择(v0.13.7):选中的 relPath 集合。清空条件:切 kind / 切 scope / 刷新后失效项自动剔除。 */
7613
7677
  const [selected, setSelected] = React.useState(new Set())
7614
7678
  /** 批量模式:用户显式开启,或已有选中项时自动生效(避免勾了看不见批量条)。 */
@@ -7616,10 +7680,72 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7616
7680
  /**
7617
7681
  * 框选批注(v0.14.0):按 relPath 存,一次查看器内可加多条。
7618
7682
  *
7619
- * 只记在内存 + 走草稿通道输出,**不落盘**(批注是"这次要跟 Agent 说的话",
7620
- * 不是需要长期保留的状态;确认态才落盘,两者语义不同)。
7683
+ * v0.16.4 起批注会写进「待处理反馈」落盘(A 档要 Agent 拉得到)。
7684
+ * v0.16.5 修:同一张图的多条批注**必须整组写**——
7685
+ * 原来每加一条就写一条 item,而 feedback.json 的键是 relPath,
7686
+ * 后写的把先写的覆盖掉,一张图框三处只剩最后一条。
7687
+ * 现在每次写「该图的完整批注数组」,Host 侧再展开成多条。
7688
+ *
7689
+ * 🔴 为什么必须有 ref:setAnnotations 的 updater 是异步的,
7690
+ * 写完马上要拿「加上这一条之后」的完整数组去落盘,读 state 会读到旧值。
7621
7691
  */
7622
7692
  const [annotations, setAnnotations] = React.useState({})
7693
+ const annotationsRef = React.useRef({})
7694
+ /**
7695
+ * recordPendingFeedback 定义在本段之后,但批注落盘要用它。
7696
+ * 用 ref 转一手,避免「先声明后使用」的顺序倒挂(TDZ)。
7697
+ */
7698
+ const recordPendingFeedbackRef = React.useRef(null)
7699
+ /** 批注的落盘形态:只留坐标与说明,id / markedAt 用于前端对号。 */
7700
+ const toStoredAnnot = React.useCallback((a) => ({
7701
+ id: String(a?.id ?? ''),
7702
+ note: typeof a?.note === 'string' ? a.note : '',
7703
+ region: {
7704
+ x: Number(a?.x) || 0,
7705
+ y: Number(a?.y) || 0,
7706
+ w: Number(a?.w) || 0,
7707
+ h: Number(a?.h) || 0,
7708
+ },
7709
+ markedAt: Number(a?.createdAt) || Date.now(),
7710
+ }), [])
7711
+ /** 某图当前批注的落盘形态(没有就返回空数组)。 */
7712
+ const storedAnnotsFor = React.useCallback((relPath) => {
7713
+ const list = annotationsRef.current?.[relPath]
7714
+ return Array.isArray(list) ? list.map(toStoredAnnot) : []
7715
+ }, [toStoredAnnot])
7716
+ /**
7717
+ * 同一条 relPath 上的批注写入「待处理」。
7718
+ *
7719
+ * action 语义:
7720
+ * · 该图还没有别的判定 → 'annotate'(按框选区域改)
7721
+ * · 该图已经有一条非 annotate 的判定(比如「交付不合格」)→ 保留原 action
7722
+ * 草稿里 mark 行与批注行本来就会各占一行,落盘这边也不能把前者冲掉。
7723
+ */
7724
+ const writePendingAnnotations = React.useCallback((relPath, list, meta) => {
7725
+ // ref 在渲染期挂载;理论上此时必然就绪,兜一手避免极端时序下抛错
7726
+ const fire = recordPendingFeedbackRef.current
7727
+ if (typeof fire !== 'function') return
7728
+ const annots = Array.isArray(list) ? list.map(toStoredAnnot) : []
7729
+ if (annots.length === 0) {
7730
+ void fire([{ path: relPath, item: null }])
7731
+ return
7732
+ }
7733
+ const prevAction = meta?.action ?? ''
7734
+ const keepAction = prevAction !== '' && prevAction !== 'annotate'
7735
+ void fire([{
7736
+ path: relPath,
7737
+ item: {
7738
+ ...(keepAction ? { action: prevAction } : { action: 'annotate' }),
7739
+ ...(keepAction && meta?.reason ? { reason: meta.reason } : {}),
7740
+ // 兼容旧读法:顶层 region 仍放最后一条,只读 region 的老逻辑不会空
7741
+ region: annots[annots.length - 1].region,
7742
+ annotations: annots,
7743
+ category: meta?.category ?? 'unknown',
7744
+ sessionId: meta?.sessionId ?? '',
7745
+ markedAt: Date.now(),
7746
+ },
7747
+ }])
7748
+ }, [toStoredAnnot])
7623
7749
  /**
7624
7750
  * 遮罩「原图 → 资产」的内存兜底(v0.14.5):导出成功后立刻登记,
7625
7751
  * 不用等列表重扫 / 翻页,反馈草稿马上就能带出遮罩路径。刷新后由扫描侧
@@ -7652,6 +7778,16 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7652
7778
  const [labelDialog, setLabelDialog] = React.useState(null)
7653
7779
  // 反馈篮是否打开
7654
7780
  const [basketOpen, setBasketOpen] = React.useState(false)
7781
+ /**
7782
+ * v0.16.4 · 待处理反馈条数(B 档角标)。
7783
+ *
7784
+ * 注意与 markedCount 的区别:
7785
+ * · markedCount = 反馈篮里现在有几条(来自 marks ∪ annotations,**持久状态**)
7786
+ * · pendingCount = 自上次「处理完」以来有几条新判定(**一次性消息**)
7787
+ * 人生成草稿 / 清空篮子后 pendingCount 归零,marks 保留 ——
7788
+ * 两者混同就会重演「删一条反馈把定好的标签也撤了」的错。
7789
+ */
7790
+ const [pendingCount, setPendingCount] = React.useState(0)
7655
7791
  // 编辑中的条目(null 表示不编辑)
7656
7792
  const [editingItem, setEditingItem] = React.useState(null)
7657
7793
  // 网格滚动位置:打开查看器前记录,关闭后恢复,让视图停在原缩略图处
@@ -7673,6 +7809,13 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7673
7809
  if (payload?.labels !== null && typeof payload?.labels === 'object') setLabels(payload.labels)
7674
7810
  })
7675
7811
  .catch((error) => console.warn('dsh-gallery: getLabels 失败', error))
7812
+ // v0.16.4 · B 档:台面打开时读一次待处理条数(纯读,不标记已读)
7813
+ callHost('getPendingFeedback', {})
7814
+ .then((payload) => {
7815
+ if (!alive || payload?.ok === false) return
7816
+ setPendingCount(Number.isFinite(payload?.count) ? payload.count : 0)
7817
+ })
7818
+ .catch((error) => console.warn('dsh-gallery: getPendingFeedback 失败', error))
7676
7819
  return () => { alive = false }
7677
7820
  }, [])
7678
7821
 
@@ -7691,10 +7834,13 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7691
7834
  return 'unknown'
7692
7835
  }, [])
7693
7836
 
7694
- /** 切一个分类的显隐。 */
7837
+ /** 切一个分类的显隐(v0.16.5:只作用于当前看板类型,三类各记各的)。 */
7695
7838
  const toggleCategory = React.useCallback((key) => {
7696
- setCategoryFilter((prev) => ({ ...prev, [key]: !prev[key] }))
7697
- }, [])
7839
+ setCategoryFilterMap((prev) => {
7840
+ const cur = prev[kind] ?? prev.image
7841
+ return { ...prev, [kind]: { ...cur, [key]: !cur[key] } }
7842
+ })
7843
+ }, [kind])
7698
7844
 
7699
7845
  /** 批量选择切换。 */
7700
7846
  const toggleSelect = React.useCallback((relPath) => {
@@ -7724,6 +7870,64 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7724
7870
  setLabelDialog({ item: first ?? null, paths, category: first?.category ?? 'unknown' })
7725
7871
  }, [selected])
7726
7872
 
7873
+ /**
7874
+ * 取某资产归属的会话 id(全局分组视图里组才有 sessionId,扁平列表没有)。
7875
+ *
7876
+ * ⚠️ 依赖只能用 `view`,**不能用 `data`**:`data` 在本组件后半段才声明,
7877
+ * 而依赖数组是渲染时立即求值的 —— 写 `[data, sessionId]` 会直接
7878
+ * `Cannot access 'data' before initialization`(渲染冒烟当场炸)。
7879
+ */
7880
+ const sessionIdOfPath = React.useCallback((relPath) => {
7881
+ const groups = (view.status === 'ready' && Array.isArray(view.data?.groups))
7882
+ ? view.data.groups
7883
+ : []
7884
+ for (const g of groups) {
7885
+ if (Array.isArray(g.files) && g.files.some((f) => f.relPath === relPath)) {
7886
+ return String(g.sessionId ?? '')
7887
+ }
7888
+ }
7889
+ return String(sessionId ?? '')
7890
+ }, [view, sessionId])
7891
+
7892
+ /**
7893
+ * v0.16.4 · A 档地基:把「人对资产的判定」镜像进待处理反馈。
7894
+ *
7895
+ * 为什么不复用 marks 当数据源:marks 是**持久状态**(改过就一直生效),
7896
+ * 而待处理反馈是**一次性消息**(人处理完就该消失)。Agent 要拉的是后者 ——
7897
+ * 「有新意见待处理」和「这张图当前是什么状态」是两件事。
7898
+ *
7899
+ * 全程只写反馈文件,不发送、不注入、不碰 composer。
7900
+ *
7901
+ * @param updates - [{ path, item }],item 传 null 表示从待处理里摘掉该条
7902
+ */
7903
+ const recordPendingFeedback = React.useCallback(async (updates) => {
7904
+ if (!Array.isArray(updates) || updates.length === 0) return
7905
+ try {
7906
+ const res = await callHost('setFeedbackBatch', { updates })
7907
+ if (res?.ok === false) throw new Error(res?.error?.message ?? 'setFeedbackBatch failed')
7908
+ if (Number.isFinite(res?.count)) setPendingCount(res.count)
7909
+ } catch (error) {
7910
+ // 落盘失败不能拦住主流程(标签/标记已经写成功了),但要留下线索
7911
+ console.warn('dsh-gallery: 待处理反馈落盘失败', error)
7912
+ }
7913
+ }, [])
7914
+ // 批注落盘那段(定义在本函数之前)要转一手调用,这里把最新引用挂上去
7915
+ recordPendingFeedbackRef.current = recordPendingFeedback
7916
+
7917
+ /**
7918
+ * v0.16.4:人已经处理完这批反馈(草稿进 composer / 清空篮子)→ 从待处理里移除。
7919
+ * **只有人能触发这个**;Agent 拉取(getPendingFeedback)绝不走这里。
7920
+ */
7921
+ const ackPending = React.useCallback(async (paths) => {
7922
+ try {
7923
+ const res = await callHost('ackFeedback', { paths: Array.isArray(paths) ? paths : [] })
7924
+ if (res?.ok === false) throw new Error(res?.error?.message ?? 'ackFeedback failed')
7925
+ if (Number.isFinite(res?.count)) setPendingCount(res.count)
7926
+ } catch (error) {
7927
+ console.warn('dsh-gallery: 确认待处理反馈失败', error)
7928
+ }
7929
+ }, [])
7930
+
7727
7931
  /**
7728
7932
  * 手动改标签的主逻辑(v0.14.2)。
7729
7933
  *
@@ -7795,6 +7999,21 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7795
7999
  const mp = await callHost('marksBatch', { updates: markUpdates })
7796
8000
  if (mp?.ok === false) throw new Error(mp?.error?.message ?? t('errorTitle'))
7797
8001
  if (mp?.marks !== undefined) setMarks(mp.marks)
8002
+ // v0.16.4 · A 档:这些判定进「待处理」(一次性),Agent 才拉得到。
8003
+ // 注意仍**不发送** —— 发送永远由人在反馈篮里点。
8004
+ await recordPendingFeedback(markUpdates.map((u) => ({
8005
+ path: u.path,
8006
+ item: {
8007
+ action: u.mark.action,
8008
+ ...(u.mark.reason !== undefined ? { reason: u.mark.reason } : {}),
8009
+ // v0.16.5:这张图上已有的框选批注要一起带上,
8010
+ // 否则「先框两处、再改标签」会把批注从待处理里冲掉
8011
+ ...(storedAnnotsFor(u.path).length > 0 ? { annotations: storedAnnotsFor(u.path) } : {}),
8012
+ category: u.mark.category ?? 'unknown',
8013
+ sessionId: sessionIdOfPath(u.path),
8014
+ markedAt: u.mark.markedAt ?? Date.now(),
8015
+ },
8016
+ })))
7798
8017
  }
7799
8018
  } catch (error) {
7800
8019
  console.warn('dsh-gallery: 改标签落盘失败', error)
@@ -7804,7 +8023,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7804
8023
  setBatchMode(false)
7805
8024
  // refresh 定义在本函数之后:不放进依赖数组,实际调用时早已初始化
7806
8025
  void refresh()
7807
- }, [labelDialog, t])
8026
+ }, [labelDialog, t, recordPendingFeedback, sessionIdOfPath, storedAnnotsFor])
7808
8027
 
7809
8028
  /**
7810
8029
  * 更新一条标记的附加字段(理由 / 只改 / 锁死)。
@@ -7824,8 +8043,23 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7824
8043
  } catch (error) {
7825
8044
  console.warn('dsh-gallery: 更新标记失败', error)
7826
8045
  }
8046
+ // v0.16.4 · A 档:编辑理由/只改/锁死也算一次新判定 → 刷新待处理里的那份
8047
+ await recordPendingFeedback([{
8048
+ path: relPath,
8049
+ item: {
8050
+ action: nextMark.action,
8051
+ ...(nextMark.reason !== undefined ? { reason: nextMark.reason } : {}),
8052
+ ...(Array.isArray(nextMark.changeOnly) && nextMark.changeOnly.length > 0 ? { changeOnly: nextMark.changeOnly } : {}),
8053
+ ...(Array.isArray(nextMark.keep) && nextMark.keep.length > 0 ? { keep: nextMark.keep } : {}),
8054
+ // v0.16.5:编辑判定时把这张图上的批注一起带上,别冲掉
8055
+ ...(storedAnnotsFor(relPath).length > 0 ? { annotations: storedAnnotsFor(relPath) } : {}),
8056
+ category: nextMark.category ?? 'unknown',
8057
+ sessionId: sessionIdOfPath(relPath),
8058
+ markedAt: nextMark.markedAt ?? Date.now(),
8059
+ },
8060
+ }])
7827
8061
  }
7828
- }, [])
8062
+ }, [recordPendingFeedback, sessionIdOfPath, storedAnnotsFor])
7829
8063
 
7830
8064
  /** 恢复自动判定:只删 labels 覆写,不动反馈篮里的任何条目。 */
7831
8065
  const resetLabels = React.useCallback(async () => {
@@ -7851,40 +8085,86 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7851
8085
  // v0.14.2:表态层的「确认 / 取消确认 / 单张表态」回调已整体移除,
7852
8086
  // 人的判断现在直接落在标签上(labels 覆写),表达走反馈篮。
7853
8087
 
7854
- /** 加一条批注(v0.14.0)。 */
8088
+ /** 加一条批注(v0.14.0)。v0.16.5:整组写盘,不再一条覆盖一条。 */
7855
8089
  const addAnnotation = React.useCallback((item, annot) => {
7856
8090
  const relPath = item.relPath
7857
- setAnnotations((prev) => {
7858
- const cur = prev[relPath] ?? []
7859
- if (cur.length >= 50) return prev // 与契约上限一致
7860
- return { ...prev, [relPath]: [...cur, annot] }
8091
+ const cur = annotationsRef.current[relPath] ?? []
8092
+ if (cur.length >= 50) return // 与契约上限一致
8093
+ const next = [...cur, annot]
8094
+ const nextAll = { ...annotationsRef.current, [relPath]: next }
8095
+ // 先同步 ref 再 setState:落盘要读「加上这一条之后」的完整数组
8096
+ annotationsRef.current = nextAll
8097
+ setAnnotations(nextAll)
8098
+ // v0.16.4 · A 档:框选批注同样是判定 → 进待处理。
8099
+ // v0.16.5:整组写,Agent 才拿得到同一张图上的每一处;
8100
+ // 若该图已有非批注判定(如「交付不合格」),保留那条 action 不被冲掉。
8101
+ const existing = marks[relPath]
8102
+ writePendingAnnotations(relPath, next, {
8103
+ category: item.category ?? 'unknown',
8104
+ sessionId: sessionIdOfPath(relPath),
8105
+ action: existing?.action ?? '',
8106
+ reason: existing?.reason ?? '',
7861
8107
  })
7862
- }, [])
8108
+ }, [marks, sessionIdOfPath, writePendingAnnotations])
7863
8109
 
7864
- /** 删一条批注。 */
8110
+ /** 删一条批注。v0.16.5:删完把剩下的整组回写,别让待处理里留着已删的那条。 */
7865
8111
  const removeAnnotation = React.useCallback((item, id) => {
7866
8112
  const relPath = item.relPath
7867
- setAnnotations((prev) => {
7868
- const cur = prev[relPath] ?? []
7869
- const next = cur.filter((a) => a.id !== id)
7870
- const out = { ...prev }
7871
- if (next.length === 0) delete out[relPath]
7872
- else out[relPath] = next
7873
- return out
7874
- })
7875
- }, [])
8113
+ const cur = annotationsRef.current[relPath] ?? []
8114
+ const next = cur.filter((a) => a.id !== id)
8115
+ const nextAll = { ...annotationsRef.current }
8116
+ if (next.length === 0) delete nextAll[relPath]
8117
+ else nextAll[relPath] = next
8118
+ annotationsRef.current = nextAll
8119
+ setAnnotations(nextAll)
8120
+ if (next.length === 0) {
8121
+ void recordPendingFeedback([{ path: relPath, item: null }])
8122
+ } else {
8123
+ writePendingAnnotations(relPath, next, {
8124
+ category: item?.category ?? 'unknown',
8125
+ sessionId: sessionIdOfPath(relPath),
8126
+ action: marks[relPath]?.action ?? '',
8127
+ reason: marks[relPath]?.reason ?? '',
8128
+ })
8129
+ }
8130
+ }, [marks, recordPendingFeedback, sessionIdOfPath, writePendingAnnotations])
7876
8131
 
7877
8132
  /** 删一条批注(按 relPath,反馈篮用;查看器走带 item 的那个)。 */
7878
8133
  const removeAnnotationById = React.useCallback((relPath, id) => {
7879
- setAnnotations((prev) => {
7880
- const cur = prev[relPath] ?? []
7881
- const next = cur.filter((a) => a.id !== id)
7882
- const out = { ...prev }
7883
- if (next.length === 0) delete out[relPath]
7884
- else out[relPath] = next
7885
- return out
7886
- })
7887
- }, [])
8134
+ const cur = annotationsRef.current[relPath] ?? []
8135
+ const next = cur.filter((a) => a.id !== id)
8136
+ const nextAll = { ...annotationsRef.current }
8137
+ if (next.length === 0) delete nextAll[relPath]
8138
+ else nextAll[relPath] = next
8139
+ annotationsRef.current = nextAll
8140
+ setAnnotations(nextAll)
8141
+ if (next.length === 0) {
8142
+ // 批注清空了,但若这张图还有标记判定,判定本身要留着
8143
+ const m = marks[relPath]
8144
+ if (m === undefined) void recordPendingFeedback([{ path: relPath, item: null }])
8145
+ else {
8146
+ void recordPendingFeedback([{
8147
+ path: relPath,
8148
+ item: {
8149
+ action: m.action,
8150
+ ...(m.reason !== undefined ? { reason: m.reason } : {}),
8151
+ ...(Array.isArray(m.changeOnly) && m.changeOnly.length > 0 ? { changeOnly: m.changeOnly } : {}),
8152
+ ...(Array.isArray(m.keep) && m.keep.length > 0 ? { keep: m.keep } : {}),
8153
+ category: m.category ?? 'unknown',
8154
+ sessionId: sessionIdOfPath(relPath),
8155
+ markedAt: m.markedAt ?? Date.now(),
8156
+ },
8157
+ }])
8158
+ }
8159
+ } else {
8160
+ writePendingAnnotations(relPath, next, {
8161
+ category: 'unknown',
8162
+ sessionId: sessionIdOfPath(relPath),
8163
+ action: marks[relPath]?.action ?? '',
8164
+ reason: marks[relPath]?.reason ?? '',
8165
+ })
8166
+ }
8167
+ }, [marks, recordPendingFeedback, sessionIdOfPath, writePendingAnnotations])
7888
8168
 
7889
8169
  /** 取某文件的批注列表(给查看器用)。 */
7890
8170
  const annotationsOf = React.useCallback((item) => {
@@ -7903,7 +8183,20 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7903
8183
  } catch (error) {
7904
8184
  console.warn('dsh-gallery: 清除标记失败', error)
7905
8185
  }
7906
- }, [])
8186
+ // v0.16.4:人主动撤掉一条 → 它也一并从「待处理」里摘掉。
8187
+ // v0.16.5:只摘「标记」,别连坐这张图上的批注 —— 撤掉判定不等于把框选说明也删了。
8188
+ const leftAnnots = annotationsRef.current[relPath] ?? []
8189
+ if (leftAnnots.length > 0) {
8190
+ writePendingAnnotations(relPath, leftAnnots, {
8191
+ category: 'unknown',
8192
+ sessionId: sessionIdOfPath(relPath),
8193
+ action: '',
8194
+ reason: '',
8195
+ })
8196
+ } else {
8197
+ await recordPendingFeedback([{ path: relPath, item: null }])
8198
+ }
8199
+ }, [recordPendingFeedback, sessionIdOfPath, writePendingAnnotations])
7907
8200
 
7908
8201
  /** 清空全部标记。 */
7909
8202
  const clearMarks = React.useCallback(async () => {
@@ -7912,6 +8205,17 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7912
8205
  for (const relPath of paths) {
7913
8206
  try { await callHost('marks', { path: relPath, mark: null }) } catch { /* 忽略单条失败 */ }
7914
8207
  }
8208
+ /**
8209
+ * v0.16.4:人点「清空反馈篮」= 明确表示这批已经处理完。
8210
+ * 待处理反馈一并清掉(不传 paths 即清空全部);
8211
+ * 手动标签 labels 不动 —— 那是持久状态,与「有没有待办」无关。
8212
+ */
8213
+ try {
8214
+ await callHost('ackFeedback', {})
8215
+ setPendingCount(0)
8216
+ } catch (error) {
8217
+ console.warn('dsh-gallery: 清空待处理反馈失败', error)
8218
+ }
7915
8219
  }, [marks])
7916
8220
 
7917
8221
  /** 打开右键菜单。 */
@@ -7920,7 +8224,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7920
8224
  lastContextRelPath.current = item.relPath
7921
8225
  setCtxMenu({
7922
8226
  item,
7923
- absPath: absPath ?? buildAbsPath(view.status === 'ready' ? view.data.root : '', item.relPath),
8227
+ absPath: absPath ?? (typeof item?.absPath === 'string' && item.absPath !== ''
8228
+ ? item.absPath
8229
+ : buildAbsPath(view.status === 'ready' ? view.data.root : '', item.relPath)),
7924
8230
  x: event.clientX,
7925
8231
  y: event.clientY,
7926
8232
  })
@@ -7949,12 +8255,21 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
7949
8255
  }
7950
8256
  }
7951
8257
  // 只保留查看器需要的字段,避免把整个分组对象塞进 state
8258
+ //
8259
+ // 🔴 这个白名单是「查看器能拿到什么」的唯一来源:字段没进来,
8260
+ // 下游就永远是 undefined。v0.16.4 踩过 —— 批注落盘要写 category,
8261
+ // 而这里没带,结果 `item.category ?? 'unknown'` 一路兜底成 unknown,
8262
+ // 磁盘上两条裁剪批注的分类全丢了(登记里明明是 input)。
8263
+ // 以后要给批注 / 遮罩加字段,先加到这里。
7952
8264
  const snapshot = list.map((it) => ({
7953
8265
  relPath: it.relPath,
7954
8266
  name: it.name ?? it.relPath.split('/').pop(),
7955
8267
  extension: it.extension ?? ('.' + (it.relPath.split('.').pop() || '')),
7956
8268
  width: it.width ?? null,
7957
8269
  height: it.height ?? null,
8270
+ // v0.16.4:分类(素材 / 过程稿 / 定稿),批注落盘与草稿都要用
8271
+ category: it.category ?? 'unknown',
8272
+ categoryManual: it.categoryManual === true,
7958
8273
  }))
7959
8274
  // v0.16.2:记住这张图属于哪个对话组 —— 裁剪产物要跟着来源组落盘,
7960
8275
  // 不能一律塞进当前对话(否则在历史对话的图上裁剪,产物跑到别的对话)。
@@ -8380,7 +8695,13 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8380
8695
  }
8381
8696
  const rel = String(it?.relPath ?? '')
8382
8697
  if (rel !== '' && !dragAssetIndex.has(rel)) {
8383
- dragAssetIndex.set(rel, { item: it, absPath: buildAbsPath(root, rel) })
8698
+ // v0.17.0:优先用 Host 下发的 absPath —— Host 用 rootOfAbs 按文件真实落盘位置
8699
+ // 算,是权威值。原来用 buildAbsPath(root, rel) 拿【第一个 root】去拼,
8700
+ // 文件在别的 root 下时拼出的是不存在的路径(实测三次都踩)。
8701
+ const realAbs = (typeof it?.absPath === 'string' && it.absPath !== '')
8702
+ ? it.absPath
8703
+ : buildAbsPath(root, rel)
8704
+ dragAssetIndex.set(rel, { item: it, absPath: realAbs })
8384
8705
  }
8385
8706
  }
8386
8707
  if (Array.isArray(data.items)) data.items.forEach(put)
@@ -8531,6 +8852,27 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8531
8852
  ? format(t('feedbackBasketToggleN'), { n: markedCount })
8532
8853
  : t('feedbackBasketToggle'))
8533
8854
 
8855
+ /**
8856
+ * v0.16.4 · B 档:待处理反馈角标。
8857
+ *
8858
+ * 为什么要和上面那个「反馈篮 · N 条」并存:
8859
+ * · 按钮上的 N = 篮子里现在有几条(持久)
8860
+ * · 角标上的 N = 自上次处理完以来有几条新判定(一次性)
8861
+ * 人做完一轮后按钮还显示条数(标记还在),但角标归零 —— 表示「没有待办了」。
8862
+ * 点角标 = 打开反馈篮,**不会**自动拉给 Agent。
8863
+ */
8864
+ const pendingBadge = pendingCount > 0
8865
+ ? h('button', {
8866
+ type: 'button',
8867
+ className: 'dg-pendingBadge',
8868
+ key: 'pendingBadge',
8869
+ 'data-gallery-pending-count': pendingCount,
8870
+ title: format(t('pendingFeedbackBadgeHint'), { n: pendingCount }),
8871
+ 'aria-label': format(t('pendingFeedbackBadgeHint'), { n: pendingCount }),
8872
+ onClick: () => setBasketOpen(true),
8873
+ }, format(t('pendingFeedbackBadge'), { n: pendingCount }))
8874
+ : null
8875
+
8534
8876
  /**
8535
8877
  * 各分类的全局计数(供顶部开关显示数字 + 判断「已显示 N / 共 M」)。
8536
8878
  * v0.13.7:确认态计数来自 marks,不来自自动分类。
@@ -8855,7 +9197,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8855
9197
  }
8856
9198
 
8857
9199
  if (useGroups) {
8858
- const cardFor = (item, groupKey, listForViewer) => {
9200
+ const cardFor = (item, groupKey, listForViewer, groupMeta) => {
8859
9201
  // 分组里的文件也走同一套卡片组件
8860
9202
  const enriched = {
8861
9203
  ...item,
@@ -8873,7 +9215,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8873
9215
  ?? (VIDEO_EXTS.includes(String(enriched.extension ?? '').toLowerCase()) ? 'video' : 'audio'),
8874
9216
  },
8875
9217
  t,
8876
- absPath: buildAbsPath(data.root, item.relPath),
9218
+ absPath: (typeof item?.absPath === 'string' && item.absPath !== ''
9219
+ ? item.absPath
9220
+ : buildAbsPath(data.root, item.relPath)),
8877
9221
  // v0.16.2:选段产物跟来源组走(groupKey 就是该组 sessionId)
8878
9222
  onPlay: (target) => setMediaPlaying({ ...target, originSessionId: groupKey }),
8879
9223
  onContextMenu: openContextMenu,
@@ -8884,7 +9228,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8884
9228
  key: `${groupKey}:${item.relPath}`,
8885
9229
  item: enriched,
8886
9230
  t,
8887
- absPath: buildAbsPath(data.root, item.relPath),
9231
+ absPath: (typeof item?.absPath === 'string' && item.absPath !== ''
9232
+ ? item.absPath
9233
+ : buildAbsPath(data.root, item.relPath)),
8888
9234
  onOpenFolder: () => { void callHost('reveal', { path: item.relPath }).catch((e) => console.error('dsh-gallery: reveal 失败', e)) },
8889
9235
  onContextMenu: openContextMenu,
8890
9236
  onPreview: (abs) => {
@@ -8896,7 +9242,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8896
9242
  void copyText(abs)
8897
9243
  }
8898
9244
  },
8899
- onCopy: (abs) => { void copyText(abs) },
9245
+ // v0.17.0:同右键菜单,复制结构化信息(文件名 + 绝对路径 + 关联遮罩)
9246
+ onCopy: (abs) => { void copyText(dragNameOf(item, abs)) },
8900
9247
  }), item, `${groupKey}:${item.relPath}`)
8901
9248
  }
8902
9249
  return wrapCard(h(Card, {
@@ -8908,7 +9255,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8908
9255
  onOpen: (opened, anchorEl) => {
8909
9256
  // 用**该组当前可见的文件**作为查看器列表:
8910
9257
  // 左右切图应在本组内循环,而不是跳到别的对话的图。
8911
- const list = Array.isArray(listForViewer) ? listForViewer : group.files
9258
+ const list = Array.isArray(listForViewer) ? listForViewer : (groupMeta?.files ?? [])
8912
9259
  let pos = list.indexOf(opened)
8913
9260
  if (pos < 0) {
8914
9261
  // 对象引用对不上时按 relPath 找(enriched 是浅拷贝,引用可能不同)
@@ -8916,7 +9263,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
8916
9263
  }
8917
9264
  if (pos < 0) return
8918
9265
  // v0.16.2:把这张图所属的组带给查看器,裁剪产物要落回同一个对话
8919
- openViewer(pos, anchorEl ?? null, list, false, { sessionId: groupKey, title: group.title ?? '' })
9266
+ openViewer(pos, anchorEl ?? null, list, false, { sessionId: groupKey, title: groupMeta?.title ?? '' })
8920
9267
  },
8921
9268
  }), item, `${groupKey}:${item.relPath}`)
8922
9269
  }
@@ -9015,7 +9362,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9015
9362
  h('div', { className: 'dg-groupBody', key: 'body' }, [
9016
9363
  visibleFiles.length > 0
9017
9364
  ? h('div', { className: `dg-grid${kind === 'file' ? ' dg-fileGrid' : ''}`, key: 'grid' },
9018
- visibleFiles.map((f) => cardFor(f, headKey, visibleFiles)))
9365
+ visibleFiles.map((f) => cardFor(f, headKey, visibleFiles, group)))
9019
9366
  : h('div', { className: 'dg-groupEmpty', key: 'empty' }, t('groupEmpty')),
9020
9367
  group.truncated
9021
9368
  ? h('div', { className: 'dg-groupEmpty', key: 'trunc', style: { marginTop: '8px' } },
@@ -9062,7 +9409,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9062
9409
  item,
9063
9410
  t,
9064
9411
  limiter: limiter.current,
9065
- absPath: buildAbsPath(data === null ? '' : data.root, item.relPath),
9412
+ absPath: (typeof item?.absPath === 'string' && item.absPath !== ''
9413
+ ? item.absPath
9414
+ : buildAbsPath(data === null ? '' : data.root, item.relPath)),
9066
9415
  onPlay: (target) => setMediaPlaying(target),
9067
9416
  onContextMenu: openContextMenu,
9068
9417
  }), item, item.relPath))
@@ -9072,7 +9421,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9072
9421
  key: item.relPath,
9073
9422
  item,
9074
9423
  t,
9075
- absPath: buildAbsPath(data.root, item.relPath),
9424
+ absPath: (typeof item?.absPath === 'string' && item.absPath !== ''
9425
+ ? item.absPath
9426
+ : buildAbsPath(data.root, item.relPath)),
9076
9427
  onOpenFolder: (abs) => { void callHost('reveal', { path: item.relPath }).catch((e) => console.error('dsh-gallery: reveal 失败', e)) },
9077
9428
  onContextMenu: openContextMenu,
9078
9429
  onPreview: (abs) => {
@@ -9229,6 +9580,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9229
9580
  onClose: closeViewer,
9230
9581
  onStep: step,
9231
9582
  onCrop: doCrop,
9583
+ // v0.16.3:Ctrl+C / 顶部按钮 → 复制当前文件(复用 copyAssets,Host 解析绝对路径写剪贴板)
9584
+ onCopyFile: (relPath) => { void doCopyAssets([relPath]) },
9232
9585
  }))
9233
9586
  : null
9234
9587
 
@@ -9342,7 +9695,14 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9342
9695
  // 批注:属于反馈侧,删一条只动内存,不碰 marks
9343
9696
  onRemoveAnnotation: (relPath, annotId) => { removeAnnotationById(relPath, annotId) },
9344
9697
  // 「清空反馈篮」= 表态 + 批注一起清,否则批注留在图上、篮子却空了
9345
- onClearAll: () => { void clearMarks(); setAnnotations({}) },
9698
+ onClearAll: () => {
9699
+ // ref 与 state 必须一起清:ref 是落盘读的那份,漏了就会把已清空的批注又写回去
9700
+ annotationsRef.current = {}
9701
+ void clearMarks()
9702
+ setAnnotations({})
9703
+ },
9704
+ // v0.16.4:草稿进 composer 后把待处理清零(人已处理完这批)
9705
+ onAck: (paths) => { void ackPending(paths) },
9346
9706
  })
9347
9707
  : null
9348
9708
 
@@ -9379,7 +9739,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9379
9739
  : undefined,
9380
9740
  onHide: () => { void doHide(ctxMenu.item) },
9381
9741
  onReveal: () => { void doReveal(ctxMenu.item) },
9382
- onCopy: () => { void copyText(ctxMenu.absPath) },
9742
+ // v0.17.0:复制【结构化信息】而不是裸路径 —— 与拖图带的信息同格式,
9743
+ // 粘到对话框里,Agent 一次就拿到 文件名 / 绝对路径 / 主遮罩。
9744
+ onCopy: () => { void copyText(dragNameOf(ctxMenu.item, ctxMenu.absPath)) },
9383
9745
  // v0.16.0 单文件复制:写系统剪贴板文件列表,可在别的对话粘贴
9384
9746
  onCopyFile: () => { void doCopyAssets([ctxMenu.item.relPath]) },
9385
9747
  onDelete: () => setDeleteTarget({ item: ctxMenu.item, busy: false }),
@@ -9440,6 +9802,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9440
9802
  return h('div', { className: 'dg-root', 'data-gallery-root': true }, [
9441
9803
  header,
9442
9804
  basketToggle,
9805
+ pendingBadge,
9443
9806
  batchBar,
9444
9807
  discardEntry,
9445
9808
  discardDialogNode,
@@ -9808,6 +10171,104 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9808
10171
  getFeedbackDraft() {
9809
10172
  return draftRef.current ?? ''
9810
10173
  },
10174
+ /**
10175
+ * v0.16.4 · A 档:按条件取资产(**结构化**,不是渲染文本)。
10176
+ *
10177
+ * 为什么给结构化:Agent 要自己判断「这批图够不够用」,
10178
+ * 只给一坨文字它没法筛、没法排序、没法拿路径去喂工作流。
10179
+ *
10180
+ * 走既有的 `list` op(Host 侧做筛选与缓存),**不新增扫描路径**。
10181
+ * 纯读:不写任何文件、不发消息、不影响台面状态。
10182
+ *
10183
+ * @param filter - {
10184
+ * kind?: 'image'|'file'|'media', scope?: 'global'|'session', sessionId?: string,
10185
+ * label?: 'input'|'intermediate'|'final', // 与 category 同义,取生效值(手动标签优先)
10186
+ * category?: 同上, confirmed?: boolean, action?: string,
10187
+ * ext?: '.png', q?: string, limit?: number, page?: number
10188
+ * }
10189
+ * @returns { schema, items, count, total, error? }
10190
+ */
10191
+ async listAssets(filter) {
10192
+ const f = (filter !== null && typeof filter === 'object') ? filter : {}
10193
+ try {
10194
+ const payload = await callHost('list', f)
10195
+ if (payload?.ok === false) {
10196
+ return { schema: 1, items: [], count: 0, total: 0, error: String(payload?.error?.message ?? 'list failed') }
10197
+ }
10198
+ // 全局分组视图下文件在 groups[].files,扁平视图下在 items —— 两种都摊平
10199
+ const flat = []
10200
+ if (Array.isArray(payload?.items)) for (const it of payload.items) flat.push(it)
10201
+ if (Array.isArray(payload?.groups)) {
10202
+ for (const g of payload.groups) {
10203
+ if (!Array.isArray(g?.files)) continue
10204
+ for (const it of g.files) {
10205
+ flat.push({
10206
+ ...it,
10207
+ sessionId: it.sessionId ?? g.sessionId,
10208
+ sessionTitle: it.sessionTitle ?? g.title,
10209
+ })
10210
+ }
10211
+ }
10212
+ }
10213
+ const seen = new Set()
10214
+ const items = []
10215
+ for (const it of flat) {
10216
+ const relPath = String(it?.relPath ?? '')
10217
+ if (relPath === '' || seen.has(relPath)) continue
10218
+ seen.add(relPath)
10219
+ items.push({
10220
+ relPath,
10221
+ // absolute 必须给:Agent 要拿它去改文件 / 喂工作流
10222
+ absolute: String(it.absPath ?? ''),
10223
+ name: String(it.name ?? relPath.split('/').pop() ?? relPath),
10224
+ category: String(it.category ?? 'unknown'),
10225
+ categoryManual: it.categoryManual === true,
10226
+ confirmed: it.confirmed === true,
10227
+ action: String(it.markAction ?? ''),
10228
+ ext: String(it.extension ?? ''),
10229
+ size: Number(it.size) || 0,
10230
+ mtime: Number(it.mtime) || 0,
10231
+ width: it.width ?? null,
10232
+ height: it.height ?? null,
10233
+ sessionId: String(it.sessionId ?? ''),
10234
+ sessionTitle: String(it.sessionTitle ?? ''),
10235
+ })
10236
+ }
10237
+ const wanted = Number(f.limit)
10238
+ const limit = Number.isFinite(wanted) && wanted > 0 ? Math.trunc(wanted) : 0
10239
+ const sliced = limit > 0 ? items.slice(0, limit) : items
10240
+ return { schema: 1, items: sliced, count: sliced.length, total: items.length }
10241
+ } catch (error) {
10242
+ return { schema: 1, items: [], count: 0, total: 0, error: String(error?.message ?? error) }
10243
+ }
10244
+ },
10245
+ /**
10246
+ * v0.16.4 · A 档:取待处理反馈(**纯读**)。
10247
+ *
10248
+ * 🔴 Agent 拉走 ≠ 人处理完。这里**不** ack、**不**清零 ——
10249
+ * 清零只发生在人点「生成草稿」或「清空反馈篮」时。
10250
+ * 否则 Agent 看一眼就把用户的意见吞了。
10251
+ *
10252
+ * @returns { schema, items, count, draft }
10253
+ * items[i] = { relPath, absolute, action, reason, changeOnly, keep, region, markedAt, category, sessionId, confirmed }
10254
+ * draft = 已渲染好的成稿文本(可直接用,省得自己拼)
10255
+ */
10256
+ async getPendingFeedback() {
10257
+ try {
10258
+ const payload = await callHost('getPendingFeedback', {})
10259
+ if (payload?.ok === false) {
10260
+ return { schema: 1, items: [], count: 0, draft: '', error: String(payload?.error?.message ?? 'failed') }
10261
+ }
10262
+ return {
10263
+ schema: Number(payload?.schema) || 1,
10264
+ items: Array.isArray(payload?.items) ? payload.items : [],
10265
+ count: Number.isFinite(payload?.count) ? payload.count : 0,
10266
+ draft: String(payload?.draft ?? ''),
10267
+ }
10268
+ } catch (error) {
10269
+ return { schema: 1, items: [], count: 0, draft: '', error: String(error?.message ?? error) }
10270
+ }
10271
+ },
9811
10272
  }
9812
10273
  window.dshGallerySeam = seam
9813
10274
  return seam
@@ -9877,8 +10338,6 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9877
10338
  // 拖完在输入框 Ctrl+V 能粘出「产出台·…」= 新代码确实执行过、dragstart 命中;
9878
10339
  // 粘不出 = 面板仍加载旧模块,需重载窗口。编码 / 写入失败时它就是唯一可用通道。
9879
10340
  void copyText(name)
9880
- // 从 Viewer「拖到对话」按钮拖出时,取预览大图而不是按钮内的节点;
9881
- // 列表卡片则仍用自己那张缩略图。两者都是同源 blob URL,canvas 不会被污染。
9882
10341
  const img = card.hasAttribute('data-gallery-dragviewer')
9883
10342
  ? document.querySelector('.dg-viewerBody img')
9884
10343
  : (target.matches('img') ? target : target.querySelector('img'))