wolverine-ai 3.1.0 → 3.1.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/.env.example +20 -0
- package/CLAUDE.md +146 -0
- package/README.md +2 -0
- package/package.json +4 -5
package/.env.example
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Wolverine — Secrets Only
|
|
2
|
+
# Copy to .env.local and fill in your keys.
|
|
3
|
+
# All other settings are in server/config/settings.json
|
|
4
|
+
|
|
5
|
+
# ── API Keys ─────────────────────────────────────────────────────
|
|
6
|
+
# Your OpenAI API key (required)
|
|
7
|
+
OPENAI_API_KEY=
|
|
8
|
+
ANTHROPIC_API_KEY=
|
|
9
|
+
# ── Dashboard Admin Key (make your own) ──────────────────────────────────────────
|
|
10
|
+
# Required for the agent command interface on the dashboard.
|
|
11
|
+
# Generate: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
12
|
+
WOLVERINE_ADMIN_KEY=
|
|
13
|
+
|
|
14
|
+
# ── Custom Secrets ───────────────────────────────────────────────
|
|
15
|
+
# Add any secret here — wolverine automatically redacts its value
|
|
16
|
+
# from all AI calls, logs, brain storage, and dashboard output.
|
|
17
|
+
#
|
|
18
|
+
# DATABASE_URL=postgres://user:pass@host:5432/db
|
|
19
|
+
# JWT_SECRET=my-secret
|
|
20
|
+
# STRIPE_SECRET_KEY=sk_live_xxx
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## What This Is
|
|
6
|
+
|
|
7
|
+
Wolverine is a self-healing Node.js server framework. It wraps a server process, catches crashes AND caught 500 errors, diagnoses them with AI (OpenAI or Anthropic), generates fixes, verifies them, and restarts — automatically. Published as `wolverine-ai` on npm (v3.1.0). 65 exports, 83 files, 6 skills.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm start # Run server/index.js under wolverine (self-healing)
|
|
13
|
+
npm run server # Run server/index.js directly (no healing)
|
|
14
|
+
npm run test:pentest # Security scan for secret leakage
|
|
15
|
+
npm run demo:list # List demo scenarios
|
|
16
|
+
npm run demo -- 01 # Run specific demo
|
|
17
|
+
npx wolverine server/index.js # CLI entry point
|
|
18
|
+
wolverine --info # System detection
|
|
19
|
+
wolverine --update # Safe framework upgrade
|
|
20
|
+
wolverine --backup "reason" # Create server snapshot
|
|
21
|
+
wolverine --list-backups # Show all snapshots
|
|
22
|
+
wolverine --rollback <id> # Restore specific backup
|
|
23
|
+
wolverine --rollback-latest # Restore most recent
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
No standard test runner — demos in `tests/fixtures/` serve as integration tests.
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+
### Heal Pipeline (src/core/wolverine.js)
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Error detected (crash OR caught 500 via IPC)
|
|
34
|
+
→ Empty stderr? → Just restart, no AI ($0.00)
|
|
35
|
+
→ Parse error → classify type → redact secrets
|
|
36
|
+
→ Injection scan (skip if < 20 chars)
|
|
37
|
+
→ Loop guard: same error failed 3+ times in 10min? → File bug report, stop
|
|
38
|
+
→ Rate limit: 5 heals per 5min max
|
|
39
|
+
→ Operational fix (zero tokens):
|
|
40
|
+
missing_module → deps.diagnose() → npm install
|
|
41
|
+
EADDRINUSE → kill stale process
|
|
42
|
+
ENOENT → create missing file
|
|
43
|
+
EACCES → chmod
|
|
44
|
+
→ Token budget by complexity: simple=20K, moderate=50K, complex=100K
|
|
45
|
+
→ Goal Loop (3 iterations):
|
|
46
|
+
1. Fast path: CODING_MODEL, JSON with code+commands, backup diff context
|
|
47
|
+
2. Agent: dynamic prompt (400 tokens simple, 1200 complex), 18 tools
|
|
48
|
+
3. Sub-agents: explore→plan→fix (Haiku triage, Sonnet/Opus fix only)
|
|
49
|
+
→ Verify: syntax → boot probe (route probe skipped — ErrorMonitor is safety net)
|
|
50
|
+
→ Success: retryCount reset, record to brain with full context
|
|
51
|
+
→ Fail: rollback, brain records "DO NOT REPEAT", next iteration
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`heal()` wraps `_healImpl()` with 5-minute `Promise.race` timeout.
|
|
55
|
+
|
|
56
|
+
### IPC Error Chain (caught 500s without crash)
|
|
57
|
+
|
|
58
|
+
1. **error-hook.js** — preloaded via `--require`, patches Fastify/Express for IPC. WeakSet dedup.
|
|
59
|
+
2. **runner.js** — spawns child with `stdio: ["inherit","inherit","pipe","ipc"]`, listens `child.on("message")`
|
|
60
|
+
3. **error-monitor.js** — tracks errors per normalized route (`/api/users/123` → `/api/users/:id`), threshold=1, 60s cooldown. Health check failures also trigger heal.
|
|
61
|
+
|
|
62
|
+
### AI Client (src/core/ai-client.js)
|
|
63
|
+
|
|
64
|
+
Dual provider: OpenAI + Anthropic. Auto-detected from model name (`claude-*` → Anthropic). All responses normalized to `{content, toolCalls, usage}`. **Anthropic prompt caching** — system prompt marked `cache_control: ephemeral`, 90% cheaper on repeat calls. Per-model output limits with 10% buffer. Every call tracked: latencyMs, success/failure, tokens, cost.
|
|
65
|
+
|
|
66
|
+
Embeddings always use OpenAI (Anthropic has no embedding API).
|
|
67
|
+
|
|
68
|
+
### Agent (src/agent/agent-engine.js)
|
|
69
|
+
|
|
70
|
+
**Dynamic system prompt**: simple errors (TypeError/ReferenceError) get 400-token compact prompt with 7 tools. Complex errors get full prompt with all 18 tools + strategy table.
|
|
71
|
+
|
|
72
|
+
18 tools: file (read/write/edit/glob/grep/list_dir/move_file), shell (bash_exec/git_log/git_diff), database (inspect_db/run_db_fix), diagnostics (check_port/check_env), deps (audit_deps/check_migration), research (web_fetch), control (done).
|
|
73
|
+
|
|
74
|
+
**Cost optimizations**: zero-cost structural compaction (no LLM, extracts signals from messages), tool result truncation (4K cap), token estimation (`text.length/4`), pre/post tool hooks (`.wolverine/hooks.json`), error-graceful tools (`[ERROR]` results not thrown).
|
|
75
|
+
|
|
76
|
+
**Protected paths**: agent cannot modify `src/`, `bin/`, `tests/`, `node_modules/`, `.env`, `package.json`. Only `server/` is editable.
|
|
77
|
+
|
|
78
|
+
### Provider Config (server/config/settings.json)
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{ "provider": "hybrid", "openai_settings": {...}, "anthropic_settings": {...}, "hybrid_settings": {...} }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Config loader reads `{provider}_settings`. Env vars override per-role. Missing config sections auto-patched on startup via `_ensureDefaults()`.
|
|
85
|
+
|
|
86
|
+
### Brain (src/brain/vector-store.js + brain.js)
|
|
87
|
+
|
|
88
|
+
IVF-indexed vector store: k-means++ clustering, BM25 keyword search, binary persistence. 60 seed docs. Benchmarks: 100=0.2ms, 10K=4.4ms, 50K=23.7ms.
|
|
89
|
+
|
|
90
|
+
**Namespace isolation**: error heals search only `errors/fixes/learnings/functions` — seed docs (20K tokens) excluded unless query is about wolverine itself. Function map hash check skips re-embedding if unchanged.
|
|
91
|
+
|
|
92
|
+
### Backup (src/backup/backup-manager.js)
|
|
93
|
+
|
|
94
|
+
All backups in `~/.wolverine-safe-backups/` (outside project, survives git pull/npm install). States: UNSTABLE → VERIFIED → STABLE (30min). Protected files never rolled back: `settings.json`, `db.js`, `.env.local`.
|
|
95
|
+
|
|
96
|
+
### Skills (src/skills/ — 6 files)
|
|
97
|
+
|
|
98
|
+
- **sql.js** — injection prevention, SafeDB, idempotency guard
|
|
99
|
+
- **deps.js** — dependency diagnosis (zero tokens), npm audit, migration paths
|
|
100
|
+
- **update.js** — safe framework upgrade, emergency backup, brain seed merge
|
|
101
|
+
- **backup.js** — agent-friendly backup/rollback with CLI commands
|
|
102
|
+
- **loop-guard.js** — infinite loop detection, bug reports, process dedup (PID file)
|
|
103
|
+
- **skill-registry.js** — auto-discovery + token-scored matching
|
|
104
|
+
|
|
105
|
+
### Telemetry (src/platform/)
|
|
106
|
+
|
|
107
|
+
Heartbeats every 60s. Stable instance ID (persisted to `.wolverine/instance-id`). Cumulative usage from disk (not session-only). `byModel` with latency/success/tokens-per-sec/cost-per-call. `byProvider` aggregated. Auto-update checks every 5min, selective git checkout (never touches `server/`).
|
|
108
|
+
|
|
109
|
+
## Key Constraints
|
|
110
|
+
|
|
111
|
+
- **Server port is always 3000.** Any other port breaks APIs. Kill 3000 and bind there.
|
|
112
|
+
- **Dashboard on PORT+1** (3001).
|
|
113
|
+
- **heal() has 5-minute timeout.** `Promise.race` recovery.
|
|
114
|
+
- **Global rate limit: 5 heals per 5 minutes.**
|
|
115
|
+
- **Loop guard: 3 failed heals on same error in 10min → stop + bug report.**
|
|
116
|
+
- **Error threshold: 1** — single 500 triggers heal. 60s cooldown per route.
|
|
117
|
+
- **Empty stderr → just restart, no AI.** Prevents token burn on signal kills.
|
|
118
|
+
- **bash_exec: 30s default, 60s cap.**
|
|
119
|
+
- **Process dedup via PID file.** Kills old process on startup.
|
|
120
|
+
- **Both API keys needed for hybrid mode** — OPENAI_API_KEY for embeddings.
|
|
121
|
+
- **Auto-update: selective git checkout** — only updates `src/`, `bin/`, `package.json`. Never touches `server/`.
|
|
122
|
+
- **Rollback protects:** `settings.json`, `db.js`, `.env.local` never overwritten.
|
|
123
|
+
|
|
124
|
+
## Configuration
|
|
125
|
+
|
|
126
|
+
- **Secrets:** `.env.local` (OPENAI_API_KEY, ANTHROPIC_API_KEY, WOLVERINE_ADMIN_KEY)
|
|
127
|
+
- **Settings:** `server/config/settings.json` — provider, 3 model presets, cluster, telemetry, rate limits, health checks, autoUpdate, errorMonitor
|
|
128
|
+
- **10 model slots:** reasoning, coding, chat, tool, classifier, audit, compacting, research, embedding
|
|
129
|
+
- **Config priority:** env vars > `{provider}_settings` > defaults
|
|
130
|
+
|
|
131
|
+
## Files That Matter Most
|
|
132
|
+
|
|
133
|
+
| File | Why |
|
|
134
|
+
|------|-----|
|
|
135
|
+
| `src/core/wolverine.js` | Heal pipeline, operational fixes, goal loop, token budgets |
|
|
136
|
+
| `src/core/runner.js` | Process manager, IPC, health/error monitors, loop guard, auto-update |
|
|
137
|
+
| `src/core/ai-client.js` | Dual provider, prompt caching, output limits, latency tracking |
|
|
138
|
+
| `src/agent/agent-engine.js` | Dynamic prompt, 18 tools, zero-cost compaction, hooks |
|
|
139
|
+
| `src/agent/sub-agents.js` | Dynamic token budgets, Haiku triage, restricted tool sets |
|
|
140
|
+
| `src/core/verifier.js` | Syntax + boot probe, error classification comparison |
|
|
141
|
+
| `src/brain/vector-store.js` | IVF + BM25 + binary persistence |
|
|
142
|
+
| `src/brain/brain.js` | 60 seed docs, namespace isolation, function map hash |
|
|
143
|
+
| `src/skills/loop-guard.js` | Infinite loop detection, bug reports, process dedup |
|
|
144
|
+
| `src/skills/update.js` | Safe upgrade, emergency backup, brain seed merge |
|
|
145
|
+
| `src/platform/auto-update.js` | Version lock, dep verification, max 1 attempt per boot |
|
|
146
|
+
| `server/config/settings.json` | Provider selection, 3 model presets, all config |
|
package/README.md
CHANGED
|
@@ -450,6 +450,8 @@ Three layers prevent token waste:
|
|
|
450
450
|
|
|
451
451
|
| Technique | What it does | Cost |
|
|
452
452
|
|-----------|-------------|------|
|
|
453
|
+
| **Dynamic system prompt** | Simple errors get 400-token prompt with 7 tools. Complex get 1200 with 18 + strategy | 50% on 70% of heals |
|
|
454
|
+
| **Brain namespace isolation** | Seed docs (20K tokens) excluded from error heals — only searched for wolverine queries | 50% context reduction |
|
|
453
455
|
| **Prompt caching** | Anthropic system prompt cached server-side — 90% cheaper on repeat calls | 12-16K tokens saved per heal |
|
|
454
456
|
| **Tool result truncation** | Tool output capped at 4K chars — prevents context blowup from large reads | Up to 30K saved per turn |
|
|
455
457
|
| **Zero-cost compaction** | Extracts structural signals (tools, files, errors) from history — no LLM call | $0.00 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wolverine-ai",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Self-healing Node.js server framework powered by AI. Catches crashes, diagnoses errors, generates fixes, verifies, and restarts — automatically.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -49,10 +49,9 @@
|
|
|
49
49
|
"src/",
|
|
50
50
|
"server/",
|
|
51
51
|
"examples/",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"README.md"
|
|
52
|
+
"README.md",
|
|
53
|
+
"CLAUDE.md",
|
|
54
|
+
".env.example"
|
|
56
55
|
],
|
|
57
56
|
"dependencies": {
|
|
58
57
|
"@anthropic-ai/sdk": "^0.82.0",
|