Editor Integration Architecture
Technical architecture and implementation details for Radium's editor integration system.
Overviewβ
The editor integration system leverages Radium's extension infrastructure and hook system to provide seamless bidirectional code exchange between editors and Radium agents.
Architecture Componentsβ
1. Extension Systemβ
All editor integrations are implemented as Radium extensions:
- radium-nvim: Neovim Lua plugin
- radium-vscode: VS Code TypeScript extension
- Clipboard mode: CLI commands (no extension needed)
Extensions are installed via:
rad extension install <extension-name>
2. Hook Systemβ
Editor integrations use two key hook types:
BeforeTool Hookβ
Purpose: Inject editor context before tool execution
Hook: editor-context (BeforeTool, priority 150)
Context Data:
{
"file_path": "/path/to/file.rs",
"language": "rust",
"selection": "selected code",
"surrounding_lines": "context above\n---\ncontext below"
}
Implementation:
- Reads environment variables set by editor
- Merges context into tool execution context
- Passes enriched context to agent
AfterTool Hookβ
Purpose: Process agent output for editor application
Hook: code-apply (AfterTool, priority 100)
Processing:
- Extracts markdown code blocks
- Structures output with metadata
- Formats for editor consumption
Output Format:
{
"code_blocks": [
{
"language": "rust",
"content": "fn improved() {}",
"index": 0
}
],
"block_count": 1
}
3. CLI Communicationβ
Editor extensions communicate with Radium via CLI commands:
rad step <agent-id>: Execute single agent steprad chat <agent-id>: Interactive chat session
Communication Protocol:
- Input: Context JSON via stdin
- Output: Agent response via stdout
- Environment: Context variables for hooks
4. Data Flowβ
Editor β Extension β CLI Command β Hook (BeforeTool) β Agent β Hook (AfterTool) β CLI β Extension β Editor
Detailed Flow:
- User Action (select code, run command)
- Extension extracts context:
- File path
- Language
- Selection
- Surrounding lines
- Extension sets environment variables for hooks
- Extension executes
rad stepwith context JSON - BeforeTool Hook enriches context
- Agent processes with enriched context
- AfterTool Hook extracts code blocks
- CLI returns structured output
- Extension displays results
- User applies changes via diff preview
Extension Structureβ
Neovim Extension (radium-nvim)β
radium-nvim/
βββ radium-extension.json # Extension manifest
βββ hooks/
β βββ editor-context.toml # BeforeTool hook config
β βββ code-apply.toml # AfterTool hook config
βββ plugin/
β βββ radium.lua # Main plugin entry
β βββ radium/
β βββ commands.lua # Command implementations
β βββ utils.lua # Utilities
β βββ diff.lua # Diff functionality
βββ tests/ # Integration tests
Key Components:
- Lua plugin for Neovim API
- Commands registered via
vim.api.nvim_create_user_command - Context extraction using Neovim API
- CLI execution via
vim.fn.jobstart
VS Code Extension (radium-vscode)β
radium-vscode/
βββ radium-extension.json # Radium extension manifest
βββ package.json # VS Code extension manifest
βββ hooks/ # Shared hooks (same as Neovim)
βββ src/
β βββ extension.ts # Main entry point
β βββ commands/
β β βββ sendSelection.ts
β β βββ applyCode.ts
β β βββ chat.ts
β βββ utils/
β βββ context.ts # Context extraction
β βββ cli.ts # CLI communication
βββ out/ # Compiled JavaScript
Key Components:
- TypeScript extension using VS Code API
- Commands registered via
vscode.commands.registerCommand - Context extraction using VS Code API
- CLI execution via
child_process.spawn
Clipboard Modeβ
radium-core/src/clipboard/
βββ mod.rs # Clipboard operations
βββ parser.rs # Format parsing
apps/cli/src/commands/
βββ clipboard.rs # CLI commands
Key Components:
- Cross-platform clipboard access (
arboardcrate) - File path annotation parsing
- Language detection
- CLI commands:
sendandreceive
Hook Implementationβ
Hook Configurationβ
Hooks are configured in TOML files:
[[hooks]]
name = "editor-context"
type = "before_tool"
priority = 150
enabled = true
script = "hooks/editor-context.sh"
Hook Executionβ
- Discovery: Hooks are discovered from extension directories
- Registration: Loaded into HookRegistry on extension installation
- Execution: Triggered during tool execution lifecycle
- Context: Receive HookContext with tool data
- Modification: Return HookResult with modified data
Environment Variablesβ
Editor extensions set these for hook access:
RADIUM_EDITOR_FILE_PATHRADIUM_EDITOR_LANGUAGERADIUM_EDITOR_SELECTIONRADIUM_EDITOR_SURROUNDING_LINES
Context Formatβ
Input Context (Editor β Radium)β
{
"file_path": "/absolute/path/to/file.rs",
"language": "rust",
"selection": "fn main() {\n println!(\"Hello\");\n}",
"surrounding_lines": "use std::io;\n---\nfn helper() {}",
"workspace": "/workspace/root" // VS Code only
}
Output Format (Radium β Editor)β
{
"original_output": "Full agent response...",
"code_blocks": [
{
"language": "rust",
"content": "fn improved() {}",
"index": 0
}
],
"block_count": 1
}
Extension Discoveryβ
Extensions are discovered from:
- User-level:
~/.radium/extensions/ - Workspace-level:
.radium/extensions/(takes precedence)
Hooks are automatically loaded from extension hooks/ directories.
Security Considerationsβ
- Path Validation: File paths are validated before use
- Sandboxing: Tool execution can use sandboxes (Docker/Seatbelt)
- Context Sanitization: Editor context is sanitized before injection
- CLI Isolation: Commands run in isolated processes
Performanceβ
- Hook Priority: Editor context hook has high priority (150) for early execution
- Caching: Hook results can be cached for repeated operations
- Async Execution: Hooks execute asynchronously to avoid blocking
- Streaming: Large outputs streamed for better performance
Extension Pointsβ
The system is extensible:
- Custom Hooks: Add hooks to extensions for custom processing
- Custom Commands: Extend CLI with editor-specific commands
- Format Support: Add parsers for additional annotation formats
- Editor Support: Create new extensions for other editors
Future Enhancementsβ
- Real-time sync (bidirectional updates)
- Multi-file operations
- Language server protocol integration
- Advanced diff/merge capabilities
- Workspace-wide context awareness