You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-11Lines changed: 17 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,20 +60,20 @@ You should see `morph_edit`, `warpgrep_codebase_search`, and `warpgrep_github_se
60
60
61
61
## Compaction
62
62
63
-
Context compression via the Morph Compact API. Runs automatically before each LLM call when the conversation exceeds a token threshold.
63
+
Context compression via the Morph Compact API. In current OpenCode 1.14.x releases, only OpenCode native compaction writes the persisted summary message that future turns and the sidebar use. This plugin handles that path by pre-compressing the selected history with Morph before OpenCode's native compaction model writes its summary.
64
64
65
65
### How it works
66
66
67
-
1.Before each LLM call, the plugin estimates the total characters in the conversation
68
-
2.If the estimate exceeds the threshold, older messages are compressed via the Morph Compact API (~250ms)
69
-
3.The compressed result is cached ("frozen") and reused on subsequent calls for prompt cache stability
70
-
4.Only the most recent user message is kept uncompacted
67
+
1.When OpenCode native compaction starts, the plugin adds Morph-aware instructions to the compaction prompt
68
+
2.The following `experimental.chat.messages.transform` hook receives the history OpenCode selected for compaction
69
+
3.Morph compresses that selected history to one summary message before OpenCode sends it to the compaction model
70
+
4.OpenCode then persists its normal compaction summary and emits `session.compacted`
71
71
72
-
The LLM receives compressed history + your latest prompt. The "Context: X tokens" number in the sidebar reflects the actual tokens sent (post-compaction).
72
+
The Morph toast means the compaction input was compressed for OpenCode. Seeing OpenCode native compaction immediately after the toast is expected; that is the mechanism that persists the summary. The "Context: X tokens" number in the sidebar is based on OpenCode's stored assistant token usage, so it updates after OpenCode finishes compaction and/or after the next assistant response, not at the instant the Morph toast appears.
73
73
74
74
### Configuring the compaction threshold
75
75
76
-
By default, compaction triggers at **70% of the model's context window**. You can override this with a fixed token limit:
76
+
For non-native transform calls, the plugin uses a default threshold of **70% of the model's context window**. With a 1M token model, that is roughly 700k estimated tokens. You can override this with a fixed token limit:
You'll also see a toast notification in the OpenCode UI when compaction triggers.
106
+
You'll also see a toast notification in the OpenCode UI:
105
107
106
-
On subsequent LLM calls (before re-compaction is needed), you'll see:
108
+
```
109
+
Prepared OpenCode compaction with Morph (20% kept) | 244ms
110
+
```
111
+
112
+
If OpenCode native compaction is not involved and a future OpenCode version calls `experimental.chat.messages.transform` before normal LLM turns, the plugin still has the older proactive path. In that path, subsequent LLM calls can show:
107
113
108
114
```
109
115
INFO service=morph Under threshold - reusing frozen block. Messages: 5 -> 5
"Note: Morph compact plugin is installed, but MORPH_API_KEY is not configured.",
1527
+
);
1528
+
return;
1529
+
}
1530
+
1531
+
armNativeCompaction();
1399
1532
output.context.push(
1400
-
"Note: Morph compact plugin is active. Older messages may already be compressed.",
1533
+
"Morph compact plugin is active. The selected conversation history will be pre-compressed before this native compaction summary is generated. Treat any Morph-compressed history as authoritative and preserve concrete facts, file paths, commands, errors, constraints, decisions, and remaining work.",
1534
+
);
1535
+
1536
+
awaitlog(
1537
+
"info",
1538
+
"OpenCode native compaction triggered; Morph will pre-compress selected history and OpenCode will persist the summary.",
0 commit comments