@henryqw/pi-auto-compact 1.1.5 → 1.1.7

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 CHANGED
@@ -44,7 +44,7 @@ Refuses to activate unless effective `compaction.enabled` is `false`. Checks `tu
44
44
 
45
45
  ## Config
46
46
 
47
- `~/.pi/agent/config/pi-auto-compact.json`
47
+ Package-owned: `~/.pi/agent/config/pi-auto-compact.json`
48
48
 
49
49
  ```json
50
50
  {
@@ -52,24 +52,10 @@ Refuses to activate unless effective `compaction.enabled` is `false`. Checks `tu
52
52
  }
53
53
  ```
54
54
 
55
- Threshold must be at least 25 and below 100. Missing config defaults to 50. Model routes live in `~/.pi/agent/config/pi-task-models.json`. Malformed shared task-model config is reported and left unchanged.
55
+ | Field | Required | Possible values | Default |
56
+ | --- | --- | --- | --- |
57
+ | `autoCompactThreshold` | No | Number, at least 25, below 100 | `50` |
56
58
 
57
- ## Remove
59
+ Unknown fields are ignored (legacy model fields are obsolete). `/auto-compact` writes this file. A missing file uses the default; a malformed or invalid file fails visibly at session start, falls back to 50%, and stays unchanged.
58
60
 
59
- ```bash
60
- pi remove npm:@henryqw/pi-auto-compact
61
- ```
62
-
63
- ## Development
64
-
65
- ```bash
66
- npm test --workspace @henryqw/pi-auto-compact
67
- npm run typecheck --workspace @henryqw/pi-auto-compact
68
- npm run pack:check --workspace @henryqw/pi-auto-compact
69
- ```
70
-
71
- `test:live` needs real Pi plus authenticated model access. Set `PI_AUTO_COMPACT_AUTH_FILE` when auth is not at `~/.pi/agent/auth.json`.
72
-
73
- ```bash
74
- npm run test:live --workspace @henryqw/pi-auto-compact
75
- ```
61
+ Shared: `~/.pi/agent/config/pi-task-models.json`, owned by `@henryqw/pi-task-models`. Task `pi-auto-compact/autoCompact` defaults to profile `fast`. Malformed shared task-model config is reported and left unchanged; compaction then uses the current session model.
@@ -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(): Config {
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 { autoCompactThreshold: DEFAULT_COMPACT_THRESHOLD_PERCENT };
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 { autoCompactThreshold: threshold };
57
+ return threshold;
62
58
  }
63
59
 
64
- function writeConfig(config: Config): void {
60
+ function writeConfig(threshold: number): void {
65
61
  const file = configPath();
66
62
  mkdirSync(dirname(file), { recursive: true });
67
- writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
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 config: Config;
249
+ let currentThreshold: number;
254
250
  try {
255
- config = readConfig();
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: ${config.autoCompactThreshold}`,
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({ autoCompactThreshold: threshold });
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().autoCompactThreshold;
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.5",
3
+ "version": "1.1.7",
4
4
  "description": "Proactively compact Pi context at a configurable threshold and resume the current task.",
5
5
  "keywords": [
6
6
  "pi-package",