pi-context-kit 0.4.3 → 0.4.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/src/panel.ts DELETED
@@ -1,75 +0,0 @@
1
- import { type ContextKitConfig, type Strategy, type Threshold } from "./config.ts";
2
-
3
- /** The `SettingItem` fields of `@earendil-works/pi-tui` that the panel uses. */
4
- export interface PanelItem {
5
- id: "enabled" | "threshold" | "strategy";
6
- label: string;
7
- description: string;
8
- currentValue: string;
9
- values: string[];
10
- }
11
-
12
- const PI_LIMIT = "At Pi's limit";
13
- const THRESHOLDS = [...[50, 60, 70, 75, 80, 90].map((percent) => `${percent}% full`), PI_LIMIT];
14
- const METHODS: Readonly<Record<Strategy, string>> = {
15
- balanced: "Summary notes (recommended)",
16
- frugal: "Trim first",
17
- "pi-summary": "Pi's summary",
18
- };
19
-
20
- /** The settings the `/context-kit` panel edits, in plain words. The rest stay in the file. */
21
- export function panelItems(config: ContextKitConfig): PanelItem[] {
22
- const threshold = thresholdText(config.threshold);
23
- const items: PanelItem[] = [
24
- {
25
- id: "enabled",
26
- label: "Automatic cleanup",
27
- description:
28
- "Makes room in a long conversation so the agent keeps working. Off leaves only Pi's own cleanup.",
29
- currentValue: config.enabled ? "On" : "Off",
30
- values: ["On", "Off"],
31
- },
32
- {
33
- id: "threshold",
34
- label: "Clean up when the context is",
35
- description:
36
- "Lower keeps answers faster and cheaper. Higher keeps more detail. At Pi's limit waits as long as Pi does.",
37
- currentValue: threshold,
38
- values: THRESHOLDS.includes(threshold) ? THRESHOLDS : [threshold, ...THRESHOLDS],
39
- },
40
- ];
41
- if (config.customOrder) return items;
42
- items.push({
43
- id: "strategy",
44
- label: "Cleanup method",
45
- description:
46
- "Summary notes: the agent writes notes ahead of time and they replace old messages. Trim first: shorten large old outputs, with no extra model call. Pi's summary: Pi's own summary.",
47
- currentValue: METHODS[config.strategy],
48
- values: Object.values(METHODS),
49
- });
50
- return items;
51
- }
52
-
53
- /** The JSON value to write for a panel choice. */
54
- export function settingValue(id: string, value: string): unknown {
55
- if (id === "enabled") return value === "On";
56
- if (id === "strategy") return Object.entries(METHODS).find(([, label]) => label === value)?.[0];
57
- if (value === PI_LIMIT) return "pi";
58
- const tokens = /^(\d+) tokens$/.exec(value);
59
- return tokens ? Number(tokens[1]) : value.replace(/ full$/, "");
60
- }
61
-
62
- /** One line for modes without the panel. */
63
- export function summaryText(config: ContextKitConfig, file: string): string {
64
- if (!config.enabled) return `pi-context-kit: automatic cleanup off. Settings: ${file}`;
65
- const at = config.threshold === "pi" ? "Pi's limit" : thresholdText(config.threshold);
66
- const method = config.customOrder
67
- ? `custom methods (${config.methodOrder.join(", ") || "none"})`
68
- : METHODS[config.strategy].replace(" (recommended)", "").toLowerCase();
69
- return `pi-context-kit: automatic cleanup at ${at}, with ${method}. Settings: ${file}`;
70
- }
71
-
72
- function thresholdText(threshold: Threshold): string {
73
- if (threshold === "pi") return PI_LIMIT;
74
- return "tokens" in threshold ? `${threshold.tokens} tokens` : `${threshold.percent}% full`;
75
- }