drtrace 0.4.0 → 0.5.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 +0 -0
- package/agents/CONTRIBUTING.md +0 -0
- package/agents/README.md +0 -0
- package/agents/daemon-method-selection.md +89 -262
- package/agents/integration-guides/cpp-best-practices.md +0 -0
- package/agents/integration-guides/cpp-ros-integration.md +0 -0
- package/agents/log-analysis.md +3 -90
- package/agents/log-help.md +5 -78
- package/agents/log-init.md +4 -0
- package/agents/log-it.md +4 -0
- package/bin/cli.js +98 -0
- package/bin/init.js +0 -0
- package/dist/bin/cli.js +98 -0
- package/dist/browser.d.ts +0 -0
- package/dist/browser.js +0 -0
- package/dist/cli/grep.d.ts +27 -0
- package/dist/cli/grep.js +251 -0
- package/dist/cli/status.d.ts +11 -0
- package/dist/cli/status.js +78 -0
- package/dist/client.d.ts +0 -0
- package/dist/client.js +0 -0
- package/dist/config-schema.d.ts +0 -0
- package/dist/config-schema.js +0 -0
- package/dist/config.d.ts +0 -0
- package/dist/config.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/init.d.ts +0 -0
- package/dist/init.js +0 -0
- package/dist/logger.d.ts +0 -0
- package/dist/logger.js +0 -0
- package/dist/node.d.ts +0 -0
- package/dist/node.js +0 -0
- package/dist/queue.d.ts +0 -0
- package/dist/queue.js +0 -0
- package/dist/resources/agents/CONTRIBUTING.md +0 -0
- package/dist/resources/agents/README.md +0 -0
- package/dist/resources/agents/daemon-method-selection.md +89 -262
- package/dist/resources/agents/integration-guides/cpp-best-practices.md +0 -0
- package/dist/resources/agents/integration-guides/cpp-ros-integration.md +0 -0
- package/dist/resources/agents/log-analysis.md +3 -90
- package/dist/resources/agents/log-help.md +5 -78
- package/dist/resources/agents/log-init.md +4 -0
- package/dist/resources/agents/log-it.md +4 -0
- package/dist/resources/cpp/drtrace_sink.hpp +1 -1
- package/dist/transport.d.ts +0 -0
- package/dist/transport.js +0 -0
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -0
- package/package.json +3 -3
- package/dist/bin/init.js +0 -31
package/README.md
CHANGED
|
File without changes
|
package/agents/CONTRIBUTING.md
CHANGED
|
File without changes
|
package/agents/README.md
CHANGED
|
File without changes
|
|
@@ -1,83 +1,97 @@
|
|
|
1
1
|
# Daemon Method Selection Guide
|
|
2
|
-
|
|
3
2
|
**Purpose**: Guide for AI agents to choose the right method for daemon interaction.
|
|
3
|
+
**Key Principle**: For AI agents, prefer interaction with daemon in this order (most preferred to least, if a method is unavailable, fall back to the next):
|
|
4
|
+
- **CLI**: if available on client machine (check `## CLI Approach` below).
|
|
5
|
+
- **HTTP/curl**: for complex interactions without dependencies (check `## HTTP/curl Approach` below).
|
|
6
|
+
- **Python code**: when rich queries are needed (check `## Python code Approach` below).
|
|
7
|
+
## CLI Approach
|
|
8
|
+
If `drtrace` CLI is installed on the client machine:
|
|
9
|
+
- Check with: `drtrace --version`
|
|
10
|
+
- Prefer CLI commands: `drtrace grep`, `drtrace tail`, `drtrace status`
|
|
11
|
+
- Benefit: no HTTP overhead and faster queries
|
|
12
|
+
### Query Filter Rule: Mutually Exclusive
|
|
13
|
+
When querying logs, use **either** `message_contains` **or** `message_regex`, **NOT both**.
|
|
14
|
+
|
|
15
|
+
| Filter | Use Case | Example |
|
|
16
|
+
| ------------------ | ---------------- | --------------------------------------------- |
|
|
17
|
+
| `message_contains` | Substring search | "timeout" matches "Connection timeout error" |
|
|
18
|
+
| `message_regex` | Regex patterns | "(db\|cache).*timeout" matches service errors |
|
|
19
|
+
**Error if both used**: API returns 400 "Cannot use both filters".
|
|
20
|
+
### Examples
|
|
21
|
+
**CLI - Substring Search**:
|
|
22
|
+
```bash
|
|
23
|
+
drtrace grep "timeout" --since 1h
|
|
24
|
+
```
|
|
25
|
+
**CLI - Regex Search** (with `-E`):
|
|
26
|
+
```bash
|
|
27
|
+
drtrace grep -E "(db|cache).*timeout" --since 1h
|
|
28
|
+
```
|
|
29
|
+
## HTTP/curl Approach
|
|
30
|
+
### Check Daemon Status
|
|
4
31
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Priority Order for AI Agents
|
|
10
|
-
|
|
11
|
-
| Priority | Method | When to Use |
|
|
12
|
-
|----------|--------|-------------|
|
|
13
|
-
| **1st** | HTTP/curl | Default - works without dependencies |
|
|
14
|
-
| **2nd** | Python code | When rich SDK features needed |
|
|
15
|
-
| **3rd** | CLI commands | Last resort - requires subprocess |
|
|
16
|
-
|
|
17
|
-
### Why HTTP-First for AI Agents?
|
|
18
|
-
|
|
19
|
-
- **No dependencies**: Just HTTP requests - works in any environment
|
|
20
|
-
- **Simpler**: curl commands are self-contained and portable
|
|
21
|
-
- **Faster**: No import overhead or Python interpreter startup
|
|
22
|
-
- **Universal**: Works from any language or tool
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Discovery First: OpenAPI Schema
|
|
27
|
-
|
|
32
|
+
```bash
|
|
33
|
+
curl http://localhost:8001/status
|
|
34
|
+
```
|
|
35
|
+
### Discovery API via OpenAPI Schema
|
|
28
36
|
**CRITICAL**: Before making any API call, fetch `/openapi.json` to discover:
|
|
29
37
|
- Available endpoints
|
|
30
38
|
- Correct field names (e.g., `ts` not `timestamp`)
|
|
31
39
|
- Request/response schemas
|
|
32
|
-
|
|
33
40
|
```bash
|
|
34
41
|
# Always fetch schema first
|
|
35
42
|
curl http://localhost:8001/openapi.json
|
|
36
43
|
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
### Common Endpoints (for Quick Reference)
|
|
45
|
+
**Note**: Always verify via `/openapi.json` - this list is for reference only (*API field names can change between versions. Using OpenAPI ensures compatibility*).
|
|
46
|
+
|
|
47
|
+
| Endpoint | Method | Purpose |
|
|
48
|
+
| ---------------------- | ------ | -------------------- |
|
|
49
|
+
| `/status` | GET | Health check |
|
|
50
|
+
| `/openapi.json` | GET | API schema |
|
|
51
|
+
| `/logs/query` | GET | Query logs |
|
|
52
|
+
| `/logs/ingest` | POST | Ingest logs |
|
|
53
|
+
| `/analysis/why` | GET | Root cause analysis |
|
|
54
|
+
| `/analysis/time-range` | GET | Time range analysis |
|
|
55
|
+
| `/help/guide/start` | POST | Start setup guide |
|
|
56
|
+
| `/help/guide/current` | GET | Current setup step |
|
|
57
|
+
| `/help/troubleshoot` | POST | Troubleshooting help |
|
|
58
|
+
### Examples
|
|
59
|
+
**HTTP - Substring Search**:
|
|
60
|
+
```bash
|
|
61
|
+
curl "http://localhost:8001/logs/query?message_contains=timeout&since=1h"
|
|
49
62
|
```
|
|
50
|
-
|
|
51
|
-
**Why this matters**: API field names can change between versions. Using OpenAPI ensures compatibility.
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Method 1: HTTP/curl (Preferred)
|
|
56
|
-
|
|
57
|
-
### Check Daemon Status
|
|
58
|
-
|
|
63
|
+
**HTTP - Regex Search**:
|
|
59
64
|
```bash
|
|
60
|
-
curl http://localhost:8001/
|
|
65
|
+
curl "http://localhost:8001/logs/query?message_regex=(db|cache).*timeout&since=1h"
|
|
61
66
|
```
|
|
62
|
-
|
|
63
|
-
### Query Logs
|
|
64
|
-
|
|
67
|
+
**HTTP - Query Logs**:
|
|
65
68
|
```bash
|
|
66
69
|
# Get logs from last 5 minutes
|
|
67
70
|
START_TS=$(python3 -c "import time; print(time.time() - 300)")
|
|
68
71
|
END_TS=$(python3 -c "import time; print(time.time())")
|
|
69
|
-
|
|
70
72
|
curl "http://localhost:8001/logs/query?start_ts=${START_TS}&end_ts=${END_TS}&application_id=myapp&limit=100"
|
|
71
73
|
```
|
|
72
|
-
|
|
73
|
-
### Root Cause Analysis
|
|
74
|
-
|
|
74
|
+
**HTTP - Query with filter**:
|
|
75
75
|
```bash
|
|
76
76
|
curl "http://localhost:8001/analysis/why?application_id=myapp&start_ts=${START_TS}&end_ts=${END_TS}&min_level=ERROR"
|
|
77
77
|
```
|
|
78
|
+
## Python code Approach
|
|
79
|
+
Use when you need rich SDK features or the HTTP method fails.
|
|
80
|
+
### Examples
|
|
81
|
+
**Get OpenAPI json for API information**
|
|
82
|
+
```python
|
|
83
|
+
import requests
|
|
78
84
|
|
|
79
|
-
|
|
85
|
+
base_url = "http://localhost:8001"
|
|
80
86
|
|
|
87
|
+
# Fetch schema to discover endpoints and field names
|
|
88
|
+
schema = requests.get(f"{base_url}/openapi.json", timeout=5).json()
|
|
89
|
+
paths = schema.get("paths", {})
|
|
90
|
+
components = schema.get("components", {}).get("schemas", {})
|
|
91
|
+
|
|
92
|
+
# Use discovered field names, not hardcoded ones
|
|
93
|
+
```
|
|
94
|
+
**Python requests (HTTP method)**
|
|
81
95
|
```python
|
|
82
96
|
import requests
|
|
83
97
|
import time
|
|
@@ -109,202 +123,31 @@ for log in logs:
|
|
|
109
123
|
level = log.get("level")
|
|
110
124
|
message = log.get("message")
|
|
111
125
|
```
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## Method 2: Python Code (Fallback)
|
|
116
|
-
|
|
117
|
-
Use when you need rich SDK features or the HTTP method fails.
|
|
118
|
-
|
|
119
|
-
### Log Analysis
|
|
120
|
-
|
|
121
|
-
```python
|
|
122
|
-
from drtrace_service.agent_interface import process_agent_query, check_daemon_status
|
|
123
|
-
import asyncio
|
|
124
|
-
|
|
125
|
-
# Check daemon first
|
|
126
|
-
status = await check_daemon_status()
|
|
127
|
-
if not status.get("available"):
|
|
128
|
-
print("Daemon not available")
|
|
129
|
-
|
|
130
|
-
# Process query - returns formatted markdown
|
|
131
|
-
response = await process_agent_query("explain error from 9:00 to 10:00 for app myapp")
|
|
132
|
-
print(response)
|
|
133
|
-
|
|
134
|
-
# Non-async context
|
|
135
|
-
response = asyncio.run(process_agent_query("show logs from last 5 minutes"))
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Setup Help
|
|
139
|
-
|
|
140
|
-
```python
|
|
141
|
-
from drtrace_service.help_agent_interface import (
|
|
142
|
-
start_setup_guide,
|
|
143
|
-
get_current_step,
|
|
144
|
-
complete_step,
|
|
145
|
-
troubleshoot,
|
|
146
|
-
)
|
|
147
|
-
from pathlib import Path
|
|
148
|
-
import asyncio
|
|
149
|
-
|
|
150
|
-
project_root = Path(".")
|
|
151
|
-
|
|
152
|
-
# Start setup guide
|
|
153
|
-
guide = await start_setup_guide(language="python", project_root=project_root)
|
|
154
|
-
|
|
155
|
-
# Get current step
|
|
156
|
-
current = await get_current_step(project_root=project_root)
|
|
157
|
-
|
|
158
|
-
# Mark step complete
|
|
159
|
-
next_step = await complete_step(step_number=1, project_root=project_root)
|
|
160
|
-
|
|
161
|
-
# Troubleshoot
|
|
162
|
-
help_text = await troubleshoot("daemon not connecting", project_root=project_root)
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Setup Suggestions
|
|
166
|
-
|
|
167
|
-
```python
|
|
168
|
-
from drtrace_service.setup_agent_interface import analyze_and_suggest, suggest_for_language
|
|
169
|
-
from pathlib import Path
|
|
170
|
-
import asyncio
|
|
171
|
-
|
|
172
|
-
project_root = Path(".")
|
|
173
|
-
|
|
174
|
-
# Get setup suggestions
|
|
175
|
-
suggestions = await analyze_and_suggest(project_root)
|
|
176
|
-
|
|
177
|
-
# Language-specific suggestions
|
|
178
|
-
python_suggestions = await suggest_for_language("python", project_root)
|
|
179
|
-
cpp_suggestions = await suggest_for_language("cpp", project_root)
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## Method 3: CLI Commands (Last Resort)
|
|
185
|
-
|
|
186
|
-
Use only when HTTP and Python methods are unavailable.
|
|
187
|
-
|
|
188
|
-
### Check Status
|
|
189
|
-
|
|
190
|
-
```bash
|
|
191
|
-
python -m drtrace_service status
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Analyze Errors
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
python -m drtrace_service why --application-id myapp --since 5m --min-level ERROR
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Setup Help
|
|
201
|
-
|
|
202
|
-
```bash
|
|
203
|
-
python -m drtrace_service help guide start --language python --project-root /path/to/project
|
|
204
|
-
python -m drtrace_service help guide current --project-root /path/to/project
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## Error Handling and Fallback Chain
|
|
210
|
-
|
|
211
|
-
```python
|
|
212
|
-
import requests
|
|
213
|
-
|
|
214
|
-
def interact_with_daemon(query: str) -> str:
|
|
215
|
-
"""Try methods in order: HTTP -> Python -> CLI"""
|
|
216
|
-
base_url = "http://localhost:8001"
|
|
217
|
-
|
|
218
|
-
# Method 1: HTTP (Preferred)
|
|
219
|
-
try:
|
|
220
|
-
# Check status first
|
|
221
|
-
status = requests.get(f"{base_url}/status", timeout=2)
|
|
222
|
-
if status.status_code == 200:
|
|
223
|
-
# Make actual request...
|
|
224
|
-
return "Success via HTTP"
|
|
225
|
-
except requests.exceptions.RequestException:
|
|
226
|
-
pass # Fall through to Python
|
|
227
|
-
|
|
228
|
-
# Method 2: Python (Fallback)
|
|
229
|
-
try:
|
|
230
|
-
from drtrace_service.agent_interface import process_agent_query
|
|
231
|
-
import asyncio
|
|
232
|
-
response = asyncio.run(process_agent_query(query))
|
|
233
|
-
return response
|
|
234
|
-
except ImportError:
|
|
235
|
-
pass # Fall through to CLI
|
|
236
|
-
|
|
237
|
-
# Method 3: CLI (Last Resort)
|
|
238
|
-
import subprocess
|
|
239
|
-
result = subprocess.run(
|
|
240
|
-
["python", "-m", "drtrace_service", "status"],
|
|
241
|
-
capture_output=True,
|
|
242
|
-
text=True
|
|
243
|
-
)
|
|
244
|
-
if result.returncode == 0:
|
|
245
|
-
return result.stdout
|
|
246
|
-
|
|
247
|
-
# All methods failed
|
|
248
|
-
return """
|
|
249
|
-
Daemon is not available.
|
|
250
|
-
|
|
251
|
-
Next Steps:
|
|
252
|
-
1. Start daemon: python -m drtrace_service
|
|
253
|
-
2. Verify: curl http://localhost:8001/status
|
|
254
|
-
"""
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
126
|
## When to Use Each Method
|
|
260
127
|
|
|
261
|
-
| Scenario
|
|
262
|
-
|
|
263
|
-
| Simple queries (status, logs) | HTTP/curl
|
|
264
|
-
| Complex analysis
|
|
265
|
-
| Rich markdown output needed
|
|
266
|
-
| Running outside Python
|
|
267
|
-
| Setup guide interaction
|
|
268
|
-
| Debugging integration
|
|
269
|
-
| Script automation
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
## Quick Reference: Common Endpoints
|
|
274
|
-
|
|
275
|
-
**Note**: Always verify via `/openapi.json` - this list is for reference only.
|
|
276
|
-
|
|
277
|
-
| Endpoint | Method | Purpose |
|
|
278
|
-
|----------|--------|---------|
|
|
279
|
-
| `/status` | GET | Health check |
|
|
280
|
-
| `/openapi.json` | GET | API schema |
|
|
281
|
-
| `/logs/query` | GET | Query logs |
|
|
282
|
-
| `/logs/ingest` | POST | Ingest logs |
|
|
283
|
-
| `/analysis/why` | GET | Root cause analysis |
|
|
284
|
-
| `/analysis/time-range` | GET | Time range analysis |
|
|
285
|
-
| `/help/guide/start` | POST | Start setup guide |
|
|
286
|
-
| `/help/guide/current` | GET | Current setup step |
|
|
287
|
-
| `/help/troubleshoot` | POST | Troubleshooting help |
|
|
288
|
-
|
|
289
|
-
---
|
|
290
|
-
|
|
291
|
-
## Important: Timestamps Are UTC
|
|
292
|
-
|
|
128
|
+
| Scenario | Recommended Method |
|
|
129
|
+
| ----------------------------- | ------------------ |
|
|
130
|
+
| Simple queries (status, logs) | CLI, HTTP/curl |
|
|
131
|
+
| Complex analysis | HTTP or Python |
|
|
132
|
+
| Rich markdown output needed | Python SDK |
|
|
133
|
+
| Running outside Python | CLI, HTTP/curl |
|
|
134
|
+
| Setup guide interaction | Python SDK |
|
|
135
|
+
| Debugging integration | CLI commands |
|
|
136
|
+
| Script automation | CLI, HTTP/curl |
|
|
137
|
+
## Important Notes
|
|
138
|
+
### Timestamps Are UTC
|
|
293
139
|
All timestamps in DrTrace API are **UTC Unix timestamps**:
|
|
294
140
|
|
|
295
|
-
| Field/Param
|
|
296
|
-
|
|
297
|
-
| `ts` (in logs)
|
|
298
|
-
| `start_ts`, `end_ts` | Unix float
|
|
299
|
-
| `since`, `until`
|
|
300
|
-
|
|
141
|
+
| Field/Param | Format | Timezone |
|
|
142
|
+
| -------------------- | -------------------- | -------- |
|
|
143
|
+
| `ts` (in logs) | Unix float | UTC |
|
|
144
|
+
| `start_ts`, `end_ts` | Unix float | UTC |
|
|
145
|
+
| `since`, `until` | Relative or ISO 8601 | UTC |
|
|
301
146
|
**Key Rules**:
|
|
302
147
|
- ISO 8601 without timezone (e.g., `2025-12-31T02:44:03`) is interpreted as **UTC**, not local time
|
|
303
148
|
- Relative times (`5m`, `1h`) are relative to server's current UTC time
|
|
304
149
|
- To query with local time, include timezone offset: `2025-12-31T09:44:03+07:00`
|
|
305
|
-
|
|
306
|
-
### Converting Local Time to UTC
|
|
307
|
-
|
|
150
|
+
#### Converting Local Time to UTC
|
|
308
151
|
**Python:**
|
|
309
152
|
```python
|
|
310
153
|
from datetime import datetime, timezone, timedelta
|
|
@@ -323,7 +166,6 @@ print(f"UTC Unix timestamp: {unix_ts}")
|
|
|
323
166
|
import time
|
|
324
167
|
unix_ts = time.mktime(local_time.timetuple())
|
|
325
168
|
```
|
|
326
|
-
|
|
327
169
|
**Bash:**
|
|
328
170
|
```bash
|
|
329
171
|
# Convert local time to Unix timestamp
|
|
@@ -332,9 +174,7 @@ date -d "2025-12-31 09:44:03" +%s
|
|
|
332
174
|
# Convert with explicit timezone
|
|
333
175
|
TZ=UTC date -d "2025-12-31T02:44:03" +%s
|
|
334
176
|
```
|
|
335
|
-
|
|
336
|
-
### API Query Examples with Timezone
|
|
337
|
-
|
|
177
|
+
#### API Query Examples with Timezone
|
|
338
178
|
```bash
|
|
339
179
|
# Option 1: Include timezone in ISO 8601 (recommended for local time)
|
|
340
180
|
curl "http://localhost:8001/logs/query?since=2025-12-31T09:44:03%2B07:00"
|
|
@@ -349,22 +189,9 @@ curl "http://localhost:8001/logs/query?start_ts=$UTC_TS"
|
|
|
349
189
|
# Option 4: Use ISO 8601 in UTC (note: no timezone = UTC)
|
|
350
190
|
curl "http://localhost:8001/logs/query?since=2025-12-31T02:44:03"
|
|
351
191
|
```
|
|
352
|
-
|
|
353
|
-
### Common Timezone Pitfalls
|
|
354
|
-
|
|
192
|
+
#### Common Timezone Pitfalls
|
|
355
193
|
1. **ISO 8601 Without Timezone**: Interpreted as UTC, not local time. If you pass `2025-12-31T09:44:03` thinking it's local 9:44 AM, it will be treated as 9:44 AM UTC.
|
|
356
|
-
|
|
357
194
|
2. **Server vs Client Timezone**: If your server is in a different timezone than your client, always use explicit UTC timestamps or include timezone offsets.
|
|
358
|
-
|
|
359
195
|
3. **Relative Times**: `since=5m` means 5 minutes before server's current UTC time, regardless of your local timezone.
|
|
360
|
-
|
|
361
|
-
---
|
|
362
|
-
|
|
363
|
-
## Related Documentation
|
|
364
|
-
|
|
365
|
-
- `docs/daemon-interaction-guide.md` - OpenAPI discovery details
|
|
366
|
-
- `docs/api-reference.md` - Complete API reference
|
|
367
|
-
|
|
368
196
|
---
|
|
369
|
-
|
|
370
|
-
**Last Updated**: 2025-12-31
|
|
197
|
+
**Last Updated**: 2026-01-06
|
|
File without changes
|
|
File without changes
|
package/agents/log-analysis.md
CHANGED
|
@@ -11,27 +11,7 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
11
11
|
<step n="1">Load persona from this current agent file (already in context)</step>
|
|
12
12
|
<step n="2">Remember: You are a Log Analysis Specialist</step>
|
|
13
13
|
<step n="3">READ the entire story file BEFORE any analysis - understand the query parsing rules</step>
|
|
14
|
-
<step n="4">When processing a user query,
|
|
15
|
-
|
|
16
|
-
**Method 1 (Preferred)**: HTTP/curl
|
|
17
|
-
- Simple, no Python dependencies, works in any environment
|
|
18
|
-
- Check status: `GET http://localhost:8001/status`
|
|
19
|
-
- Query logs: `GET http://localhost:8001/logs/query?since=5m&application_id=X`
|
|
20
|
-
- Analysis: `GET http://localhost:8001/analysis/why?application_id=X&since=5m`
|
|
21
|
-
- **CRITICAL**: First fetch `/openapi.json` to discover field names (e.g., timestamp is `ts`, NOT `timestamp`)
|
|
22
|
-
|
|
23
|
-
**Method 2 (Fallback)**: Python SDK
|
|
24
|
-
- Use when HTTP is blocked or you need async features
|
|
25
|
-
- Try: `from drtrace_service.agent_interface import process_agent_query, check_daemon_status`
|
|
26
|
-
- Use `response = await process_agent_query(user_query)` or `asyncio.run(process_agent_query(user_query))`
|
|
27
|
-
- Return the response string directly (it's already formatted markdown)
|
|
28
|
-
|
|
29
|
-
**Method 3 (Last resort)**: CLI commands
|
|
30
|
-
- If both HTTP and Python fail: Execute `python -m drtrace_service why --application-id X --since 5m`
|
|
31
|
-
- Parse the CLI output and format for the user
|
|
32
|
-
|
|
33
|
-
**Important**: Always check daemon status first. If daemon is unavailable, return clear error message with next steps.
|
|
34
|
-
</step>
|
|
14
|
+
<step n="4">When processing a user query, check `agents/daemon-method-selection.md` for details.</step>
|
|
35
15
|
<step n="5">If information is missing, ask the user for clarification with helpful suggestions</step>
|
|
36
16
|
<step n="6">If daemon is unavailable, provide clear error message and next steps</step>
|
|
37
17
|
<step n="7">Show greeting, then display numbered list of ALL menu items from menu section</step>
|
|
@@ -66,77 +46,12 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
66
46
|
|
|
67
47
|
**Priority Order**: HTTP/curl (preferred) → Python SDK → CLI (last resort)
|
|
68
48
|
|
|
69
|
-
### Quick Reference: Analysis API Operations
|
|
70
|
-
|
|
71
|
-
| Operation | HTTP (Preferred) | Python SDK |
|
|
72
|
-
|-----------|------------------|------------|
|
|
73
|
-
| Query logs | `GET /logs/query` | `process_agent_query("show logs...")` |
|
|
74
|
-
| Root cause | `GET /analysis/why` | `process_agent_query("explain error...")` |
|
|
75
|
-
| Check status | `GET /status` | `check_daemon_status()` |
|
|
76
|
-
|
|
77
|
-
### HTTP/curl Examples (Preferred)
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
# Check daemon status
|
|
81
|
-
curl http://localhost:8001/status
|
|
82
|
-
|
|
83
|
-
# Query logs from last 5 minutes
|
|
84
|
-
START_TS=$(python3 -c "import time; print(time.time() - 300)")
|
|
85
|
-
END_TS=$(python3 -c "import time; print(time.time())")
|
|
86
|
-
|
|
87
|
-
curl "http://localhost:8001/logs/query?start_ts=${START_TS}&end_ts=${END_TS}&application_id=myapp&limit=100"
|
|
88
|
-
|
|
89
|
-
# Root cause analysis
|
|
90
|
-
curl "http://localhost:8001/analysis/why?application_id=myapp&start_ts=${START_TS}&end_ts=${END_TS}&min_level=ERROR"
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Python SDK Examples (Fallback)
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
from drtrace_service.agent_interface import process_agent_query, check_daemon_status
|
|
97
|
-
import asyncio
|
|
98
|
-
|
|
99
|
-
# Check daemon first
|
|
100
|
-
status = await check_daemon_status()
|
|
101
|
-
if not status.get("available"):
|
|
102
|
-
print("Daemon not available")
|
|
103
|
-
|
|
104
|
-
# Process query - returns formatted markdown
|
|
105
|
-
response = await process_agent_query("explain error from 9:00 to 10:00 for app myapp")
|
|
106
|
-
|
|
107
|
-
# Non-async context
|
|
108
|
-
response = asyncio.run(process_agent_query("show logs from last 5 minutes"))
|
|
109
|
-
```
|
|
110
|
-
|
|
111
49
|
**Key Points:**
|
|
112
50
|
- **Package**: `drtrace_service` (NOT `drtrace_client`)
|
|
113
51
|
- **Returns**: Formatted markdown string ready to display
|
|
114
52
|
- **Async**: Functions are async, use `await` or `asyncio.run()`
|
|
115
53
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
1. **HTTP/curl (Preferred)**: Simple, no dependencies
|
|
119
|
-
2. **Python SDK (Fallback)**: Rich async features when HTTP unavailable
|
|
120
|
-
3. **CLI (Last Resort)**: `python -m drtrace_service why ...`
|
|
121
|
-
|
|
122
|
-
**Important**: Always fetch `/openapi.json` first when using HTTP to discover correct field names (e.g., `ts` not `timestamp`).
|
|
123
|
-
|
|
124
|
-
See `agents/daemon-method-selection.md` for complete fallback implementation.
|
|
125
|
-
|
|
126
|
-
### Quick Reference: Endpoints
|
|
127
|
-
|
|
128
|
-
| Endpoint | Purpose |
|
|
129
|
-
|----------|---------|
|
|
130
|
-
| `GET /status` | Health check |
|
|
131
|
-
| `GET /logs/query` | Query logs |
|
|
132
|
-
| `GET /analysis/why` | Root cause analysis |
|
|
133
|
-
| `GET /analysis/time-range` | Time range analysis |
|
|
134
|
-
| `GET /analysis/cross-module` | Cross-module analysis |
|
|
135
|
-
|
|
136
|
-
**Parameters** (verify via `/openapi.json`):
|
|
137
|
-
- `start_ts`, `end_ts`: Unix timestamps (floats)
|
|
138
|
-
- `min_level`: DEBUG, INFO, WARN, ERROR, CRITICAL
|
|
139
|
-
- `limit`: defaults to 100, max 1000
|
|
54
|
+
**Best Practice**: See `docs/agent-design-best-practices.md` → "DrTrace Query Constraints" for detailed guidance.
|
|
140
55
|
|
|
141
56
|
<menu>
|
|
142
57
|
<item cmd="*analyze">[A] Analyze logs for a time range</item>
|
|
@@ -213,6 +128,4 @@ See `agents/daemon-method-selection.md` for complete fallback implementation.
|
|
|
213
128
|
|
|
214
129
|
</capabilities>
|
|
215
130
|
</agent>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
|
|
131
|
+
```
|
package/agents/log-help.md
CHANGED
|
@@ -11,7 +11,7 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
11
11
|
<step n="1">Load persona from this current agent file (already in context)</step>
|
|
12
12
|
<step n="2">Remember: You are a Setup Guide Assistant for DrTrace</step>
|
|
13
13
|
<step n="3">Your primary mission is to walk users through DrTrace setup step-by-step using the help APIs and setup guide, not to guess or skip steps</step>
|
|
14
|
-
<step n="4">
|
|
14
|
+
<step n="4">When processing a user query, check `agents/daemon-method-selection.md` for details.</step>
|
|
15
15
|
<step n="5">For each user interaction, clearly state the current step, what to do next, and how to verify it worked</step>
|
|
16
16
|
<step n="6">When calling help APIs, use:
|
|
17
17
|
- `start_setup_guide(language, project_root)` to begin or restart a guide
|
|
@@ -50,6 +50,10 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
50
50
|
</principles>
|
|
51
51
|
</persona>
|
|
52
52
|
|
|
53
|
+
## CLI Availability & Filters
|
|
54
|
+
|
|
55
|
+
See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
|
|
56
|
+
|
|
53
57
|
<menu title="How can I guide your DrTrace setup?">
|
|
54
58
|
<item cmd="S" hotkey="S" name="Start setup guide">
|
|
55
59
|
Begin or restart the step-by-step setup guide for a specific language.
|
|
@@ -92,83 +96,6 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
92
96
|
</agent>
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
## How to Use DrTrace Help APIs
|
|
96
|
-
|
|
97
|
-
**Reference**: See `agents/daemon-method-selection.md` for complete method selection guide.
|
|
98
|
-
|
|
99
|
-
**Priority Order**: HTTP/curl (preferred) → Python SDK → CLI (last resort)
|
|
100
|
-
|
|
101
|
-
### Quick Reference: Help API Operations
|
|
102
|
-
|
|
103
|
-
| Operation | HTTP (Preferred) | Python SDK |
|
|
104
|
-
|-----------|------------------|------------|
|
|
105
|
-
| Start guide | `POST /help/guide/start` | `start_setup_guide(language, project_root)` |
|
|
106
|
-
| Current step | `GET /help/guide/current` | `get_current_step(project_root)` |
|
|
107
|
-
| Complete step | `POST /help/guide/complete` | `complete_step(step_number, project_root)` |
|
|
108
|
-
| Troubleshoot | `POST /help/troubleshoot` | `troubleshoot(issue, project_root)` |
|
|
109
|
-
|
|
110
|
-
### HTTP/curl Examples (Preferred)
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
# Start setup guide
|
|
114
|
-
curl -X POST http://localhost:8001/help/guide/start \
|
|
115
|
-
-H "Content-Type: application/json" \
|
|
116
|
-
-d '{"language": "python", "project_root": "/path/to/project"}'
|
|
117
|
-
|
|
118
|
-
# Get current step
|
|
119
|
-
curl "http://localhost:8001/help/guide/current?project_root=/path/to/project"
|
|
120
|
-
|
|
121
|
-
# Mark step complete
|
|
122
|
-
curl -X POST http://localhost:8001/help/guide/complete \
|
|
123
|
-
-H "Content-Type: application/json" \
|
|
124
|
-
-d '{"step_number": 1, "project_root": "/path/to/project"}'
|
|
125
|
-
|
|
126
|
-
# Troubleshoot
|
|
127
|
-
curl -X POST http://localhost:8001/help/troubleshoot \
|
|
128
|
-
-H "Content-Type: application/json" \
|
|
129
|
-
-d '{"issue": "daemon not connecting", "project_root": "/path/to/project"}'
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Python SDK Examples (Fallback)
|
|
133
|
-
|
|
134
|
-
```python
|
|
135
|
-
from pathlib import Path
|
|
136
|
-
from drtrace_service.help_agent_interface import (
|
|
137
|
-
start_setup_guide,
|
|
138
|
-
get_current_step,
|
|
139
|
-
complete_step,
|
|
140
|
-
troubleshoot,
|
|
141
|
-
)
|
|
142
|
-
import asyncio
|
|
143
|
-
|
|
144
|
-
project_root = Path(".")
|
|
145
|
-
|
|
146
|
-
# Start guide
|
|
147
|
-
guide = await start_setup_guide(language="python", project_root=project_root)
|
|
148
|
-
|
|
149
|
-
# Get current step
|
|
150
|
-
current = await get_current_step(project_root=project_root)
|
|
151
|
-
|
|
152
|
-
# Complete step
|
|
153
|
-
next_step = await complete_step(step_number=1, project_root=project_root)
|
|
154
|
-
|
|
155
|
-
# Troubleshoot
|
|
156
|
-
help_text = await troubleshoot("daemon not connecting", project_root=project_root)
|
|
157
|
-
|
|
158
|
-
# Non-async context
|
|
159
|
-
guide = asyncio.run(start_setup_guide(language="python", project_root=project_root))
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Fallback Strategy
|
|
163
|
-
|
|
164
|
-
1. **HTTP/curl (Preferred)**: Simple, no dependencies, works everywhere
|
|
165
|
-
2. **Python SDK (Fallback)**: Rich async features when HTTP unavailable
|
|
166
|
-
3. **CLI (Last Resort)**: `python -m drtrace_service help guide ...`
|
|
167
|
-
|
|
168
|
-
**Important**: Always fetch `/openapi.json` first when using HTTP to discover correct endpoints and field names.
|
|
169
|
-
|
|
170
|
-
See `agents/daemon-method-selection.md` for complete fallback implementation.
|
|
171
|
-
|
|
172
99
|
## Activation Instructions
|
|
173
100
|
|
|
174
101
|
To activate the `log-help` agent in a project:
|
package/agents/log-init.md
CHANGED
|
@@ -30,6 +30,10 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
30
30
|
</activation>
|
|
31
31
|
|
|
32
32
|
<persona>
|
|
33
|
+
|
|
34
|
+
## CLI Availability & Filters
|
|
35
|
+
|
|
36
|
+
See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
|
|
33
37
|
<role>Setup Specialist</role>
|
|
34
38
|
<identity>Expert at analyzing project structures and suggesting intelligent DrTrace integration. Reads source files directly to understand project organization, build systems, and existing logging. Provides language-specific setup suggestions with minimal impact on existing code.</identity>
|
|
35
39
|
<communication_style>Clear and educational. Reads and analyzes project files before suggesting setup. Explains reasoning for each suggestion. Provides structured responses with code examples. Ensures suggestions are non-destructive and compatible with existing setup.</communication_style>
|
package/agents/log-it.md
CHANGED
|
@@ -52,6 +52,10 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
52
52
|
</principles>
|
|
53
53
|
</persona>
|
|
54
54
|
|
|
55
|
+
## CLI Availability & Filters
|
|
56
|
+
|
|
57
|
+
See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
|
|
58
|
+
|
|
55
59
|
<menu title="What can I help you log?">
|
|
56
60
|
<item cmd="L" hotkey="L" name="Log this function">
|
|
57
61
|
Analyze a specific function and suggest strategic logging points.
|