@misakacloud/opencode-compact-enhance 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +30 -2
- package/package.json +26 -4
- package/src/index.ts +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chisaato
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @misakacloud/opencode-compact-enhance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCode V2 插件:在 OpenChamber Web 或 TUI 触发上下文压缩时,指定摘要应优先保留哪些细节、略去哪些内容。需要 OpenCode 2.3.2 或更高版本。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
在 OpenCode 的 `opencode.jsonc` 中添加插件:
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
{
|
|
11
|
+
"plugins": ["@misakacloud/opencode-compact-enhance@latest"]
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 用法
|
|
16
|
+
|
|
17
|
+
在 OpenChamber Web 或 TUI 的会话输入框中,从斜杠菜单选择 `/compact-enhance`,并按需附上指令:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
/compact-enhance 保留关键架构决策、失败原因和未解决问题;略去重复的调试日志
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
不带参数或参数只有空白时,等同于普通 `/compact`,不会设置摘要指令。压缩请求失败时(例如会话内容太少,无法压缩),客户端会显示命令错误。
|
|
24
|
+
|
|
25
|
+
## 工作原理
|
|
26
|
+
|
|
27
|
+
插件在服务端注册命令,因此 OpenChamber Web 和 TUI 都能在斜杠菜单中找到它。服务端保存指令(如有)后,请求压缩当前会话。压缩钩子将指令附加到发给摘要模型的请求中,不会把它写进聊天记录。摘要模型会被要求在保留默认摘要格式的同时,优先按指令调整内容取舍和细节密度。
|
|
28
|
+
|
|
29
|
+
- 指令按会话保存,**只在下一次进入压缩钩子时生效一次**。同一会话再次设置指令会覆盖尚未使用的旧指令。
|
|
30
|
+
- 如果会话内容太少或其他原因让这次请求还没进入压缩钩子,指令会保留到下一次压缩;无论是手动 `/compact` 还是自动压缩,都能使用它。
|
|
31
|
+
- 指令在压缩钩子中取出后即被消费。如果后续摘要生成失败,需重新提交指令。未使用的指令仅保存在服务端内存中,不会跨重启保留。
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "@misakacloud/opencode-compact-enhance",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "OpenCode V2 plugin: give the next context compaction a one-shot instruction",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"files": ["src", "README.md", "LICENSE"],
|
|
12
|
+
"scripts": { "typecheck": "tsc --noEmit", "test": "vitest run", "build": "tsc --noEmit" },
|
|
13
|
+
"dependencies": { "@opencode/plugin": "^2.3.2" },
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/bun": "latest",
|
|
16
|
+
"@types/node": "^25.6.0",
|
|
17
|
+
"typescript": "^6.0.3",
|
|
18
|
+
"vitest": "^4.1.5"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/chisaato/opencode-plugins.git",
|
|
23
|
+
"directory": "packages/compact-enhance"
|
|
24
|
+
},
|
|
25
|
+
"author": "chisaato",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"publishConfig": { "access": "public", "provenance": true }
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin"
|
|
2
|
+
|
|
3
|
+
export const CompactEnhancePlugin = Plugin.define({
|
|
4
|
+
id: "opencode-compact-enhance",
|
|
5
|
+
async setup(ctx) {
|
|
6
|
+
const instructions = new Map<string, string>()
|
|
7
|
+
|
|
8
|
+
await ctx.command.transform((editor) => {
|
|
9
|
+
editor.add({
|
|
10
|
+
name: "compact-enhance",
|
|
11
|
+
description: "带指令压缩上下文:本次输入作为一次性摘要偏向指令,不进入聊天记录",
|
|
12
|
+
async execute(input) {
|
|
13
|
+
const instruction = input.prompt.text?.trim()
|
|
14
|
+
if (instruction) instructions.set(input.sessionID, instruction)
|
|
15
|
+
await ctx.session.compact({ sessionID: input.sessionID })
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
await ctx.session.hook("compaction", async (event) => {
|
|
21
|
+
const hint = instructions.get(event.sessionID)
|
|
22
|
+
if (hint === undefined) return
|
|
23
|
+
|
|
24
|
+
// 只让本次摘要请求使用该指令,不写入会话历史。
|
|
25
|
+
instructions.delete(event.sessionID)
|
|
26
|
+
if (!hint) return
|
|
27
|
+
|
|
28
|
+
event.messages.push({
|
|
29
|
+
role: "user",
|
|
30
|
+
content: [{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: [
|
|
33
|
+
"The user explicitly requests the following for this compaction only.",
|
|
34
|
+
"Follow this instruction when deciding what to retain: include more detail where requested, and condense or omit details where requested.",
|
|
35
|
+
"If it conflicts with the default summary brevity or level-of-detail rules, prioritize this instruction while keeping the requested summary format.",
|
|
36
|
+
"Apply the instruction to the summary itself; do not quote it or carry it forward as a task.",
|
|
37
|
+
"",
|
|
38
|
+
hint,
|
|
39
|
+
].join("\n"),
|
|
40
|
+
}],
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export default CompactEnhancePlugin
|