AIRI Core - Coding Workspace

Overview

The coding workspace is an AIRI-native coding-agent surface hosted inside the existing chat window. It revives the useful parts of Roo-style coding agents without porting Roo's VS Code extension architecture or legacy transcript model.

The core idea is simple:

This keeps AIRI as the host operating system for the coding experience. External agents and MCP servers become replaceable backends, not competing renderers.

Goals

  1. Add a coding mode to AIRI's existing chat window.
  2. Use AIRI's upstream MCP runtime for code intelligence instead of building a one-off code search stack.
  3. Prefer Serena MCP for semantic operations: symbol lookup, declarations, references, diagnostics, and targeted source retrieval.
  4. Keep all file edits, command execution, and approvals under AIRI-owned policy.
  5. Make Pi/Codex ACP integration possible without making either one the foundation of the native coding workspace.
  6. Preserve the existing chat message model, including tool-call slices and custom tool renderers.

Non-Goals

Current AIRI Fit

The repository already has most of the required host primitives:

The coding workspace should use these paths instead of introducing a parallel agent runtime.

Architecture

Chat Window
  |
  | user message + selected coding mode
  v
Chat Orchestrator Runtime
  |
  | active tool set + prompt contributions
  v
Coding Workspace Module
  |
  |-- Code Intelligence Facade
  |     |-- Serena MCP adapter preferred
  |     |-- generic MCP adapter fallback
  |     `-- local search fallback
  |
  |-- Workspace Tool Provider
  |     |-- read_file
  |     |-- list_files
  |     |-- apply_patch
  |     |-- write_file
  |     |-- run_command
  |     |-- read_command_output
  |     `-- update_todo
  |
  |-- Approval and Policy Gate
  |     |-- mode restrictions
  |     |-- path sandbox
  |     |-- diff approvals
  |     `-- command approvals
  |
  `-- Optional ACP Engine Adapter
        |-- Pi subprocess
        |-- Codex subprocess
        `-- other ACP-compatible agents

The model sees stable AIRI-native coding tools. Internally, those tools may call Serena MCP, generic MCP, local filesystem functions, or an ACP subprocess. The chat UI does not need to know which backend served the request.

Coding Module

The coding module is a Stage/Tamagotchi module similar in placement to consciousness, hearing, vision, and other runtime modules.

It owns:

The module should register tools through useLlmToolsStore and prompt contributions through useLlmToolsetPromptsStore, matching the existing plugin and MCP tool patterns.

Coding state should attach to the active chat session where possible. AIRI already has a session store, session metadata, and a sessions drawer, so the coding module should not introduce a parallel conversation model. When the user is having a normal conversation, coding controls stay compact and inactive unless a workspace or coding mode is selected.

Modes

Modes are AIRI-owned. They control tool availability and prompt policy.

Ask

Purpose: answer questions and inspect code.

Allowed:

Blocked:

Spec

Purpose: plan changes through Kiro-style spec artifacts: requirements.md, design.md, and tasks.md.

Allowed:

Blocked by default:

Code

Purpose: implement changes.

Allowed:

Gates:

Debug

Purpose: investigate failures and verify hypotheses.

Allowed:

Gates:

MCP and Serena

MCP should be treated as a first-class substrate. The existing Electron MCP runtime remains the lifecycle owner for stdio servers.

Serena is an external dependency and should not be silently installed. The MCP settings page should provide a predefined Serena server template with a link to Serena's setup documentation and a clear prerequisite that uv must be available on PATH. Users can then test and enable the server through AIRI's normal MCP config flow.

The coding workspace adds a semantic facade over MCP:

workspace_get_symbols_overview
workspace_find_symbol
workspace_find_declaration
workspace_find_references
workspace_get_diagnostics
workspace_search_pattern
workspace_ranked_context

When Serena is configured and running, the facade maps these tools to Serena calls:

Serena mutating tools are deliberately not exposed as direct model tools in the first milestone:

Those operations may be used later to produce edit proposals, but AIRI should still apply final changes through its own patch and approval pipeline.

If Serena is unavailable, the facade falls back to generic MCP or local tools:

Fallback output must keep the same shape as the Serena-backed path so prompts, renderers, and tests stay stable.

Generic MCP Escape Hatch

The existing generic MCP tools should remain available:

They are useful for discovery and non-coding MCP servers. Coding workflows, however, should prefer stable AIRI workspace tools over raw model-selected MCP tool names. This avoids brittle prompts such as requiring the model to call builtIn_mcpCallTool with a serialized JSON argument for every code lookup.

Workspace Tools

The workspace tool provider exposes guarded tools with AIRI-owned semantics.

Read Tools

Code Intelligence Tools

workspace_ranked_context is a composed helper that can use Serena symbols, references, and pattern search when available, then fall back to local search results when needed.

Edit Tools

Terminal Tools

Commands should run through Electron main or a core workspace runtime, not the renderer. Long-running commands are captured as artifacts and summarized in chat.

Approval and Authority

The approval gate is the main safety boundary.

Policy rules:

The same approval gate should serve native tools, MCP-backed tools, and ACP engines. This prevents multiple authority systems from diverging.

ACP Engine Adapter

ACP is an interoperability layer for external coding agents. It lets AIRI host Pi, Codex, or other agents as subprocesses while preserving AIRI's native chat surface.

The adapter owns:

The ACP adapter does not own:

Engine selection belongs in the coding module settings:

The first implementation can ship without ACP, but the native tool/event model should be designed so ACP can plug in without a rewrite.

Chat UI

The existing chat timeline remains the only visible transcript.

Coding mode must integrate into the vanilla AIRI chat window without obstructing normal conversation. The default experience remains regular chat; workspace controls appear as a compact strip or drawer only when the user opts into coding context.

Additions:

The UI should not render a second Roo/Pi/Codex transcript. External events are normalized into AIRI message slices.

Data Flow

Native Coding Turn

User sends message
  -> chat orchestrator composes prompt with active coding mode
  -> LLM calls AIRI workspace tools
  -> tools route to Serena MCP, filesystem, terminal, or patch backend
  -> approval gate pauses edits/commands when needed
  -> tool results stream into chat slices
  -> final assistant response persists in AIRI chat session

Serena Search

workspace_find_symbol
  -> code intelligence facade
  -> MCP runtime list/status check
  -> Serena MCP call
  -> normalized symbol result
  -> chat tool renderer

ACP Turn

User sends message with engine = ACP: Pi
  -> ACP adapter starts or reuses subprocess session
  -> subprocess streams events
  -> adapter maps text to assistant slices
  -> adapter maps action requests to AIRI tools/approvals
  -> final output persists in AIRI chat session

Persistence

Persist at least:

Do not persist secrets from MCP configs or subprocess environment variables into chat messages.

Testing Strategy

Core tests:

Renderer tests:

Electron main tests:

Contract tests:

Milestones

Milestone 1 - Native Coding Workspace

Milestone 2 - MCP Hardening

Milestone 3 - Native Swarm Runtime

Milestone 4 - ACP Engine Adapter

Milestone 5 - Advanced Code Operations

Open Questions

  1. What production safety policy should replace the experimental AFK autopilot authority model?
  2. What stability milestone should trigger ACP backend work?

Decision

Proceed with an AIRI-native coding workspace hosted in the existing chat window. Use MCP, especially Serena, as the preferred code-intelligence backend. Keep all workspace authority and approvals in AIRI. Use native AIRI agents for the first swarm runtime and defer Pi/Codex ACP subprocess engines until the native agent model is stable. Coding state is scoped to chat sessions when enabled, and Serena is offered through MCP settings as a predefined external integration rather than auto-installed.