openclaw-topic-shift-reset 0.4.2 → 0.4.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +13 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-topic-shift-reset",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "OpenClaw plugin that detects topic shifts and starts a fresh session automatically.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/index.ts CHANGED
@@ -1252,8 +1252,9 @@ function classifyMessage(params: {
1252
1252
  now: number;
1253
1253
  }): ClassificationDecision {
1254
1254
  const { cfg, state, now } = params;
1255
+ const hasSimilarity = params.usedEmbedding && typeof params.similarity === "number";
1255
1256
  const score =
1256
- params.usedEmbedding && typeof params.similarity === "number"
1257
+ hasSimilarity
1257
1258
  ? 0.7 * (1 - params.similarity) +
1258
1259
  0.15 * params.lexical.lexicalDistance +
1259
1260
  0.15 * params.lexical.novelty
@@ -1281,21 +1282,25 @@ function classifyMessage(params: {
1281
1282
  return { kind: "stable", metrics, reason: "cooldown" };
1282
1283
  }
1283
1284
 
1285
+ const lexicalHardSignal =
1286
+ params.lexical.score >= cfg.hardScoreThreshold ||
1287
+ (params.lexical.novelty >= cfg.hardNoveltyThreshold &&
1288
+ params.lexical.lexicalDistance >= 0.65);
1284
1289
  const hardSignal =
1285
- score >= cfg.hardScoreThreshold ||
1286
- (params.usedEmbedding && typeof params.similarity === "number"
1287
- ? params.similarity <= cfg.hardSimilarityThreshold &&
1288
- params.lexical.novelty >= cfg.hardNoveltyThreshold
1289
- : params.lexical.novelty >= cfg.hardNoveltyThreshold &&
1290
- params.lexical.lexicalDistance >= 0.65);
1290
+ hasSimilarity &&
1291
+ (score >= cfg.hardScoreThreshold ||
1292
+ (params.similarity <= cfg.hardSimilarityThreshold &&
1293
+ params.lexical.novelty >= cfg.hardNoveltyThreshold));
1291
1294
 
1292
1295
  if (hardSignal) {
1293
1296
  return { kind: "rotate-hard", metrics, reason: "hard-threshold" };
1294
1297
  }
1295
1298
 
1299
+ const forceSoftPathFromLexicalHard = !hasSimilarity && lexicalHardSignal;
1296
1300
  const softSignal =
1301
+ forceSoftPathFromLexicalHard ||
1297
1302
  score >= cfg.softScoreThreshold ||
1298
- (params.usedEmbedding && typeof params.similarity === "number"
1303
+ (hasSimilarity
1299
1304
  ? params.similarity <= cfg.softSimilarityThreshold &&
1300
1305
  params.lexical.novelty >= cfg.softNoveltyThreshold
1301
1306
  : params.lexical.novelty >= cfg.softNoveltyThreshold &&