This commit is contained in:
bonald 2026-01-31 00:50:05 +09:00 committed by GitHub
commit 57bd703924
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -79,6 +79,7 @@ export function buildEmbeddedExtensionPaths(params: {
const compactionCfg = params.cfg?.agents?.defaults?.compaction; const compactionCfg = params.cfg?.agents?.defaults?.compaction;
setCompactionSafeguardRuntime(params.sessionManager, { setCompactionSafeguardRuntime(params.sessionManager, {
maxHistoryShare: compactionCfg?.maxHistoryShare, maxHistoryShare: compactionCfg?.maxHistoryShare,
model: params.model,
}); });
paths.push(resolvePiExtensionPath("compaction-safeguard")); paths.push(resolvePiExtensionPath("compaction-safeguard"));
} }

View File

@ -1,5 +1,8 @@
import type { Api, Model } from "@mariozechner/pi-ai";
export type CompactionSafeguardRuntimeValue = { export type CompactionSafeguardRuntimeValue = {
maxHistoryShare?: number; maxHistoryShare?: number;
model?: Model<Api>;
}; };
// Session-scoped runtime registry keyed by object identity. // Session-scoped runtime registry keyed by object identity.

View File

@ -146,8 +146,12 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
const toolFailureSection = formatToolFailuresSection(toolFailures); const toolFailureSection = formatToolFailuresSection(toolFailures);
const fallbackSummary = `${FALLBACK_SUMMARY}${toolFailureSection}${fileOpsSummary}`; const fallbackSummary = `${FALLBACK_SUMMARY}${toolFailureSection}${fileOpsSummary}`;
const model = ctx.model; const runtime = getCompactionSafeguardRuntime(ctx.sessionManager);
const model = ctx.model ?? runtime?.model;
if (!model) { if (!model) {
console.warn(
"Compaction safeguard: no model available (ctx.model and runtime.model both undefined)",
);
return { return {
compaction: { compaction: {
summary: fallbackSummary, summary: fallbackSummary,
@ -175,7 +179,6 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
const turnPrefixMessages = preparation.turnPrefixMessages ?? []; const turnPrefixMessages = preparation.turnPrefixMessages ?? [];
let messagesToSummarize = preparation.messagesToSummarize; let messagesToSummarize = preparation.messagesToSummarize;
const runtime = getCompactionSafeguardRuntime(ctx.sessionManager);
const maxHistoryShare = runtime?.maxHistoryShare ?? 0.5; const maxHistoryShare = runtime?.maxHistoryShare ?? 0.5;
const tokensBefore = const tokensBefore =