@xynogen/pix-runtime 0.4.2 → 0.5.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 +13 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/pix-command.ts +17 -0
- package/src/sections/compaction.ts +46 -0
- package/src/sections/index.ts +3 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ See `DESIGN.md` for the full contract.
|
|
|
10
10
|
## What it does
|
|
11
11
|
|
|
12
12
|
- Versioned, sparse `pix.json` (`$version: 1`) — defaults resolve in code.
|
|
13
|
-
- Typed sections: `collapse`, `pretty`, `io`, `optimizer`, `gate`.
|
|
13
|
+
- Typed sections: `collapse`, `pretty`, `io`, `compaction`, `optimizer`, `gate`.
|
|
14
14
|
- Atomic writes behind a serialized in-process queue and a short-lived
|
|
15
15
|
cross-process lock. A failed write leaves the old file intact.
|
|
16
16
|
- Immutable, deeply frozen config snapshots with a monotonic revision.
|
|
@@ -49,6 +49,18 @@ with `/pix`. The default is 30 seconds. It applies to Pix network operations,
|
|
|
49
49
|
including remote skills, web fetch/search/transcription, MCP requests and
|
|
50
50
|
connection bootstrap, background model-data refreshes, and update downloads.
|
|
51
51
|
|
|
52
|
+
Set `compaction.triggerPercent` in `~/.pi/agent/pix.json`, or change **Compaction →
|
|
53
|
+
Trigger (% ctx)** with `/pix`. It is the context-window usage percent (0–100) used
|
|
54
|
+
to calculate the trigger; the default is `60` and `0` disables the self-trigger
|
|
55
|
+
(pi decides when to compact). The `/pix` picker offers 0, 5, 10, 15, 20, 25, 30,
|
|
56
|
+
40, 50, 60, 70, 80, 90.
|
|
57
|
+
|
|
58
|
+
`compaction.minimumTokens` is the absolute floor for that calculation. The
|
|
59
|
+
effective threshold is `max(contextWindow × triggerPercent, minimumTokens)`, so
|
|
60
|
+
a 300K-context model at 10% waits for 100K tokens instead of compacting at 30K.
|
|
61
|
+
The default floor is 100K; `/pix` offers 100K, 150K, 200K, 300K, 400K, 500K, and
|
|
62
|
+
600K. pix-core consumes both settings.
|
|
63
|
+
|
|
52
64
|
Collapse policy helpers:
|
|
53
65
|
|
|
54
66
|
```ts
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/pix-command.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import type { PixRuntime } from "./runtime.ts";
|
|
19
19
|
import type { DeepPartial, SectionHandle } from "./schema.ts";
|
|
20
20
|
import { collapseSection } from "./sections/collapse.ts";
|
|
21
|
+
import { compactionSection } from "./sections/compaction.ts";
|
|
21
22
|
import { gateSection } from "./sections/gate.ts";
|
|
22
23
|
import { ioSection } from "./sections/io.ts";
|
|
23
24
|
import { prettySection } from "./sections/pretty.ts";
|
|
@@ -77,6 +78,22 @@ const SETTINGS: SettingRow<unknown>[] = [
|
|
|
77
78
|
read: (v) => String(v.timeoutSec),
|
|
78
79
|
patch: (value) => ({ timeoutSec: Number(value) }),
|
|
79
80
|
}),
|
|
81
|
+
row({
|
|
82
|
+
section: "Compaction",
|
|
83
|
+
label: "Trigger (% ctx)",
|
|
84
|
+
handle: compactionSection,
|
|
85
|
+
values: ["0", "5", "10", "15", "20", "25", "30", "40", "50", "60", "70", "80", "90"],
|
|
86
|
+
read: (v) => String(v.triggerPercent),
|
|
87
|
+
patch: (value) => ({ triggerPercent: Number(value) }),
|
|
88
|
+
}),
|
|
89
|
+
row({
|
|
90
|
+
section: "Compaction",
|
|
91
|
+
label: "Minimum tokens",
|
|
92
|
+
handle: compactionSection,
|
|
93
|
+
values: ["100k", "150k", "200k", "300k", "400k", "500k", "600k"],
|
|
94
|
+
read: (v) => `${v.minimumTokens / 1000}k`,
|
|
95
|
+
patch: (value) => ({ minimumTokens: Number.parseInt(value, 10) * 1000 }),
|
|
96
|
+
}),
|
|
80
97
|
row({
|
|
81
98
|
section: "Gate",
|
|
82
99
|
label: "Guardrails",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineSection, isObj } from "../schema.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom compaction config. pix-core always replaces pi's built-in compaction
|
|
5
|
+
* summary. When `triggerPercent > 0` it also drives its own trigger from live
|
|
6
|
+
* context usage. The effective threshold is the larger of that percentage of
|
|
7
|
+
* the active model's context window and `minimumTokens`. `0` disables the
|
|
8
|
+
* self-trigger (pi decides when to compact).
|
|
9
|
+
*/
|
|
10
|
+
export interface CompactionConfig {
|
|
11
|
+
/** Context-window usage percent that fires compaction; 0 = off. */
|
|
12
|
+
triggerPercent: number;
|
|
13
|
+
/** Absolute floor for a percentage-based trigger. */
|
|
14
|
+
minimumTokens: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const MINIMUM_TOKEN_FLOOR = 100_000;
|
|
18
|
+
|
|
19
|
+
const DEFAULTS: Readonly<CompactionConfig> = {
|
|
20
|
+
triggerPercent: 60,
|
|
21
|
+
minimumTokens: MINIMUM_TOKEN_FLOOR,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Clamp to [0, 100]; non-numbers fall back. */
|
|
25
|
+
function pctOr(v: unknown, fallback: number): number {
|
|
26
|
+
if (typeof v !== "number" || !Number.isFinite(v)) return fallback;
|
|
27
|
+
return Math.min(100, Math.max(0, v));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Require a finite token floor of at least 100k. */
|
|
31
|
+
function minimumTokensOr(v: unknown, fallback: number): number {
|
|
32
|
+
if (typeof v !== "number" || !Number.isFinite(v)) return fallback;
|
|
33
|
+
return Math.max(MINIMUM_TOKEN_FLOOR, Math.round(v));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const compactionSection = defineSection<"compaction", CompactionConfig>({
|
|
37
|
+
key: "compaction",
|
|
38
|
+
defaults: DEFAULTS,
|
|
39
|
+
parse(raw) {
|
|
40
|
+
if (!isObj(raw)) return { ...DEFAULTS };
|
|
41
|
+
return {
|
|
42
|
+
triggerPercent: pctOr(raw.triggerPercent, DEFAULTS.triggerPercent),
|
|
43
|
+
minimumTokens: minimumTokensOr(raw.minimumTokens, DEFAULTS.minimumTokens),
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
});
|
package/src/sections/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { type CollapseConfig, collapseSection } from "./collapse.ts";
|
|
2
|
+
export { type CompactionConfig, compactionSection } from "./compaction.ts";
|
|
2
3
|
export {
|
|
3
4
|
type GateConfig,
|
|
4
5
|
type GateRuleConfig,
|
|
@@ -22,6 +23,7 @@ export {
|
|
|
22
23
|
} from "./pretty.ts";
|
|
23
24
|
|
|
24
25
|
import { collapseSection } from "./collapse.ts";
|
|
26
|
+
import { compactionSection } from "./compaction.ts";
|
|
25
27
|
import { gateSection } from "./gate.ts";
|
|
26
28
|
import { ioSection } from "./io.ts";
|
|
27
29
|
import { optimizerSection } from "./optimizer.ts";
|
|
@@ -34,4 +36,5 @@ export const builtinSections = [
|
|
|
34
36
|
ioSection,
|
|
35
37
|
optimizerSection,
|
|
36
38
|
gateSection,
|
|
39
|
+
compactionSection,
|
|
37
40
|
] as const;
|