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.
Files changed (2) hide show
  1. package/dist/index.js +50 -61
  2. 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 injectedContents = params.fileContents.size > 0 ? Array.from(params.fileContents.entries()).sort(([a], [b]) => a.localeCompare(b)).map(([path, content]) => `Contents of ${path}:
148
- ${content}`).join(`
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. 全局 memory:\`${params.globalMemoryDir}\`
158
- 2. 项目 memory:\`${params.projectMemoryDir}\`
163
+ 记忆层(直接用 Write / Edit 工具操作):
164
+ 1. 全局:\`${params.globalMemoryDir}/\` — 跨项目偏好
165
+ 2. 项目:\`${params.projectMemoryDir}/\` — 项目特定知识
159
166
 
160
- ### 何时保存 memory
167
+ 文件按主题分类(preferences.md、decisions.md、setup.md 等),写入时保持简洁,用 markdown bullet points,保持原意不扩写。
161
168
 
162
- **你必须(MUST)保存 memory 当:**
163
- - 用户明确要求记住(触发词:${TRIGGER_WORDS_CN.join("、")} / ${TRIGGER_WORDS_EN.join(", ")})
169
+ ### 何时保存
170
+
171
+ **必须保存:**
172
+ - 用户明确要求记住(触发词:${TRIGGER_WORDS_CN.join("、")} / ${TRIGGER_WORDS_EN.join(", ")})
164
173
  - 用户纠正了你的行为或表达了明确偏好
165
174
 
166
- **建议保存 memory 当:**
167
- - 发现了跨会话有用的模式或约定(想想:如果明天从头开始,这个信息有帮助吗?)
168
- - 用户描述了目标或背景("我在做..."、"我们在迁移到...")
169
- - 找到了可能再次出现的问题的解决方案
170
- - 用户的工作流、工具、沟通风格偏好
175
+ **建议保存(判断标准:如果明天从头开始,这个信息有帮助吗?):**
176
+ - 架构决策、技术选型及其理由
177
+ - 反复出现问题的根因与解决方案
178
+ - 工作流、工具链、沟通风格等跨会话模式
171
179
 
172
180
  ### 不要保存
173
181
 
174
- - 临时的当前任务细节(只在本次对话有用的信息)
175
- - AGENTS.md CLAUDE.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
- ### 用户核心 Preferences
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 保存提示 (Compaction Phase)
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
- 简洁的 bullet points,保持原意不扩写
265
+ 简洁 bullet points,保持原意
275
266
  \`\`\`
276
267
 
277
- 确实没有值得保存的,标记 \`[MEMORY: none]\`。
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
- var LANGUAGE_PREFERENCE_PROMPT = `
335
- ## Language Preference
324
+ function buildLanguagePrompt(language) {
325
+ const lang = language || "the language the user used most in this session";
326
+ return `## Language Preference
336
327
 
337
- Important: Write the compaction summary in the user's preferred language(for example, if user prefers Chinese, then the compaction should be in Chinese as well).
338
- All section titles, descriptions, analysis, and next-step suggestions should use the user's language.
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(LANGUAGE_PREFERENCE_PROMPT);
336
+ output.context.push(buildLanguagePrompt(config.compaction?.language));
348
337
  })
349
338
  };
350
339
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-tweaks",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"