smart-compaction 0.2.0 → 0.2.2
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 +21 -7
- package/index.js +20 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,19 +87,33 @@ installs cleanly and just reports `available: false` instead of erroring.
|
|
|
87
87
|
|
|
88
88
|
### Tell the model when to use it
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
This is baked into both tools' own descriptions, so it works out of the box with no setup: each
|
|
91
|
+
tool's description tells the model to check `context_status` right after finishing a
|
|
92
|
+
self-contained step (e.g. right after `todo_write` marks an item `completed`) and to follow up
|
|
93
|
+
with `compact_now` once usage climbs past roughly 70-90%. Since both descriptions are sent to the
|
|
94
|
+
model on every request automatically, no `AGENTS.md` edit is required for this behavior — unlike
|
|
95
|
+
an early version of this plugin, which relied entirely on a hand-written `AGENTS.md` rule and
|
|
96
|
+
(measured directly against real session logs) got essentially no organic use as a result: the
|
|
97
|
+
description alone wasn't a strong enough signal.
|
|
98
|
+
|
|
99
|
+
That said, standing instructions carry more weight than a tool description competing against
|
|
100
|
+
everything else in a long tool catalog. If you want to reinforce it further, copy
|
|
101
|
+
[`agents-snippet.md`](./agents-snippet.md) into your `AGENTS.md` (or whatever your profile injects
|
|
102
|
+
as standing instructions).
|
|
97
103
|
|
|
98
104
|
Tying this to todo-completion matters: it's a real, already-tracked signal for "I just finished a
|
|
99
105
|
self-contained unit of work," instead of asking the model to estimate its own remaining work or
|
|
100
106
|
guess whether a conversation "feels long," both of which it's generally bad at. `context_status`
|
|
101
107
|
replaces that guess with the real number.
|
|
102
108
|
|
|
109
|
+
The snippet deliberately does *not* say "compact once usage crosses 70-80%" as the primary rule —
|
|
110
|
+
a threshold check alone is still reactive: a step that turns out bigger than expected (a large
|
|
111
|
+
file, a long diff, a subagent dispatch) can blow straight past a comfortable-looking percentage
|
|
112
|
+
*during* that step, which is exactly the mid-step interruption this plugin exists to avoid. The
|
|
113
|
+
percentage is kept only as a hard backstop; the primary check is comparing remaining headroom
|
|
114
|
+
against the size of the step about to start, and compacting early — before that step, not during
|
|
115
|
+
or after it — whenever the fit looks tight.
|
|
116
|
+
|
|
103
117
|
## Building from source
|
|
104
118
|
|
|
105
119
|
Requires Node 22+. Plain JS, no build step — `git clone`, `pnpm install`, done.
|
package/index.js
CHANGED
|
@@ -33,8 +33,15 @@ const DESCRIPTION =
|
|
|
33
33
|
'Voluntarily compact older conversation history now, at a point you know is safe: '
|
|
34
34
|
+ 'right after finishing a concrete step (e.g. just marked a todo item completed), '
|
|
35
35
|
+ 'never mid-edit or with unfinished work pending. Use this instead of waiting to be '
|
|
36
|
-
+ 'interrupted by automatic compaction
|
|
37
|
-
+ '
|
|
36
|
+
+ 'interrupted by automatic compaction. Do not decide this only by checking whether usage '
|
|
37
|
+
+ 'is already past a fixed percentage — that is still reactive, and a step that turns out '
|
|
38
|
+
+ 'bigger than expected can blow past a comfortable-looking number mid-step. Before '
|
|
39
|
+
+ 'starting the next step, weigh how much room is left against what that step will '
|
|
40
|
+
+ 'actually cost (a big file read, a long diff, a subagent dispatch); if it is not clearly '
|
|
41
|
+
+ 'going to fit with room to spare, call this now even while usage still looks moderate. '
|
|
42
|
+
+ 'Compacting a little early costs nothing; running out mid-step loses exactly the context '
|
|
43
|
+
+ 'that step needed. Call context_status first if unsure how much room is actually left. '
|
|
44
|
+
+ 'Harmless to call speculatively either way — it no-ops if there is not enough history to '
|
|
38
45
|
+ 'compact yet.'
|
|
39
46
|
|
|
40
47
|
/**
|
|
@@ -125,11 +132,17 @@ export function apply(ctx) {
|
|
|
125
132
|
const CONTEXT_STATUS_DESCRIPTION =
|
|
126
133
|
'Check real, current context-window usage for this session: tokens used so far and the '
|
|
127
134
|
+ 'model\'s actual context-window size, whatever model this session happens to be running. '
|
|
128
|
-
+ '
|
|
129
|
-
+ '
|
|
130
|
-
+ '
|
|
131
|
-
+ '
|
|
132
|
-
+ '
|
|
135
|
+
+ 'Call this right after finishing any self-contained step — e.g. right after todo_write '
|
|
136
|
+
+ 'marks an item completed, never mid-edit or with unfinished work pending — instead of '
|
|
137
|
+
+ 'guessing whether the conversation "feels long." Use the result to judge whether what is '
|
|
138
|
+
+ 'left is enough for the next step specifically (a big file read, a long diff, a subagent '
|
|
139
|
+
+ 'dispatch), not just whether percentUsed has crossed some fixed number — a step that '
|
|
140
|
+
+ 'turns out larger than expected can still blow past a comfortable-looking percentage. '
|
|
141
|
+
+ 'When in doubt, call compact_now before starting that next step rather than after it runs '
|
|
142
|
+
+ 'into trouble: as a hard backstop, treat anything past roughly 70-90% (depending on '
|
|
143
|
+
+ 'profile config) as reason enough on its own, but do not wait for that number if the next '
|
|
144
|
+
+ 'step alone looks likely to use it up. Harmless to call anytime — read-only, never '
|
|
145
|
+
+ 'modifies the session.'
|
|
133
146
|
|
|
134
147
|
function renderContextStatus(value) {
|
|
135
148
|
if (!value.available) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smart-compaction",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "dsh plugin: a compact_now tool letting the model trigger compaction itself at a safe point, plus a context_status tool so it can check real token usage against its context window, instead of only the automatic token-threshold trigger.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|