mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
Format compaction PR changes and validate locally
- apply oxfmt formatting to changed files - keep replay-safety, typed hook, and changelog fixes - validated targeted tests, oxfmt check, and check:changed locally
This commit is contained in:
committed by
Peter Steinberger
parent
cb4f4f5f3a
commit
9de06e3dee
@@ -160,13 +160,13 @@ Npm specs are registry-only (package name + optional exact version or dist-tag).
|
||||
|
||||
## Bundled hooks
|
||||
|
||||
| Hook | Events | What it does |
|
||||
| --------------------- | ------------------------------ | ----------------------------------------------------- |
|
||||
| session-memory | `command:new`, `command:reset` | Saves session context to `<workspace>/memory/` |
|
||||
| bootstrap-extra-files | `agent:bootstrap` | Injects additional bootstrap files from glob patterns |
|
||||
| command-logger | `command` | Logs all commands to `~/.openclaw/logs/commands.log` |
|
||||
| compaction-notifier | `session:compact:before`, `session:compact:after` | Sends visible chat notices when session compaction starts/ends |
|
||||
| boot-md | `gateway:startup` | Runs `BOOT.md` when the gateway starts |
|
||||
| Hook | Events | What it does |
|
||||
| --------------------- | ------------------------------------------------- | -------------------------------------------------------------- |
|
||||
| session-memory | `command:new`, `command:reset` | Saves session context to `<workspace>/memory/` |
|
||||
| bootstrap-extra-files | `agent:bootstrap` | Injects additional bootstrap files from glob patterns |
|
||||
| command-logger | `command` | Logs all commands to `~/.openclaw/logs/commands.log` |
|
||||
| compaction-notifier | `session:compact:before`, `session:compact:after` | Sends visible chat notices when session compaction starts/ends |
|
||||
| boot-md | `gateway:startup` | Runs `BOOT.md` when the gateway starts |
|
||||
|
||||
Enable any bundled hook:
|
||||
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
name: compaction-notifier
|
||||
description: "Send visible chat notices when session compaction starts and finishes."
|
||||
metadata:
|
||||
{ "openclaw": { "emoji": "🧹", "events": ["session:compact:before", "session:compact:after"], "always": true } }
|
||||
{
|
||||
"openclaw":
|
||||
{
|
||||
"emoji": "🧹",
|
||||
"events": ["session:compact:before", "session:compact:after"],
|
||||
"always": true,
|
||||
},
|
||||
}
|
||||
---
|
||||
|
||||
# Compaction Notifier
|
||||
|
||||
@@ -11,23 +11,27 @@ const handler: HookHandler = async (event) => {
|
||||
|
||||
if (event.type === "session" && event.action === "compact:before") {
|
||||
const messageCount = readOptionalNumber(context, "messageCount");
|
||||
const messageSuffix = messageCount !== undefined && messageCount >= 0
|
||||
? ` (${messageCount} messages)`
|
||||
: "";
|
||||
event.messages.push(`🧹 Compacting context${messageSuffix} so I can continue without losing history…`);
|
||||
const messageSuffix =
|
||||
messageCount !== undefined && messageCount >= 0 ? ` (${messageCount} messages)` : "";
|
||||
event.messages.push(
|
||||
`🧹 Compacting context${messageSuffix} so I can continue without losing history…`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type === "session" && event.action === "compact:after") {
|
||||
const tokensBefore = readOptionalNumber(context, "tokensBefore");
|
||||
const tokensAfter = readOptionalNumber(context, "tokensAfter");
|
||||
const tokenDelta = tokensBefore !== undefined && tokensAfter !== undefined
|
||||
? ` (${tokensBefore.toLocaleString()} → ${tokensAfter.toLocaleString()} tokens)`
|
||||
: "";
|
||||
const tokenDelta =
|
||||
tokensBefore !== undefined && tokensAfter !== undefined
|
||||
? ` (${tokensBefore.toLocaleString()} → ${tokensAfter.toLocaleString()} tokens)`
|
||||
: "";
|
||||
event.messages.push(`✅ Context compacted${tokenDelta}. Continuing from where I left off.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`[compaction-notifier] failed: ${error instanceof Error ? error.message : String(error)}`);
|
||||
console.warn(
|
||||
`[compaction-notifier] failed: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user