Illia Polosukhin 7fb41555a9 ci(gateway): enforce platform/feature boundaries — ironclaw#2599 stage 5 (#2647)
* refactor(gateway): relocate auth / sse / ws into platform/ — ironclaw#2599 stage 3

Third increment of the ironclaw#2599 platform/feature split (follow-up
to #2628 and #2643). Moves the three transport / framing modules into
the platform/ subtree so the platform layer now contains the full set
of cross-cutting infrastructure (state, router, static_files, auth,
sse, ws).

Changes:

- src/channels/web/auth.rs  -> src/channels/web/platform/auth.rs
- src/channels/web/sse.rs   -> src/channels/web/platform/sse.rs
- src/channels/web/ws.rs    -> src/channels/web/platform/ws.rs
- platform/mod.rs declares the three new submodules.
- channels/web/mod.rs adds backward-compat re-exports
  (`pub use platform::{auth, sse, ws};`) so every existing
  `crate::channels::web::{auth,sse,ws}::...` call site - roughly 40
  files across handlers, tests, integration tests, and sibling
  modules - continues to resolve without edits. Follow-up PRs will
  migrate call sites to the canonical `platform::` path incrementally.
- platform/mod.rs doc comment now describes the platform layer as
  having auth / SSE / WS (no longer "in later stages of #2599").
- CLAUDE.md file map points at the new paths and notes the re-exports.

Pure move + re-export. No behavior change. Module contents are
byte-identical to pre-move.

Verified: cargo fmt --all; cargo clippy --all --benches --tests
--examples --all-features clean; python3 scripts/check_no_panics.py
clean; cargo check --all-features --all-targets clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(gateway): extract OAuth / relay callbacks into features/oauth/ — ironclaw#2599 stage 4a

Fourth increment of the ironclaw#2599 platform/feature split. Opens
the `features/` subtree with the OAuth feature slice — the first
vertical slice to move out of server.rs into its own module under
the ironclaw#2599 target layout.

Slice contents:

- `features/oauth/mod.rs` owns the three public gateway routes
  that receive OAuth-style callbacks:
  * `oauth_callback_handler` — generic OAuth callback for
    installable extensions (CSRF lookup, token exchange, storage,
    optional auto-activation).
  * `relay_events_handler` — HMAC-signed webhook from channel-relay.
  * `slack_relay_oauth_callback_handler` — Slack-specific relay
    completion flow.
- Slice-private helpers `oauth_error_page` and
  `redact_oauth_state_for_logs` move with the slice (they have no
  other callers).

Wiring:

- `platform/router.rs` imports the three handlers from
  `features::oauth` instead of `server`; no route-table change.
- `channels/web/mod.rs` registers `pub(crate) mod features;`.
- `server.rs` loses the three handlers and their helpers, plus the
  imports they owned (`Sha256`, `Digest`, `HeaderMap`,
  `DEFAULT_RELAY_NAME`, `extension_name_candidates`,
  `SecretConsumeResult`). The test module re-imports the ones it
  still uses for the integration-level OAuth callback tests.

Pure move. No behavior change. Each handler body is byte-identical
to its pre-move counterpart. Every test in `server.rs` that exercises
the OAuth callbacks (`test_oauth_callback_missing_params`, etc.)
continues to pass against the re-imported handlers.

Stats: server.rs 6973 → 6248 lines (−725); new `features/oauth/mod.rs`
is 775 lines; new `features/mod.rs` 14 lines. The +30 delta is
comment headers documenting the slice boundary.

Verified: `cargo fmt --all`;
`cargo clippy --all --benches --tests --examples --all-features`
clean; `python3 scripts/check_no_panics.py` clean;
`cargo test --lib` 5069 passed (one more than stage 3 — the new
`css_handler_returns_base_in_multi_tenant_mode` test from staging
lands green), same 2 pre-existing failures carried over (fixture
and test-infra issues unrelated to gateway layout).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci(gateway): enforce platform/feature boundaries — ironclaw#2599 stage 5

Adds `scripts/check_gateway_boundaries.py` and wires it into the
`code_style` CI workflow as a required check. The script enforces the
ironclaw#2599 layering rule: every file under `src/channels/web/platform/`
except `router.rs` must not import from `handlers/` or `features/`.

How it works:

- Walks `src/channels/web/platform/*.rs`, skipping `router.rs` (the
  intentional composition point) and test modules.
- Strips line comments, block comments, and string / raw-string / char
  literals so references inside docstrings and explanatory text don't
  trigger false positives.
- Matches six forbidden import shapes:
  `crate::channels::web::{handlers,features}::`,
  `super::{handlers,features}::`,
  `super::super::{handlers,features}::`.
- Prints diagnostics with file:line and the matched pattern for every
  violation; exits non-zero on any.
- Carries unit tests behind a `test` subcommand
  (`python3 scripts/check_gateway_boundaries.py test`) that the CI
  job runs alongside the check itself.

Simultaneous fix: one pre-existing back-edge that the check surfaced
was the OIDC `check_email_domain()` helper living in
`handlers/auth.rs` but called from `platform/auth.rs`. The helper is
platform-level (it gates JWT validation before any handler runs), so
it moves into `platform::auth` along with its five unit tests; the
handler call site in `handlers::auth::handle_callback` now imports
from the new home. No behavior change.

The second pre-existing back-edge is the frontend bundle assembly
path: `platform/static_files::build_frontend_html` calls
`read_layout_config` and `load_resolved_widgets`, both still in
`handlers/frontend.rs`. Migrating them requires also moving
`read_widget_manifest` and the widget-size constants, which touches
`load_widget_manifests` (used by `/api/frontend/widgets` and the
engine-v2 widget endpoint). That's a separate focused PR — tracked
via a narrow allowlist entry in the script with a follow-up comment.
The allowlist is explicitly documented as "must not grow without
reviewer sign-off".

CLAUDE.md's "Platform vs. feature layering" section now names the
script as the enforcement point.

Verified: `python3 scripts/check_gateway_boundaries.py test` — 9
tests pass; `python3 scripts/check_gateway_boundaries.py` — clean;
`cargo fmt --all`; `cargo clippy --all --benches --tests --examples
--all-features` clean; `python3 scripts/check_no_panics.py` clean;
`cargo test --lib channels::web` — 425 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci(gateway): close boundary-checker bypasses — PR #2647 review

Four issues raised on PR #2647's review are addressed:

- Grouped `use crate::channels::web::{ handlers::... }` imports escape
  the per-line scan because the forbidden segment lands on a
  continuation line. Adds a multiline GROUPED_FORBIDDEN_PATTERN that
  matches across newlines and reports the line where `handlers::`,
  `features::`, or `server::` actually appears.
- `use crate::channels::web::server::...` routes through the
  `server.rs` compatibility shim and still creates a platform →
  feature back-edge. Adds `server::` (and its `super::` variants) to
  FORBIDDEN_PATTERNS. Existing pre-existing shim usage in
  `platform/ws.rs` is captured as a tracked allowlist entry — the
  allowlist shrinks as individual types migrate out of `server.rs`.
- `#[cfg(test)] mod ...` and `mod tests { ... }` bodies are now
  actually blanked before pattern matching, matching the docstring's
  stated exemption. Caller-level regression tests in platform files
  can import handler/feature modules without tripping the check.
- `gateway-boundaries` is no longer gated solely on `has_code`. A new
  `has_boundary_check` output on the `changes` job fires when the
  checker script or this workflow itself changes, so PRs that only
  edit `scripts/check_gateway_boundaries.py` or
  `.github/workflows/code_style.yml` still run the guardrail.

Also picks up a small perf nit: `text.splitlines()` is now computed
once outside the loop instead of per-violation.

Regression tests cover each case (grouped crate-web import, grouped
super import, server-shim back-edge, cfg(test)/mod tests skip, and a
sanity check that the test-module skip doesn't blanket-ignore the
rest of the file).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci(gateway): brace-aware grouped scan + narrower ws.rs allowlist — PR #2647 Copilot review

Two issues raised by Copilot on the round-1 fixes:

- `GROUPED_FORBIDDEN_PATTERN` used `[^{}]*?` and so could not match
  grouped imports that contain *nested* braces — e.g.
  `use crate::channels::web::{ platform::{state::GatewayState},
  handlers::auth::login_handler };` produced zero violations even
  though the forbidden segment is plainly inside the web::{...}
  group. Replaced the regex with a depth-tracking walk: find each
  `crate::channels::web::{` / `super::{` / `super::super::{` header,
  find the matching `}` by counting braces (`{` / `}` only; string
  and comment contents are already blanked), then scan the body for
  `(handlers|features|server)::`. Report line numbers off absolute
  offsets so the reported line is where the forbidden segment lives,
  not where the header's `{` is.

- `ws.rs`'s allowlist entry whitelisted the whole
  `crate::channels::web::server::` prefix, which would let any *new*
  accidental server-shim import in ws.rs silently pass. Narrowed to
  seven per-symbol entries covering the current pre-existing uses
  (GatewayState, PerUserRateLimiter, RateLimiter,
  ActiveConfigSnapshot, images_to_attachments, and the two
  handle_legacy_auth_* helpers). Future accidental shim imports fail
  the check and require explicit reviewer sign-off to add.

Added `test_detects_nested_brace_grouped_import` as the regression
test for the brace-aware scanner.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 19:18:56 +09:00
2026-02-04 22:09:52 -08:00
2026-02-22 19:08:43 +00:00
2026-02-22 19:08:43 +00:00
2026-02-21 15:14:57 -07:00
2026-04-09 14:18:30 +02:00
2026-04-09 14:18:30 +02:00
2026-04-09 14:18:30 +02:00
2026-04-09 14:18:30 +02:00

IronClaw

IronClaw

Your secure personal AI assistant, always on your side

License: MIT OR Apache-2.0 Telegram: @ironclawAI Reddit: r/ironclawAI gitcgr

English | 简体中文 | Русский | 日本語 | 한국어

PhilosophyFeaturesInstallationConfigurationSecurityArchitecture


Philosophy

IronClaw is built on a simple principle: your AI assistant should work for you, not against you.

In a world where AI systems are increasingly opaque about data handling and aligned with corporate interests, IronClaw takes a different approach:

  • Your data stays yours - All information is stored locally, encrypted, and never leaves your control
  • Transparency by design - Open source, auditable, no hidden telemetry or data harvesting
  • Self-expanding capabilities - Build new tools on the fly without waiting for vendor updates
  • Defense in depth - Multiple security layers protect against prompt injection and data exfiltration

IronClaw is the AI assistant you can actually trust with your personal and professional life.

Features

Security First

  • WASM Sandbox - Untrusted tools run in isolated WebAssembly containers with capability-based permissions
  • Credential Protection - Secrets are never exposed to tools; injected at the host boundary with leak detection
  • Prompt Injection Defense - Pattern detection, content sanitization, and policy enforcement
  • Endpoint Allowlisting - HTTP requests only to explicitly approved hosts and paths

Always Available

  • Multi-channel - REPL, HTTP webhooks, WASM channels (Telegram, Slack), and web gateway
  • Docker Sandbox - Isolated container execution with per-job tokens and orchestrator/worker pattern
  • Web Gateway - Browser UI with real-time SSE/WebSocket streaming
  • Routines - Cron schedules, event triggers, webhook handlers for background automation
  • Heartbeat System - Proactive background execution for monitoring and maintenance tasks
  • Parallel Jobs - Handle multiple requests concurrently with isolated contexts
  • Self-repair - Automatic detection and recovery of stuck operations

Self-Expanding

  • Dynamic Tool Building - Describe what you need, and IronClaw builds it as a WASM tool
  • MCP Protocol - Connect to Model Context Protocol servers for additional capabilities
  • Plugin Architecture - Drop in new WASM tools and channels without restarting

Persistent Memory

  • Hybrid Search - Full-text + vector search using Reciprocal Rank Fusion
  • Workspace Filesystem - Flexible path-based storage for notes, logs, and context
  • Identity Files - Maintain consistent personality and preferences across sessions

Installation

Prerequisites

  • Rust 1.85+
  • PostgreSQL 15+ with pgvector extension
  • NEAR AI account (authentication handled via setup wizard)

Download or Build

Visit Releases page to see the latest updates.

Install via Windows Installer (Windows)

Download the Windows Installer and run it.

Install via powershell script (Windows)
irm https://github.com/nearai/ironclaw/releases/latest/download/ironclaw-installer.ps1 | iex
Install via shell script (macOS, Linux, Windows/WSL)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/nearai/ironclaw/releases/latest/download/ironclaw-installer.sh | sh
Install via Homebrew (macOS/Linux)
brew install ironclaw
Compile the source code (Cargo on Windows, Linux, macOS)

Install it with cargo, just make sure you have Rust installed on your computer.

# Clone the repository
git clone https://github.com/nearai/ironclaw.git
cd ironclaw

# Build
cargo build --release

# Run tests
cargo test

For full release (after modifying channel sources), run ./scripts/build-all.sh to rebuild channels first.

Database Setup

# Create database
createdb ironclaw

# Enable pgvector
psql ironclaw -c "CREATE EXTENSION IF NOT EXISTS vector;"

Configuration

Run the setup wizard to configure IronClaw:

ironclaw onboard

The wizard handles database connection, NEAR AI authentication (via browser OAuth), and secrets encryption (using your system keychain). Settings are persisted in the connected database; bootstrap variables (e.g. DATABASE_URL, LLM_BACKEND) are written to ~/.ironclaw/.env so they are available before the database connects.

Alternative LLM Providers

IronClaw defaults to NEAR AI but supports many LLM providers out of the box. Built-in providers include Anthropic, OpenAI, GitHub Copilot, Google Gemini, MiniMax, Mistral, and Ollama (local). OpenAI-compatible services like OpenRouter (300+ models), Together AI, Fireworks AI, and self-hosted servers (vLLM, LiteLLM) are also supported.

Select your provider in the wizard, or set environment variables directly:

# Example: MiniMax (built-in, 204K context)
LLM_BACKEND=minimax
MINIMAX_API_KEY=...

# Example: OpenAI-compatible endpoint
LLM_BACKEND=openai_compatible
LLM_BASE_URL=https://openrouter.ai/api/v1
LLM_API_KEY=sk-or-...
LLM_MODEL=anthropic/claude-sonnet-4

See docs/capabilities/llm-providers.md for a full provider guide.

Security

IronClaw implements defense in depth to protect your data and prevent misuse.

WASM Sandbox

All untrusted tools run in isolated WebAssembly containers:

  • Capability-based permissions - Explicit opt-in for HTTP, secrets, tool invocation
  • Endpoint allowlisting - HTTP requests only to approved hosts/paths
  • Credential injection - Secrets injected at host boundary, never exposed to WASM code
  • Leak detection - Scans requests and responses for secret exfiltration attempts
  • Rate limiting - Per-tool request limits to prevent abuse
  • Resource limits - Memory, CPU, and execution time constraints
WASM ──► Allowlist ──► Leak Scan ──► Credential ──► Execute ──► Leak Scan ──► WASM
         Validator     (request)     Injector       Request     (response)

Prompt Injection Defense

External content passes through multiple security layers:

  • Pattern-based detection of injection attempts
  • Content sanitization and escaping
  • Policy rules with severity levels (Block/Warn/Review/Sanitize)
  • Tool output wrapping for safe LLM context injection

Data Protection

  • All data stored locally in your PostgreSQL database
  • Secrets encrypted with AES-256-GCM
  • No telemetry, analytics, or data sharing
  • Full audit log of all tool executions

Architecture

┌────────────────────────────────────────────────────────────────┐
│                          Channels                              │
│  ┌──────┐  ┌──────┐   ┌─────────────┐  ┌─────────────┐         │
│  │ REPL │  │ HTTP │   │WASM Channels│  │ Web Gateway │         │
│  └──┬───┘  └──┬───┘   └──────┬──────┘  │ (SSE + WS)  │         │
│     │         │              │         └──────┬──────┘         │
│     └─────────┴──────────────┴────────────────┘                │
│                              │                                 │
│                    ┌─────────▼─────────┐                       │
│                    │    Agent Loop     │  Intent routing       │
│                    └────┬──────────┬───┘                       │
│                         │          │                           │
│              ┌──────────▼────┐  ┌──▼───────────────┐           │
│              │  Scheduler    │  │ Routines Engine  │           │
│              │(parallel jobs)│  │(cron, event, wh) │           │
│              └──────┬────────┘  └────────┬─────────┘           │
│                     │                    │                     │
│       ┌─────────────┼────────────────────┘                     │
│       │             │                                          │
│   ┌───▼─────┐  ┌────▼────────────────┐                         │
│   │ Local   │  │    Orchestrator     │                         │
│   │Workers  │  │  ┌───────────────┐  │                         │
│   │(in-proc)│  │  │ Docker Sandbox│  │                         │
│   └───┬─────┘  │  │   Containers  │  │                         │
│       │        │  │ ┌───────────┐ │  │                         │
│       │        │  │ │Worker / CC│ │  │                         │
│       │        │  │ └───────────┘ │  │                         │
│       │        │  └───────────────┘  │                         │
│       │        └─────────┬───────────┘                         │
│       └──────────────────┤                                     │
│                          │                                     │
│              ┌───────────▼──────────┐                          │
│              │    Tool Registry     │                          │
│              │  Built-in, MCP, WASM │                          │
│              └──────────────────────┘                          │
└────────────────────────────────────────────────────────────────┘

Core Components

Component Purpose
Agent Loop Main message handling and job coordination
Router Classifies user intent (command, query, task)
Scheduler Manages parallel job execution with priorities
Worker Executes jobs with LLM reasoning and tool calls
Orchestrator Container lifecycle, LLM proxying, per-job auth
Web Gateway Browser UI with chat, memory, jobs, logs, extensions, routines
Routines Engine Scheduled (cron) and reactive (event, webhook) background tasks
Workspace Persistent memory with hybrid search
Safety Layer Prompt injection defense and content sanitization

Usage

# First-time setup (configures database, auth, etc.)
ironclaw onboard

# Start interactive REPL
cargo run

# With debug logging
RUST_LOG=ironclaw=debug cargo run

Development

# Format code
cargo fmt

# Lint
cargo clippy --all --benches --tests --examples --all-features

# Run tests
createdb ironclaw_test
cargo test

# Run specific test
cargo test test_name
  • Channels: See docs/channels/overview.mdx for setup of Telegram, Discord, and other channels.
  • Changing channel sources: Run ./channels-src/telegram/build.sh before cargo build so the updated WASM is bundled.

OpenClaw Heritage

IronClaw is a Rust reimplementation inspired by OpenClaw. See FEATURE_PARITY.md for the complete tracking matrix.

Key differences:

  • Rust vs TypeScript - Native performance, memory safety, single binary
  • WASM sandbox vs Docker - Lightweight, capability-based security
  • PostgreSQL vs SQLite - Production-ready persistence
  • Security-first design - Multiple defense layers, credential protection

License

Licensed under either of:

at your option.

Description
IronClaw is OpenClaw inspired implementation in Rust focused on privacy and security IronClaw 基于一个简单的原则:你的 AI 助手应该为你服务,而不是与你为敌。
Readme 1.8 GiB
Languages
Rust 86%
Python 7.5%
JavaScript 3.4%
Shell 1.9%
CSS 0.9%
Other 0.2%