oc-tweaks 0.3.1 → 0.4.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/dist/index.js +50 -61
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -144,54 +144,46 @@ function buildMemoryGuide(params) {
|
|
|
144
144
|
`) : "- (暂无全局 memory 文件)";
|
|
145
145
|
const projectList = params.projectFiles.length > 0 ? params.projectFiles.map((name) => `- \`${name}\``).join(`
|
|
146
146
|
`) : "- (暂无项目级 memory 文件)";
|
|
147
|
-
const
|
|
148
|
-
|
|
147
|
+
const MAX_LINES_PER_FILE = 200;
|
|
148
|
+
const injectedContents = params.fileContents.size > 0 ? Array.from(params.fileContents.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([path, content]) => {
|
|
149
|
+
const lines = content.split(`
|
|
150
|
+
`);
|
|
151
|
+
const truncated = lines.length > MAX_LINES_PER_FILE ? lines.slice(0, MAX_LINES_PER_FILE).join(`
|
|
152
|
+
`) + `
|
|
153
|
+
[...truncated, use Read tool for full content]` : content;
|
|
154
|
+
return `Contents of ${path}:
|
|
155
|
+
${truncated}`;
|
|
156
|
+
}).join(`
|
|
149
157
|
|
|
150
158
|
`) : "(暂无可注入的 memory 内容)";
|
|
151
159
|
return `## \uD83E\uDDE0 Memory 系统指引
|
|
152
160
|
|
|
153
|
-
Memory 是 AGENTS.md / CLAUDE.md
|
|
154
|
-
不要将 AGENTS.md / CLAUDE.md 中已有的内容重复写入 memory。
|
|
161
|
+
Memory 是 AGENTS.md / CLAUDE.md 的**补充**,存储跨会话有价值的信息。
|
|
155
162
|
|
|
156
|
-
|
|
157
|
-
1.
|
|
158
|
-
2.
|
|
163
|
+
记忆层(直接用 Write / Edit 工具操作):
|
|
164
|
+
1. 全局:\`${params.globalMemoryDir}/\` — 跨项目偏好
|
|
165
|
+
2. 项目:\`${params.projectMemoryDir}/\` — 项目特定知识
|
|
159
166
|
|
|
160
|
-
|
|
167
|
+
文件按主题分类(preferences.md、decisions.md、setup.md 等),写入时保持简洁,用 markdown bullet points,保持原意不扩写。
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
### 何时保存
|
|
170
|
+
|
|
171
|
+
**必须保存:**
|
|
172
|
+
- 用户明确要求记住(触发词:${TRIGGER_WORDS_CN.join("、")} / ${TRIGGER_WORDS_EN.join(", ")})
|
|
164
173
|
- 用户纠正了你的行为或表达了明确偏好
|
|
165
174
|
|
|
166
|
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
- 用户的工作流、工具、沟通风格偏好
|
|
175
|
+
**建议保存(判断标准:如果明天从头开始,这个信息有帮助吗?):**
|
|
176
|
+
- 架构决策、技术选型及其理由
|
|
177
|
+
- 反复出现问题的根因与解决方案
|
|
178
|
+
- 工作流、工具链、沟通风格等跨会话模式
|
|
171
179
|
|
|
172
180
|
### 不要保存
|
|
173
181
|
|
|
174
|
-
-
|
|
175
|
-
- AGENTS.md
|
|
176
|
-
-
|
|
182
|
+
- 本次对话的临时细节(具体报错、一次性调试步骤)
|
|
183
|
+
- AGENTS.md / CLAUDE.md 中已有的内容(不得重复或矛盾)
|
|
184
|
+
- 未验证的猜测(先查证再记录)
|
|
177
185
|
- 机密信息(密码、API key 等)
|
|
178
186
|
|
|
179
|
-
### 如何保存
|
|
180
|
-
|
|
181
|
-
直接使用你的内置 Write 或 Edit 工具操作 memory 文件:
|
|
182
|
-
- 全局 memory:\`${params.globalMemoryDir}/\`
|
|
183
|
-
- 项目 memory:\`${params.projectMemoryDir}/\`
|
|
184
|
-
|
|
185
|
-
文件按主题分类(如 preferences.md、decisions.md、setup.md、notes.md)。
|
|
186
|
-
写入时保持简洁,用 markdown bullet points,保持原意不扩写。
|
|
187
|
-
|
|
188
|
-
### 如何更新已有 memory
|
|
189
|
-
|
|
190
|
-
- 更新已有文件时,使用 Edit 工具追加或修改特定段落,不要用 Write 整体覆盖
|
|
191
|
-
- 内容要具体、信息密集(包含文件路径、函数名、具体命令等)
|
|
192
|
-
- 当某个 memory 文件内容过长时,精简旧条目而不是无限追加
|
|
193
|
-
- 更新时保持已有内容的结构完整,不要破坏其他条目
|
|
194
|
-
|
|
195
187
|
### 当前 Memory 文件
|
|
196
188
|
**全局**
|
|
197
189
|
${globalList}
|
|
@@ -199,7 +191,7 @@ ${globalList}
|
|
|
199
191
|
**项目级**
|
|
200
192
|
${projectList}
|
|
201
193
|
|
|
202
|
-
###
|
|
194
|
+
### 已有 Memory 内容
|
|
203
195
|
${injectedContents}`;
|
|
204
196
|
}
|
|
205
197
|
var autoMemoryPlugin = async ({ directory }) => {
|
|
@@ -247,40 +239,38 @@ var autoMemoryPlugin = async ({ directory }) => {
|
|
|
247
239
|
if (!config || config.autoMemory?.enabled !== true)
|
|
248
240
|
return;
|
|
249
241
|
await ensureAutoMemoryInfra(home, projectMemoryDir);
|
|
250
|
-
output.context.push(`## \uD83D\uDCBE Memory
|
|
242
|
+
output.context.push(`## \uD83D\uDCBE Memory Checkpoint
|
|
243
|
+
|
|
244
|
+
核心问题:**如果明天开一个全新会话,本轮对话中有哪些信息会让你希望已经记录下来?**
|
|
251
245
|
|
|
252
|
-
|
|
246
|
+
有 → 标记保存。没有 → 标记 none。
|
|
253
247
|
|
|
254
|
-
###
|
|
255
|
-
-
|
|
256
|
-
- 用户纠正了你的行为(隐含偏好)
|
|
248
|
+
### 值得保存
|
|
249
|
+
- 用户表达的偏好、纠正、或明确要求记住的内容
|
|
257
250
|
- 架构决策、设计约束、技术选型及其理由
|
|
258
|
-
- 跨会话有价值的模式或约定(问自己:明天从头开始,这个信息有帮助吗?)
|
|
259
251
|
- 反复出现问题的根因与解决方案
|
|
260
|
-
-
|
|
261
|
-
|
|
262
|
-
### 不应该保存的
|
|
263
|
-
- 仅本次对话有用的临时细节(具体报错、一次性调试命令)
|
|
264
|
-
- AGENTS.md / CLAUDE.md 中已有的内容(不得重复)
|
|
265
|
-
- 未验证的猜测或中间结论
|
|
266
|
-
- 机密信息(密码、API key、token)
|
|
252
|
+
- 工作流、工具链、沟通风格等跨会话有价值的模式
|
|
267
253
|
|
|
268
|
-
###
|
|
254
|
+
### 不要保存
|
|
255
|
+
- 本次对话的临时细节(具体报错、一次性调试步骤)
|
|
256
|
+
- AGENTS.md / CLAUDE.md 中已有的内容
|
|
257
|
+
- 未验证的猜测
|
|
258
|
+
- 机密信息(密码、API key 等)
|
|
269
259
|
|
|
270
|
-
|
|
260
|
+
每次 compaction 最多标记 1-2 条,宁缺毋滥。
|
|
271
261
|
|
|
262
|
+
有内容:
|
|
272
263
|
\`\`\`
|
|
273
264
|
[MEMORY: 文件名.md]
|
|
274
|
-
|
|
265
|
+
简洁 bullet points,保持原意
|
|
275
266
|
\`\`\`
|
|
276
267
|
|
|
277
|
-
|
|
268
|
+
无内容:\`[MEMORY: none]\` 并附一句理由说明为何无需保存
|
|
278
269
|
|
|
279
270
|
### Memory 路径
|
|
280
271
|
- 全局:\`${globalMemoryDir}/\`
|
|
281
272
|
- 项目:\`${projectMemoryDir}/\`
|
|
282
|
-
|
|
283
|
-
后续对话中应根据标记调用内置 Read/Edit/Write 工具写入对应 memory 文件。`);
|
|
273
|
+
`);
|
|
284
274
|
})
|
|
285
275
|
};
|
|
286
276
|
};
|
|
@@ -331,20 +321,19 @@ ${VIOLATION_WARNING}`;
|
|
|
331
321
|
};
|
|
332
322
|
};
|
|
333
323
|
// src/plugins/compaction.ts
|
|
334
|
-
|
|
335
|
-
|
|
324
|
+
function buildLanguagePrompt(language) {
|
|
325
|
+
const lang = language || "the language the user used most in this session";
|
|
326
|
+
return `## Language Preference
|
|
336
327
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Keep technical terms (filenames, variable names, commands, code snippets) in their original form.
|
|
340
|
-
`;
|
|
328
|
+
Write the compaction summary in ${lang}. Keep technical terms (filenames, commands, code) in their original form.`;
|
|
329
|
+
}
|
|
341
330
|
var compactionPlugin = async () => {
|
|
342
331
|
return {
|
|
343
332
|
"experimental.session.compacting": safeHook("compaction", async (_input, output) => {
|
|
344
333
|
const config = await loadOcTweaksConfig();
|
|
345
334
|
if (!config || config.compaction?.enabled !== true)
|
|
346
335
|
return;
|
|
347
|
-
output.context.push(
|
|
336
|
+
output.context.push(buildLanguagePrompt(config.compaction?.language));
|
|
348
337
|
})
|
|
349
338
|
};
|
|
350
339
|
};
|