@kernel.chat/kbot 3.27.0 → 3.28.1
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 +137 -30
- package/dist/cli.js +99 -0
- package/dist/cli.js.map +1 -1
- package/dist/self-defense.d.ts +71 -0
- package/dist/self-defense.d.ts.map +1 -0
- package/dist/self-defense.js +403 -0
- package/dist/self-defense.js.map +1 -0
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<strong>kbot</strong><br>
|
|
3
|
-
<em>The only AI agent that builds its own tools.</em>
|
|
3
|
+
<em>The only AI agent that builds its own tools — and defends itself.</em>
|
|
4
4
|
</p>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
@@ -19,33 +19,62 @@
|
|
|
19
19
|
npm install -g @kernel.chat/kbot
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
**
|
|
22
|
+
**Self-defending AI agent. 345+ tools. 26 agents. 20 providers. Forges new tools at runtime. Built-in cybersecurity suite. $0 local AI. MIT licensed.**
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
## What's New
|
|
26
|
+
## What's New
|
|
27
|
+
|
|
28
|
+
### v3.28 — Self-Defense System
|
|
29
|
+
|
|
30
|
+
kbot now protects its own integrity — and yours.
|
|
31
|
+
|
|
32
|
+
| Feature | What it means |
|
|
33
|
+
|---------|---------------|
|
|
34
|
+
| **Memory Integrity** | HMAC signatures on all memory files. Tampered memories are detected and quarantined. |
|
|
35
|
+
| **Prompt Injection Detection** | Real-time scanning of inputs for injection attacks, jailbreaks, and adversarial prompts. |
|
|
36
|
+
| **Knowledge Sanitization** | Learned patterns and forged tools are sanitized before storage to prevent poisoning. |
|
|
37
|
+
| **Forge Verification** | Cryptographic verification of forged tools — unsigned or modified tools are blocked. |
|
|
38
|
+
| **Anomaly Detection** | Behavioral baselines with statistical anomaly scoring. Alerts on drift. |
|
|
39
|
+
| **Incident Logging** | Tamper-proof audit log of all security events. |
|
|
40
|
+
| **`kbot defense`** | `audit` · `sign` · `verify` · `incidents` — full CLI for the defense system. |
|
|
41
|
+
|
|
42
|
+
### v3.27 — Cybersecurity Tools
|
|
43
|
+
|
|
44
|
+
Seven new security tools, available to every agent:
|
|
45
|
+
|
|
46
|
+
`dep_audit` · `secret_scan` · `ssl_check` · `headers_check` · `cve_lookup` · `port_scan` · `owasp_check`
|
|
47
|
+
|
|
48
|
+
Plus P0 fixes: all Supabase edge functions now enforce auth headers. No more unauthenticated access.
|
|
49
|
+
|
|
50
|
+
### v3.26 — Trader Agent & Finance Stack
|
|
27
51
|
|
|
28
52
|
| Feature | What it means |
|
|
29
53
|
|---------|---------------|
|
|
30
54
|
| **Trader Agent** | `kbot --agent trader` — crypto market analysis, paper trading, DeFi yield scanning. |
|
|
31
|
-
| **Finance Tools** |
|
|
32
|
-
| **
|
|
55
|
+
| **Finance Tools (11)** | `market_data`, `market_overview`, `price_history`, `technical_analysis`, `paper_trade`, `market_sentiment`, `defi_yields` + 4 more. |
|
|
56
|
+
| **Wallet & Swaps (9)** | Create/import Solana wallets (AES-256-CBC encrypted). Jupiter DEX swaps. Token balances, transaction history, airdrop tracking. |
|
|
57
|
+
| **Stock Tools (6)** | Stock screener, earnings calendar, sector rotation, company fundamentals, insider trades, options flow. |
|
|
58
|
+
| **Sentiment (5)** | Social sentiment, whale tracking, fear & greed index, news aggregation, trend detection. |
|
|
59
|
+
| **Introspection Engine** | `kbot insights` · `kbot reflect` · `kbot compare` — ask kbot what it knows about itself. |
|
|
33
60
|
| **`kbot help`** | New CLI subcommand — quick reference for commands, agents, and support channels. |
|
|
34
61
|
|
|
35
62
|
---
|
|
36
63
|
|
|
37
64
|
## Why kbot?
|
|
38
65
|
|
|
39
|
-
Other AI agents are static — fixed tools, single providers, no memory, no learning. kbot is the first AI agent that **evolves itself**:
|
|
66
|
+
Other AI agents are static — fixed tools, single providers, no memory, no learning. kbot is the first AI agent that **evolves itself** and **defends itself**:
|
|
40
67
|
|
|
41
68
|
- **Forges its own tools** — When kbot encounters a task it can't handle, it creates a new tool on the spot via `forge_tool`. The tool persists, gets tested, and can be shared via the Forge Registry.
|
|
69
|
+
- **Self-defending** — HMAC memory integrity, prompt injection detection, forge verification, anomaly detection, and tamper-proof incident logging. Run `kbot defense audit` anytime.
|
|
70
|
+
- **Cybersecurity built in** — Dependency audits, secret scanning, SSL/TLS checks, header analysis, CVE lookup, port scanning, OWASP checks. Every project gets security tooling for free.
|
|
42
71
|
- **Self-evolving** — Autopoietic health monitoring (`kbot vitals`) tracks tool success rates, token budgets, and memory pressure. The immune agent self-audits for drift and regressions.
|
|
43
72
|
- **Cost-aware routing** — Automatically selects the cheapest model capable of handling each task. Claude for complex reasoning, DeepSeek for simple queries. Saves 60-90% on API costs.
|
|
44
73
|
- **Fallback chains** — If Anthropic is down, kbot cascades to OpenAI, then Groq, then local. Zero manual intervention.
|
|
45
74
|
- **20 providers, zero lock-in** — Claude, GPT, Gemini, Grok, DeepSeek, Groq, Mistral, and 13 more. Switch anytime.
|
|
46
75
|
- **Runs fully offline** — Embedded llama.cpp runs GGUF models directly. No Ollama needed. $0, fully private.
|
|
47
76
|
- **Learns your patterns** — Bayesian skill ratings + pattern extraction. Gets faster and smarter over time.
|
|
48
|
-
- **26 specialist agents** — Say "fix the auth bug" and it routes to `coder`. Say "research JWT tokens" and it routes to `researcher`. Auto-routed with probabilistic confidence.
|
|
77
|
+
- **26 specialist agents** — Say "fix the auth bug" and it routes to `coder`. Say "research JWT tokens" and it routes to `researcher`. Say "analyze BTC" and it routes to `trader`. Auto-routed with probabilistic confidence.
|
|
49
78
|
- **Crash-proof** — Checkpoints after every tool call. Resume interrupted sessions automatically.
|
|
50
79
|
- **Use as a library** — Clean SDK with typed exports. Build your own tools on top of kbot.
|
|
51
80
|
- **Works in your IDE** — Built-in MCP server for VS Code, Cursor, Zed, Neovim. ACP for JetBrains.
|
|
@@ -84,6 +113,12 @@ kbot "I need a tool that converts CSV to JSON with column filtering"
|
|
|
84
113
|
# Check system health
|
|
85
114
|
kbot vitals
|
|
86
115
|
|
|
116
|
+
# Audit your own defenses
|
|
117
|
+
kbot defense audit
|
|
118
|
+
|
|
119
|
+
# Scan a project for vulnerabilities
|
|
120
|
+
kbot --agent guardian "run a full security scan on this repo"
|
|
121
|
+
|
|
87
122
|
# Pipe mode — compose with Unix tools
|
|
88
123
|
kbot -p "generate a user roles migration" > migration.sql
|
|
89
124
|
```
|
|
@@ -105,7 +140,7 @@ kbot forge install k8s-pod-monitor
|
|
|
105
140
|
kbot forge publish sentiment_analyze
|
|
106
141
|
```
|
|
107
142
|
|
|
108
|
-
Forged tools are first-class citizens — they get the same middleware pipeline, permission checks, and telemetry as built-in tools.
|
|
143
|
+
Forged tools are first-class citizens — they get the same middleware pipeline, permission checks, forge verification, and telemetry as built-in tools.
|
|
109
144
|
|
|
110
145
|
## SDK — Use kbot as a Library
|
|
111
146
|
|
|
@@ -128,7 +163,7 @@ for await (const event of agent.stream("explain this code")) {
|
|
|
128
163
|
const files = await tools.execute('glob', { pattern: 'src/**/*.ts' })
|
|
129
164
|
console.log(files.result)
|
|
130
165
|
|
|
131
|
-
// List all
|
|
166
|
+
// List all 345+ tools
|
|
132
167
|
console.log(tools.list().map(t => t.name))
|
|
133
168
|
```
|
|
134
169
|
|
|
@@ -142,27 +177,28 @@ import { ResponseStream } from '@kernel.chat/kbot' // Stream
|
|
|
142
177
|
|
|
143
178
|
## Specialists
|
|
144
179
|
|
|
145
|
-
|
|
180
|
+
26 agents, auto-routed by Bayesian skill ratings, or pick one with `kbot --agent <name>`:
|
|
146
181
|
|
|
147
182
|
| | Agents |
|
|
148
183
|
|---|---|
|
|
149
184
|
| **Core** | kernel, researcher, coder, writer, analyst |
|
|
150
185
|
| **Extended** | aesthete, guardian, curator, strategist |
|
|
151
|
-
| **Domain** | infrastructure, quant, investigator, oracle, chronist, sage, communicator, adapter |
|
|
186
|
+
| **Domain** | infrastructure, quant, investigator, oracle, chronist, sage, communicator, adapter, trader |
|
|
152
187
|
| **System** | immune, forge |
|
|
153
|
-
| **Presets** | hacker, operator, dreamer, creative, developer, gamedev, playtester
|
|
188
|
+
| **Presets** | hacker, operator, dreamer, creative, developer, gamedev, playtester |
|
|
154
189
|
|
|
155
190
|
```bash
|
|
156
191
|
kbot --agent researcher "what papers cite Friston's Free Energy Principle?"
|
|
157
192
|
kbot --agent guardian "review src/auth.ts for security issues"
|
|
158
193
|
kbot --agent coder "refactor this into smaller functions"
|
|
194
|
+
kbot --agent trader "analyze BTC momentum and run a paper trade"
|
|
159
195
|
```
|
|
160
196
|
|
|
161
|
-
##
|
|
197
|
+
## 345+ Tools
|
|
162
198
|
|
|
163
199
|
| Category | Examples |
|
|
164
200
|
|----------|---------|
|
|
165
|
-
| **Forge** | forge_tool, forge_search, forge_install, forge_publish |
|
|
201
|
+
| **Forge** | forge_tool, forge_search, forge_install, forge_publish, forge_verify |
|
|
166
202
|
| **Files & Code** | read, write, glob, grep, multi-file write |
|
|
167
203
|
| **Quality** | lint (ESLint/Biome/Clippy), test (Vitest/Jest/pytest), deps audit, format, type-check |
|
|
168
204
|
| **Shell** | bash, parallel execute, background tasks |
|
|
@@ -184,10 +220,35 @@ kbot --agent coder "refactor this into smaller functions"
|
|
|
184
220
|
| **LSP** | goto definition, find references, hover, rename, diagnostics, symbols |
|
|
185
221
|
| **Memory** | persistent save, search, update, forget — survives across sessions |
|
|
186
222
|
| **IDE** | MCP server, ACP server, LSP bridge |
|
|
187
|
-
| **Finance** | market data,
|
|
188
|
-
| **
|
|
223
|
+
| **Finance** | market data, technical analysis, paper trading, DeFi yields, Solana wallet & swaps, stock screener, sentiment, whale tracking |
|
|
224
|
+
| **Cybersecurity** | dep_audit, secret_scan, ssl_check, headers_check, cve_lookup, port_scan, owasp_check |
|
|
225
|
+
| **Self-Defense** | memory HMAC, injection detection, knowledge sanitization, forge verification, anomaly detection, incident log |
|
|
226
|
+
| **System** | vitals, immune audit, defense audit, cost tracking, fallback status |
|
|
189
227
|
| **Meta** | subagents, worktrees, planner, sessions, checkpoints, self-eval |
|
|
190
228
|
|
|
229
|
+
## Finance & Trading
|
|
230
|
+
|
|
231
|
+
The **trader agent** (`kbot --agent trader`) is a full-stack financial analysis and paper trading system:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Market analysis
|
|
235
|
+
kbot --agent trader "what's the momentum on ETH right now?"
|
|
236
|
+
kbot --agent trader "screen for undervalued large-cap stocks"
|
|
237
|
+
|
|
238
|
+
# Paper trading (no real money at risk)
|
|
239
|
+
kbot --agent trader "open a paper long on SOL with 2x leverage"
|
|
240
|
+
kbot --agent trader "show my paper portfolio P&L"
|
|
241
|
+
|
|
242
|
+
# DeFi
|
|
243
|
+
kbot --agent trader "find the best stablecoin yields on Solana"
|
|
244
|
+
kbot --agent trader "swap 0.1 SOL for USDC on Jupiter"
|
|
245
|
+
|
|
246
|
+
# Sentiment
|
|
247
|
+
kbot --agent trader "what's crypto twitter saying about the next FOMC?"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**31 finance tools** across 5 categories: market data (11), wallet & swaps (9), stocks (6), and sentiment (5). All paper trading is simulated — no real funds are moved unless you explicitly configure and confirm a live wallet transaction.
|
|
251
|
+
|
|
191
252
|
## Middleware Pipeline
|
|
192
253
|
|
|
193
254
|
Extend tool execution with composable middleware:
|
|
@@ -210,7 +271,7 @@ pipeline.use(executionMiddleware(myExecutor))
|
|
|
210
271
|
await pipeline.execute({ toolName: 'bash', toolArgs: { command: 'ls' }, toolCallId: '1', metadata: {}, aborted: false })
|
|
211
272
|
```
|
|
212
273
|
|
|
213
|
-
Built-in middleware: `permissionMiddleware`, `hookMiddleware`, `timeoutMiddleware`, `metricsMiddleware`, `truncationMiddleware`, `telemetryMiddleware`.
|
|
274
|
+
Built-in middleware: `permissionMiddleware`, `hookMiddleware`, `timeoutMiddleware`, `metricsMiddleware`, `truncationMiddleware`, `telemetryMiddleware`, `defenseMiddleware`.
|
|
214
275
|
|
|
215
276
|
## 20 Providers
|
|
216
277
|
|
|
@@ -241,19 +302,29 @@ Cost-aware routing automatically picks the cheapest provider that can handle eac
|
|
|
241
302
|
|
|
242
303
|
## Local Mode
|
|
243
304
|
|
|
244
|
-
No API key needed. No data leaves your machine.
|
|
305
|
+
No API key needed. No data leaves your machine. 11 models across 3 tiers:
|
|
245
306
|
|
|
246
307
|
```bash
|
|
247
308
|
# Use Ollama (if installed)
|
|
248
309
|
kbot local
|
|
249
310
|
|
|
250
311
|
# Or run models directly — embedded llama.cpp, no external service
|
|
251
|
-
kbot models pull llama3.
|
|
312
|
+
kbot models pull llama3.3-8b
|
|
252
313
|
kbot local --embedded
|
|
253
314
|
|
|
254
315
|
# GPU-accelerated: Metal (Mac), CUDA (Linux/Windows), Vulkan
|
|
255
316
|
```
|
|
256
317
|
|
|
318
|
+
### Model Catalog
|
|
319
|
+
|
|
320
|
+
| Tier | Models | Use case |
|
|
321
|
+
|------|--------|----------|
|
|
322
|
+
| **Light** | Llama 3.3 3B, Qwen 3 4B, Phi-4 Mini | Fast completions, simple tasks, low-RAM machines |
|
|
323
|
+
| **Standard** | Llama 3.3 8B, Qwen 3 8B, Mistral 7B, Codestral 22B | General-purpose coding, chat, analysis |
|
|
324
|
+
| **Heavy** | DeepSeek R1 14B, Llama 3.3 70B (Q4), Qwen 3 32B, Codestral 22B (Q8) | Complex reasoning, large codebase analysis |
|
|
325
|
+
|
|
326
|
+
All models auto-download on first use. GPU acceleration detected automatically (Metal on Apple Silicon, CUDA on NVIDIA, Vulkan fallback).
|
|
327
|
+
|
|
257
328
|
## Structured Streaming
|
|
258
329
|
|
|
259
330
|
Stream typed events to any consumer:
|
|
@@ -308,8 +379,14 @@ Works with Claude Code, Cursor, VS Code, Windsurf, Zed, Neovim. Exposes file ops
|
|
|
308
379
|
| `kbot imessage-agent start` | **iMessage agent** — free SMS/iMessage on macOS |
|
|
309
380
|
| `kbot audit <repo>` | Security + quality audit with shareable badge |
|
|
310
381
|
| `kbot consultation` | Consultation engine — guardrails, intake, client management |
|
|
382
|
+
| `kbot defense audit` | **Self-defense audit** — verify memory integrity, check for anomalies |
|
|
383
|
+
| `kbot defense sign` | Sign all memory and forge artifacts with HMAC |
|
|
384
|
+
| `kbot defense verify` | Verify signatures on memory and forged tools |
|
|
385
|
+
| `kbot defense incidents` | Review tamper-proof security incident log |
|
|
311
386
|
| `kbot vitals` | Autopoietic health check — memory, tools, token budgets |
|
|
312
387
|
| `kbot synthesis` | What kbot knows — memory, patterns, insights |
|
|
388
|
+
| `kbot insights` | Introspection — what kbot has learned about itself |
|
|
389
|
+
| `kbot reflect` | Self-reflection on recent sessions and decisions |
|
|
313
390
|
| `kbot serve` | Start HTTP REST + SSE streaming server |
|
|
314
391
|
| `kbot contribute <repo>` | Find good-first-issues and quick wins |
|
|
315
392
|
| `kbot voice` | Text-to-speech output mode |
|
|
@@ -357,29 +434,59 @@ kbot's agent loop runs 11 always-on cognition modules based on peer-reviewed res
|
|
|
357
434
|
|
|
358
435
|
These aren't metaphors. They're TypeScript modules with paper citations in the headers. The interference between modules — not the modules themselves — is where intelligent behavior emerges. See the [research paper](../../docs/cognitive-module-interference.md).
|
|
359
436
|
|
|
360
|
-
##
|
|
437
|
+
## Security
|
|
361
438
|
|
|
362
|
-
|
|
439
|
+
kbot has two layers of security: protecting **your projects** and protecting **itself**.
|
|
363
440
|
|
|
364
|
-
|
|
365
|
-
|---------|-------------|
|
|
366
|
-
| [`@kernel.chat/skill-router`](https://www.npmjs.com/package/@kernel.chat/skill-router) | Bayesian agent routing — TrueSkill-style, zero LLM calls |
|
|
367
|
-
| [`@kernel.chat/memory-tiers`](https://www.npmjs.com/package/@kernel.chat/memory-tiers) | Three-tier memory: observations → reflections → identity |
|
|
368
|
-
| [`@kernel.chat/tool-forge`](https://www.npmjs.com/package/@kernel.chat/tool-forge) | Runtime tool creation from structured definitions |
|
|
369
|
-
| [`@kernel.chat/prompt-evolver`](https://www.npmjs.com/package/@kernel.chat/prompt-evolver) | GEPA-style prompt self-optimization from execution traces |
|
|
370
|
-
| [`@kernel.chat/kbot-openclaw`](https://www.npmjs.com/package/@kernel.chat/kbot-openclaw) | OpenClaw plugin — kbot as brain for 50+ messaging channels |
|
|
441
|
+
### Project Security (Cybersecurity Tools)
|
|
371
442
|
|
|
372
|
-
|
|
443
|
+
```bash
|
|
444
|
+
kbot --agent guardian "full security audit on this repo"
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
| Tool | What it does |
|
|
448
|
+
|------|-------------|
|
|
449
|
+
| `dep_audit` | Scans dependencies for known vulnerabilities (npm, pip, cargo, go) |
|
|
450
|
+
| `secret_scan` | Detects leaked API keys, tokens, and credentials in source code |
|
|
451
|
+
| `ssl_check` | Validates SSL/TLS certificates, cipher suites, and protocol versions |
|
|
452
|
+
| `headers_check` | Audits HTTP security headers (CSP, HSTS, X-Frame-Options, etc.) |
|
|
453
|
+
| `cve_lookup` | Searches the NVD database for CVEs by package, version, or keyword |
|
|
454
|
+
| `port_scan` | Scans open ports and identifies running services |
|
|
455
|
+
| `owasp_check` | Tests for OWASP Top 10 vulnerabilities |
|
|
456
|
+
|
|
457
|
+
### Self-Defense System
|
|
458
|
+
|
|
459
|
+
kbot protects the integrity of its own memory, tools, and behavior:
|
|
460
|
+
|
|
461
|
+
- **HMAC Memory Integrity** — Every memory file is signed. Tampered memories are detected and quarantined on read.
|
|
462
|
+
- **Prompt Injection Detection** — Inputs are scanned for known injection patterns, jailbreak attempts, and adversarial prompts before processing.
|
|
463
|
+
- **Knowledge Sanitization** — Learned patterns and forged tool definitions are sanitized before storage to prevent knowledge poisoning.
|
|
464
|
+
- **Forge Verification** — Forged tools are cryptographically signed. Unsigned or modified tools are blocked from execution.
|
|
465
|
+
- **Anomaly Detection** — Behavioral baselines are maintained. Statistical anomaly scoring flags unexpected tool usage, token spikes, or routing drift.
|
|
466
|
+
- **Incident Logging** — All security events are recorded in a tamper-proof audit log. Review with `kbot defense incidents`.
|
|
467
|
+
|
|
468
|
+
### Infrastructure Security
|
|
373
469
|
|
|
374
470
|
- **AES-256-CBC encrypted keys at rest** — API keys and wallet private keys never stored in plaintext
|
|
375
471
|
- **Permission system** — destructive operations (file delete, git push, wallet sends) require explicit confirmation
|
|
376
472
|
- **Tool execution timeouts** — 5-minute cap with middleware pipeline; no runaway processes
|
|
377
|
-
- **Immune agent self-audit** — continuous drift detection, anomaly scoring, regression checks
|
|
378
473
|
- **Wallet transaction limits** — configurable spend caps and confirmation gates for on-chain operations
|
|
379
474
|
- **Shell sandboxing** — blocklist prevents dangerous commands; config files restricted to owner (chmod 600)
|
|
380
475
|
- **Local-only telemetry** — session checkpoints and metrics never leave your machine
|
|
381
476
|
- **Open source (MIT)** — audit the code yourself at [github.com/isaacsight/kernel](https://github.com/isaacsight/kernel)
|
|
382
477
|
|
|
478
|
+
## Standalone Packages
|
|
479
|
+
|
|
480
|
+
Use kbot's brain without the full agent:
|
|
481
|
+
|
|
482
|
+
| Package | What it does |
|
|
483
|
+
|---------|-------------|
|
|
484
|
+
| [`@kernel.chat/skill-router`](https://www.npmjs.com/package/@kernel.chat/skill-router) | Bayesian agent routing — TrueSkill-style, zero LLM calls |
|
|
485
|
+
| [`@kernel.chat/memory-tiers`](https://www.npmjs.com/package/@kernel.chat/memory-tiers) | Three-tier memory: observations → reflections → identity |
|
|
486
|
+
| [`@kernel.chat/tool-forge`](https://www.npmjs.com/package/@kernel.chat/tool-forge) | Runtime tool creation from structured definitions |
|
|
487
|
+
| [`@kernel.chat/prompt-evolver`](https://www.npmjs.com/package/@kernel.chat/prompt-evolver) | GEPA-style prompt self-optimization from execution traces |
|
|
488
|
+
| [`@kernel.chat/kbot-openclaw`](https://www.npmjs.com/package/@kernel.chat/kbot-openclaw) | OpenClaw plugin — kbot as brain for 50+ messaging channels |
|
|
489
|
+
|
|
383
490
|
## Need Help?
|
|
384
491
|
|
|
385
492
|
| Channel | What it's for |
|
package/dist/cli.js
CHANGED
|
@@ -741,6 +741,105 @@ async function main() {
|
|
|
741
741
|
const { generateComparison } = await import('./introspection.js');
|
|
742
742
|
process.stderr.write(generateComparison());
|
|
743
743
|
});
|
|
744
|
+
// ── Self-Defense ──
|
|
745
|
+
const defenseCmd = program
|
|
746
|
+
.command('defense')
|
|
747
|
+
.description('Self-defense systems — memory integrity, injection detection, anomaly scanning');
|
|
748
|
+
defenseCmd
|
|
749
|
+
.command('audit')
|
|
750
|
+
.description('Full defense audit — memory integrity, anomalies, incidents, recommendations')
|
|
751
|
+
.action(async () => {
|
|
752
|
+
const { runDefenseAudit } = await import('./self-defense.js');
|
|
753
|
+
const chalk = (await import('chalk')).default;
|
|
754
|
+
const audit = runDefenseAudit();
|
|
755
|
+
console.log();
|
|
756
|
+
console.log(` ${chalk.bold('kbot defense audit')}`);
|
|
757
|
+
console.log();
|
|
758
|
+
// Overall status
|
|
759
|
+
const statusColor = audit.overallStatus === 'secure' ? chalk.green : audit.overallStatus === 'warning' ? chalk.yellow : chalk.red;
|
|
760
|
+
console.log(` ${chalk.bold('Status')}: ${statusColor(audit.overallStatus.toUpperCase())}`);
|
|
761
|
+
console.log();
|
|
762
|
+
// Memory integrity
|
|
763
|
+
const mi = audit.memoryIntegrity;
|
|
764
|
+
console.log(` ${chalk.bold('Memory Integrity')}`);
|
|
765
|
+
console.log(` ${chalk.dim('─'.repeat(40))}`);
|
|
766
|
+
console.log(` Files: ${mi.total} OK: ${chalk.green(String(mi.ok))} Tampered: ${mi.tampered ? chalk.red(String(mi.tampered)) : '0'} New: ${mi.new} Missing: ${mi.missing}`);
|
|
767
|
+
console.log();
|
|
768
|
+
// Anomalies
|
|
769
|
+
if (audit.anomalies.anomalies.length > 0) {
|
|
770
|
+
console.log(` ${chalk.bold('Anomalies')} (${audit.anomalies.anomalies.length})`);
|
|
771
|
+
console.log(` ${chalk.dim('─'.repeat(40))}`);
|
|
772
|
+
for (const a of audit.anomalies.anomalies) {
|
|
773
|
+
const c = a.severity === 'critical' ? chalk.red : a.severity === 'high' ? chalk.yellow : chalk.dim;
|
|
774
|
+
console.log(` ${c(`[${a.severity.toUpperCase()}]`)} ${a.description}`);
|
|
775
|
+
}
|
|
776
|
+
console.log();
|
|
777
|
+
}
|
|
778
|
+
// Incidents
|
|
779
|
+
if (audit.recentIncidents.length > 0) {
|
|
780
|
+
console.log(` ${chalk.bold('Recent Incidents')} (${audit.recentIncidents.length})`);
|
|
781
|
+
console.log(` ${chalk.dim('─'.repeat(40))}`);
|
|
782
|
+
for (const i of audit.recentIncidents.slice(-5)) {
|
|
783
|
+
console.log(` ${i.timestamp.split('T')[0]} ${chalk.dim(i.type)} — ${i.description.slice(0, 60)}`);
|
|
784
|
+
}
|
|
785
|
+
console.log();
|
|
786
|
+
}
|
|
787
|
+
// Recommendations
|
|
788
|
+
if (audit.recommendations.length > 0) {
|
|
789
|
+
console.log(` ${chalk.bold('Recommendations')}`);
|
|
790
|
+
console.log(` ${chalk.dim('─'.repeat(40))}`);
|
|
791
|
+
for (const r of audit.recommendations) {
|
|
792
|
+
console.log(` → ${r}`);
|
|
793
|
+
}
|
|
794
|
+
console.log();
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
defenseCmd
|
|
798
|
+
.command('sign')
|
|
799
|
+
.description('Sign all memory files — establishes integrity baseline')
|
|
800
|
+
.action(async () => {
|
|
801
|
+
const { signMemoryFiles } = await import('./self-defense.js');
|
|
802
|
+
signMemoryFiles();
|
|
803
|
+
printSuccess('Memory files signed. Integrity baseline established.');
|
|
804
|
+
});
|
|
805
|
+
defenseCmd
|
|
806
|
+
.command('verify')
|
|
807
|
+
.description('Verify memory file integrity — detect tampering')
|
|
808
|
+
.action(async () => {
|
|
809
|
+
const { verifyMemoryIntegrity } = await import('./self-defense.js');
|
|
810
|
+
const chalk = (await import('chalk')).default;
|
|
811
|
+
const results = verifyMemoryIntegrity();
|
|
812
|
+
if (results.length === 0) {
|
|
813
|
+
printInfo('No memory files to verify. Run `kbot defense sign` first.');
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
for (const r of results) {
|
|
817
|
+
const icon = r.status === 'ok' ? chalk.green('✓') : r.status === 'tampered' ? chalk.red('✗ TAMPERED') : r.status === 'new' ? chalk.yellow('? new') : chalk.red('! missing');
|
|
818
|
+
console.log(` ${icon} ${r.file}`);
|
|
819
|
+
}
|
|
820
|
+
const tampered = results.filter(r => r.status === 'tampered');
|
|
821
|
+
if (tampered.length > 0) {
|
|
822
|
+
printError(`${tampered.length} file(s) tampered with outside of kbot!`);
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
printSuccess('All memory files intact.');
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
defenseCmd
|
|
829
|
+
.command('incidents')
|
|
830
|
+
.description('Show recent security incidents')
|
|
831
|
+
.action(async () => {
|
|
832
|
+
const { getIncidents } = await import('./self-defense.js');
|
|
833
|
+
const incidents = getIncidents(20);
|
|
834
|
+
if (incidents.length === 0) {
|
|
835
|
+
printInfo('No security incidents recorded.');
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
printInfo(`${incidents.length} incident(s):`);
|
|
839
|
+
for (const i of incidents) {
|
|
840
|
+
printInfo(` ${i.timestamp.split('T')[0]} [${i.severity}] ${i.type} — ${i.description.slice(0, 70)} (${i.action})`);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
744
843
|
program
|
|
745
844
|
.command('machine')
|
|
746
845
|
.description('Show full system profile — hardware, GPU, OS, dev tools, AI capabilities')
|