@raquezha/noheadroom 0.2.2 → 0.2.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/dist/index.js +9 -5
- package/extensions/index.ts +7 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -293,8 +293,8 @@ function generateFingerprint(messages) {
|
|
|
293
293
|
return messages
|
|
294
294
|
.map((m) => {
|
|
295
295
|
const converted = convertMessage(m);
|
|
296
|
-
const
|
|
297
|
-
return `${m.role}:${
|
|
296
|
+
const text = converted ? extractOpenAIText(converted) : "";
|
|
297
|
+
return `${m.role}:${text.length}:${stableHash(text)}`;
|
|
298
298
|
})
|
|
299
299
|
.join(",");
|
|
300
300
|
}
|
|
@@ -382,12 +382,16 @@ function announceAppliedCompression(pi, ctx, result, appliedMessages) {
|
|
|
382
382
|
// Note: we no longer use pi.appendEntry or pi.sendMessage here because
|
|
383
383
|
// modifying the session history inside the context event triggers an infinite loop.
|
|
384
384
|
// Non-interactive `pi -p` does not always show footer/status UI, so print an explicit proof line.
|
|
385
|
-
|
|
385
|
+
// In interactive Pi TUI, writing to stderr during the context hook can leave a stale "Working..." row.
|
|
386
|
+
if (!ctx.hasUI)
|
|
387
|
+
process.stderr.write(`🗜 ${line}\n`);
|
|
386
388
|
}
|
|
387
389
|
function announceGuardSkip(ctx, reason, result) {
|
|
388
390
|
const line = `noheadroom: compression skipped by guard (${reason}); Headroom reported ${result.tokensSaved.toLocaleString()} tokens saved but Pi context was left unchanged`;
|
|
389
391
|
ctx.ui.notify(line, "warning");
|
|
390
|
-
|
|
392
|
+
// In interactive Pi TUI, writing to stderr during the context hook can leave a stale "Working..." row.
|
|
393
|
+
if (!ctx.hasUI)
|
|
394
|
+
process.stderr.write(`⚠ ${line}\n`);
|
|
391
395
|
}
|
|
392
396
|
function recordCompressionError(runtime, ctx, error) {
|
|
393
397
|
runtime.state.stats.lastError = getErrorMessage(error);
|
|
@@ -479,7 +483,7 @@ function renderFooterStatus(ctx, config, state) {
|
|
|
479
483
|
if (!state.stats.last)
|
|
480
484
|
return paint("success", "✓") + paint("dim", " Headroom");
|
|
481
485
|
const pct = Math.round((1 - state.stats.last.compressionRatio) * 100);
|
|
482
|
-
return (paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()}
|
|
486
|
+
return (paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()} sve)`));
|
|
483
487
|
}
|
|
484
488
|
async function showProxyStats(ctx, client, config) {
|
|
485
489
|
if (isRemoteBlocked(config)) {
|
package/extensions/index.ts
CHANGED
|
@@ -368,8 +368,8 @@ function generateFingerprint(messages: AgentMessage[]): string {
|
|
|
368
368
|
return messages
|
|
369
369
|
.map((m) => {
|
|
370
370
|
const converted = convertMessage(m);
|
|
371
|
-
const
|
|
372
|
-
return `${m.role}:${
|
|
371
|
+
const text = converted ? extractOpenAIText(converted) : "";
|
|
372
|
+
return `${m.role}:${text.length}:${stableHash(text)}`;
|
|
373
373
|
})
|
|
374
374
|
.join(",");
|
|
375
375
|
}
|
|
@@ -460,13 +460,15 @@ function announceAppliedCompression(
|
|
|
460
460
|
// Note: we no longer use pi.appendEntry or pi.sendMessage here because
|
|
461
461
|
// modifying the session history inside the context event triggers an infinite loop.
|
|
462
462
|
// Non-interactive `pi -p` does not always show footer/status UI, so print an explicit proof line.
|
|
463
|
-
|
|
463
|
+
// In interactive Pi TUI, writing to stderr during the context hook can leave a stale "Working..." row.
|
|
464
|
+
if (!ctx.hasUI) process.stderr.write(`🗜 ${line}\n`);
|
|
464
465
|
}
|
|
465
466
|
|
|
466
467
|
function announceGuardSkip(ctx: ExtensionContext, reason: string, result: CompressResult): void {
|
|
467
468
|
const line = `noheadroom: compression skipped by guard (${reason}); Headroom reported ${result.tokensSaved.toLocaleString()} tokens saved but Pi context was left unchanged`;
|
|
468
469
|
ctx.ui.notify(line, "warning");
|
|
469
|
-
|
|
470
|
+
// In interactive Pi TUI, writing to stderr during the context hook can leave a stale "Working..." row.
|
|
471
|
+
if (!ctx.hasUI) process.stderr.write(`⚠ ${line}\n`);
|
|
470
472
|
}
|
|
471
473
|
|
|
472
474
|
function recordCompressionError(runtime: HeadroomRuntime, ctx: ExtensionContext, error: unknown): void {
|
|
@@ -576,7 +578,7 @@ function renderFooterStatus(ctx: ExtensionContext, config: HeadroomConfig, state
|
|
|
576
578
|
|
|
577
579
|
const pct = Math.round((1 - state.stats.last.compressionRatio) * 100);
|
|
578
580
|
return (
|
|
579
|
-
paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()}
|
|
581
|
+
paint("success", "✓") + paint("dim", ` Headroom -${pct}% (${state.stats.last.tokensSaved.toLocaleString()} sve)`)
|
|
580
582
|
);
|
|
581
583
|
}
|
|
582
584
|
|
package/package.json
CHANGED