openclaw-topic-shift-reset 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # openclaw-topic-shift-reset
2
+
3
+ OpenClaw plugin that detects topic shifts and rotates to a fresh session automatically.
4
+
5
+ ## Quick start config
6
+
7
+ Most users should only set these fields:
8
+
9
+ ```json
10
+ {
11
+ "plugins": {
12
+ "entries": {
13
+ "openclaw-topic-shift-reset": {
14
+ "enabled": true,
15
+ "config": {
16
+ "enabled": true,
17
+ "preset": "balanced",
18
+ "embeddings": "auto",
19
+ "handoff": "summary",
20
+ "dryRun": true,
21
+ "debug": true
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ Then:
30
+
31
+ 1. Run with `dryRun: true` and `debug: true`.
32
+ 2. Send normal messages on one topic.
33
+ 3. Switch to a clearly different topic.
34
+ 4. Watch logs for `classify`, `suspect`, `rotate-hard`/`rotate-soft`, `dry-run rotate`.
35
+ 5. Set `dryRun: false` when behavior looks good.
36
+
37
+ ## Presets
38
+
39
+ - `conservative`: fewer resets, more confirmation
40
+ - `balanced`: default
41
+ - `aggressive`: faster/more sensitive resets
42
+
43
+ Default preset internals:
44
+
45
+ | Key | conservative | balanced | aggressive |
46
+ | --- | --- | --- | --- |
47
+ | `historyWindow` | `12` | `10` | `8` |
48
+ | `minHistoryMessages` | `4` | `3` | `2` |
49
+ | `minMeaningfulTokens` | `7` | `6` | `5` |
50
+ | `softConsecutiveSignals` | `3` | `2` | `1` |
51
+ | `cooldownMinutes` | `10` | `5` | `2` |
52
+ | `softScoreThreshold` | `0.80` | `0.72` | `0.64` |
53
+ | `hardScoreThreshold` | `0.92` | `0.86` | `0.78` |
54
+
55
+ ## Embeddings
56
+
57
+ `embeddings` supports:
58
+
59
+ - `auto` (default)
60
+ - `openai`
61
+ - `ollama`
62
+ - `none` (lexical only)
63
+
64
+ ## Install locally
65
+
66
+ ```bash
67
+ openclaw plugins install --link ~/Projects/openclaw-topic-shift-reset
68
+ openclaw plugins enable openclaw-topic-shift-reset
69
+ openclaw plugins info openclaw-topic-shift-reset
70
+ ```
71
+
72
+ Restart gateway after install/config changes.
73
+
74
+ ## Logs
75
+
76
+ ```bash
77
+ openclaw logs --follow --plain | rg topic-shift-reset
78
+ ```
79
+
80
+ ## Advanced tuning
81
+
82
+ Use `config.advanced` only if needed. Full reference:
83
+
84
+ - `docs/configuration.md`
85
+
86
+ Tuning keys must be inside `advanced`; top-level tuning keys are rejected by schema validation.
87
+
88
+ Common guardrail for short acknowledgments:
89
+
90
+ ```json
91
+ {
92
+ "advanced": {
93
+ "minSignalChars": 20,
94
+ "minSignalTokenCount": 3,
95
+ "minSignalEntropy": 1.2,
96
+ "stripEnvelope": true
97
+ }
98
+ }
99
+ ```
100
+
101
+ This skips classification for very short/low-information messages (for example `ok`, `gracias`, `por favor`).
102
+
103
+ ## Local development
104
+
105
+ No build step is required. OpenClaw loads `src/index.ts` via jiti.
106
+
107
+ ## Publish
108
+
109
+ ```bash
110
+ cd ~/Projects/openclaw-topic-shift-reset
111
+ npm publish
112
+ npm view openclaw-topic-shift-reset version --userconfig "$(mktemp)"
113
+ ```
114
+
115
+ ## Known tradeoff (plugin-only)
116
+
117
+ This plugin improves timing with fast path + fallback, but cannot guarantee 100% that the triggering message becomes the first persisted message of the new session without core pre-session hooks.
@@ -0,0 +1,149 @@
1
+ # Configuration
2
+
3
+ ## Recommended public config
4
+
5
+ Use this minimal config for normal users:
6
+
7
+ ```json
8
+ {
9
+ "enabled": true,
10
+ "preset": "balanced",
11
+ "embeddings": "auto",
12
+ "handoff": "summary",
13
+ "dryRun": false,
14
+ "debug": false
15
+ }
16
+ ```
17
+
18
+ ## Public options
19
+
20
+ - `enabled`: turn plugin behavior on/off.
21
+ - `preset`: `conservative | balanced | aggressive`.
22
+ - `embeddings`: `auto | openai | ollama | none`.
23
+ - `handoff`: `none | summary | verbatim`.
24
+ - `dryRun`: if `true`, logs decisions but never rotates sessions.
25
+ - `debug`: if `true`, emits per-message metrics logs.
26
+
27
+ ## Built-in presets defaults
28
+
29
+ `preset` controls the classifier layer. These are the built-in defaults:
30
+
31
+ | Key | conservative | balanced (default) | aggressive |
32
+ | --- | --- | --- | --- |
33
+ | `historyWindow` | `12` | `10` | `8` |
34
+ | `minHistoryMessages` | `4` | `3` | `2` |
35
+ | `minMeaningfulTokens` | `7` | `6` | `5` |
36
+ | `minTokenLength` | `2` | `2` | `2` |
37
+ | `softConsecutiveSignals` | `3` | `2` | `1` |
38
+ | `cooldownMinutes` | `10` | `5` | `2` |
39
+ | `softScoreThreshold` | `0.80` | `0.72` | `0.64` |
40
+ | `hardScoreThreshold` | `0.92` | `0.86` | `0.78` |
41
+ | `softSimilarityThreshold` | `0.30` | `0.36` | `0.46` |
42
+ | `hardSimilarityThreshold` | `0.18` | `0.24` | `0.34` |
43
+ | `softNoveltyThreshold` | `0.66` | `0.58` | `0.48` |
44
+ | `hardNoveltyThreshold` | `0.80` | `0.74` | `0.60` |
45
+
46
+ ## Shared defaults
47
+
48
+ These defaults apply in all presets unless overridden:
49
+
50
+ - `handoff`: `summary`
51
+ - `handoffLastN`: `6`
52
+ - `handoffMaxChars`: `220`
53
+ - `embeddings`: `auto`
54
+ - `embedding.timeoutMs`: `7000`
55
+ - `minSignalChars`: `20`
56
+ - `minSignalTokenCount`: `3`
57
+ - `minSignalEntropy`: `1.2`
58
+ - `stripEnvelope`: `true`
59
+
60
+ ## Advanced overrides
61
+
62
+ The runtime resolves config in this order:
63
+
64
+ 1. Built-in preset defaults.
65
+ 2. Shared defaults.
66
+ 3. `advanced` overrides (only the keys you set).
67
+
68
+ Power users can override behavior via `advanced`:
69
+
70
+ ```json
71
+ {
72
+ "preset": "balanced",
73
+ "advanced": {
74
+ "cooldownMinutes": 3,
75
+ "minSignalEntropy": 1.4,
76
+ "softConsecutiveSignals": 2,
77
+ "softScoreThreshold": 0.7,
78
+ "hardScoreThreshold": 0.84,
79
+ "handoffLastN": 5,
80
+ "embedding": {
81
+ "model": "text-embedding-3-small",
82
+ "timeoutMs": 7000
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ Advanced keys:
89
+
90
+ - `historyWindow`
91
+ - `minHistoryMessages`
92
+ - `minMeaningfulTokens`
93
+ - `minTokenLength`
94
+ - `minSignalChars`
95
+ - `minSignalTokenCount`
96
+ - `minSignalEntropy`
97
+ - `stripEnvelope`
98
+ - `softConsecutiveSignals`
99
+ - `cooldownMinutes`
100
+ - `softScoreThreshold`
101
+ - `hardScoreThreshold`
102
+ - `softSimilarityThreshold`
103
+ - `hardSimilarityThreshold`
104
+ - `softNoveltyThreshold`
105
+ - `hardNoveltyThreshold`
106
+ - `ignoredProviders`
107
+ - `handoff`
108
+ - `handoffLastN`
109
+ - `handoffMaxChars`
110
+ - `embeddings`
111
+ - `embedding.provider`
112
+ - `embedding.model`
113
+ - `embedding.baseUrl`
114
+ - `embedding.apiKey`
115
+ - `embedding.timeoutMs`
116
+
117
+ Notes:
118
+
119
+ - Top-level public keys stay minimal: `enabled`, `preset`, `embeddings`, `handoff`, `dryRun`, `debug`.
120
+ - Tuning keys outside `advanced` are rejected by config schema validation.
121
+
122
+ ## Log interpretation
123
+
124
+ Classifier logs look like:
125
+
126
+ `topic-shift-reset: classify source=<fast|fallback> kind=<...> reason=<...> ...`
127
+
128
+ Kinds:
129
+
130
+ - `warmup`: not enough baseline history yet.
131
+ - `stable`: no shift action.
132
+ - `suspect`: first soft signal; waiting confirmation.
133
+ - `rotate-hard`: immediate reset trigger.
134
+ - `rotate-soft`: soft signal confirmed.
135
+
136
+ Reasons:
137
+
138
+ - `warmup`
139
+ - `stable`
140
+ - `cooldown`
141
+ - `skip-low-signal`
142
+ - `soft-suspect`
143
+ - `soft-confirmed`
144
+ - `hard-threshold`
145
+
146
+ Other lines:
147
+
148
+ - `dry-run rotate`: would have rotated, but `dryRun=true`.
149
+ - `rotated`: actual session rotation happened.
@@ -0,0 +1,217 @@
1
+ {
2
+ "id": "openclaw-topic-shift-reset",
3
+ "name": "Topic Shift Reset",
4
+ "description": "Detects subject shifts and rotates to a fresh OpenClaw session with optional context handoff.",
5
+ "configSchema": {
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "enabled": {
10
+ "type": "boolean",
11
+ "default": true
12
+ },
13
+ "preset": {
14
+ "type": "string",
15
+ "enum": ["conservative", "balanced", "aggressive"],
16
+ "default": "balanced"
17
+ },
18
+ "embeddings": {
19
+ "type": "string",
20
+ "enum": ["auto", "none", "openai", "ollama"],
21
+ "default": "auto"
22
+ },
23
+ "handoff": {
24
+ "type": "string",
25
+ "enum": ["none", "summary", "verbatim"],
26
+ "default": "summary"
27
+ },
28
+ "dryRun": {
29
+ "type": "boolean",
30
+ "default": false
31
+ },
32
+ "debug": {
33
+ "type": "boolean",
34
+ "default": false
35
+ },
36
+ "advanced": {
37
+ "type": "object",
38
+ "additionalProperties": false,
39
+ "properties": {
40
+ "historyWindow": {
41
+ "type": "integer",
42
+ "minimum": 2,
43
+ "maximum": 40,
44
+ "default": 10
45
+ },
46
+ "minHistoryMessages": {
47
+ "type": "integer",
48
+ "minimum": 1,
49
+ "maximum": 30,
50
+ "default": 3
51
+ },
52
+ "minMeaningfulTokens": {
53
+ "type": "integer",
54
+ "minimum": 2,
55
+ "maximum": 60,
56
+ "default": 6
57
+ },
58
+ "minTokenLength": {
59
+ "type": "integer",
60
+ "minimum": 1,
61
+ "maximum": 8,
62
+ "default": 2
63
+ },
64
+ "minSignalChars": {
65
+ "type": "integer",
66
+ "minimum": 1,
67
+ "maximum": 500,
68
+ "default": 20
69
+ },
70
+ "minSignalTokenCount": {
71
+ "type": "integer",
72
+ "minimum": 1,
73
+ "maximum": 60,
74
+ "default": 3
75
+ },
76
+ "minSignalEntropy": {
77
+ "type": "number",
78
+ "minimum": 0,
79
+ "maximum": 8,
80
+ "default": 1.2
81
+ },
82
+ "stripEnvelope": {
83
+ "type": "boolean",
84
+ "default": true
85
+ },
86
+ "softConsecutiveSignals": {
87
+ "type": "integer",
88
+ "minimum": 1,
89
+ "maximum": 4,
90
+ "default": 2
91
+ },
92
+ "cooldownMinutes": {
93
+ "type": "integer",
94
+ "minimum": 0,
95
+ "maximum": 240,
96
+ "default": 5
97
+ },
98
+ "softScoreThreshold": {
99
+ "type": "number",
100
+ "minimum": 0,
101
+ "maximum": 1,
102
+ "default": 0.72
103
+ },
104
+ "hardScoreThreshold": {
105
+ "type": "number",
106
+ "minimum": 0,
107
+ "maximum": 1,
108
+ "default": 0.86
109
+ },
110
+ "softSimilarityThreshold": {
111
+ "type": "number",
112
+ "minimum": 0,
113
+ "maximum": 1,
114
+ "default": 0.36
115
+ },
116
+ "hardSimilarityThreshold": {
117
+ "type": "number",
118
+ "minimum": 0,
119
+ "maximum": 1,
120
+ "default": 0.24
121
+ },
122
+ "softNoveltyThreshold": {
123
+ "type": "number",
124
+ "minimum": 0,
125
+ "maximum": 1,
126
+ "default": 0.58
127
+ },
128
+ "hardNoveltyThreshold": {
129
+ "type": "number",
130
+ "minimum": 0,
131
+ "maximum": 1,
132
+ "default": 0.74
133
+ },
134
+ "ignoredProviders": {
135
+ "type": "array",
136
+ "items": {
137
+ "type": "string"
138
+ },
139
+ "default": []
140
+ },
141
+ "handoff": {
142
+ "type": "string",
143
+ "enum": ["none", "summary", "verbatim", "verbatim_last_n"]
144
+ },
145
+ "handoffLastN": {
146
+ "type": "integer",
147
+ "minimum": 1,
148
+ "maximum": 20,
149
+ "default": 6
150
+ },
151
+ "handoffMaxChars": {
152
+ "type": "integer",
153
+ "minimum": 60,
154
+ "maximum": 800,
155
+ "default": 220
156
+ },
157
+ "embeddings": {
158
+ "type": "string",
159
+ "enum": ["auto", "none", "openai", "ollama"]
160
+ },
161
+ "embedding": {
162
+ "type": "object",
163
+ "additionalProperties": false,
164
+ "properties": {
165
+ "provider": {
166
+ "type": "string",
167
+ "enum": ["auto", "none", "openai", "ollama"],
168
+ "default": "auto"
169
+ },
170
+ "model": {
171
+ "type": "string"
172
+ },
173
+ "baseUrl": {
174
+ "type": "string"
175
+ },
176
+ "apiKey": {
177
+ "type": "string"
178
+ },
179
+ "timeoutMs": {
180
+ "type": "integer",
181
+ "minimum": 1000,
182
+ "maximum": 30000,
183
+ "default": 7000
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ },
191
+ "uiHints": {
192
+ "preset": {
193
+ "label": "Behavior Preset",
194
+ "help": "conservative = fewer resets, balanced = default, aggressive = faster resets."
195
+ },
196
+ "embeddings": {
197
+ "label": "Embeddings",
198
+ "help": "auto uses whichever embedding backend your instance already has configured."
199
+ },
200
+ "handoff": {
201
+ "label": "Context Handoff",
202
+ "help": "summary keeps transitions transparent without copying full transcript."
203
+ },
204
+ "dryRun": {
205
+ "label": "Dry Run",
206
+ "help": "Only log decisions; do not rotate sessions."
207
+ },
208
+ "debug": {
209
+ "label": "Debug Logs",
210
+ "help": "Emit per-message classifier metrics."
211
+ },
212
+ "advanced": {
213
+ "label": "Advanced Overrides",
214
+ "help": "Optional expert tuning. Leave empty for preset behavior."
215
+ }
216
+ }
217
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "openclaw-topic-shift-reset",
3
+ "version": "0.1.0",
4
+ "description": "OpenClaw plugin that detects topic shifts and starts a fresh session automatically.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "openclaw.plugin.json",
13
+ "README.md",
14
+ "docs",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "echo 'No build required. OpenClaw loads src/index.ts via jiti.'",
19
+ "dev": "echo 'No watch build required.'",
20
+ "prepack": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "openclaw",
24
+ "plugin",
25
+ "session",
26
+ "topic-shift"
27
+ ],
28
+ "license": "MIT",
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "peerDependencies": {
33
+ "openclaw": ">=2026.2.18"
34
+ },
35
+ "openclaw": {
36
+ "extensions": [
37
+ "./src/index.ts"
38
+ ]
39
+ }
40
+ }