@yolk_vat-y/dsh-project-memory 0.6.1 → 0.6.3
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 +128 -3
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/client/client.js +340 -50
- package/client/client.js.map +1 -1
- package/package.json +11 -8
- package/src/auto-inject.js +25 -1
- package/src/client/MemoryView.tsx +157 -44
- package/src/client/TaskCommandNode.tsx +1 -0
- package/src/client/TaskPanel.module.css +23 -0
- package/src/client/TaskPanel.tsx +13 -7
- package/src/client/locales.ts +10 -0
- package/src/client/paging.js +165 -0
- package/src/client/task-data-store.ts +33 -14
- package/src/client/task-scope.js +32 -0
- package/src/commands/insight-actions.js +90 -12
- package/src/commands/invocation.js +4 -1
- package/src/commands/task-actions.js +3 -2
- package/src/commands/tasks.js +5 -2
- package/src/index.js +10 -0
- package/src/insight-store.js +441 -35
- package/src/lazy.js +5 -3
- package/src/ops.js +13 -2
- package/src/recall.js +13 -8
- package/src/setup/taskbridge.js +9 -4
- package/src/store.js +86 -121
- package/src/tools/forget.js +46 -6
- package/src/tools/lesson-tools.js +21 -8
- package/src/tools/query-memory.js +16 -5
- package/src/tools/remember.js +30 -14
- package/src/tools/stats.js +5 -1
- package/src/types.js +8 -1
- package/src/util/fs.js +3 -1
- package/src/util/session-dir.js +48 -0
- package/src/vector-index.js +3 -2
package/src/tools/remember.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
2
2
|
import { assertIndexRoot, memoryRootFor, resolveSafeIndexRoot } from '../util/fs.js'
|
|
3
3
|
import { ProjectMemoryStore } from '../store.js'
|
|
4
|
+
import { cfgInsight, saveInsight, GlobalStore, defaultGlobalFile } from '../insight-store.js'
|
|
5
|
+
import { ensureGlobalInit } from '../global-seed.js'
|
|
6
|
+
import { vectorItemsFrom } from '../vector-index.js'
|
|
7
|
+
import { createWriteCosine } from '../auto-inject.js'
|
|
4
8
|
|
|
5
9
|
export function rememberTool(config) {
|
|
6
10
|
return defineTool({
|
|
7
11
|
name: 'remember',
|
|
8
12
|
description:
|
|
9
13
|
'Save an experience note (problem -> solution) into project memory, e.g. a bug you just fixed. ' +
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'(the tiered insight store) — query_memory searches both.',
|
|
14
|
+
'It lands as a `kind:experience` entry in the same store as lessons / decisions / procedures, so query_memory ' +
|
|
15
|
+
'finds it and the same dedup applies (near-identical writes merge, similar ones report the nearest id). ' +
|
|
16
|
+
'Prefer save_lesson for anything that is not a problem->solution note.',
|
|
14
17
|
parameters: {
|
|
15
18
|
problem: {
|
|
16
19
|
type: 'string',
|
|
@@ -41,16 +44,29 @@ export function rememberTool(config) {
|
|
|
41
44
|
assertIndexRoot(root, args.root || root)
|
|
42
45
|
const memoryDir = memoryRootFor(root, config.memoryDir)
|
|
43
46
|
const store = new ProjectMemoryStore(memoryDir).load()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const cfg = cfgInsight(config)
|
|
48
|
+
ensureGlobalInit(config) // 幂等:project 写入可能被自动提升到 global
|
|
49
|
+
const globalStore = new GlobalStore(cfg.globalFile || defaultGlobalFile()).load()
|
|
50
|
+
// 与 save_lesson 同一条写入路径 ⇒ 同一套去重/自动覆盖/近邻提示;没装 leanvec 时 `cosine` 为 null,
|
|
51
|
+
// 退回纯词法(与旧版经验层行为一致)。
|
|
52
|
+
const cosine = await createWriteCosine(config, { storeDir: memoryDir, items: vectorItemsFrom(store, globalStore) })
|
|
53
|
+
const raw = {
|
|
54
|
+
title: args.problem,
|
|
55
|
+
kind: 'experience',
|
|
56
|
+
problem: args.problem,
|
|
57
|
+
solution: args.solution,
|
|
58
|
+
files: args.source_file ? [args.source_file] : undefined,
|
|
59
|
+
confidence: 1,
|
|
60
|
+
}
|
|
61
|
+
let result
|
|
62
|
+
store.commit((s) => {
|
|
63
|
+
result = saveInsight({ store: s, globalStore, raw, scope: 'project', cfg, source: 'agent', cosine })
|
|
64
|
+
return result
|
|
53
65
|
})
|
|
66
|
+
globalStore.commit()
|
|
67
|
+
if (!result || !result.ok) return `Failed: ${result?.error || '写入未完成'}`
|
|
68
|
+
const verb = result.action === 'created' ? 'Saved' : 'Updated existing'
|
|
69
|
+
return `${verb} experience note (${result.id}).${result.hint ? ` ${result.hint}` : ''}`
|
|
54
70
|
},
|
|
55
71
|
})
|
|
56
|
-
}
|
|
72
|
+
}
|
package/src/tools/stats.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
2
|
-
import { memoryRootFor, resolveSafeIndexRoot } from '../util/fs.js'
|
|
2
|
+
import { assertIndexRoot, memoryRootFor, resolveSafeIndexRoot } from '../util/fs.js'
|
|
3
3
|
import { ProjectMemoryStore, storeOverview } from '../store.js'
|
|
4
4
|
import { truncate } from '../util/text.js'
|
|
5
5
|
|
|
@@ -23,6 +23,10 @@ export function statsTool(config) {
|
|
|
23
23
|
},
|
|
24
24
|
async execute(args, exec) {
|
|
25
25
|
const root = resolveSafeIndexRoot(exec, args.root, config)
|
|
26
|
+
// 读路径也要验根存在:可选的向量层(leanvec)在索引空 store 时会落盘 vectors 缓存,
|
|
27
|
+
// 于是"传错一个 root"就能在任意可写位置造出 `<root>/.dsh-project-memory` —— 而回报
|
|
28
|
+
// 只是"空 store",看起来像"这个项目没有记忆"。与 index_repo/watch_repo 同一道护栏。
|
|
29
|
+
assertIndexRoot(root, args.root || root)
|
|
26
30
|
const store = new ProjectMemoryStore(memoryRootFor(root, config.memoryDir)).load()
|
|
27
31
|
const overview = storeOverview(store)
|
|
28
32
|
const files = Object.entries(store.files).sort((a, b) => String(b[1].indexedAt || '').localeCompare(String(a[1].indexedAt || '')))
|
package/src/types.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {'lesson' | 'decision' | 'procedure' | 'experience'} InsightKind
|
|
6
6
|
* lesson: 曾踩坑/纠偏(pattern→fix);decision: 曾权衡的选型(topic→choice+reason);
|
|
7
|
-
* procedure: 多步操作指南(steps);experience:
|
|
7
|
+
* procedure: 多步操作指南(steps);experience: 问题→解法笔记(`remember` 写的就是它,
|
|
8
|
+
* v0.4 experience.json 在加载时导入成同一实体,不再有第二个存储)。
|
|
8
9
|
*
|
|
9
10
|
* @typedef {'task' | 'project' | 'global'} InsightScope
|
|
10
11
|
* task: tasks.json 内嵌于任务实体 task.insights[](私有草稿);
|
|
@@ -35,6 +36,8 @@
|
|
|
35
36
|
* @property {number} [confidence] 0..1
|
|
36
37
|
* @property {number} [hitCount] 被注入/命中的次数(强化信号,无 LLM)
|
|
37
38
|
* @property {string} [lastHitAt] 最近一次命中时间 ISO(衰减/归档依据)
|
|
39
|
+
* @property {object} [prev] 被自动覆盖/就地更新挤掉的**上一个**值(按字段名),只留一版:
|
|
40
|
+
* 误覆盖后用同一个 id 再写一次即可写回;不是历史(不做折叠、不压实)
|
|
38
41
|
* @property {boolean} [archived] 归档 = 软删:不进召回/注入,可恢复
|
|
39
42
|
* @property {string[]} [tags]
|
|
40
43
|
* @property {string} createdAt
|
|
@@ -45,6 +48,10 @@
|
|
|
45
48
|
* @typedef {object} InsightConfig
|
|
46
49
|
* @property {number} [dedupOverlap] 双向 token overlap 阈值(≥ 合并/取代)
|
|
47
50
|
* @property {number} [reinforceBand] 近重复强化带下界(0.65~dedupOverlap → 强化)
|
|
51
|
+
* @property {number} [autoMergeCos] 向量余弦自动覆盖带(默认 0.9,需 leanvec;无向量则不用)
|
|
52
|
+
* @property {number} [autoMergeMargin] 自动覆盖还要求第一名领先第二名这么多(默认 0.05)
|
|
53
|
+
* @property {number} [hintCos] 向量近邻提示带(默认 0.7,只在返回文本里提示 id,不改数据)
|
|
54
|
+
* @property {number} [maxForgetMatches] forget 关键词删除的命中上限(默认 10);超了一条都不删,只回报候选
|
|
48
55
|
* @property {number} [maxProject] project insights 容量(归档区另计)
|
|
49
56
|
* @property {number} [maxGlobalProcedures] global insights 容量
|
|
50
57
|
* @property {number} [promoteConfidence] 提升 project 所需最低 confidence
|
package/src/util/fs.js
CHANGED
|
@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
6
6
|
import { createHash } from 'node:crypto'
|
|
7
7
|
import os from 'node:os'
|
|
8
8
|
import path from 'node:path'
|
|
9
|
+
import { sessionWorkingDir } from './session-dir.js'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 原子写 JSON:先写同目录的 `<file>.<pid>.tmp`,再 rename 覆盖目标。
|
|
@@ -542,7 +543,8 @@ export function assertSafeRoot(root, { requested = root, allowUnsafe = false } =
|
|
|
542
543
|
|
|
543
544
|
export function resolveIndexRoot(exec, explicitRoot) {
|
|
544
545
|
if (explicitRoot && explicitRoot.trim()) return path.resolve(explicitRoot)
|
|
545
|
-
|
|
546
|
+
// 会话当前工作目录:0.2.1+ 读 workingDirectory 投影(cd 后会变),老宿主回退 header.cwd。
|
|
547
|
+
const sessionCwd = sessionWorkingDir(exec?.agent?.session, { agent: exec?.agent })
|
|
546
548
|
if (sessionCwd) return path.resolve(sessionCwd)
|
|
547
549
|
return path.resolve(process.cwd())
|
|
548
550
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话「当前工作目录」的唯一取值口。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:dsh 0.2.1 引入了 `@deepseek-ai/dsh-working-directory`,把**当前执行目录**
|
|
5
|
+
* 从 `Session.header.cwd` 里拆了出去——`header.cwd` 现在只表示「原始项目身份 / 权限根」,
|
|
6
|
+
* `working_directory({cd})` 改的是会话投影 `workingDirectory`,**不写回 header**。
|
|
7
|
+
* 本插件的全部根解析(索引 / 检索 / 懒索引 / 审计注入 / 任务桥 / watch)用的都是「人明确
|
|
8
|
+
* 选择的工作位置」这层语义(见 util/fs.js 的根推导注释),所以必须跟着这条新权威走,
|
|
9
|
+
* 否则用户 cd 到另一个项目后,记忆仍落在原项目的 store 上(不报错,只是静默错根)。
|
|
10
|
+
*
|
|
11
|
+
* 兼容策略:新服务用 `ctx.get()` **软探测**——它既不在插件的顶层 inject 里(那是装配期
|
|
12
|
+
* 门控,缺一项插件就整个不挂载),在老宿主(< 0.2.1)上也根本不存在;两者都回退到
|
|
13
|
+
* `header.cwd`,也就是该服务出现之前"当前工作目录"的存放位置。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 读该会话的当前工作目录。
|
|
18
|
+
*
|
|
19
|
+
* 取值顺序(前者只在真的可用时才生效):
|
|
20
|
+
* 1. `workingDirectory.get(session)` —— 0.2.1+ 的权威。该投影的 `init` 就是
|
|
21
|
+
* `header => header.cwd ?? null`,所以**没 cd 过时它与 header.cwd 恒等**,
|
|
22
|
+
* 本函数对既有行为是 no-op;cd 过才返回改写后的目录。
|
|
23
|
+
* 2. `session.header.cwd` —— 服务缺失(老宿主)或会话不是宿主 Session 时的回退。
|
|
24
|
+
* 3. `agent.session.header.cwd` —— 会话对象与服务都拿不到时的最后回退。
|
|
25
|
+
*
|
|
26
|
+
* 全程不抛出:根解析在审计 / 注入等旁路里被调用,那里读不到目录只应降级,不应带崩调用方。
|
|
27
|
+
* @param {object|null} [session] - 宿主 Session(`workingDirectory.get` 需要它)。
|
|
28
|
+
* @param {{agent?: object, ctx?: object}} [opts] - `agent` 提供 `agent.ctx` 回退;`ctx` 直接指定宿主上下文(任务桥这类只有 ctx 的地方)。
|
|
29
|
+
* @returns {string|undefined} 绝对目录;都取不到时 undefined。
|
|
30
|
+
*/
|
|
31
|
+
export function sessionWorkingDir(session, opts = {}) {
|
|
32
|
+
const agent = opts.agent
|
|
33
|
+
const target = session || agent?.session || null
|
|
34
|
+
const host = opts.ctx || agent?.ctx || null
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const svc = host && typeof host.get === 'function' ? host.get('workingDirectory') : null
|
|
38
|
+
if (svc && typeof svc.get === 'function' && target) {
|
|
39
|
+
const dir = svc.get(target)
|
|
40
|
+
if (typeof dir === 'string' && dir) return dir
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
// 老宿主没有该服务;或 session 不是宿主认识的 Session——两种情况都走 header 回退。
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const cwd = target?.header?.cwd ?? agent?.session?.header?.cwd
|
|
47
|
+
return typeof cwd === 'string' && cwd ? cwd : undefined
|
|
48
|
+
}
|
package/src/vector-index.js
CHANGED
|
@@ -172,14 +172,15 @@ export function openVectorIndex({ dir = null, items = [], embed, model, dim = DI
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
* 从两个 store 收集**要建索引的条目**:洞察层(项目 +
|
|
175
|
+
* 从两个 store 收集**要建索引的条目**:洞察层(项目 + 全局)。
|
|
176
176
|
* 与提示通道/召回看到的池子同源;归档条目不进(它们不会被召回)。
|
|
177
|
+
* v0.4 的经验笔记也在里面——统一存储后它们是 `kind:'experience'` 的 insight,
|
|
178
|
+
* 加载时已从 experience.json 导入,不再有第二个池子。
|
|
177
179
|
*/
|
|
178
180
|
export function vectorItemsFrom(store, globalStore) {
|
|
179
181
|
const out = []
|
|
180
182
|
try { if (typeof store?.insightItems === 'function') out.push(...store.insightItems()) } catch { /* store 形状不保证 */ }
|
|
181
183
|
try { if (typeof globalStore?.items === 'function') out.push(...globalStore.items()) } catch { /* 同上 */ }
|
|
182
|
-
try { if (Array.isArray(store?.experience)) out.push(...store.experience) } catch { /* 同上 */ }
|
|
183
184
|
return out.filter((it) => it && !it.archived)
|
|
184
185
|
}
|
|
185
186
|
|