@yolk_vat-y/dsh-project-memory 0.6.10 → 0.6.12
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 +72 -89
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/client/client.js +8 -3
- package/client/client.js.map +1 -1
- package/package.json +9 -9
- package/src/auto-inject.js +8 -2
- package/src/client/MemoryView.tsx +8 -4
- package/src/commands/insight-actions.js +27 -35
- package/src/enhancer.js +4 -2
- package/src/insight-store.js +32 -30
- package/src/lazy.js +13 -2
- package/src/llm.js +1 -8
- package/src/ops.js +74 -4
- package/src/setup/taskbridge.js +34 -10
- package/src/store.js +73 -24
- package/src/tools/context.js +14 -0
- package/src/tools/forget.js +10 -17
- package/src/tools/index-doc.js +4 -6
- package/src/tools/index-repo.js +4 -6
- package/src/tools/lesson-tools.js +31 -33
- package/src/tools/output.js +5 -0
- package/src/tools/query-memory.js +8 -9
- package/src/tools/remember.js +11 -18
- package/src/tools/stats.js +3 -5
- package/src/tools/task-tools.js +17 -23
- package/src/tools/watch-repo.js +8 -9
- package/src/util/fs.js +10 -2
- package/src/util/insight-fields.js +22 -0
- package/src/util/patch.js +28 -0
- package/src/util/search.js +11 -1
- package/src/util/task-view.js +3 -1
- package/src/util/text.js +2 -0
- package/src/util/value.js +16 -0
- package/src/watch.js +11 -3
package/src/tools/task-tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { TEXT_OUTPUT } from './output.js'
|
|
3
|
+
import { openProjectContext } from './context.js'
|
|
4
4
|
import { truncate } from '../util/text.js'
|
|
5
5
|
import { sessionIdOf, stepProgress, timeAgo } from '../util/task-view.js'
|
|
6
6
|
import { genTaskId, hash8, adoptStepsToSession, shouldAdoptToHost } from '../setup/taskbridge.js'
|
|
@@ -19,15 +19,13 @@ export function listTasksTool(config) {
|
|
|
19
19
|
return defineTool({
|
|
20
20
|
name: 'list_tasks',
|
|
21
21
|
description:
|
|
22
|
-
'
|
|
22
|
+
'List this project\'s task records (archived included). Look here first in a new or resumed session, then select_task to pick one.',
|
|
23
23
|
parameters: {
|
|
24
|
-
root: { type: 'string', description: '
|
|
24
|
+
root: { type: 'string', description: 'project root (default: cwd)' },
|
|
25
25
|
},
|
|
26
|
-
output:
|
|
26
|
+
output: TEXT_OUTPUT,
|
|
27
27
|
async execute(args, exec) {
|
|
28
|
-
const
|
|
29
|
-
assertIndexRoot(root, args.root || root)
|
|
30
|
-
const store = new ProjectMemoryStore(memoryRootFor(root, config.memoryDir)).load()
|
|
28
|
+
const { store } = openProjectContext(exec, args, config)
|
|
31
29
|
const tasks = store.getTasks()
|
|
32
30
|
if (!tasks.length) {
|
|
33
31
|
return '任务记录: 0 套(先做一步再建清单,或用 select_task 新建)'
|
|
@@ -44,18 +42,16 @@ export function selectTaskTool(config, host) {
|
|
|
44
42
|
return defineTool({
|
|
45
43
|
name: 'select_task',
|
|
46
44
|
description:
|
|
47
|
-
'
|
|
48
|
-
+ '
|
|
45
|
+
'Bind the session to a task (its todo list and files read afterwards sync into it). Exact taskId, or an exact title match'
|
|
46
|
+
+ '(creates one if absent); returns the task card used to rebuild the checklist.',
|
|
49
47
|
parameters: {
|
|
50
|
-
taskId: { type: 'string', description: '
|
|
51
|
-
title: { type: 'string', description: '
|
|
52
|
-
root: { type: 'string', description: '
|
|
48
|
+
taskId: { type: 'string', description: 'exact task id' },
|
|
49
|
+
title: { type: 'string', description: 'exact title; creates if absent' },
|
|
50
|
+
root: { type: 'string', description: 'project root (default: cwd)' },
|
|
53
51
|
},
|
|
54
|
-
output:
|
|
52
|
+
output: TEXT_OUTPUT,
|
|
55
53
|
async execute(args, exec) {
|
|
56
|
-
const root =
|
|
57
|
-
assertIndexRoot(root, args.root || root)
|
|
58
|
-
const store = new ProjectMemoryStore(memoryRootFor(root, config.memoryDir)).load()
|
|
54
|
+
const { root, store } = openProjectContext(exec, args, config)
|
|
59
55
|
const sid = sessionIdOf(exec)
|
|
60
56
|
const now = new Date().toISOString()
|
|
61
57
|
const error = (msg) => truncate(JSON.stringify({ success: false, error: msg }), config.maxOutputChars)
|
|
@@ -150,7 +146,7 @@ export function showTaskPanelTool(config) {
|
|
|
150
146
|
name: 'show_task_panel',
|
|
151
147
|
description: 'Open the task panel in the UI.',
|
|
152
148
|
parameters: {},
|
|
153
|
-
output:
|
|
149
|
+
output: TEXT_OUTPUT,
|
|
154
150
|
async execute() {
|
|
155
151
|
// 开面板的动作在**客户端**:这个工具名被 src/client/ShowTaskPanelNode.tsx 认领,
|
|
156
152
|
// 结果节点一渲染就由浏览器侧调 `taskUIStore.open()`。
|
|
@@ -170,13 +166,11 @@ export function archiveTaskTool(config, host) {
|
|
|
170
166
|
description: 'Archive a task (restore by selecting it again).',
|
|
171
167
|
parameters: {
|
|
172
168
|
taskId: { type: 'string', required: true, description: 'task id' },
|
|
173
|
-
root: { type: 'string', description: '
|
|
169
|
+
root: { type: 'string', description: 'project root (default: cwd)' },
|
|
174
170
|
},
|
|
175
|
-
output:
|
|
171
|
+
output: TEXT_OUTPUT,
|
|
176
172
|
async execute(args, exec) {
|
|
177
|
-
const root =
|
|
178
|
-
assertIndexRoot(root, args.root || root)
|
|
179
|
-
const store = new ProjectMemoryStore(memoryRootFor(root, config.memoryDir)).load()
|
|
173
|
+
const { root, store } = openProjectContext(exec, args, config)
|
|
180
174
|
const task = store.getTask(args.taskId)
|
|
181
175
|
if (!task) return truncate(JSON.stringify({ success: false, error: 'Task not found' }), config.maxOutputChars)
|
|
182
176
|
if (task.archived) return truncate(JSON.stringify({ success: false, error: 'Already archived' }), config.maxOutputChars)
|
package/src/tools/watch-repo.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
2
|
+
import { TEXT_OUTPUT } from './output.js'
|
|
2
3
|
import { existsSync } from 'node:fs'
|
|
3
4
|
import path from 'node:path'
|
|
4
5
|
import { assertIndexRoot, assertSafeRoot, memoryRootFor, resolveIndexRoot, rootRejection, sessionMemoryRootOrNull, storeKey } from '../util/fs.js'
|
|
5
6
|
import { ProjectMemoryStore } from '../store.js'
|
|
6
7
|
import { cfgValue } from '../util/config.js'
|
|
8
|
+
import { normalizeWatchIntervalMs } from '../watch.js'
|
|
7
9
|
|
|
8
10
|
export function watchRepoTool(watchManager, config) {
|
|
9
11
|
return defineTool({
|
|
@@ -14,17 +16,14 @@ export function watchRepoTool(watchManager, config) {
|
|
|
14
16
|
root: {
|
|
15
17
|
type: 'string',
|
|
16
18
|
required: true,
|
|
17
|
-
description: '
|
|
19
|
+
description: 'project root (relative: session cwd)',
|
|
18
20
|
},
|
|
19
21
|
watch: {
|
|
20
22
|
type: 'boolean',
|
|
21
|
-
description: 'false =
|
|
23
|
+
description: 'false = stop watching',
|
|
22
24
|
},
|
|
23
25
|
},
|
|
24
|
-
output:
|
|
25
|
-
schema: { type: 'string' },
|
|
26
|
-
render: (_args, value) => [{ type: 'text', text: value }],
|
|
27
|
-
},
|
|
26
|
+
output: TEXT_OUTPUT,
|
|
28
27
|
async execute(args, exec) {
|
|
29
28
|
const root = resolveIndexRoot(exec, args.root)
|
|
30
29
|
// 不存在的根不写进 watchlist:watch 每轮会 commit → save → mkdirSync,把它重新造出来。
|
|
@@ -72,9 +71,9 @@ export function watchRepoTool(watchManager, config) {
|
|
|
72
71
|
new ProjectMemoryStore(memoryDir).load().commit((s) => s.addWatch(root))
|
|
73
72
|
await mirrorSessionWatchlist(true)
|
|
74
73
|
watchManager.addRoot(root)
|
|
75
|
-
const
|
|
76
|
-
watchManager.start(
|
|
77
|
-
return `Watching ${root} (interval ${
|
|
74
|
+
const intervalMs = normalizeWatchIntervalMs(Number(cfgValue(config, 'watchInterval')) * 1000)
|
|
75
|
+
watchManager.start(intervalMs)
|
|
76
|
+
return `Watching ${root} (interval ${intervalMs / 1000}s). Docs/code changes will be re-indexed silently.`
|
|
78
77
|
},
|
|
79
78
|
})
|
|
80
79
|
}
|
package/src/util/fs.js
CHANGED
|
@@ -254,11 +254,15 @@ export function acquireDirLock(dir, { timeoutMs = 2000, staleMs = 10000, hardSta
|
|
|
254
254
|
}
|
|
255
255
|
if (lockIsStale(state, { staleMs, hardLimit, maxHoldMs })) {
|
|
256
256
|
// 只删"刚刚读到的那个内容":两次读之间锁可能已被别人抢到并重写。
|
|
257
|
+
// 回收失败(只读目录、Windows 杀毒/索引器长期占用)不能无条件 continue:那会变成
|
|
258
|
+
// 无 deadline、无等待的同步自旋,timeoutMs 被完全忽略,save()/commit()/退出 flush 卡死。
|
|
259
|
+
if (Date.now() >= deadline) return null
|
|
257
260
|
try {
|
|
258
261
|
if (readFileSync(file, 'utf8') === state.text) unlinkWithRetry(file)
|
|
259
262
|
} catch {
|
|
260
263
|
// 已被别处回收,或杀毒瞬时占用;下一轮继续判定
|
|
261
264
|
}
|
|
265
|
+
Atomics.wait(sleeper, 0, 0, 10)
|
|
262
266
|
continue
|
|
263
267
|
}
|
|
264
268
|
if (Date.now() >= deadline) return null
|
|
@@ -610,12 +614,16 @@ export function listProjectFiles(root, opts = {}) {
|
|
|
610
614
|
// 配置/状态/密钥(`.env`、`.ssh`),非 git 目录没有"被跟踪=作者同意"这层信号。
|
|
611
615
|
// 真要索引某个隐藏文件,走显式 `index_doc`(它不受扫描清单限制)。
|
|
612
616
|
if (segs.some((s) => s.startsWith('.'))) continue
|
|
613
|
-
|
|
617
|
+
// 与 walkDir 同口径:`DEFAULT_IGNORE` 只作用于**目录段**,根目录下一个叫 `build`
|
|
618
|
+
// 的普通文件仍然要收(此前对文件名也判,`git init` 前后语料会变)。
|
|
619
|
+
if (segs.slice(0, -1).some((s) => DEFAULT_IGNORE.has(s))) continue
|
|
614
620
|
const abs = path.join(root, rel)
|
|
615
621
|
// 与 walkDir 同一判据:exclude 是子树级前缀。必须在 maxDepth 之前——被排除文件不该把
|
|
616
622
|
// 扫描标成 truncated(否则本轮不清理"未见到的旧条目")。
|
|
617
623
|
if (policy && excludedEntryForAbs(abs, policy)) continue
|
|
618
|
-
|
|
624
|
+
// 文件的“目录深度”是 segs.length - 1;walkDir 的 maxDepth 也按目录层数计,
|
|
625
|
+
// 此前用 segs.length 会让 git 分支少收浅一层,并在同一棵树上报不同的 capped。
|
|
626
|
+
if (segs.length - 1 > maxDepth) {
|
|
619
627
|
capped = true
|
|
620
628
|
continue
|
|
621
629
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// insight kind ↔ 正文字段归属:save_lesson 就地更新与面板 /insight edit 共用。
|
|
2
|
+
// ALL_CONTENT 不含 trigger —— 任何 kind 都能带 authored trigger,切 kind 不能删掉注入面。
|
|
3
|
+
|
|
4
|
+
const KIND_CONTENT = {
|
|
5
|
+
lesson: ['pattern', 'fix'],
|
|
6
|
+
decision: ['choice', 'reason'],
|
|
7
|
+
procedure: ['steps', 'trigger'],
|
|
8
|
+
experience: ['problem', 'solution'],
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ALL_CONTENT = ['body', 'pattern', 'fix', 'problem', 'solution', 'choice', 'reason', 'steps']
|
|
12
|
+
|
|
13
|
+
/** 切 kind 后清掉不属于新 kind 的旧内容字段;procedure 保留通用 body。 */
|
|
14
|
+
export function pruneKindFields(item, oldKind) {
|
|
15
|
+
if (!item || item.kind === oldKind || !KIND_CONTENT[item.kind]) return
|
|
16
|
+
const keep = new Set(KIND_CONTENT[item.kind])
|
|
17
|
+
const keepBody = item.kind === 'procedure'
|
|
18
|
+
for (const f of ALL_CONTENT) {
|
|
19
|
+
if (keep.has(f) || (keepBody && f === 'body')) continue
|
|
20
|
+
delete item[f]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex `apply_patch` 正文里的目标路径。
|
|
3
|
+
*
|
|
4
|
+
* 这个工具没有 `file_path` / `path` 参数,路径只出现在补丁正文的文件头里:
|
|
5
|
+
* *** Add File: src/a.ts / *** Update File: src/b.ts / *** Delete File: src/c.ts
|
|
6
|
+
* *** Move to: src/d.ts(跟在 Update File 之后,是移动后的新路径)
|
|
7
|
+
* 正文里的增删行都带 `+` / `-` / 空格前缀,所以行首的 `*** …` 只可能是文件头。
|
|
8
|
+
*
|
|
9
|
+
* 只做机械提取:不校验补丁语法、不判断文件是否存在——调用方拿到的路径仍要走
|
|
10
|
+
* 自己的根归一化(项目外会被丢弃)。
|
|
11
|
+
*
|
|
12
|
+
* @param {string} input - `apply_patch` 的 `input` 参数(整段补丁文本)
|
|
13
|
+
* @returns {string[]} 按出现顺序去重后的路径(原样,未解析为绝对路径)
|
|
14
|
+
*/
|
|
15
|
+
export function patchFilePaths(input) {
|
|
16
|
+
if (typeof input !== 'string' || input === '') return []
|
|
17
|
+
const paths = []
|
|
18
|
+
const seen = new Set()
|
|
19
|
+
for (const line of input.split(/\r?\n/)) {
|
|
20
|
+
const matched = /^\*\*\* (?:Add|Update|Delete) File:\s*(.+)$/.exec(line) || /^\*\*\* Move to:\s*(.+)$/.exec(line)
|
|
21
|
+
if (!matched) continue
|
|
22
|
+
const raw = matched[1].trim().replace(/^(['"`])(.*)\1$/, '$2').trim()
|
|
23
|
+
if (!raw || seen.has(raw)) continue
|
|
24
|
+
seen.add(raw)
|
|
25
|
+
paths.push(raw)
|
|
26
|
+
}
|
|
27
|
+
return paths
|
|
28
|
+
}
|
package/src/util/search.js
CHANGED
|
@@ -215,12 +215,22 @@ export function rankEntriesMergedScored(entries, queries, limit = 8) {
|
|
|
215
215
|
// (没有 problem/solution 参数),独立打分器会把那种条目打成 0 分且无处可查。现由
|
|
216
216
|
// `recall.js` 用与洞察层相同的 `insightToEntry` 适配器打分,本函数随能力一起删除。
|
|
217
217
|
|
|
218
|
+
const LATIN_TERM_RE = /^[a-z0-9_]+$/
|
|
219
|
+
const WORD_CHAR_RE = /[a-z0-9_]/
|
|
220
|
+
|
|
218
221
|
function countOccurrences(text, token) {
|
|
219
222
|
if (!token) return 0
|
|
220
223
|
let count = 0
|
|
221
224
|
let pos = 0
|
|
225
|
+
// 拉丁词项必须按词边界计数:`searchText` 不是 token 化的,用裸 indexOf 会让 `cat` 命中
|
|
226
|
+
// "concatenate"、`log` 命中 "dialog",与按 token 统计的 IDF 不同源(假阳性 + 分数不可比)。
|
|
227
|
+
// CJK bigram / 西里尔词干没有 ASCII 词边界,保持子串计数。
|
|
228
|
+
const bounded = LATIN_TERM_RE.test(token)
|
|
222
229
|
while ((pos = text.indexOf(token, pos)) !== -1) {
|
|
223
|
-
|
|
230
|
+
if (!bounded
|
|
231
|
+
|| (!WORD_CHAR_RE.test(text[pos - 1] || '') && !WORD_CHAR_RE.test(text[pos + token.length] || ''))) {
|
|
232
|
+
count++
|
|
233
|
+
}
|
|
224
234
|
pos += token.length
|
|
225
235
|
}
|
|
226
236
|
return count
|
package/src/util/task-view.js
CHANGED
|
@@ -51,7 +51,9 @@ export function stepProgress(task) {
|
|
|
51
51
|
|
|
52
52
|
/** 相对时间(中文):面板、list_tasks、/tasks 三处文案共用同一套阈值。 */
|
|
53
53
|
export function timeAgo(iso) {
|
|
54
|
-
const
|
|
54
|
+
const t = Date.parse(iso ?? '')
|
|
55
|
+
if (!Number.isFinite(t)) return '未知'
|
|
56
|
+
const diff = Date.now() - t
|
|
55
57
|
const m = Math.floor(diff / 60000)
|
|
56
58
|
if (m < 1) return '刚刚'
|
|
57
59
|
if (m < 60) return `${m}分钟前`
|
package/src/util/text.js
CHANGED
|
@@ -14,6 +14,8 @@ export function textOf(message) {
|
|
|
14
14
|
|
|
15
15
|
export function truncate(text, maxChars) {
|
|
16
16
|
if (typeof text !== 'string') return String(text)
|
|
17
|
+
// 非有限值(缺配置 / 测试桩)原样返回,而不是输出 “...[truncated at undefined chars]”。
|
|
18
|
+
if (!Number.isFinite(maxChars)) return text
|
|
17
19
|
if (text.length <= maxChars) return text
|
|
18
20
|
return text.slice(0, maxChars) + `\n\n...[truncated at ${maxChars} chars]`
|
|
19
21
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// 值判定与 ISO 时间:磁盘 JSON 的形状校验、排序键比较在各层共用同一套语义。
|
|
2
|
+
// 时间戳只认非空字符串,缺失/非法/数字一律 0(`Date.parse('0')` 会得到 2000-01-01)。
|
|
3
|
+
|
|
4
|
+
export function isRecord(value) {
|
|
5
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function isoMs(value) {
|
|
9
|
+
if (typeof value !== 'string' || !value) return 0
|
|
10
|
+
const t = Date.parse(value)
|
|
11
|
+
return Number.isFinite(t) ? t : 0
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function newerIso(a, b) {
|
|
15
|
+
return isoMs(a) - isoMs(b)
|
|
16
|
+
}
|
package/src/watch.js
CHANGED
|
@@ -22,10 +22,19 @@ import { clearIndexFailure, recordIndexFailure } from './index-failures.js'
|
|
|
22
22
|
export function applyWatchSettings(watchManager, config) {
|
|
23
23
|
watchManager.stop()
|
|
24
24
|
if (cfgValue(config, 'watch') === false) return false
|
|
25
|
-
watchManager.start(Number(cfgValue(config, 'watchInterval')) * 1000)
|
|
25
|
+
watchManager.start(normalizeWatchIntervalMs(Number(cfgValue(config, 'watchInterval')) * 1000))
|
|
26
26
|
return true
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* 把配置里的毫秒值归一成**实际会用的**轮询间隔:非法值回落 30s,合法值下限 1s。
|
|
31
|
+
* 工具回报与 `start()` 必须读同一份,否则 `watchInterval: 0` 会回报 "0s"、实际 1s。
|
|
32
|
+
*/
|
|
33
|
+
export function normalizeWatchIntervalMs(intervalMs) {
|
|
34
|
+
const raw = Number(intervalMs)
|
|
35
|
+
return Number.isFinite(raw) ? Math.max(raw, 1000) : 30000
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
/**
|
|
30
39
|
* 有界并发 map。同步 `statSync` 循环在 Windows(尤其 WSL 挂 `/mnt/c`)会把事件循环卡住:
|
|
31
40
|
* 400 文件实测 ~0.9s、12k 文件按同一比例是几十秒,期间面板与工具调用全部停摆。
|
|
@@ -169,8 +178,7 @@ export class WatchManager {
|
|
|
169
178
|
|
|
170
179
|
start(intervalMs = 30000) {
|
|
171
180
|
// 非法值(NaN/undefined)会让定时器退化成 1ms 轮询打满事件循环,故回退默认 30s。
|
|
172
|
-
|
|
173
|
-
this._baseInterval = Number.isFinite(raw) ? Math.max(raw, 1000) : 30000
|
|
181
|
+
this._baseInterval = normalizeWatchIntervalMs(intervalMs)
|
|
174
182
|
// 空闲退避:连续没有变化的轮次把间隔翻倍,最长 2 分钟一轮;任何变化立刻回到 base。
|
|
175
183
|
// 轮询是 O(树) 的 walkDir + 逐文件 stat(本仓库一轮实测 58–87ms),常驻 15s 一轮都在磨 I/O。
|
|
176
184
|
this._maxInterval = Math.max(this._baseInterval, Math.min(this._baseInterval * 8, 120000))
|