shariq-pi-extensions 0.2.17 → 0.2.18

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.
@@ -6,6 +6,7 @@ import { uuidv7, type Api, type Context, type Model, type Usage, type AssistantM
6
6
  import type { ExtensionContext, SessionBeforeCompactEvent } from "@earendil-works/pi-coding-agent";
7
7
  import type { SmartCompactionConfig } from "./config.ts";
8
8
  import {
9
+ CHECKPOINT_RESUMPTION_PREAMBLE,
9
10
  formatFileOperationsXml,
10
11
  sanitizeTagContent,
11
12
  SMART_COMPACTION_INITIAL_PROMPT,
@@ -544,7 +545,7 @@ export async function runSmartCompaction(
544
545
  lockfilesAndGeneratedAssets: gitState.lockfilesAndGeneratedAssets,
545
546
  });
546
547
 
547
- const finalSummary = `${finalSummaryText}${fileOpsXml}`;
548
+ const finalSummary = `${CHECKPOINT_RESUMPTION_PREAMBLE}${finalSummaryText}${fileOpsXml}`;
548
549
  const cycleCount = prior.cycleCount + 1;
549
550
 
550
551
  const details: SmartCompactionDetails = {
@@ -145,10 +145,19 @@ function extractTextContent(content: unknown): string {
145
145
  return "";
146
146
  }
147
147
 
148
+ export const CHECKPOINT_RESUMPTION_PREAMBLE =
149
+ `> **Context Checkpoint**: This is an automatically generated checkpoint condensing earlier conversation turns to free up context. Treat this captured context as established ground truth and continue the task directly without acknowledging or discussing this summary.\n\n`;
150
+
148
151
  export function serializeConversationForCompaction(messages: AgentMessage[]): string {
149
152
  const parts: string[] = [];
153
+ const totalMessages = messages.length;
154
+
155
+ for (let i = 0; i < totalMessages; i++) {
156
+ const msg = messages[i];
157
+ const isRecent = (totalMessages - i) <= 14;
158
+ const toolHead = isRecent ? 1500 : 500;
159
+ const toolTail = isRecent ? 1500 : 500;
150
160
 
151
- for (const msg of messages) {
152
161
  if (msg.role === "user") {
153
162
  const text = extractTextContent((msg as any).content);
154
163
  if (text) parts.push(`[User]:\n${sanitizeTagContent(text)}`);
@@ -179,7 +188,7 @@ export function serializeConversationForCompaction(messages: AgentMessage[]): st
179
188
 
180
189
  if (thinkingBlocks.length > 0) {
181
190
  const combinedThinking = thinkingBlocks.join("\n");
182
- parts.push(`[Assistant Thinking]:\n${sanitizeTagContent(truncateHeadAndTail(combinedThinking, 800, 800))}`);
191
+ parts.push(`[Assistant Thinking]:\n${sanitizeTagContent(truncateHeadAndTail(combinedThinking, isRecent ? 800 : 400, isRecent ? 800 : 400))}`);
183
192
  }
184
193
  if (textBlocks.length > 0) {
185
194
  parts.push(`[Assistant]:\n${sanitizeTagContent(textBlocks.join("\n"))}`);
@@ -190,7 +199,7 @@ export function serializeConversationForCompaction(messages: AgentMessage[]): st
190
199
  } else if (msg.role === "toolResult") {
191
200
  const text = extractTextContent((msg as any).content);
192
201
  if (text) {
193
- parts.push(`[Tool Result]:\n${sanitizeTagContent(truncateHeadAndTail(text, TOOL_RESULT_HEAD_CHARS, TOOL_RESULT_TAIL_CHARS))}`);
202
+ parts.push(`[Tool Result]:\n${sanitizeTagContent(truncateHeadAndTail(text, toolHead, toolTail))}`);
194
203
  }
195
204
  } else if (msg.role === "custom") {
196
205
  const text = extractTextContent((msg as any).content);
@@ -198,7 +207,7 @@ export function serializeConversationForCompaction(messages: AgentMessage[]): st
198
207
  } else if (msg.role === "bashExecution") {
199
208
  const cmd = (msg as any).command ?? "";
200
209
  const out = (msg as any).output ?? "";
201
- parts.push(`[Command Executed]:\n$ ${sanitizeTagContent(cmd)}\n${sanitizeTagContent(truncateHeadAndTail(out, 800, 800))}`);
210
+ parts.push(`[Command Executed]:\n$ ${sanitizeTagContent(cmd)}\n${sanitizeTagContent(truncateHeadAndTail(out, isRecent ? 800 : 400, isRecent ? 800 : 400))}`);
202
211
  } else if (msg.role === "compactionSummary" || msg.role === "branchSummary") {
203
212
  const summary = (msg as any).summary ?? "";
204
213
  if (summary) parts.push(`[Prior Summary]:\n${sanitizeTagContent(summary)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shariq-pi-extensions",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Cross-platform extension suite for the Pi coding agent.",
5
5
  "license": "MIT",
6
6
  "author": "Shariq Riaz",