opencode-clm 0.2.0 → 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/CHANGELOG.md +1 -1
- package/README.md +87 -66
- package/index.ts +753 -40
- package/package.json +6 -6
- package/src/budget.ts +166 -22
- package/src/channel.ts +187 -0
- package/src/clm.ts +478 -57
- package/src/compaction.ts +251 -0
- package/src/context-document.ts +2 -1
- package/src/continuity.ts +127 -1
- package/src/history.ts +109 -0
- package/src/mirror-store.ts +40 -2
- package/src/opencode.ts +59 -0
- package/src/overflow.ts +6 -3
- package/src/overrides.ts +13 -1
- package/src/panel/command.ts +8 -2
- package/src/panel/files.ts +4 -0
- package/src/panel/keys.ts +11 -1
- package/src/panel/model.ts +26 -2
- package/src/panel/timeline.ts +7 -1
- package/src/panel/view.ts +39 -10
- package/src/presentation.ts +8 -2
- package/src/projection.ts +8 -0
- package/src/session-files.ts +134 -32
- package/src/settings-table.ts +131 -17
- package/src/settings.ts +100 -5
- package/src/tui/complete.ts +102 -0
- package/src/tui/data.ts +89 -3
- package/src/tui/intercept.ts +10 -6
- package/src/tui/locator.ts +101 -0
- package/src/tui/panel.ts +14 -2
- package/src/tui/plugin.ts +222 -35
- package/src/tui/remote.ts +199 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
From 0.1.1 on, release notes are generated by git-cliff from Conventional Commits and
|
|
4
4
|
published on [GitHub Releases](https://github.com/bcmyguest/opencode-clm/releases).
|
|
5
5
|
|
|
6
|
-
## 0.1.0
|
|
6
|
+
## 0.1.0
|
|
7
7
|
|
|
8
8
|
First release: Context Language Model mode for OpenCode 1.18, ported from pi-clm 1.0.0.
|
|
9
9
|
|
package/README.md
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
# opencode-clm
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-clm)
|
|
4
|
+
[](https://github.com/bcmyguest/opencode-clm/actions/workflows/ci.yml)
|
|
5
|
+
|
|
3
6
|
```
|
|
4
7
|
____ _ __ __
|
|
5
8
|
/ ___| | | \/ |
|
|
6
9
|
| | | | | |\/| |
|
|
7
10
|
| |___| |___| | | |
|
|
8
|
-
\____|_____|_| |_|
|
|
11
|
+
\____|_____|_| |_|
|
|
12
|
+
|
|
13
|
+
opencode-clm
|
|
14
|
+
the agent that manages its own context
|
|
9
15
|
```
|
|
10
16
|
|
|
11
|
-
`opencode-clm` is an [OpenCode](https://opencode.ai) plugin that
|
|
12
|
-
|
|
13
|
-
model edits that file with its ordinary tools, and the edited
|
|
14
|
-
|
|
15
|
-
[pi-clm](https://github.com/lolipopshock/pi-clm)
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
`opencode-clm` is an [OpenCode](https://opencode.ai) plugin that lets the agent manage its
|
|
18
|
+
own context: before each request the plugin writes the conversation to a file, the
|
|
19
|
+
language model edits that file with its ordinary tools, and the edited version becomes its
|
|
20
|
+
next input. OpenCode's stored session stays unchanged. It ports
|
|
21
|
+
[pi-clm](https://github.com/lolipopshock/pi-clm), the Pi extension for the paper
|
|
22
|
+
[Context Language Models](https://arxiv.org/pdf/2609.37725) and its [research
|
|
23
|
+
codebase](https://github.com/facebookresearch/context-language-models).
|
|
18
24
|
|
|
19
25
|
## Install
|
|
20
26
|
|
|
21
|
-
Tested with OpenCode 1.18.34. The package holds two plugins, and OpenCode loads them from
|
|
22
|
-
two lists:
|
|
23
|
-
|
|
24
|
-
- the **server plugin** (`index.ts`) in `plugin` of `opencode.json`: the mirror, edits,
|
|
25
|
-
budget, tools, and the `/clm` and `/clm-compact` commands;
|
|
26
|
-
- the **TUI plugin** (`tui.ts`) in `plugin` of `tui.json`: the `/clm` panel.
|
|
27
|
-
|
|
28
27
|
```sh
|
|
29
|
-
opencode plugin opencode-clm # project:
|
|
28
|
+
opencode plugin opencode-clm # this project: .opencode/opencode.json and .opencode/tui.json
|
|
30
29
|
opencode plugin -g opencode-clm # global: opencode.json(c) and tui.json in ~/.config/opencode
|
|
31
30
|
```
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
The package holds two plugins: the server plugin (`index.ts`: mirror, edits, budget,
|
|
33
|
+
`/clm`, `/clm-compact`) and the TUI plugin (`tui.ts`: the `/clm` panel). Install both:
|
|
34
|
+
without the TUI plugin there is no panel, and each `/clm` command costs a model turn.
|
|
35
|
+
`opencode plugin` writes the spec to both files. By hand, add it to both `plugin` lists;
|
|
36
|
+
options go on the `opencode.json` entry only, and the TUI plugin reads them from there:
|
|
35
37
|
|
|
36
38
|
```jsonc
|
|
37
39
|
// opencode.json
|
|
@@ -40,40 +42,72 @@ files. To do it by hand, add `"opencode-clm"` to both lists:
|
|
|
40
42
|
{ "plugin": ["opencode-clm"] }
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
Options go on the `opencode.json` entry only; the TUI plugin finds that entry and reads
|
|
44
|
-
the same options (`mirrorDir` above all). It recognises `opencode-clm`,
|
|
45
|
-
`opencode-clm@<version or source>` (including the `opencode-clm@file:…` form `opencode
|
|
46
|
-
plugin` writes for a tarball), and `file://` URLs or paths that name this package or its
|
|
47
|
-
`index.ts`. From a local clone, use `file:///path/to/opencode-clm/index.ts` in
|
|
48
|
-
`opencode.json` and `file:///path/to/opencode-clm/tui.ts` in `tui.json`.
|
|
49
|
-
|
|
50
|
-
With the TUI plugin, a typed `/clm …` line runs in the TUI and costs no model turn: the
|
|
51
|
-
panel opens, or a toast answers, or the setting changes. Only `/clm reset` goes to the
|
|
52
|
-
server command. Without the TUI plugin (or with `opencode run --command clm`), the server
|
|
53
|
-
command answers `/clm` as text, which costs one model turn because OpenCode cannot cancel
|
|
54
|
-
a command. Version 0.1.0 on npm has the server plugin only; the panel and `/clm config`
|
|
55
|
-
arrive with 0.2.0.
|
|
56
|
-
|
|
57
45
|
## Quick start
|
|
58
46
|
|
|
59
47
|
| command | what it does |
|
|
60
48
|
|---------|--------------|
|
|
61
|
-
| `/clm` | open the panel: **overview** (context size per request
|
|
62
|
-
| `/clm
|
|
63
|
-
| `/clm
|
|
64
|
-
| `/clm
|
|
65
|
-
| `/clm
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
| `/clm` | open the panel: **overview** (context size per request + every accepted edit) <br><img src="https://raw.githubusercontent.com/bcmyguest/opencode-clm/main/.github/images/overview.png" alt="The overview page: context size per request, with the requests after which the model edited its context" width="720"> <br> **input** (what the next request contains) · **edits** (per-revision side-by-side diff) <br><img src="https://raw.githubusercontent.com/bcmyguest/opencode-clm/main/.github/images/edits.png" alt="The edits page: a tool result before and after the model shortened it" width="720"> |
|
|
50
|
+
| `/clm overview` / `input` / `edits` / `settings` | open the panel on that page (`timeline` and `edit` also work); without the TUI plugin, print it as text |
|
|
51
|
+
| `/clm status` | a toast: on or off, revision, last request size, budget, fixed overhead, last outcome; `mode notices-only` when set |
|
|
52
|
+
| `/clm config` | open **settings**; `/clm config <setting> <value>` changes one, `/clm config reset` drops this session's changes <br><img src="https://raw.githubusercontent.com/bcmyguest/opencode-clm/main/.github/images/settings.png" alt="The settings page: sizes, files, and every setting" width="720"> |
|
|
53
|
+
| `/clm-compact [instructions]` | ask the model to compact its own context now; anything you add (e.g. what to keep) is passed along. The result shows on the **edits** page |
|
|
54
|
+
| `/clm on` / `off` / `reset` / `path` | enable, use raw context, discard the accepted revision, show the mirror's path |
|
|
55
|
+
| `/clm budget [value]` | show or change the budget, the same as `/clm config budget`: a share of the model window (default `50%`), tokens (`64k`), or `window` |
|
|
56
|
+
| `/clm config mode notices-only` | keep the budget notices, reminders and overflow guard but take away editing: no mirror, no protocol prompt, raw history. For comparing "telling the model its budget" with "letting it edit"; `/clm config mode edit` switches back |
|
|
57
|
+
|
|
58
|
+
With the TUI plugin, typed `/clm …` lines run in the TUI and cost no model turn, and Tab
|
|
59
|
+
completes their subcommands, setting names and values;
|
|
60
|
+
`/clm reset` is handed to the server plugin, also without a turn. The right of the
|
|
61
|
+
session prompt shows `clm <size> / <budget> · r<revision>` (`~` before the size marks an
|
|
62
|
+
estimate the provider has not confirmed; `clm off · r<revision>` while CLM is off;
|
|
63
|
+
`clm notices-only <size> / <budget> · r<revision>` in notices-only mode).
|
|
64
|
+
|
|
65
|
+
In the panel: `1–4` or `Tab` switch pages, `← →` step through the overview's markers or
|
|
66
|
+
the edits page's revisions, `z` zooms the chart, `Enter` opens the selection, `r`
|
|
67
|
+
reloads, `q` closes.
|
|
68
|
+
|
|
69
|
+
## Benchmarks
|
|
70
|
+
|
|
71
|
+
These numbers come from one machine (AMD Strix Halo, gfx1151, Vulkan) running
|
|
72
|
+
Qwen3.8-Flash-Next (UD-IQ4_XS) through lemonade, on a llama.cpp build with an
|
|
73
|
+
unreleased patch that ports the paper's
|
|
74
|
+
[Suffix Cache Reuse](https://github.com/facebookresearch/context-language-models/tree/main/suffix_cache_reuse)
|
|
75
|
+
(an SGLang patch) to llama.cpp's hybrid models. On a stock server, an edit re-prefills
|
|
76
|
+
everything after the first changed token.
|
|
77
|
+
|
|
78
|
+
**GSM8K, 50 test problems, edited prompt.** Each problem is primed with an 8-shot prompt
|
|
79
|
+
holding three stale worked examples, then asked again with that block replaced by a
|
|
80
|
+
one-line note, mirroring a CLM edit. Temperature 0, thinking off.
|
|
81
|
+
|
|
82
|
+
| | reuse after the edit | full prefill |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| accuracy | 48/50 | 49/50 |
|
|
85
|
+
| median tokens prefilled | 23 | 1,362 |
|
|
86
|
+
| median prompt time | 0.51 s | 5.02 s |
|
|
87
|
+
| median request time | 3.1 s | 7.2 s |
|
|
88
|
+
|
|
89
|
+
**A live OpenCode session** with opencode-clm 0.2.0 (48k budget, auto-compaction off)
|
|
90
|
+
read and summarised every file under `src/` and `test/` of this repository and wrote its
|
|
91
|
+
notes: 49 requests, 16 accepted edits, 0 rejected. The server reused cache after 23 edits
|
|
92
|
+
and prefilled 11,240 tokens in total, where a prefix-only cache would have prefilled
|
|
93
|
+
214,585 (95% less); requests of 20–48k tokens prefilled 34–3,523 tokens each.
|
|
94
|
+
|
|
95
|
+
**Nine agent tasks in OpenCode** (find and fix, opencode-clm 0.3.0, 1 run each), CLM
|
|
96
|
+
at a 32k budget vs CLM off: both solved 9/9; CLM took 55.5 s per task vs 91.3 s and
|
|
97
|
+
prefilled 2,868 tokens vs 7,317 on average. CLM accepted only 1 edit in 9 runs because no
|
|
98
|
+
task came near the budget, so most of the gain looks behavioural: told its budget, the
|
|
99
|
+
model makes fewer tool calls. One CLM run read files outside its workspace and is not
|
|
100
|
+
comparable.
|
|
101
|
+
|
|
102
|
+
Flash-Next was not trained for CLM, so it makes more edit mistakes than the paper's
|
|
103
|
+
trained models. Hosted APIs are untested.
|
|
70
104
|
|
|
71
105
|
## Docs
|
|
72
106
|
|
|
73
|
-
- [How it works](docs/how-it-works.md)
|
|
74
|
-
- [Configuration](docs/configuration.md)
|
|
75
|
-
- [Architecture](docs/architecture.md)
|
|
76
|
-
- [Development](docs/development.md)
|
|
107
|
+
- [How it works](docs/how-it-works.md) — the mirror, what runs without the model, the panel, model and server support, safety.
|
|
108
|
+
- [Configuration](docs/configuration.md) — every setting (editing, budget, reserve, reminders, reminder-cooldown, gate, guard, compaction, cap, steering, mode, one-tool, trailer, compact-prompt, reasoning), plugin options and environment variables.
|
|
109
|
+
- [Architecture](docs/architecture.md) — modules, session files, design notes, known limitations.
|
|
110
|
+
- [Development](docs/development.md) — setup, checks, the integration suites, releasing.
|
|
77
111
|
|
|
78
112
|
## Citation
|
|
79
113
|
|
|
@@ -94,27 +128,14 @@ If you use opencode-clm in your research, please cite
|
|
|
94
128
|
## Credits
|
|
95
129
|
|
|
96
130
|
- [pi-clm](https://github.com/lolipopshock/pi-clm) 1.0.0 (MIT, Copyright 2026 Emanuel
|
|
97
|
-
Casco): the design and most of the code derive from it, the `/clm` panel included
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
[NOTICE](NOTICE) lists the files; [LICENSE](LICENSE) carries pi-clm's notice.
|
|
106
|
-
- Context Language Models, [arXiv 2609.37725](https://arxiv.org/abs/2609.37725), and
|
|
107
|
-
[facebookresearch/context-language-models](https://github.com/facebookresearch/context-language-models)
|
|
108
|
-
(CC BY-NC 4.0). This package copies no text from that repository (normalized 5-gram
|
|
109
|
-
check: no shared span over 6 tokens). The `fit` / `shrink` edit gate and the default
|
|
110
|
-
25/50/75% reminder steps follow its harness design, and the edit-cost advice in the
|
|
111
|
-
skill, inherited from pi-clm, covers the same points as the harness prompt in different
|
|
112
|
-
words. This package is not licensed under CC BY-NC and is not endorsed by its authors.
|
|
113
|
-
|
|
114
|
-
## AI assistance
|
|
115
|
-
|
|
116
|
-
Claude Code (Claude Opus) wrote the code and documentation in this repository. The
|
|
117
|
-
maintainer has not hand-reviewed them.
|
|
131
|
+
Casco): the design and most of the code derive from it, the `/clm` panel included, and
|
|
132
|
+
most model-facing text is adapted from it. [NOTICE](NOTICE) lists the files.
|
|
133
|
+
- [facebookresearch/context-language-models](https://github.com/facebookresearch/context-language-models)
|
|
134
|
+
(CC BY-NC 4.0): this package copies no text from it; the `fit` / `shrink` edit gate and
|
|
135
|
+
the default 25/50/75% reminder steps follow its harness design. This package is not
|
|
136
|
+
licensed under CC BY-NC and is not endorsed by its authors.
|
|
137
|
+
- Claude Code (Claude Opus) wrote the code and documentation; the maintainer has not
|
|
138
|
+
hand-reviewed them.
|
|
118
139
|
|
|
119
140
|
## License
|
|
120
141
|
|