oc-tweaks 0.3.2 → 0.4.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 +12 -4
- package/dist/index.js +38 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,13 +89,15 @@ Customize the appearance of the WPF notification window.
|
|
|
89
89
|
|
|
90
90
|
### `compaction`
|
|
91
91
|
|
|
92
|
-
This plugin ensures that when OpenCode compacts a session's context, the resulting summary is generated in your preferred language
|
|
92
|
+
This plugin ensures that when OpenCode compacts a session's context, the resulting summary is generated in your preferred language and writing style.
|
|
93
93
|
|
|
94
94
|
**Configuration Options:**
|
|
95
95
|
|
|
96
96
|
| Property | Type | Default | Description |
|
|
97
97
|
|---|---|---|---|
|
|
98
98
|
| `enabled` | boolean | `true` | Enable or disable the plugin. |
|
|
99
|
+
| `language` | string | session language | Target language for the compaction summary (e.g., `"繁体中文"`, `"French"`). Defaults to the language the user used most in the session. |
|
|
100
|
+
| `style` | string | `"concise and well-organized"` | Writing style for the compaction summary (e.g., `"毛泽东语言风格"`, `"academic"`). |
|
|
99
101
|
|
|
100
102
|
### `autoMemory`
|
|
101
103
|
|
|
@@ -163,7 +165,9 @@ Here is an example of a `~/.config/opencode/oc-tweaks.json` file with all option
|
|
|
163
165
|
}
|
|
164
166
|
},
|
|
165
167
|
"compaction": {
|
|
166
|
-
"enabled": true
|
|
168
|
+
"enabled": true,
|
|
169
|
+
"language": "繁体中文",
|
|
170
|
+
"style": "毛泽东语言风格"
|
|
167
171
|
},
|
|
168
172
|
"autoMemory": {
|
|
169
173
|
"enabled": true
|
|
@@ -275,13 +279,15 @@ bunx oc-tweaks init
|
|
|
275
279
|
|
|
276
280
|
### `compaction`
|
|
277
281
|
|
|
278
|
-
此插件确保当 OpenCode
|
|
282
|
+
此插件确保当 OpenCode 压缩会话上下文时,生成的摘要使用你的首选语言和写作风格。
|
|
279
283
|
|
|
280
284
|
**配置选项:**
|
|
281
285
|
|
|
282
286
|
| 属性 | 类型 | 默认值 | 描述 |
|
|
283
287
|
|---|---|---|---|
|
|
284
288
|
| `enabled` | boolean | `true` | 启用或禁用此插件。 |
|
|
289
|
+
| `language` | string | 会话语言 | 压缩摘要的目标语言(如 `"繁体中文"`、`"French"`)。默认使用会话中用户最常使用的语言。 |
|
|
290
|
+
| `style` | string | `"concise and well-organized"` | 压缩摘要的写作风格(如 `"毛泽东语言风格"`、`"academic"`)。 |
|
|
285
291
|
|
|
286
292
|
### `autoMemory`
|
|
287
293
|
|
|
@@ -349,7 +355,9 @@ bunx oc-tweaks init
|
|
|
349
355
|
}
|
|
350
356
|
},
|
|
351
357
|
"compaction": {
|
|
352
|
-
"enabled": true
|
|
358
|
+
"enabled": true,
|
|
359
|
+
"language": "繁体中文",
|
|
360
|
+
"style": "毛泽东语言风格"
|
|
353
361
|
},
|
|
354
362
|
"autoMemory": {
|
|
355
363
|
"enabled": true
|
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
|
-
|
|
161
|
+
Memory 是 AGENTS.md / CLAUDE.md 的**补充**,存储跨会话有价值的信息。
|
|
162
|
+
|
|
163
|
+
记忆层(直接用 Write / Edit 工具操作):
|
|
164
|
+
1. 全局:\`${params.globalMemoryDir}/\` — 跨项目偏好
|
|
165
|
+
2. 项目:\`${params.projectMemoryDir}/\` — 项目特定知识
|
|
155
166
|
|
|
156
|
-
|
|
157
|
-
1. 全局 memory:\`${params.globalMemoryDir}\`
|
|
158
|
-
2. 项目 memory:\`${params.projectMemoryDir}\`
|
|
167
|
+
文件按主题分类(preferences.md、decisions.md、setup.md 等),写入时保持简洁,用 markdown bullet points,保持原意不扩写。
|
|
159
168
|
|
|
160
|
-
### 何时保存
|
|
169
|
+
### 何时保存
|
|
161
170
|
|
|
162
|
-
|
|
163
|
-
- 用户明确要求记住(触发词:${TRIGGER_WORDS_CN.join("、")} / ${TRIGGER_WORDS_EN.join(", ")}
|
|
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 }) => {
|
|
@@ -251,7 +243,7 @@ var autoMemoryPlugin = async ({ directory }) => {
|
|
|
251
243
|
|
|
252
244
|
核心问题:**如果明天开一个全新会话,本轮对话中有哪些信息会让你希望已经记录下来?**
|
|
253
245
|
|
|
254
|
-
有 → 标记保存。没有 → 标记 none
|
|
246
|
+
有 → 标记保存。没有 → 标记 none。
|
|
255
247
|
|
|
256
248
|
### 值得保存
|
|
257
249
|
- 用户表达的偏好、纠正、或明确要求记住的内容
|
|
@@ -262,9 +254,10 @@ var autoMemoryPlugin = async ({ directory }) => {
|
|
|
262
254
|
### 不要保存
|
|
263
255
|
- 本次对话的临时细节(具体报错、一次性调试步骤)
|
|
264
256
|
- AGENTS.md / CLAUDE.md 中已有的内容
|
|
265
|
-
- 未验证的猜测
|
|
257
|
+
- 未验证的猜测
|
|
258
|
+
- 机密信息(密码、API key 等)
|
|
266
259
|
|
|
267
|
-
|
|
260
|
+
每次 compaction 最多标记 1-2 条,宁缺毋滥。
|
|
268
261
|
|
|
269
262
|
有内容:
|
|
270
263
|
\`\`\`
|
|
@@ -328,20 +321,20 @@ ${VIOLATION_WARNING}`;
|
|
|
328
321
|
};
|
|
329
322
|
};
|
|
330
323
|
// src/plugins/compaction.ts
|
|
331
|
-
|
|
332
|
-
|
|
324
|
+
function buildCompactionPrompt(language, style) {
|
|
325
|
+
const lang = language || "the language the user used most in this session";
|
|
326
|
+
const writingStyle = style || "concise and well-organized";
|
|
327
|
+
return `## Language & Style Preference
|
|
333
328
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
Keep technical terms (filenames, variable names, commands, code snippets) in their original form.
|
|
337
|
-
`;
|
|
329
|
+
Write the compaction summary in ${lang}, using a ${writingStyle} writing style. Keep technical terms (filenames, commands, code) in their original form.`;
|
|
330
|
+
}
|
|
338
331
|
var compactionPlugin = async () => {
|
|
339
332
|
return {
|
|
340
333
|
"experimental.session.compacting": safeHook("compaction", async (_input, output) => {
|
|
341
334
|
const config = await loadOcTweaksConfig();
|
|
342
335
|
if (!config || config.compaction?.enabled !== true)
|
|
343
336
|
return;
|
|
344
|
-
output.context.push(
|
|
337
|
+
output.context.push(buildCompactionPrompt(config.compaction?.language, config.compaction?.style));
|
|
345
338
|
})
|
|
346
339
|
};
|
|
347
340
|
};
|