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 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 (unreleased)
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
+ [![npm](https://img.shields.io/npm/v/opencode-clm)](https://www.npmjs.com/package/opencode-clm)
4
+ [![CI](https://github.com/bcmyguest/opencode-clm/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bcmyguest/opencode-clm/actions/workflows/ci.yml)
5
+
3
6
  ```
4
7
  ____ _ __ __
5
8
  / ___| | | \/ |
6
9
  | | | | | |\/| |
7
10
  | |___| |___| | | |
8
- \____|_____|_| |_| opencode-clm: the model manages its own context in OpenCode
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 runs a model as a Context
12
- Language Model. Before each request the plugin writes the conversation to a text file; the
13
- model edits that file with its ordinary tools, and the edited text is what it receives on
14
- the next request. OpenCode's stored session stays unchanged. It ports
15
- [pi-clm](https://github.com/lolipopshock/pi-clm) 1.0.0, the Pi extension that accompanies
16
- the paper [Context Language Models](https://arxiv.org/abs/2609.37725).
17
- [PORTING.md](PORTING.md) maps each pi-clm file to its counterpart here.
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: adds it to .opencode/opencode.json and .opencode/tui.json
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
- `opencode plugin` detects both targets from the package and writes the spec to both
34
- files. To do it by hand, add `"opencode-clm"` to both lists:
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, fixed overhead and usable budget, every accepted edit) <br><img src=".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 will contain) · **edits** (each revision, message by message, with a side-by-side diff) <br><img src=".github/images/edits.png" alt="The edits page: a tool result before and after the model shortened it" width="720"> |
62
- | `/clm status` | a toast: CLM on or off, revision, last request size, budget, fixed overhead, last outcome (the server command's text adds the changed settings) |
63
- | `/clm config` | open **settings**; `/clm config <setting> <value>` changes one, `/clm config reset` drops this session's changes <br><img src=".github/images/settings.png" alt="The settings page: sizes, files, and every setting" width="720"> |
64
- | `/clm-compact [instructions]` | ask the model to compact its context now; text you add (what to keep, for example) goes into the prompt. The result shows on the **edits** page |
65
- | `/clm on` / `off` / `reset` | apply edits or send the raw history for this session (the `editing` setting); `reset` drops the accepted revision (server command, one model turn) |
66
-
67
- In the panel: `1–4` or `Tab` switch pages, `← →` step through the overview's list
68
- (edits, rejections, resets, compactions, now) or the edits page's revisions, `z` zooms
69
- the chart, `Enter` opens the selection, `r` reloads, `q` closes.
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): the mirror, edits, the budget, compaction, the panel, safety.
74
- - [Configuration](docs/configuration.md): sizing the budget, every setting and its environment variable, `/clm config`.
75
- - [Architecture](docs/architecture.md): modules, session files, design notes, known limitations.
76
- - [Development](docs/development.md): setup, checks, the integration suites, releasing.
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
- (`src/panel/timeline.ts`, `src/panel/diff.ts` and the page layouts in
99
- `src/panel/view.ts` port its `timeline.ts`, `diff.ts` and `viewer.ts`). Model-facing text
100
- taken from pi-clm, adapted: the compaction prompt (`src/compact.ts`), the `clm-context`
101
- skill, the budget notices, the mirror rejection and receipt messages, and the overflow
102
- and observation notes. `steering/house-brief.md` is byte-identical to pi-clm's. Written
103
- for this package: the system-prompt protocol section (`src/presentation.ts`), the
104
- edit-gate refusal note, and the plugin's own receipts, commands and tool descriptions.
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