openclaw-trace 1.0.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/LICENSE +21 -0
- package/README.md +246 -0
- package/budget.json +4 -0
- package/dashboard-helper.sh +169 -0
- package/openclaw-trace.js +2773 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenClaw Trace Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# OpenClaw Trace
|
|
2
|
+
|
|
3
|
+
**End-to-end tracing and observability for OpenClaw multi-agent systems**
|
|
4
|
+
|
|
5
|
+
An extension for OpenClaw that provides comprehensive visibility into agent execution traces, token consumption, costs, and performance across all your agents.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
### Main Dashboard View
|
|
10
|
+
<img width="1911" height="524" alt="image" src="https://github.com/user-attachments/assets/48b6a3ce-ddf9-493c-ae3b-c0778629f225" />
|
|
11
|
+
|
|
12
|
+
*Overview of agent performance with cost and context growth charts. Shows sidebar with all agents, stats cards, and expandable heartbeat rows.*
|
|
13
|
+
|
|
14
|
+
### Detailed Heartbeat Analysis
|
|
15
|
+
<img width="1884" height="716" alt="image" src="https://github.com/user-attachments/assets/d1e6ec2c-8956-4f49-86da-711fce27075f" />
|
|
16
|
+
|
|
17
|
+
*Expanded heartbeat view showing cost per step, tool usage breakdown, cost breakdown, and detailed step-by-step execution with full tool call/result inspection.*
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- 📊 **Real-time monitoring** - Live agent status, auto-refresh, cross-agent overview
|
|
22
|
+
- 💰 **Budget tracking** - Daily/monthly limits with projected costs and alerts
|
|
23
|
+
- 📈 **Historical analysis** - 7-day trends, per-heartbeat drill-down, context growth
|
|
24
|
+
- ⚡ **Optimization tools** - Cache hit rates, waste detection, actionable hints
|
|
25
|
+
- 🔍 **A/B comparison** - Side-by-side heartbeat comparison with delta calculations
|
|
26
|
+
- 🎛️ **Collapsible sidebar** - Toggle agent list for more screen space
|
|
27
|
+
- 📊 **Rich charts** - Cost, context, and tool usage visualizations
|
|
28
|
+
- 🔍 **Step inspection** - Full tool call/result details with expandable views
|
|
29
|
+
- 📤 **API access** - Programmatic access to all metrics via REST API
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### Prerequisites
|
|
34
|
+
- **OpenClaw** installed and configured at `~/.openclaw`
|
|
35
|
+
- **Node.js** v14+ (already required by OpenClaw)
|
|
36
|
+
|
|
37
|
+
### Quick Start (recommended)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx openclaw-trace
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
No installation needed — runs directly from npm.
|
|
44
|
+
|
|
45
|
+
### Global Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install -g openclaw-trace
|
|
49
|
+
openclaw-trace
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Output:
|
|
53
|
+
```
|
|
54
|
+
🦞 OpenClaw Trace → http://localhost:3141
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Access the Dashboard
|
|
58
|
+
|
|
59
|
+
Open your browser to **http://localhost:3141**
|
|
60
|
+
|
|
61
|
+
### Navigation
|
|
62
|
+
|
|
63
|
+
- **Sidebar Toggle** - Click ☰ button to hide/show the agent sidebar for more screen space
|
|
64
|
+
- **Sidebar** - Click any agent to view its details
|
|
65
|
+
- **Overview** - Default view showing all agents and 7-day trend
|
|
66
|
+
- **Agent View** - Session cost, heartbeats, cache stats, and full drill-down
|
|
67
|
+
- **Compare Mode** - Click "Compare" button in header → select 2 heartbeats → view delta
|
|
68
|
+
- **API Buttons** - Each heartbeat has 📋 API and ⚠ API buttons to copy URLs for programmatic access
|
|
69
|
+
|
|
70
|
+
### API Access for Agents
|
|
71
|
+
|
|
72
|
+
The dashboard provides REST API endpoints that agents can use for self-improvement and optimization:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Source helper functions
|
|
76
|
+
source ~/.openclaw/canvas/dashboard-helper.sh
|
|
77
|
+
|
|
78
|
+
# Check if budget allows running
|
|
79
|
+
if dashboard_check_budget; then
|
|
80
|
+
echo "Budget OK, running agent..."
|
|
81
|
+
else
|
|
82
|
+
echo "Budget exceeded, skipping"
|
|
83
|
+
exit 1
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# Get latest heartbeat data
|
|
87
|
+
latest=$(dashboard_latest_hb "promo-assistant-reddit")
|
|
88
|
+
cost=$(echo $latest | jq -r '.totalCost')
|
|
89
|
+
errors=$(echo $latest | jq -r '.errorCount')
|
|
90
|
+
|
|
91
|
+
# Get only error steps from previous run
|
|
92
|
+
errors_only=$(dashboard_latest_errors_only "promo-assistant-reddit")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Available API endpoints:**
|
|
96
|
+
- `/api/agents` - List all agents with stats
|
|
97
|
+
- `/api/agent/:id` - Get specific agent details
|
|
98
|
+
- `/api/latest?agent=X` - Get latest heartbeat
|
|
99
|
+
- `/api/heartbeat?agent=X&hb=N` - Get specific heartbeat by index
|
|
100
|
+
- `/api/heartbeats?agent=X&errors=true` - Query heartbeats with filters
|
|
101
|
+
- `/api/budget` - Get current budget status
|
|
102
|
+
- `/api/daily?days=N` - Get daily cost breakdown
|
|
103
|
+
- `/api/stats` - Overall system statistics
|
|
104
|
+
|
|
105
|
+
**Error filtering:**
|
|
106
|
+
Add `&errors_only=true` to any heartbeat endpoint to get only steps with errors. Perfect for debugging and self-correction loops.
|
|
107
|
+
|
|
108
|
+
See [API.md](API.md) and [ERRORS_ONLY_FEATURE.md](ERRORS_ONLY_FEATURE.md) for complete documentation.
|
|
109
|
+
|
|
110
|
+
## Configuration
|
|
111
|
+
|
|
112
|
+
### Budget Settings
|
|
113
|
+
|
|
114
|
+
Edit `~/.openclaw/canvas/budget.json`:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"daily": 10.00, // Daily spending limit in USD
|
|
119
|
+
"monthly": 200.00 // Monthly spending limit in USD
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The dashboard calculates:
|
|
124
|
+
- **Daily progress**: Today's spend vs daily limit
|
|
125
|
+
- **Projected monthly**: (7-day average × 30) vs monthly limit
|
|
126
|
+
|
|
127
|
+
### Port Configuration
|
|
128
|
+
|
|
129
|
+
To change the default port (3141), edit `openclaw-trace.js`:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
const PORT = 3141; // Change to your preferred port
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Understanding the Metrics
|
|
136
|
+
|
|
137
|
+
### Live Status Dots
|
|
138
|
+
- 🟢 **Green**: Active (heartbeat < 15min ago)
|
|
139
|
+
- 🟡 **Yellow**: Idle (heartbeat < 1hr ago)
|
|
140
|
+
- ⚫ **Grey**: Inactive (heartbeat > 1hr ago)
|
|
141
|
+
|
|
142
|
+
### Cache Hit Rate
|
|
143
|
+
- **>70%**: Excellent (green) - prompt caching is working well
|
|
144
|
+
- **50-70%**: Good (blue) - normal for varied workloads
|
|
145
|
+
- **<50%**: Low (orange) - possible prompt drift or cold starts
|
|
146
|
+
|
|
147
|
+
### Waste Flags
|
|
148
|
+
- **Runaway loop**: >30 steps in one heartbeat
|
|
149
|
+
- **Low cache hit**: <50% cache efficiency (>5 steps)
|
|
150
|
+
- **Large result**: >10k char tool result (likely unscoped snapshot)
|
|
151
|
+
- **Bloated context**: >50k tokens in one step
|
|
152
|
+
|
|
153
|
+
## How It Works
|
|
154
|
+
|
|
155
|
+
The dashboard reads OpenClaw's session JSONL files from:
|
|
156
|
+
```
|
|
157
|
+
~/.openclaw/agents/*/sessions/sessions.json
|
|
158
|
+
~/.openclaw/agents/*/sessions/*.jsonl
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
It parses:
|
|
162
|
+
- Token usage (`input`, `output`, `cacheRead`, `cacheWrite`)
|
|
163
|
+
- Costs per step (from Claude API usage metadata)
|
|
164
|
+
- Tool calls (browser, read, write, bash, etc.)
|
|
165
|
+
- Errors and timing data
|
|
166
|
+
|
|
167
|
+
**No external dependencies** - pure Node.js stdlib + embedded HTML/CSS/JS.
|
|
168
|
+
|
|
169
|
+
## Troubleshooting
|
|
170
|
+
|
|
171
|
+
### Dashboard won't start
|
|
172
|
+
```bash
|
|
173
|
+
# Check if port 3141 is already in use
|
|
174
|
+
lsof -ti:3141
|
|
175
|
+
|
|
176
|
+
# Kill existing process
|
|
177
|
+
lsof -ti:3141 | xargs kill -9
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### No data showing
|
|
181
|
+
- Ensure OpenClaw agents have run at least once
|
|
182
|
+
- Check `~/.openclaw/agents/*/sessions/` contains `.jsonl` files
|
|
183
|
+
- Verify `~/.openclaw/openclaw.json` exists with agent definitions
|
|
184
|
+
|
|
185
|
+
### Budget bar not showing
|
|
186
|
+
- Create `~/.openclaw/canvas/budget.json` with valid JSON
|
|
187
|
+
- Ensure at least one heartbeat exists for today
|
|
188
|
+
|
|
189
|
+
## Integration with OpenClaw
|
|
190
|
+
|
|
191
|
+
This dashboard is designed as a **drop-in extension** for OpenClaw. It:
|
|
192
|
+
- ✅ Reads existing OpenClaw session files (no schema changes)
|
|
193
|
+
- ✅ Works with all 10 platform agents (Threads, Twitter, Reddit, HN, PH, IH, Dev.to, LinkedIn, Medium, TikTok)
|
|
194
|
+
- ✅ Runs independently on a separate port (doesn't interfere with gateway)
|
|
195
|
+
- ✅ Auto-discovers agents from `openclaw.json`
|
|
196
|
+
|
|
197
|
+
### Using with OpenClaw Gateway
|
|
198
|
+
|
|
199
|
+
If you're running the OpenClaw gateway (`openclaw serve`), the dashboard runs alongside it:
|
|
200
|
+
- **Gateway**: `http://localhost:18789`
|
|
201
|
+
- **Dashboard**: `http://localhost:3141`
|
|
202
|
+
|
|
203
|
+
Both can run simultaneously with no conflicts.
|
|
204
|
+
|
|
205
|
+
## Development
|
|
206
|
+
|
|
207
|
+
The entire application is a single `openclaw-trace.js` file (~1350 lines):
|
|
208
|
+
- **Backend**: Node.js HTTP server + JSONL parser
|
|
209
|
+
- **Frontend**: Embedded HTML/CSS/JS (no build step)
|
|
210
|
+
- **Rendering**: Vanilla JS with SVG charts
|
|
211
|
+
|
|
212
|
+
To modify:
|
|
213
|
+
1. Edit `openclaw-trace.js`
|
|
214
|
+
2. Restart the server
|
|
215
|
+
3. Refresh browser (auto-refresh will pick up data changes)
|
|
216
|
+
|
|
217
|
+
## Performance
|
|
218
|
+
|
|
219
|
+
- **Session file reads**: ~50ms for 10 agents with 100+ heartbeats each
|
|
220
|
+
- **Memory usage**: ~30MB RSS
|
|
221
|
+
- **Browser performance**: Handles 1000+ heartbeats smoothly
|
|
222
|
+
|
|
223
|
+
## Roadmap
|
|
224
|
+
|
|
225
|
+
Potential future enhancements:
|
|
226
|
+
- [ ] Webhook alerts when budget exceeds threshold
|
|
227
|
+
- [ ] Per-agent budget allocation
|
|
228
|
+
- [ ] Model comparison (Opus vs Sonnet vs Haiku costs)
|
|
229
|
+
- [ ] Browser extension for inline metrics
|
|
230
|
+
- [ ] Prometheus/Grafana exporter
|
|
231
|
+
|
|
232
|
+
## Contributing
|
|
233
|
+
|
|
234
|
+
Contributions welcome! Please open an issue or PR at https://github.com/Tell-Me-Mo/openclaw-trace
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT License - see LICENSE file for details
|
|
239
|
+
|
|
240
|
+
## Acknowledgments
|
|
241
|
+
|
|
242
|
+
Built for the OpenClaw multi-agent framework.
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
**Need help?** Open an issue or reach out in the OpenClaw community.
|
package/budget.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# OpenClaw Trace Helper Functions
|
|
3
|
+
# Source this file in your agent scripts: source ~/.openclaw/canvas/dashboard-helper.sh
|
|
4
|
+
|
|
5
|
+
DASHBOARD_API="http://127.0.0.1:3141/api"
|
|
6
|
+
|
|
7
|
+
# Check if budget is OK to run
|
|
8
|
+
# Returns 0 if OK, 1 if over budget
|
|
9
|
+
dashboard_check_budget() {
|
|
10
|
+
local status=$(curl -s "$DASHBOARD_API/budget" | jq -r '.status // "error"')
|
|
11
|
+
case "$status" in
|
|
12
|
+
ok|warning) return 0 ;;
|
|
13
|
+
over|error) return 1 ;;
|
|
14
|
+
esac
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Get budget percentage used today
|
|
18
|
+
dashboard_budget_pct() {
|
|
19
|
+
curl -s "$DASHBOARD_API/budget" | jq -r '.dailyPct // 0'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# Get latest heartbeat for agent
|
|
23
|
+
# Usage: dashboard_latest_hb "promo-assistant-reddit"
|
|
24
|
+
dashboard_latest_hb() {
|
|
25
|
+
local agent_id="$1"
|
|
26
|
+
curl -s "$DASHBOARD_API/latest?agent=$agent_id"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# Get specific heartbeat by index (0 = latest, 1 = second-to-latest, etc.)
|
|
30
|
+
# Usage: dashboard_get_hb "promo-assistant-reddit" 2
|
|
31
|
+
dashboard_get_hb() {
|
|
32
|
+
local agent_id="$1"
|
|
33
|
+
local index="${2:-0}"
|
|
34
|
+
curl -s "$DASHBOARD_API/heartbeat?agent=$agent_id&index=$index"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Get only error steps from latest heartbeat
|
|
38
|
+
# Usage: dashboard_latest_errors_only "promo-assistant-reddit"
|
|
39
|
+
dashboard_latest_errors_only() {
|
|
40
|
+
local agent_id="$1"
|
|
41
|
+
curl -s "$DASHBOARD_API/latest?agent=$agent_id&errors_only=true"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Get only error steps from specific heartbeat
|
|
45
|
+
# Usage: dashboard_get_hb_errors "promo-assistant-reddit" 1
|
|
46
|
+
dashboard_get_hb_errors() {
|
|
47
|
+
local agent_id="$1"
|
|
48
|
+
local index="${2:-0}"
|
|
49
|
+
curl -s "$DASHBOARD_API/heartbeat?agent=$agent_id&index=$index&errors_only=true"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Get latest heartbeat cost
|
|
53
|
+
# Usage: dashboard_latest_cost "promo-assistant-reddit"
|
|
54
|
+
dashboard_latest_cost() {
|
|
55
|
+
local agent_id="$1"
|
|
56
|
+
curl -s "$DASHBOARD_API/latest?agent=$agent_id" | jq -r '.totalCost // 0'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Get latest heartbeat error count
|
|
60
|
+
# Usage: dashboard_latest_errors "promo-assistant-reddit"
|
|
61
|
+
dashboard_latest_errors() {
|
|
62
|
+
local agent_id="$1"
|
|
63
|
+
curl -s "$DASHBOARD_API/latest?agent=$agent_id" | jq -r '.errorCount // 0'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Get agent summary
|
|
67
|
+
# Usage: dashboard_agent_info "promo-assistant-reddit"
|
|
68
|
+
dashboard_agent_info() {
|
|
69
|
+
local agent_id="$1"
|
|
70
|
+
curl -s "$DASHBOARD_API/agent/$agent_id"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Get recent heartbeats with errors
|
|
74
|
+
# Usage: dashboard_recent_errors "promo-assistant-reddit" 10
|
|
75
|
+
dashboard_recent_errors() {
|
|
76
|
+
local agent_id="$1"
|
|
77
|
+
local limit="${2:-10}"
|
|
78
|
+
curl -s "$DASHBOARD_API/heartbeats?agent=$agent_id&errors=true&limit=$limit"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Get expensive heartbeats (above threshold)
|
|
82
|
+
# Usage: dashboard_expensive_hbs 0.01 20
|
|
83
|
+
dashboard_expensive_hbs() {
|
|
84
|
+
local min_cost="${1:-0.01}"
|
|
85
|
+
local limit="${2:-10}"
|
|
86
|
+
curl -s "$DASHBOARD_API/heartbeats?minCost=$min_cost&limit=$limit"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# Get today's cost
|
|
90
|
+
dashboard_today_cost() {
|
|
91
|
+
curl -s "$DASHBOARD_API/daily?days=1" | jq -r '.[0].cost // 0'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Get today's heartbeat count
|
|
95
|
+
dashboard_today_count() {
|
|
96
|
+
curl -s "$DASHBOARD_API/daily?days=1" | jq -r '.[0].heartbeats // 0'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Get all agents list
|
|
100
|
+
dashboard_list_agents() {
|
|
101
|
+
curl -s "$DASHBOARD_API/agents"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
# Get overall stats
|
|
105
|
+
dashboard_stats() {
|
|
106
|
+
curl -s "$DASHBOARD_API/stats"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Check if agent has recent errors (last 5 heartbeats)
|
|
110
|
+
# Returns 0 if no errors, 1 if errors found
|
|
111
|
+
dashboard_has_errors() {
|
|
112
|
+
local agent_id="$1"
|
|
113
|
+
local error_count=$(curl -s "$DASHBOARD_API/heartbeats?agent=$agent_id&errors=true&limit=5" | jq 'length')
|
|
114
|
+
[ "$error_count" -gt 0 ] && return 1 || return 0
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
# Pretty print budget status
|
|
118
|
+
dashboard_budget_status() {
|
|
119
|
+
local budget=$(curl -s "$DASHBOARD_API/budget")
|
|
120
|
+
echo "Budget Status:"
|
|
121
|
+
echo " Today: \$$(echo $budget | jq -r '.todayCost') / \$$(echo $budget | jq -r '.daily') ($(echo $budget | jq -r '.dailyPct')%)"
|
|
122
|
+
echo " Projected Monthly: \$$(echo $budget | jq -r '.projectedMonthly') / \$$(echo $budget | jq -r '.monthly')"
|
|
123
|
+
echo " Status: $(echo $budget | jq -r '.status')"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
# Pretty print agent stats
|
|
127
|
+
dashboard_agent_stats() {
|
|
128
|
+
local agent_id="$1"
|
|
129
|
+
local info=$(curl -s "$DASHBOARD_API/agent/$agent_id")
|
|
130
|
+
echo "Agent: $(echo $info | jq -r '.name')"
|
|
131
|
+
echo " Total Cost: \$$(echo $info | jq -r '.totalCost')"
|
|
132
|
+
echo " Heartbeats: $(echo $info | jq -r '.heartbeats | length')"
|
|
133
|
+
echo " Errors: $(echo $info | jq -r '.totalErrors')"
|
|
134
|
+
echo " Cache Hit: $(echo $info | jq -r '.avgCacheHit')%"
|
|
135
|
+
echo " Context: $(echo $info | jq -r '.totalTokens') / $(echo $info | jq -r '.contextTokens')"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Example usage guard
|
|
139
|
+
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
|
140
|
+
echo "OpenClaw Trace Helper Functions"
|
|
141
|
+
echo "Usage: source $0"
|
|
142
|
+
echo ""
|
|
143
|
+
echo "Available functions:"
|
|
144
|
+
echo " dashboard_check_budget - Check if budget allows running (exit 0 = OK)"
|
|
145
|
+
echo " dashboard_budget_pct - Get budget % used today"
|
|
146
|
+
echo " dashboard_latest_hb AGENT - Get latest heartbeat JSON"
|
|
147
|
+
echo " dashboard_get_hb AGENT INDEX - Get specific heartbeat by index (0=latest)"
|
|
148
|
+
echo " dashboard_latest_errors_only AGENT - Get only error steps from latest heartbeat"
|
|
149
|
+
echo " dashboard_get_hb_errors AGENT INDEX - Get only error steps from specific heartbeat"
|
|
150
|
+
echo " dashboard_latest_cost AGENT - Get latest heartbeat cost"
|
|
151
|
+
echo " dashboard_latest_errors AGENT - Get latest heartbeat error count"
|
|
152
|
+
echo " dashboard_agent_info AGENT - Get agent summary"
|
|
153
|
+
echo " dashboard_recent_errors AGENT [LIMIT] - Get recent error heartbeats"
|
|
154
|
+
echo " dashboard_expensive_hbs [MIN_COST] [LIMIT] - Get expensive heartbeats"
|
|
155
|
+
echo " dashboard_today_cost - Get today's total cost"
|
|
156
|
+
echo " dashboard_today_count - Get today's heartbeat count"
|
|
157
|
+
echo " dashboard_list_agents - List all agents"
|
|
158
|
+
echo " dashboard_stats - Get overall statistics"
|
|
159
|
+
echo " dashboard_has_errors AGENT - Check if agent has recent errors (exit 1 = yes)"
|
|
160
|
+
echo " dashboard_budget_status - Pretty print budget status"
|
|
161
|
+
echo " dashboard_agent_stats AGENT - Pretty print agent stats"
|
|
162
|
+
echo ""
|
|
163
|
+
echo "Example:"
|
|
164
|
+
echo " if dashboard_check_budget; then"
|
|
165
|
+
echo " echo 'Budget OK, running agent...'"
|
|
166
|
+
echo " else"
|
|
167
|
+
echo " echo 'Budget exceeded, skipping'"
|
|
168
|
+
echo " fi"
|
|
169
|
+
fi
|