pi-mega-compact 0.4.26 → 0.4.27
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.
|
@@ -27,8 +27,19 @@ export function runCompact(pi, runtime, config, ctx, messages, opts = {}) {
|
|
|
27
27
|
// compact more of the session, down to the preserveRecentMin floor.
|
|
28
28
|
const preserve = preserveRecentForPressure(opts.compressionPressure ?? 0, config.preserveRecent, config.preserveRecentMin);
|
|
29
29
|
const keepFrom = opts.keepFrom ?? Math.max(0, view.length - preserve);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// For very small sessions (fewer messages than preserveRecent), allow
|
|
31
|
+
// compacting everything except the last message — the user explicitly
|
|
32
|
+
// requested compaction, so don't refuse it just because the session is short.
|
|
33
|
+
if (keepFrom <= 0) {
|
|
34
|
+
if (view.length <= 1)
|
|
35
|
+
return { skipped: true };
|
|
36
|
+
// Use the fallback: compact everything except the last message
|
|
37
|
+
const fallbackKeepFrom = view.length - 1;
|
|
38
|
+
return doCompact(view, fallbackKeepFrom, opts, sid, config, pi, ctx, runtime);
|
|
39
|
+
}
|
|
40
|
+
return doCompact(view, keepFrom, opts, sid, config, pi, ctx, runtime);
|
|
41
|
+
}
|
|
42
|
+
function doCompact(view, keepFrom, opts, sid, config, pi, ctx, runtime) {
|
|
32
43
|
runtime.pulsing = true; // animate the status line while the (sync) pipeline runs
|
|
33
44
|
const result = compactSession({
|
|
34
45
|
sessionId: sid,
|
|
@@ -11,6 +11,7 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
11
11
|
import { sessionEntryToContextMessages } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
13
13
|
import { compactSession } from "../src/engine.js";
|
|
14
|
+
import type { EngineMessage } from "../src/types.js";
|
|
14
15
|
import { recallAndInline } from "../src/recall.js";
|
|
15
16
|
import { normalizeSessionId } from "../src/store.js";
|
|
16
17
|
import { touchSession, logDaily } from "../src/store/sqlite.js";
|
|
@@ -51,8 +52,29 @@ export function runCompact(
|
|
|
51
52
|
config.preserveRecentMin,
|
|
52
53
|
);
|
|
53
54
|
const keepFrom = opts.keepFrom ?? Math.max(0, view.length - preserve);
|
|
54
|
-
|
|
55
|
+
// For very small sessions (fewer messages than preserveRecent), allow
|
|
56
|
+
// compacting everything except the last message — the user explicitly
|
|
57
|
+
// requested compaction, so don't refuse it just because the session is short.
|
|
58
|
+
if (keepFrom <= 0) {
|
|
59
|
+
if (view.length <= 1) return { skipped: true };
|
|
60
|
+
// Use the fallback: compact everything except the last message
|
|
61
|
+
const fallbackKeepFrom = view.length - 1;
|
|
62
|
+
return doCompact(view, fallbackKeepFrom, opts, sid, config, pi, ctx, runtime);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return doCompact(view, keepFrom, opts, sid, config, pi, ctx, runtime);
|
|
66
|
+
}
|
|
55
67
|
|
|
68
|
+
function doCompact(
|
|
69
|
+
view: EngineMessage[],
|
|
70
|
+
keepFrom: number,
|
|
71
|
+
opts: { keepFrom?: number; summary?: string; compressionPressure?: number },
|
|
72
|
+
sid: string,
|
|
73
|
+
config: MegaConfig,
|
|
74
|
+
pi: ExtensionAPI,
|
|
75
|
+
ctx: ExtensionContext,
|
|
76
|
+
runtime: MegaRuntime,
|
|
77
|
+
): RunCompactResult {
|
|
56
78
|
runtime.pulsing = true; // animate the status line while the (sync) pipeline runs
|
|
57
79
|
const result = compactSession(
|
|
58
80
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mega-compact",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.27",
|
|
4
4
|
"description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BSD-2-Clause",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc -p tsconfig.json",
|
|
44
44
|
"lint": "tsc --noEmit && node scripts/guardrails-scan.mjs",
|
|
45
|
-
"test": "npm run build && node --test \"dist/src/**/*.test.js\" \"dist/extensions/**/*.test.js\"",
|
|
45
|
+
"test": "npm run build && node --test --test-timeout=180000 \"dist/src/**/*.test.js\" \"dist/extensions/**/*.test.js\"",
|
|
46
46
|
"guardrails": "python3 scripts/regression_check.py --all || node scripts/guardrails-scan.mjs",
|
|
47
47
|
"precommit": "bash .claude/hooks/pre-commit.sh",
|
|
48
48
|
"prepublishOnly": "npm run build",
|