@poolzin/pool-bot 2026.3.9 → 2026.3.10

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.
Files changed (125) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +147 -69
  3. package/dist/.buildstamp +1 -1
  4. package/dist/agents/error-classifier.js +26 -77
  5. package/dist/agents/skills/security.js +1 -7
  6. package/dist/build-info.json +3 -3
  7. package/dist/cli/cron-cli/register.cron-dashboard.js +339 -0
  8. package/dist/cli/cron-cli/register.js +2 -0
  9. package/dist/cli/errors.js +187 -0
  10. package/dist/cli/program/command-registry.js +13 -0
  11. package/dist/cli/program/register.maintenance.js +21 -0
  12. package/dist/cli/program/register.subclis.js +9 -0
  13. package/dist/cli/swarm-cli/register.js +8 -0
  14. package/dist/cli/swarm-cli/register.swarm-status.js +488 -0
  15. package/dist/cli/telemetry-cli/register.js +10 -0
  16. package/dist/cli/telemetry-cli/register.telemetry-alerts.js +176 -0
  17. package/dist/cli/telemetry-cli/register.telemetry-metrics.js +323 -0
  18. package/dist/cli/telemetry-cli/register.telemetry-status.js +179 -0
  19. package/dist/commands/doctor-checks.js +498 -0
  20. package/dist/context-engine/index.js +1 -1
  21. package/dist/context-engine/legacy.js +1 -3
  22. package/dist/context-engine/summarizing.js +5 -8
  23. package/dist/cron/service/timer.js +18 -0
  24. package/dist/gateway/protocol/index.js +5 -2
  25. package/dist/gateway/protocol/schema/error-codes.js +1 -0
  26. package/dist/gateway/protocol/schema/swarm.js +80 -0
  27. package/dist/gateway/protocol/schema.js +1 -0
  28. package/dist/gateway/server-close.js +4 -0
  29. package/dist/gateway/server-constants.js +1 -0
  30. package/dist/gateway/server-cron.js +29 -0
  31. package/dist/gateway/server-maintenance.js +35 -2
  32. package/dist/gateway/server-methods/swarm.js +58 -0
  33. package/dist/gateway/server-methods/telemetry.js +71 -0
  34. package/dist/gateway/server-methods-list.js +8 -0
  35. package/dist/gateway/server-methods.js +9 -2
  36. package/dist/gateway/server.impl.js +33 -16
  37. package/dist/infra/abort-pattern.js +4 -4
  38. package/dist/infra/retry.js +3 -1
  39. package/dist/skills/commands.js +7 -25
  40. package/dist/skills/index.js +14 -17
  41. package/dist/skills/parser.js +12 -27
  42. package/dist/skills/registry.js +3 -6
  43. package/dist/skills/security.js +2 -8
  44. package/dist/swarm/service.js +247 -0
  45. package/dist/telemetry/alert-engine.js +258 -0
  46. package/dist/telemetry/cron-instrumentation.js +49 -0
  47. package/dist/telemetry/gateway-instrumentation.js +80 -0
  48. package/dist/telemetry/instrumentation.js +66 -0
  49. package/dist/telemetry/service.js +345 -0
  50. package/dist/tui/components/assistant-message.js +6 -2
  51. package/dist/tui/components/hyperlink-markdown.js +32 -0
  52. package/dist/tui/components/searchable-select-list.js +12 -1
  53. package/dist/tui/components/user-message.js +6 -2
  54. package/dist/tui/index.js +22 -6
  55. package/dist/tui/theme/theme-detection.js +226 -0
  56. package/dist/tui/tui-command-handlers.js +20 -0
  57. package/dist/tui/tui-formatters.js +4 -3
  58. package/dist/tui/utils/ctrl-c-handler.js +67 -0
  59. package/dist/tui/utils/osc8-hyperlinks.js +208 -0
  60. package/dist/tui/utils/safe-stop.js +180 -0
  61. package/dist/tui/utils/session-key-utils.js +81 -0
  62. package/dist/tui/utils/text-sanitization.js +284 -0
  63. package/dist/utils/lru-cache.js +116 -0
  64. package/dist/utils/performance.js +199 -0
  65. package/dist/utils/retry.js +240 -0
  66. package/docs/MELHORIAS_IMPLEMENTADAS.md +228 -0
  67. package/docs/MELHORIAS_PROFISSIONAIS.md +282 -0
  68. package/docs/PLANO_ACAO_TUI.md +357 -0
  69. package/docs/PROGRESSO_TUI.md +66 -0
  70. package/docs/RELATORIO_FINAL.md +217 -0
  71. package/docs/diagnostico-shell-completion.md +265 -0
  72. package/docs/features/advanced-memory.md +585 -0
  73. package/docs/features/discord-components-v2.md +277 -0
  74. package/docs/features/swarm.md +100 -0
  75. package/docs/features/telemetry.md +284 -0
  76. package/docs/integrations/INTEGRATION_PLAN.md +665 -345
  77. package/docs/models/provider-infrastructure.md +400 -0
  78. package/docs/security/exec-approvals.md +294 -0
  79. package/extensions/bluebubbles/package.json +1 -1
  80. package/extensions/copilot-proxy/package.json +1 -1
  81. package/extensions/diagnostics-otel/package.json +1 -1
  82. package/extensions/discord/package.json +1 -1
  83. package/extensions/feishu/package.json +1 -1
  84. package/extensions/google-antigravity-auth/package.json +1 -1
  85. package/extensions/google-gemini-cli-auth/package.json +1 -1
  86. package/extensions/googlechat/package.json +1 -1
  87. package/extensions/hexstrike-bridge/README.md +119 -0
  88. package/extensions/hexstrike-bridge/index.test.ts +247 -0
  89. package/extensions/hexstrike-bridge/index.ts +487 -0
  90. package/extensions/hexstrike-bridge/package.json +17 -0
  91. package/extensions/imessage/package.json +1 -1
  92. package/extensions/irc/package.json +1 -1
  93. package/extensions/line/package.json +1 -1
  94. package/extensions/llm-task/package.json +1 -1
  95. package/extensions/lobster/package.json +1 -1
  96. package/extensions/matrix/CHANGELOG.md +5 -0
  97. package/extensions/matrix/package.json +1 -1
  98. package/extensions/mattermost/package.json +1 -1
  99. package/extensions/mcp-server/index.ts +14 -0
  100. package/extensions/mcp-server/package.json +11 -0
  101. package/extensions/mcp-server/src/service.ts +540 -0
  102. package/extensions/memory-core/package.json +1 -1
  103. package/extensions/memory-lancedb/package.json +1 -1
  104. package/extensions/minimax-portal-auth/package.json +1 -1
  105. package/extensions/msteams/CHANGELOG.md +5 -0
  106. package/extensions/msteams/package.json +1 -1
  107. package/extensions/nextcloud-talk/package.json +1 -1
  108. package/extensions/nostr/CHANGELOG.md +5 -0
  109. package/extensions/nostr/package.json +1 -1
  110. package/extensions/open-prose/package.json +1 -1
  111. package/extensions/openai-codex-auth/package.json +1 -1
  112. package/extensions/signal/package.json +1 -1
  113. package/extensions/slack/package.json +1 -1
  114. package/extensions/telegram/package.json +1 -1
  115. package/extensions/tlon/package.json +1 -1
  116. package/extensions/twitch/CHANGELOG.md +5 -0
  117. package/extensions/twitch/package.json +1 -1
  118. package/extensions/voice-call/CHANGELOG.md +5 -0
  119. package/extensions/voice-call/package.json +1 -1
  120. package/extensions/whatsapp/package.json +1 -1
  121. package/extensions/zalo/CHANGELOG.md +5 -0
  122. package/extensions/zalo/package.json +1 -1
  123. package/extensions/zalouser/CHANGELOG.md +5 -0
  124. package/extensions/zalouser/package.json +1 -1
  125. package/package.json +8 -1
@@ -0,0 +1,277 @@
1
+ # Discord Components V2
2
+
3
+ Pool Bot supports Discord's Components V2 system for building rich, interactive messages. This feature uses the `@buape/carbon` library to provide a declarative API for creating containers, sections, buttons, selects, media galleries, and modals.
4
+
5
+ ## Overview
6
+
7
+ Components V2 messages are structured using a `blocks`-based layout system wrapped in a container. Unlike traditional Discord embeds, Components V2 supports:
8
+
9
+ - **Containers** with accent colors and spoiler support
10
+ - **Text blocks** with markdown support
11
+ - **Sections** with thumbnails or accessory buttons
12
+ - **Separators** with configurable spacing
13
+ - **Action rows** with buttons and select menus
14
+ - **Media galleries** for image grids
15
+ - **File attachments** with spoiler support
16
+ - **Modals** for form-based interactions
17
+
18
+ ## Using Components
19
+
20
+ Components are defined in the `components` field when sending messages via the `message` tool.
21
+
22
+ ### Basic Structure
23
+
24
+ ```json
25
+ {
26
+ "text": "Optional top-level text",
27
+ "container": {
28
+ "accentColor": "#3498db",
29
+ "spoiler": false
30
+ },
31
+ "blocks": [
32
+ { "type": "text", "text": "Hello from Components V2!" },
33
+ { "type": "separator", "spacing": "large", "divider": true }
34
+ ],
35
+ "reusable": false
36
+ }
37
+ ```
38
+
39
+ ## Block Types
40
+
41
+ ### Text Block
42
+
43
+ Display simple text content with full markdown support.
44
+
45
+ ```json
46
+ { "type": "text", "text": "**Bold** and *italic* text with [links](https://example.com)" }
47
+ ```
48
+
49
+ ### Section Block
50
+
51
+ Group related content with an optional thumbnail or button accessory.
52
+
53
+ ```json
54
+ {
55
+ "type": "section",
56
+ "text": "Main content text",
57
+ "accessory": {
58
+ "type": "thumbnail",
59
+ "url": "https://example.com/image.png"
60
+ }
61
+ }
62
+ ```
63
+
64
+ With a button accessory:
65
+
66
+ ```json
67
+ {
68
+ "type": "section",
69
+ "texts": ["Line 1", "Line 2", "Line 3"],
70
+ "accessory": {
71
+ "type": "button",
72
+ "button": {
73
+ "label": "Click me",
74
+ "style": "primary"
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ **Limits:** Up to 3 text displays per section.
81
+
82
+ ### Separator Block
83
+
84
+ Add visual spacing between blocks.
85
+
86
+ ```json
87
+ { "type": "separator", "spacing": "large", "divider": true }
88
+ ```
89
+
90
+ **Spacing options:** `"small"`, `"large"`, `1`, `2`
91
+
92
+ ### Actions Block
93
+
94
+ Contains interactive elements: buttons or select menus.
95
+
96
+ #### Buttons
97
+
98
+ ```json
99
+ {
100
+ "type": "actions",
101
+ "buttons": [
102
+ { "label": "Confirm", "style": "success" },
103
+ { "label": "Cancel", "style": "danger" },
104
+ { "label": "Info", "style": "secondary" },
105
+ { "label": "Visit", "style": "link", "url": "https://example.com" }
106
+ ]
107
+ }
108
+ ```
109
+
110
+ **Button styles:** `primary`, `secondary`, `success`, `danger`, `link`
111
+
112
+ **Limits:** Up to 5 buttons per action row.
113
+
114
+ #### Select Menus
115
+
116
+ ```json
117
+ {
118
+ "type": "actions",
119
+ "select": {
120
+ "type": "string",
121
+ "placeholder": "Choose an option",
122
+ "options": [
123
+ { "label": "Option 1", "value": "opt1", "description": "First option" },
124
+ { "label": "Option 2", "value": "opt2" }
125
+ ]
126
+ }
127
+ }
128
+ ```
129
+
130
+ **Select types:** `string`, `user`, `role`, `mentionable`, `channel`
131
+
132
+ ### Media Gallery Block
133
+
134
+ Display a grid of images.
135
+
136
+ ```json
137
+ {
138
+ "type": "media-gallery",
139
+ "items": [
140
+ { "url": "https://example.com/photo1.jpg", "description": "Photo 1" },
141
+ { "url": "https://example.com/photo2.jpg", "spoiler": true }
142
+ ]
143
+ }
144
+ ```
145
+
146
+ ### File Block
147
+
148
+ Reference an uploaded file attachment.
149
+
150
+ ```json
151
+ {
152
+ "type": "file",
153
+ "file": "attachment://document.pdf",
154
+ "spoiler": false
155
+ }
156
+ ```
157
+
158
+ ## Modals
159
+
160
+ Create form-based interactions that open when users click a trigger button.
161
+
162
+ ```json
163
+ {
164
+ "text": "Click below to open the form",
165
+ "modal": {
166
+ "title": "Feedback Form",
167
+ "triggerLabel": "Open Feedback",
168
+ "triggerStyle": "primary",
169
+ "fields": [
170
+ {
171
+ "type": "text",
172
+ "name": "name",
173
+ "label": "Your Name",
174
+ "placeholder": "Enter your name",
175
+ "required": true,
176
+ "style": "short"
177
+ },
178
+ {
179
+ "type": "text",
180
+ "name": "feedback",
181
+ "label": "Feedback",
182
+ "placeholder": "Share your thoughts...",
183
+ "style": "paragraph",
184
+ "maxLength": 1000
185
+ },
186
+ {
187
+ "type": "select",
188
+ "name": "rating",
189
+ "label": "Rating",
190
+ "options": [
191
+ { "label": "Excellent", "value": "5" },
192
+ { "label": "Good", "value": "4" },
193
+ { "label": "Fair", "value": "3" }
194
+ ]
195
+ }
196
+ ]
197
+ }
198
+ }
199
+ ```
200
+
201
+ ### Modal Field Types
202
+
203
+ | Type | Description |
204
+ |------|-------------|
205
+ | `text` | Single-line or paragraph text input |
206
+ | `checkbox` | Multiple-choice checkbox group |
207
+ | `radio` | Single-choice radio group |
208
+ | `select` | Dropdown select menu |
209
+ | `role-select` | Discord role selector |
210
+ | `user-select` | Discord user selector |
211
+
212
+ **Limits:** Maximum 5 fields per modal.
213
+
214
+ ## Complete Example
215
+
216
+ ```json
217
+ {
218
+ "components": {
219
+ "container": {
220
+ "accentColor": "#5865F2"
221
+ },
222
+ "blocks": [
223
+ {
224
+ "type": "section",
225
+ "text": "## Welcome to Pool Bot!",
226
+ "accessory": {
227
+ "type": "thumbnail",
228
+ "url": "https://cdn.discordapp.com/avatars/..."
229
+ }
230
+ },
231
+ { "type": "separator", "spacing": "small" },
232
+ {
233
+ "type": "text",
234
+ "text": "Choose an action below to get started."
235
+ },
236
+ {
237
+ "type": "actions",
238
+ "buttons": [
239
+ { "label": "Get Started", "style": "success" },
240
+ { "label": "Documentation", "style": "link", "url": "https://docs.molt.bot" },
241
+ { "label": "Support", "style": "secondary" }
242
+ ]
243
+ }
244
+ ],
245
+ "modal": {
246
+ "title": "Contact Support",
247
+ "triggerLabel": "Contact Us",
248
+ "triggerStyle": "primary",
249
+ "fields": [
250
+ {
251
+ "type": "text",
252
+ "name": "issue",
253
+ "label": "Describe your issue",
254
+ "style": "paragraph",
255
+ "required": true
256
+ }
257
+ ]
258
+ }
259
+ }
260
+ }
261
+ ```
262
+
263
+ ## Component Persistence
264
+
265
+ Set `reusable: true` to allow components to be used across multiple interactions. By default, components are single-use.
266
+
267
+ ## Technical Details
268
+
269
+ - Components are built using `@buape/carbon` library
270
+ - Custom IDs use `occomp:` prefix for components and `ocmodal:` for modals
271
+ - Messages with Components V2 automatically receive the `IsComponentsV2` flag
272
+ - Component interactions are handled by the Discord gateway and routed to the appropriate agent session
273
+
274
+ ## Related
275
+
276
+ - [Discord Gateway](/gateway/overview) - How component interactions are processed
277
+ - [Message Tool](/features/message-tool) - General message sending capabilities
@@ -0,0 +1,100 @@
1
+ # Agent Swarm
2
+
3
+ Pool Bot supports **Agent Swarms** - coordinated groups of agents that work together on complex tasks through distributed task allocation and specialized capabilities.
4
+
5
+ ## Overview
6
+
7
+ An agent swarm consists of:
8
+ - **Orchestrator**: The main agent that coordinates task distribution
9
+ - **Members**: Individual agents with specific capabilities
10
+ - **Tasks**: Work items assigned to agents based on strategy
11
+ - **Strategy**: Algorithm for task distribution
12
+
13
+ ## Commands
14
+
15
+ ### List Swarms
16
+
17
+ ```bash
18
+ poolbot swarm list
19
+ ```
20
+
21
+ Shows all active swarms with member and task counts.
22
+
23
+ ### View Swarm Status
24
+
25
+ ```bash
26
+ poolbot swarm status
27
+ poolbot swarm status --id <swarm-id>
28
+ ```
29
+
30
+ Displays a detailed dashboard showing:
31
+ - Swarm statistics (members, tasks, completion rate)
32
+ - Member status table with capabilities
33
+ - Task queue with priorities and assignments
34
+ - Visual status indicators
35
+
36
+ ### Create a Swarm
37
+
38
+ ```bash
39
+ poolbot swarm create --name "My Swarm" \
40
+ --description "Team coordination swarm" \
41
+ --strategy capability_match \
42
+ --orchestrator main
43
+ ```
44
+
45
+ **Options:**
46
+ - `--name` (required): Swarm name
47
+ - `--description`: Optional description
48
+ - `--strategy`: Task distribution strategy (see below)
49
+ - `--orchestrator`: Orchestrator agent ID (default: "main")
50
+
51
+ ## Task Distribution Strategies
52
+
53
+ | Strategy | Description |
54
+ |----------|-------------|
55
+ | `round_robin` | Cycles through agents evenly |
56
+ | `least_busy` | Assigns to agent with fewest active tasks |
57
+ | `capability_match` | Matches tasks to agent capabilities (default) |
58
+ | `priority_queue` | Processes highest priority tasks first |
59
+
60
+ ## Status Indicators
61
+
62
+ ### Member Status
63
+ - `◌ idle` - Agent ready for work
64
+ - `▶ working` - Agent processing task
65
+ - `✖ error` - Agent encountered error
66
+ - `⊘ offline` - Agent unavailable
67
+
68
+ ### Task Status
69
+ - `○ pending` - Waiting for assignment
70
+ - `◎ assigned` - Assigned to agent
71
+ - `◐ in_progress` - Being processed
72
+ - `● completed` - Finished successfully
73
+ - `✖ failed` - Failed with error
74
+
75
+ ## JSON Output
76
+
77
+ All commands support `--json` for programmatic use:
78
+
79
+ ```bash
80
+ poolbot swarm status --json
81
+ poolbot swarm list --json
82
+ poolbot swarm create --name "Test" --json
83
+ ```
84
+
85
+ ## Gateway RPC Methods
86
+
87
+ Swarm functionality is exposed via gateway RPC:
88
+
89
+ - `swarm.list` - List all swarms
90
+ - `swarm.status` - Get swarm details
91
+ - `swarm.create` - Create new swarm
92
+
93
+ ## Architecture
94
+
95
+ The swarm system consists of:
96
+ - **SwarmService** (`src/swarm/service.ts`) - Core business logic
97
+ - **Gateway Handlers** (`src/gateway/server-methods/swarm.ts`) - RPC endpoints
98
+ - **CLI Commands** (`src/cli/swarm-cli/`) - User interface
99
+
100
+ Swarm state is currently stored in-memory (persistent storage planned for future releases).
@@ -0,0 +1,284 @@
1
+ # OpenTelemetry Observability
2
+
3
+ Pool Bot includes built-in OpenTelemetry (OTel) observability for monitoring gateway performance, tracing requests, and collecting metrics.
4
+
5
+ ## Overview
6
+
7
+ The telemetry system provides:
8
+
9
+ - **Distributed Tracing**: Track request flows through the gateway
10
+ - **Metrics Collection**: Counters, histograms, and gauges for performance monitoring
11
+ - **Multiple Exporters**: Console, in-memory (for CLI), or OTLP (for production)
12
+ - **Runtime Configuration**: Enable/disable via config without restarts
13
+
14
+ ## Configuration
15
+
16
+ Enable telemetry in your Pool Bot config:
17
+
18
+ ```bash
19
+ poolbot config set diagnostics.otel.enabled true
20
+ poolbot config set diagnostics.otel.endpoint http://localhost:4318/v1/traces
21
+ poolbot config set diagnostics.otel.serviceName poolbot-gateway
22
+ poolbot config set diagnostics.otel.traces true
23
+ poolbot config set diagnostics.otel.metrics true
24
+ poolbot config set diagnostics.otel.sampleRate 1.0
25
+ ```
26
+
27
+ ### Configuration Options
28
+
29
+ | Option | Type | Default | Description |
30
+ |--------|------|---------|-------------|
31
+ | `enabled` | boolean | `false` | Master switch for telemetry |
32
+ | `endpoint` | string | - | OTLP endpoint URL (e.g., `http://localhost:4318`) |
33
+ | `protocol` | string | `http/protobuf` | Protocol: `http/protobuf` or `grpc` |
34
+ | `headers` | object | - | Custom headers for OTLP requests |
35
+ | `serviceName` | string | `poolbot` | Service name in traces/metrics |
36
+ | `traces` | boolean | `true` | Enable trace collection |
37
+ | `metrics` | boolean | `true` | Enable metrics collection |
38
+ | `sampleRate` | number | `1.0` | Trace sampling rate (0.0-1.0) |
39
+ | `flushIntervalMs` | number | `60000` | Metrics export interval |
40
+
41
+ ## CLI Commands
42
+
43
+ ### Status Dashboard
44
+
45
+ View telemetry status and configuration:
46
+
47
+ ```bash
48
+ poolbot telemetry status
49
+ ```
50
+
51
+ Displays:
52
+ - Service initialization state
53
+ - Exporter type and endpoint
54
+ - Tracing/metrics configuration
55
+ - Current metrics snapshot
56
+
57
+ ### Metrics Dashboard
58
+
59
+ View collected metrics:
60
+
61
+ ```bash
62
+ poolbot telemetry metrics
63
+ ```
64
+
65
+ Shows:
66
+ - Gateway request counts and latency
67
+ - WebSocket connection metrics
68
+ - Cron job execution stats
69
+ - Custom application metrics
70
+
71
+ Use `--json` for machine-readable output:
72
+
73
+ ```bash
74
+ poolbot telemetry metrics --json
75
+ ```
76
+
77
+ ## Instrumentation
78
+
79
+ ### Gateway Instrumentation
80
+
81
+ The gateway automatically instruments:
82
+
83
+ - HTTP request duration and counts
84
+ - WebSocket connection lifecycle
85
+ - RPC method calls
86
+ - Channel operations
87
+
88
+ ### Cron Instrumentation
89
+
90
+ Cron jobs are instrumented with:
91
+
92
+ - Job execution duration
93
+ - Success/failure counts
94
+ - Schedule adherence metrics
95
+
96
+ ### Custom Instrumentation
97
+
98
+ Add custom metrics in your code:
99
+
100
+ ```typescript
101
+ import { withInstrumentation, recordCounter, recordHistogram } from "../telemetry/instrumentation.js";
102
+
103
+ // Wrap a function with tracing
104
+ const result = await withInstrumentation("my-operation", async (span) => {
105
+ span.setAttribute("custom.attribute", "value");
106
+ return await doWork();
107
+ });
108
+
109
+ // Record a counter
110
+ recordCounter("poolbot.mycomponent.events", 1, { event_type: "created" });
111
+
112
+ // Record a histogram value
113
+ recordHistogram("poolbot.mycomponent.duration", durationMs);
114
+ ```
115
+
116
+ ## Exporters
117
+
118
+ ### Console Exporter
119
+
120
+ Outputs traces and metrics to stdout (useful for debugging):
121
+
122
+ ```bash
123
+ poolbot config set diagnostics.otel.enabled true
124
+ # No endpoint = console exporter
125
+ ```
126
+
127
+ ### OTLP Exporter
128
+
129
+ Send to any OTLP-compatible backend:
130
+
131
+ ```bash
132
+ poolbot config set diagnostics.otel.enabled true
133
+ poolbot config set diagnostics.otel.endpoint http://jaeger:4318
134
+ ```
135
+
136
+ Compatible with:
137
+ - [Jaeger](https://www.jaegertracing.io/)
138
+ - [Tempo](https://grafana.com/oss/tempo/)
139
+ - [Honeycomb](https://www.honeycomb.io/)
140
+ - [Datadog](https://www.datadoghq.com/)
141
+ - Any OTLP-compliant collector
142
+
143
+ ### In-Memory Exporter
144
+
145
+ Used internally by the CLI for displaying metrics without external dependencies.
146
+
147
+ ## Architecture
148
+
149
+ The telemetry system consists of:
150
+
151
+ 1. **TelemetryService** (`src/telemetry/service.ts`): Core SDK initialization and lifecycle
152
+ 2. **Instrumentation Helpers** (`src/telemetry/instrumentation.ts`): High-level APIs for tracing and metrics
153
+ 3. **Gateway Instrumentation** (`src/telemetry/gateway-instrumentation.ts`): Gateway-specific metrics
154
+ 4. **Cron Instrumentation** (`src/telemetry/cron-instrumentation.ts`): Cron job metrics
155
+ 5. **RPC Handlers** (`src/gateway/server-methods/telemetry.ts`): CLI-to-gateway communication
156
+ 6. **Alert Engine** (`src/telemetry/alert-engine.ts`): Intelligent alerting with configurable rules
157
+
158
+ ## Alerting
159
+
160
+ Pool Bot includes an intelligent alert system that monitors telemetry data and notifies you when issues are detected.
161
+
162
+ ### Built-in Alert Rules
163
+
164
+ | Rule | Condition | Severity | Description |
165
+ |------|-----------|----------|-------------|
166
+ | `cron-job-failures` | >3 failures in 5min | error | Cron job execution failures |
167
+ | `cron-job-slow` | >60s execution | warn | Cron jobs running slowly |
168
+ | `cron-job-stuck` | >5min execution | error | Cron jobs stuck/frozen |
169
+ | `security-scan-failures` | >0 failures | error | Security scan failures |
170
+ | `hexstrike-api-latency` | >5s response | warn | HexStrike API slow |
171
+ | `swarm-task-failures` | >3 failures in 5min | error | Swarm task failures |
172
+ | `gateway-memory-high` | >512MB usage | warn | High memory usage |
173
+ | `gateway-memory-critical` | >1GB usage | error | Critical memory usage |
174
+ | `gateway-cpu-high` | >80% CPU | warn | High CPU usage |
175
+
176
+ ### Alert Configuration
177
+
178
+ Configure alerts via config:
179
+
180
+ ```bash
181
+ # Enable alerts
182
+ poolbot config set alerts.enabled true
183
+
184
+ # Configure notification channels
185
+ poolbot config set alerts.channels.webhook.url https://hooks.slack.com/services/...
186
+ poolbot config set alerts.channels.announce true # Use configured announce channel
187
+ ```
188
+
189
+ ### Custom Alert Rules
190
+
191
+ Add custom rules programmatically:
192
+
193
+ ```typescript
194
+ import { alertEngine } from "../telemetry/alert-engine.js";
195
+
196
+ // Add custom rule
197
+ alertEngine.addRule({
198
+ id: "my-custom-alert",
199
+ name: "Custom Metric Alert",
200
+ metric: "poolbot.mycomponent.errors",
201
+ condition: { type: "threshold", operator: ">", value: 10 },
202
+ windowMs: 60000, // 1 minute window
203
+ severity: "error",
204
+ channels: ["webhook"]
205
+ });
206
+ ```
207
+
208
+ ### Alert Channels
209
+
210
+ - **Webhook**: POST alert payload to configured URL
211
+ - **Announce**: Send to configured announce channel (Discord, Slack, etc.)
212
+ - **Console**: Log to stderr (always enabled)
213
+
214
+ ### Alert Payload
215
+
216
+ ```json
217
+ {
218
+ "ruleId": "cron-job-failures",
219
+ "ruleName": "Cron Job Failures",
220
+ "severity": "error",
221
+ "message": "Alert: Cron Job Failures - 5 failures in 5 minutes",
222
+ "timestamp": "2026-03-10T12:00:00Z",
223
+ "data": { "failures": 5, "window": "5m" }
224
+ }
225
+ ```
226
+
227
+ ## Troubleshooting
228
+
229
+ ### Telemetry not initializing
230
+
231
+ Check logs for:
232
+ ```
233
+ [telemetry] service started
234
+ ```
235
+
236
+ If missing, verify:
237
+ - `diagnostics.otel.enabled` is `true`
238
+ - Config was saved: `poolbot config get diagnostics.otel`
239
+
240
+ ### No metrics appearing
241
+
242
+ For OTLP export:
243
+ - Verify endpoint URL is correct
244
+ - Check network connectivity: `curl -v $OTEL_ENDPOINT`
245
+ - Review collector logs for rejected spans
246
+
247
+ ### High memory usage
248
+
249
+ - Reduce `sampleRate` (e.g., `0.1` for 10% sampling)
250
+ - Lower `flushIntervalMs` to export more frequently
251
+ - Disable unused instrumentation: `diagnostics.otel.metrics: false`
252
+
253
+ ## Examples
254
+
255
+ ### Basic Setup with Jaeger
256
+
257
+ ```bash
258
+ # Start Jaeger
259
+ docker run -d --name jaeger \
260
+ -p 16686:16686 \
261
+ -p 4318:4318 \
262
+ jaegertracing/all-in-one:latest
263
+
264
+ # Configure Pool Bot
265
+ poolbot config set diagnostics.otel.enabled true
266
+ poolbot config set diagnostics.otel.endpoint http://localhost:4318/v1/traces
267
+ poolbot config set diagnostics.otel.serviceName poolbot-dev
268
+
269
+ # Restart gateway
270
+ poolbot gateway restart
271
+
272
+ # View traces at http://localhost:16686
273
+ ```
274
+
275
+ ### Debugging with Console Output
276
+
277
+ ```bash
278
+ poolbot config set diagnostics.otel.enabled true
279
+ poolbot config set diagnostics.otel.traces true
280
+ poolbot config set diagnostics.otel.metrics false # Reduce noise
281
+
282
+ # Watch telemetry output
283
+ poolbot gateway run 2>&1 | grep -E "\[telemetry\]|Span|Metric"
284
+ ```