@henryqw/pi-auto-compact 1.1.4 → 1.1.6
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 +1 -1
- package/extensions/auto-compact.ts +10 -18
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,21 +33,17 @@ const MIN_COMPACT_THRESHOLD_PERCENT = 25;
|
|
|
33
33
|
const AUTO_COMPACT_TASK = "pi-auto-compact/autoCompact";
|
|
34
34
|
const configPath = () => join(getAgentDir(), "config", "pi-auto-compact.json");
|
|
35
35
|
|
|
36
|
-
type Config = {
|
|
37
|
-
autoCompactThreshold: number;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
36
|
function isValidThreshold(value: unknown): value is number {
|
|
41
37
|
return typeof value === "number" && Number.isFinite(value) && value >= MIN_COMPACT_THRESHOLD_PERCENT && value < 100;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
function readConfig():
|
|
40
|
+
function readConfig(): number {
|
|
45
41
|
let value: unknown;
|
|
46
42
|
try {
|
|
47
43
|
value = JSON.parse(readFileSync(configPath(), "utf8"));
|
|
48
44
|
} catch (error) {
|
|
49
45
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
50
|
-
return
|
|
46
|
+
return DEFAULT_COMPACT_THRESHOLD_PERCENT;
|
|
51
47
|
}
|
|
52
48
|
throw error;
|
|
53
49
|
}
|
|
@@ -58,13 +54,13 @@ function readConfig(): Config {
|
|
|
58
54
|
if (!isValidThreshold(threshold)) {
|
|
59
55
|
throw new Error(`autoCompactThreshold must be at least ${MIN_COMPACT_THRESHOLD_PERCENT} and below 100.`);
|
|
60
56
|
}
|
|
61
|
-
return
|
|
57
|
+
return threshold;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
function writeConfig(
|
|
60
|
+
function writeConfig(threshold: number): void {
|
|
65
61
|
const file = configPath();
|
|
66
62
|
mkdirSync(dirname(file), { recursive: true });
|
|
67
|
-
writeFileSync(file, `${JSON.stringify(
|
|
63
|
+
writeFileSync(file, `${JSON.stringify({ autoCompactThreshold: threshold }, null, 2)}\n`);
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
function configuredTaskRoutes(ctx: ExtensionContext): ResolvedTaskRoute[] {
|
|
@@ -250,32 +246,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
250
246
|
return;
|
|
251
247
|
}
|
|
252
248
|
|
|
253
|
-
let
|
|
249
|
+
let currentThreshold: number;
|
|
254
250
|
try {
|
|
255
|
-
|
|
251
|
+
currentThreshold = readConfig();
|
|
256
252
|
} catch {
|
|
257
253
|
ctx.ui.notify("Couldn't read pi-auto-compact config.", "error");
|
|
258
254
|
return;
|
|
259
255
|
}
|
|
260
256
|
|
|
261
257
|
const input = await ctx.ui.input(
|
|
262
|
-
`Auto-compact threshold (%) · current: ${
|
|
258
|
+
`Auto-compact threshold (%) · current: ${currentThreshold}`,
|
|
263
259
|
"Enter a number at least 25 and below 100",
|
|
264
260
|
);
|
|
265
261
|
if (input === undefined) return;
|
|
266
262
|
|
|
267
263
|
const threshold = Number(input.trim());
|
|
268
|
-
if (Number.isFinite(threshold) && threshold < MIN_COMPACT_THRESHOLD_PERCENT) {
|
|
269
|
-
ctx.ui.notify("Auto-compact threshold below 25% is not meaningful.", "error");
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
264
|
if (!isValidThreshold(threshold)) {
|
|
273
265
|
ctx.ui.notify("Threshold must be at least 25% and below 100%.", "error");
|
|
274
266
|
return;
|
|
275
267
|
}
|
|
276
268
|
|
|
277
269
|
try {
|
|
278
|
-
writeConfig(
|
|
270
|
+
writeConfig(threshold);
|
|
279
271
|
} catch {
|
|
280
272
|
ctx.ui.notify("Couldn't save pi-auto-compact config.", "error");
|
|
281
273
|
return;
|
|
@@ -289,7 +281,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
289
281
|
// activation unless effective global/project settings disable it.
|
|
290
282
|
pi.on("session_start", (event, ctx) => {
|
|
291
283
|
try {
|
|
292
|
-
autoCompactThreshold = readConfig()
|
|
284
|
+
autoCompactThreshold = readConfig();
|
|
293
285
|
} catch {
|
|
294
286
|
autoCompactThreshold = DEFAULT_COMPACT_THRESHOLD_PERCENT;
|
|
295
287
|
ctx.ui.notify("Couldn't read pi-auto-compact config; using 50%.", "error");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-auto-compact",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Proactively compact Pi context at a configurable threshold and resume the current task.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"pack:check": "npm pack --dry-run"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@earendil-works/pi-coding-agent": "^0.84.
|
|
28
|
+
"@earendil-works/pi-coding-agent": "^0.84.3"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@henryqw/pi-task-models": "^0.
|
|
47
|
+
"@henryqw/pi-task-models": "^1.0.0"
|
|
48
48
|
}
|
|
49
49
|
}
|