clawprobe 0.1.0
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/README.md +301 -0
- package/dist/cli/commands/compacts.d.ts +11 -0
- package/dist/cli/commands/compacts.d.ts.map +1 -0
- package/dist/cli/commands/compacts.js +68 -0
- package/dist/cli/commands/compacts.js.map +1 -0
- package/dist/cli/commands/context.d.ts +8 -0
- package/dist/cli/commands/context.d.ts.map +1 -0
- package/dist/cli/commands/context.js +78 -0
- package/dist/cli/commands/context.js.map +1 -0
- package/dist/cli/commands/cost.d.ts +12 -0
- package/dist/cli/commands/cost.d.ts.map +1 -0
- package/dist/cli/commands/cost.js +52 -0
- package/dist/cli/commands/cost.js.map +1 -0
- package/dist/cli/commands/memory.d.ts +36 -0
- package/dist/cli/commands/memory.d.ts.map +1 -0
- package/dist/cli/commands/memory.js +139 -0
- package/dist/cli/commands/memory.js.map +1 -0
- package/dist/cli/commands/session.d.ts +10 -0
- package/dist/cli/commands/session.d.ts.map +1 -0
- package/dist/cli/commands/session.js +95 -0
- package/dist/cli/commands/session.js.map +1 -0
- package/dist/cli/commands/status.d.ts +9 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +68 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/suggest.d.ts +11 -0
- package/dist/cli/commands/suggest.d.ts.map +1 -0
- package/dist/cli/commands/suggest.js +68 -0
- package/dist/cli/commands/suggest.js.map +1 -0
- package/dist/cli/format.d.ts +29 -0
- package/dist/cli/format.d.ts.map +1 -0
- package/dist/cli/format.js +125 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/core/config.d.ts +63 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +92 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/db.d.ts +87 -0
- package/dist/core/db.d.ts.map +1 -0
- package/dist/core/db.js +263 -0
- package/dist/core/db.js.map +1 -0
- package/dist/core/jsonl-parser.d.ts +55 -0
- package/dist/core/jsonl-parser.d.ts.map +1 -0
- package/dist/core/jsonl-parser.js +79 -0
- package/dist/core/jsonl-parser.js.map +1 -0
- package/dist/core/memory-editor.d.ts +18 -0
- package/dist/core/memory-editor.d.ts.map +1 -0
- package/dist/core/memory-editor.js +125 -0
- package/dist/core/memory-editor.js.map +1 -0
- package/dist/core/session-store.d.ts +35 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +66 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/watcher.d.ts +19 -0
- package/dist/core/watcher.d.ts.map +1 -0
- package/dist/core/watcher.js +83 -0
- package/dist/core/watcher.js.map +1 -0
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +147 -0
- package/dist/daemon.js.map +1 -0
- package/dist/engines/compact-diff.d.ts +19 -0
- package/dist/engines/compact-diff.d.ts.map +1 -0
- package/dist/engines/compact-diff.js +124 -0
- package/dist/engines/compact-diff.js.map +1 -0
- package/dist/engines/cost.d.ts +73 -0
- package/dist/engines/cost.d.ts.map +1 -0
- package/dist/engines/cost.js +149 -0
- package/dist/engines/cost.js.map +1 -0
- package/dist/engines/file-analyzer.d.ts +28 -0
- package/dist/engines/file-analyzer.d.ts.map +1 -0
- package/dist/engines/file-analyzer.js +139 -0
- package/dist/engines/file-analyzer.js.map +1 -0
- package/dist/engines/rule-engine.d.ts +25 -0
- package/dist/engines/rule-engine.d.ts.map +1 -0
- package/dist/engines/rule-engine.js +209 -0
- package/dist/engines/rule-engine.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +207 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# clawprobe 🦞🔬
|
|
2
|
+
|
|
3
|
+
**The missing observability layer for OpenClaw**
|
|
4
|
+
|
|
5
|
+
See what your agent thinks. Track what it forgets. Know what you spend.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g clawprobe
|
|
9
|
+
clawprobe start
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Why clawprobe?
|
|
15
|
+
|
|
16
|
+
OpenClaw users regularly face three problems with no good solution:
|
|
17
|
+
|
|
18
|
+
**1. Runaway API costs** — Bills of $22/day to $3,600/month. The built-in `/context detail` command has a known 10x token undercount bug. You're flying blind.
|
|
19
|
+
|
|
20
|
+
**2. Silent memory loss** — Compaction silently discards conversation context mid-task. Agreed-upon decisions, file paths, preferences — gone. You don't even know what was lost.
|
|
21
|
+
|
|
22
|
+
**3. Memory is a black box** — What does your agent actually remember? Editing `MEMORY.md` by hand is the only option.
|
|
23
|
+
|
|
24
|
+
clawprobe fixes all three — without touching a single line of OpenClaw's internals.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## How it works
|
|
29
|
+
|
|
30
|
+
clawprobe reads OpenClaw's existing data files — session transcripts, session store, workspace memory files — and turns them into actionable insights. No code changes, no ContextEngine plugins, no configuration required.
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
OpenClaw data files clawprobe
|
|
34
|
+
───────────────────── ──────────────────────────────────
|
|
35
|
+
sessions.json → Accurate token counts & cost tracking
|
|
36
|
+
*.jsonl transcripts → Compact event detection & diff
|
|
37
|
+
workspace/*.md files → File size analysis & truncation detection
|
|
38
|
+
MEMORY.md → Memory browser & editor
|
|
39
|
+
memory/*.sqlite → Semantic memory search
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
### 💰 Cost Tracking
|
|
47
|
+
|
|
48
|
+
See exactly where your API budget goes, broken down by day, week, and month.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
$ clawprobe cost --week
|
|
52
|
+
|
|
53
|
+
💰 Weekly Cost (Mar 10 – Mar 17, 2026)
|
|
54
|
+
|
|
55
|
+
Total: $18.42
|
|
56
|
+
Daily avg: $2.63
|
|
57
|
+
Month est: $78.90
|
|
58
|
+
|
|
59
|
+
Mon ██████████ $3.21
|
|
60
|
+
Tue ████████ $2.84
|
|
61
|
+
Wed ████████████████ $4.12 ← peak
|
|
62
|
+
Thu ██████ $2.10
|
|
63
|
+
Fri █████████ $2.95
|
|
64
|
+
Sat ████ $1.52
|
|
65
|
+
Sun █████ $1.68
|
|
66
|
+
|
|
67
|
+
Input tokens: 412,000 (78%) $14.42
|
|
68
|
+
Output tokens: 115,000 (22%) $4.00
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 📦 Compact Event Tracking
|
|
72
|
+
|
|
73
|
+
Every time OpenClaw compacts your session, clawprobe captures exactly what was lost — and lets you save it to long-term memory in one command.
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
$ clawprobe compacts
|
|
77
|
+
|
|
78
|
+
📦 Compact Events
|
|
79
|
+
|
|
80
|
+
#3 Today 14:22
|
|
81
|
+
14 messages compacted (Turn 3 → Turn 16)
|
|
82
|
+
Tokens before: 38,450
|
|
83
|
+
|
|
84
|
+
⚠ Potentially lost:
|
|
85
|
+
Turn 3 👤 "This project uses PostgreSQL, not MySQL"
|
|
86
|
+
Turn 12 👤 "API response format must use snake_case"
|
|
87
|
+
|
|
88
|
+
Summary: "User is building a TypeScript backend..."
|
|
89
|
+
→ Missing: database choice, API format preference
|
|
90
|
+
|
|
91
|
+
[run: clawprobe memory save-compact 3]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 🧠 Memory Browser
|
|
95
|
+
|
|
96
|
+
Browse, search, edit, and add to your agent's memory — no more hand-editing Markdown.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
$ clawprobe memory search "database"
|
|
100
|
+
|
|
101
|
+
🔍 3 results
|
|
102
|
+
|
|
103
|
+
1. MEMORY.md:8 (score: 0.92)
|
|
104
|
+
"Database: PostgreSQL. Not MySQL. Team prefers PG advanced features."
|
|
105
|
+
|
|
106
|
+
2. memory/2026-03-10.md:15 (score: 0.85)
|
|
107
|
+
"Decided on Prisma ORM for migrations. Scripts in src/migrations/."
|
|
108
|
+
|
|
109
|
+
3. memory/2026-03-08.md:3 (score: 0.71)
|
|
110
|
+
"Redis for caching layer. Config in .env."
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
$ clawprobe memory add "New requirement: API pagination, default 20 items per page"
|
|
115
|
+
✅ Added to MEMORY.md
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 🔍 Context Analysis
|
|
119
|
+
|
|
120
|
+
Understand how your agent's context window is being used, and catch issues before they cost you.
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
$ clawprobe context
|
|
124
|
+
|
|
125
|
+
🔍 Context Analysis
|
|
126
|
+
|
|
127
|
+
Workspace files:
|
|
128
|
+
SOUL.md 912 chars ~228 tok ✓ fully injected
|
|
129
|
+
AGENTS.md 1,742 chars ~436 tok ✓ fully injected
|
|
130
|
+
TOOLS.md 54,210 chars ~13,553 tok ⚠ TRUNCATED → 20,000 chars (~5,000 tok)
|
|
131
|
+
USER.md 388 chars ~97 tok ✓ fully injected
|
|
132
|
+
MEMORY.md 912 chars ~228 tok ✓ fully injected
|
|
133
|
+
|
|
134
|
+
Context tokens (from session): 31,204 / 128,000 (24%)
|
|
135
|
+
Workspace files estimate: ~7,100 tok (23%)
|
|
136
|
+
|
|
137
|
+
⚠ TOOLS.md: 34,210 chars (63%) are never seen by the model
|
|
138
|
+
→ Consider splitting into per-task files or using Skills
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 💡 Optimization Suggestions
|
|
142
|
+
|
|
143
|
+
clawprobe automatically detects common cost and reliability issues.
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
$ clawprobe suggest
|
|
147
|
+
|
|
148
|
+
💡 Suggestions
|
|
149
|
+
|
|
150
|
+
[CRITICAL] TOOLS.md truncated for 7 consecutive days
|
|
151
|
+
34K chars of tool descriptions never reach the model.
|
|
152
|
+
Estimated waste: ~$2.10/week
|
|
153
|
+
→ Split TOOLS.md into smaller Skill-specific files
|
|
154
|
+
|
|
155
|
+
[WARNING] Compaction frequency is high (avg 32 min interval)
|
|
156
|
+
reserveTokens=16384 may be too low for your workflow.
|
|
157
|
+
→ Try: increase to 24000 in openclaw.json
|
|
158
|
+
|
|
159
|
+
[INFO] 3 workspace files haven't changed in 30+ days
|
|
160
|
+
IDENTITY.md, HEARTBEAT.md may be safe to trim
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 📊 Web Dashboard
|
|
164
|
+
|
|
165
|
+
A local web UI for deeper visual analysis.
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
$ clawprobe start
|
|
169
|
+
Dashboard: http://localhost:4747
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Pages: Overview · Cost Trends · Compact Timeline · Context · Memory · Sessions
|
|
173
|
+
|
|
174
|
+
Access remotely via SSH tunnel:
|
|
175
|
+
```bash
|
|
176
|
+
ssh -L 4747:localhost:4747 user@your-server
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 💬 IM Integration (OpenClaw Skill)
|
|
180
|
+
|
|
181
|
+
Install the clawprobe Skill to interact via Telegram, WhatsApp, or any chat app connected to OpenClaw.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
openclaw plugins install @clawprobe/skill
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Then in chat:
|
|
188
|
+
```
|
|
189
|
+
You: probe cost
|
|
190
|
+
Agent: 💰 This week: $18.42 (avg $2.63/day, est $78.90/month)
|
|
191
|
+
|
|
192
|
+
You: probe compacts
|
|
193
|
+
Agent: 📦 Last compact: 14:22 today. 14 messages compacted.
|
|
194
|
+
⚠ Lost: PostgreSQL preference, snake_case API format
|
|
195
|
+
→ Reply "probe save 3" to save to long-term memory
|
|
196
|
+
|
|
197
|
+
You: probe suggest
|
|
198
|
+
Agent: 💡 TOOLS.md truncated (CRITICAL) — wasting ~$2.10/week
|
|
199
|
+
reserveTokens may be too low (WARNING)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Installation
|
|
205
|
+
|
|
206
|
+
### Requirements
|
|
207
|
+
|
|
208
|
+
- Node.js ≥ 22
|
|
209
|
+
- OpenClaw installed and configured
|
|
210
|
+
- macOS or Linux (Windows via WSL2)
|
|
211
|
+
|
|
212
|
+
### Install
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm install -g clawprobe
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### First run
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
clawprobe start
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
clawprobe auto-detects your OpenClaw installation at `~/.openclaw`. No configuration needed.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Quick Reference
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Status
|
|
232
|
+
clawprobe status # Current session info
|
|
233
|
+
clawprobe context # Context window breakdown
|
|
234
|
+
|
|
235
|
+
# Cost
|
|
236
|
+
clawprobe cost # This week
|
|
237
|
+
clawprobe cost --day # Today
|
|
238
|
+
clawprobe cost --month # This month
|
|
239
|
+
|
|
240
|
+
# Compact events
|
|
241
|
+
clawprobe compacts # Last 5 events
|
|
242
|
+
clawprobe compacts --last 10 # Last 10 events
|
|
243
|
+
|
|
244
|
+
# Memory
|
|
245
|
+
clawprobe memory list # List all long-term memory
|
|
246
|
+
clawprobe memory search "postgres" # Search memory
|
|
247
|
+
clawprobe memory add "prefer snake_case" # Add to memory
|
|
248
|
+
clawprobe memory save-compact 3 # Save from compact event #3
|
|
249
|
+
|
|
250
|
+
# Suggestions
|
|
251
|
+
clawprobe suggest # Show all suggestions
|
|
252
|
+
|
|
253
|
+
# Dashboard
|
|
254
|
+
clawprobe start # Start daemon + web UI at :4747
|
|
255
|
+
clawprobe stop # Stop daemon
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Compatibility
|
|
261
|
+
|
|
262
|
+
| ContextEngine Plugin | Compatible |
|
|
263
|
+
|----------------------|-----------|
|
|
264
|
+
| LegacyContextEngine (default) | ✅ |
|
|
265
|
+
| lossless-claw | ✅ |
|
|
266
|
+
| OpenViking Plugin | ✅ |
|
|
267
|
+
| MemOS Cloud Plugin | ✅ |
|
|
268
|
+
| ClawVault | ✅ |
|
|
269
|
+
| Any other plugin | ✅ |
|
|
270
|
+
|
|
271
|
+
clawprobe works by reading OpenClaw's file system, not by hooking into the ContextEngine. It is compatible with any plugin configuration.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Privacy
|
|
276
|
+
|
|
277
|
+
- **100% local** — no data ever leaves your machine
|
|
278
|
+
- **Read-only by default** — only writes when you explicitly use `memory add`, `memory edit`, `memory delete`, or `memory save-compact`
|
|
279
|
+
- **No telemetry** — clawprobe collects nothing
|
|
280
|
+
- **No accounts** — no sign-up, no API keys required
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Contributing
|
|
285
|
+
|
|
286
|
+
clawprobe is open source (MIT). Contributions welcome.
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
git clone https://github.com/your-username/clawprobe
|
|
290
|
+
cd clawprobe
|
|
291
|
+
npm install
|
|
292
|
+
npm run dev
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
See [DESIGN.md](./DESIGN.md) for architecture details.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
MIT © 2026 clawprobe contributors
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResolvedConfig } from "../../core/config.js";
|
|
2
|
+
interface CompactsOptions {
|
|
3
|
+
agent?: string;
|
|
4
|
+
session?: string;
|
|
5
|
+
last?: number;
|
|
6
|
+
showMessages?: boolean;
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function runCompacts(cfg: ResolvedConfig, opts: CompactsOptions): Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=compacts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compacts.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/compacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA+E3F"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { openDb, getCompactEvents } from "../../core/db.js";
|
|
2
|
+
import { header, fmtDate, fmtTokens, roleIcon, outputJson, severity, divider } from "../format.js";
|
|
3
|
+
export async function runCompacts(cfg, opts) {
|
|
4
|
+
const agent = opts.agent ?? cfg.probe.openclaw.agent;
|
|
5
|
+
const db = openDb(cfg.probeDir);
|
|
6
|
+
const limit = opts.last ?? 5;
|
|
7
|
+
const events = getCompactEvents(db, agent, limit, opts.session);
|
|
8
|
+
if (opts.json) {
|
|
9
|
+
outputJson(events.map((e) => ({
|
|
10
|
+
id: e.id,
|
|
11
|
+
sessionKey: e.session_key,
|
|
12
|
+
compactionEntryId: e.compaction_entry_id,
|
|
13
|
+
tokensBefore: e.tokens_before,
|
|
14
|
+
compactedAt: e.compacted_at,
|
|
15
|
+
compactedMessageCount: e.compacted_message_count,
|
|
16
|
+
summaryText: e.summary_text,
|
|
17
|
+
compactedMessages: e.compacted_messages
|
|
18
|
+
? JSON.parse(e.compacted_messages)
|
|
19
|
+
: [],
|
|
20
|
+
})));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
header("📦", `Compact Events`, `last ${limit}`);
|
|
24
|
+
if (events.length === 0) {
|
|
25
|
+
console.log(severity.muted(" No compact events recorded yet."));
|
|
26
|
+
console.log();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
for (const [i, event] of events.entries()) {
|
|
30
|
+
const compactedMessages = event.compacted_messages ? JSON.parse(event.compacted_messages) : [];
|
|
31
|
+
const when = event.compacted_at ? fmtDate(event.compacted_at) : "unknown time";
|
|
32
|
+
const count = event.compacted_message_count ?? compactedMessages.length;
|
|
33
|
+
console.log();
|
|
34
|
+
console.log(` ${severity.bold(`#${event.id}`)} ${when} ${severity.muted("[" + event.session_key.slice(0, 10) + "…]")}`);
|
|
35
|
+
console.log();
|
|
36
|
+
console.log(` ${count} messages compacted`);
|
|
37
|
+
if (event.tokens_before) {
|
|
38
|
+
console.log(` Tokens before: ${fmtTokens(event.tokens_before)}`);
|
|
39
|
+
}
|
|
40
|
+
if (compactedMessages.length > 0) {
|
|
41
|
+
console.log();
|
|
42
|
+
console.log(severity.muted(" Compacted messages:"));
|
|
43
|
+
const preview = opts.showMessages ? compactedMessages : compactedMessages.slice(0, 4);
|
|
44
|
+
for (const msg of preview) {
|
|
45
|
+
const icon = roleIcon(msg.role);
|
|
46
|
+
const text = msg.content.slice(0, 120).replace(/\n/g, " ");
|
|
47
|
+
console.log(` ${icon} "${text}${msg.content.length > 120 ? "…" : ""}"`);
|
|
48
|
+
}
|
|
49
|
+
if (!opts.showMessages && compactedMessages.length > 4) {
|
|
50
|
+
console.log(severity.muted(` … and ${compactedMessages.length - 4} more messages`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (event.summary_text) {
|
|
54
|
+
console.log();
|
|
55
|
+
console.log(severity.muted(" Summary generated:"));
|
|
56
|
+
const summaryPreview = event.summary_text.slice(0, 200).replace(/\n/g, " ");
|
|
57
|
+
console.log(` "${summaryPreview}${event.summary_text.length > 200 ? "…" : ""}"`);
|
|
58
|
+
}
|
|
59
|
+
console.log();
|
|
60
|
+
console.log(` ${severity.muted("→ Save to memory:")} clawprobe memory save-compact ${event.id}`);
|
|
61
|
+
if (i < events.length - 1) {
|
|
62
|
+
console.log();
|
|
63
|
+
divider();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
console.log();
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=compacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compacts.js","sourceRoot":"","sources":["../../../src/cli/commands/compacts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAuB,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAgB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAUjH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAmB,EAAE,IAAqB;IAC1E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrD,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IAE7B,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAEhE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,UAAU,CACR,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjB,EAAE,EAAE,CAAC,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iB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,iBAAiB,CAAC,MAAM,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC3F,CAAC;QACH,CAAC;QAED,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC;YACtD,MAAM,cAAc,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAC5E,OAAO,CAAC,GAAG,CAAC,UAAU,cAAc,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACxF,CAAC;QAED,OAAO,CAAC,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,OAAO,QAAQ,CAAC,KAAK,CAAC,mBAAmB,CAAC,kCAAkC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAEpG,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResolvedConfig } from "../../core/config.js";
|
|
2
|
+
interface ContextOptions {
|
|
3
|
+
agent?: string;
|
|
4
|
+
json?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function runContext(cfg: ResolvedConfig, opts: ContextOptions): Promise<void>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAQtD,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAWD,wBAAsB,UAAU,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA0FzF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { openDb } from "../../core/db.js";
|
|
2
|
+
import { getActiveSession } from "../../core/session-store.js";
|
|
3
|
+
import { getLatestWorkspaceAnalysis } from "../../engines/file-analyzer.js";
|
|
4
|
+
import { header, makeTable, fmtTokens, truncBadge, outputJson, severity, } from "../format.js";
|
|
5
|
+
const MODEL_WINDOWS = {
|
|
6
|
+
"claude-opus-4": 200000,
|
|
7
|
+
"claude-sonnet-4.5": 200000,
|
|
8
|
+
"gpt-5.4": 128000,
|
|
9
|
+
"gpt-5.4-mini": 128000,
|
|
10
|
+
"gemini-3.1-flash": 1000000,
|
|
11
|
+
"deepseek-v3": 128000,
|
|
12
|
+
};
|
|
13
|
+
export async function runContext(cfg, opts) {
|
|
14
|
+
const agent = opts.agent ?? cfg.probe.openclaw.agent;
|
|
15
|
+
const db = openDb(cfg.probeDir);
|
|
16
|
+
const analysis = getLatestWorkspaceAnalysis(db, agent, cfg.workspaceDir, cfg.bootstrapMaxChars);
|
|
17
|
+
const activeSession = getActiveSession(cfg.sessionsDir);
|
|
18
|
+
const contextTokens = activeSession?.contextTokens ?? 0;
|
|
19
|
+
const modelKey = activeSession?.modelOverride;
|
|
20
|
+
const windowSize = modelKey
|
|
21
|
+
? (Object.entries(MODEL_WINDOWS).find(([k]) => modelKey.includes(k))?.[1] ?? 128000)
|
|
22
|
+
: 128000;
|
|
23
|
+
if (opts.json) {
|
|
24
|
+
outputJson({
|
|
25
|
+
agent,
|
|
26
|
+
bootstrapMaxChars: analysis.bootstrapMaxChars,
|
|
27
|
+
contextTokens,
|
|
28
|
+
windowSize,
|
|
29
|
+
files: analysis.files.map((f) => ({
|
|
30
|
+
name: f.name,
|
|
31
|
+
rawChars: f.rawChars,
|
|
32
|
+
injectedChars: f.injectedChars,
|
|
33
|
+
wasTruncated: f.wasTruncated,
|
|
34
|
+
lostChars: f.lostChars,
|
|
35
|
+
lostPercent: Math.round(f.lostPercent),
|
|
36
|
+
estTokens: f.estTokens,
|
|
37
|
+
injectedEstTokens: f.injectedEstTokens,
|
|
38
|
+
})),
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
header("🔍", "Context Analysis", `agent: ${agent}`);
|
|
43
|
+
console.log(severity.bold(" Workspace files (injected at session start):"));
|
|
44
|
+
console.log();
|
|
45
|
+
const table = makeTable(["File", "Raw size", "Injected", "~Tokens", "Status"], [16, 14, 14, 10, 14]);
|
|
46
|
+
for (const f of analysis.files) {
|
|
47
|
+
table.push([
|
|
48
|
+
f.name,
|
|
49
|
+
`${f.rawChars.toLocaleString()} chars`,
|
|
50
|
+
f.wasTruncated
|
|
51
|
+
? `${f.injectedChars.toLocaleString()} chars`
|
|
52
|
+
: `${f.injectedChars.toLocaleString()} chars`,
|
|
53
|
+
`~${fmtTokens(f.injectedEstTokens)}`,
|
|
54
|
+
truncBadge(f.wasTruncated),
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
console.log(table.toString());
|
|
58
|
+
if (analysis.truncatedFiles.length > 0) {
|
|
59
|
+
console.log();
|
|
60
|
+
for (const f of analysis.truncatedFiles) {
|
|
61
|
+
console.log(severity.warning(` ⚠ ${f.name}: ${f.lostChars.toLocaleString()} chars (${Math.round(f.lostPercent)}%) are never seen by the model`));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(severity.bold(" Token estimates:"));
|
|
66
|
+
console.log();
|
|
67
|
+
const totalWorkspaceTokens = analysis.files.reduce((s, f) => s + f.injectedEstTokens, 0);
|
|
68
|
+
if (contextTokens > 0) {
|
|
69
|
+
console.log(` Context window (from session): ${fmtTokens(contextTokens)} / ${fmtTokens(windowSize)} tokens`);
|
|
70
|
+
}
|
|
71
|
+
console.log(` Workspace files (estimate): ~${fmtTokens(totalWorkspaceTokens)} tokens`);
|
|
72
|
+
if (contextTokens > 0) {
|
|
73
|
+
const remaining = windowSize - contextTokens;
|
|
74
|
+
console.log(` Remaining headroom: ${fmtTokens(remaining)} tokens`);
|
|
75
|
+
}
|
|
76
|
+
console.log();
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/cli/commands/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EACL,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,GAC/D,MAAM,cAAc,CAAC;AAOtB,MAAM,aAAa,GAA2B;IAC5C,eAAe,EAAE,MAAM;IACvB,mBAAmB,EAAE,MAAM;IAC3B,SAAS,EAAE,MAAM;IACjB,cAAc,EAAE,MAAM;IACtB,kBAAkB,EAAE,OAAO;IAC3B,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAmB,EAAE,IAAoB;IACxE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrD,MAAM,EAA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CAAC,CAAC,WAAW,CAAC,gCAAgC,CACnH,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,EAAE,CAAC;IAEd,MAAM,oBAAoB,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAEzF,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,oCAAoC,SAAS,CAAC,aAAa,CAAC,MAAM,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAChH,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,qCAAqC,SAAS,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC3F,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC,oCAAoC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResolvedConfig } from "../../core/config.js";
|
|
2
|
+
interface CostOptions {
|
|
3
|
+
agent?: string;
|
|
4
|
+
day?: boolean;
|
|
5
|
+
week?: boolean;
|
|
6
|
+
month?: boolean;
|
|
7
|
+
all?: boolean;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function runCost(cfg: ResolvedConfig, opts: CostOptions): Promise<void>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOtD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DnF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { openDb } from "../../core/db.js";
|
|
2
|
+
import { getPeriodCost } from "../../engines/cost.js";
|
|
3
|
+
import { header, fmtUsd, fmtTokens, costBar, outputJson, severity, } from "../format.js";
|
|
4
|
+
export async function runCost(cfg, opts) {
|
|
5
|
+
const agent = opts.agent ?? cfg.probe.openclaw.agent;
|
|
6
|
+
const db = openDb(cfg.probeDir);
|
|
7
|
+
const period = opts.day ? "day" :
|
|
8
|
+
opts.month ? "month" :
|
|
9
|
+
opts.all ? "all" :
|
|
10
|
+
"week";
|
|
11
|
+
const summary = getPeriodCost(db, agent, period, cfg.probe.cost.customPrices);
|
|
12
|
+
if (opts.json) {
|
|
13
|
+
outputJson(summary);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
header("💰", `${period === "day" ? "Today's" : period === "week" ? "Weekly" : period === "month" ? "Monthly" : "All-time"} Cost`, summary.period);
|
|
17
|
+
console.log(` Total: ${fmtUsd(summary.totalUsd)}`);
|
|
18
|
+
if (period !== "day") {
|
|
19
|
+
console.log(` Daily avg: ${fmtUsd(summary.dailyAvg)}`);
|
|
20
|
+
console.log(` Month est: ${fmtUsd(summary.monthEstimate)}`);
|
|
21
|
+
}
|
|
22
|
+
console.log();
|
|
23
|
+
if (summary.daily.length === 0) {
|
|
24
|
+
console.log(severity.muted(" No cost data yet. Run clawprobe as a daemon to collect data."));
|
|
25
|
+
console.log();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Daily chart
|
|
29
|
+
const maxUsd = Math.max(...summary.daily.map((d) => d.usd), 0.01);
|
|
30
|
+
for (const day of summary.daily) {
|
|
31
|
+
const isToday = day.date === new Date().toISOString().slice(0, 10);
|
|
32
|
+
const label = isToday ? severity.bold(day.date) : day.date;
|
|
33
|
+
const bar = costBar(day.usd, maxUsd);
|
|
34
|
+
const usdStr = fmtUsd(day.usd);
|
|
35
|
+
console.log(` ${label} ${bar} ${usdStr}`);
|
|
36
|
+
}
|
|
37
|
+
console.log();
|
|
38
|
+
console.log(` Input: ${fmtTokens(summary.inputTokens)} tokens ${fmtUsd(summary.totalUsd * (summary.inputTokens / Math.max(summary.inputTokens + summary.outputTokens, 1)))}` +
|
|
39
|
+
` (${Math.round((summary.inputTokens / Math.max(summary.inputTokens + summary.outputTokens, 1)) * 100)}%)`);
|
|
40
|
+
console.log(` Output: ${fmtTokens(summary.outputTokens)} tokens ${fmtUsd(summary.totalUsd * (summary.outputTokens / Math.max(summary.inputTokens + summary.outputTokens, 1)))}` +
|
|
41
|
+
` (${Math.round((summary.outputTokens / Math.max(summary.inputTokens + summary.outputTokens, 1)) * 100)}%)`);
|
|
42
|
+
if (cfg.probe.alerts.dailyBudgetUsd) {
|
|
43
|
+
const budget = cfg.probe.alerts.dailyBudgetUsd;
|
|
44
|
+
const today = summary.daily.find((d) => d.date === new Date().toISOString().slice(0, 10));
|
|
45
|
+
if (today && today.usd > budget * 0.8) {
|
|
46
|
+
console.log();
|
|
47
|
+
console.log(severity.warning(` ⚠ Today's spend ($${today.usd.toFixed(2)}) is near your daily budget ($${budget.toFixed(2)})`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log();
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M,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC1F,IAAI,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC;YACtC,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,uBAAuB,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,iCAAiC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAClI,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ResolvedConfig } from "../../core/config.js";
|
|
2
|
+
interface MemoryListOptions {
|
|
3
|
+
agent?: string;
|
|
4
|
+
file?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface MemorySearchOptions {
|
|
8
|
+
agent?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface MemoryAddOptions {
|
|
13
|
+
agent?: string;
|
|
14
|
+
file?: string;
|
|
15
|
+
}
|
|
16
|
+
interface MemoryEditOptions {
|
|
17
|
+
agent?: string;
|
|
18
|
+
file?: string;
|
|
19
|
+
}
|
|
20
|
+
interface MemoryDeleteOptions {
|
|
21
|
+
agent?: string;
|
|
22
|
+
file?: string;
|
|
23
|
+
yes?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface MemorySaveCompactOptions {
|
|
26
|
+
agent?: string;
|
|
27
|
+
file?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function runMemoryList(cfg: ResolvedConfig, opts: MemoryListOptions): Promise<void>;
|
|
30
|
+
export declare function runMemorySearch(cfg: ResolvedConfig, query: string, opts: MemorySearchOptions): Promise<void>;
|
|
31
|
+
export declare function runMemoryAdd(cfg: ResolvedConfig, content: string, opts: MemoryAddOptions): Promise<void>;
|
|
32
|
+
export declare function runMemoryEdit(cfg: ResolvedConfig, entryIndex: number, newContent: string | undefined, opts: MemoryEditOptions): Promise<void>;
|
|
33
|
+
export declare function runMemoryDelete(cfg: ResolvedConfig, entryIndex: number, opts: MemoryDeleteOptions): Promise<void>;
|
|
34
|
+
export declare function runMemorySaveCompact(cfg: ResolvedConfig, compactId: number, opts: MemorySaveCompactOptions): Promise<void>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAgBtD,UAAU,iBAAiB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,iBAAiB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,UAAU,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