dsh-gallery 1.5.0 → 1.6.4

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/scan.js CHANGED
@@ -9,7 +9,7 @@ import path from 'node:path'
9
9
  import { ASSET_CATEGORY, classifyAsset } from './classify.js'
10
10
  import { BASH_TOOLS, DEFAULT_SESSIONS_DIR, DSH_HOME, OUTPUT_TOOLS, VIDEO_EXTS, VIEW_IMAGE_EXTS, VIEW_TOOLS } from './constants.js'
11
11
  import { isInside, measureImage, readHead } from './fsutil.js'
12
- import { buildGroups } from './groups.js'
12
+ import { buildGroups, buildRootSessionResolver } from './groups.js'
13
13
  import { collectAbsolutePaths, findSubSessionLogs, locateSessionDir, readSessionLogText } from './session.js'
14
14
  import { readHiddenList, resolveOptions } from './settings.js'
15
15
  import { readLabels, LABEL_CATEGORIES } from './labels.js'
@@ -25,6 +25,12 @@ export function parentDirOf(relPath) {
25
25
  return p.includes('/') ? p.slice(0, p.lastIndexOf('/')) : ''
26
26
  }
27
27
 
28
+ /**
29
+ * 分类的「确定性」排序。同一对话多次引用同一张图(父会话 + 子智能体会话)时,
30
+ * 取更确定的那个 —— 不能因为子会话只看了一眼就把定稿降级成素材。
31
+ */
32
+ const CATEGORY_RANK = { final: 3, intermediate: 2, input: 1, unknown: 0 }
33
+
28
34
  /** v0.14.7:当前对话分类。日志/登记里没有的、同目录外部图片自动标「素材」(input)。 */
29
35
  /**
30
36
  * 2026-11-15:同目录放宽的「新鲜度」门槛。
@@ -700,25 +706,117 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
700
706
  })
701
707
  }
702
708
 
703
- // 文件绝对路径 → { sessionId, title, category }
709
+ // 文件绝对路径 → [{ sessionId, title, createdAt, category }](**多值**)
710
+ //
711
+ // 2026-11-25:子智能体会话(parentSession 指向父会话)的产出并进**根父会话**。
712
+ // 「当前对话」视图本来就把子会话资产合并(见 resolveSessionScope 的「修法 C」),
713
+ // 但全局按对话分组时子会话是按 owner 单独成组的 —— 两套尺子不一致,实测就是
714
+ // 「全局里这个对话只有 5 张,点进对话却有 35 张」,看着像资产丢了。
715
+ //
716
+ // 同日再改:改成**多值**。原先「一个文件只归一个对话,谁最近引用算谁的」,
717
+ // 结果只要另一个对话贴过这张图,原对话的组里就少一张(老板实测:打开有 21 张、
718
+ // 全局只剩 5 张)。现在凡是在日志里引用过它的对话都记下来,分组时各入各的组,
719
+ // 两个视图才对得上账。实测全库 3527 个被引用的文件里 1523 个被多个对话引用。
720
+ const rootSessionOf = buildRootSessionResolver(sessionIndex)
704
721
  const ownerByAbs = new Map()
705
722
  if (sessionIndex !== null) {
706
723
  for (const [sid, entry] of sessionIndex) {
724
+ const rootId = rootSessionOf(sid)
725
+ const rootEntry = rootId === sid ? entry : sessionIndex.get(rootId)
726
+ const groupTitle = String(rootEntry?.title ?? entry.title ?? '')
727
+ const groupCreatedAt = Number(rootEntry?.createdAt) || Number(entry.createdAt) || 0
707
728
  for (const [abs, cat] of entry.files) {
708
- // 同一个文件被多个对话产出时,取最近的那个对话
709
- const prev = ownerByAbs.get(abs)
710
- if (prev === undefined || entry.createdAt > prev.createdAt) {
711
- ownerByAbs.set(abs, {
712
- sessionId: sid,
713
- title: entry.title || '',
714
- createdAt: entry.createdAt,
729
+ let list = ownerByAbs.get(abs)
730
+ if (list === undefined) {
731
+ list = []
732
+ ownerByAbs.set(abs, list)
733
+ }
734
+ const exist = list.find((x) => x.sessionId === rootId)
735
+ if (exist === undefined) {
736
+ list.push({
737
+ sessionId: rootId,
738
+ title: groupTitle,
739
+ createdAt: groupCreatedAt,
715
740
  category: cat,
741
+ // 原始产出会话:子会话时与 sessionId 不同,供诊断用
742
+ ...(rootId === sid ? {} : { ownerSessionId: sid }),
716
743
  })
744
+ } else if (CATEGORY_RANK[cat] > CATEGORY_RANK[exist.category]) {
745
+ // 同一对话多次引用(父 + 子会话)时取更确定的那一档:final > intermediate > input
746
+ exist.category = cat
717
747
  }
718
748
  }
719
749
  }
720
750
  }
721
751
 
752
+ // 2026-11-25:全局分组的「产出者」索引 —— 靠「用过的目录 + 时间窗口」判定谁产出的。
753
+ //
754
+ // 起因(老板两次报):全局里「DSH辅助漫剧制作流程」只剩 2 张,切进该对话却有 13 张。
755
+ // 那 11 张在 11-24 13:25 产出,却被 11-24 20:21 才开张的同名对话 (1)「引用」走了 ——
756
+ // 文件比它开张还早一个多小时。原规则「谁最近引用算谁的」把**看过**当成了**产出**。
757
+ //
758
+ // 三条约束,缺一不可:
759
+ // ① 目录必须是有子目录的层(根直属层在 session-index 里已排除,太宽);
760
+ // ② 文件必须晚于该会话开始(isFreshSince 同一把关),老图不会被新对话吸走;
761
+ // ③ 同目录被多个会话用过时取「开始得最晚」的那个。
762
+ // 优先级见下面 item 归属链:当前对话 > 截帧登记 > 本索引 > 日志精确引用。
763
+ const dirOwnerIndex = new Map()
764
+ if (sessionIndex !== null) {
765
+ for (const [sid, entry] of sessionIndex) {
766
+ const dirs = entry.dirs
767
+ if (!(dirs instanceof Set) || dirs.size === 0) continue
768
+ const rootId = rootSessionOf(sid)
769
+ const rootEntry = rootId === sid ? entry : sessionIndex.get(rootId)
770
+ const startMs = Number(entry.startMs) || Number(entry.createdAt) || 0
771
+ if (startMs <= 0) continue
772
+ const cand = {
773
+ sessionId: rootId,
774
+ title: String(rootEntry?.title ?? entry.title ?? ''),
775
+ createdAt: Number(rootEntry?.createdAt) || Number(entry.createdAt) || 0,
776
+ startMs,
777
+ }
778
+ for (const dir of dirs) {
779
+ const item = dir === '' ? { ...cand, rootLevel: true } : cand
780
+ const list = dirOwnerIndex.get(dir)
781
+ if (list === undefined) dirOwnerIndex.set(dir, [item])
782
+ else list.push(item)
783
+ }
784
+ }
785
+ }
786
+ /**
787
+ * 目录 + 时间判定:返回**所有**命中的候选会话(开始时间从新到旧)。
788
+ *
789
+ * 为什么返回数组而不是只挑一个:老板对账的标准是「打开这个对话看到几张,
790
+ * 全局这个组就该有几张」。实测 a912 与 94d7 两个对话的活跃期重叠,
791
+ * 同一批图两边都说得通 —— 单选必然让一边少几张,看着就像资产丢了。
792
+ * 允许「一张图同时属于用它产出过的每个对话」,两个视图就永远对得上账。
793
+ * 实测代价:全库 6944 条里仅 266 条(3.8%)会进多个组,可接受。
794
+ */
795
+ const matchDirOwners = (item) => {
796
+ if (dirOwnerIndex.size === 0) return []
797
+ const list = dirOwnerIndex.get(parentDirOf(item.relPath))
798
+ if (list === undefined) return []
799
+ // 🔴 只认 mtime(最后写出时间),**不看 birthtime**。
800
+ // 实测踩过:图卡 mtime 是产出时间,但 birthtime 因跨盘复制变成了更晚的时刻,
801
+ // 于是被判定「更晚开张的对话也算新鲜」,归属被抢走。
802
+ const mtime = Number(item.mtime) || 0
803
+ if (mtime <= 0) return []
804
+ const hits = []
805
+ const seen = new Set()
806
+ for (const cand of list) {
807
+ if (mtime < cand.startMs) continue
808
+ if (seen.has(cand.sessionId)) continue
809
+ seen.add(cand.sessionId)
810
+ hits.push(cand)
811
+ }
812
+ hits.sort((a, b) => {
813
+ // 根直属层的最低优先:有具体子目录的判定永远排在前面
814
+ if ((a.rootLevel === true) !== (b.rootLevel === true)) return a.rootLevel === true ? 1 : -1
815
+ return b.startMs - a.startMs
816
+ })
817
+ return hits
818
+ }
819
+
722
820
  // 2026-11-15:全局资产下置顶的「当前对话」组,必须和「当前对话」视图用同一把尺子。
723
821
  // 旧做法把归属交给全库会话索引、谁最近算谁的:本对话明明能看见的图,
724
822
  // 会被更早引用过它的老对话抢走(老板实测:全局 2 张、当前对话视图 4 张)。
@@ -799,6 +897,16 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
799
897
  }
800
898
  }
801
899
 
900
+ // 2026-11-25:当前对话本身若是子智能体会话,「当前对话组」也按根父会话算 ——
901
+ // 否则同一个子会话的文件会在两个组里分家(目录兜底进父组、精确命中的自成一组)。
902
+ const currentRootSid = sessionId === '' ? sessionId : rootSessionOf(sessionId)
903
+ const currentRootMeta = currentRootSid === sessionId
904
+ ? globalCurrentMeta
905
+ : {
906
+ title: String(sessionIndex?.get(currentRootSid)?.title ?? globalCurrentMeta?.title ?? ''),
907
+ createdAt: Number(sessionIndex?.get(currentRootSid)?.createdAt) || globalCurrentMeta?.createdAt || 0,
908
+ }
909
+
802
910
  // 已隐藏的路径:扫描时直接跳过(不移动文件,只从列表里拿掉)
803
911
  const hiddenSet = new Set(await readHiddenList(opts.settingsFile))
804
912
 
@@ -1021,16 +1129,71 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1021
1129
  // 登记不在会话日志里:ownerByAbs 查不到时,用登记里的会话信息补一个虚拟归属。
1022
1130
  // 日志里已有归属的文件(例如视频本身)一律沿用原归属,不受影响。
1023
1131
  const frameSid = String(frame?.sessionId ?? '')
1132
+ // 子会话截的帧同样并进根父会话(与 ownerByAbs 归一同一口径)
1133
+ const frameRootSid = frameSid === '' ? '' : rootSessionOf(frameSid)
1024
1134
  const virtualOwner = frame !== undefined && frameSid !== ''
1025
1135
  ? {
1026
- sessionId: frameSid,
1027
- title: String(frame.sessionTitle ?? '') || sessionIndex?.get(frameSid)?.title || '',
1028
- createdAt: Number(frame.sessionCreatedAt) || sessionIndex?.get(frameSid)?.createdAt || 0,
1136
+ sessionId: frameRootSid,
1137
+ title: String(frame.sessionTitle ?? '') || sessionIndex?.get(frameRootSid)?.title || '',
1138
+ createdAt: Number(frame.sessionCreatedAt) || sessionIndex?.get(frameRootSid)?.createdAt || 0,
1029
1139
  // 截帧 = 过程稿;粘贴 / 裁剪 = 素材(登记里带着 category,缺省回落过程稿)
1030
1140
  category: frameCategoryOf(frame),
1031
1141
  }
1032
1142
  : undefined
1033
- const owner = ownerByAbs.get(abs) ?? virtualOwner
1143
+ const indexedList = ownerByAbs.get(abs) ?? []
1144
+ // 主归属:日志里「最近引用」它的那个对话(沿用原排序,保证历史行为不变)
1145
+ const indexedOwner = indexedList.length === 0
1146
+ ? undefined
1147
+ : indexedList.reduce((a, b) => (b.createdAt > a.createdAt ? b : a))
1148
+ // 2026-11-25:**产出者判定优先于「谁最近引用算谁的」**。
1149
+ //
1150
+ // 实测反例(老板 11-25 报):a912「DSH辅助漫剧制作流程」(11-23 19:24)产出的
1151
+ // 11 张图卡,被 11-24 20:21 才开张的同名对话 94d7「引用」走了 —— 于是 a912 在
1152
+ // 全局只剩 2 张,而切进该对话能看见 13 张。两个视图用了两套尺子。
1153
+ //
1154
+ // 优先级:当前对话 > 截帧登记 > 目录 + 时间(产出者)> 日志精确引用。
1155
+ // 但**归属不止一个**:凡是认得这张图的对话,分组时各入各的组(见下面 refs)。
1156
+ const dirOwners = virtualOwner === undefined
1157
+ ? matchDirOwners({
1158
+ relPath: item.relPath,
1159
+ mtime: item.mtime,
1160
+ })
1161
+ : []
1162
+ const dirOwner = dirOwners.length > 0 ? dirOwners[0] : null
1163
+ /**
1164
+ * 这张图「属于」的对话清单(多值)。
1165
+ *
1166
+ * 老板的对账标准很朴素:**打开这个对话看到几张,全局这个组就该有几张**。
1167
+ * 原先一个文件只归一个对话,只要别的对话贴过同一张图,原对话的组就少一张
1168
+ * (实测「产线测试快速反馈」打开 21 张、全局只剩 5 张)。现在改成多归属。
1169
+ */
1170
+ const refs = []
1171
+ const refSids = new Set()
1172
+ const pushRef = (sessionId, title, createdAt, category) => {
1173
+ const sid = String(sessionId ?? '')
1174
+ if (sid === '' || refSids.has(sid)) return
1175
+ refSids.add(sid)
1176
+ refs.push({
1177
+ sessionId: sid,
1178
+ title: title ?? '',
1179
+ createdAt: Number(createdAt) || 0,
1180
+ category,
1181
+ })
1182
+ }
1183
+ // ① 日志里精确引用过它的对话 —— 最硬的证据,排最前
1184
+ for (const own of indexedList) pushRef(own.sessionId, own.title, own.createdAt, own.category)
1185
+ // ② 目录 + 时间窗:判定为产出者(分类用该对话自己的判定,没有则素材)。
1186
+ // 根直属层同样参与 —— 早年试过「有更具体归属就跳过根层」,结果 Chief 系列
1187
+ // 对话的组里各少 12 张素材(打开对话有、全局没有),对账失败。
1188
+ for (const cand of dirOwners) {
1189
+ const own = sessionIndex?.get(cand.sessionId)?.files?.get(abs)
1190
+ pushRef(cand.sessionId, cand.title, cand.createdAt,
1191
+ typeof own === 'string' ? own : ASSET_CATEGORY.INPUT)
1192
+ }
1193
+ // ③ 截帧 / 粘贴登记
1194
+ if (virtualOwner !== undefined) {
1195
+ pushRef(virtualOwner.sessionId, virtualOwner.title, virtualOwner.createdAt, virtualOwner.category)
1196
+ }
1034
1197
  item.absPath = abs
1035
1198
  if (isSession) {
1036
1199
  const autoCategory = scopeInfo.categoryByRel?.get(item.relPath.toLowerCase())
@@ -1051,9 +1214,9 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1051
1214
  const exact = globalCurrentExactRels.has(relKey)
1052
1215
  item.category = categoryForSessionAsset(globalCurrentCategory?.get(relKey), !exact)
1053
1216
  if (!exact) item.externalAsset = true
1054
- item.sessionId = sessionId
1055
- item.sessionTitle = globalCurrentMeta?.title ?? ''
1056
- item.sessionCreatedAt = globalCurrentMeta?.createdAt ?? 0
1217
+ item.sessionId = currentRootSid
1218
+ item.sessionTitle = currentRootMeta?.title ?? ''
1219
+ item.sessionCreatedAt = currentRootMeta?.createdAt ?? 0
1057
1220
  // 2026-11-24:全局「当前对话」组里的共享文件同样加共享标记
1058
1221
  if (globalCurrentSharedAbsSet !== null && globalCurrentSharedAbsSet.has(abs.toLowerCase())) {
1059
1222
  item.shared = true
@@ -1062,11 +1225,31 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1062
1225
  if (globalCurrentInheritedAbsSet !== null && globalCurrentInheritedAbsSet.has(abs.toLowerCase())) {
1063
1226
  item.inherited = true
1064
1227
  }
1065
- } else if (owner !== undefined) {
1066
- item.category = owner.category
1067
- item.sessionId = owner.sessionId
1068
- item.sessionTitle = owner.title
1069
- item.sessionCreatedAt = owner.createdAt
1228
+ } else if (virtualOwner !== undefined) {
1229
+ // 截帧 / 粘贴登记:本会话当场产出的硬证据,优先级最高
1230
+ item.category = virtualOwner.category
1231
+ item.sessionId = virtualOwner.sessionId
1232
+ item.sessionTitle = virtualOwner.title
1233
+ item.sessionCreatedAt = virtualOwner.createdAt
1234
+ } else if (dirOwner !== null) {
1235
+ // 2026-11-25:目录 + 时间窗口命中 —— 文件落在本会话用过的目录里,且晚于会话开始。
1236
+ // 分类:若该文件也被这个会话在日志里精确引用过,沿用日志分类(与「当前对话」
1237
+ // 视图同源判据),否则按外部素材标 input。
1238
+ const sameOwner = indexedList.find((x) => x.sessionId === dirOwner.sessionId)
1239
+ item.category = categoryForSessionAsset(sameOwner?.category, sameOwner === undefined)
1240
+ if (sameOwner === undefined) item.externalAsset = true
1241
+ item.sessionId = dirOwner.sessionId
1242
+ item.sessionTitle = dirOwner.title
1243
+ item.sessionCreatedAt = dirOwner.createdAt
1244
+ // 供诊断:这条是靠目录 + 时间判定的产出,不是日志精确记录
1245
+ item.dirOwner = true
1246
+ } else if (indexedOwner !== undefined) {
1247
+ item.category = indexedOwner.category
1248
+ item.sessionId = indexedOwner.sessionId
1249
+ item.sessionTitle = indexedOwner.title
1250
+ item.sessionCreatedAt = indexedOwner.createdAt
1251
+ // 子智能体产出:分组并进父会话,但保留原始产出会话,诊断时能分清是谁做的
1252
+ if (indexedOwner.ownerSessionId !== undefined) item.ownerSessionId = indexedOwner.ownerSessionId
1070
1253
  } else {
1071
1254
  // 不属于任何已知对话、也不在当前对话目录里的文件:归到「历史资产」,
1072
1255
  // 分类记为**未归类**。不能兜底成 input —— 那会把几千个历史文件全标成「输入」
@@ -1074,11 +1257,26 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1074
1257
  item.sessionId = null
1075
1258
  }
1076
1259
 
1260
+ // 2026-11-25:多归属表 —— 只有真的被多个对话认得才建(绝大多数条目只有一项)。
1261
+ // 主归属那条用「本分支判出来的分类」覆盖,保证置顶的当前对话组与视图完全一致。
1262
+ if (refs.length > 1) {
1263
+ const self = item.sessionId === null || item.sessionId === undefined
1264
+ ? undefined
1265
+ : refs.find((r) => r.sessionId === item.sessionId)
1266
+ if (self !== undefined) self.category = item.category
1267
+ item.sessionRefs = refs
1268
+ }
1269
+
1077
1270
  // 手动改过的标签覆盖机器预判,且刷新 / 重扫 / 重启都不会回退。
1078
1271
  const manual = manualLabels[item.relPath]
1079
1272
  if (manual !== undefined && LABEL_CATEGORIES.includes(manual?.category)) {
1080
1273
  item.category = manual.category
1081
1274
  item.categoryManual = true
1275
+ // 2026-11-25:多归属的副本同样要跟着手动标签走,否则同一张图
1276
+ // 在「打开这个对话」里是定稿、在全局同组里却是素材(实测量过 1 张差异)。
1277
+ if (Array.isArray(item.sessionRefs)) {
1278
+ for (const ref of item.sessionRefs) ref.category = manual.category
1279
+ }
1082
1280
  } else {
1083
1281
  item.categoryManual = false
1084
1282
  }
@@ -1142,6 +1340,9 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1142
1340
  // 2026-11-25:来源标记必须透传给全局分组,否则资产台卡片看不到角标
1143
1341
  ...(item.inherited ? { inherited: true } : {}),
1144
1342
  ...(item.shared ? { shared: true } : {}),
1343
+ // 2026-11-25:一张图可能同时属于用它产出过的多个对话 —— 这张副归属表
1344
+ // 必须带到分组里,否则只有主归属那组有它(全局就比对话里少几张)。
1345
+ ...(Array.isArray(item.sessionRefs) ? { sessionRefs: item.sessionRefs } : {}),
1145
1346
  })
1146
1347
  }
1147
1348
  }
@@ -1202,7 +1403,7 @@ export async function scanGallery(config, kind = 'image', scope = 'global', sess
1202
1403
  // 🔴 明细一次算全(全量留在服务端缓存),不再按 120 条截断:
1203
1404
  // 历史组有 5000+ 张,截断后旧图永远翻不到。
1204
1405
  // 响应由 host/http.js 瘦身成每组 60 张,前端点「再显示」再按需取下一批。
1205
- groups: isSession ? null : buildGroups(allItemsSummary, Number.MAX_SAFE_INTEGER, sessionId, sessionStates),
1406
+ groups: isSession ? null : buildGroups(allItemsSummary, Number.MAX_SAFE_INTEGER, currentRootSid, sessionStates),
1206
1407
  }
1207
1408
  }
1208
1409
 
@@ -188,6 +188,16 @@ export async function buildSessionIndex(sessionsDir, opts, deps) {
188
188
 
189
189
  // 只看落在扫描目录内的路径
190
190
  const files = new Map()
191
+ // 2026-11-25:本对话「用过的目录」(相对扫描根、小写),供全局分组做目录兜底。
192
+ //
193
+ // 起因:老板在全局资产里看到「DSH辅助漫剧制作流程」只剩 2 张,切进该对话却是 12 张。
194
+ // 那 10 张日志里没有精确路径,只有「当前对话」视图靠「目录 + 时间窗口」兜得住;
195
+ // 全局分组只认精确路径,它们就掉进「历史资产」了。这里把目录也记进索引。
196
+ //
197
+ // 只收有子目录的层 + 根直属层(空串)—— 后者单列,由 scan 侧当作**最低优先**的
198
+ // 兜底:一个会话只要在根层产过文件,就会认得根层之后的所有新图,很容易过度归属,
199
+ // 所以它只在「没有任何更具体的归属」时才生效(实测「新项目调研」缺的 5 张就在根层)。
200
+ const dirs = new Set()
191
201
  let maxMtime = meta.createdAt
192
202
  for (const [abs, info] of assets) {
193
203
  let ownerRoot = null
@@ -196,6 +206,9 @@ export async function buildSessionIndex(sessionsDir, opts, deps) {
196
206
  }
197
207
  if (ownerRoot === null) continue
198
208
  files.set(abs, info.category)
209
+ const relDir = path.relative(ownerRoot, path.dirname(path.resolve(abs)))
210
+ .split(path.sep).join('/')
211
+ if (!relDir.startsWith('..')) dirs.add(relDir.toLowerCase())
199
212
  try {
200
213
  const st = await fsp.stat(abs)
201
214
  if (st.mtimeMs > maxMtime) maxMtime = st.mtimeMs
@@ -204,18 +217,23 @@ export async function buildSessionIndex(sessionsDir, opts, deps) {
204
217
  }
205
218
  }
206
219
 
207
- if (files.size === 0) {
208
- sessionEntryCache.set(d.logPath, { key, entry: null })
209
- continue
210
- }
220
+ // 2026-11-25:files 为空也**不再丢弃**这条记录。
221
+ // 原因:子会话可能只把产出落在扫描根外(日志里没路径),父会话条目却是
222
+ // 子会话归并的依据 —— 丢掉它,buildRootSessionResolver 就找不到父链,
223
+ // 子会话会单独成组,父组永远少几张(实测「尺间空间IP品牌重塑」少 59 张)。
224
+ // 空条目对 ownerByAbs / dirOwnerIndex 都是空循环,不产生副作用。
211
225
 
212
226
  const entry = {
213
227
  sessionId: d.sessionId,
214
228
  title,
215
229
  createdAt: meta.createdAt,
230
+ // 目录兜底的时间门槛:文件必须「晚于本对话开始」才算它的产出,
231
+ // 与 resolveSessionScope 的 isFreshSince 同一把关,避免把老图抢进新对话。
232
+ startMs: meta.createdAt,
216
233
  cwd: meta.cwd,
217
234
  parentSession: meta.parentSession,
218
235
  files,
236
+ dirs,
219
237
  maxMtime,
220
238
  logMtime: d.logMtime,
221
239
  }
package/host/settings.js CHANGED
@@ -147,6 +147,10 @@ export function resolveOptions(config) {
147
147
  maxEntries: numberOr(merged.maxEntries, DEFAULTS.maxEntries, 1, 1000000),
148
148
  maxImageBytes: numberOr(merged.maxImageBytes, DEFAULTS.maxImageBytes, 1, 512 * 1024 * 1024),
149
149
  maxMediaBytes: numberOr(merged.maxMediaBytes, DEFAULTS.maxMediaBytes, 1, 1024 * 1024 * 1024),
150
+ // v1.5.0 / v1.6.0 的两个 TTL:一直没进返回体,导致设置里改了也不生效(永远走默认)。
151
+ // 0 是合法值(= 永不清理),所以下限必须是 0,不能套 numberOr 的「最小 1」习惯。
152
+ contextTtlHours: numberOr(merged.contextTtlHours, DEFAULTS.contextTtlHours, 0, 24 * 366),
153
+ trashTtlHours: numberOr(merged.trashTtlHours, DEFAULTS.trashTtlHours, 0, 24 * 366),
150
154
  }
151
155
  }
152
156