pi-mega-compact 0.6.9 → 0.7.1
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 +10 -8
- package/dist/extensions/dashboard-server.js +17 -6
- package/dist/extensions/mega-commands.js +12 -1
- package/dist/extensions/mega-compact-driver.js +1 -0
- package/dist/extensions/mega-compact.test.js +286 -51
- package/dist/extensions/mega-config.js +67 -5
- package/dist/extensions/mega-events.js +151 -27
- package/dist/extensions/mega-pipeline.js +53 -17
- package/dist/extensions/mega-runtime.js +443 -115
- package/dist/extensions/openclaw-mega-compact.js +291 -0
- package/dist/src/dedup-engine.test.js +63 -38
- package/dist/src/minilm.js +92 -0
- package/dist/src/wordpiece.js +129 -0
- package/extensions/dashboard-server.ts +17 -6
- package/extensions/mega-commands.ts +12 -1
- package/extensions/mega-compact-driver.ts +56 -55
- package/extensions/mega-compact.test.ts +947 -516
- package/extensions/mega-config.ts +84 -6
- package/extensions/mega-dashboard.ts +11 -0
- package/extensions/mega-events.ts +558 -360
- package/extensions/mega-pipeline.ts +481 -393
- package/extensions/mega-runtime.ts +957 -502
- package/package.json +1 -1
- package/src/dedup-engine.test.ts +103 -42
package/package.json
CHANGED
package/src/dedup-engine.test.ts
CHANGED
|
@@ -24,6 +24,12 @@ import { autoCompactCheck } from "./compact.js";
|
|
|
24
24
|
import { loadDedupConfig, type DedupConfigShape } from "./config/dedup.js";
|
|
25
25
|
import type { EngineMessage } from "./types.js";
|
|
26
26
|
|
|
27
|
+
// Real percentage-based threshold config. Replaces the previous LOCAL replica of
|
|
28
|
+
// COMPACT_TIERS + resolveThresholdFromEnv that asserted the OLD static token
|
|
29
|
+
// amounts — importing the live source of truth keeps tests in sync with the
|
|
30
|
+
// source (thresholds are tierPct × the model's context window, not fixed tokens).
|
|
31
|
+
import { TIER_PCT, effectiveThresholdTokens, loadConfig } from "../extensions/mega-config.js";
|
|
32
|
+
|
|
27
33
|
// recallAndInline may or may not be exported; import safely.
|
|
28
34
|
import * as recallMod from "./recall.js";
|
|
29
35
|
|
|
@@ -540,48 +546,63 @@ describe("Edge Cases", () => {
|
|
|
540
546
|
});
|
|
541
547
|
});
|
|
542
548
|
|
|
543
|
-
// -------------------- 7. Tier Switching --------------------
|
|
549
|
+
// -------------------- 7. Tier Switching (percentage-based) --------------------
|
|
550
|
+
|
|
551
|
+
// Replaces the previous LOCAL replica of COMPACT_TIERS + resolveThresholdFromEnv
|
|
552
|
+
// that asserted the OLD static token amounts. We now import the REAL config
|
|
553
|
+
// helpers from extensions/mega-config.js so the tests track the live source of
|
|
554
|
+
// truth: thresholds are tierPct × the model's context window (not fixed tokens).
|
|
555
|
+
|
|
556
|
+
describe("Tier Switching — percentage-based thresholds", () => {
|
|
557
|
+
// Documented tierPct fractions (single source of truth in mega-config.ts).
|
|
558
|
+
it("each named tier carries the documented tierPct fraction", () => {
|
|
559
|
+
assert.equal(TIER_PCT.low, 0.5);
|
|
560
|
+
assert.equal(TIER_PCT.medium, 0.6);
|
|
561
|
+
assert.equal(TIER_PCT.high, 0.7);
|
|
562
|
+
assert.equal(TIER_PCT.ultra, 0.7);
|
|
563
|
+
assert.equal(TIER_PCT.mega, 0.75);
|
|
564
|
+
});
|
|
544
565
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
["
|
|
550
|
-
["
|
|
551
|
-
["
|
|
552
|
-
["
|
|
566
|
+
// Boot fallback threshold (sane gate before the first context event supplies a
|
|
567
|
+
// window): round(tierPct × 200_000). Resolved through the REAL loadConfig().
|
|
568
|
+
it("MEGACOMPACT_TIER env resolves to the boot fallback threshold via real config", () => {
|
|
569
|
+
const tiers: Array<[keyof typeof TIER_PCT, number]> = [
|
|
570
|
+
["low", 100_000], // 0.50 × 200_000
|
|
571
|
+
["medium", 120_000], // 0.60 × 200_000
|
|
572
|
+
["high", 140_000], // 0.70 × 200_000
|
|
573
|
+
["ultra", 140_000], // 0.70 × 200_000
|
|
574
|
+
["mega", 150_000], // 0.75 × 200_000
|
|
553
575
|
];
|
|
554
|
-
|
|
555
|
-
for (const [tier, expectedThreshold] of tiers) {
|
|
576
|
+
for (const [tier, expectedBoot] of tiers) {
|
|
556
577
|
const original = process.env.MEGACOMPACT_TIER;
|
|
578
|
+
delete process.env.MEGACOMPACT_THRESHOLD_TOKENS;
|
|
557
579
|
process.env.MEGACOMPACT_TIER = tier;
|
|
558
580
|
try {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
581
|
+
const cfg = loadConfig();
|
|
582
|
+
assert.equal(cfg.tier, tier, `tier ${tier} should resolve`);
|
|
583
|
+
assert.equal(cfg.tierPct, TIER_PCT[tier], `tier ${tier} tierPct`);
|
|
562
584
|
assert.equal(
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
`tier ${tier} should
|
|
585
|
+
cfg.thresholdTokens,
|
|
586
|
+
expectedBoot,
|
|
587
|
+
`tier ${tier} boot fallback threshold should be ${expectedBoot}`,
|
|
566
588
|
);
|
|
567
589
|
} finally {
|
|
568
|
-
if (original === undefined)
|
|
569
|
-
|
|
570
|
-
} else {
|
|
571
|
-
process.env.MEGACOMPACT_TIER = original;
|
|
572
|
-
}
|
|
590
|
+
if (original === undefined) delete process.env.MEGACOMPACT_TIER;
|
|
591
|
+
else process.env.MEGACOMPACT_TIER = original;
|
|
573
592
|
}
|
|
574
593
|
}
|
|
575
594
|
});
|
|
576
595
|
|
|
577
|
-
it("explicit MEGACOMPACT_THRESHOLD_TOKENS overrides tier", () => {
|
|
596
|
+
it("explicit MEGACOMPACT_THRESHOLD_TOKENS overrides tier (custom stays absolute)", () => {
|
|
578
597
|
const originalTier = process.env.MEGACOMPACT_TIER;
|
|
579
598
|
const originalThreshold = process.env.MEGACOMPACT_THRESHOLD_TOKENS;
|
|
580
|
-
process.env.MEGACOMPACT_TIER
|
|
599
|
+
delete process.env.MEGACOMPACT_TIER;
|
|
581
600
|
process.env.MEGACOMPACT_THRESHOLD_TOKENS = "123456";
|
|
582
601
|
try {
|
|
583
|
-
const
|
|
584
|
-
assert.equal(
|
|
602
|
+
const cfg = loadConfig();
|
|
603
|
+
assert.equal(cfg.tier, "custom", "explicit token threshold → custom tier");
|
|
604
|
+
assert.equal(cfg.tierPct, null, "custom tier has no tierPct (stays absolute)");
|
|
605
|
+
assert.equal(cfg.thresholdTokens, 123_456, "explicit token threshold should win");
|
|
585
606
|
} finally {
|
|
586
607
|
if (originalTier === undefined) delete process.env.MEGACOMPACT_TIER;
|
|
587
608
|
else process.env.MEGACOMPACT_TIER = originalTier;
|
|
@@ -591,19 +612,59 @@ describe("Tier Switching", () => {
|
|
|
591
612
|
});
|
|
592
613
|
});
|
|
593
614
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
615
|
+
describe("effectiveThresholdTokens — tierPct × model window", () => {
|
|
616
|
+
// The real compaction fire point. Tiered → scales with the window so it always
|
|
617
|
+
// fires BELOW pi's native ~80% auto-compact for any model size. Custom (null
|
|
618
|
+
// tierPct) → absolute explicitThreshold, never percent-scaled.
|
|
619
|
+
|
|
620
|
+
it("scales tierPct × window for a 200k model", () => {
|
|
621
|
+
assert.equal(
|
|
622
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.low, fallbackThreshold: 100_000, window: 200_000 }),
|
|
623
|
+
100_000,
|
|
624
|
+
);
|
|
625
|
+
assert.equal(
|
|
626
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.mega, fallbackThreshold: 150_000, window: 200_000 }),
|
|
627
|
+
150_000,
|
|
628
|
+
);
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it("scales tierPct × window for a 1M model", () => {
|
|
632
|
+
assert.equal(
|
|
633
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.low, fallbackThreshold: 500_000, window: 1_000_000 }),
|
|
634
|
+
500_000,
|
|
635
|
+
);
|
|
636
|
+
assert.equal(
|
|
637
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.mega, fallbackThreshold: 750_000, window: 1_000_000 }),
|
|
638
|
+
750_000,
|
|
639
|
+
);
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it("falls back to the boot threshold when the window is 0/unknown", () => {
|
|
643
|
+
assert.equal(
|
|
644
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.mega, fallbackThreshold: 150_000, window: 0 }),
|
|
645
|
+
150_000,
|
|
646
|
+
);
|
|
647
|
+
assert.equal(
|
|
648
|
+
effectiveThresholdTokens({ tierPct: TIER_PCT.low, fallbackThreshold: 100_000, window: -5 }),
|
|
649
|
+
100_000,
|
|
650
|
+
);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it("custom (tierPct null) stays an absolute threshold regardless of window", () => {
|
|
654
|
+
assert.equal(
|
|
655
|
+
effectiveThresholdTokens({ tierPct: null, fallbackThreshold: 100_000, window: 200_000, explicitThreshold: 123456 }),
|
|
656
|
+
123456,
|
|
657
|
+
"explicit absolute wins (200k window)",
|
|
658
|
+
);
|
|
659
|
+
assert.equal(
|
|
660
|
+
effectiveThresholdTokens({ tierPct: null, fallbackThreshold: 100_000, window: 1_000_000, explicitThreshold: 123456 }),
|
|
661
|
+
123456,
|
|
662
|
+
"explicit absolute wins (1M window)",
|
|
663
|
+
);
|
|
664
|
+
assert.equal(
|
|
665
|
+
effectiveThresholdTokens({ tierPct: null, fallbackThreshold: 100_000, window: 200_000 }),
|
|
666
|
+
100_000,
|
|
667
|
+
"no explicit → boot fallback",
|
|
668
|
+
);
|
|
669
|
+
});
|
|
670
|
+
});
|