@trans-ai/trans-code 0.8.2 → 0.10.0
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 +20 -2
- package/docs/superpowers/plans/2026-11-21-auto-compact.md +84 -0
- package/docs/superpowers/plans/2026-11-21-compact-speed.md +85 -0
- package/docs/superpowers/plans/2026-11-22-user-memory.md +243 -0
- package/docs/superpowers/plans/2026-11-22-web-tools.md +192 -0
- package/docs/superpowers/specs/2026-11-21-auto-compact-design.md +25 -0
- package/docs/superpowers/specs/2026-11-21-compact-speed-design.md +21 -0
- package/docs/superpowers/specs/2026-11-22-user-memory-design.md +48 -0
- package/docs/superpowers/specs/2026-11-22-web-tools-design.md +48 -0
- package/package.json +1 -1
- package/src/acp/server.ts +6 -0
- package/src/agent/loop.ts +5 -1
- package/src/agent/memory.test.ts +169 -0
- package/src/agent/memory.ts +207 -0
- package/src/agent/system-prompt.test.ts +87 -1
- package/src/agent/system-prompt.ts +23 -1
- package/src/agent/tools/index.ts +7 -0
- package/src/agent/tools/memory.test.ts +88 -0
- package/src/agent/tools/memory.ts +61 -0
- package/src/agent/tools/types.ts +2 -0
- package/src/agent/tools/web-fetch.test.ts +186 -0
- package/src/agent/tools/web-fetch.ts +137 -0
- package/src/agent/tools/web-search.test.ts +100 -0
- package/src/agent/tools/web-search.ts +41 -0
- package/src/commands.test.ts +104 -1
- package/src/commands.ts +101 -0
- package/src/config.test.ts +25 -0
- package/src/config.ts +52 -0
- package/src/provider/web-search.test.ts +195 -0
- package/src/provider/web-search.ts +143 -0
- package/src/screens/REPL.tsx +222 -24
- package/src/screens/search-setup.test.ts +89 -0
- package/src/screens/search-setup.ts +57 -0
- package/src/screens/submit.test.ts +8 -0
- package/src/screens/submit.ts +1 -1
- package/src/sessions/compact.test.ts +90 -25
- package/src/sessions/compact.ts +41 -9
- package/src/version.ts +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# 自动压缩(每轮提交前阈值检查)— 设计
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
对齐 Claude Code 的 proactive autocompact:会话进行中每轮提交前检查上下文占用,超阈值自动压缩,避免长会话撞上下文上限。与恢复压缩、`/compact` 三路归一(同一个 `runCompaction`)。
|
|
6
|
+
|
|
7
|
+
## 设计(参考 claudecode/src/services/compact/autoCompact.ts)
|
|
8
|
+
|
|
9
|
+
- **检查点**:每次提交聊天消息时(`handleSubmit` 在进入 agent loop 之前),估算 `messagesRef` 总量,超阈值先压缩再继续本轮
|
|
10
|
+
- **估算**:纯函数 `estimateTokens(messages) = 全部消息文本长度 / 4`(CC 同款粗估,chars≈4/token)
|
|
11
|
+
- **阈值**:`autoCompact.thresholdChars`(默认 **200_000** 字符 ≈ 50k token —— 多厂商无窗口注册表,取保守值;128k 窗口模型够用,32k 模型也不会先撞墙),命中即压缩
|
|
12
|
+
- **配置**:`~/.transcode.json` 的 `autoCompact?: { enabled?: boolean; thresholdChars?: number }`,`normalizeAutoCompact` 容错(仿 `normalizeAutoUpdate`:坏配置回落默认,**默认开启**)
|
|
13
|
+
- **压缩参数**:keepTurns 用 `DEFAULT_KEEP_TURNS`(=1,与两入口一致的「一套逻辑」);失败回退语义不变
|
|
14
|
+
- **熔断器**:`useRef` 记连续失败次数,**连续 3 次停止自动压缩**(CC 同款,真实事故换来的),成功即复位;自动失败提示仅首次显示,后续静默(CC:自动失败不打扰)
|
|
15
|
+
- **显示**:压缩前先落一条空宿主条目,流式摘要照常打进聊天区,完成后 `transcriptEntries` 渲染窗口(与 /compact 同款)
|
|
16
|
+
- **跳过**:无进行中会话(首轮)、`TRANSCODE_MOCK=1`、已 busy、压缩中重入
|
|
17
|
+
|
|
18
|
+
## 非目标
|
|
19
|
+
|
|
20
|
+
- 不做 per-model 上下文窗口注册表、microcompact(工具结果修剪)、reactive(PTL 错误后被动压缩)、阻塞上限/警告分层 —— 有 per-model 窗口数据后再上
|
|
21
|
+
|
|
22
|
+
## 备选(已否)
|
|
23
|
+
|
|
24
|
+
- 默认关闭待配置:用户点明参考 CC(CC 默认开启)— 默认开
|
|
25
|
+
- 按轮数触发(如每 20 轮):轮长差异大,token 估算更贴近 CC 语义
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 压缩提速(流式 + 快速模型路由 + 硬上限)— 设计
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
压缩慢的两个根源:阻塞式 `invoke()` 全程无反馈(感知慢)、用当前推理模型烧思考 token(真慢)。对齐 Claude Code 的做法:流式展示、可路由快速模型、输出硬上限。
|
|
6
|
+
|
|
7
|
+
## 设计
|
|
8
|
+
|
|
9
|
+
- **流式**:`CompactModel` 接口从 `{ invoke }` 改为 `{ stream(input): AsyncIterable<{content}> }`;`compressSession(record, model, keepTurns, onDelta?)` 逐块累积摘要,`onDelta(块文本)` 回调供 REPL 实时打进聊天区(先显示「正在提炼前情提要…」再流式输出)。流中抛错/空结果 → 原有失败回退语义不变
|
|
10
|
+
- **字符硬上限**:`COMPACT_MAX_SUMMARY_CHARS = 1200`,累积超限即停止消费流(provider 无关的输出钳制,替代依赖各厂商 maxTokens 参数)
|
|
11
|
+
- **快速模型路由**:压缩调用用 `createModel(getRouting()['compact'] ?? 当前模型)` —— 在 `~/.transcode.json` 的 `routing` 里配 `"compact": "<快速模型>"`(如 glm-4.6-air / deepseek-chat)即可换快模型;未配置则维持当前模型(流式 + 上限仍生效)
|
|
12
|
+
- 测试:mock 改为 async generator;新增流式累积、超限截断、流中报错、onDelta 传递用例
|
|
13
|
+
|
|
14
|
+
## 非目标
|
|
15
|
+
|
|
16
|
+
- 不做 prompt-cache 复用(单请求形态不同)、不做增量边界总结(数据模型不同)、不引入 <summary> 八段式(后续可单独迭代)
|
|
17
|
+
|
|
18
|
+
## 备选(已否)
|
|
19
|
+
|
|
20
|
+
- per-call maxTokens 参数:LangChain 跨厂商 bind 参数行为不一,字符上限更可靠
|
|
21
|
+
- 默认硬编码快速模型:用户 key/厂商各异,routing 显式配置更诚实
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# 用户记忆系统(全局指令 + 自动记忆)— 设计
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
让 transcode 跨会话、跨项目记住用户偏好与纠正。项目级记忆(TRANS.md/AGENTS.md 注入)已有;本设计补齐用户级:全局指令文件、agent 自主写入的自动记忆、REPL 查看入口。对 ACP 定位尤其重要——transonce/multica 反复拉起 transcode,每次会话都能带上积累的偏好,而不是每次白纸。
|
|
6
|
+
|
|
7
|
+
## 设计(参考 claudecode/docs/context/project-memory.mdx 与 CC auto-memory)
|
|
8
|
+
|
|
9
|
+
**存储**(根目录默认 `~/.transcode/`,与 sessions 同级;整体可用 `TRANSCODE_USER_DIR` 覆盖——`TRANS.md` 与 `memory/` 一起切到测试根,仿 `sessionsDir()` 的 env 注入,保证测试不碰真实用户数据):
|
|
10
|
+
|
|
11
|
+
- `~/.transcode/TRANS.md` — 全局指令,用户手写(相当于 `~/.claude/CLAUDE.md`:"我所有项目都用 bun、commit 用中文")
|
|
12
|
+
- `~/.transcode/memory/MEMORY.md` — 索引,每条一行:`- [标题](文件.md) — 一句话钩子`
|
|
13
|
+
- `~/.transcode/memory/<slug>.md` — 一条事实一个文件:frontmatter(`name` / `description` / `type`)+ 正文。type 取值:`user`(用户是谁、偏好) | `feedback`(对 AI 行为的纠正) | `project`(跨会话项目约束) | `reference`(外部资源指针)。frontmatter 行级解析这三键,不引 yaml 依赖
|
|
14
|
+
|
|
15
|
+
**注入**(改 `system-prompt.ts`;REPL 与 ACP 两入口自动生效):
|
|
16
|
+
|
|
17
|
+
- 新增 `loadUserMemory()`:读全局指令 + 索引 + 全部记忆文件,合计预算 **12k 字符**。超预算策略:TRANS.md 超长按现有项目文件方式截断;记忆条目**整条丢弃、不腰斩**(半条指令比省略更危险),按 type 优先级 `user > feedback > project > reference` 先丢最低,注入末尾注明被省略的条目名(记忆本就该小)
|
|
18
|
+
- `buildSystemPrompt` 新增 `## User memory` 段,位于 Project instructions 之前:全局指令原文 + 记忆索引 + 各条内容
|
|
19
|
+
- "How to work" 增一条:用户纠正行为或表达持久偏好时,用 `memory_save` 记下;引用可能过期的记忆前先验证(文件还在?函数还存在?)
|
|
20
|
+
|
|
21
|
+
**工具**(注册进 `AGENT_TOOLS`,ACP 与子 agent 同享):
|
|
22
|
+
|
|
23
|
+
- `memory_save { name, type, content, description? }` — 新建/覆盖一条记忆并同步 MEMORY.md 索引;`description`(frontmatter + 索引钩子)可选,缺省取 content 首行截 60 字符,不为它多打一次模型调用;description 里写明**不该存什么**(代码结构、git 历史、临时任务状态、TRANS.md 已有内容),让模型自筛(CC 同款清单)
|
|
24
|
+
- `memory_delete { name }` — 删条目并同步索引
|
|
25
|
+
- 均 `isMutating: true`,沿用现有两道门禁:plan 模式(`loop.ts` 的 `planMode` 只读探索)与 `readonly` 权限模式都会拒绝 mutating 工具,无需新增模式
|
|
26
|
+
|
|
27
|
+
**命令**(REPL 兜底,本地直写、不经模型):
|
|
28
|
+
|
|
29
|
+
- `/memory` — 列索引 + 存储路径 + 手动编辑提示
|
|
30
|
+
- `/remember <text>` — 快速存一条 `type=user` 记忆(name 自动 slug,冲突加序号)
|
|
31
|
+
- `/forget <name>` — 删除
|
|
32
|
+
|
|
33
|
+
**刷新**:无需失效机制——REPL(`REPL.tsx:409`)与 ACP(`acp/session.ts:125`)每次提交都重建 system prompt,记忆变更下一轮即生效。
|
|
34
|
+
|
|
35
|
+
**测试**:memory 存取纯函数(增删、索引同步、预算截断、坏 frontmatter 容错);两工具 schema/execute;system-prompt 注入格式。新文件:`src/agent/memory.ts` + `src/agent/tools/memory.ts`(工具),命令进 `commands.ts`。
|
|
36
|
+
|
|
37
|
+
## 非目标
|
|
38
|
+
|
|
39
|
+
- @import 语法、子目录嵌套 AGENTS.md(方案 C 内容)
|
|
40
|
+
- 相关性召回/向量检索(条数少,预算内全量注入;条数膨胀后再上)
|
|
41
|
+
- 记忆过期自动清理、跨设备同步
|
|
42
|
+
|
|
43
|
+
## 备选(已否)
|
|
44
|
+
|
|
45
|
+
- 只加全局指令文件(方案 A):agent 不会自己积累,每次仍白纸
|
|
46
|
+
- 只注入索引 + 按需读取工具:省 token 但多一套召回机制,MVP 不值
|
|
47
|
+
- 单一 memory 工具带 action 字段:与仓库粒度工具风格(files/search 等均拆分)不一致
|
|
48
|
+
- `/remember` 走完整 agent loop(仿 /init):慢且不确定,本地直写即可
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Web 工具(WebFetch + WebSearch)— 设计
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
给 agent 补上联网能力:抓网页(WebFetch)与搜网(WebSearch)。多模型架构下必须厂商无关——搜索不走任何模型提供商的服务端工具,transcode 只提供实现,搜索商与 key 由用户自己配置,配好全局生效。对齐 CCB 的 WebFetch/WebSearch 能力面,但不搬其 Anthropic 专属实现。
|
|
6
|
+
|
|
7
|
+
## 设计
|
|
8
|
+
|
|
9
|
+
### WebFetch(零配置,开箱即用)
|
|
10
|
+
|
|
11
|
+
- **工具 `web_fetch { url, prompt? }`**:原生 `fetch`(Bun 内建,零新依赖),跟随重定向,15s 超时(AbortSignal.timeout)
|
|
12
|
+
- **User-Agent**:诚实 bot 惯例 `Mozilla/5.0 (compatible; transcode/<version>)`,不伪装浏览器;被站点 403 时错误如实返回模型
|
|
13
|
+
- **字符集**:收字节(arrayBuffer)后按 Content-Type 头 / meta 标签嗅探 charset,`TextDecoder` 解码(gbk/gb2312 官方构建均支持),兜底 UTF-8——中文页面不乱码
|
|
14
|
+
- **代理**:全局安装路径(bun shebang)的 fetch 原生认 HTTP(S)_PROXY,零代码;Node dist 自建路径 v1 不做显式代理(不引 undici),README 注明
|
|
15
|
+
- **响应处理**:大小上限 512KB(超限截断);HTML 走零依赖文本提取——剥 `script`/`style`/`head` 噪声,标签转文本,空行折叠;text/plain、application/json 原样(截断);其余二进制类型返回内容类型与大小提示
|
|
16
|
+
- **输出**:页面标题 + 提取文本,字符上限 20k(超限截断并注明);`prompt` 参数仅原样附在输出前作阅读指引,不做小模型二次加工(CCB 用 Haiku 转写,多花一次调用,v1 不值)
|
|
17
|
+
- **权限**:`kind: 'fetch'`、`isMutating: false` —— readonly 与 plan 模式放行(对工作区只读)
|
|
18
|
+
|
|
19
|
+
### WebSearch(用户配置,全局生效)
|
|
20
|
+
|
|
21
|
+
- **配置**:`~/.transcode.json` 新增 `webSearch: { provider: 'tavily' | 'brave', apiKey: string }`。**无环境变量口子,不内置任何 key**;`loadConfig()` 每次现读,改完下一轮生效(REPL/ACP 全局)。两条配置路径:
|
|
22
|
+
- **手改 JSON**(power-user 兜底):直接编辑 `webSearch` 段
|
|
23
|
+
- **REPL 交互 `/search`**:仿 `/models` 三级流程由 REPL 拦截——选搜索商(tavily/brave)→ 输 key(已存的可回车沿用)→ **发一条真实测试查询验证**(显示命中条数与首条标题,失败亮 API 原始报错可重输)→ `saveConfig` 写入 `webSearch` 段
|
|
24
|
+
- **适配器**:每家一个纯函数适配器,统一出入参 `{ query, maxResults } → { title, url, snippet }[]`
|
|
25
|
+
- Tavily:`POST https://api.tavily.com/search`(`{ api_key, query, max_results }`)
|
|
26
|
+
- Brave:`GET https://api.search.brave.com/res/v1/web/search`(头 `X-Subscription-Token`,参数 `q`/`count`)
|
|
27
|
+
- 未知 provider / 缺 apiKey / 请求失败 → 返回可读错误文案
|
|
28
|
+
- **工具 `web_search { query, maxResults? }`**(默认 5 条):输出 `title — url\nsnippet` 列表;`kind: 'fetch'`、`isMutating: false`
|
|
29
|
+
- **未配置时模型不可见**:工具列表在 `loop.ts:315` 每轮组装,按配置过滤——`webSearch` 段无效时 `web_search` 不进本轮工具表(模型不会浪费轮次撞错误),`web_fetch` 恒可用
|
|
30
|
+
- **坏配置感知**:`webSearch` 段**存在但无效**(provider 拼错 / key 空)→ REPL 启动打一行警告并提示 `/search`,ACP 侧 stderr 提示一次;**完全未配置** → 全程静默
|
|
31
|
+
|
|
32
|
+
### 注册与共享
|
|
33
|
+
|
|
34
|
+
两工具经 `dispatchPool` 进 `AGENT_TOOLS`,ACP 与子 agent 同享(与 memory 工具同路径)。
|
|
35
|
+
|
|
36
|
+
## 非目标
|
|
37
|
+
|
|
38
|
+
- 域名安全预检/企业出口代理(CC 的 claude.ai 预检那套)、LRU 缓存、小模型页面转写
|
|
39
|
+
- Node dist 路径的显式代理支持(undici ProxyAgent 依赖)——bun 路径原生认环境代理已覆盖全局安装
|
|
40
|
+
- 搜索商生态扩张(先 Tavily + Brave 两家,适配器接口留口)
|
|
41
|
+
- 流式抓取、图片/二进制内容的多模态回传
|
|
42
|
+
|
|
43
|
+
## 备选(已否)
|
|
44
|
+
|
|
45
|
+
- **Anthropic 服务端 `web_search` 工具(CCB 同款)**:只对 anthropic kind 生效,GLM/DeepSeek 主力网关全用不上 — 已否
|
|
46
|
+
- **DuckDuckGo HTML 抓取**:免 key 但脆弱且 ToS 灰色,不做默认路径
|
|
47
|
+
- **本周期只发 WebFetch**:搜索是"查最新文档"场景的另一半,适配器成本低,一起做
|
|
48
|
+
- **环境变量配 key**:用户明确不要——配置只走 `~/.transcode.json`,单一事实源
|
package/package.json
CHANGED
package/src/acp/server.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import { RPC_ERRORS, RpcError, JsonRpcTransport } from './transport.js';
|
|
3
3
|
import { AcpSession, sessionCwd, sessionNewResult, type AcpSessionHost } from './session.js';
|
|
4
|
+
import { loadConfig } from '../config.js';
|
|
5
|
+
import { webSearchConfigWarning } from '../provider/web-search.js';
|
|
4
6
|
import { VERSION } from '../version.js';
|
|
5
7
|
import type {
|
|
6
8
|
AcpPermissionRequest,
|
|
@@ -166,6 +168,10 @@ export class AcpServer implements AcpSessionHost {
|
|
|
166
168
|
process.stderr.write(
|
|
167
169
|
`[transcode] session ${session.id} created cwd=${cwd} model=${session.modelState.currentModelId}\n`,
|
|
168
170
|
);
|
|
171
|
+
const webSearchWarning = webSearchConfigWarning(loadConfig().webSearch);
|
|
172
|
+
if (webSearchWarning) {
|
|
173
|
+
process.stderr.write(`[transcode] ${webSearchWarning}\n`);
|
|
174
|
+
}
|
|
169
175
|
return sessionNewResult(session);
|
|
170
176
|
}
|
|
171
177
|
}
|
package/src/agent/loop.ts
CHANGED
|
@@ -312,7 +312,11 @@ export async function runAgentLoop(
|
|
|
312
312
|
};
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
|
|
315
|
+
// Per-turn gating: disabled tools (e.g. unconfigured web_search) never
|
|
316
|
+
// reach the model, so it cannot waste turns calling them.
|
|
317
|
+
const tools = (options.tools ?? AGENT_TOOLS).filter(
|
|
318
|
+
(tool) => !tool.isEnabled || tool.isEnabled(),
|
|
319
|
+
);
|
|
316
320
|
// Claude Code style: generous default cap (their subagents use 200),
|
|
317
321
|
// overridable via TRANSCODE_MAX_TURNS. Hitting it is loud, never silent.
|
|
318
322
|
const envTurns = Number(process.env.TRANSCODE_MAX_TURNS);
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, promises as fs, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
USER_MEMORY_BUDGET_CHARS,
|
|
7
|
+
deleteMemory,
|
|
8
|
+
globalInstructionsPath,
|
|
9
|
+
loadUserMemory,
|
|
10
|
+
memoryDir,
|
|
11
|
+
saveMemory,
|
|
12
|
+
} from './memory.js';
|
|
13
|
+
|
|
14
|
+
let root: string;
|
|
15
|
+
|
|
16
|
+
async function withRoot(run: () => Promise<void>): Promise<void> {
|
|
17
|
+
root = mkdtempSync(path.join(tmpdir(), 'transcode-memory-'));
|
|
18
|
+
process.env.TRANSCODE_USER_DIR = root;
|
|
19
|
+
try {
|
|
20
|
+
await run();
|
|
21
|
+
} finally {
|
|
22
|
+
delete process.env.TRANSCODE_USER_DIR;
|
|
23
|
+
rmSync(root, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function writeEntryFile(name: string, raw: string): Promise<void> {
|
|
28
|
+
mkdirSync(memoryDir(), { recursive: true });
|
|
29
|
+
await fs.writeFile(path.join(memoryDir(), `${name}.md`), raw, 'utf8');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('memory store', () => {
|
|
33
|
+
test('save→load 往返:文件 + 索引 + frontmatter 三键', async () => {
|
|
34
|
+
await withRoot(async () => {
|
|
35
|
+
const entry = await saveMemory({
|
|
36
|
+
name: 'bun-not-node',
|
|
37
|
+
type: 'feedback',
|
|
38
|
+
content: '所有项目用 bun 跑脚本。',
|
|
39
|
+
description: '用户偏好 bun',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(entry.name).toBe('bun-not-node');
|
|
43
|
+
expect(entry.type).toBe('feedback');
|
|
44
|
+
|
|
45
|
+
const file = path.join(memoryDir(), 'bun-not-node.md');
|
|
46
|
+
expect(existsSync(file)).toBe(true);
|
|
47
|
+
const raw = await fs.readFile(file, 'utf8');
|
|
48
|
+
expect(raw).toContain('name: bun-not-node');
|
|
49
|
+
expect(raw).toContain('type: feedback');
|
|
50
|
+
expect(raw).toContain('description: 用户偏好 bun');
|
|
51
|
+
expect(raw).toContain('所有项目用 bun 跑脚本。');
|
|
52
|
+
|
|
53
|
+
const index = await fs.readFile(path.join(memoryDir(), 'MEMORY.md'), 'utf8');
|
|
54
|
+
expect(index).toContain('- [bun-not-node](bun-not-node.md) — 用户偏好 bun');
|
|
55
|
+
|
|
56
|
+
const loaded = await loadUserMemory();
|
|
57
|
+
expect(loaded.entries).toHaveLength(1);
|
|
58
|
+
expect(loaded.entries[0]).toEqual(entry);
|
|
59
|
+
expect(loaded.omitted).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('索引是再生产物:手删 MEMORY.md 后 load 仍返回条目,save 后索引重建', async () => {
|
|
64
|
+
await withRoot(async () => {
|
|
65
|
+
await saveMemory({ name: 'a-first', type: 'user', content: '一', description: 'd1' });
|
|
66
|
+
await saveMemory({ name: 'b-second', type: 'user', content: '二', description: 'd2' });
|
|
67
|
+
await fs.rm(path.join(memoryDir(), 'MEMORY.md'));
|
|
68
|
+
|
|
69
|
+
const loaded = await loadUserMemory();
|
|
70
|
+
expect(loaded.entries.map((e) => e.name)).toEqual(['a-first', 'b-second']);
|
|
71
|
+
|
|
72
|
+
await saveMemory({ name: 'c-third', type: 'user', content: '三', description: 'd3' });
|
|
73
|
+
const index = await fs.readFile(path.join(memoryDir(), 'MEMORY.md'), 'utf8');
|
|
74
|
+
expect(index).toContain('a-first');
|
|
75
|
+
expect(index).toContain('b-second');
|
|
76
|
+
expect(index).toContain('c-third');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('预算:大 reference + 小 user 超预算 → user 保留、reference 进 omitted', async () => {
|
|
81
|
+
await withRoot(async () => {
|
|
82
|
+
await saveMemory({
|
|
83
|
+
name: 'aaa-big-ref',
|
|
84
|
+
type: 'reference',
|
|
85
|
+
content: 'x'.repeat(USER_MEMORY_BUDGET_CHARS),
|
|
86
|
+
description: '大引用',
|
|
87
|
+
});
|
|
88
|
+
await saveMemory({ name: 'zzz-user', type: 'user', content: '小而重要', description: '用户事实' });
|
|
89
|
+
|
|
90
|
+
const loaded = await loadUserMemory();
|
|
91
|
+
expect(loaded.entries.map((e) => e.name)).toEqual(['zzz-user']);
|
|
92
|
+
expect(loaded.omitted).toEqual(['aaa-big-ref']);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('TRANS.md 超预算 → 截断并附 "... (global instructions truncated)"', async () => {
|
|
97
|
+
await withRoot(async () => {
|
|
98
|
+
writeFileSync(globalInstructionsPath(), 'g'.repeat(USER_MEMORY_BUDGET_CHARS + 500));
|
|
99
|
+
const loaded = await loadUserMemory();
|
|
100
|
+
expect(loaded.globalInstructions).not.toBeNull();
|
|
101
|
+
expect((loaded.globalInstructions ?? '').length).toBeLessThanOrEqual(
|
|
102
|
+
USER_MEMORY_BUDGET_CHARS,
|
|
103
|
+
);
|
|
104
|
+
expect(loaded.globalInstructions).toContain('... (global instructions truncated)');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('坏 frontmatter(空文件/缺 type/未知 type)→ 跳过该条不崩', async () => {
|
|
109
|
+
await withRoot(async () => {
|
|
110
|
+
await writeEntryFile('empty', '');
|
|
111
|
+
await writeEntryFile('no-frontmatter', '正文没有 frontmatter');
|
|
112
|
+
await writeEntryFile('missing-type', '---\nname: missing-type\ndescription: d\n---\n正文');
|
|
113
|
+
await writeEntryFile('unknown-type', '---\nname: unknown-type\ntype: diary\n---\n正文');
|
|
114
|
+
await saveMemory({ name: 'good-one', type: 'user', content: '好条目', description: 'ok' });
|
|
115
|
+
|
|
116
|
+
const loaded = await loadUserMemory();
|
|
117
|
+
expect(loaded.entries.map((e) => e.name)).toEqual(['good-one']);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('危险 name(空、a/b、..)→ saveMemory 抛错,deleteMemory 返回 false', async () => {
|
|
122
|
+
await withRoot(async () => {
|
|
123
|
+
await expect(saveMemory({ name: ' ', type: 'user', content: 'x' })).rejects.toThrow();
|
|
124
|
+
await expect(saveMemory({ name: 'a/b', type: 'user', content: 'x' })).rejects.toThrow();
|
|
125
|
+
await expect(saveMemory({ name: '..', type: 'user', content: 'x' })).rejects.toThrow();
|
|
126
|
+
|
|
127
|
+
expect(await deleteMemory('a/b')).toBe(false);
|
|
128
|
+
expect(await deleteMemory('..')).toBe(false);
|
|
129
|
+
expect(await deleteMemory('')).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('description 缺省取 content 首个非空行截 60 字符', async () => {
|
|
134
|
+
await withRoot(async () => {
|
|
135
|
+
const long = 'a'.repeat(80);
|
|
136
|
+
const entry = await saveMemory({ name: 'derived', type: 'user', content: `\n\n${long}` });
|
|
137
|
+
expect(entry.description).toBe('a'.repeat(60));
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('deleteMemory:命中删文件并重写索引,未命中返回 false', async () => {
|
|
142
|
+
await withRoot(async () => {
|
|
143
|
+
await saveMemory({ name: 'keep-me', type: 'user', content: '留', description: 'k' });
|
|
144
|
+
await saveMemory({ name: 'drop-me', type: 'user', content: '删', description: 'd' });
|
|
145
|
+
|
|
146
|
+
expect(await deleteMemory('drop-me')).toBe(true);
|
|
147
|
+
expect(existsSync(path.join(memoryDir(), 'drop-me.md'))).toBe(false);
|
|
148
|
+
const index = await fs.readFile(path.join(memoryDir(), 'MEMORY.md'), 'utf8');
|
|
149
|
+
expect(index).toContain('keep-me');
|
|
150
|
+
expect(index).not.toContain('drop-me');
|
|
151
|
+
expect(await loadUserMemory()).toMatchObject({ entries: [expect.objectContaining({ name: 'keep-me' })] });
|
|
152
|
+
|
|
153
|
+
expect(await deleteMemory('drop-me')).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('scanEntries robustness', () => {
|
|
159
|
+
test('memory 目录里混入目录/不可读项 → 跳过不崩', async () => {
|
|
160
|
+
await withRoot(async () => {
|
|
161
|
+
const { mkdirSync } = await import('node:fs');
|
|
162
|
+
mkdirSync(path.join(memoryDir(), 'trap.md'), { recursive: true });
|
|
163
|
+
await saveMemory({ name: 'fine-one', type: 'user', content: 'ok', description: 'ok' });
|
|
164
|
+
|
|
165
|
+
const loaded = await loadUserMemory();
|
|
166
|
+
expect(loaded.entries.map((e) => e.name)).toEqual(['fine-one']);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* User-level memory: global instructions (~/.transcode/TRANS.md) plus a
|
|
7
|
+
* directory of one-fact-per-file memories. Directory files are the source
|
|
8
|
+
* of truth; MEMORY.md is a write-through index regenerated on every
|
|
9
|
+
* save/delete, never read back.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type MemoryType = 'user' | 'feedback' | 'project' | 'reference';
|
|
13
|
+
|
|
14
|
+
export interface MemoryEntry {
|
|
15
|
+
name: string;
|
|
16
|
+
type: MemoryType;
|
|
17
|
+
description: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface UserMemory {
|
|
22
|
+
globalInstructions: string | null;
|
|
23
|
+
entries: MemoryEntry[];
|
|
24
|
+
omitted: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const USER_MEMORY_BUDGET_CHARS = 12_000;
|
|
28
|
+
|
|
29
|
+
/** Over-budget drop priority: user facts survive longest, pointers go first. */
|
|
30
|
+
const PRIORITY: Record<MemoryType, number> = { user: 3, feedback: 2, project: 1, reference: 0 };
|
|
31
|
+
const MEMORY_TYPES = Object.keys(PRIORITY) as MemoryType[];
|
|
32
|
+
const TRUNCATION_NOTE = '... (global instructions truncated)';
|
|
33
|
+
const DESCRIPTION_MAX_CHARS = 60;
|
|
34
|
+
|
|
35
|
+
// Test isolation mirrors TRANSCODE_SESSIONS_DIR.
|
|
36
|
+
export function userMemoryRoot(): string {
|
|
37
|
+
return process.env.TRANSCODE_USER_DIR ?? path.join(homedir(), '.transcode');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function globalInstructionsPath(): string {
|
|
41
|
+
return path.join(userMemoryRoot(), 'TRANS.md');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function memoryDir(): string {
|
|
45
|
+
return path.join(userMemoryRoot(), 'memory');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Trimmed, separator-free file stem; null when the name cannot be a file. */
|
|
49
|
+
export function sanitizeMemoryName(name: string): string | null {
|
|
50
|
+
const trimmed = name.trim();
|
|
51
|
+
if (!trimmed || trimmed === '.' || trimmed === '..') return null;
|
|
52
|
+
if (trimmed.includes('/') || trimmed.includes('\\')) return null;
|
|
53
|
+
return trimmed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Line-level frontmatter parse (name/type/description only); null when malformed. */
|
|
57
|
+
export function parseMemoryFile(raw: string): MemoryEntry | null {
|
|
58
|
+
const lines = raw.split('\n');
|
|
59
|
+
let start = 0;
|
|
60
|
+
while (start < lines.length && lines[start].trim() === '') start++;
|
|
61
|
+
if (start >= lines.length || lines[start].trim() !== '---') return null;
|
|
62
|
+
let end = -1;
|
|
63
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
64
|
+
if (lines[i].trim() === '---') {
|
|
65
|
+
end = i;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (end === -1) return null;
|
|
70
|
+
|
|
71
|
+
let name: string | null = null;
|
|
72
|
+
let type: MemoryType | null = null;
|
|
73
|
+
let description = '';
|
|
74
|
+
for (let i = start + 1; i < end; i++) {
|
|
75
|
+
const colon = lines[i].indexOf(':');
|
|
76
|
+
if (colon === -1) continue;
|
|
77
|
+
const key = lines[i].slice(0, colon).trim();
|
|
78
|
+
const value = lines[i].slice(colon + 1).trim();
|
|
79
|
+
if (key === 'name') name = value;
|
|
80
|
+
else if (key === 'description') description = value;
|
|
81
|
+
else if (key === 'type' && (MEMORY_TYPES as string[]).includes(value)) {
|
|
82
|
+
type = value as MemoryType;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!name || !type) return null;
|
|
86
|
+
return { name, type, description, content: lines.slice(end + 1).join('\n').trim() };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function renderMemoryFile(entry: MemoryEntry): string {
|
|
90
|
+
return (
|
|
91
|
+
`---\nname: ${entry.name}\ntype: ${entry.type}\ndescription: ${entry.description}\n---\n` +
|
|
92
|
+
`${entry.content}\n`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function renderMemoryIndex(entries: MemoryEntry[]): string {
|
|
97
|
+
if (entries.length === 0) return '';
|
|
98
|
+
return entries.map((e) => `- [${e.name}](${e.name}.md) — ${e.description}`).join('\n') + '\n';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Memory files in display (alphabetical) order; malformed files are skipped. */
|
|
102
|
+
function scanEntries(): MemoryEntry[] {
|
|
103
|
+
let files: string[];
|
|
104
|
+
try {
|
|
105
|
+
files = fs.readdirSync(memoryDir());
|
|
106
|
+
} catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
const entries: MemoryEntry[] = [];
|
|
110
|
+
for (const file of files.filter((n) => n.endsWith('.md') && n !== 'MEMORY.md').sort()) {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = parseMemoryFile(fs.readFileSync(path.join(memoryDir(), file), 'utf8'));
|
|
113
|
+
if (parsed) entries.push(parsed);
|
|
114
|
+
} catch {
|
|
115
|
+
// Unreadable item (permissions, a directory, …): skip, like malformed files.
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return entries;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Atomic replace: a crash mid-write can never truncate a memory file. */
|
|
122
|
+
function writeAtomic(target: string, data: string): void {
|
|
123
|
+
const tmp = `${target}.tmp`;
|
|
124
|
+
fs.writeFileSync(tmp, data);
|
|
125
|
+
try {
|
|
126
|
+
fs.renameSync(tmp, target);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
try {
|
|
129
|
+
fs.rmSync(tmp, { force: true });
|
|
130
|
+
} catch {
|
|
131
|
+
// Best-effort cleanup; the original error matters more.
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function rewriteIndex(): void {
|
|
138
|
+
writeAtomic(path.join(memoryDir(), 'MEMORY.md'), renderMemoryIndex(scanEntries()));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function deriveDescription(content: string): string {
|
|
142
|
+
const first = content.split('\n').map((l) => l.trim()).find((l) => l.length > 0) ?? '';
|
|
143
|
+
return first.length > DESCRIPTION_MAX_CHARS ? first.slice(0, DESCRIPTION_MAX_CHARS) : first;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function loadUserMemory(): Promise<UserMemory> {
|
|
147
|
+
let globalInstructions: string | null = null;
|
|
148
|
+
let remaining = USER_MEMORY_BUDGET_CHARS;
|
|
149
|
+
try {
|
|
150
|
+
const raw = fs.readFileSync(globalInstructionsPath(), 'utf8').trim();
|
|
151
|
+
if (raw) {
|
|
152
|
+
globalInstructions =
|
|
153
|
+
raw.length > remaining
|
|
154
|
+
? `${raw.slice(0, Math.max(0, remaining - TRUNCATION_NOTE.length - 1))}\n${TRUNCATION_NOTE}`
|
|
155
|
+
: raw;
|
|
156
|
+
remaining -= globalInstructions.length;
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
// No global instructions file yet.
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Over budget: drop whole entries (never clip mid-fact), lowest priority
|
|
163
|
+
// first, ties resolved to the last in alphabetical display order.
|
|
164
|
+
const kept = scanEntries();
|
|
165
|
+
const omitted: string[] = [];
|
|
166
|
+
const totalCost = () => kept.reduce((sum, e) => sum + renderMemoryFile(e).length, 0);
|
|
167
|
+
while (totalCost() > remaining && kept.length > 0) {
|
|
168
|
+
let victim = 0;
|
|
169
|
+
for (let i = 1; i < kept.length; i++) {
|
|
170
|
+
if (PRIORITY[kept[i].type] <= PRIORITY[kept[victim].type]) victim = i;
|
|
171
|
+
}
|
|
172
|
+
omitted.push(kept[victim].name);
|
|
173
|
+
kept.splice(victim, 1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { globalInstructions, entries: kept, omitted };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function saveMemory(input: {
|
|
180
|
+
name: string;
|
|
181
|
+
type: MemoryType;
|
|
182
|
+
content: string;
|
|
183
|
+
description?: string;
|
|
184
|
+
}): Promise<MemoryEntry> {
|
|
185
|
+
const name = sanitizeMemoryName(input.name);
|
|
186
|
+
if (!name) throw new Error(`invalid memory name: ${JSON.stringify(input.name)}`);
|
|
187
|
+
const entry: MemoryEntry = {
|
|
188
|
+
name,
|
|
189
|
+
type: input.type,
|
|
190
|
+
description: input.description?.trim() || deriveDescription(input.content),
|
|
191
|
+
content: input.content.trim(),
|
|
192
|
+
};
|
|
193
|
+
fs.mkdirSync(memoryDir(), { recursive: true });
|
|
194
|
+
writeAtomic(path.join(memoryDir(), `${name}.md`), renderMemoryFile(entry));
|
|
195
|
+
rewriteIndex();
|
|
196
|
+
return entry;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function deleteMemory(name: string): Promise<boolean> {
|
|
200
|
+
const safe = sanitizeMemoryName(name);
|
|
201
|
+
if (!safe) return false;
|
|
202
|
+
const target = path.join(memoryDir(), `${safe}.md`);
|
|
203
|
+
if (!fs.existsSync(target)) return false;
|
|
204
|
+
fs.rmSync(target);
|
|
205
|
+
rewriteIndex();
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import { mkdtempSync, promises as fs, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { mkdirSync, mkdtempSync, promises as fs, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { INIT_PROMPT, buildSystemPrompt, loadProjectContext } from './system-prompt.js';
|
|
@@ -87,3 +87,89 @@ describe('INIT_PROMPT', () => {
|
|
|
87
87
|
expect(INIT_PROMPT.toLowerCase()).toContain('analyze');
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
|
+
|
|
91
|
+
describe('user memory injection', () => {
|
|
92
|
+
const memory = {
|
|
93
|
+
globalInstructions: 'All projects run on bun.',
|
|
94
|
+
entries: [
|
|
95
|
+
{
|
|
96
|
+
name: 'commit-style-zh',
|
|
97
|
+
type: 'feedback' as const,
|
|
98
|
+
description: '中文 commit 惯例',
|
|
99
|
+
content: 'Commit messages written in Chinese.',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
omitted: ['stale-pointer'],
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
test('userMemory 有内容 → 渲染 ## User memory 段,位于 ## Project instructions 之前', () => {
|
|
106
|
+
const prompt = buildSystemPrompt({
|
|
107
|
+
cwd: '/tmp',
|
|
108
|
+
projectFiles: [{ path: 'TRANS.md', content: 'project rules' }],
|
|
109
|
+
userMemory: memory,
|
|
110
|
+
});
|
|
111
|
+
expect(prompt).toContain('## User memory');
|
|
112
|
+
expect(prompt.indexOf('## User memory')).toBeLessThan(
|
|
113
|
+
prompt.indexOf('## Project instructions'),
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('段内含 Global instructions 原文、索引行、各条 #### name 与正文、omitted 注名行', () => {
|
|
118
|
+
const prompt = buildSystemPrompt({ cwd: '/tmp', projectFiles: [], userMemory: memory });
|
|
119
|
+
expect(prompt).toContain('### Global instructions');
|
|
120
|
+
expect(prompt).toContain('All projects run on bun.');
|
|
121
|
+
expect(prompt).toContain('- [commit-style-zh](commit-style-zh.md) — 中文 commit 惯例');
|
|
122
|
+
expect(prompt).toContain('#### commit-style-zh');
|
|
123
|
+
expect(prompt).toContain('Commit messages written in Chinese.');
|
|
124
|
+
expect(prompt).toContain('(omitted: stale-pointer)');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('userMemory 为空/缺省 → 不渲染该段;How to work 始终含 memory_save 引导行', () => {
|
|
128
|
+
const empty = buildSystemPrompt({
|
|
129
|
+
cwd: '/tmp',
|
|
130
|
+
projectFiles: [],
|
|
131
|
+
userMemory: { globalInstructions: null, entries: [], omitted: [] },
|
|
132
|
+
});
|
|
133
|
+
expect(empty).not.toContain('## User memory');
|
|
134
|
+
expect(empty).toContain('memory_save');
|
|
135
|
+
|
|
136
|
+
const absent = buildSystemPrompt({ cwd: '/tmp', projectFiles: [] });
|
|
137
|
+
expect(absent).not.toContain('## User memory');
|
|
138
|
+
expect(absent).toContain('memory_save');
|
|
139
|
+
expect(absent).toContain('verify it still holds');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('loadProjectContext 集成:TRANSCODE_USER_DIR 根下放 TRANS.md + memory 条目 → context.userMemory 装载', async () => {
|
|
143
|
+
const dir = workspace();
|
|
144
|
+
const userRoot = mkdtempSync(path.join(tmpdir(), 'transcode-user-memory-'));
|
|
145
|
+
process.env.TRANSCODE_USER_DIR = userRoot;
|
|
146
|
+
try {
|
|
147
|
+
writeFileSync(path.join(userRoot, 'TRANS.md'), 'Global rule: bun only.\n');
|
|
148
|
+
mkdirSync(path.join(userRoot, 'memory'), { recursive: true });
|
|
149
|
+
writeFileSync(
|
|
150
|
+
path.join(userRoot, 'memory', 'pref-editor.md'),
|
|
151
|
+
'---\nname: pref-editor\ntype: user\ndescription: 编辑器偏好\n---\nVim keybindings everywhere.\n',
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const context = await loadProjectContext(dir);
|
|
155
|
+
expect(context.userMemory?.globalInstructions).toBe('Global rule: bun only.');
|
|
156
|
+
expect(context.userMemory?.entries[0]?.name).toBe('pref-editor');
|
|
157
|
+
expect(context.userMemory?.omitted).toEqual([]);
|
|
158
|
+
} finally {
|
|
159
|
+
delete process.env.TRANSCODE_USER_DIR;
|
|
160
|
+
rmSync(userRoot, { recursive: true, force: true });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('omitted-only user memory', () => {
|
|
166
|
+
test('全部条目超预算被丢 → 段仍渲染且含 omitted 注名', () => {
|
|
167
|
+
const prompt = buildSystemPrompt({
|
|
168
|
+
cwd: '/tmp',
|
|
169
|
+
projectFiles: [],
|
|
170
|
+
userMemory: { globalInstructions: null, entries: [], omitted: ['huge'] },
|
|
171
|
+
});
|
|
172
|
+
expect(prompt).toContain('## User memory');
|
|
173
|
+
expect(prompt).toContain('(omitted: huge)');
|
|
174
|
+
});
|
|
175
|
+
});
|