mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 11:41:26 +00:00
feat: inject post-compaction workspace context as system event (#18023)
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
updateSessionStoreEntry,
|
||||
} from "../../config/sessions.js";
|
||||
import { emitDiagnosticEvent, isDiagnosticsEnabled } from "../../infra/diagnostic-events.js";
|
||||
import { enqueueSystemEvent } from "../../infra/system-events.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { estimateUsageCost, resolveModelCostConfig } from "../../utils/usage-format.js";
|
||||
import { resolveResponseUsageMode, type VerboseLevel } from "../thinking.js";
|
||||
@@ -36,6 +37,7 @@ import { appendUsageLine, formatResponseUsageLine } from "./agent-runner-utils.j
|
||||
import { createAudioAsVoiceBuffer, createBlockReplyPipeline } from "./block-reply-pipeline.js";
|
||||
import { resolveBlockStreamingCoalescing } from "./block-streaming.js";
|
||||
import { createFollowupRunner } from "./followup-runner.js";
|
||||
import { readPostCompactionContext } from "./post-compaction-context.js";
|
||||
import { enqueueFollowupRun, type FollowupRun, type QueueSettings } from "./queue.js";
|
||||
import { createReplyToModeFilterForChannel, resolveReplyToMode } from "./reply-threading.js";
|
||||
import { incrementRunCompactionCount, persistRunSessionUsage } from "./session-run-accounting.js";
|
||||
@@ -547,6 +549,21 @@ export async function runReplyAgent(params: {
|
||||
lastCallUsage: runResult.meta.agentMeta?.lastCallUsage,
|
||||
contextTokensUsed,
|
||||
});
|
||||
|
||||
// Inject post-compaction workspace context for the next agent turn
|
||||
if (sessionKey) {
|
||||
const workspaceDir = process.cwd();
|
||||
readPostCompactionContext(workspaceDir)
|
||||
.then((contextContent) => {
|
||||
if (contextContent) {
|
||||
enqueueSystemEvent(contextContent, { sessionKey });
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Silent failure — post-compaction context is best-effort
|
||||
});
|
||||
}
|
||||
|
||||
if (verboseEnabled) {
|
||||
const suffix = typeof count === "number" ? ` (count ${count})` : "";
|
||||
finalPayloads = [{ text: `🧹 Auto-compaction complete${suffix}.` }, ...finalPayloads];
|
||||
|
||||
Reference in New Issue
Block a user