dsh-memory-palace 1.7.0 → 1.7.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  把 WorkBuddy 的文件式记忆系统移植进 [DeepSeek Harness](https://www.deepseek.com/harness/) —— 为 Harness 提供**跨会话持久化、人类可直接编辑的 Markdown 记忆**。
4
4
 
5
- [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com) [![npm](https://img.shields.io/npm/v/dsh-memory-palace.svg?label=npm&labelColor=000000&color=ff4b01)](https://www.npmjs.com/package/dsh-memory-palace) [![DeepSeek Harness:0.1.2-rc.1](https://img.shields.io/badge/DeepSeek%20Harness-0.1.2--rc.1-success.svg?labelColor=4D6BFE)](https://github.com/deepseek-ai/deepseek-harness)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![Awesome DSH Plugin](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com) [![npm](https://img.shields.io/npm/v/dsh-memory-palace.svg?label=npm&labelColor=000000&color=ff4b01)](https://www.npmjs.com/package/dsh-memory-palace) [![DeepSeek Harness:0.1.5-rc.1](https://img.shields.io/badge/DeepSeek%20Harness-0.1.5--rc.1-success.svg?labelColor=4D6BFE)](https://github.com/deepseek-ai/deepseek-harness)
6
6
 
7
7
  ## 特性
8
8
 
@@ -12,10 +12,11 @@
12
12
  - **WorkBuddy / CodeBuddy 桥接**:项目已有对应记忆目录时直接读写,无需重复维护。
13
13
  - **记忆工具**:AI 可主动写入、聚合读取、按内容删除(删除需人工确认),写入自带去重。
14
14
  - **手动蒸馏**:会话标题栏一键把当前对话或项目记忆提炼成长期记忆。
15
- - **设置页集成**:全部配置均可在 DSH 设置面板中图形化调整,无需改配置文件。
15
+ - **设置页集成**:全部配置均可在 DSH 设置面板中图形化调整(按板块折叠),无需改配置文件。
16
+ - **自定义指令**:不适合写进记忆的特殊指令可在设置页配置,插件经系统提示词注入。
16
17
  - **主动记忆(插件模式)**:以指令引导 AI 在完成任务、修复问题、确定决策、获知偏好时主动落档。
17
18
  - **智能模式**:由模型自动提炼每轮新增内容,摘要进日志、长期事实进记忆。
18
- - **记忆注入**:长期记忆全程常驻、每个步骤都可见;今日日志按轮次注入,避免上下文膨胀。
19
+ - **记忆注入**:长期记忆与今日日志以「会话起始快照」常驻上下文、按文件身份各只注入一次 —— 既保证每个步骤都可见,又不破坏前缀缓存、不堆积冗余快照。
19
20
  - **混合模式(🔥推荐)**:子代理每轮自动整理日志并去重,长期记忆由主 AI 主动维护,兼顾自动化与可控性。
20
21
  - **标准插件包**:经官方插件机制一键安装,无需改动 harness。
21
22
 
@@ -63,7 +64,7 @@
63
64
  |---|---|---|
64
65
  | `memory_note` | 项目级 | 把约定/偏好写入当前项目全部目标 `MEMORY.md`(去重) |
65
66
  | `memory_note_user` | 用户级 | 把跨项目偏好写入 `~/.deepseek-harness/MEMORY.md`(去重) |
66
- | `memory_read` | 聚合 | 一次性读取用户级 + 项目级记忆、今日日志与最近 3 份历史日志 |
67
+ | `memory_read` | 按需 | 读取记忆。`scope` 默认 `memory`(用户级 + 项目级);可选 `project`(仅项目级,与 `memory_write` 的写侧 scope 同名)/ `today` / `yesterday` / `daily`(近三天日志)/ `all`(长期记忆 + 日志) |
67
68
  | `memory_delete` | 用户级/项目级/每日级 | 按内容删除记忆条目(两阶段确认:先预览匹配位置与内容,用户确认后再删;删除动作经 harness 原生确认弹窗硬闸门,真人点允许才真正执行) |
68
69
  | `memory_write`(hybrid) | 项目级/用户级 | 章节化写入:章节存在则末尾追加,不存在则新建章节(章节化格式规范) |
69
70
  | `memory_update_section`(hybrid) | 项目级/用户级 | 整章节精确替换/单条标记删除:oldText 归一化精确匹配防 stale,失败拒绝并回显实际内容 |
@@ -77,7 +78,7 @@
77
78
 
78
79
  ```bash
79
80
  dsh plugin --profile web add github:lovezi0/dsh-memory-palace
80
- # 锁定版本:dsh plugin --profile web add github:lovezi0/dsh-memory-palace#v1.7.0
81
+ # 锁定版本:dsh plugin --profile web add github:lovezi0/dsh-memory-palace#v1.7.1
81
82
  ```
82
83
 
83
84
  方式二:clone 后本地安装(开发 / 修改源码场景)
@@ -109,7 +110,7 @@ dsh plugin --profile web remove dsh-memory-palace
109
110
 
110
111
  ## 配置
111
112
  *面板路径为 DSH 设置 →「记忆」*
112
- 所有配置项(基础 / 自动记录 / 开发 三张卡片的字段、默认值与说明)已整理至 [CONFIG.md](./CONFIG.md)
113
+ 所有配置项(核心 / 自定义指令 / 自动记录 / 存储路径与预算 / 开发 五张卡片的字段、默认值与说明)已整理至 [CONFIG.md](./CONFIG.md)
113
114
 
114
115
  ## 开发
115
116
 
@@ -118,12 +119,16 @@ dsh plugin --profile web remove dsh-memory-palace
118
119
 
119
120
  ## 版本历史
120
121
 
122
+ - **1.7.1**
123
+ - 💪移除日志重注机制优化缓存命中降低堆积冗余
124
+ - 💪记忆设置UI优化
125
+ - 🔥增加自定义指令 prompt 配置与注入
126
+ - 💪memory_read 增加 scope 参数
121
127
  - **1.7.0**
122
- - **1.7.0.alpha.1**
123
- - 🔥新增独立通道注入记忆文件
124
- - 🐛修复存在多种记忆路径时读取冲突的问题
125
- - 💪优化记忆子 agent 投影消息节省 token
126
- - 💪优化 SUBAGENT_SYSTEM 记忆输出格式
128
+ - 🔥新增独立通道注入记忆文件
129
+ - 🐛修复存在多种记忆路径时读取冲突的问题
130
+ - 💪优化记忆子 agent 投影消息节省 token
131
+ - 💪优化 SUBAGENT_SYSTEM 记忆输出格式
127
132
  - **1.6.3**
128
133
  - npm publish
129
134
  - **1.6.3.alpha.4**
package/lib/client.js CHANGED
@@ -16,8 +16,13 @@ window.__ModuleLoader__.load({
16
16
  title: "记忆",
17
17
  intro: "memory-palace 记忆宫殿:跨会话持久化的 Markdown 记忆。",
18
18
  core: "核心",
19
+ coreDesc: "buddy 记忆桥接与项目记忆目录",
20
+ custom: "自定义指令",
21
+ customDesc: "不适合写进用户记忆的特殊指令,经系统提示词注入",
19
22
  smartSummary: "自动记录",
23
+ smartSummaryDesc: "记忆模式、自动记录与模型参数",
20
24
  storage: "存储路径与预算",
25
+ storageDesc: "记忆文件路径、日志保留与注入预算",
21
26
  bridgeLabel: "桥接 buddy 项目记忆",
22
27
  bridgeHint: "项目已存在 .workbuddy / .codebuddy 记忆目录时直接读写,不再建 .deepseek-harness/memory/",
23
28
  dirsLabel: "buddy 记忆目录(逗号分隔,按序优先)",
@@ -47,6 +52,8 @@ window.__ModuleLoader__.load({
47
52
  subagentLogBudgetHint: "记忆子代理回喂今日工作日志的字符上限;超出时仅回喂章节目录,子代理按需读取章节。默认 20000。",
48
53
  summaryModelLabel: "模型",
49
54
  summaryModelHint: "记忆插件当前使用的模型(智能模式会话摘要 / 手动蒸馏 / hybrid 记忆子代理共用)。留空=复用当前会话的 provider/model;也可固定廉价小模型省 token。",
55
+ expand: "展开",
56
+ collapse: "收起",
50
57
  save: "保存",
51
58
  saving: "保存中…",
52
59
  discard: "放弃",
@@ -73,6 +80,7 @@ window.__ModuleLoader__.load({
73
80
  distillDebugLogLabel: "蒸馏调试日志",
74
81
  distillDebugLogHint: "开启后向 dsh 服务端控制台(stderr)输出蒸馏 LLM 调用诊断。info 级别仅输出元数据(不含文本);配合 distillLogLevel=debug 会额外打印 LLM 原始响应(分隔符包裹),仅限受信本地排障。",
75
82
  dev: "开发",
83
+ devDesc: "蒸馏调试日志与超时",
76
84
  distillTimeoutLabel: "蒸馏超时(秒)",
77
85
  distillTimeoutHint: "单次蒸馏 LLM 调用的超时上限(秒);超时视为失败并降级。覆盖智能模式摘要与手动蒸馏,默认 60 秒。",
78
86
  summaryMaxTokensLabel: "会话摘要最大 Token",
@@ -80,7 +88,10 @@ window.__ModuleLoader__.load({
80
88
  projectMaxTokensLabel: "项目蒸馏最大 Token",
81
89
  projectMaxTokensHint: "最终输出软预算(prompt 约束,思考不受限;实际硬上限由模型自身 maxTokens 决定)。默认 8000。",
82
90
  feedbackEnabledLabel: "回喂存量记忆",
83
- feedbackEnabledHint: "每次蒸馏时附带项目级 + 用户级记忆作为参考,使其能基于既有记忆做增量维护(delete 仅手动蒸馏开放)。混合模式下仅手动触发蒸馏受影响(自动路径走记忆子代理,自带日志回喂)。默认关。"
91
+ feedbackEnabledHint: "每次蒸馏时附带项目级 + 用户级记忆作为参考,使其能基于既有记忆做增量维护(delete 仅手动蒸馏开放)。混合模式下仅手动触发蒸馏受影响(自动路径走记忆子代理,自带日志回喂)。默认关。",
92
+ customLabel: "自定义指令内容",
93
+ customHint: "非空时注入系统提示词,位置在记忆插件与分工说明之后。对全部会话生效;留空则不注入。",
94
+ customPlaceholder: "例如:回答用中文;代码注释用英文;提交信息用祈使句…"
84
95
  };
85
96
 
86
97
  const en = {
@@ -88,8 +99,13 @@ window.__ModuleLoader__.load({
88
99
  title: "Memory",
89
100
  intro: "memory-palace: persistent, human-readable Markdown memory across sessions.",
90
101
  core: "Core",
102
+ coreDesc: "Buddy memory bridging and workspace memory dirs",
103
+ custom: "Custom instructions",
104
+ customDesc: "Special instructions that do not belong in user memory, injected via the system prompt",
91
105
  smartSummary: "Auto-record",
106
+ smartSummaryDesc: "Memory mode, auto-record and model parameters",
92
107
  storage: "Storage & budgets",
108
+ storageDesc: "Memory file paths, log retention and injection budgets",
93
109
  bridgeLabel: "Bridge buddy project memory",
94
110
  bridgeHint: "Read/write directly into existing .workbuddy / .codebuddy memory dirs instead of creating .deepseek-harness/memory/",
95
111
  dirsLabel: "Buddy memory dirs (comma-separated, first wins)",
@@ -119,6 +135,8 @@ window.__ModuleLoader__.load({
119
135
  subagentLogBudgetHint: "Max chars of today's daily log fed back to the memory sub-agent; beyond this only the chapter TOC is fed and the sub-agent reads sections on demand. Default 20000.",
120
136
  summaryModelLabel: "Model",
121
137
  summaryModelHint: "The model currently used by the memory plugin (shared by smart-mode session summarization / manual distillation / the hybrid memory sub-agent). Leave empty to reuse the current session's provider/model, or pin a cheap model (provider/model) to save tokens.",
138
+ expand: "Expand",
139
+ collapse: "Collapse",
122
140
  save: "Save",
123
141
  saving: "Saving…",
124
142
  discard: "Discard",
@@ -145,6 +163,7 @@ window.__ModuleLoader__.load({
145
163
  distillDebugLogLabel: "Distill debug log",
146
164
  distillDebugLogHint: "When on, prints distill LLM call diagnostics to the dsh server console (stderr). info level prints metadata only (no text); with distillLogLevel=debug it additionally prints the raw LLM response (wrapped in delimiters), for trusted local troubleshooting only.",
147
165
  dev: "Developer",
166
+ devDesc: "Distill debug log and timeout",
148
167
  distillTimeoutLabel: "Distill timeout (s)",
149
168
  distillTimeoutHint: "Timeout (in seconds) for a single distill LLM call; on timeout it fails and degrades. Covers both smart-mode summary and manual distillation. Default 60s.",
150
169
  summaryMaxTokensLabel: "Session summary max tokens",
@@ -152,7 +171,10 @@ window.__ModuleLoader__.load({
152
171
  projectMaxTokensLabel: "Project distill max tokens",
153
172
  projectMaxTokensHint: "Final output soft budget (prompt constraint, thinking not limited; actual hard cap is the model's own maxTokens). Default 8000.",
154
173
  feedbackEnabledLabel: "Feed existing memory into distillation",
155
- feedbackEnabledHint: "Feed the project-level + user-level memory in as reference on every distillation so the LLM can maintain existing memory incrementally (delete is only allowed via manual distillation). In hybrid mode only manual distillation is affected (the automatic path runs through the memory sub-agent, which feeds the log itself). Off by default."
174
+ feedbackEnabledHint: "Feed the project-level + user-level memory in as reference on every distillation so the LLM can maintain existing memory incrementally (delete is only allowed via manual distillation). In hybrid mode only manual distillation is affected (the automatic path runs through the memory sub-agent, which feeds the log itself). Off by default.",
175
+ customLabel: "Custom instruction text",
176
+ customHint: "When non-empty it is injected into the system prompt right after the memory-plugin and memory-roles instructions. Applies to every session; leave empty to inject nothing.",
177
+ customPlaceholder: "e.g. Answer in Chinese; write code comments in English; use imperative commit subjects…"
156
178
  };
157
179
 
158
180
 
@@ -179,7 +201,8 @@ window.__ModuleLoader__.load({
179
201
  projectMaxTokens: v.projectMaxTokens != null ? String(v.projectMaxTokens) : "8000",
180
202
  reorgCooldownDays: v.reorgCooldownDays != null ? String(v.reorgCooldownDays) : "7",
181
203
  subagentLogBudget: v.subagentLogBudget != null ? String(v.subagentLogBudget) : "20000",
182
- feedbackEnabled: v.feedbackEnabled === false ? "false" : "true"
204
+ feedbackEnabled: v.feedbackEnabled === false ? "false" : "true",
205
+ customInstructions: v.customInstructions || ""
183
206
  };
184
207
  }
185
208
 
@@ -250,6 +273,9 @@ window.__ModuleLoader__.load({
250
273
  const [failed, setFailed] = react.useState(false);
251
274
  const [validation, setValidation] = react.useState(null);
252
275
  const [modelOptions, setModelOptions] = react.useState([]);
276
+ // v1.7.1(特性2):折叠卡片的展开态(key → bool)。照抄宿主 ui-settings-plugins/PluginCard
277
+ // 的语义 —— 纯前端临时状态、**不持久化**:「用户打开哪张卡」是一次阅读手势,不是配置。
278
+ const [openCards, setOpenCards] = react.useState({});
253
279
 
254
280
  // 初始加载(从自有 route 读真实值)。
255
281
  react.useEffect(() => {
@@ -334,6 +360,8 @@ window.__ModuleLoader__.load({
334
360
  // 保存成功后同步 remote(真实返回值),保留当前 draft(= 用户保存的目标值)。
335
361
  setRemote({ value: full.value, user: full.user, revision: full.revision, loaded: true });
336
362
  setDirty(false);
363
+ // 保存完成 = 这一轮编辑动作结束 → 收起全部卡片回到总览态(对齐宿主 PluginCard 行为)。
364
+ setOpenCards({});
337
365
  } catch (e) {
338
366
  setFailed(true);
339
367
  } finally {
@@ -423,19 +451,68 @@ window.__ModuleLoader__.load({
423
451
  borderTop: "1px solid var(--dsw-alias-border-l2, #e5e7eb)"
424
452
  };
425
453
 
454
+ // ---- v1.7.1(特性2):折叠卡片样式 —— 逐值照抄宿主 ui-settings-plugins 的 PluginCard.module.css ----
455
+ // 竖向「name 叠在 description 上」的卡片宿主无可复用组件(它导出的 DisclosureRow 是横向 24px
456
+ // 紧凑行,布局不同,宿主 README 亦明确区分二者),故手写;chevron 用 data URI 内联 SVG
457
+ // (本项目 client 只能 require("react"),不引宿主图标包)。
426
458
  const cardStyle = {
427
- border: "1px solid var(--dsw-alias-border-l2, #e5e7eb)",
428
- borderRadius: "12px",
429
- padding: "14px 16px",
459
+ border: "0.5px solid var(--dsw-alias-border-l4, #e5e7eb)",
460
+ // ⚠️ 必须显式写 borderColor:展开/收起靠 React diff 增删 cardOpenStyle 的 borderColor。
461
+ // 若只依赖 shorthand 的颜色,open 态写入的 borderColor 被移除后,CSSOM 中 border-color
462
+ // 声明随之删除 → 回退 UA 初始值 currentColor(文字色,近黑)→ 收起后边框变黑(真机 bug)。
463
+ borderColor: "var(--dsw-alias-border-l4, #e5e7eb)",
464
+ borderRadius: "16px",
430
465
  marginBottom: "12px",
431
- background: "var(--dsw-alias-bg-layer-2, #ffffff)"
466
+ background: "var(--dsw-alias-bg-layer-3, #fafafa)",
467
+ overflow: "hidden"
432
468
  };
433
- const groupTitleStyle = {
434
- margin: "0 0 4px",
435
- fontSize: "13px",
436
- fontWeight: "500",
469
+ const cardOpenStyle = {
470
+ ...cardStyle,
471
+ background: "var(--dsw-alias-bg-layer-2, #ffffff)",
472
+ borderColor: "var(--dsw-alias-label-dimmed, #c9ced6)"
473
+ };
474
+ const cardHeaderStyle = {
475
+ display: "flex",
476
+ alignItems: "center",
477
+ gap: "12px",
478
+ width: "100%",
479
+ padding: "14px 16px",
480
+ appearance: "none",
481
+ WebkitAppearance: "none",
482
+ border: "0",
483
+ background: "none",
484
+ font: "inherit",
485
+ textAlign: "left",
486
+ cursor: "pointer"
487
+ };
488
+ const cardHeadTextStyle = { flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: "4px" };
489
+ const cardNameStyle = {
490
+ fontSize: "15px",
491
+ fontWeight: "600",
492
+ lineHeight: "1.4",
437
493
  color: "var(--dsw-alias-label-primary, #1f2329)"
438
494
  };
495
+ const cardDescStyle = {
496
+ fontSize: "13px",
497
+ lineHeight: "1.5",
498
+ color: "var(--dsw-alias-label-tertiary, #8a919f)"
499
+ };
500
+ const cardBodyStyle = {
501
+ borderTop: "0.5px solid var(--dsw-alias-border-l2, #e5e7eb)",
502
+ margin: "0 16px",
503
+ paddingBottom: "8px"
504
+ };
505
+ const chevronStyle = {
506
+ flexShrink: 0,
507
+ width: "14px",
508
+ height: "14px",
509
+ backgroundImage:
510
+ "url(data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3.5 5.25L7 8.75L10.5 5.25' stroke='%2381858C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E)",
511
+ backgroundRepeat: "no-repeat",
512
+ backgroundPosition: "center",
513
+ backgroundSize: "14px 14px",
514
+ transition: "transform .16s"
515
+ };
439
516
  const sectionStyle = {
440
517
  maxWidth: "760px",
441
518
  color: "var(--dsw-alias-label-primary, #1f2329)",
@@ -503,18 +580,45 @@ window.__ModuleLoader__.load({
503
580
  const hintStyle = { color: "var(--dsw-alias-label-tertiary, #8a919f)", margin: 0, fontSize: "12px", lineHeight: "1.5" };
504
581
  const errStyle = { color: "var(--dsw-alias-label-error, #d54941)", margin: 0, fontSize: "12px", lineHeight: "1.5" };
505
582
 
583
+ const toggleCard = (key) => setOpenCards((o) => ({ ...o, [key]: !o[key] }));
584
+ // 折叠卡片:header 自身是 button(整行可点 + aria-expanded + aria-label),body 仅在展开时渲染。
585
+ const card = (key, title, desc, children) =>
586
+ h("div", { style: openCards[key] ? cardOpenStyle : cardStyle }, [
587
+ h("button", {
588
+ type: "button",
589
+ className: "mp-card-header",
590
+ "aria-expanded": openCards[key] ? "true" : "false",
591
+ "aria-label": `${t(openCards[key] ? "collapse" : "expand")}: ${title}`,
592
+ style: cardHeaderStyle,
593
+ onClick: () => toggleCard(key)
594
+ }, [
595
+ h("span", { style: cardHeadTextStyle }, [
596
+ h("span", { style: cardNameStyle }, title),
597
+ h("span", { style: cardDescStyle }, desc)
598
+ ]),
599
+ h("span", { style: openCards[key] ? { ...chevronStyle, transform: "rotate(180deg)" } : chevronStyle })
600
+ ]),
601
+ openCards[key] ? h("div", { className: "mp-card-body", style: cardBodyStyle }, children) : null
602
+ ]);
603
+
506
604
  const num = (field) => ({
507
605
  type: "text",
508
606
  inputMode: "numeric",
509
607
  value: draft[field],
510
608
  disabled,
511
- style: { ...inputStyle, borderColor: validation === field ? "var(--dsw-alias-label-error, #d54941)" : undefined },
609
+ style: { ...inputStyle, borderColor: validation === field ? "var(--dsw-alias-label-error, #d54941)" : "var(--dsw-alias-border-l2, #e5e7eb)" },
512
610
  onChange: (e) => edit(field, e.target.value)
513
611
  });
514
612
 
515
613
  return h("div", { className: "memory-palace-settings", style: sectionStyle }, [
516
614
  // 强制覆盖宿主 Webview 全局样式对原生 checkbox 尺寸的覆盖(内联 style 可能不敌全局 CSS)。
517
- h("style", null, ".memory-palace-settings input[type=checkbox]{width:18px!important;height:18px!important;margin:0;flex-shrink:0!important;cursor:pointer;}"),
615
+ h("style", null,
616
+ ".memory-palace-settings input[type=checkbox]{width:18px!important;height:18px!important;margin:0;flex-shrink:0!important;cursor:pointer;}" +
617
+ // v1.7.1(特性2):展开区首条元素自带 borderTop(row/toggle 共用该样式),会与
618
+ // .mp-card-body 的 border-top 叠成双线 → 去掉首条的边框与上内边距。
619
+ ".memory-palace-settings .mp-card-body > *:first-child{border-top:0!important;padding-top:0!important;}" +
620
+ ".memory-palace-settings .mp-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4b5bff);outline-offset:-2px;border-radius:16px;}"
621
+ ),
518
622
  h("div", { style: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px" } }, [
519
623
  h("div", null, [
520
624
  h("h3", { style: headingStyle }, t("title")),
@@ -526,8 +630,7 @@ window.__ModuleLoader__.load({
526
630
  ])
527
631
  ]),
528
632
  failed ? h("p", { style: errStyle }, t("saveFailed")) : null,
529
- h("div", { style: cardStyle }, [
530
- h("p", { style: groupTitleStyle }, t("core")),
633
+ card("core", t("core"), t("coreDesc"), [
531
634
  h("div", { style: toggleStyle }, [
532
635
  h("div", { style: { flexShrink: 1, minWidth: 0 } }, [
533
636
  h("p", { style: { ...labelStyle, margin: 0 } }, t("bridgeLabel")),
@@ -548,8 +651,27 @@ window.__ModuleLoader__.load({
548
651
  placeholder: ".workbuddy/memory, .codebuddy/memory"
549
652
  }), "buddyWorkspaceMemoryDirs")
550
653
  ]),
551
- h("div", { style: cardStyle }, [
552
- h("p", { style: groupTitleStyle }, t("smartSummary")),
654
+ // v1.7.1(特性3):自定义指令。非空时经 system prompt 追加到「记忆分工说明」之后;
655
+ // 它是恒定内容(用户配置一次不变),故放 section 而非 E 投影 —— 零缓存成本。
656
+ card("custom", t("custom"), t("customDesc"), [
657
+ row(t("customLabel"), t("customHint"),
658
+ h("textarea", {
659
+ value: draft.customInstructions,
660
+ disabled,
661
+ rows: 6,
662
+ placeholder: t("customPlaceholder"),
663
+ style: {
664
+ ...inputStyle,
665
+ height: "auto",
666
+ minHeight: "120px",
667
+ padding: "10px 12px",
668
+ lineHeight: "1.6",
669
+ resize: "vertical"
670
+ },
671
+ onChange: (e) => edit("customInstructions", e.target.value)
672
+ }), "customInstructions")
673
+ ]),
674
+ card("smartSummary", t("smartSummary"), t("smartSummaryDesc"), [
553
675
  // 轮次结束自动记录(summarize):三种记忆模式的共用总闸门,始终显示,置于记忆模式之上、不随模式切换隐藏。
554
676
  toggle(t("summarizeLabel"), t("summarizeHint"), "summarize"),
555
677
  row(t("memoryModeLabel"),
@@ -599,16 +721,14 @@ window.__ModuleLoader__.load({
599
721
  row(t("projectMaxTokensLabel"), t("projectMaxTokensHint"), h("input", num("projectMaxTokens")), "projectMaxTokens")
600
722
  ])
601
723
  ]),
602
- h("div", { style: cardStyle }, [
603
- h("p", { style: groupTitleStyle }, t("storage")),
724
+ card("storage", t("storage"), t("storageDesc"), [
604
725
  row(t("userPathLabel"), t("userPathHint"), h("input", { ...num("userMemoryPath"), type: "text" }), "userMemoryPath"),
605
726
  row(t("wsDirLabel"), t("wsDirHint"), h("input", { ...num("workspaceMemoryDir"), type: "text" }), "workspaceMemoryDir"),
606
727
  row(t("retentionLabel"), draft.memoryMode === "hybrid" ? t("retentionHintHybrid") : t("retentionHint"), h("input", num("dailyLogRetentionDays")), "dailyLogRetentionDays"),
607
728
  row(t("userBudgetLabel"), t("userBudgetHint"), h("input", num("userBudgetChars")), "userBudgetChars"),
608
729
  row(t("wsBudgetLabel"), t("wsBudgetHint"), h("input", num("workspaceBudgetChars")), "workspaceBudgetChars")
609
730
  ]),
610
- h("div", { style: cardStyle }, [
611
- h("p", { style: groupTitleStyle }, t("dev")),
731
+ card("dev", t("dev"), t("devDesc"), [
612
732
  row(t("distillTimeoutLabel"), t("distillTimeoutHint"), h("input", num("summaryTimeoutMs")), "summaryTimeoutMs"),
613
733
  toggle(t("distillDebugLogLabel"), t("distillDebugLogHint"), "distillDebugLog")
614
734
  ])
@@ -3,7 +3,7 @@
3
3
  import { mkdir, readdir, unlink, readFile, writeFile } from "node:fs/promises";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { join, dirname } from "node:path";
6
- import { todayISO, expandHome, readMdSync, toHomeShort, normLine, isStructural, stripSmartTag } from "./text.mjs";
6
+ import { todayISO, expandHome, normLine, isStructural, stripSmartTag } from "./text.mjs";
7
7
 
8
8
  // 追加一行记忆,若目标文件已包含相同内容则跳过(去重),返回是否实际写入。
9
9
  export async function appendLineDedup(file, line) {
@@ -237,30 +237,6 @@ export function createRecords({ getConfig, paths }) {
237
237
  }
238
238
  }
239
239
 
240
- // 读取目录里最近的(非今日)每日日志,拼成一段供 memory_read 展示(最多 3 份)。
241
- async function recentLogs(dir) {
242
- let files = [];
243
- try {
244
- files = await readdir(dir);
245
- } catch {
246
- return "";
247
- }
248
- const today = todayISO();
249
- const dated = files
250
- .map((f) => /^(\d{4}-\d{2}-\d{2})\.md$/.exec(f))
251
- .filter((m) => m && m[1] < today)
252
- .map((m) => m[1])
253
- .sort()
254
- .reverse()
255
- .slice(0, 3);
256
- const parts = [];
257
- for (const date of dated) {
258
- const text = readMdSync(join(dir, `${date}.md`));
259
- if (text) parts.push(`# 日志 ${date} @ ${toHomeShort(dir)}\n${text.slice(0, cfg().workspaceBudgetChars)}`);
260
- }
261
- return parts.join("\n\n");
262
- }
263
-
264
240
  // 轻量结构化条目(无 LLM):截断原始文本,错误带 [ERROR] 前缀。
265
241
  async function writeLightEntry(dirs, turn, isError) {
266
242
  const userText = turn.find((b) => b.role === "user")?.text ?? "";
@@ -289,5 +265,7 @@ export function createRecords({ getConfig, paths }) {
289
265
  }
290
266
  }
291
267
 
292
- return { appendDaily, prune, recentLogs, writeLightEntry, captureError };
268
+ // v1.7.1:recentLogs 已删除 —— memory_read 的 scope='daily' 改为按日期(isoDaysAgo)直读,
269
+ // 不再需要"最近 N 份文件"语义(跨日跳空会取偏)。
270
+ return { appendDaily, prune, writeLightEntry, captureError };
293
271
  }
@@ -14,6 +14,16 @@ export const todayISO = () => {
14
14
  return `${d.getFullYear()}-${m}-${day}`;
15
15
  };
16
16
 
17
+ // 本地日期偏移(0=今天,1=昨天,2=前天…),供 memory_read 按**日期**取日志
18
+ // (而不是"最近 N 份文件"——跨日跳空时会取偏)。同 todayISO 的教训:必须本地时间。
19
+ export const isoDaysAgo = (n = 0) => {
20
+ const d = new Date();
21
+ d.setDate(d.getDate() - n);
22
+ const m = String(d.getMonth() + 1).padStart(2, "0");
23
+ const day = String(d.getDate()).padStart(2, "0");
24
+ return `${d.getFullYear()}-${m}-${day}`;
25
+ };
26
+
17
27
  // 本地时间戳(YYYY-MM-DDTHH-mm-ss,`:` 换 `-` 兼容 Windows 文件名)。
18
28
  // 同 todayISO 的教训:必须用本地时间,不能用 toISOString()(UTC 会差 8 小时)。
19
29
  // 供项目记忆蒸馏备份文件名(MEMORY.md.{时间戳})使用。
@@ -232,7 +232,7 @@ export function registerHybridTools({ ctx, getConfig, paths, records, state }) {
232
232
  "(workspaceBudgetChars); (2) at least reorgCooldownDays (default 7) since the last reorganize. " +
233
233
  "If either gate fails the call is REJECTED — use memory_update_section instead. " +
234
234
  "Requirements for newContent: keep the full `## 章节` + `- 条目` format; NEVER lose still-valid key " +
235
- "information — read the daily logs (memory_read) and current MEMORY.md for cross-checking first; " +
235
+ "information — read the daily logs and current MEMORY.md for cross-checking first (memory_read with scope 'all'); " +
236
236
  "merge duplicates, drop only strikethrough/obsolete content; keep user-level MEMORY.md untouched " +
237
237
  "(user-level reorganization is FORBIDDEN). A last-reorg timestamp comment is appended automatically. " +
238
238
  "A user confirmation dialog is shown before execution.",
package/lib/index.js CHANGED
@@ -22,11 +22,10 @@
22
22
  // - src/index.mjs:最薄入口——apply() 装配 + 闭包运行时(session/event 跟踪、settle 时序、section 注入)
23
23
  // - src/client/(00-head…90-tail):浏览器 bundle 源码(build 时零依赖拼接为 lib/client.js 单文件,
24
24
  // 硬约束——dsh 客户端模块系统不支持插件相对 require)
25
- import { join } from "node:path";
26
25
  import Schema from "@deepseek-ai/schemastery";
27
26
  // v1.6.0-rc1:适配 DSH 0.1.2-alpha.2——dsh-settings 不再导出自由函数 installSettingsSection /
28
27
  // settingsNamespace,设置节注册改用 SettingsProvider 实例方法 installSection(经 ctx.inject(["settings"]))。
29
- import { todayISO, toHomeShort, readMdSync, budgetClip, stripSmartTag, stripDeletedLines, extractText, extractToolErrorText } from "./common/text.mjs";
28
+ import { extractText, extractToolErrorText } from "./common/text.mjs";
30
29
  import { SCENE_KEYWORDS } from "./common/prompts.mjs";
31
30
  import { createPaths } from "./common/paths.mjs";
32
31
  import { createRecords } from "./common/records.mjs";
@@ -61,7 +60,7 @@ export const Config = Schema.object({
61
60
  summaryTimeoutMs: Schema.number().default(60000).description("蒸馏 LLM 调用的超时(毫秒),超时视为失败并降级;覆盖智能模式摘要与手动蒸馏两条链路;默认 60000(60s)。"),
62
61
  distillDebugLog: Schema.boolean().default(false).description("调试开关:向 dsh 服务端 stderr 输出蒸馏 LLM 调用诊断。distillLogLevel=info 时仅输出元数据(模型解析/请求参数/流进度/错误详情,不含文本);distillLogLevel=debug 会额外打印 LLM 原始响应文本(分隔符包裹),仅限受信本地排障开启。"),
63
62
  // ---- v1.4.1:蒸馏 stderr 日志级别(平铺键,不进 UI;默认 info;distillDebugLog=true 时生效) ----
64
- distillLogLevel: Schema.string().default("info").description("蒸馏 stderr 日志级别:info=仅元数据诊断(默认,不打印 LLM 原始响应);debug=额外打印 LLM 原始响应文本(分隔符包裹),仅限受信本地排障开启。无需 UI 配置,经 profile/settings.yaml 设置 distillLogLevel 键。"),
63
+ distillLogLevel: Schema.string().default("info").description("蒸馏 stderr 日志级别:info=仅元数据诊断(默认,不打印 LLM 原始响应);debug=额外打印 LLM 原始响应文本(分隔符包裹),仅限受信本地排障开启。无需 UI 配置,经 DSH home($DSH_HOME)根目录的 settings.yaml 设置 distillLogLevel 键。"),
65
64
  // ---- v1.4.0:智能模式最终输出软预算(v1.4.1 起语义变更:prompt 软约束,思考不受限;实际硬上限由模型自身 maxTokens 决定) ----
66
65
  summaryMaxTokens: Schema.number().default(2000).description("会话摘要 LLM 的最终输出软预算(prompt 约束,思考不受限;实际硬上限由模型自身 maxTokens 决定)。默认 2000;可调大以容纳更多 durable 事实。"),
67
66
  projectMaxTokens: Schema.number().default(8000).description("手动「蒸馏项目记忆」LLM 的最终输出软预算(prompt 约束,思考不受限;实际硬上限由模型自身 maxTokens 决定)。默认 8000。"),
@@ -70,6 +69,9 @@ export const Config = Schema.object({
70
69
  // ---- v1.6.0:hybrid 模式配置(仅 memoryMode=hybrid 时生效) ----
71
70
  reorgCooldownDays: Schema.number().default(7).description("hybrid 模式:项目级 MEMORY.md 全量重整的冷却天数(距上次重整)。与「超出注入预算」双条件同时满足才允许 memory_reorganize;时间戳以 HTML 注释落在 MEMORY.md 文件尾。"),
72
71
  subagentLogBudget: Schema.number().default(20000).description("hybrid 模式:记忆子代理回喂今日工作日志的字符上限。超出时仅回喂章节目录,子代理用 log_read_section 按需读取章节。"),
72
+ // ---- v1.7.1(特性3):自定义指令(用户自写,经 system prompt 注入到「记忆分工 prompt」之后) ----
73
+ // 放 system 而非 E 投影:用户配置一次即恒定 → 零缓存成本(见下方 section 的分流原则)。
74
+ customInstructions: Schema.string().default("").description("自定义指令:非空时追加到系统提示词「记忆分工说明」之后,用于承载不适合写进用户记忆的特殊指令。对全部会话与三种记忆模式生效;留空则不注入。"),
73
75
  });
74
76
 
75
77
  export const inject = ["systemPrompt", "tools", "llm", "webServer", "webRuntime"];
@@ -139,7 +141,7 @@ export function apply(ctx, config) {
139
141
  const paths = createPaths(() => source(), () => state.activeCwd);
140
142
  const records = createRecords({ getConfig: () => source(), paths });
141
143
  const distill = createDistill({ ctx, getConfig: () => source(), paths, records, state });
142
- registerTools({ ctx, getConfig: () => source(), paths, records, state });
144
+ registerTools({ ctx, getConfig: () => source(), paths, state });
143
145
  registerApi({ ctx, paths, distill, state, getSettingsFace });
144
146
  // v1.6.0:hybrid 模式独立模块。必须【无条件注册】——apply() 同步段执行时 settings 服务
145
147
  // 尚未挂载(v1.6.0-rc1 起设置节经 SettingsProvider.installSection 在 ctx.inject(["settings"])
@@ -212,24 +214,18 @@ export function apply(ctx, config) {
212
214
  });
213
215
 
214
216
  // ---------- 读取:同步 section text(systemPrompt 要求同步) ----------
215
- // v1.7.0:section 只保留「常量指令(intro)+ 今日工作日志」。
216
- // 用户级 / 项目级 MEMORY.md 已移出 section,改由 E 投影(src/projection.mjs)承载为
217
- // 常驻消息(每个 step 可见)。分流依据是「变化频率」:MEMORY.md 低频 durable → 投影;
218
- // 今日日志高频易变 → 留 section 每步注入(不进历史以免膨胀)。
217
+ // v1.7.1:section **只保留恒定内容**(intro 指令 + 记忆分工说明 + planNote),
218
+ // 今日工作日志已迁入 E 投影(src/projection.mjs)。
219
+ // 分流依据是「内容是否恒定」:恒定 → 留 section(system prompt 在序列最前,内容恒定则
220
+ // 前缀缓存永久有效);易变 → 走 E 投影追加到历史尾部,且按文件身份只注一次。
221
+ // ⚠️ 切勿把任何「每步可能变化」的内容放回本 section —— 变一次就会让其后整段前缀作废。
222
+ // 实测代价:9 次全量重算、命中率从 99.26% 掉到 94.53%(见 testdata/session.v3.jsonl)。
219
223
  ctx.systemPrompt.section({
220
224
  name: "memory-palace",
221
225
  order: 50,
222
226
  text: () => {
223
227
  const cfg = source();
224
228
  if (!cfg.enabled) return "";
225
- const blocks = [];
226
- // 今日工作日志:每 step 注入,预算 workspaceBudgetChars(与项目 MEMORY.md 同字段,
227
- // 但各自独立 budgetClip 截断,互不挤占)。v1.4.1 的 budgetClip 已是"结构行 + 尾部最新"。
228
- for (const dir of paths.readDirs()) {
229
- const dirShort = toHomeShort(dir);
230
- const t = readMdSync(join(dir, `${todayISO()}.md`));
231
- if (t) blocks.push(`# 今日工作日志 (${todayISO()} @ ${dirShort})\n${stripSmartTag(stripDeletedLines(budgetClip(t, cfg.workspaceBudgetChars)))}`);
232
- }
233
229
  // v1.7.0:alreadyInjected / injectedSessionIds 已整体删除(记忆正文改走 E 投影)。
234
230
  // intro(含记忆公民指令)仍【始终】注入——若因记忆为空而整体返回空串,agent 将不知道
235
231
  // 记忆系统存在、不会主动记,形成「无记忆 → 无指令 → 永不记」死循环。
@@ -241,7 +237,7 @@ export function apply(ctx, config) {
241
237
  // v1.6.0:hybrid=记忆子代理自动维护日志 + agent 主动维护 MEMORY.md(见 HYBRID_PROACTIVE)。
242
238
  const proactive =
243
239
  source().memoryMode === "smart"
244
- ? "\n\n[记忆说明] 你的跨 session 记忆由 LLM 智能摘要自动维护(每轮结束自动提炼摘要并沉淀 durable 事实到 MEMORY.md),无需主动调用 memory_note / memory_note_user;读取全部记忆用 memory_read 工具(不要手动 glob/read 记忆文件)。"
240
+ ? "\n\n[记忆说明] 你的跨 session 记忆由 LLM 智能摘要自动维护(每轮结束自动提炼摘要并沉淀 durable 事实到 MEMORY.md),无需主动调用 memory_note / memory_note_user;读取记忆用 memory_read 工具,scope 默认 'memory',需要日志时显式传 scope(不要手动 glob/read 记忆文件)。"
245
241
  : source().memoryMode === "hybrid"
246
242
  ? HYBRID_PROACTIVE
247
243
  : "\n\n[记忆公民指令] 你拥有跨 session 的 Markdown 记忆。以下场景【必须】主动调用 memory_note(项目级约定)或 memory_note_user(跨项目个人偏好)落档,不要依赖轮次结束的自动兜底——它只做原始文本截断,无法代替你的高质量总结:\n" +
@@ -253,19 +249,25 @@ export function apply(ctx, config) {
253
249
  "判定标准:这条信息「下个 session 的我」还需要吗?不需要(闲聊、一次性操作、显而易见)就不记。格式:一句话结论开头 + 关键细节(命令/路径/数字),不写流水账。";
254
250
  const intro = bridged
255
251
  ? "你拥有持久化、人类可直接编辑的 Markdown 记忆文件。当前项目已存在 WorkBuddy/CodeBuddy 项目记忆目录,本插件直接读写这些目录(不再单独创建 .deepseek-harness/memory/)。" +
256
- "写入记忆:项目级约定用 memory_note 工具,跨项目个人偏好用 memory_note_user 工具;读取全部记忆用 memory_read 工具(不要手动 glob/read 记忆文件)。用它保持跨 session 一致性;看不到的内容不要编造。" +
252
+ "写入记忆:项目级约定用 memory_note 工具,跨项目个人偏好用 memory_note_user 工具;读取记忆用 memory_read 工具,scope 默认 'memory'(用户级 + 项目级 MEMORY.md),需要今日/历史日志时显式传 scope:'daily' 或 'all'(不要手动 glob/read 记忆文件)。用它保持跨 session 一致性;看不到的内容不要编造。" +
253
+ "注意:上下文中的记忆是**会话起始快照**,不随记忆文件之后的更新自动刷新;需要以当前状态为依据时(改记忆前、或据记忆作答前)用 memory_read 重读。" +
257
254
  antiMangle + proactive
258
255
  : "你拥有持久化、人类可直接编辑的 Markdown 记忆文件(位于 ~/.deepseek-harness/MEMORY.md,以及各项目的 .deepseek-harness/MEMORY.md(长期记忆)与 .deepseek-harness/memory/(每日日志))。" +
259
- "写入记忆:项目级约定用 memory_note 工具,跨项目个人偏好用 memory_note_user 工具;读取全部记忆用 memory_read 工具(不要手动 glob/read 记忆文件)。用它保持跨 session 一致性;看不到的内容不要编造。" +
256
+ "写入记忆:项目级约定用 memory_note 工具,跨项目个人偏好用 memory_note_user 工具;读取记忆用 memory_read 工具,scope 默认 'memory'(用户级 + 项目级 MEMORY.md),需要今日/历史日志时显式传 scope:'daily' 或 'all'(不要手动 glob/read 记忆文件)。用它保持跨 session 一致性;看不到的内容不要编造。" +
257
+ "注意:上下文中的记忆是**会话起始快照**,不随记忆文件之后的更新自动刷新;需要以当前状态为依据时(改记忆前、或据记忆作答前)用 memory_read 重读。" +
260
258
  antiMangle + proactive;
261
259
  // 计划模式禁写提示(硬编码默认行为,无开关):无论记忆模式都追加,让 agent 自觉不写(网关物理兜底仍生效)
262
260
  const planNote = state.planModeActive
263
261
  ? "\n\n[plan 模式] 当前处于 plan 模式,不要调用 memory_note / memory_note_user 写入记忆,也不要请求删除记忆(读取记忆用 memory_read,仍可用)。"
264
262
  : "";
265
263
  const introFull = intro + planNote;
266
- // v1.7.0:blocks 仅含今日日志(用户级/项目级 MEMORY.md 已移出,改由 E 投影注入)。
267
- // 返回值永非空串(只含 intro 时亦然),避免 harness 对空 section 的处理歧义。
268
- return blocks.length ? [introFull, ...blocks].join("\n\n") : introFull;
264
+ // v1.7.1(特性3):自定义指令追加在「记忆插件 prompt + 记忆分工 prompt」之后 ——
265
+ // 拼接顺序即 system prompt 里的实际排布(同一 section 内完成,order 不变)。
266
+ // 它由用户在设置页配置,内容恒定 → 放 system 零缓存成本,不违反本节的分流原则。
267
+ const custom = typeof cfg.customInstructions === "string" ? cfg.customInstructions.trim() : "";
268
+ // v1.7.1:本 section 已无任何动态块(日志迁出 E 投影),直接返回常量指令。
269
+ // 返回值仍非空串(即便自定义指令为空也含 intro),避免 harness 对空 section 的处理歧义。
270
+ return custom ? `${introFull}\n\n[用户自定义指令] ${custom}` : introFull;
269
271
  },
270
272
  });
271
273
 
@@ -1,28 +1,35 @@
1
- // memory-palace v1.7.0 特性1:E 投影 —— 记忆正文的独立注入通道。
1
+ // memory-palace E 投影 —— 记忆正文与今日日志的独立注入通道。
2
2
  //
3
3
  // 背景(v1.6.3 及以前):用户级 + 项目级 MEMORY.md 走 systemPrompt.section,受
4
4
  // 「仅首次注入」限制(`alreadyInjected` 打了标记就不撕,只有 compaction 清),
5
5
  // 导致记忆正文在 turn 1 的 step 2 之后就消失、全程不再进场。
6
6
  //
7
- // 现在:两份 MEMORY.md 改经 `agent/pre-step` 投影为**独立 user 消息**,常驻对话历史:
7
+ // 现在:记忆正文改经 `agent/pre-step` 投影为**独立 user 消息**,常驻对话历史:
8
8
  // - 每个 step 都可见(消息在历史里,不依赖注入时机);
9
- // - 内容未变只写一次(进历史后后续 step 的 decision.messages 已含它 → 去重命中);
10
- // - compaction 把消息移出 surface 后,后续 step 找不到 → 自动重注(白送)。
9
+ // - v1.7.1 起去重判据由「全文深比较」改为「**文件身份**」(首行 heading,含路径 + 日期):
10
+ // 同一文件只注一次,内容再变也不重注 —— 记忆正文由 agent 自己写入,其内容本就在
11
+ // 上下文(tool/call 参数)里,重注纯属冗余;换文件(跨日期日志)才视为新身份注入;
12
+ // - v1.7.1 起**今日工作日志由 systemPrompt.section 迁入本通道**。日志是 agent 唯一
13
+ // 「不知道自己缺」的内容(hybrid 子代理以独立 LLM stream 写入、不回注主对话),
14
+ // 必须注入;迁出后 section 只剩恒定指令 → system prompt 恒定 → 前缀缓存永久有效
15
+ // (此前日志在 section 里每步求值,一变就让序列最前的整段前缀作废)。
16
+ // - compaction 把消息移出 surface 后,身份判据即判为缺失 → 自动重注**磁盘最新版**,
17
+ // 顺带完成一次「刷新到最新」。
11
18
  //
12
19
  // 实现照抄宿主 `packages/context/agent-instructions/src/index.ts` 三件套(API 全公开、无第一方特权):
13
20
  // 1. `inject: ['sessionProjections']`(服务随 dsh-base 默认装载)
14
21
  // 2. `ctx.on('agent/pre-step', async ({agent, messages, step, signal}, next) => {...})`
15
22
  // 3. `createUserMessage()`(来自 @deepseek-ai/dsh-llm)
16
- // 投递方式:同步版——折叠进 `decision.messages`(`toSpliced(lastClaimedIndex + 1, 0, desired)`),
23
+ // 投递方式:同步版——折叠进 `decision.messages`(`toSpliced(lastClaimedIndex + 1, 0, ...pending)`),
17
24
  // 不做异步 inbox 刷新(agent-instructions 注释明写异步投影有两个 commit 边界的时序约束,
18
25
  // 本版刻意回避;记忆更新后下一步自然带上新内容)。
19
26
  //
20
27
  // 🔴 契约风险:pre-step 监听器抛错会让**整个 turn 失败**(宿主测试
21
28
  // packages/acp/acp/tests/turns.spec.ts:150-156 锚定),故钩子内整体 try-catch,
22
29
  // 任何异常降级为「本步不投影」并留一行 stderr 线索,绝不冒泡。详见 DEVELOPMENT.md §7.4。
23
- import { isDeepStrictEqual } from "node:util";
30
+ import { join } from "node:path";
24
31
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
25
- import { expandHome, toHomeShort, readMdSync, budgetClip, stripSmartTag, stripDeletedLines } from "./common/text.mjs";
32
+ import { expandHome, toHomeShort, todayISO, readMdSync, budgetClip, stripSmartTag, stripDeletedLines } from "./common/text.mjs";
26
33
 
27
34
  // 投影消息的 source 标注。
28
35
  // - kind: 'plugin' → 明确标注"插件注入",供下游按 source 过滤(子 agent 去噪 / turnBuffer 采集)。
@@ -34,20 +41,35 @@ const PROJECTION_SOURCE = Object.freeze({
34
41
  form: "instructions",
35
42
  });
36
43
 
37
- // 同一份内容是否已在这批消息里(逐字段深比较,照抄 agent-instructions 的 sameContextPayload)。
38
- function sameContextPayload(left, right) {
39
- return isDeepStrictEqual(left.content, right.content)
40
- && isDeepStrictEqual(left.source, right.source);
44
+ // v1.7.1 判据:投影身份 = 消息首行 heading(已编码目标文件路径 + 日期)。
45
+ // 只比身份、不比正文 —— 同一文件投影过一次后,内容再变也不重注。
46
+ function projectionIdentity(msg) {
47
+ const text = msg?.content?.[0]?.text ?? "";
48
+ const i = text.indexOf("\n");
49
+ return i === -1 ? text : text.slice(0, i);
41
50
  }
42
51
 
43
- // 扫描当前 surface,判断该 payload 是否已经作为本插件消息存在于会话历史中。
44
- // 存在 → 不重复注入("内容不变只写一次"靠它实现)。
52
+ // 只在双方都是本插件投影时才比身份 —— 规避真实用户消息与宿主注入消息
53
+ // (runtime context / skill 目录等)因首行文本巧合而误撞。
54
+ function isOwnProjection(msg) {
55
+ return msg?.source?.kind === "plugin" && msg?.source?.plugin === "dsh-memory-palace";
56
+ }
57
+
58
+ function sameProjectionIdentity(left, right) {
59
+ return isOwnProjection(left) && isOwnProjection(right)
60
+ && projectionIdentity(left) === projectionIdentity(right);
61
+ }
62
+
63
+ // 扫描当前 surface,判断该身份是否已经作为本插件消息存在于会话历史中。
64
+ // 存在 → 不重复注入("同一文件只注一次"靠它实现)。
65
+ // compaction 把消息移出 surface 后即判为缺失 → 自动重注磁盘最新版
66
+ // (身份不变、正文刷新,故无需 injectedSessionIds 之类的标记机制)。
45
67
  function alreadyOnSurface(session, desired) {
46
68
  const nodes = session?.surface?.nodes;
47
69
  if (!Array.isArray(nodes)) return false;
48
70
  for (const seq of nodes) {
49
71
  const event = typeof session.eventAt === "function" ? session.eventAt(seq) : undefined;
50
- if (event?.type === "user/message" && sameContextPayload(event.data, desired)) return true;
72
+ if (event?.type === "user/message" && sameProjectionIdentity(event.data, desired)) return true;
51
73
  }
52
74
  return false;
53
75
  }
@@ -62,10 +84,10 @@ function buildProjection(text, heading) {
62
84
  }
63
85
 
64
86
  /**
65
- * 收集本步要投影的记忆消息(用户级 + 项目级,各自独立一条)。
66
- * 两者拆成两条独立消息(v1.7.0 定案):否则"项目记忆一改,用户记忆连带重发"。
87
+ * 收集本步要投影的消息(用户级 / 项目级 MEMORY.md / 今日工作日志,各自独立一条)。
88
+ * 拆成多条独立消息(v1.7.0 定案,v1.7.1 扩展):否则"某一条内容一改,其余连带重发"。
67
89
  * @param {{ getConfig: () => object, paths: object }} deps
68
- * @returns {object[]} 按 [用户级, 项目级…] 顺序的消息数组(可能为空)
90
+ * @returns {object[]} 按 [用户级, 项目级…, 今日日志…] 顺序的消息数组(可能为空)
69
91
  */
70
92
  export function buildProjections({ getConfig, paths }) {
71
93
  const cfg = getConfig();
@@ -92,6 +114,16 @@ export function buildProjections({ getConfig, paths }) {
92
114
  if (msg) out.push(msg);
93
115
  }
94
116
  }
117
+ // 今日工作日志(v1.7.1 由 systemPrompt.section 迁入)。heading 沿用原 section 格式,
118
+ // 天然含日期与目录 → 跨天 / 换目录自动成为新身份。预算沿用 workspaceBudgetChars,
119
+ // 与项目级 MEMORY.md 各自独立 budgetClip,互不挤占。
120
+ for (const dir of paths.readDirs()) {
121
+ const text = readMdSync(join(dir, `${todayISO()}.md`));
122
+ if (!text) continue;
123
+ const clipped = stripSmartTag(stripDeletedLines(budgetClip(text, cfg.workspaceBudgetChars)));
124
+ const msg = buildProjection(clipped, `# 今日工作日志 (${todayISO()} @ ${toHomeShort(dir)})`);
125
+ if (msg) out.push(msg);
126
+ }
95
127
  return out;
96
128
  }
97
129
 
@@ -109,10 +141,10 @@ export function registerProjection({ ctx, getConfig, paths }) {
109
141
  const session = agent?.session;
110
142
  const desired = buildProjections({ getConfig, paths });
111
143
  if (!desired.length) return decision;
112
- // 逐条去重:已被本步的 messages 覆盖、或已在 surface 上的,跳过。
144
+ // 逐条去重(按**文件身份**、非内容):已被本步 messages 覆盖、或已在 surface 上的,跳过。
113
145
  const pending = desired.filter((msg) =>
114
- !messages.some((m) => sameContextPayload(m, msg))
115
- && !decision.messages.some((m) => sameContextPayload(m, msg))
146
+ !messages.some((m) => sameProjectionIdentity(m, msg))
147
+ && !decision.messages.some((m) => sameProjectionIdentity(m, msg))
116
148
  && !alreadyOnSurface(session, msg));
117
149
  if (!pending.length) return decision;
118
150
  // 折叠位置:紧跟在"本步被认领的消息"之后,使直接提示在前、驱动追加的 runtime context 在后。
package/lib/tools.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  // memory-palace 记忆工具:memory_note / memory_note_user / memory_read / memory_delete
2
2
  // + 删除硬确认闸门(tools/pre-execute → harness 原生确认弹窗)。
3
- // 经 registerTools 注入 ctx/config/paths/records/运行时状态;在 index.mjs 装配时调用一次。
3
+ // 经 registerTools 注入 ctx/config/paths/运行时状态;在 index.mjs 装配时调用一次。
4
4
  import { defineTool } from "@deepseek-ai/dsh-tools";
5
5
  import { join } from "node:path";
6
- import { todayISO, expandHome, toHomeShort, readMdSync } from "./common/text.mjs";
6
+ import { todayISO, isoDaysAgo, expandHome, toHomeShort, readMdSync, budgetClip } from "./common/text.mjs";
7
7
  import { appendLineDedup, findMatches, removeLineByMatch, recentLogDates } from "./common/records.mjs";
8
8
 
9
9
  /**
10
- * @param {{ ctx: object, getConfig: () => object, paths: object, records: object, state: object }} deps
10
+ * @param {{ ctx: object, getConfig: () => object, paths: object, state: object }} deps
11
11
  */
12
- export function registerTools({ ctx, getConfig, paths, records, state }) {
12
+ export function registerTools({ ctx, getConfig, paths, state }) {
13
13
  const cfg = () => getConfig();
14
14
 
15
15
  // 删除作用域的中文标签。
@@ -162,18 +162,34 @@ export function registerTools({ ctx, getConfig, paths, records, state }) {
162
162
  }),
163
163
  );
164
164
 
165
- // ---------- 可选工具:读取全部记忆(用户级 + 项目级 MEMORY.md 与每日日志) ----------
166
- // AI 说"读取项目记忆/看看记忆"时直接调用,返回聚合内容,避免 AI 自己翻文件、只找 MEMORY.md 而漏掉每日日志。
165
+ // ---------- 可选工具:读取记忆(scope 控制范围,默认只读 durable 长期记忆) ----------
166
+ // AI 说"读取项目记忆/看看记忆"时直接调用,返回聚合内容,避免 AI 自己翻文件、只找 MEMORY.md 而漏掉项目级记忆。
167
+ // v1.7.1:加 scope(memory 默认 / project / today / yesterday / daily / all)—— 当日日志实测
168
+ // 可达 1.7 万字符,默认值刻意不含它;确实需要日志时必须显式传 scope。
169
+ // project 原名 node —— 为与 memory_write / memory_update_section 的 scope='project' 统一而更名,消除读写两侧命名歧义。
167
170
  ctx.tools.register(
168
171
  defineTool({
169
172
  name: "memory_read",
170
173
  description:
171
- "Read all persistent memory: user-level MEMORY.md (cross-project preferences), " +
172
- "and for the current project the workspace MEMORY.md plus recent daily logs " +
173
- "(YYYY-MM-DD.md) from .workbuddy/memory, .codebuddy/memory, or .deepseek-harness/memory. " +
174
- "Use this instead of manually globbing/reading memory files — it aggregates everything. " +
175
- "This tool takes no parameters; call it with an empty object, e.g. tools.memory_read({}) — the runtime rejects undefined arguments.",
176
- parameters: {},
174
+ "Read persistent memory. scope defaults to 'memory' and decides what comes back: " +
175
+ "'memory' (default) = user-level MEMORY.md (cross-project preferences) + this project's workspace MEMORY.md; " +
176
+ "'project' = this project's workspace MEMORY.md only (same naming as the write-side scope of memory_write / memory_update_section); " +
177
+ "'today' / 'yesterday' = that single day's daily log; " +
178
+ "'daily' = the last three days of logs (today + yesterday + the day before); " +
179
+ "'all' = memory + daily (large — only when the logs are genuinely needed). " +
180
+ "Start from the default scope and widen it only when the question is really about logs. " +
181
+ "Use this instead of manually globbing/reading memory files. " +
182
+ "Call it as tools.memory_read({}) or tools.memory_read({ scope: 'daily' }) — the runtime rejects undefined arguments.",
183
+ parameters: {
184
+ scope: {
185
+ type: "string",
186
+ enum: ["memory", "project", "today", "yesterday", "daily", "all"],
187
+ description:
188
+ "What to read. 'memory' (default) = user-level + workspace MEMORY.md (durable long-term memory; usually all you need). " +
189
+ "'project' = workspace MEMORY.md only (same value as the write-side scope of memory_write). 'today' / 'yesterday' = that single day's log. " +
190
+ "'daily' = last three days of logs. 'all' = memory + daily.",
191
+ },
192
+ },
177
193
  output: {
178
194
  schema: {
179
195
  type: "object",
@@ -186,28 +202,50 @@ export function registerTools({ ctx, getConfig, paths, records, state }) {
186
202
  },
187
203
  render: (_args, value) => [{ type: "text", text: value?.memory ?? value?.message ?? "No memory." }],
188
204
  },
189
- async execute() {
205
+ async execute(args = {}) {
190
206
  const c = cfg();
191
207
  if (!c.enabled) return { ok: false, message: "memory-palace is currently disabled in settings.", memory: "" };
208
+ // v1.7.1:默认 scope='memory'(长期记忆)。刻意不设 'all' —— 默认全量会让 agent
209
+ // 不加思考地把日志(实测单日可达 1.7 万字符)一起吞下,白白吃掉上下文。
210
+ const scope = args?.scope ?? "memory";
211
+ const wantUser = scope === "memory" || scope === "all";
212
+ const wantProject = scope === "memory" || scope === "project" || scope === "all";
213
+ // 日志按**日期**取(而非"最近 N 份文件"——跨日跳空会取偏):today / yesterday / daily(近三天) / all
214
+ const logDays =
215
+ scope === "today" ? [0]
216
+ : scope === "yesterday" ? [1]
217
+ : scope === "daily" || scope === "all" ? [0, 1, 2]
218
+ : [];
192
219
  try {
193
220
  const blocks = [];
194
- const userFile = expandHome(c.userMemoryPath);
195
- const userFileShort = toHomeShort(userFile);
196
- const u = readMdSync(userFile);
197
- if (u) blocks.push(`# 用户级记忆 (${userFileShort})\n${u}`);
221
+ if (wantUser) {
222
+ const userFile = expandHome(c.userMemoryPath);
223
+ const u = readMdSync(userFile);
224
+ if (u) blocks.push(`# 用户级记忆 (${toHomeShort(userFile)})\n${u}`);
225
+ }
198
226
  for (const dir of paths.readDirs()) {
199
227
  const dirShort = toHomeShort(dir);
200
- const w = paths.memoryReadCandidates(dir).map(readMdSync).filter(Boolean).join("\n\n");
201
- if (w) blocks.push(`# 工作区记忆 (${dirShort})\n${w}`);
202
- const t = readMdSync(join(dir, `${todayISO()}.md`));
203
- if (t) blocks.push(`# 今日工作日志 (${todayISO()} @ ${dirShort})\n${t}`);
204
- const recent = await records.recentLogs(dir);
205
- if (recent) blocks.push(recent);
228
+ if (wantProject) {
229
+ // 标题必须用实际读到的 MEMORY.md 路径,而非日志目录 —— dsh 布局下 MEMORY.md 位于
230
+ // 日志目录的上一级,旧实现拿 dir(.../memory)当标题会误导真实路径(buddy 布局
231
+ // MEMORY.md 恰在 memory/ 内所以未暴露)。与 E 投影的 per-file 粒度对齐。
232
+ for (const f of paths.memoryReadCandidates(dir)) {
233
+ const t = readMdSync(f);
234
+ if (t) blocks.push(`# 工作区记忆 (${toHomeShort(f)})\n${t}`);
235
+ }
236
+ }
237
+ for (const n of logDays) {
238
+ const day = isoDaysAgo(n);
239
+ const t = readMdSync(join(dir, `${day}.md`));
240
+ if (!t) continue;
241
+ const label = n === 0 ? "今日" : n === 1 ? "昨日" : "前日";
242
+ blocks.push(`# ${label}工作日志 (${day} @ ${dirShort})\n${budgetClip(t, c.workspaceBudgetChars)}`);
243
+ }
206
244
  }
207
245
  if (!blocks.length) {
208
- return { ok: true, message: "No memory files found yet.", memory: "" };
246
+ return { ok: true, message: `No memory files found (scope=${scope}).`, memory: "" };
209
247
  }
210
- return { ok: true, message: "Memory loaded.", memory: blocks.join("\n\n") };
248
+ return { ok: true, message: `Memory loaded (scope=${scope}).`, memory: blocks.join("\n\n") };
211
249
  } catch (e) {
212
250
  return { ok: false, message: `Failed: ${e}`, memory: "" };
213
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memory-palace",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "把 WorkBuddy 的文件式记忆系统移植进 DeepSeek Harness:用户级 + 工作区的人类可读 Markdown 记忆(~/.deepseek-harness/MEMORY.md 与 <cwd>/.deepseek-harness/memory/)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",