dsh-workbuddy-shared-memory 0.1.0 → 0.1.1
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/package.json +1 -1
- package//345/205/245/345/217/243.js +35 -20
- package//345/267/245/345/205/267.js +28 -2
- package//347/255/226/347/225/245.js +19 -12
- package//350/256/260/345/277/206/346/226/207/344/273/266.js +1 -1
- package//350/257/273/346/210/221.md +58 -43
- package//350/267/257/345/276/204.js +12 -6
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WorkBuddy 共享记忆 —— Host 插件入口。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 注入位置与触发时机对齐 WorkBuddy:策略和两层记忆都进入 system prompt,
|
|
5
|
+
* 每次系统提示词装配时重新读取文件。WorkBuddy 把项目级记忆放在
|
|
6
|
+
* <会话工作区>/.workbuddy/memory(分组目录即工作区目录);DSH 工作区
|
|
7
|
+
* 会话也按同一个目录读写,不再向上寻找 .git。
|
|
8
8
|
*/
|
|
9
9
|
import z from '@deepseek-ai/schemastery'
|
|
10
|
-
import {
|
|
10
|
+
import { 项目根目录, 项目记忆目录由根, 用户记忆目录 } from './路径.js'
|
|
11
11
|
import { 用户记忆注入块, 项目记忆注入块 } from './记忆文件.js'
|
|
12
12
|
import { 策略文本 } from './策略.js'
|
|
13
13
|
import { 创建工具 } from './工具.js'
|
|
@@ -26,7 +26,7 @@ export const Config = z.object({
|
|
|
26
26
|
distillAfterDays: z.number().step(1).min(1).default(30),
|
|
27
27
|
injectPolicy: z.boolean().default(true),
|
|
28
28
|
injectContent: z.boolean().default(true),
|
|
29
|
-
projectRootMarkers: z.array(z.string()).default([
|
|
29
|
+
projectRootMarkers: z.array(z.string()).default([]),
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
const 默认配置 = {
|
|
@@ -40,11 +40,25 @@ const 默认配置 = {
|
|
|
40
40
|
distillAfterDays: 30,
|
|
41
41
|
injectPolicy: true,
|
|
42
42
|
injectContent: true,
|
|
43
|
-
projectRootMarkers: [
|
|
43
|
+
projectRootMarkers: [],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 解析当前会话的项目根;无活动 agent(如标题生成)时不注入项目级内容。 */
|
|
47
|
+
function 当前项目根(ctx, 配置, 上下文) {
|
|
48
|
+
const agent = 上下文?.agent
|
|
49
|
+
const session = agent?.session
|
|
50
|
+
if (session === undefined) return undefined
|
|
51
|
+
try {
|
|
52
|
+
const 固定目录 = session.header?.cwd?.trim()
|
|
53
|
+
const 工作目录 = 固定目录 || ctx.workingDirectory.get(session)
|
|
54
|
+
return 项目根目录(工作目录, 配置.projectRootMarkers)
|
|
55
|
+
} catch {
|
|
56
|
+
return undefined
|
|
57
|
+
}
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
/** 组装本轮要注入的记忆快照;任何一层失败都只告警,不影响对话。 */
|
|
47
|
-
function 注入记忆内容(
|
|
61
|
+
function 注入记忆内容(配置, 项目根, 告警) {
|
|
48
62
|
const 块 = []
|
|
49
63
|
try {
|
|
50
64
|
const 文本 = 用户记忆注入块(用户记忆目录(配置), 配置.userMemoryLimit, 告警)
|
|
@@ -52,15 +66,13 @@ function 注入记忆内容(ctx, 配置, 上下文, 告警) {
|
|
|
52
66
|
} catch (错误) {
|
|
53
67
|
告警(`用户级记忆注入失败:${错误?.message ?? 错误}`)
|
|
54
68
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const cwd = ctx.workingDirectory.get(agent.session)
|
|
59
|
-
const 文本 = 项目记忆注入块(项目记忆目录(cwd, 配置), 配置.projectMemoryLimit, 告警)
|
|
69
|
+
if (项目根 !== undefined) {
|
|
70
|
+
try {
|
|
71
|
+
const 文本 = 项目记忆注入块(项目记忆目录由根(项目根, 配置), 配置.projectMemoryLimit, 告警)
|
|
60
72
|
if (文本) 块.push(文本)
|
|
73
|
+
} catch (错误) {
|
|
74
|
+
告警(`项目记忆注入失败:${错误?.message ?? 错误}`)
|
|
61
75
|
}
|
|
62
|
-
} catch (错误) {
|
|
63
|
-
告警(`项目记忆注入失败:${错误?.message ?? 错误}`)
|
|
64
76
|
}
|
|
65
77
|
return 块.join('\n\n')
|
|
66
78
|
}
|
|
@@ -75,17 +87,20 @@ export function apply(ctx, 用户配置 = {}) {
|
|
|
75
87
|
name: 'workbuddy-memory:policy',
|
|
76
88
|
order: 8600,
|
|
77
89
|
interpolate: false,
|
|
78
|
-
text: () => 策略文本(
|
|
90
|
+
text: (上下文) => 策略文本(配置, 当前项目根(ctx, 配置, 上下文)),
|
|
79
91
|
})
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
if (配置.injectContent) {
|
|
83
|
-
ctx.systemPrompt.
|
|
95
|
+
ctx.systemPrompt.section({
|
|
84
96
|
name: 'workbuddy-memory:content',
|
|
85
|
-
order:
|
|
86
|
-
required: true,
|
|
97
|
+
order: 8601,
|
|
87
98
|
interpolate: false,
|
|
88
|
-
text: (上下文) =>
|
|
99
|
+
text: (上下文) => {
|
|
100
|
+
const 项目根 = 当前项目根(ctx, 配置, 上下文)
|
|
101
|
+
if (项目根 === undefined) return ''
|
|
102
|
+
return 注入记忆内容(配置, 项目根, 告警)
|
|
103
|
+
},
|
|
89
104
|
})
|
|
90
105
|
}
|
|
91
106
|
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* 工具名遵循 DSH 命名契约使用英文;读写路径与 WorkBuddy 桌面应用保持一致(互操作所需)。
|
|
4
4
|
*/
|
|
5
5
|
import { join } from 'node:path'
|
|
6
|
+
import { existsSync } from 'node:fs'
|
|
6
7
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
7
8
|
import {
|
|
8
|
-
项目记忆目录, 用户记忆目录, 项目根目录, 数据目录名,
|
|
9
|
+
项目记忆目录, 用户记忆目录, 项目根目录, 数据目录名, 配置根目录,
|
|
9
10
|
今天日期, 是合法日期, 用户记忆文件名, 项目记忆文件名,
|
|
10
11
|
} from './路径.js'
|
|
11
12
|
import {
|
|
@@ -41,6 +42,9 @@ export function 创建工具(环境) {
|
|
|
41
42
|
|
|
42
43
|
async function 会话目录(exec) {
|
|
43
44
|
if (exec.agent === undefined) throw new Error('记忆工具需要在活动的 DSH 会话中使用')
|
|
45
|
+
/** 工作区根固定在会话头里;会话内 cd 到子目录时仍按原工作区读写。 */
|
|
46
|
+
const 固定目录 = exec.agent.session?.header?.cwd
|
|
47
|
+
if (typeof 固定目录 === 'string' && 固定目录.trim().length > 0) return 固定目录
|
|
44
48
|
return ctx.workingDirectory.ensure(exec.agent, exec.signal)
|
|
45
49
|
}
|
|
46
50
|
|
|
@@ -56,6 +60,27 @@ export function 创建工具(环境) {
|
|
|
56
60
|
return 服务?.resolve({ ...(exec.agent ? { session: exec.agent.session } : {}) })
|
|
57
61
|
}
|
|
58
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 用户级记忆位于会话工作区之外;workspace-write 下先为该会话登记一个
|
|
65
|
+
* 可写根(已存在的用户级目录,否则配置根)。read-only 仍然拒绝,
|
|
66
|
+
* danger-full-access 不需要这一步。
|
|
67
|
+
*/
|
|
68
|
+
const 已授权用户目录 = new WeakSet()
|
|
69
|
+
function 启用用户目录写入(exec) {
|
|
70
|
+
const 服务 = ctx.get('sandboxPolicy')
|
|
71
|
+
const session = exec.agent?.session
|
|
72
|
+
if (服务 === undefined || session === undefined || 已授权用户目录.has(session)) return
|
|
73
|
+
try {
|
|
74
|
+
const 用户目录 = 用户记忆目录(配置)
|
|
75
|
+
const 根 = existsSync(用户目录) ? 用户目录 : 配置根目录(配置)
|
|
76
|
+
if (!existsSync(根)) return
|
|
77
|
+
服务.registerWritableRoot(session, 根)
|
|
78
|
+
已授权用户目录.add(session)
|
|
79
|
+
} catch (错误) {
|
|
80
|
+
ctx.logger.warn(`[WorkBuddy 记忆] 用户级目录可写根注册失败:${错误?.message ?? 错误}`)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
59
84
|
function 目标路径(target, cwd, date) {
|
|
60
85
|
if (target === 'user') return join(用户记忆目录(配置), 用户记忆文件名)
|
|
61
86
|
const 目录 = 项目记忆目录(cwd, 配置)
|
|
@@ -101,7 +126,7 @@ export function 创建工具(环境) {
|
|
|
101
126
|
行.push(` MEMORY.md:读取失败(${用户读取.错误?.message ?? 用户读取.错误})`)
|
|
102
127
|
}
|
|
103
128
|
const 根 = 项目根目录(cwd, 配置.projectRootMarkers)
|
|
104
|
-
行.push(
|
|
129
|
+
行.push(`工作区目录:${cwd}`)
|
|
105
130
|
行.push(`项目根:${根}`)
|
|
106
131
|
行.push(`项目记忆目录:${项目目录}`)
|
|
107
132
|
const 项目读取 = 读取本地文本(项目路径)
|
|
@@ -203,6 +228,7 @@ export function 创建工具(环境) {
|
|
|
203
228
|
新文本 = 规整替换(args.content)
|
|
204
229
|
操作 = 现有.存在 ? '覆盖' : '新建'
|
|
205
230
|
}
|
|
231
|
+
if (target === 'user') 启用用户目录写入(exec)
|
|
206
232
|
await 写入记忆文本(fs, 路径, 新文本, exec.signal, 沙箱策略(exec))
|
|
207
233
|
const 行 = [`已${操作}:${路径}`, `文件长度:${新文本.trim().length} UTF-16 字符`]
|
|
208
234
|
const 上限 = target === 'user' ? 配置.userMemoryLimit : target === 'project' ? 配置.projectMemoryLimit : null
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 记忆策略提示词:与 WorkBuddy 记忆层的规则保持一致(但不含其云端记忆层),
|
|
3
|
-
*
|
|
3
|
+
* 作为系统提示词章节注入。项目路径必须是当前会话解析出的绝对路径,
|
|
4
|
+
* 否则模型直接 Read/Edit 时会找不到文件。
|
|
4
5
|
*
|
|
5
6
|
* 文案为本项目自行撰写,不复制对方提示词原文;规则条目与被注入的路径、
|
|
6
7
|
* 上限、标记则必须与真实行为一致,否则模型会按错误的约定写文件。
|
|
7
8
|
*/
|
|
8
|
-
import { 数据目录名,
|
|
9
|
+
import { 数据目录名, 用户记忆目录, 项目记忆目录由根 } from './路径.js'
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
export function 策略文本(
|
|
11
|
+
/** 生成策略文本;项目根由当前会话解析,用户目录每次重新解析以跟随账号切换。 */
|
|
12
|
+
export function 策略文本(配置, 项目根) {
|
|
12
13
|
const 用户目录 = 用户记忆目录(配置)
|
|
13
|
-
const
|
|
14
|
-
|
|
14
|
+
const 目录名 = 数据目录名(配置)
|
|
15
|
+
const 项目目录 = 项目根 ? 项目记忆目录由根(项目根, 配置) : `<workspace>/${目录名}/memory`
|
|
16
|
+
const 标记 = (配置.projectRootMarkers ?? []).filter((项) => typeof 项 === 'string' && 项.length > 0)
|
|
17
|
+
const 根说明 = 标记.length > 0
|
|
18
|
+
? `The project root is the nearest ancestor of the session workspace directory that contains ${标记.join(' / ')}; if no ancestor does, the workspace directory itself is the project root.`
|
|
19
|
+
: `The project root is exactly the session workspace directory (the DSH workspace folder, which is also the WorkBuddy group folder). It is never derived from an enclosing git repository.`
|
|
20
|
+
return `IMPORTANT: You have access to two independent local memory layers with different scopes and different write rules. Both are plain Markdown files that the WorkBuddy desktop app shares with you: whichever side writes, the other one reads the same file on its next prompt build.
|
|
15
21
|
<memory_system>
|
|
16
22
|
|
|
17
23
|
# Layer 1 — User-level Local Memory (read/write)
|
|
@@ -24,16 +30,17 @@ Only the injected copy is truncated past the limit; the file itself never gets t
|
|
|
24
30
|
|
|
25
31
|
# Layer 2 — Workspace Memory (read/write)
|
|
26
32
|
|
|
27
|
-
Directory:
|
|
28
|
-
|
|
33
|
+
Directory: ${项目目录} | Scope: this DSH workspace only
|
|
34
|
+
${根说明}
|
|
35
|
+
This workspace folder is the same folder WorkBuddy uses for this project group. Both sides read and write ${目录名}/memory under it, so a write from either side is visible to the other side's next session.
|
|
29
36
|
|
|
30
37
|
Files:
|
|
31
38
|
- YYYY-MM-DD.md — daily work log. Append-only: never overwrite it.
|
|
32
|
-
- MEMORY.md — curated long-term notes for this
|
|
39
|
+
- MEMORY.md — curated long-term notes for this workspace. Limit: ${配置.sessionWriteBudget} chars per session.
|
|
33
40
|
- If today's file is absent, create the directory and the dated file first (memory_write does this automatically).
|
|
34
41
|
|
|
35
42
|
Reading history: pick the source you need instead of reading everything.
|
|
36
|
-
- Work this
|
|
43
|
+
- Work this workspace did before → recent daily logs first, then MEMORY.md.
|
|
37
44
|
- Nothing depends on history → skip the memory files entirely.
|
|
38
45
|
|
|
39
46
|
Scope of responsibility: workspace memory is supplementary only. It never replaces your reply, your final answer, or any deliverable the user asked for.
|
|
@@ -44,12 +51,12 @@ Scope of responsibility: workspace memory is supplementary only. It never replac
|
|
|
44
51
|
- wrote or generated a report or document
|
|
45
52
|
- refactored code or changed architecture
|
|
46
53
|
- chose a technical approach (framework, design pattern, ...)
|
|
47
|
-
- the user stated
|
|
54
|
+
- the user stated workspace conventions or preferences → also update MEMORY.md in place
|
|
48
55
|
|
|
49
56
|
Daily logs are append-only. Do not record transient things (search results, temporary paths, tool errors). Keep only what stays useful in later sessions.
|
|
50
57
|
|
|
51
58
|
Maintenance: distill daily logs older than ${配置.distillAfterDays} days into MEMORY.md by topic, then delete the old files. Never store secrets unless the user asks you to.
|
|
52
59
|
|
|
53
|
-
Tools: memory_read looks at these files (one layer, one day's log, recent days, or a status report); memory_write appends or replaces them, and enforces append-only for daily logs. Plain read/edit calls on the
|
|
60
|
+
Tools: memory_read looks at these files (one layer, one day's log, recent days, or a status report); memory_write appends or replaces them, and enforces append-only for daily logs. Plain read/edit calls on the exact absolute paths above work too.
|
|
54
61
|
</memory_system>`
|
|
55
62
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 注入标记、截断算法、空文件处理按 WorkBuddy 5.11.3 的可观察行为实现:
|
|
5
5
|
* - 读取后 trim;文件不存在或内容为空时不注入任何标签
|
|
6
6
|
* - 用户级上限 4,000、项目级上限 10,000,均按 UTF-16 码元计数
|
|
7
|
-
* - 注入是同步的(DSH 的
|
|
7
|
+
* - 注入是同步的(DSH 的 system prompt section 同步求值),因此读取用 node:fs;
|
|
8
8
|
* 工具写入走 ctx.fs,沿用宿主的原子写与沙箱策略。
|
|
9
9
|
*/
|
|
10
10
|
import { readFileSync, readdirSync } from 'node:fs'
|
|
@@ -12,78 +12,93 @@
|
|
|
12
12
|
|
|
13
13
|
## 安装
|
|
14
14
|
|
|
15
|
-
让 DSH 调用 `plugin_manager install_bundle`,target 填 `dsh-workbuddy-shared-memory@0.1.
|
|
15
|
+
让 DSH 调用 `plugin_manager install_bundle`,target 填 `dsh-workbuddy-shared-memory@0.1.1`,或在 Web 界面的 Plugins 页面安装。要求 DSH `0.2.2-rc.5`(`engines.dsh: ^0.2.2-rc.5`)与 Node `>=22`。装完需要**重启 DSH**(Host 插件在启动时加载),然后**新开会话**。
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## 目录对应
|
|
18
18
|
|
|
19
|
-
| 层
|
|
20
|
-
|
|
|
21
|
-
| 用户级记忆
|
|
22
|
-
| 项目长期笔记 |
|
|
23
|
-
| 项目每日日志 |
|
|
19
|
+
| 层 | 位置 | 作用 |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| 用户级记忆 | `~/.workbuddy/user-<uid>-<entId\|personal>/MEMORY.md` | 跨项目、长期强制规则(环境路径、个人约定) |
|
|
22
|
+
| 项目长期笔记 | `<DSH 工作区>/.workbuddy/memory/MEMORY.md` | 当前工作区的精选笔记 |
|
|
23
|
+
| 项目每日日志 | `<DSH 工作区>/.workbuddy/memory/YYYY-MM-DD.md` | 只追加的工作日志 |
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
25
|
+
核心对应关系:**DSH 工作区目录就是 WorkBuddy 的分组目录**。DSH 会话在哪个工作区,项目级记忆就在该工作区的 `.workbuddy/memory` 下;WorkBuddy 用同一个文件夹作为分组目录时,两边看到的完全是同一批文件。
|
|
26
|
+
|
|
27
|
+
- 项目根**不再向上寻找 `.git`**。默认 `projectRootMarkers: []`,即项目根 = 会话固定的工作区目录(`session.header.cwd`)。会话内 `cd` 到子目录不会改变记忆位置。
|
|
28
|
+
- 只有显式配置了 `projectRootMarkers`(例如 `['.git']`)才会向上找标记;这是 opt-in 的旧行为,不是默认值。
|
|
29
|
+
- 未登录 WorkBuddy 时,用户级目录回退为配置根本身;插件会在配置根下探测 `user-*` 账号目录,也可以用 `userDir` 显式指定。
|
|
30
|
+
- DSH 工作区与 WorkBuddy 分组如果不是同一个文件夹,项目记忆不会自动共享——需要把 DSH 工作区开在分组目录上,或用 `workbuddyRoot` / 路径配置对齐。
|
|
28
31
|
|
|
29
32
|
## 注入方式
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
34
|
+
策略和两层记忆内容**都进入 system prompt**,与 WorkBuddy 的注入位置一致:
|
|
35
|
+
|
|
36
|
+
- 策略(静态规则)走 `systemPrompt.section`(`workbuddy-memory:policy`,order `8600`)。路径按当前会话实时解析成**绝对路径**,不再出现 `<项目根>` 占位符。
|
|
37
|
+
- 内容(`<user_memory>` + `<working_memory_content>`)走 `systemPrompt.section`(`workbuddy-memory:content`,order `8601`):每次系统提示词装配都重新读文件。
|
|
38
|
+
- 不再使用 `systemPrompt.context`,因此记忆不会作为 user-role 快照追加进会话历史。代价是:记忆文件变化时 system prompt 文本会变化,DSH 会原地替换该文本,相关前缀缓存可能失效;这是为了让注入位置与 WorkBuddy 对齐而接受的取舍。
|
|
39
|
+
- 用户级上限 **4,000 UTF-16 字符**,项目级上限 **10,000 UTF-16 字符**。截断按 UTF-16 码元计算,切口落到代理对中间时回退一个码元,不会切碎 emoji。用户级超限附加 `... (user memory truncated)`;项目级超限附加 WorkBuddy legacy 的强制清理指令。
|
|
40
|
+
- 文件不存在、内容 trim 后为空就完全不注入;读取失败只告警,不影响对话。
|
|
41
|
+
- 写入规则随策略注入:用户明确要求长期记住时更新用户级文件;完成实质性工作后追加当日日志;用户分享项目约定时更新项目笔记;超过 30 天的日志蒸馏进项目笔记后删除。
|
|
37
42
|
|
|
38
43
|
## 工具
|
|
39
44
|
|
|
40
|
-
| 工具
|
|
41
|
-
|
|
|
42
|
-
| `memory_read`
|
|
45
|
+
| 工具 | 用途 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `memory_read` | `target=user/project/daily/recent/status`;读单层记忆、某日日志、最近日志或状态报告(路径、长度、注入上限、待蒸馏清单),长文件支持 `offset/limit` 分页 |
|
|
43
48
|
| `memory_write` | `target=user/project/daily`,`mode=append/replace`;`daily` 强制只追加;`replace` 可配 `old_string`/`new_string` 做唯一片段原地编辑 |
|
|
44
49
|
|
|
45
|
-
直接使用 DSH 自带的 `read`/`edit`
|
|
50
|
+
直接使用 DSH 自带的 `read`/`edit` 操作上述绝对路径也可以,两条路并不冲突。
|
|
46
51
|
|
|
47
52
|
## 配置
|
|
48
53
|
|
|
49
54
|
在 `cordis.patch.yml` 的 `workbuddy-memory` 行里写 config:
|
|
50
55
|
|
|
51
|
-
| 字段
|
|
52
|
-
|
|
|
53
|
-
| `enabled`
|
|
54
|
-
| `dataFolderName`
|
|
55
|
-
| `workbuddyRoot`
|
|
56
|
-
| `userDir`
|
|
57
|
-
| `userMemoryLimit`
|
|
58
|
-
| `projectMemoryLimit`
|
|
59
|
-
| `sessionWriteBudget`
|
|
60
|
-
| `distillAfterDays`
|
|
61
|
-
| `injectPolicy` / `injectContent` | `true`
|
|
62
|
-
| `projectRootMarkers`
|
|
56
|
+
| 字段 | 默认 | 含义 |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| `enabled` | `true` | 总开关 |
|
|
59
|
+
| `dataFolderName` | `''` | 数据目录名,缺省读 `WORKBUDDY_DATA_FOLDER_NAME` 或 `.workbuddy` |
|
|
60
|
+
| `workbuddyRoot` | `''` | WorkBuddy 配置根,缺省读 `WORKBUDDY_CONFIG_DIR` 或 `~/<数据目录名>` |
|
|
61
|
+
| `userDir` | `''` | 显式指定用户级记忆目录,缺省自动探测 `user-*` |
|
|
62
|
+
| `userMemoryLimit` | `4000` | 用户级注入上限(UTF-16 字符) |
|
|
63
|
+
| `projectMemoryLimit` | `10000` | 项目级注入上限(UTF-16 字符) |
|
|
64
|
+
| `sessionWriteBudget` | `3000` | 写进提示词的项目笔记每会话预算 |
|
|
65
|
+
| `distillAfterDays` | `30` | 超过该天数的日志进入待蒸馏清单 |
|
|
66
|
+
| `injectPolicy` / `injectContent` | `true` | 分别控制策略提示词与记忆内容注入 |
|
|
67
|
+
| `projectRootMarkers` | `[]` | 项目根标记;空 = 直接用会话工作区目录,非空才向上找 |
|
|
68
|
+
|
|
69
|
+
## 沙箱与写入
|
|
70
|
+
|
|
71
|
+
- 项目级记忆在 DSH 工作区内,`workspace-write` 下可直接写。
|
|
72
|
+
- 用户级记忆在工作区外。`memory_write` 的 `target=user` 会在写入前为该**会话**懒注册可写根:优先注册已存在的用户级目录,否则注册配置根;每个会话只注册一次。`read-only` 仍然拒绝,`danger-full-access` 不需要注册。
|
|
73
|
+
- 这个可写根是 DSH 运行时状态,只对当前会话有效;resume / fork 后的新会话首次写入会重新注册。
|
|
74
|
+
- 直接用 `read`/`edit` 工具改用户级文件不会触发注册;在 `workspace-write` 下仍会被宿主拒绝,此时请用 `memory_write target=user`。
|
|
75
|
+
- 显式 `userDir` 指向配置根之外且尚未创建的目录时,懒注册会退回配置根,可能仍覆盖不到该目录;请先创建 `userDir`。
|
|
63
76
|
|
|
64
77
|
## 限制
|
|
65
78
|
|
|
66
|
-
- **没有云端记忆层**:WorkBuddy 的服务端画像与 `conversation_search`
|
|
67
|
-
-
|
|
79
|
+
- **没有云端记忆层**:WorkBuddy 的服务端画像与 `conversation_search` 依赖腾讯服务端,本插件不涉及;策略只描述用户级与项目级两层本地记忆。
|
|
80
|
+
- **对齐的是 legacy 本地记忆布局**:不针对 WorkBuddy 的 platform 模式(服务端云记忆 + 本地缓存)做适配。
|
|
81
|
+
- **用户账号目录仍是启发式**:多个 `user-*` 目录并存时按 `MEMORY.md` 的 mtime 选择,可能选错;请用 `userDir` 固定。
|
|
68
82
|
- **跨进程并发**:没有跨进程文件锁,WorkBuddy 与 DSH 同时写同一文件时后写者覆盖先写者;进程内的并行工具调用已串行化。
|
|
69
|
-
-
|
|
70
|
-
-
|
|
83
|
+
- **项目根语义**:默认不做任何上溯,所以 DSH 工作区必须就是 WorkBuddy 分组目录;跨工作区不共享项目记忆。
|
|
84
|
+
- **无提交的自动化测试**:当前靠合成工作区脚本与本机联调验证;补正式测试是待办。
|
|
71
85
|
|
|
72
86
|
## 真机验证
|
|
73
87
|
|
|
74
|
-
1.
|
|
75
|
-
2. `memory_write`
|
|
76
|
-
3. 反向在 WorkBuddy 里让它记住一条规则,回 DSH
|
|
88
|
+
1. 重启 DSH 后新开会话,`memory_read`(`target=status`),确认「用户级目录 / 工作区目录 / 项目根 / 项目记忆目录」符合预期。
|
|
89
|
+
2. `memory_write` 往当日日志追加一条,检查 `<DSH 工作区>/.workbuddy/memory/YYYY-MM-DD.md`;在 WorkBuddy 打开同一分组问「今天做了什么」,应能看到。
|
|
90
|
+
3. 反向在 WorkBuddy 里让它记住一条规则,回 DSH **新开会话**(让 system prompt 重新装配)后 `memory_read target=user` 应能读到,且模型回答能引用它。
|
|
91
|
+
4. 在 `workspace-write` 下测试 `memory_write target=user`,应成功;直接 `edit` 用户级文件则应被宿主拒绝,这符合预期。
|
|
77
92
|
|
|
78
93
|
## 开发
|
|
79
94
|
|
|
80
95
|
```bash
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
pnpm install --offline
|
|
97
|
+
pnpm run check # 五个运行时文件逐个 node --check
|
|
83
98
|
npm pack --dry-run # 看发布内容
|
|
84
99
|
```
|
|
85
100
|
|
|
86
|
-
纯 JavaScript,无构建步骤:`exports` 直接指向包根的 `入口.js
|
|
101
|
+
纯 JavaScript,无构建步骤:`exports` 直接指向包根的 `入口.js`。本地 `node_modules` 里的 peer 依赖是 pnpm 链接;如果目录被改名,需要重新 `pnpm install` 修复链接。
|
|
87
102
|
|
|
88
103
|
## 包内文件
|
|
89
104
|
|
|
@@ -91,4 +106,4 @@ npm pack --dry-run # 看发布内容
|
|
|
91
106
|
|
|
92
107
|
## 许可
|
|
93
108
|
|
|
94
|
-
MIT,见 [LICENSE](LICENSE)。
|
|
109
|
+
MIT,见 [LICENSE](LICENSE)。
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 按 WorkBuddy 5.11.3 的实际目录布局实现:
|
|
5
5
|
* - 数据目录名:WORKBUDDY_DATA_FOLDER_NAME 或 '.workbuddy'
|
|
6
|
-
* - 配置根目录:WORKBUDDY_CONFIG_DIR 或
|
|
6
|
+
* - 配置根目录:WORKBUDDY_CONFIG_DIR 或 ~/<数据目录名>
|
|
7
7
|
* - 用户级目录:user-<uid>-<enterpriseId|personal>,未登录时回退到配置根
|
|
8
8
|
* - 项目级目录:<项目根>/<数据目录名>/memory
|
|
9
9
|
*/
|
|
@@ -24,7 +24,7 @@ export function 数据目录名(配置) {
|
|
|
24
24
|
export function 配置根目录(配置) {
|
|
25
25
|
return 配置.workbuddyRoot?.trim()
|
|
26
26
|
|| process.env.WORKBUDDY_CONFIG_DIR?.trim()
|
|
27
|
-
|| join(homedir(),
|
|
27
|
+
|| join(homedir(), 数据目录名(配置))
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -53,13 +53,15 @@ export function 用户记忆目录(配置) {
|
|
|
53
53
|
return 根
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
56
|
+
/** 从会话工作目录向上寻找项目根;标记列表为空时直接以会话目录为项目根(WorkBuddy 分组语义)。 */
|
|
57
57
|
export function 项目根目录(工作目录, 标记列表) {
|
|
58
58
|
const 起点 = resolve(工作目录)
|
|
59
|
+
const 标记 = (标记列表 ?? []).filter((项) => typeof 项 === 'string' && 项.length > 0)
|
|
60
|
+
if (标记.length === 0) return 起点
|
|
59
61
|
let 当前 = 起点
|
|
60
62
|
while (true) {
|
|
61
|
-
for (const
|
|
62
|
-
try { if (existsSync(join(当前,
|
|
63
|
+
for (const 标记项 of 标记) {
|
|
64
|
+
try { if (existsSync(join(当前, 标记项))) return 当前 } catch { /* 忽略不可读目录 */ }
|
|
63
65
|
}
|
|
64
66
|
const 父级 = dirname(当前)
|
|
65
67
|
if (父级 === 当前) return 起点
|
|
@@ -68,9 +70,13 @@ export function 项目根目录(工作目录, 标记列表) {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/** 项目级记忆目录:<项目根>/<数据目录名>/memory。 */
|
|
73
|
+
export function 项目记忆目录由根(根, 配置) {
|
|
74
|
+
return join(根, 数据目录名(配置), 'memory')
|
|
75
|
+
}
|
|
76
|
+
|
|
71
77
|
export function 项目记忆目录(工作目录, 配置) {
|
|
72
78
|
const 根 = 项目根目录(工作目录, 配置.projectRootMarkers)
|
|
73
|
-
return
|
|
79
|
+
return 项目记忆目录由根(根, 配置)
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/** 本地时区的 YYYY-MM-DD,与每日日志文件名一致。 */
|