@kernel.chat/kbot 3.30.0 → 3.31.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.
@@ -0,0 +1,133 @@
1
+ // kbot Notification System — Proactive alerts from the daemon
2
+ //
3
+ // Channels:
4
+ // - system: macOS Notification Center (osascript) / Linux (notify-send)
5
+ // - terminal: bell character to active terminal
6
+ // - discord: webhook to configured channel
7
+ // - log: always writes to daemon log
8
+ //
9
+ // The daemon triggers notifications when:
10
+ // - Price alerts fire
11
+ // - Security incidents detected (memory tampering, injection attempts)
12
+ // - Provider outages
13
+ // - Dependency vulnerabilities discovered
14
+ import { execSync } from 'node:child_process';
15
+ import { existsSync, readFileSync } from 'node:fs';
16
+ import { join } from 'node:path';
17
+ import { homedir, platform } from 'node:os';
18
+ /** Send a notification through the specified channel */
19
+ export async function notify(opts) {
20
+ const channel = opts.channel || 'system';
21
+ try {
22
+ switch (channel) {
23
+ case 'system':
24
+ return sendSystemNotification(opts);
25
+ case 'terminal':
26
+ // Bell character — works in any terminal
27
+ process.stdout.write('\x07');
28
+ return true;
29
+ case 'discord':
30
+ return await sendDiscordNotification(opts);
31
+ case 'log':
32
+ // Log-only — handled by caller
33
+ return true;
34
+ default:
35
+ return false;
36
+ }
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }
42
+ /** macOS Notification Center or Linux notify-send */
43
+ function sendSystemNotification(opts) {
44
+ const os = platform();
45
+ if (os === 'darwin') {
46
+ // macOS — use osascript for Notification Center
47
+ const title = opts.title.replace(/"/g, '\\"');
48
+ const body = opts.body.replace(/"/g, '\\"');
49
+ const sound = opts.urgency === 'critical' ? ' sound name "Funk"' : opts.sound ? ' sound name "default"' : '';
50
+ try {
51
+ execSync(`osascript -e 'display notification "${body}" with title "${title}"${sound}'`, { timeout: 5000 });
52
+ return true;
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
58
+ if (os === 'linux') {
59
+ // Linux — use notify-send
60
+ const urgency = opts.urgency || 'normal';
61
+ try {
62
+ execSync(`notify-send -u ${urgency} "${opts.title}" "${opts.body}"`, { timeout: 5000 });
63
+ return true;
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
69
+ // Windows — use PowerShell toast
70
+ if (os === 'win32') {
71
+ try {
72
+ const ps = `
73
+ [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
74
+ $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
75
+ $textNodes = $template.GetElementsByTagName('text')
76
+ $textNodes.Item(0).AppendChild($template.CreateTextNode('${opts.title}')) | Out-Null
77
+ $textNodes.Item(1).AppendChild($template.CreateTextNode('${opts.body}')) | Out-Null
78
+ $toast = [Windows.UI.Notifications.ToastNotification]::new($template)
79
+ [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('kbot').Show($toast)
80
+ `;
81
+ execSync(`powershell -command "${ps.replace(/\n/g, ';')}"`, { timeout: 5000 });
82
+ return true;
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+ /** Send notification to Discord webhook */
91
+ async function sendDiscordNotification(opts) {
92
+ // Check for configured webhook
93
+ const configPath = join(homedir(), '.kbot', 'config.json');
94
+ let webhookUrl = process.env.DISCORD_WEBHOOK_URL || '';
95
+ if (!webhookUrl && existsSync(configPath)) {
96
+ try {
97
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
98
+ webhookUrl = config.discord_webhook || '';
99
+ }
100
+ catch { /* no config */ }
101
+ }
102
+ if (!webhookUrl)
103
+ return false;
104
+ const color = opts.urgency === 'critical' ? 0xFF0000 : opts.urgency === 'low' ? 0x888888 : 0x6B5B95;
105
+ try {
106
+ const res = await fetch(webhookUrl, {
107
+ method: 'POST',
108
+ headers: { 'Content-Type': 'application/json' },
109
+ body: JSON.stringify({
110
+ embeds: [{
111
+ title: opts.title,
112
+ description: opts.body,
113
+ color,
114
+ timestamp: new Date().toISOString(),
115
+ footer: { text: 'kbot daemon' },
116
+ }],
117
+ }),
118
+ signal: AbortSignal.timeout(5000),
119
+ });
120
+ return res.ok;
121
+ }
122
+ catch {
123
+ return false;
124
+ }
125
+ }
126
+ /** Send notification on all available channels */
127
+ export async function notifyAll(opts) {
128
+ await Promise.allSettled([
129
+ notify({ ...opts, channel: 'system' }),
130
+ notify({ ...opts, channel: 'discord' }),
131
+ ]);
132
+ }
133
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.js","sourceRoot":"","sources":["../src/notifications.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,YAAY;AACZ,0EAA0E;AAC1E,kDAAkD;AAClD,6CAA6C;AAC7C,uCAAuC;AACvC,EAAE;AACF,0CAA0C;AAC1C,wBAAwB;AACxB,yEAAyE;AACzE,uBAAuB;AACvB,4CAA4C;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAY3C,wDAAwD;AACxD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAyB;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAA;IAExC,IAAI,CAAC;QACH,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAA;YAErC,KAAK,UAAU;gBACb,yCAAyC;gBACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;gBAC5B,OAAO,IAAI,CAAA;YAEb,KAAK,SAAS;gBACZ,OAAO,MAAM,uBAAuB,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AAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;IAEnG,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,EAAE;YAClC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,MAAM,EAAE,CAAC;wBACP,KAAK,EAAE,IAAI,CAAC,KAAK;wBACjB,WAAW,EAAE,IAAI,CAAC,IAAI;wBACtB,KAAK;wBACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;wBACnC,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;qBAChC,CAAC;aACH,CAAC;YACF,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;SAClC,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,EAAE,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAA;IAAC,CAAC;AAC1B,CAAC;AAED,kDAAkD;AAClD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAyB;IACvD,MAAM,OAAO,CAAC,UAAU,CAAC;QACvB,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;KACxC,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kernel.chat/kbot",
3
- "version": "3.30.0",
3
+ "version": "3.31.0",
4
4
  "description": "The only AI agent that builds its own tools — and defends itself. Self-Defense System: HMAC memory integrity, prompt injection detection, knowledge sanitization, forge verification, anomaly detection, incident logging. Cybersecurity tools: dep_audit, secret_scan, ssl_check, headers_check, cve_lookup, port_scan, owasp_check. Machine-aware situated intelligence: full hardware profiling (CPU, GPU, RAM, display, battery, dev tools), resource-adaptive tool pipeline, memory-pressure throttling, GPU-accelerated model routing. Multi-channel cognitive engine: email agent, iMessage agent, consultation pipeline, Trader agent with paper trading & DeFi, 26 specialist agents, 345+ tools, 20 providers. Finance stack: 31 tools across market data, wallet & swaps, stocks, and sentiment. Synthesis Engine: closed-loop intelligence compounding. Runtime tool forging, Forge Registry, autopoietic health, immune self-audit. Cost-aware model routing, fallback chains, Bayesian skill routing. 11 local models (Llama 3.3, Qwen 3, DeepSeek R1, Codestral 22B). Embedded llama.cpp, MCP server, SDK. MIT.",
5
5
  "type": "module",
6
6
  "repository": {