pi-cache-optimizer 2.10.2 → 2.10.3
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 +1 -1
- package/src/prompt-rewrite.ts +18 -0
package/package.json
CHANGED
package/src/prompt-rewrite.ts
CHANGED
|
@@ -182,6 +182,12 @@ export function compressSkillsInSystemPrompt(
|
|
|
182
182
|
* position and `<skills>` wrapper. Returns true only when Pi's re-rendered prompt
|
|
183
183
|
* really contains the compressed list; otherwise the section is restored and the
|
|
184
184
|
* caller falls back to the string substitution.
|
|
185
|
+
*
|
|
186
|
+
* A custom base prompt (`customPrompt`) can hold its own copy of the verbose
|
|
187
|
+
* list: pi-subagents passes the parent's rendered prompt there, and an idle
|
|
188
|
+
* parent renders its unedited base options. That copy is compressed in place
|
|
189
|
+
* too; otherwise the re-render still contains the verbose list, the section edit
|
|
190
|
+
* is rolled back, and the string fallback forces the prompt.
|
|
185
191
|
*/
|
|
186
192
|
export function compressSkillsViaSection(event: {
|
|
187
193
|
readonly systemPrompt: string;
|
|
@@ -199,11 +205,23 @@ export function compressSkillsViaSection(event: {
|
|
|
199
205
|
const compressed = formatSkillsForPromptCompressed(options.skills, skillFileReadTool(options) ?? "read").trim();
|
|
200
206
|
if (!compressed || compressed.length >= verbose.length) return false;
|
|
201
207
|
|
|
208
|
+
const previousCustom = options.customPrompt;
|
|
209
|
+
const customHasVerbose = typeof previousCustom === "string" && previousCustom.includes(verbose);
|
|
210
|
+
if (customHasVerbose) options.customPrompt = previousCustom.split(verbose).join(compressed);
|
|
211
|
+
// Only the custom prompt held the list (Pi renders no skills section of its own, e.g. no
|
|
212
|
+
// read/bash tool): done, and no `<skills>` section is added where Pi renders none.
|
|
213
|
+
if (customHasVerbose && !event.systemPrompt.includes(verbose)) {
|
|
214
|
+
if (event.systemPrompt.includes(compressed)) return true;
|
|
215
|
+
options.customPrompt = previousCustom;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
202
219
|
const previous = sections.skills;
|
|
203
220
|
sections.skills = compressed;
|
|
204
221
|
if (event.systemPrompt.includes(compressed) && !event.systemPrompt.includes(verbose)) return true;
|
|
205
222
|
if (previous === undefined) delete sections.skills;
|
|
206
223
|
else sections.skills = previous;
|
|
224
|
+
options.customPrompt = previousCustom;
|
|
207
225
|
return false;
|
|
208
226
|
}
|
|
209
227
|
|