@falling-ts/dsh-force-compact 0.2.4 → 0.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@falling-ts/dsh-force-compact",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "DSH Cordis plugin: hooks the core model-request seam (agent/pre-step + agent/request) to force-compact a session's context and disable thinking per the \"强制压缩配置\" settings namespace (disableThinking, autoThresholdTokens, retainLatestTokens, turnEndForceCompactionEnabled). When the threshold fires (or /force-compact queues while busy), the latest `retainLatestTokens` of the conversation's surface tokens are KEPT VERBATIM and everything before that cutoff is COMPACTED INTO A SINGLE SUMMARY NODE in one LLM call (original span entries become shadowed/skipped). Also compacts at each turn/end and at each session/flush durability checkpoint. Host half is a pure listener; a web client half registers a settings.section (强制压缩 / Force Compact) that reads and writes the same settings namespace.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -82,7 +82,7 @@ export const WORKING_TEXTS = Object.freeze([
82
82
  '正在驯服混沌...',
83
83
  '正在召唤赛博大脑...',
84
84
  '正在翻阅《天机》...',
85
- 'CPU 正在冒烟...',
85
+ 'GPU 正在冒烟...',
86
86
  '正在跟熵值搏斗...',
87
87
  '正在画饼给你吃...',
88
88
  '正在偷渡灵感...',
@@ -618,15 +618,29 @@ async function __forceCompactIfNeededBody(ctx, agent, signal, mode) {
618
618
  )
619
619
  }
620
620
 
621
- // At or above the threshold: do NOT request the model. Retain the latest
622
- // `retainLatestTokens` of the surface VERBATIM, and send everything before
623
- // that cutoff (the head) as ONE BATCH to the LLM summarizer. The loop retries
624
- // the step against the shrunken context (retained tail unchanged).
625
- ctx.logger.info(
626
- `[force-compact] ${session.id}: context ~${total} tokens >= threshold ${settings.autoThresholdTokens}; `
627
- + `rejecting the model request and compacting the head while retaining the latest ~${settings.retainLatestTokens} tokens`,
621
+ // SHORT-CIRCUIT: when the whole current surface window does not exceed the
622
+ // retention budget, there is no head to compact (the tail-retaining selector
623
+ // would walk the entire window and return null). The threshold was tripped
624
+ // by the provider-usage baseline rather than by real surface growth, so an
625
+ // attempted compaction is a guaranteed no-op — skip it and let the request
626
+ // proceed without pretending to compact.
627
+ if (windowSumObserved > 0 && Number.isFinite(windowSumObserved) && windowSumObserved <= settings.retainLatestTokens) {
628
+ ctx.logger.debug(
629
+ `[force-compact] ${session.id}: threshold ${settings.autoThresholdTokens} tripped on a surface window (~${Math.round(windowSumObserved)} tokens) that does not exceed retainLatestTokens (~${settings.retainLatestTokens}) — nothing above the retention floor to compact; letting the request proceed`,
630
+ )
631
+ return false
632
+ }
633
+
634
+ // At or above the threshold: attempt a retained-tail compaction (the request
635
+ // itself always proceeds; the plugin never rejects the model call).
636
+ ctx.logger.debug(
637
+ `[force-compact] ${session.id}: context ~${total} tokens >= threshold ${settings.autoThresholdTokens} — attempting a retained-tail compaction (success/failure is reported by the backend below; the request itself proceeds regardless)`,
628
638
  )
629
- const committed = await compactRetainingLatest(ctx, agent, signal, mode, measurement)
639
+ // NOTE: threshold path has NO originating slash-command, so the 5th argument
640
+ // (sourceCommandId) must be omitted — passing something else here (e.g. the
641
+ // `measurement` snapshot, as an earlier revision did) would leak a non-string
642
+ // into the compaction/* events' sourceCommandId field.
643
+ const committed = await compactRetainingLatest(ctx, agent, signal, mode)
630
644
  if (!committed) {
631
645
  // BLANK OUTCOME — nothing shrank, so the NEXT step re-attempts at the same
632
646
  // total. That is intentional ("先压缩再说"): a blank result never wedges the