Skip to main content

Personal AI Gateway โ€” Pure Python, zero-dependency AI assistant with multi-model routing, web UI, and 56+ built-in tools

Project description

๐Ÿ˜ˆ SalmAlm (์‚ถ์•Ž)

Your Entire AI Life in One pip install

PyPI Python License: MIT CI Tests Tools Commands

ํ•œ๊ตญ์–ด README


What is SalmAlm?

SalmAlm is a personal AI gateway โ€” one Python package that gives you a full-featured AI assistant with a web UI, Telegram/Discord bots, 62 tools, and 10 features you won't find anywhere else.

No Docker. No Node.js. No config files. Just:

pip install salmalm
salmalm
# โ†’ http://localhost:18800

First launch opens a Setup Wizard โ€” paste an API key, pick a model, done.

โš ๏ธ Don't run salmalm from inside a cloned repo directory โ€” Python will import the local source instead of the installed package. Run from ~ or any other directory.


Why SalmAlm?

Feature SalmAlm ChatGPT OpenClaw Open WebUI
๐Ÿ”ง Install complexity pip install N/A npm + config Docker
๐Ÿค– Multi-provider routing โœ… โŒ โœ… โœ…
๐Ÿง  Self-Evolving Prompt โœ… โŒ โŒ โŒ
๐Ÿ‘ป Shadow Mode โœ… โŒ โŒ โŒ
๐Ÿ’€ Dead Man's Switch โœ… โŒ โŒ โŒ
๐Ÿ” Encrypted Vault โœ… โŒ โŒ โŒ
๐Ÿ“ฑ Telegram + Discord โœ… โŒ โœ… โŒ
๐Ÿงฉ MCP Marketplace โœ… โŒ โŒ โœ…
๐Ÿ“ฆ Zero dependencies* โœ… N/A โŒ โŒ

*stdlib-only core; optional cryptography for vault, otherwise pure Python HMAC-CTR fallback


โšก Quick Start

# One-liner install (creates venv, installs, symlinks to ~/.local/bin)
curl -fsSL https://raw.githubusercontent.com/hyunjun6928-netizen/salmalm/main/scripts/install.sh | bash

# Or manual install
pip install salmalm

# Start (web UI at http://localhost:18800)
salmalm

# Auto-open browser on start
salmalm --open

# โš ๏ธ If you installed with install.sh before v0.17.24, remove the old PATH entry:
# Edit ~/.bashrc (or ~/.zshrc) and delete the line containing "salmalm-env/bin"

# Create desktop shortcut (double-click to launch!)
salmalm --shortcut

# Self-update to latest version
salmalm --update

# Custom port / external access
SALMALM_PORT=8080 salmalm
SALMALM_BIND=0.0.0.0 salmalm    # expose to LAN (see Security section)

Updating

Three ways to update SalmAlm:

# Option 1: Built-in command (recommended)
salmalm --update

# Option 2: pip directly
pip install --upgrade salmalm

# Option 3: Web UI
# Settings โ†’ ๐Ÿ”„ Update โ†’ "Check for Updates" โ†’ "โฌ†๏ธ Update"

After updating, restart the server (Ctrl+C then salmalm).

Desktop Shortcut

Run salmalm --shortcut once to create a desktop icon:

Platform What's created How to use
Windows SalmAlm.bat on Desktop Double-click โ†’ server starts + browser opens
Linux salmalm.desktop on Desktop Double-click โ†’ server starts + browser opens
macOS SalmAlm.command on Desktop Double-click โ†’ server starts + browser opens

The shortcut is version-independent โ€” update SalmAlm anytime, the shortcut keeps working.

Supported Providers

Provider Models Env Variable
Anthropic Claude Opus 4, Sonnet 4, Haiku 4.5 ANTHROPIC_API_KEY
OpenAI GPT-5.2, GPT-4.1, o3, o4-mini OPENAI_API_KEY
Google Gemini 3 Pro/Flash, 2.5 Pro/Flash GOOGLE_API_KEY
xAI Grok-4, Grok-3 XAI_API_KEY
Ollama Any local model OLLAMA_URL

Set keys via environment variables or the web UI Settings โ†’ API Keys.

CLI Token Reuse (Optional)

If you already use OpenAI Codex CLI or Claude Code, SalmAlm can automatically detect and reuse their OAuth tokens:

CLI Tool Token Path
OpenAI Codex CLI ~/.codex/auth.json
Claude Code ~/.claude/credentials.json

No configuration needed โ€” if the files exist, SalmAlm reads them at startup.

โš ๏ธ Use at your own risk. These tokens are issued for their respective CLI tools. Reusing them in a third-party application may violate the provider's Terms of Service. SalmAlm does not modify or share these tokens โ€” it only reads them locally. You are solely responsible for compliance with each provider's TOS.


๐ŸŽฏ Feature Overview

Core AI

  • Intelligent model routing โ€” auto-selects model by complexity (simpleโ†’Haiku, moderateโ†’Sonnet, complexโ†’Opus), extracted to dedicated model_selection module with user-configurable routing
  • Extended Thinking โ€” deep reasoning mode with budget control
  • 5-stage context compaction โ€” strip binary โ†’ trim tools โ†’ drop old โ†’ truncate โ†’ LLM summarize, with cross-session continuity via compaction_summaries DB table
  • Prompt caching โ€” Anthropic cache_control for 90% cost reduction on system prompts
  • Model failover โ€” exponential backoff + transient error retry (timeout/5xx/429) with 1.5s delay across providers
  • Message queue โ€” offline message queuing with FIFO ordering, 3-stage retry backoff, and dead letter handling; auto-drain on model recovery
  • Sub-agent system โ€” spawn/steer/collect background AI workers with isolated sessions; 8 actions (spawn, stop, list, log, info, steer, collect, status)
  • Streaming stability โ€” partial content preservation on abort; AbortController accumulates tokens and freezes on cancel
  • Cache-aware session pruning โ€” respects Anthropic prompt cache TTL (5min) with 60s cooldown

62 Built-in Tools

Web search (Brave), email (Gmail), calendar (Google), file I/O, shell exec, Python eval, image generation (DALL-E), TTS/STT, browser automation (Playwright), RAG search, QR codes, system monitor, OS-native sandbox, mesh networking, canvas preview, and more.

Web UI

  • Real-time streaming (WebSocket + SSE fallback)
  • WebSocket reconnect with session resume (buffered message flush)
  • Session branching, rollback, search (Ctrl+K)
  • Command palette (Ctrl+Shift+P)
  • Message edit/delete/regenerate
  • Image paste/drag-drop with vision
  • Code syntax highlighting
  • Dark/Light themes (light default), EN/KR i18n
  • PWA installable
  • CSP-compatible โ€” all JS in external app.js, no inline event handlers
  • Compaction progress indicator (โœจ Compacting context...)

Infrastructure

  • OS-native sandbox โ€” bubblewrap (Linux) / sandbox-exec (macOS) / rlimit fallback; auto-detects strongest tier
  • Mesh networking โ€” P2P between SalmAlm instances (task delegation, clipboard sharing, LAN UDP discovery, HMAC auth)
  • Canvas โ€” local HTML/code/chart preview server at :18803
  • Browser automation โ€” Playwright snapshot/act pattern (see setup below)

๐ŸŒ Browser Automation (Optional)

pip install salmalm[browser]
playwright install chromium

Once installed, the AI can browse the web, take screenshots, fill forms, and interact with pages autonomously.

Channels

  • Web โ€” full-featured SPA at localhost:18800
  • Telegram โ€” polling + webhook with inline buttons
  • Discord โ€” bot with thread support

Admin Panels

  • ๐Ÿ“ˆ Dashboard โ€” token usage, cost tracking, daily trends with date filters
  • ๐Ÿ“‹ Sessions โ€” full session management with search, delete, branch indicators
  • โฐ Cron Jobs โ€” scheduled AI tasks with CRUD management
  • ๐Ÿง  Memory โ€” file browser for agent memory/personality files
  • ๐Ÿ”ฌ Debug โ€” real-time system diagnostics (5 cards, auto-refresh)
  • ๐Ÿ“‹ Logs โ€” server log viewer with level filter
  • ๐Ÿ“– Docs โ€” built-in reference for all 32 commands and 10 unique features

โœจ 10 Unique Features

These are SalmAlm-only โ€” not found in ChatGPT, OpenClaw, Open WebUI, or any other gateway:

# Feature What it does
1 Self-Evolving Prompt AI auto-generates personality rules from your conversations (FIFO, max 20)
2 Dead Man's Switch Automated emergency actions if you go inactive for N days
3 Shadow Mode AI silently learns your communication style, replies as you when away
4 Life Dashboard Unified view of health, finance, habits, calendar in one command
5 Mood-Aware Response Detects emotional state and adjusts tone automatically
6 Encrypted Vault PBKDF2-200K + HMAC-authenticated stream cipher for private conversations
7 Agent-to-Agent Protocol HMAC-SHA256 signed communication between SalmAlm instances
8 A/B Split Response Get two different model perspectives on the same question
9 Time Capsule Schedule messages to your future self
10 Thought Stream Private journaling timeline with hashtag search and mood tracking

๐Ÿ“‹ Commands (62+)

Click to expand full command list
Command Description
/help Show all commands
/status Session status
/model <name> Switch model (opus/sonnet/haiku/gpt/auto)
/think [level] Extended thinking (low/medium/high)
/compact Compress context
/context Token count breakdown
/usage Token & cost tracking
/persona <name> Switch persona
/branch Branch conversation
/rollback [n] Undo last n messages
/remind <time> <msg> Set reminder
/expense <amt> <desc> Track expense
/pomodoro Focus timer
/note <text> Quick note
/link <url> Save link
/routine Daily routines
/shadow Shadow mode
/vault Encrypted vault
/capsule Time capsule
/deadman Dead man's switch
/a2a Agent-to-agent
/workflow Workflow engine
/mcp MCP management
/subagents Sub-agents (spawn, steer, collect, list, stop, log, info, status)
/evolve Self-evolving prompt
/mood Mood detection
/split A/B split response
/cron Cron jobs
/bash <cmd> Shell command
/screen Browser control
/life Life dashboard
/briefing Daily briefing
/debug Real-time system diagnostics
/security Security status overview
/plugins Plugin management
/export Export session data
/soul View/edit AI personality file
/config Configuration management
/brave Brave search settings
/approve Approve pending exec commands
/agent Agent management
/plan Create multi-step plans
/compare Compare model responses
/hooks Webhook management
/health System health check
/bookmarks View saved links
/new New session
/clear Clear current session
/whoami Current user info
/tools List available tools
/prune Prune context manually
/skill Skill management
/oauth OAuth setup (Gmail, Calendar)
/queue Message queue management
/tts <text> Text-to-speech
/voice Voice settings
/thought Stream of consciousness
/models Show current model info
/uptime Server uptime
/latency Response latency stats
/health detail Detailed health report
/restart Restart server
/stop Stop server
/reset Reset session state
/verbose Toggle verbose mode
/reasoning Toggle reasoning display
/dock Dock management
/send Send message to channel

๐Ÿ”’ Security

SalmAlm follows a dangerous features default OFF policy:

Feature Default Opt-in
Network bind 127.0.0.1 (loopback only) SALMALM_BIND=0.0.0.0
Shell operators (pipe, redirect, chain) Blocked SALMALM_ALLOW_SHELL=1
Home directory file read Workspace only SALMALM_ALLOW_HOME_READ=1
Vault (without cryptography) Disabled SALMALM_VAULT_FALLBACK=1 for HMAC-CTR
Interpreters in exec Blocked Use /bash or python_eval tool instead
Dangerous exec flags (find -exec, awk -f, etc.) Blocked N/A (security hardening, no override)
HTTP request headers Allowlist only SALMALM_HEADER_PERMISSIVE=1 for blocklist mode

Header Security

HTTP request tool uses allowlist mode by default โ€” only safe headers (Accept, Content-Type, Authorization, User-Agent, etc.) are permitted. Unknown headers are rejected.

Set SALMALM_HEADER_PERMISSIVE=1 to switch to blocklist mode (blocks only dangerous headers like Proxy-Authorization, X-Forwarded-For).

Route Security Middleware

Every HTTP route has a security policy (auth, audit, CSRF, rate limit) enforced automatically via web/middleware.py:

  • Public routes (/, /setup, /static/*) โ€” no auth required
  • API routes (/api/*) โ€” auth required, writes audited, CSRF enforced on POST
  • Sensitive routes (/api/vault/*, /api/admin/*) โ€” always require auth + CSRF

Developers can't accidentally skip auth โ€” the middleware chain enforces it structurally.

Tool Risk Tiers

Tools are classified by risk level, and critical tools are blocked on external network exposure without authentication:

Tier Tools External (0.0.0.0)
๐Ÿ”ด Critical exec, bash, file_write, file_delete, python_eval, browser_action, sandbox_exec Auth required
๐ŸŸก High http_request, send_email, file_read, mesh_task Allowed with warning
๐ŸŸข Normal web_search, calendar, QR, etc. Allowed

External Exposure Safety

When binding to 0.0.0.0, SalmAlm automatically:

  • โš ๏ธ Warns if no admin password is set
  • โš ๏ธ Warns about dangerous tools being accessible
  • Blocks critical tools for unauthenticated sessions

Additional Hardening

  • SSRF defense โ€” private IP blocklist on every redirect hop, scheme allowlist, userinfo block, decimal IP normalization
  • Shell operator blocking โ€” pipe (|), redirect (>), chain (&&, ||, ;) blocked by default in exec
  • Exec argument blocklist โ€” dangerous flags blocked per command: find -exec, awk system(), tar --to-command, git clone/push, sed -i, xargs -I
  • Token security โ€” JWT with kid key rotation, jti revocation, PBKDF2-200K password hashing
  • Login lockout โ€” persistent DB-backed brute-force protection with auto-cleanup
  • Audit trail โ€” append-only checkpoint log with automated cron (every 6 hours) + cleanup (30 days)
  • Rate limiting โ€” in-memory per-IP rate limiter (60 req/min) for API routes
  • WebSocket origin validation โ€” prevents cross-site WebSocket hijacking
  • CSP-compatible UI โ€” no inline scripts or event handlers; external app.js with ETag caching; optional strict CSP via SALMALM_CSP_NONCE=1
  • Exec resource limits โ€” foreground exec: CPU timeout+5s, 1GB RAM, 100 fd, 50MB fsize (Linux/macOS)
  • Tool timeouts โ€” per-tool wall-clock limits (exec 120s, browser 90s, default 60s)
  • Tool result truncation โ€” per-tool output limits (exec 20K, browser 10K, HTTP 15K chars)
  • Secret isolation โ€” API keys, tokens, and credentials are stripped from subprocess environments (exec, python_eval, background sessions). Tools cannot access secrets via echo $OPENAI_API_KEY or os.environ
  • Output redaction โ€” tool outputs are scanned for patterns matching API keys (sk-, ghp_, pypi-, AKIA, etc.) and automatically replaced with [REDACTED] before reaching the LLM
  • python_eval sandbox โ€” blocks import os/sys/subprocess, vault/crypto access, environ reads, credential file paths, dunder introspection, and network imports. Runs in isolated subprocess with resource limits
  • Per-tool secret scoping โ€” each tool accesses only its own required credentials via hardcoded vault.get('specific_key') calls. No tool has access to the full vault. The LLM cannot read arbitrary vault entries
  • SQLite hardening โ€” WAL journal mode + 5s busy_timeout (prevents "database is locked")
  • 51 security regression tests โ€” SSRF bypass, header injection, exec bypass, tool tiers, route policies, secret isolation, output redaction

Threat model: SalmAlm is a local single-user tool. The vault provides at-rest encryption for API keys and private conversations using PBKDF2-HMAC-SHA256 (200K iterations) key derivation from a user-entered master password. The password is held in memory only while the process runs and is never written to disk. For localhost convenience, SALMALM_VAULT_KEY env var can skip the unlock prompt โ€” this is a deliberate UX trade-off documented in SECURITY.md, not a security recommendation for exposed deployments. If you bind to 0.0.0.0, set a strong vault password and do not use the env var.

See SECURITY.md for full details.


๐Ÿ”‘ Google OAuth Setup (Gmail & Calendar)

SalmAlm can read/send Gmail and manage Google Calendar via OAuth 2.0.

1. Create OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a project (or select an existing one)
  3. Enable APIs: Go to APIs & Services โ†’ Library and enable:
    • Gmail API
    • Google Calendar API
  4. Create OAuth client: Go to Credentials โ†’ Create Credentials โ†’ OAuth client ID
    • Application type: Web application
    • Authorized redirect URI: http://localhost:18800/api/google/callback
    • (Replace 18800 with your SALMALM_PORT if changed)
  5. Copy the Client ID and Client Secret

2. Store Credentials in SalmAlm

Open the web UI โ†’ Settings โ†’ Vault, and save:

Key Value
google_client_id your-client-id.apps.googleusercontent.com
google_client_secret GOCSPX-your-secret

Or via slash command:

/vault set google_client_id your-client-id
/vault set google_client_secret your-secret

3. Authorize

Run /oauth in the chat or go to Settings โ†’ OAuth Auth. Click the Google sign-in link โ€” you'll be redirected to Google's consent screen, then back to SalmAlm.

Note: If your Google Cloud app is in "Testing" mode, you must add your Google account as a test user under OAuth consent screen โ†’ Test users in the Cloud Console. Otherwise Google will block the authorization.

4. Use It

Once connected, SalmAlm tools like gmail_read, gmail_send, calendar_list, and calendar_create become fully functional. Just ask naturally:

  • "Check my unread emails"
  • "Schedule a meeting tomorrow at 3pm"

๐Ÿ”ง Configuration

# Server
SALMALM_PORT=18800         # Web server port
SALMALM_BIND=127.0.0.1    # Bind address (default: loopback only)
SALMALM_WS_PORT=18801     # WebSocket port
SALMALM_HOME=~/SalmAlm    # Data directory (DB, vault, logs, memory)

# AI
SALMALM_LLM_TIMEOUT=30    # LLM request timeout (seconds)
SALMALM_COST_CAP=0        # Monthly cost cap (0=unlimited)
SALMALM_REFLECT=0          # Disable self-reflection pass (saves cost/latency)

# Security
SALMALM_VAULT_PW=...         # Auto-unlock vault on start
SALMALM_ALLOW_SHELL=1        # Enable shell operators in exec
SALMALM_ALLOW_HOME_READ=1    # Allow file read outside workspace
SALMALM_VAULT_FALLBACK=1     # Allow HMAC-CTR vault without cryptography
SALMALM_HEADER_PERMISSIVE=1  # HTTP headers: blocklist mode instead of allowlist
SALMALM_CSP_NONCE=1          # Strict CSP with nonce-based script-src
SALMALM_OPEN_BROWSER=1       # Auto-open browser on server start

# Mesh
SALMALM_MESH_SECRET=...   # HMAC secret for mesh peer authentication

All configuration is also available through the web UI.


๐Ÿ—๏ธ Architecture

Browser โ”€โ”€WebSocketโ”€โ”€โ–บ SalmAlm โ”€โ”€โ–บ Anthropic / OpenAI / Google / xAI / Ollama
   โ”‚                     โ”‚
   โ””โ”€โ”€HTTP/SSEโ”€โ”€โ–บ       โ”œโ”€โ”€ SQLite (sessions, usage, memory, audit)
                         โ”œโ”€โ”€ Model Selection (complexity-based routing)
Telegram โ”€โ”€โ–บ             โ”œโ”€โ”€ Tool Registry (62 tools)
Discord  โ”€โ”€โ–บ             โ”œโ”€โ”€ Cron Scheduler + Audit Cron
                         โ”œโ”€โ”€ Sub-Agent Manager (spawn/steer/collect)
Mesh Peers โ”€โ”€โ–บ           โ”œโ”€โ”€ Message Queue (offline + retry + dead letter)
                         โ”œโ”€โ”€ RAG Engine (TF-IDF + cosine similarity)
                         โ”œโ”€โ”€ OS-native Sandbox (bwrap/unshare/rlimit)
                         โ”œโ”€โ”€ Canvas Server (:18803)
                         โ”œโ”€โ”€ Security Middleware (auth/audit/rate/CSRF per route)
                         โ”œโ”€โ”€ Plugin System
                         โ””โ”€โ”€ Vault (PBKDF2 encrypted)
  • 231 modules, 45K+ lines, 82 test files, 1,710 tests
  • Pure Python 3.10+ stdlib โ€” no frameworks, no heavy dependencies
  • Route-table architecture (59 GET + 63 POST registered handlers)
  • Default bind 127.0.0.1 โ€” explicit opt-in for network exposure
  • Runtime data under ~/SalmAlm (configurable via SALMALM_HOME)
  • Cost estimation unified in core/cost.py with per-model pricing
  • Slash commands extracted to core/slash_commands.py (engine.py: 2007โ†’1221 lines)
  • Model selection extracted to core/model_selection.py
  • Web UI JS extracted to external static/app.js (index.html: 3016โ†’661 lines)

Version Management

# Bump version across all source files (pyproject.toml + __init__.py)
python scripts/bump_version.py 0.17.0

# CI automatically checks version consistency

๐Ÿณ Docker (Optional)

git clone https://github.com/hyunjun6928-netizen/salmalm.git
cd salmalm
docker compose up -d

๐Ÿ”Œ Plugins

Drop a .py file in the plugins/ directory โ€” auto-discovered on startup:

# plugins/my_plugin.py
TOOLS = [{
    'name': 'my_tool',
    'description': 'Says hello',
    'input_schema': {'type': 'object', 'properties': {'name': {'type': 'string'}}}
}]

def handle_my_tool(args):
    return f"Hello, {args.get('name', 'world')}!"

๐Ÿค Contributing

See CONTRIBUTING.md for full guide including test execution, code style, and architecture overview.

git clone https://github.com/hyunjun6928-netizen/salmalm.git
cd salmalm
pip install -e ".[dev]"

# Run tests (per-file, CI-style)
for f in tests/test_*.py; do python -m pytest "$f" -q --timeout=30; done

๐Ÿ“„ License

MIT


SalmAlm = ์‚ถ(Life) + ์•Ž(Knowledge)

Your life, understood by AI.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

salmalm-0.18.27.tar.gz (694.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

salmalm-0.18.27-py3-none-any.whl (657.4 kB view details)

Uploaded Python 3

File details

Details for the file salmalm-0.18.27.tar.gz.

File metadata

  • Download URL: salmalm-0.18.27.tar.gz
  • Upload date:
  • Size: 694.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for salmalm-0.18.27.tar.gz
Algorithm Hash digest
SHA256 83c8f02dcce5f347e4a5afab4387220aed7542b42a0c8e85f4e4f3bd16a72030
MD5 e7e1b1b5d5be3b6a776979107ed49998
BLAKE2b-256 5a94aa736e5da8ea359072b557bc8f48c72ea25f5a1e5028ea1953489fba0568

See more details on using hashes here.

File details

Details for the file salmalm-0.18.27-py3-none-any.whl.

File metadata

  • Download URL: salmalm-0.18.27-py3-none-any.whl
  • Upload date:
  • Size: 657.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for salmalm-0.18.27-py3-none-any.whl
Algorithm Hash digest
SHA256 13b460f51c0d310f3e0df0a6c6bf54c8087cb1f29ffb71e0f05409795608b757
MD5 138c736f458ba783ea13733e63b49ec3
BLAKE2b-256 93ad7ca8bfdacd28b313f8d9d24dc66030ba7aba9dfad066203a92625095bb77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page