shariq-pi-extensions 0.2.11 → 0.2.13

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.
@@ -63,13 +63,23 @@ export function createFactoryResponsesWebSocketFetch(options: FactoryWebSocketFe
63
63
  });
64
64
 
65
65
  const abort = () => {
66
- socket.close();
67
- void writer.abort(new Error("Factory request was aborted"));
66
+ init?.signal?.removeEventListener("abort", abort);
67
+ try {
68
+ socket.close();
69
+ } catch {
70
+ // Ignore socket close errors during abort.
71
+ }
72
+ void writer.abort(init?.signal?.reason || new Error("Factory request was aborted")).catch(() => undefined);
68
73
  if (!settled) {
69
74
  settled = true;
70
- reject(new Error("Factory request was aborted"));
75
+ reject(init?.signal?.reason || new Error("Factory request was aborted"));
71
76
  }
72
77
  };
78
+
79
+ if (init?.signal?.aborted) {
80
+ abort();
81
+ return;
82
+ }
73
83
  init?.signal?.addEventListener("abort", abort, { once: true });
74
84
 
75
85
  socket.once("open", () => {
@@ -86,11 +96,11 @@ export function createFactoryResponsesWebSocketFetch(options: FactoryWebSocketFe
86
96
 
87
97
  socket.on("message", (data: RawData) => {
88
98
  const text = data.toString();
89
- void writer.write(encoder.encode(`data: ${text}\n\n`));
99
+ void writer.write(encoder.encode(`data: ${text}\n\n`)).catch(() => undefined);
90
100
  try {
91
101
  const event = JSON.parse(text) as { type?: string };
92
102
  if (event.type === "response.completed" || event.type === "response.failed" || event.type === "error") {
93
- void writer.close();
103
+ void writer.close().catch(() => undefined);
94
104
  socket.close();
95
105
  }
96
106
  } catch {
@@ -99,6 +109,7 @@ export function createFactoryResponsesWebSocketFetch(options: FactoryWebSocketFe
99
109
  });
100
110
 
101
111
  socket.once("unexpected-response", (_request, response) => {
112
+ init?.signal?.removeEventListener("abort", abort);
102
113
  const chunks: Buffer[] = [];
103
114
  response.on("data", (chunk: Buffer) => chunks.push(chunk));
104
115
  response.on("end", () => {
@@ -114,11 +125,12 @@ export function createFactoryResponsesWebSocketFetch(options: FactoryWebSocketFe
114
125
  });
115
126
 
116
127
  socket.once("error", (error) => {
128
+ init?.signal?.removeEventListener("abort", abort);
117
129
  if (!settled) {
118
130
  settled = true;
119
131
  reject(error);
120
132
  } else if (opened) {
121
- void writer.abort(error);
133
+ void writer.abort(error).catch(() => undefined);
122
134
  }
123
135
  });
124
136
  socket.once("close", () => {
@@ -40,7 +40,10 @@ Settings are persisted in `~/.pi/agent/smart-compaction.json`:
40
40
  "version": 1,
41
41
  "enabled": true,
42
42
  "model": "inherit",
43
- "thinkingLevel": "medium",
44
- "maxSummaryTokens": 16384
43
+ "thinkingLevel": "inherit"
45
44
  }
46
45
  ```
46
+
47
+ - `model`: `"inherit"` (uses current active session model) or explicit `"provider/model-id"`.
48
+ - `thinkingLevel`: `"inherit"` (uses current session's thinking level) or `"off" | "low" | "medium" | "high" | "max"`.
49
+ - `maxSummaryTokens`: optional override integer; if omitted, dynamically defaults to the model's full native output capacity (65,536–128,000+ tokens) so summaries are never artificially truncated.
@@ -6,16 +6,15 @@ export interface SmartCompactionConfig {
6
6
  version: 1;
7
7
  enabled: boolean;
8
8
  model: string; // "inherit" or "provider/model-id"
9
- thinkingLevel?: "off" | "low" | "medium" | "high";
10
- maxSummaryTokens?: number;
9
+ thinkingLevel?: "inherit" | "off" | "low" | "medium" | "high" | "max";
10
+ maxSummaryTokens?: number; // optional override; defaults to model's full capacity
11
11
  }
12
12
 
13
13
  export const DEFAULT_SMART_COMPACTION_CONFIG: SmartCompactionConfig = {
14
14
  version: 1,
15
15
  enabled: true,
16
16
  model: "inherit",
17
- thinkingLevel: "medium",
18
- maxSummaryTokens: 16384,
17
+ thinkingLevel: "inherit",
19
18
  };
20
19
 
21
20
  export function smartCompactionConfigPath(): string {
@@ -30,12 +29,12 @@ export function loadSmartCompactionConfig(file = smartCompactionConfigPath()): S
30
29
  version: 1,
31
30
  enabled: typeof raw.enabled === "boolean" ? raw.enabled : DEFAULT_SMART_COMPACTION_CONFIG.enabled,
32
31
  model: typeof raw.model === "string" && raw.model.trim() ? raw.model.trim() : DEFAULT_SMART_COMPACTION_CONFIG.model,
33
- thinkingLevel: raw.thinkingLevel && ["off", "low", "medium", "high"].includes(raw.thinkingLevel)
34
- ? raw.thinkingLevel
32
+ thinkingLevel: raw.thinkingLevel && ["inherit", "off", "low", "medium", "high", "max"].includes(raw.thinkingLevel)
33
+ ? (raw.thinkingLevel as SmartCompactionConfig["thinkingLevel"])
35
34
  : DEFAULT_SMART_COMPACTION_CONFIG.thinkingLevel,
36
35
  maxSummaryTokens: typeof raw.maxSummaryTokens === "number" && raw.maxSummaryTokens > 0
37
36
  ? raw.maxSummaryTokens
38
- : DEFAULT_SMART_COMPACTION_CONFIG.maxSummaryTokens,
37
+ : undefined,
39
38
  };
40
39
  } catch {
41
40
  return { ...DEFAULT_SMART_COMPACTION_CONFIG };
@@ -50,8 +49,8 @@ export function saveSmartCompactionConfig(config: SmartCompactionConfig, file =
50
49
  version: 1,
51
50
  enabled: config.enabled,
52
51
  model: config.model || "inherit",
53
- thinkingLevel: config.thinkingLevel ?? "medium",
54
- maxSummaryTokens: config.maxSummaryTokens ?? 16384,
52
+ thinkingLevel: config.thinkingLevel ?? "inherit",
53
+ maxSummaryTokens: config.maxSummaryTokens,
55
54
  };
56
55
  try {
57
56
  fs.writeFileSync(temporary, `${JSON.stringify(document, null, 2)}\n`, { mode: 0o600 });
@@ -44,7 +44,7 @@ export function resolveCompactionModel(
44
44
 
45
45
  export interface RunSmartCompactionOptions {
46
46
  event: SessionBeforeCompactEvent;
47
- ctx: Pick<ExtensionContext, "model" | "modelRegistry">;
47
+ ctx: Pick<ExtensionContext, "model" | "modelRegistry" | "thinkingLevel">;
48
48
  config: SmartCompactionConfig;
49
49
  }
50
50
 
@@ -97,18 +97,27 @@ export async function runSmartCompaction(
97
97
  ],
98
98
  };
99
99
 
100
- const requestedMaxTokens = config.maxSummaryTokens ?? 16384;
101
- const maxTokens = model.maxTokens > 0 ? Math.min(requestedMaxTokens, model.maxTokens) : requestedMaxTokens;
102
-
103
100
  const completeOptions: Record<string, unknown> = {
104
- maxTokens,
105
101
  signal,
106
102
  cacheRetention: "none",
107
103
  sessionId: uuidv7(),
108
104
  };
109
105
 
110
- if (model.reasoning && config.thinkingLevel && config.thinkingLevel !== "off") {
111
- completeOptions.reasoning = config.thinkingLevel;
106
+ // If user explicitly configured a maxSummaryTokens override, pass it.
107
+ // Otherwise, omit maxTokens so the provider uses the model's full native maximum output capacity (e.g. 128k, 65k).
108
+ if (typeof config.maxSummaryTokens === "number" && config.maxSummaryTokens > 0) {
109
+ completeOptions.maxTokens = config.maxSummaryTokens;
110
+ }
111
+
112
+ // Resolve reasoning effort / thinking level
113
+ if (model.reasoning) {
114
+ const desiredThinking = config.thinkingLevel === "inherit" || !config.thinkingLevel
115
+ ? ctx.thinkingLevel
116
+ : config.thinkingLevel;
117
+
118
+ if (desiredThinking && desiredThinking !== "off") {
119
+ completeOptions.reasoning = desiredThinking;
120
+ }
112
121
  }
113
122
 
114
123
  const response = await ctx.modelRegistry.complete(model, context, completeOptions as any);
@@ -164,11 +164,19 @@ export function createSmartCompactionExtension(options: SmartCompactionExtension
164
164
  }
165
165
 
166
166
  // Default status
167
+ const currentModelDesc = config.model === "inherit"
168
+ ? `inherit (${cmdCtx.model ? `${cmdCtx.model.provider}/${cmdCtx.model.id}` : "active session model"})`
169
+ : config.model;
170
+ const currentThinkingDesc = config.thinkingLevel === "inherit"
171
+ ? `inherit (${cmdCtx.thinkingLevel ?? "session default"})`
172
+ : (config.thinkingLevel ?? "inherit");
173
+ const maxTokensDesc = config.maxSummaryTokens ? `${config.maxSummaryTokens}` : "unlimited (full model output capacity)";
174
+
167
175
  const status = [
168
176
  `Smart Compaction: ${config.enabled ? "ENABLED" : "DISABLED"}`,
169
- `Model: ${config.model} (${config.model === "inherit" ? (cmdCtx.model ? `${cmdCtx.model.provider}/${cmdCtx.model.id}` : "inherit") : config.model})`,
170
- `Thinking Level: ${config.thinkingLevel ?? "medium"}`,
171
- `Max Tokens: ${config.maxSummaryTokens ?? 4096}`,
177
+ `Model: ${currentModelDesc}`,
178
+ `Thinking Level: ${currentThinkingDesc}`,
179
+ `Max Output Tokens: ${maxTokensDesc}`,
172
180
  "",
173
181
  "Commands:",
174
182
  " /smart-compaction enable | disable",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shariq-pi-extensions",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Cross-platform extension suite for the Pi coding agent.",
5
5
  "license": "MIT",
6
6
  "author": "Shariq Riaz",