@syncause/debug-daemon 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 +258 -0
- package/dist/index.js +28140 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Syncause Debug Daemon
|
|
2
|
+
|
|
3
|
+
The Syncause Project Debug Daemon (MCP Daemon) provides high-performance RPC services for runtime data collection, analysis, and debugging.
|
|
4
|
+
|
|
5
|
+
## 🚀 Core Features
|
|
6
|
+
|
|
7
|
+
### Multi-mode Transport Layer
|
|
8
|
+
- **Local Mode**: Supports Windows named pipes and Unix domain sockets, providing ultra-low latency local communication.
|
|
9
|
+
- **REMOTE Mode**: Supports standard HTTP protocol, facilitating cross-network or inter-container communication.
|
|
10
|
+
|
|
11
|
+
### High-Performance Architecture
|
|
12
|
+
- **Lightweight RPC Framework**: Based on JSON-RPC 2.0 protocol, supports request/response mode with built-in message framing.
|
|
13
|
+
- **Multi-user Isolation**: Achieves multi-client isolation through `apiKey`, independently maintaining collection status and data storage.
|
|
14
|
+
- **Smart Caching**: In-memory caching mechanism reduces disk I/O by 90%+, with batch writing optimization.
|
|
15
|
+
- **Concurrency Safety**: Operation lock mechanism ensures safe concurrent writing, preventing data races.
|
|
16
|
+
|
|
17
|
+
### Intelligent Data Processing
|
|
18
|
+
- **LLM Integration**: Intelligent analysis and summary generation for runtime data.
|
|
19
|
+
- **Dual-mode Search**: Supports Vector Embedding and Fuzzy Match.
|
|
20
|
+
- **Automatic Polling**: Global polling mechanism synchronizes application runtime data in real-time.
|
|
21
|
+
|
|
22
|
+
### Robustness Guarantee
|
|
23
|
+
- **Graceful Shutdown**: Comprehensive signal handling automatically cleans up resources and persists data.
|
|
24
|
+
- **Auto Shutdown**: Intelligently monitors activity status, automatically shutting down after idle time to save resources.
|
|
25
|
+
- **Structured Logging**: Tiered logging support with file rotation.
|
|
26
|
+
- **Configuration Management**: Unified environment variable configuration, supporting runtime tuning.
|
|
27
|
+
|
|
28
|
+
## 📦 Quick Start
|
|
29
|
+
|
|
30
|
+
### Prerequisites
|
|
31
|
+
- Node.js 20.x or higher
|
|
32
|
+
- npm or yarn
|
|
33
|
+
|
|
34
|
+
### Install Dependencies
|
|
35
|
+
```bash
|
|
36
|
+
npm install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Build Project
|
|
40
|
+
```bash
|
|
41
|
+
# TypeScript compilation
|
|
42
|
+
npm run build
|
|
43
|
+
|
|
44
|
+
# Or use esbuild for high-speed bundling
|
|
45
|
+
npm run bundle
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Global Installation (Optional)
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Start Service
|
|
54
|
+
|
|
55
|
+
**Development Mode** (PowerShell):
|
|
56
|
+
```powershell
|
|
57
|
+
$env:MODE = "local"
|
|
58
|
+
$env:LOG_TO_CONSOLE = "true"
|
|
59
|
+
$env:LOG_LEVEL = "debug"
|
|
60
|
+
npx tsx src/index.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Development Mode** (Bash):
|
|
64
|
+
```bash
|
|
65
|
+
MODE=local LOG_TO_CONSOLE=true LOG_LEVEL=debug npx tsx src/index.ts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Production Mode**:
|
|
69
|
+
```bash
|
|
70
|
+
node dist/index.js
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Run after Global Installation**:
|
|
74
|
+
```bash
|
|
75
|
+
syncause-debug-daemon
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## ⚙️ Configuration Guide
|
|
79
|
+
|
|
80
|
+
All configuration items can be customized via environment variables or command-line arguments.
|
|
81
|
+
**Priority**: Command Line Arguments > Environment Variables > Defaults.
|
|
82
|
+
|
|
83
|
+
Command-line arguments support `--KEY=VALUE` or `--key value` formats (case-insensitive).
|
|
84
|
+
For example, `HTTP_PORT` can be specified via `--HTTP_PORT=9090` or `--http_port 9090`.
|
|
85
|
+
|
|
86
|
+
### Server Configuration
|
|
87
|
+
|
|
88
|
+
| Variable Name | Description | Default | Note |
|
|
89
|
+
| :--- | :--- | :--- | :--- |
|
|
90
|
+
| `MODE` | Server running mode | `local` | `local` or `remote` |
|
|
91
|
+
| `AUTO_SHUTDOWN_MINUTES` | Idle auto-shutdown time | `5` | Unit: minutes. Automatically shuts down if no request (including ping) is received within this time. Set to `0` to disable. |
|
|
92
|
+
| `HTTP_PORT` | HTTP mode listening port | `8080` | Valid only in HTTP mode |
|
|
93
|
+
|
|
94
|
+
### Log Configuration
|
|
95
|
+
|
|
96
|
+
| Variable Name | Description | Default | Options |
|
|
97
|
+
| :--- | :--- | :--- | :--- |
|
|
98
|
+
| `LOG_LEVEL` | Log level | `info` | `debug`, `info`, `warn`, `error` |
|
|
99
|
+
| `LOG_TO_CONSOLE` | Console output | `false` | `true`, `false` |
|
|
100
|
+
|
|
101
|
+
### Storage Configuration
|
|
102
|
+
|
|
103
|
+
| Variable Name | Description | Default | Note |
|
|
104
|
+
| :--- | :--- | :--- | :--- |
|
|
105
|
+
| `STORAGE_PERSIST_INTERVAL` | Persistence check interval | `5000` | Unit: milliseconds |
|
|
106
|
+
| `STORAGE_MAX_TRACES_PER_APP` | Max traces per app | `250` | Retains latest records if exceeded |
|
|
107
|
+
|
|
108
|
+
### Service Configuration
|
|
109
|
+
|
|
110
|
+
| Variable Name | Description | Default | Note |
|
|
111
|
+
| :--- | :--- | :--- | :--- |
|
|
112
|
+
| `SERVICE_PROXY_URL` | API proxy URL | `https://api.syn-cause.com/codeproxy` | Used to retrieve app and trace data |
|
|
113
|
+
| `SERVICE_POLLING_INTERVAL` | Polling interval | `10000` | Unit: milliseconds |
|
|
114
|
+
|
|
115
|
+
### Configuration Examples
|
|
116
|
+
|
|
117
|
+
#### Via Environment Variables
|
|
118
|
+
|
|
119
|
+
```powershell
|
|
120
|
+
# Windows PowerShell
|
|
121
|
+
$env:MODE = "local"
|
|
122
|
+
$env:LOG_TO_CONSOLE = "true"
|
|
123
|
+
$env:LOG_LEVEL = "debug"
|
|
124
|
+
$env:SERVICE_PROXY_URL = "http://192.168.1.6:32220"
|
|
125
|
+
npx tsx src/index.ts
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Linux/macOS Bash
|
|
130
|
+
MODE=local LOG_TO_CONSOLE=true LOG_LEVEL=debug \
|
|
131
|
+
SERVICE_PROXY_URL=http://192.168.1.6:32220 \
|
|
132
|
+
npx tsx src/index.ts
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Via Command Line Arguments
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Cross-platform
|
|
139
|
+
npx tsx src/index.ts \
|
|
140
|
+
--mode local \
|
|
141
|
+
--log_to_console true \
|
|
142
|
+
--log_level debug \
|
|
143
|
+
--service_proxy_url http://192.168.1.6:32220
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 📂 Project Structure
|
|
147
|
+
|
|
148
|
+
```text
|
|
149
|
+
src/
|
|
150
|
+
├── common/ # Common protocols and utilities
|
|
151
|
+
│ ├── common.ts # Common constants and utility functions
|
|
152
|
+
│ ├── framing.ts # Message framing processing
|
|
153
|
+
│ ├── protocol.ts # RPC protocol definitions
|
|
154
|
+
│ └── version.ts # Version information
|
|
155
|
+
├── config/ # Unified configuration management
|
|
156
|
+
│ └── index.ts # Configuration loading and management
|
|
157
|
+
├── core/ # Core business logic layer
|
|
158
|
+
│ ├── api/ # External service integration (LLM, Embedding)
|
|
159
|
+
│ ├── logger/ # Structured logging system
|
|
160
|
+
│ ├── services/ # Business services (Multi-user management, data collection)
|
|
161
|
+
│ ├── storage/ # Storage persistence (Disk I/O, cache management)
|
|
162
|
+
│ └── utils/ # Utility classes (Tree building, similarity calculation, search strategies)
|
|
163
|
+
├── rpc/ # RPC protocol implementation
|
|
164
|
+
│ ├── handler/ # RPC method handlers
|
|
165
|
+
│ ├── server.ts # RPC core server
|
|
166
|
+
│ └── utils/ # RPC utility functions
|
|
167
|
+
└── transport/ # Transport layer implementation
|
|
168
|
+
└── server/ # Local and HTTP server implementations
|
|
169
|
+
├── baseServer.ts # Base server abstract class
|
|
170
|
+
├── http.ts # HTTP server implementation
|
|
171
|
+
└── local.ts # Local server implementation (Named pipes/Domain sockets)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 📡 RPC Interfaces
|
|
175
|
+
|
|
176
|
+
### Core Interfaces
|
|
177
|
+
|
|
178
|
+
#### `ping`
|
|
179
|
+
Client heartbeat detection and registration.
|
|
180
|
+
- **Parameters**:
|
|
181
|
+
- `meta.apiKey` - User identifier
|
|
182
|
+
|
|
183
|
+
#### `get_runtime_facts`
|
|
184
|
+
Query application runtime data.
|
|
185
|
+
- **Parameters**:
|
|
186
|
+
- `meta.apiKey` - User identifier
|
|
187
|
+
- `projectId` - Project ID
|
|
188
|
+
- `searchText` - Search keywords (optional)
|
|
189
|
+
- `matchMode` - Match mode: `embedding` or `fuzzy`
|
|
190
|
+
|
|
191
|
+
#### `search_debug_traces`
|
|
192
|
+
AI intelligent troubleshooting.
|
|
193
|
+
- **Parameters**:
|
|
194
|
+
- `meta.apiKey` - User identifier
|
|
195
|
+
- `projectId` - Project ID
|
|
196
|
+
- `query` - Problem description
|
|
197
|
+
- `limit` - Number of results to return
|
|
198
|
+
|
|
199
|
+
### Advanced Interfaces
|
|
200
|
+
|
|
201
|
+
#### `get_trace_insight`
|
|
202
|
+
Get complete request lifecycle report.
|
|
203
|
+
- **Parameters**:
|
|
204
|
+
- `meta.apiKey` - User identifier
|
|
205
|
+
- `projectId` - Project ID
|
|
206
|
+
- `traceId` - Trace ID
|
|
207
|
+
|
|
208
|
+
#### `inspect_method_snapshot`
|
|
209
|
+
Method-level deep analysis.
|
|
210
|
+
- **Parameters**:
|
|
211
|
+
- `meta.apiKey` - User identifier
|
|
212
|
+
- `projectId` - Project ID
|
|
213
|
+
- `traceId` - Trace ID
|
|
214
|
+
- `className` - Class name
|
|
215
|
+
- `methodName` - Method name
|
|
216
|
+
- `includeSubCalls` - Whether to include sub-calls
|
|
217
|
+
|
|
218
|
+
#### `diff_trace_execution`
|
|
219
|
+
Comparative analysis of two request executions.
|
|
220
|
+
- **Parameters**:
|
|
221
|
+
- `meta.apiKey` - User identifier
|
|
222
|
+
- `projectId` - Project ID
|
|
223
|
+
- `baseTraceId` - Trace ID for the failure case
|
|
224
|
+
- `compareTraceId` - Trace ID for the reference case (optional)
|
|
225
|
+
|
|
226
|
+
## 🛡️ Operations Guide
|
|
227
|
+
|
|
228
|
+
### Graceful Shutdown
|
|
229
|
+
|
|
230
|
+
When receiving `Ctrl+C` (SIGINT) or `SIGTERM` signals, the daemon will:
|
|
231
|
+
|
|
232
|
+
1. Stop global polling timers.
|
|
233
|
+
2. Persist all cached data to disk.
|
|
234
|
+
3. Close all active connections.
|
|
235
|
+
4. Flush log buffers.
|
|
236
|
+
5. Initiate a 10-second timeout protection to ensure process termination.
|
|
237
|
+
|
|
238
|
+
### Log Locations
|
|
239
|
+
|
|
240
|
+
Log files are named by PID and stored in:
|
|
241
|
+
|
|
242
|
+
- **Windows**: `%APPDATA%\syncause-debug\logs\`
|
|
243
|
+
- **Linux**: `~/.local/share/syncause-debug/logs/`
|
|
244
|
+
- **macOS**: `~/Library/Application Support/syncause-debug/logs/`
|
|
245
|
+
|
|
246
|
+
### Dependencies
|
|
247
|
+
|
|
248
|
+
Main dependencies:
|
|
249
|
+
- `openai`: OpenAI API client for LLM integration.
|
|
250
|
+
- `winston`: Structured logging system.
|
|
251
|
+
- `uuid`: Unique identifier generation.
|
|
252
|
+
- `p-limit`: Concurrency control.
|
|
253
|
+
|
|
254
|
+
Development dependencies:
|
|
255
|
+
- `typescript`: TypeScript compiler.
|
|
256
|
+
- `esbuild`: High-speed bundling tool.
|
|
257
|
+
- `tsx`: TypeScript execution tool.
|
|
258
|
+
- `@types/*`: TypeScript type definitions.
|