- SwiftUI macOS app with C++17 code analysis engine (ObjC++ bridge) - Agentic AI loop: LLM plans → tool calls → execution → feedback loop - 15 agent tools: file ops, terminal, git, xcode build, code intel - 7 persistent terminal tools with background session management - Chat sidebar with agent step rendering and auto-apply - NVIDIA NIM API integration (Llama 3.3 70B default) - OpenAI tool_calls format with prompt-based fallback - Code editor with syntax highlighting and multi-tab support - File tree, console view, terminal view - Git integration and workspace management
6.2 KiB
CxIDE — Developer Guide
Getting Started
# Clone and enter project
git clone <repo-url> CxIDE && cd CxIDE
# Run first-time setup
./scripts/setup.sh
Setup validates your toolchain, installs git hooks, and builds the agent CLI.
Project Structure
CxIDE/
├── SwiftIDEApp.swift # @main entry point
├── EngineFactory.swift # Engine selection factory
├── SwiftCodeEngine.swift # Full Swift execution engine
├── SandboxedSwiftEngine.swift # Safe interpreter
├── Core/ # C++ analysis engine
│ ├── CodeEngine.hpp/cpp # Tokenizer, metrics, analysis
│ ├── SwiftEngineWrapper.* # ObjC++ bridge
│ ├── CodeEngine.swift # CppEngineController facade
│ └── FileItem.swift # File model
├── Agent/ # Embedded MCP agent (56 tools)
│ ├── MCPServer.swift # JSON-RPC server
│ ├── MCPTypes.swift # Protocol types
│ ├── AgentConfig.swift # Configuration
│ ├── AgentMemory.swift # Session memory
│ └── Tools/ # 8 tool modules
├── Models/ # Data models
├── Views/ # SwiftUI views
├── ViewModels/ # View models
├── Services/ # AgentService
├── CxSwiftAgent/ # Standalone SPM agent package
├── scripts/ # Build & dev scripts
├── hooks/ # Git hooks
└── docs/ # Documentation
Daily Workflow
Build & Run
# Compile C++ engine + ObjC++ bridge
./scripts/build.sh
# Release build
./scripts/build.sh release
# Open in Xcode for SwiftUI development
open CxIDE.xcodeproj # or create one if needed
Testing
# Run full test suite (C++ validation + agent tests + structure check)
./scripts/test.sh
# Agent tests only
cd CxSwiftAgent && swift test
# Lint check
./scripts/lint.sh
Clean Build
./scripts/clean.sh
Adding Features
Adding a new View
- Create
Views/YourView.swift - Add any new model types to
Models/Models.swift - Wire into
IDEContainerView.swift(sidebar or panel) - Add state to
EditorViewModel.swiftif needed
Adding an Agent Tool
- Choose the appropriate module in
Agent/Tools/(or create a new one) - Add tool registration in the module's
register()function:
server.registerTool(MCPToolDefinition(
name: "your_tool_name",
description: "What it does",
inputSchema: ["type": "object", "properties": [...]],
annotations: ToolAnnotations(readOnlyHint: true)
) { params in
// Implementation
return ["content": [["type": "text", "text": "result"]]]
})
- If it's a new module, register it in
Services/AgentService.swift:
YourModule.register(on: server, config: config, memory: memory)
- Add the tool name to
AgentService.toolCategoriesand optionallyreadOnlyTools - Add a routing keyword in
AgentService.routeMessage()if applicable
Modifying the C++ Engine
- Add declaration to
Core/CodeEngine.hpp - Implement in
Core/CodeEngine.cpp - Add ObjC wrapper method in
Core/SwiftEngineWrapper.hand.mm - Add Swift facade method in
Core/CodeEngine.swift(CppEngineController) - Rebuild:
./scripts/build.sh
Commit Conventions
This project uses Conventional Commits:
type(scope): description
Types: feat, fix, refactor, docs, test, build, ci, chore, perf, style, agent
Scopes: core, agent, views, models, services, vm, engine, tools
Examples:
feat(agent): add workspace analysis tool
fix(core): handle nested block comments in tokenizer
refactor(views): extract agent chat into separate component
docs: update architecture diagram
test(agent): add integration tests for file operations
build: add release optimization flags
The commit-msg hook enforces this format automatically.
Git Hooks
Installed automatically by ./scripts/setup.sh or manually:
cp hooks/* .git/hooks/ && chmod +x .git/hooks/*
| Hook | What It Does |
|---|---|
pre-commit |
Validates C++ syntax, scans for secrets and merge markers |
commit-msg |
Enforces conventional commit format |
pre-push |
Compiles C++ engine, runs agent tests, scans for sensitive data |
Agent Commands
Available from the Command Palette (Cmd+Shift+P) or the Agent sidebar:
| Command | Shortcut | Description |
|---|---|---|
| Agent: Explain Code | Cmd+Shift+E | Explain the current editor content |
| Agent: Review Code | Cmd+Shift+R | Review code for issues and improvements |
| Agent: Fix Issues | — | Auto-fix detected issues |
| Agent: Generate Tests | — | Generate unit tests for current code |
| Agent: Analyze Workspace | — | Full workspace analysis |
| Agent: Run Diagnostics | — | Lint, complexity, and health checks |
| Agent: Security Audit | — | Scan for security vulnerabilities |
| Agent: List Tools | — | Show all 56 available tools |
Direct Tool Invocation
In the Agent chat panel, prefix with / to call a tool directly:
/file_list {"path": "."}
/git_status {}
/diag_complexity {"path": "Core/CodeEngine.cpp"}
Environment Variables (Agent)
| Variable | Default | Description |
|---|---|---|
CX_WORKSPACE |
cwd | Workspace root path |
CX_LOG_LEVEL |
info | Logging: debug, info, warn, error |
CX_PROFILE |
development | Profile: development, staging, production |
CX_SANDBOX |
false | Restrict to read-only tools |
CX_AUTH_TOKEN |
— | API authentication token |
CX_HOST |
127.0.0.1 | HTTP server bind address |
CX_PORT |
3001 | HTTP server port |
Troubleshooting
C++ bridge not linking: Ensure the bridging header Core/SwiftEngineWrapper.h is
set in Xcode Build Settings → "Objective-C Bridging Header".
Agent tools not registering: Check Services/AgentService.swift initialize() —
all 8 tool modules must be registered.
Swift execution fails: SwiftCodeEngine needs /usr/bin/swift — macOS only.
On other platforms, the sandbox engine is used automatically.
Sandbox mode blocks writes: Toggle agentService.sandboxMode or unset CX_SANDBOX.