smart-compaction 0.2.1 → 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 +11 -7
- package/index.js +19 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,19 +97,23 @@ an early version of this plugin, which relied entirely on a hand-written `AGENTS
|
|
|
97
97
|
description alone wasn't a strong enough signal.
|
|
98
98
|
|
|
99
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,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
> After marking a todo item `completed` (never while one is `in_progress`), call `context_status`.
|
|
104
|
-
> If usage is climbing past roughly 70-80% of the context window, call `compact_now` too. Both are
|
|
105
|
-
> safe to call speculatively — `context_status` is read-only, and `compact_now` no-ops if there
|
|
106
|
-
> isn't enough history to compact yet.
|
|
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).
|
|
107
103
|
|
|
108
104
|
Tying this to todo-completion matters: it's a real, already-tracked signal for "I just finished a
|
|
109
105
|
self-contained unit of work," instead of asking the model to estimate its own remaining work or
|
|
110
106
|
guess whether a conversation "feels long," both of which it's generally bad at. `context_status`
|
|
111
107
|
replaces that guess with the real number.
|
|
112
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
|
+
|
|
113
117
|
## Building from source
|
|
114
118
|
|
|
115
119
|
Requires Node 22+. Plain JS, no build step — `git clone`, `pnpm install`, done.
|
package/index.js
CHANGED
|
@@ -33,12 +33,16 @@ 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
|
-
+ 'is a
|
|
38
|
-
+ '
|
|
39
|
-
+ '
|
|
40
|
-
+ '
|
|
41
|
-
+ '
|
|
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 '
|
|
45
|
+
+ 'compact yet.'
|
|
42
46
|
|
|
43
47
|
/**
|
|
44
48
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
@@ -130,11 +134,15 @@ const CONTEXT_STATUS_DESCRIPTION =
|
|
|
130
134
|
+ 'model\'s actual context-window size, whatever model this session happens to be running. '
|
|
131
135
|
+ 'Call this right after finishing any self-contained step — e.g. right after todo_write '
|
|
132
136
|
+ 'marks an item completed, never mid-edit or with unfinished work pending — instead of '
|
|
133
|
-
+ 'guessing whether the conversation "feels long."
|
|
134
|
-
+ '
|
|
135
|
-
+ '
|
|
136
|
-
+ '
|
|
137
|
-
+ '
|
|
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.'
|
|
138
146
|
|
|
139
147
|
function renderContextStatus(value) {
|
|
140
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",
|