@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 +1 -1
- package/src/core/ui-signal.js +1 -1
- package/src/hooks/guard.js +22 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falling-ts/dsh-force-compact",
|
|
3
|
-
"version": "0.2.
|
|
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",
|
package/src/core/ui-signal.js
CHANGED
package/src/hooks/guard.js
CHANGED
|
@@ -618,15 +618,29 @@ async function __forceCompactIfNeededBody(ctx, agent, signal, mode) {
|
|
|
618
618
|
)
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
-
//
|
|
622
|
-
//
|
|
623
|
-
//
|
|
624
|
-
// the
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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
|
-
|
|
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
|