@yolk_vat-y/dsh-project-memory 0.6.6 → 0.6.8

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.
@@ -1,5 +1,6 @@
1
1
  import { defineTool } from '@deepseek-ai/dsh-tools'
2
2
  import path from 'node:path'
3
+ import { statSync } from 'node:fs'
3
4
  import { assertIndexRoot, assertReadableFile, assertSafeRoot, excludedEntryForPath, findProjectRoot, memoryRootFor, sessionMemoryRootOrNull, sha256OfFile, storeKey } from '../util/fs.js'
4
5
  import { buildDocEntries } from '../doc-pipeline.js'
5
6
  import { docEntriesNeedBackfill } from '../doc-index.js'
@@ -57,11 +58,20 @@ export function indexDocTool(ctx, config) {
57
58
  const store = new ProjectMemoryStore(memoryDir).load()
58
59
 
59
60
  const rel = storeKey(path.relative(root, filePath).split(path.sep).join('/'))
61
+ // mtime 必须在读正文之前取:记录里的 mtime 不能比内容新,否则懒索引的快路径会跳过之后的真实改动。
62
+ let mtimeMs
63
+ try {
64
+ mtimeMs = statSync(filePath).mtimeMs
65
+ } catch {
66
+ mtimeMs = undefined
67
+ }
60
68
  const { hash, size } = await sha256OfFile(filePath)
61
69
  const existing = store.fileRecord(rel)
62
70
  // 与 index_repo/watch/lazy 同一条判据:哈希未变但旧条目缺 terms 时仍要重抽一次(一次性回填)。
63
71
  // 少了这一步,terms 回填就是"路径相关"的——只有走 index_repo 才生效。
64
72
  if (existing && existing.sha256 === hash && !docEntriesNeedBackfill(store.entries[rel])) {
73
+ // 旧记录没有 explicit 时在这里补上:否则重新 index_doc 一次也救不回被扫描清理掉的文件。
74
+ if (!existing.explicit) store.commit((s) => s.markFile(rel, { ...existing, explicit: true }))
65
75
  return `Skipped (unchanged): ${rel}\nAlready indexed with ${(store.entries[rel] || []).length} entry/entries.`
66
76
  }
67
77
 
@@ -80,7 +90,11 @@ export function indexDocTool(ctx, config) {
80
90
 
81
91
  return store.commit((s) => {
82
92
  s.setEntries(rel, entries)
83
- s.markFile(rel, { sha256: hash, size, type: 'doc', indexedAt: new Date().toISOString() })
93
+ // explicit:这个文件可能是被 .gitignore 排除的(显式索引不受 gitignore 限制),
94
+ // 扫描清单里永远不会有它 —— 清理时靠这个标记区分"没扫到"与"被删了"。
95
+ const record = { sha256: hash, size, type: 'doc', indexedAt: new Date().toISOString(), explicit: true }
96
+ if (typeof mtimeMs === 'number' && Number.isFinite(mtimeMs)) record.mtimeMs = mtimeMs
97
+ s.markFile(rel, record)
84
98
  const preview = entries
85
99
  .map((e) => ` - ${e.title} @ ${rel}:${e.sourceLine}`)
86
100
  .join('\n')
@@ -50,15 +50,18 @@ export async function indexRepository(ctx, config, root, { reindex = false, allo
50
50
  if (!kind) continue
51
51
 
52
52
  try {
53
- const size = statSync(filePath).size
53
+ const st = statSync(filePath)
54
+ const size = st.size
54
55
  const record = store.fileRecord(rel)
55
- const plan = await planFileIndex({ rel, filePath, kind, config, record, existingEntries: store.entries[rel], size, force: reindex })
56
+ const plan = await planFileIndex({ rel, filePath, kind, config, record, existingEntries: store.entries[rel], size, mtimeMs: st.mtimeMs, force: reindex })
56
57
  if (plan.key === UNCHANGED) {
58
+ // 内容没变、mtime 变了(touch / checkout 还原):把新 mtime 记回去,下一次扫描才命得快路径。
59
+ if (typeof plan.mtimeMs === 'number') store.refreshMtime(rel, plan.mtimeMs)
57
60
  skipped++
58
61
  continue
59
62
  }
60
63
  if (plan.key === OVERSIZE) {
61
- // 体积超限的代码文件:旧记录一律清掉,避免检索命中一个已经不索引的文件。
64
+ // 体积超限的文件:旧记录一律清掉,避免检索命中一个已经不索引的文件。
62
65
  batch.push({ rel, drop: true })
63
66
  skipped++
64
67
  if (batch.length >= COMMIT_BATCH) flushBatch()
@@ -84,6 +87,7 @@ export async function indexRepository(ctx, config, root, { reindex = false, allo
84
87
  const { removed } = commitFileUpdates(store, {
85
88
  updates: batch,
86
89
  unseen: truncated ? null : seen,
90
+ root,
87
91
  })
88
92
  const stats = store.stats()
89
93
  let report =
@@ -16,7 +16,7 @@ export function lessonTool(config) {
16
16
  return defineTool({
17
17
  name: 'save_lesson',
18
18
  description:
19
- '写入一条教训 / 决策 / 流程(单条 insight)。写入前与既有记忆比对:高相似度自动覆盖(旧值留在 prev),'
19
+ '写入一条教训 / 决策 / 流程(单条 insight)。只写下次仍成立的判据与命令;某次运行的值(版本号、计数、分支名)不进正文。写入前与既有记忆比对:高相似度自动覆盖(旧值留在 prev),'
20
20
  + '较近的提示近邻 id。发现记错/过时:带 id 再写一次即就地覆盖;确定要删用 forget。',
21
21
  parameters: {
22
22
  id: { type: 'string', description: '既有条目 id(就地更新,忽略 scope)' },
@@ -40,7 +40,7 @@ export function lessonTool(config) {
40
40
  writes: { type: 'array', items: { type: 'string' }, description: '项目相对路径,禁 glob' },
41
41
  intents: { type: 'array', items: { type: 'string' }, description: '意图词(CJK≥2,拉丁≥5)' },
42
42
  },
43
- description: '唯一触发面:三者取或。',
43
+ description: '唯一触发面:三者取或;不写则只能靠检索命中,不会主动注入。',
44
44
  },
45
45
  guard: {
46
46
  type: 'object',