@yolk_vat-y/dsh-project-memory 0.6.5 → 0.6.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/CHANGELOG.md +194 -0
- package/README.md +24 -21
- package/README.zh-CN.md +25 -23
- package/package.json +6 -4
- package/scripts/bench-edits.mjs +87 -0
- package/skills/project-memory/SKILL.md +72 -0
- package/skills/project-memory/scripts/pm-digest.mjs +138 -0
- package/src/audit.js +35 -62
- package/src/auto-inject.js +171 -220
- package/src/chunker.js +1 -1
- package/src/client/paging.js +22 -50
- package/src/client/slash.ts +12 -48
- package/src/doc-index.js +7 -5
- package/src/doc-pipeline.js +2 -0
- package/src/enhancer.js +45 -92
- package/src/index-pipeline.js +14 -10
- package/src/index.js +51 -73
- package/src/insight-store.js +132 -129
- package/src/ops.js +290 -54
- package/src/project-profile.js +20 -15
- package/src/readiness.js +153 -106
- package/src/recall.js +55 -134
- package/src/skill.js +86 -0
- package/src/store.js +311 -214
- package/src/tools/index-doc.js +5 -1
- package/src/tools/index-repo.js +2 -1
- package/src/tools/lesson-tools.js +2 -2
- package/src/util/flush.js +62 -0
- package/src/util/fs.js +346 -191
- package/src/util/path-token.js +8 -3
- package/src/util/persist.js +27 -0
- package/src/util/ru.js +202 -0
- package/src/util/search.js +33 -1
- package/src/vector-index.js +104 -104
- package/src/watch.js +74 -61
package/src/tools/index-doc.js
CHANGED
|
@@ -62,6 +62,8 @@ export function indexDocTool(ctx, config) {
|
|
|
62
62
|
// 与 index_repo/watch/lazy 同一条判据:哈希未变但旧条目缺 terms 时仍要重抽一次(一次性回填)。
|
|
63
63
|
// 少了这一步,terms 回填就是"路径相关"的——只有走 index_repo 才生效。
|
|
64
64
|
if (existing && existing.sha256 === hash && !docEntriesNeedBackfill(store.entries[rel])) {
|
|
65
|
+
// 旧记录没有 explicit 时在这里补上:否则重新 index_doc 一次也救不回被扫描清理掉的文件。
|
|
66
|
+
if (!existing.explicit) store.commit((s) => s.markFile(rel, { ...existing, explicit: true }))
|
|
65
67
|
return `Skipped (unchanged): ${rel}\nAlready indexed with ${(store.entries[rel] || []).length} entry/entries.`
|
|
66
68
|
}
|
|
67
69
|
|
|
@@ -80,7 +82,9 @@ export function indexDocTool(ctx, config) {
|
|
|
80
82
|
|
|
81
83
|
return store.commit((s) => {
|
|
82
84
|
s.setEntries(rel, entries)
|
|
83
|
-
|
|
85
|
+
// explicit:这个文件可能是被 .gitignore 排除的(显式索引不受 gitignore 限制),
|
|
86
|
+
// 扫描清单里永远不会有它 —— 清理时靠这个标记区分"没扫到"与"被删了"。
|
|
87
|
+
s.markFile(rel, { sha256: hash, size, type: 'doc', indexedAt: new Date().toISOString(), explicit: true })
|
|
84
88
|
const preview = entries
|
|
85
89
|
.map((e) => ` - ${e.title} @ ${rel}:${e.sourceLine}`)
|
|
86
90
|
.join('\n')
|
package/src/tools/index-repo.js
CHANGED
|
@@ -58,7 +58,7 @@ export async function indexRepository(ctx, config, root, { reindex = false, allo
|
|
|
58
58
|
continue
|
|
59
59
|
}
|
|
60
60
|
if (plan.key === OVERSIZE) {
|
|
61
|
-
//
|
|
61
|
+
// 体积超限的文件:旧记录一律清掉,避免检索命中一个已经不索引的文件。
|
|
62
62
|
batch.push({ rel, drop: true })
|
|
63
63
|
skipped++
|
|
64
64
|
if (batch.length >= COMMIT_BATCH) flushBatch()
|
|
@@ -84,6 +84,7 @@ export async function indexRepository(ctx, config, root, { reindex = false, allo
|
|
|
84
84
|
const { removed } = commitFileUpdates(store, {
|
|
85
85
|
updates: batch,
|
|
86
86
|
unseen: truncated ? null : seen,
|
|
87
|
+
root,
|
|
87
88
|
})
|
|
88
89
|
const stats = store.stats()
|
|
89
90
|
let report =
|
|
@@ -16,7 +16,7 @@ export function lessonTool(config) {
|
|
|
16
16
|
return defineTool({
|
|
17
17
|
name: 'save_lesson',
|
|
18
18
|
description:
|
|
19
|
-
'写入一条教训 / 决策 / 流程(单条 insight
|
|
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',
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 退出/卸载前的最后一道写盘兜底。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:保存失败后的后台重试**不能**当正确性保证——用户结束对话、关掉 dsh 时不会等
|
|
5
|
+
* 20s 的重试。正确性来自两点:① `save()` 在锁竞争时同步等待(见 store.js 的 LOCK_WAIT_MS);
|
|
6
|
+
* ② 万一仍失败,进程正常退出或插件卸载时再同步写一次。
|
|
7
|
+
*
|
|
8
|
+
* 注册的是脏 store(而不是所有 store):只有内存里还有未落盘变更的才需要 flush。
|
|
9
|
+
* `process.on('exit')` 只允许同步代码,`save()` 本身是同步的,所以这里直接调用。
|
|
10
|
+
* 信号导致的异常退出(SIGKILL / 未处理的 SIGINT)不保证走到这里——那是操作系统的边界。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @type {Set<{ flushPending?: (timeoutMs: number) => boolean }>} */
|
|
14
|
+
const pending = new Set()
|
|
15
|
+
let installed = false
|
|
16
|
+
|
|
17
|
+
function install() {
|
|
18
|
+
if (installed) return
|
|
19
|
+
installed = true
|
|
20
|
+
process.on('exit', () => {
|
|
21
|
+
flushDirtyStores({ timeoutMs: 1500 })
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 标记"这个 store 有未落盘的变更"。
|
|
27
|
+
* @param {{ flushPending?: (timeoutMs: number) => boolean }} store
|
|
28
|
+
*/
|
|
29
|
+
export function trackDirty(store) {
|
|
30
|
+
pending.add(store)
|
|
31
|
+
install()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 落盘成功后取消标记。
|
|
36
|
+
* @param {object} store
|
|
37
|
+
*/
|
|
38
|
+
export function untrackDirty(store) {
|
|
39
|
+
pending.delete(store)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 同步 flush 所有脏 store。退出钩子与插件 disposer 共用;测试可直接调用。
|
|
44
|
+
* @param {{ timeoutMs?: number }} [opts] 每个 store 最多等锁多久(退出路径要短,避免"关不掉")
|
|
45
|
+
* @returns {number} 成功落盘的 store 数
|
|
46
|
+
*/
|
|
47
|
+
export function flushDirtyStores({ timeoutMs = 1500 } = {}) {
|
|
48
|
+
let saved = 0
|
|
49
|
+
for (const store of [...pending]) {
|
|
50
|
+
try {
|
|
51
|
+
if (typeof store.flushPending === 'function' && store.flushPending(timeoutMs)) saved++
|
|
52
|
+
} catch {
|
|
53
|
+
// 退出路径上的失败只能放弃:不抛、不打印,避免把关闭流程变成错误弹窗
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return saved
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 仅供测试:当前还有多少个脏 store 挂着。 */
|
|
60
|
+
export function _pendingDirtyCountForTest() {
|
|
61
|
+
return pending.size
|
|
62
|
+
}
|