Format compaction PR changes and validate locally · openclaw/openclaw@9de06e3
simplyclever
·
2026-05-03
·
via Recent Commits to openclaw:main
File tree
src/hooks/bundled/compaction-notifier
| Original file line number | Diff line number | Diff line change |
|---|
@@ -160,13 +160,13 @@ Npm specs are registry-only (package name + optional exact version or dist-tag).
|
160 | 160 | |
161 | 161 | ## Bundled hooks |
162 | 162 | |
163 | | -| Hook | Events | What it does | |
164 | | -| --------------------- | ------------------------------ | ----------------------------------------------------- | |
165 | | -| session-memory | `command:new`, `command:reset` | Saves session context to `<workspace>/memory/` | |
166 | | -| bootstrap-extra-files | `agent:bootstrap` | Injects additional bootstrap files from glob patterns | |
167 | | -| command-logger | `command` | Logs all commands to `~/.openclaw/logs/commands.log` | |
168 | | -| compaction-notifier | `session:compact:before`, `session:compact:after` | Sends visible chat notices when session compaction starts/ends | |
169 | | -| boot-md | `gateway:startup` | Runs `BOOT.md` when the gateway starts | |
| 163 | +| Hook | Events | What it does | |
| 164 | +| --------------------- | ------------------------------------------------- | -------------------------------------------------------------- | |
| 165 | +| session-memory | `command:new`, `command:reset` | Saves session context to `<workspace>/memory/` | |
| 166 | +| bootstrap-extra-files | `agent:bootstrap` | Injects additional bootstrap files from glob patterns | |
| 167 | +| command-logger | `command` | Logs all commands to `~/.openclaw/logs/commands.log` | |
| 168 | +| compaction-notifier | `session:compact:before`, `session:compact:after` | Sends visible chat notices when session compaction starts/ends | |
| 169 | +| boot-md | `gateway:startup` | Runs `BOOT.md` when the gateway starts | |
170 | 170 | |
171 | 171 | Enable any bundled hook: |
172 | 172 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,14 @@
|
2 | 2 | name: compaction-notifier |
3 | 3 | description: "Send visible chat notices when session compaction starts and finishes." |
4 | 4 | metadata: |
5 | | -{ "openclaw": { "emoji": "🧹", "events": ["session:compact:before", "session:compact:after"], "always": true } } |
| 5 | +{ |
| 6 | +"openclaw": |
| 7 | +{ |
| 8 | +"emoji": "🧹", |
| 9 | +"events": ["session:compact:before", "session:compact:after"], |
| 10 | +"always": true, |
| 11 | +}, |
| 12 | +} |
6 | 13 | --- |
7 | 14 | |
8 | 15 | # Compaction Notifier |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,23 +11,27 @@ const handler: HookHandler = async (event) => {
|
11 | 11 | |
12 | 12 | if (event.type === "session" && event.action === "compact:before") { |
13 | 13 | const messageCount = readOptionalNumber(context, "messageCount"); |
14 | | -const messageSuffix = messageCount !== undefined && messageCount >= 0 |
15 | | - ? ` (${messageCount} messages)` |
16 | | - : ""; |
17 | | -event.messages.push(`🧹 Compacting context${messageSuffix} so I can continue without losing history…`); |
| 14 | +const messageSuffix = |
| 15 | +messageCount !== undefined && messageCount >= 0 ? ` (${messageCount} messages)` : ""; |
| 16 | +event.messages.push( |
| 17 | +`🧹 Compacting context${messageSuffix} so I can continue without losing history…`, |
| 18 | +); |
18 | 19 | return; |
19 | 20 | } |
20 | 21 | |
21 | 22 | if (event.type === "session" && event.action === "compact:after") { |
22 | 23 | const tokensBefore = readOptionalNumber(context, "tokensBefore"); |
23 | 24 | const tokensAfter = readOptionalNumber(context, "tokensAfter"); |
24 | | -const tokenDelta = tokensBefore !== undefined && tokensAfter !== undefined |
25 | | - ? ` (${tokensBefore.toLocaleString()} → ${tokensAfter.toLocaleString()} tokens)` |
26 | | - : ""; |
| 25 | +const tokenDelta = |
| 26 | +tokensBefore !== undefined && tokensAfter !== undefined |
| 27 | + ? ` (${tokensBefore.toLocaleString()} → ${tokensAfter.toLocaleString()} tokens)` |
| 28 | + : ""; |
27 | 29 | event.messages.push(`✅ Context compacted${tokenDelta}. Continuing from where I left off.`); |
28 | 30 | } |
29 | 31 | } catch (error) { |
30 | | -console.warn(`[compaction-notifier] failed: ${error instanceof Error ? error.message : String(error)}`); |
| 32 | +console.warn( |
| 33 | +`[compaction-notifier] failed: ${error instanceof Error ? error.message : String(error)}`, |
| 34 | +); |
31 | 35 | } |
32 | 36 | }; |
33 | 37 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。