Commit Graph
85 Commits
Author SHA1 Message Date
a35db4d32d feat: Add Google Suite & Telegram WASM tools (#9)
* Add Google Calendar and Gmail WASM tools, and /add-tool skill

Scaffold two new WASM tools that share a single Google OAuth token:
- google-calendar: list/get/create/update/delete calendar events
- gmail: list/search/get/send/draft/reply/trash emails

Both tools use the sandboxed WIT interface with strict HTTP allowlists,
credential injection, and rate limiting. OAuth config requests only
the minimum scopes needed (calendar.events, gmail.modify, gmail.compose).

Also adds the /add-tool skill for scaffolding future WASM or built-in
tools with all boilerplate wired up.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Document WASM vs MCP server decision guide in CLAUDE.md

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Add Google Drive WASM tool with full file and sharing management

Supports 12 actions: list/get/download/upload/update files, create
folders, delete/trash, share/list/remove permissions, and list shared
drives. Works with both personal and organizational drives via the
corpora parameter. Uses shared google_oauth_token for auth.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Add Google Sheets, Docs, and Slides WASM tools

Three new Google Workspace tools sharing google_oauth_token:
- Sheets: create spreadsheets, read/write/append values, manage sheets, format cells
- Docs: create/read/edit documents, text formatting, paragraphs, tables, lists
- Slides: create/edit presentations, shapes, images, text formatting, thumbnails, templates

Also adds tools-src/TOOLS.md tracking implementation status.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Add Telegram WASM tool with direct MTProto over HTTPS

Replace TDLight Docker dependency with pure-Rust grammers crates
for direct encrypted MTProto communication to Telegram's web
transport endpoints. No middleware, no Docker needed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Gitignore Cargo.lock files in WASM tools

Library crates should not commit lock files. Consolidate per-tool
.gitignore into a single one at wasm-tools/ level.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Flatten tools-src/wasm-tools/ into tools-src/

All tools are WASM, the extra nesting added no value. Moves all tool
crates up one level, updates WIT paths and documentation references.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Fix Slack tool: add OAuth auth, URL encoding, pin wit-bindgen

- Add OAuth 2.0 auth section to Slack capabilities with proper scopes
  and manual fallback instructions
- URL-encode query parameters in GET requests to prevent injection
- Remove dead SlackApiError struct
- Pin wit-bindgen to =0.36 across all WASM tools for Rust 1.86 compat
- Update add-tool template with pinned version

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-02-09 06:16:27 +00:00
e6725eb6d9 feat: Improve CLI (#5)
* Start working on improved CLI

* Add tool result previews, boxed approval card, and polished help screen

REPL iteration 2: styled /help with grouped sections, box-drawing
approval card with colored params, dim separator before responses,
inline tool output previews via new StatusUpdate::ToolResult variant.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
2026-02-09 05:42:41 +00:00
Illia Polosukhin 6bcc168ec5 Adding skills for reusable work 2026-02-06 21:25:14 -08:00
Illia PolosukhinandClaude Opus 4.6 bf3b8b339f Fix MCP tool calls, approval loop, shutdown, and improve web UI
- Fix MCP tool schema deserialization: rename input_schema to match
  protocol's camelCase inputSchema, so models receive actual parameter
  schemas instead of empty defaults
- Fix conversation history: add tool_calls field to ChatMessage and
  include assistant message with tool_calls before tool results, as
  required by OpenAI-compatible APIs
- Fix approval loop: pass resume_after_tool flag to run_agentic_loop
  so the "force tool use" heuristic doesn't re-trigger after approval
- Fix shutdown: add Submission::Quit, Ctrl+C signal handler, and
  graceful shutdown flow
- Fix MCP activate button: auto-attempt auth flow when activation
  fails due to missing authentication
- Add inline approval cards in chat via SSE ApprovalNeeded events
- Add markdown rendering in chat (marked.js) with proper streaming
- Add structured fields to log entries (key=value pairs from tracing)
- Collapse log entries to single line with click-to-expand

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 18:04:44 -08:00
Illia PolosukhinandClaude Opus 4.6 2cdd04a359 Add auth mode, fix MCP token handling, and parallelize startup loading
Auth mode: when a tool requires an API key, the thread enters a special
mode where the next user message is routed directly to the credential
store, bypassing logs, turns, history, and compaction entirely. This
prevents tokens from leaking into debug output or persistent storage.

Fix MCP auth: auth_mcp now actually uses the token parameter (was
ignored as _token) and falls back to manual token entry when OAuth
and DCR are both unsupported.

Parallel loading: WASM tools, WASM channels, and MCP servers now load
concurrently at startup. Within each loader, individual items also
load in parallel (join_all for WASM, JoinSet for MCP servers).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 13:35:17 -08:00
Illia Polosukhin 9b729795fb Merge remote-tracking branch 'origin/main' into ui
# Conflicts:
#	src/channels/mod.rs
#	src/main.rs
2026-02-06 13:22:26 -08:00
Illia Polosukhin a351711312 Adding web UI 2026-02-06 12:11:12 -08:00
Illia PolosukhinandClaude Opus 4.6 f34a80191e Rename examples/ to tools-src/
Update doc references in CLAUDE.md and slack README.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 11:53:09 -08:00
Illia PolosukhinandClaude Opus 4.6 9d156411fc Unify webhook servers into single WebhookServer
Replace the dual-server architecture (HttpChannel + WasmChannelServer both
competing for port 8080) with a single WebhookServer that composes route
fragments from all sources. Channels define routes but never spawn servers.

- Add WebhookServer struct that collects Router fragments and binds one listener
- Extract routes() from HttpChannel, remove server-spawning from start/shutdown
- Delete WasmChannelServer (keep WasmChannelRouter and route builder)
- Rewire main.rs to compose all webhook routes into one server

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 11:12:17 -08:00
Illia PolosukhinandClaude Opus 4.6 8439293df3 Fix WASM channel on-status instantiation failure and HTTP port conflict
Consolidate channel sources into channels-src/ by moving whatsapp from
channels/. Add on_status stubs to Slack and WhatsApp so their WASM
binaries export the function added in the latest WIT. Fix Slack's
emit_message call to pass by reference (API changed). Guard WASM webhook
server startup to skip when the HTTP channel already occupies port 8080.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 10:01:26 -08:00
Illia PolosukhinandClaude Opus 4.6 8be390afab Rename setup CLI command to onboard for compatibility
Serde alias on `onboard_completed` preserves existing settings.json files
that still have the old `setup_completed` key.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 09:56:32 -08:00
Illia PolosukhinandClaude Opus 4.6 4d0fe7d37e Replace TUI (ratatui) with REPL (rustyline + termimad)
Drop the full Ratatui TUI in favor of a lighter REPL channel built on
rustyline (line editing, history, tab-completion) and termimad (inline
markdown rendering). Removes ratatui and crossterm event-stream deps,
adds rustyline and termimad. Simplifies main.rs startup to use the REPL
directly instead of the alternate-screen TUI.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 09:00:32 -08:00
Illia Polosukhin cb987321a9 Merge remote-tracking branch 'origin/main' 2026-02-06 08:53:27 -08:00
Illia PolosukhinandClaude Opus 4.6 a93c7ed893 Fix README drift from codebase reality
Channels listed CLI/Telegram/WhatsApp/Slack but only REPL + HTTP are
built-in (Telegram/Slack are WASM channels, WhatsApp never existed).
Auth section required a manual session token but the actual flow uses
OAuth via `ironclaw setup`. Config pointed at a nonexistent
refinery.toml, used the wrong default model, and the curl example had
the wrong field name. Updated all sections to match the code.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-06 08:51:24 -08:00
Illia PolosukhinandClaude Opus 4.6 3c54e692a5 Split LICENSE into LICENSE-MIT and LICENSE-APACHE per README
The README references LICENSE-MIT and LICENSE-APACHE for the dual
MIT/Apache-2.0 license, matching the Cargo.toml declaration and the
standard Rust convention. Rename the existing MIT file and add the
Apache 2.0 text.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 21:54:50 -08:00
Illia PolosukhinandClaude Opus 4.6 48ab73574e Add owner-only access control for Telegram bot
Restrict the bot so only the configured owner_id can interact with it.
Non-owner messages are silently dropped with a debug log, keeping the
bot invisible to strangers. Owner ID is persisted to workspace storage
in on_start so stateless WASM callbacks can read it.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 21:52:35 -08:00
Illia PolosukhinandClaude Opus 4.6 4f8fd4ad5f Reject workspace paths in write_file, force LLM to use memory_write
write_file now detects workspace files (HEARTBEAT.md, MEMORY.md,
SOUL.md, etc.) and daily/context/ prefixes, returning an error that
tells the LLM to use memory_write with the correct target instead.
This prevents the LLM from writing workspace data to the local
filesystem when it should go to the database.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 20:15:53 -08:00
Illia PolosukhinandClaude Opus 4.6 ae3c86a7ea Add in-chat extension discovery, auth, and activation system
Introduces a unified extension abstraction over MCP servers and WASM tools
with six agent-callable tools (tool_search, tool_install, tool_auth,
tool_activate, tool_list, tool_remove) so users can add capabilities
conversationally without CLI commands.

Includes built-in registry of 11 MCP servers, online discovery via URL
probing and GitHub search, OAuth 2.1 flows for MCP servers, and manual
token auth for WASM tools.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 20:11:29 -08:00
Illia PolosukhinandClaude Opus 4.6 7fcc2279cc Route HEARTBEAT writes to workspace DB and broadcast notifications
- Add dedicated "heartbeat" target in memory_write tool so the LLM
  routes HEARTBEAT.md writes to the database instead of the filesystem
- Update tool description to clarify it's database-backed storage
- Broadcast heartbeat notifications to all channels when no explicit
  notify target is configured, instead of silently logging them

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 20:02:33 -08:00
Illia PolosukhinandClaude Opus 4.6 0ca05e3de3 Seed HEARTBEAT.md on first access and skip effectively-empty checklists
The heartbeat feature was dead on arrival: nothing ever created HEARTBEAT.md,
so the runner silently skipped every cycle. Now the workspace returns an
in-memory seed template when the file doesn't exist in the database (no DB
write), and the runner detects "effectively empty" content (headers, HTML
comments, bare list markers) to avoid wasting LLM API calls on placeholder
templates. The user creates the real DB entry via memory_write when they
actually want periodic checks.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 19:51:59 -08:00
Illia PolosukhinandClaude Opus 4.6 e0016a95e8 Add Telegram typing indicator via WIT on-status callback
Thread message metadata through Channel::send_status so WASM channels
can route status updates (like typing indicators) to the correct chat.
The WasmChannel spawns a background task that repeats on_status every
4 seconds to keep Telegram's typing bubble alive until the response
is sent.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 19:44:43 -08:00
Illia PolosukhinandClaude Opus 4.6 f3c85f57fc Add proactivity features: memory CLI, session pruning, self-repair notifications, slash commands, status diagnostics, context warnings
Closes the proactivity gap with six features:

- Memory CLI (`ironclaw memory search/read/write/tree/status`) for direct workspace access without starting the full agent
- Session pruning background task that evicts idle sessions (configurable TTL, default 7 days)
- Self-repair notifications broadcast recovery results through channel manager instead of silent logging
- `/heartbeat`, `/summarize`, `/suggest` slash commands for manual heartbeat trigger, thread summarization, and next-step suggestions
- `ironclaw status` diagnostics command checking DB, session, secrets, embeddings, WASM tools, channels, heartbeat, and MCP servers
- Context pressure warning that notifies users before auto-compaction fires

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-05 19:28:13 -08:00
Illia Polosukhin 1c9f9db420 Merge remote-tracking branch 'origin/main' 2026-02-05 17:52:10 -08:00
Illia PolosukhinandClaude Opus 4.5 974bc8d407 Add hosted MCP server support with OAuth 2.1 and token refresh
Enables connecting to official MCP servers (like Notion) instead of
building custom WASM tools. Uses OAuth 2.1 with PKCE and supports
Dynamic Client Registration for zero-config authentication.

Key features:
- OAuth 2.1 flow with PKCE for secure browser-based auth
- Dynamic Client Registration (DCR) for servers without pre-configured clients
- Automatic token refresh on 401 responses
- Session management with Mcp-Session-Id headers
- SSE streaming response handling

New CLI commands:
- `mcp add <name> <url>` - Add an MCP server
- `mcp remove <name>` - Remove an MCP server
- `mcp list` - List configured servers
- `mcp auth <name>` - Authenticate with a server
- `mcp test <name>` - Test connection

Also removes the Notion WASM tool example since it's superseded by the
Notion MCP server which provides 13 official tools.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 17:43:26 -08:00
Illia Polosukhin 3e6dfb8409 Addressing vareity of security issues 2026-02-05 10:40:24 -08:00
Illia Polosukhin 5992e27507 Merge remote-tracking branch 'origin/main' 2026-02-05 09:51:46 -08:00
Illia PolosukhinandClaude Opus 4.5 0ab9643843 Add interactive setup wizard and persistent settings
- Add 7-step setup wizard: database, security, auth, model, embeddings, channels, heartbeat
- Store settings in ~/.ironclaw/settings.json with env var > settings > default priority
- Add OS keychain integration for secrets master key (macOS/Linux)
- Add `ironclaw config` CLI subcommand (list/get/set/reset/path)
- Expand Settings struct with all configuration fields
- Enhanced setup detection to auto-trigger wizard when needed

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 09:50:52 -08:00
Illia Polosukhin 91308ac773 Create notion tool 2026-02-05 09:09:48 -08:00
Illia PolosukhinandClaude Opus 4.5 598dd43b1c Rebrand to IronClaw with security-first mission
Renamed project from "near-agent" to "ironclaw" throughout the codebase.
Updated documentation to emphasize the core philosophy:
- Your data stays yours (local, encrypted, no telemetry)
- Self-expanding capabilities (build tools on the fly)
- Defense in depth (WASM sandbox, prompt injection defense)
- Always on user's side

Key changes:
- Package name: near-agent -> ironclaw
- Config paths: ~/.near-agent/ -> ~/.ironclaw/
- Database name in docs: near_agent -> ironclaw
- CLI binary: near-agent -> ironclaw
- Log filters: RUST_LOG=near_agent -> RUST_LOG=ironclaw
- All user-facing strings (welcome messages, help text, etc.)

Preserved for compatibility:
- HKDF salt "near-agent-secrets-v1" (changing would break existing secrets)
- WIT interface names (near::agent::*)
- NEAR AI provider config (NEARAI_* env vars)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 01:10:40 -08:00
Illia PolosukhinandClaude Opus 4.5 2486065fa7 Fix build_software tool stuck in planning mode loop
The builder would get stuck when the LLM returned JSON specs or planning
text instead of tool calls. The loop would continue for all iterations
without making progress, eventually timing out.

Changes:
- Make initial prompt directive: "Use write_file NOW" instead of passive
  "Start by creating the project structure"
- Add consecutive_text_responses counter to detect stuck state
- Fail fast after 2 consecutive text-only responses with clear error
- Send strong nudge on first text response: "STOP. Call write_file..."
- Reset counter once tools have been executed (completion phase)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 00:59:44 -08:00
Illia Polosukhin 3d37160940 Enable sandbox by default 2026-02-05 00:39:20 -08:00
Illia PolosukhinandClaude Opus 4.5 aec42aceda Fix Telegram Markdown formatting and clarify tool/memory distinctions
- Add escape_telegram_markdown() to handle underscores in tool names
  (e.g., build_software was breaking Telegram's Markdown parser)
- Use Telegram-compatible *bold* syntax instead of **bold**
- Clarify workspace memory vs filesystem tool descriptions to prevent
  LLM from using read_file on memory_tree paths
- Update build_software to strongly prefer Rust WASM for agent tools
- Rewrite WASM tool template to use Component Model with wit_bindgen
  instead of outdated extern "C" approach

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 00:37:19 -08:00
Illia PolosukhinandClaude Opus 4.5 9edc666ee3 Simplify Telegram channel config with host-injected tunnel/webhook settings
The WASM channel no longer needs its own polling_enabled/tunnel_url settings.
Instead, the host injects tunnel_url and webhook_secret into the channel config
at runtime before start() is called.

Changes:
- Add update_config() method to WasmChannel for runtime config injection
- Simplify TelegramConfig to only have bot_username, respond_to_all_group_messages
- Host injects tunnel_url (from Settings) and webhook_secret (from secrets store)
- Channel checks if tunnel_url is present to determine webhook vs polling mode
- Add delete_webhook() for clean transition to polling mode when no tunnel

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-05 00:05:32 -08:00
Illia PolosukhinandClaude Opus 4.5 e6946172f7 Apply Telegram channel learnings to WhatsApp implementation
- Fix metadata flow: store sender_phone for response routing
- Add credential injection in headers (Bearer {WHATSAPP_ACCESS_TOKEN})
- Add secret_validated check for webhook defense in depth
- Add status message filtering to prevent loops
- Add proper WhatsApp API error response parsing
- Create whatsapp.capabilities.json with setup/secrets/rate limits
- Add docs/BUILDING_CHANNELS.md with patterns and examples

Also fix UTF-8 truncation bugs across codebase:
- wrapper.rs: content preview, response body, webhook body logging
- agent_loop.rs: params truncation for approval display
- shell.rs: truncate_for_error() helper

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:32:23 -08:00
Illia Polosukhin ce87ec1dbe Merge remote-tracking branch 'origin/main' 2026-02-04 22:11:37 -08:00
Illia PolosukhinandClaude Opus 4.5 c14911009f Add WhatsApp channel WASM module
Implements the sandboxed-channel WIT interface for WhatsApp Cloud API:
- Webhook verification (GET with hub.mode=subscribe)
- Incoming message handling (POST webhooks)
- Outgoing responses via Graph API
- Parses WhatsApp webhook payload format

Built and tested in Docker sandbox with wasm32-wasip2 target.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:09:53 -08:00
Illia Polosukhin 9d3f993b4e Docker file for sandbox 2026-02-04 22:09:52 -08:00
Illia PolosukhinandClaude Opus 4.5 7baf9e379d Replace hardcoded intent patterns with job tools
Remove the brittle natural language pattern matching from the router
and add job management tools to the normal tool registry instead.

- Add job tools: create_job, list_jobs, job_status, cancel_job
- Router now only handles explicit /commands
- Natural language goes through agentic loop with all tools
- LLM naturally picks appropriate tools based on user intent
- Share ContextManager between job tools and Agent

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:09:52 -08:00
Illia PolosukhinandClaude Opus 4.5 27ffc12f6c Fix router test to match intentional job creation patterns
The test expected "Can you create a website for me?" to route as CreateJob,
but the extract_intent logic intentionally requires explicit job creation
patterns (containing both "create" and "job") to avoid capturing general
conversation as job requests.

Updated test to verify:
- "create job: ..." routes to CreateJob
- Messages with both "create" and "job" route to CreateJob
- General requests without explicit "job" fall through to Chat

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:09:52 -08:00
Illia PolosukhinandClaude Opus 4.5 a39f5aa1a4 Add Docker execution sandbox for secure shell command isolation
Implements a general-purpose Docker sandbox (inspired by Codex) that provides:
- Container isolation for shell commands with ephemeral containers
- HTTP proxy for network access control with domain allowlist
- Credential injection by proxy (secrets never enter containers)
- Three security policies: ReadOnly, WorkspaceWrite, FullAccess
- Resource limits (memory, CPU, timeout enforcement)

Key components:
- SandboxManager: Main entry point coordinating proxy and containers
- NetworkProxy: HTTP proxy validating requests and injecting credentials
- ContainerRunner: Docker lifecycle management via bollard
- DomainAllowlist: Pattern matching for allowed network destinations

The ShellTool now routes commands through the sandbox when enabled,
with automatic fallback to direct execution if Docker is unavailable.

Configuration via SANDBOX_ENABLED, SANDBOX_POLICY, SANDBOX_TIMEOUT_SECS,
SANDBOX_MEMORY_LIMIT_MB, SANDBOX_IMAGE, SANDBOX_EXTRA_DOMAINS env vars.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:09:52 -08:00
Illia Polosukhin 0596a6c847 Webhook and polling integrations for channels 2026-02-04 22:02:13 -08:00
Illia PolosukhinandClaude Opus 4.5 7955c9742e Add Telegram webhook support with credential injection
Enable instant message delivery for Telegram via webhooks instead of polling.

Key changes:
- Add tunnel URL configuration for local development (ngrok, cloudflare)
- Auto-register webhook with Telegram API on startup using setWebhook
- Implement webhook secret validation via X-Telegram-Bot-Api-Secret-Token header
- Add credential injection for bot token via URL placeholder substitution
- Fix metadata preservation in respond() to route replies correctly
- Fix serde flatten with Option<T> issue in capabilities schema parsing

The credential injection pattern replaces {TELEGRAM_BOT_TOKEN} placeholders
in URLs with the actual token from the secrets store, keeping credentials
out of WASM module memory until the HTTP request is made.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 21:19:42 -08:00
Illia PolosukhinandClaude Opus 4.5 4ab20ff939 Move setup wizard credentials to database storage
Changes setup wizard to save channel secrets (Telegram bot token, HTTP
webhook secret) to PostgreSQL via SecretsStore instead of files.

This enables the WASM channel credential injector to find and inject
the secrets properly, since it reads from the database.

Requires:
- DATABASE_URL to be set
- SECRETS_MASTER_KEY (will generate and display if not set)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 09:49:11 -08:00
Illia PolosukhinandClaude Opus 4.5 c7f0e8014d Add interactive setup wizard for first-run configuration
Introduces `near-agent setup` command that guides users through:
- NEAR AI authentication (reuses existing OAuth flow)
- Model selection (fetches from API or shows defaults)
- Channel configuration (HTTP webhook, Telegram)

Features:
- First-run detection: auto-runs wizard if no session exists
- Respects existing settings: shows current model with keep/change option
- Saves channel secrets to ~/.near-agent/secrets/ with 0600 permissions
- Validates Telegram bot tokens via API before saving

Also fixes default NEARAI_BASE_URL to use cloud-api.near.ai (api.near.ai
returns 410 Gone).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 09:42:41 -08:00
Illia PolosukhinandClaude Opus 4.5 1605939e2a Add Telegram Bot API channel as WASM module
Implements a loadable WASM channel for Telegram following the existing
Slack channel pattern:

- Webhook-based message receiving at /webhook/telegram
- Private chat and group chat support (with @mention filtering)
- Reply threading via reply_to_message_id
- User name extraction from Telegram user objects
- Bot token injection by host (never exposed to WASM)

Files:
- channels-src/telegram/src/lib.rs - Main implementation
- channels-src/telegram/Cargo.toml - Dependencies
- channels-src/telegram/telegram.capabilities.json - Permissions
- channels-src/telegram/build.sh - Build script

To use: copy telegram.wasm and telegram.capabilities.json to
~/.near-agent/channels/ and configure telegram_bot_token secret.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 09:16:03 -08:00
Illia PolosukhinandClaude Opus 4.5 be18812376 Add OpenClaw feature parity tracking matrix
Comprehensive comparison of IronClaw vs OpenClaw features to enable
coordinated development. Includes status indicators, priority levels,
owner fields for claiming work, and documented architectural deviations.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 22:06:48 -08:00
Illia PolosukhinandClaude Opus 4.5 7ef6362d83 Add Chat Completions API support and expand REPL debugging
- Add NearAiChatProvider using /v1/chat/completions endpoint with API key auth
- Add NEARAI_API_KEY and NEARAI_API_MODE config options
- Auto-detect API mode from presence of API key
- Keep existing Responses API (NearAiProvider) for session-based auth
- Fix response parsing to accept input_text/output_text/text content types
- Expand REPL with /help, /debug toggle, colored output
- Better tool status display (dots vs verbose based on debug mode)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 21:55:05 -08:00
Illia Polosukhin 74d94d33b0 Implementing channels to be handled in wasm 2026-02-03 14:57:27 -08:00
Illia Polosukhin 2c26ba8431 Support non interactive mode and model selection 2026-02-03 14:47:26 -08:00
Illia PolosukhinandClaude Opus 4.5 2cc9aed364 Implement tool approval, fix tool definition refresh, and wire embeddings
This commit addresses three critical issues from code review:

1. Tool approval enforcement: Tools declaring requires_approval() (shell,
   http, file write/patch, build_software) now gate execution. Adds
   PendingApproval struct, session-scoped auto-approved tools set, and
   approval flow with yes/no/always commands.

2. Tool definition refresh: Tool definitions now refresh each iteration
   in both chat and job loops, so newly built tools become visible
   immediately within the same session.

3. Worker tool call handling: Changed respond() to respond_with_tools()
   when select_tools returns empty, properly executing tool calls instead
   of formatting them as text.

Also includes prior work from the plan:
- Wire embeddings provider (OpenAI + NEAR AI) to workspace
- Load workspace system prompt (identity files) into LLM context
- Route heartbeat notifications through channel manager
- Enable auto-context compaction when threshold exceeded
- Refactor to config structs (AgentDeps, WorkerDeps, LlmCallRecord)
- Fix clippy warnings (saturating_sub, too_many_arguments)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 11:34:10 -08:00
Illia Polosukhin 8af48390a9 Tool use 2026-02-03 10:50:20 -08:00
Illia Polosukhin 7210470544 Wiring more 2026-02-03 10:08:06 -08:00
Illia PolosukhinandClaude Opus 4.5 235f6aae18 Add heartbeat integration, planning phase, and auto-repair
- Add HeartbeatConfig for proactive periodic execution with channel notifications
- Add use_planning option to Worker for ActionPlan generation before tool execution
- Implement tool failure tracking in database (V3 migration)
- Add auto-repair via Builder for broken WASM tools in self_repair.rs
- Record tool failures in Worker for self-repair tracking
- Update .env.example with new configuration options

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 09:32:01 -08:00
Illia Polosukhin 2df4a4f5f0 Login flow 2026-02-03 09:20:26 -08:00
Illia Polosukhin dedda9c51d Extend support for session management 2026-02-03 08:59:59 -08:00
Illia Polosukhin c9ebb117ab Adding builder capability 2026-02-03 08:36:55 -08:00
Illia Polosukhin 343782524f Load tools at launch 2026-02-03 00:48:22 -08:00
Illia PolosukhinandClaude Opus 4.5 575269546b Fix multiline message rendering in TUI
- Switch from List to Paragraph widget for message display
- Split message content by newlines and render each line separately
- Auto-scroll to show most recent messages
- Add empty line between messages for readability
- Wrap long lines properly

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:38:19 -08:00
Illia PolosukhinandClaude Opus 4.5 066df79595 Parse NEAR AI alternative response format with output field
The API returns a different JSON structure with output as a Value.
Added extract_text_from_output() to handle various output formats:
- String: return directly
- Array with text/content fields: extract and join
- Object with text/content/message fields: extract

Both complete() and complete_with_tools() now handle this format.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:29:36 -08:00
Illia PolosukhinandClaude Opus 4.5 635aeb66a7 Handle NEAR AI plain text responses
The API sometimes returns plain text instead of JSON structure.
Now we detect this and extract the text content directly.

- Detect "Unexpected response format" errors with raw text
- Parse as JSON string if quoted, otherwise use raw
- Works for both complete() and complete_with_tools()

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:26:11 -08:00
Illia PolosukhinandClaude Opus 4.5 2b2f0d56c6 Disable mouse capture to allow text selection in TUI
- Remove EnableMouseCapture/DisableMouseCapture from terminal setup
- Users can now select and copy text using normal terminal selection
- We weren't using mouse events anyway

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:24:18 -08:00
Illia PolosukhinandClaude Opus 4.5 cd426b7e9d Add verbose logging to debug empty NEAR AI responses
- Log request body before sending
- Log full response text before parsing
- Log parse errors with full response content
- This helps debug why output array is empty

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:23:33 -08:00
Illia PolosukhinandClaude Opus 4.5 1ae64981d8 Improve NEAR AI response parsing for varying response formats
- Add direct text field support on NearAiOutputItem
- Accept both "output_text" and "text" content types
- Join all content items instead of taking just the first
- Better debug logging showing item.text field

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:18:34 -08:00
Illia PolosukhinandClaude Opus 4.5 42d6e87186 Show status/thinking messages in chat window, debug empty responses
- Add ThinkingMessage variant to AppEvent for chat-visible status
- Add set_thinking() and clear_thinking() to AppState
- Thinking messages show as system messages with spinner indicator
- Auto-clear thinking messages when agent response arrives
- Tool started/completed now shown in chat window
- Add debug logging to NEAR AI provider to diagnose empty responses
- Log raw response output when text extraction returns empty

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:17:40 -08:00
Illia Polosukhin 3d709eb253 Improving slack tool example 2026-02-03 00:16:48 -08:00
Illia PolosukhinandClaude Opus 4.5 11d3e816e5 Add timeout and logging to NEAR AI provider
- Add 2 minute timeout to HTTP client for LLM calls
- Add debug logging for requests and error logging for failures
- Prevents indefinite hangs when NEAR AI is slow or unavailable

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:13:40 -08:00
Illia PolosukhinandClaude Opus 4.5 7f9f0cd21e Add status updates to show agent thinking/processing state
- Add StatusUpdate enum with Thinking, ToolStarted, ToolCompleted, StreamChunk, Status variants
- Add send_status method to Channel trait (default no-op)
- Implement send_status in TuiChannel to show status in UI
- Add send_status to ChannelManager for routing to specific channels
- Update handle_message to send "Processing..." status for Chat/CreateJob
- Update handle_chat to send "Generating response..." and show errors

Now when a user sends a message, they see feedback that the agent is working.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:12:48 -08:00
Illia PolosukhinandClaude Opus 4.5 d1cb748914 Add CLI subcommands for WASM tool management
Introduces a new CLI module with subcommands for managing WASM tools:
- `tool install`: Build and install tools from source or .wasm files
- `tool list`: List installed tools with optional verbose output
- `tool remove`: Remove installed tools
- `tool info`: Show detailed tool information including capabilities

The install command supports building from Cargo source directories using
cargo-component, or installing pre-compiled .wasm files directly. It
auto-detects capabilities JSON sidecar files and validates them before
installation.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-03 00:05:12 -08:00
Illia PolosukhinandClaude Opus 4.5 9232e623e8 Fix TUI shutdown: send /shutdown message and handle in agent loop
When the TUI quits (Ctrl+D twice), it now:
1. Sends a "/shutdown" message through the channel before closing
2. Explicitly drops msg_tx to ensure channel closure

The agent loop now:
1. Returns Option<String> from handle_message (None = shutdown)
2. Handles /quit, /exit, /shutdown commands by returning None
3. Breaks out of the main loop on shutdown signal
4. Lists /quit in help menu

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:59:28 -08:00
Illia PolosukhinandClaude Opus 4.5 b52122a275 Remove SimpleCliChannel, add Ctrl+D twice quit, redirect logs to TUI
- Remove SimpleCliChannel (only TuiChannel remains)
- Add ctrl_d_pending flag to AppState for two-press quit behavior
- Implement Ctrl+D twice to quit (first press shows hint, second quits)
- Add TuiLogWriter with MakeWriter impl for tracing integration
- Create TuiChannel event channel upfront in new() so log_writer() works
- Configure tracing to send logs to TUI status line
- Any key press clears the Ctrl+D pending state

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:54:01 -08:00
Illia PolosukhinandClaude Opus 4.5 4ae59ef52c Fix TuiChannel integration and enable in main.rs
- Store event_tx in Arc<Mutex<>> so respond() can send to TUI
- Fix run_event_loop to take owned receiver
- Switch main.rs from SimpleCliChannel to TuiChannel
- Add proper terminal cleanup on TUI error

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:47:41 -08:00
Illia PolosukhinandClaude Opus 4.5 09032d69cb Integrate Codex patterns: task scheduler, TUI, sessions, compaction
Add Codex-inspired patterns for improved agent architecture:

**Task Scheduler (Phase 1 & 4)**
- New Task enum with Job, ToolExec, Background variants
- TaskHandler trait for custom background tasks
- Scheduler.spawn_subtask() and spawn_batch() for parallel execution
- Worker executes multiple tools in parallel via futures::join_all

**Tool Approval System (Phase 6)**
- Tool.requires_approval() method (default false for sandboxed tools)
- HttpTool marked as requiring approval (external network)
- MCP protocol annotations: destructive_hint, side_effects_hint

**Ratatui TUI CLI (Phase 2)**
- Replace blocking stdin with event-driven TUI
- ChatComposer with history navigation and tab completion
- ApprovalOverlay modal with y/n/a keyboard shortcuts
- Raw mode with proper terminal cleanup

**Session/Turn Model (Phase 3)**
- Session, Thread, Turn structs for conversation tracking
- Submission enum for user input, approvals, undo, interrupt
- UndoManager with checkpoint-based undo/redo

**Context Compaction (Phase 5)**
- ContextMonitor with token estimation and threshold checks
- CompactionStrategy: Summarize, Truncate, MoveToWorkspace
- ContextCompactor writes summaries to workspace daily logs

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:41:57 -08:00
Illia Polosukhin d047c23b2d Adding LICENSE 2026-02-02 23:28:43 -08:00
Illia PolosukhinandClaude Opus 4.5 4b147038db Add README with IronClaw branding
Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:24:17 -08:00
Illia PolosukhinandClaude Opus 4.5 32bfd24154 Add WASM sandbox secure API extension
Extends the WASM sandbox with HTTP API capabilities, secrets management,
tool aliasing, and leak detection. Key security principle: WASM never
sees credentials, injection happens at host boundary.

New modules:
- secrets: AES-256-GCM encrypted storage with HKDF key derivation
- leak_detector: Aho-Corasick + regex pattern matching for secret exfiltration
- capabilities: Extended capability system (HTTP, ToolInvoke, Secrets)
- allowlist: HTTP endpoint validation with glob patterns
- credential_injector: Host-boundary credential injection
- rate_limiter: Sliding window per-tool rate limiting
- storage: WASM binary storage with BLAKE3 integrity verification

Leak detection happens at two points:
1. Before HTTP request (prevents exfiltration via URL/headers/body)
2. After response (prevents exposure in outputs returned to WASM)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 23:22:52 -08:00
Illia PolosukhinandClaude Opus 4.5 45bbfa026d Wire database Store into agent loop
Persist jobs and actions to PostgreSQL using fire-and-forget pattern:
- Scheduler passes store to Worker, persists cancellations
- Worker persists job status changes and tool execution actions
- Agent persists new jobs on creation
- All DB writes use tokio::spawn to avoid blocking execution

Store remains optional to preserve --no-db mode.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 22:53:12 -08:00
Illia Polosukhin aea3f47f8b Implementing WASM runtime 2026-02-02 22:47:02 -08:00
Illia PolosukhinandClaude Opus 4.5 383fb21c07 Add workspace integration tests
- Create tests/workspace_integration.rs with 10 database tests
- Export MockEmbeddings for use in integration tests
- Tests cover: read/write, append, nested paths, delete, memory ops,
  daily log, FTS search, hybrid search, list_all, system_prompt

Requires: DATABASE_URL=postgres://localhost/near_agent_test

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 22:01:09 -08:00
Illia PolosukhinandClaude Opus 4.5 b316a7f4f5 Compact memory_tree output format
- Directories indicated by trailing `/` instead of is_directory field
- Files are plain strings, dirs with children are objects
- Remove redundant name/path (just show name in tree)
- Remove preview and updated_at (use memory_read if needed)
- Output is just the tree array, no wrapper object

Example: ["MEMORY.md", {"daily/": ["2024-01-15.md"]}, "projects/"]

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:49:32 -08:00
Illia PolosukhinandClaude Opus 4.5 3f7624eefc Replace memory_list with memory_tree tool
The memory_tree tool provides a hierarchical view of the workspace
with configurable depth (default 1). This is more useful for
exploring nested directory structures.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:44:07 -08:00
Illia PolosukhinandClaude Opus 4.5 3718cfa767 Simplify workspace to path-based storage, remove legacy code
- Consolidate all migrations into V1__initial.sql
- Replace DocType enum with flexible path-based file storage
- Add list_workspace_files SQL function for directory listing
- Update memory tools for path-based API (memory_read, memory_write,
  memory_search, memory_list)
- Remove unused OpenAI/Anthropic providers (NEAR AI only)
- Simplify config to remove multi-provider support
- Update CLAUDE.md documentation

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:38:53 -08:00
Illia PolosukhinandClaude Opus 4.5 f29892b3fb Add NEAR AI chat-api as default LLM provider
Adds NearAiProvider that uses the NEAR AI unified API at
api.near.ai/v1/responses with session token authentication.
This provides access to multiple models (OpenAI, Anthropic, etc.)
through a single endpoint with user auth and usage tracking.

- Add src/llm/nearai.rs with complete provider implementation
- Add NearAiConfig to config.rs with session_token, model, base_url
- Add NearAi variant to LlmProvider enum (accepts nearai/near-ai/near_ai)
- Change default provider from OpenAi to NearAi
- Update .env.example with NEAR AI configuration
- Update CLAUDE.md documentation

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:26:39 -08:00
Illia PolosukhinandClaude Opus 4.5 e30db26bfe Add CLAUDE.md project documentation
Documents the workspace/memory system added in the previous commit,
including architecture, usage patterns, and remaining TODOs.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:20:12 -08:00
Illia PolosukhinandClaude Opus 4.5 4e238e60ac Add workspace and memory system (OpenClaw-inspired)
Implements persistent memory for agents with hybrid search:

- Database-backed workspace with PostgreSQL (not filesystem)
- Memory documents: MEMORY.md, daily logs, identity files
- Chunked content with FTS (tsvector) + vector (pgvector) indexes
- Reciprocal Rank Fusion (RRF) for hybrid search combining BM25 and semantic
- Memory tools: memory_search, memory_write, memory_read
- Proactive heartbeat system for periodic execution (30 min default)
- OpenAI embeddings provider (text-embedding-3-small)

Key patterns from OpenClaw:
- "Memory is files, not RAM" - explicit persistence required
- Two-tier memory: daily logs (raw) + curated MEMORY.md
- Session isolation via user_id/agent_id scoping

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-02 21:18:47 -08:00
Illia Polosukhin 8c38566378 Initial implementation of the agent framework 2026-02-02 20:41:05 -08:00