@pinet/model-aware-compaction 0.2.1 → 0.2.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 CHANGED
@@ -37,7 +37,7 @@ Rules are evaluated in order. `*` wildcards are supported, such as `example-prox
37
37
 
38
38
  ## Behavior
39
39
 
40
- After each `turn_end`, the extension reads `ctx.getContextUsage()` and the active `ctx.model`. When usage first exceeds the matching rule's `activeContextTokens`, it calls `ctx.compact()`. It prevents duplicate calls while compaction is in flight and re-arms after usage drops below the threshold, the model changes, a session starts, or compaction fails.
40
+ After each `agent_end`, the extension reads `ctx.getContextUsage()` and the active `ctx.model`. Waiting for `agent_end` is important: tool-using runs can emit several `turn_end` events, and Pi's `ctx.compact()` aborts an active agent operation before compacting. Triggering only after the complete model/tool loop has settled prevents compaction from discarding pending tool work. When usage first exceeds the matching rule's `activeContextTokens`, the extension calls `ctx.compact()`. It prevents duplicate calls while compaction is in flight and re-arms after usage drops below the threshold, the model changes, a session starts, or compaction fails.
41
41
 
42
42
  Run `/model-aware-compaction-status` to inspect the active model, usage, matched threshold, state, and loaded rules.
43
43
 
package/dist/config.js CHANGED
@@ -11,6 +11,8 @@ function parseSettings(path) {
11
11
  return null;
12
12
  try {
13
13
  const parsed = JSON.parse(fs.readFileSync(path, "utf8"));
14
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
15
+ return null;
14
16
  const value = parsed[SETTINGS_KEY];
15
17
  if (!value || typeof value !== "object" || Array.isArray(value))
16
18
  return null;
package/dist/index.js CHANGED
@@ -10,7 +10,9 @@ export default function modelAwareCompaction(pi) {
10
10
  };
11
11
  pi.on("session_start", rearm);
12
12
  pi.on("model_select", rearm);
13
- pi.on("turn_end", (_event, rawCtx) => {
13
+ // ctx.compact() aborts an active agent operation. Wait for the complete
14
+ // model/tool loop to settle so compaction cannot discard pending tool work.
15
+ pi.on("agent_end", (_event, rawCtx) => {
14
16
  const ctx = rawCtx;
15
17
  const config = loadConfig(ctx.cwd);
16
18
  const usage = ctx.getContextUsage?.();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@pinet/model-aware-compaction",
3
- "version": "0.2.1",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "description": "Pi extension for proactive model-aware context compaction thresholds",
6
6
  "author": "Will Porcellini <5994936+gugu91@users.noreply.github.com>",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/gugu91/extensions.git",
10
+ "url": "git+https://github.com/gugu91/pinet.git",
11
11
  "directory": "model-aware-compaction"
12
12
  },
13
13
  "publishConfig": {
@@ -40,9 +40,9 @@
40
40
  "scripts": {
41
41
  "build": "node ../scripts/build-package.mjs",
42
42
  "prepack": "pnpm run build",
43
- "lint": "eslint . --ext .ts",
43
+ "lint": "oxlint .",
44
44
  "typecheck": "tsc --noEmit",
45
- "test": "vitest run"
45
+ "test": "vitest run --config ../vitest.config.ts"
46
46
  },
47
47
  "dependencies": {},
48
48
  "peerDependencies": {