@monotykamary/pi-vcc 0.7.3 → 0.7.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monotykamary/pi-vcc",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Algorithmic conversation compactor for pi - transcript-preserving structured summaries, no LLM calls",
5
5
  "main": "index.ts",
6
6
  "keywords": [
@@ -1,6 +1,6 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
2
  import { dirname, join } from "path";
3
- import { getAgentDir } from "@earendil-works/pi-coding-agent";
3
+ import { CONFIG_DIR_NAME, getAgentDir } from "@earendil-works/pi-coding-agent";
4
4
 
5
5
  const settingsPath = (): string =>
6
6
  process.env.PI_VCC_CONFIG_PATH ?? join(getAgentDir(), "pi-vcc-config.json");
@@ -181,6 +181,32 @@ const readJson = (path: string): Record<string, unknown> | null => {
181
181
  }
182
182
  };
183
183
 
184
+ const readPiCoreCompactionEnabled = (path: string): boolean | undefined => {
185
+ const parsed = readJson(path);
186
+ if (!parsed) return undefined;
187
+ const enabled = (parsed as { compaction?: { enabled?: unknown } }).compaction?.enabled;
188
+ return typeof enabled === "boolean" ? enabled : undefined;
189
+ };
190
+
191
+ /**
192
+ * Read pi-core's effective `compaction.enabled` setting.
193
+ *
194
+ * pi-core's `_checkCompaction` bails immediately when this is false, so neither
195
+ * overflow nor threshold auto-compaction fires. When that happens pi-vcc must
196
+ * drive compaction itself via `ctx.compact()` (the manual path skips the
197
+ * `enabled` gate). Mirrors pi-core's merge: project (`<cwd>/<CONFIG_DIR_NAME>/
198
+ * settings.json`) overrides global (`<agentDir>/settings.json`); defaults true.
199
+ */
200
+ export function isPiCoreCompactionEnabled(projectCwd?: string): boolean {
201
+ const globalEnabled = readPiCoreCompactionEnabled(join(getAgentDir(), "settings.json"));
202
+ if (projectCwd) {
203
+ const projectEnabled = readPiCoreCompactionEnabled(join(projectCwd, CONFIG_DIR_NAME, "settings.json"));
204
+ if (typeof projectEnabled === "boolean") return projectEnabled;
205
+ }
206
+ if (typeof globalEnabled === "boolean") return globalEnabled;
207
+ return true;
208
+ }
209
+
184
210
  export function loadSettings(): PiVccSettings {
185
211
  const parsed = readJson(settingsPath());
186
212
  if (!parsed || typeof parsed !== "object") return { ...DEFAULT_SETTINGS };
@@ -7,13 +7,14 @@ import {
7
7
  isCodexOutputLimitError,
8
8
  markCodexContextOverflowPending,
9
9
  } from "../core/codex-output-limit";
10
- import { loadSettings, getModelThreshold, resolveTriggerTokens } from "../core/settings";
10
+ import { loadSettings, getModelThreshold, isPiCoreCompactionEnabled, resolveTriggerTokens } from "../core/settings";
11
11
 
12
12
  type ProactiveContext = {
13
13
  model?: any;
14
14
  getContextUsage?: () => any;
15
15
  compact?: (options?: any) => void;
16
16
  ui?: any;
17
+ sessionManager?: { getCwd?: () => string };
17
18
  };
18
19
 
19
20
  const formatTokens = (n: number): string => {
@@ -182,11 +183,17 @@ export const registerProactiveThresholdHook = (pi: ExtensionAPI) => {
182
183
  }
183
184
  if (isCodexContextOverflowError(lastMessage)) {
184
185
  markCodexContextOverflowPending();
185
- // pi-core's overflow check also requires the assistant message to carry
186
- // the current model identity. Codex can omit it on failed responses;
187
- // force the recovery only for that case so matching responses continue
188
- // through pi-core's normal auto-retry path.
189
- if (!hasCurrentModelIdentity(lastMessage, ctx.model)) {
186
+ // pi-core's overflow compaction only fires when compaction is enabled AND
187
+ // the assistant message carries the current model identity. If either
188
+ // is missing pi-core bails (or its LLM compaction would re-overflow), so
189
+ // pi-vcc must drive the recovery compaction itself via ctx.compact(),
190
+ // whose manual path skips the `enabled` gate and uses pi-vcc's static
191
+ // summary. When pi-core will handle it, defer to avoid a racing second
192
+ // compaction that would abort pi-core's own retry.
193
+ const piCoreWillHandle =
194
+ hasCurrentModelIdentity(lastMessage, ctx.model) &&
195
+ isPiCoreCompactionEnabled(ctx.sessionManager?.getCwd?.());
196
+ if (!piCoreWillHandle) {
190
197
  triggerCodexContextOverflowCompaction(ctx);
191
198
  }
192
199
  return;