IDE Integrations (Cursor, Copilot)
Relevant source files
The following files were used as context for generating this wiki page:
Morty integrates with AI-powered IDE agents and CLI tools to automate coding tasks. By leveraging the Cursor Agent and GitHub Copilot CLI, Morty acts as a wrapper that provides project-specific context, rules, and task management to these underlying AI engines. This integration allows Morty to drive autonomous coding loops where the IDE-associated agents perform the actual implementation, testing, and linting of code.
These integrations are part of a broader "AI Engine" abstraction layer that supports multiple providers, including Claude Code, OpenCode, and Factory Droid. When using Cursor or Copilot, Morty handles the orchestration of tasks—either sequentially or via parallel worktrees—while the specific IDE tool manages the file system modifications and reasoning.
Sources: morty.sh:11-15, README.md:1-10
Architecture and Integration Layer
Morty interacts with Cursor and Copilot via their respective command-line interfaces. The system wraps these tools in a "Pre-flight check" to ensure the necessary binaries are available in the user's environment before execution.
Morty selects the AI engine based on CLI arguments and invokes the corresponding external command with specific flags for non-interactive execution.
Sources: morty.sh:425-452, cli/src/cli/args.ts:40-55
Engine Specifics
The integration for each engine requires different CLI flags and permission handling:
| Engine | CLI Command | Permission Mode | Output Format |
|---|---|---|---|
| Cursor | agent | --force (Auto-approve) | stream-json |
| Copilot | copilot | -p (Prompt flag) | text / duration |
Sources: README.md:278-286, morty.sh:824-836
Cursor Integration Logic
The Cursor integration utilizes the agent CLI. Morty invokes this with the --print and --force flags to ensure the agent operates in a non-interactive mode suitable for automated loops.
Execution Flow
When Cursor is selected as the engine, Morty builds a prompt containing project context (from .morty/config.yaml) and task instructions. The command is executed as follows:
agent --print --force --output-format stream-json "$prompt"
Sources: morty.sh:824-828, cli/src/execution/prompt.ts:30-50
Output Parsing
Since Cursor does not always provide raw token usage through its CLI, Morty tracks the performance using duration markers.
The parser looks for a JSON object with "type":"result" and extracts the duration_ms field to report performance statistics in the final summary.
Sources: morty.sh:874-895, morty.sh:1232-1240
GitHub Copilot Integration Logic
Morty supports GitHub Copilot via the @github/copilot CLI extension. It is invoked using the --copilot flag.
Command Invocation
For Copilot, Morty uses the -p flag to pass the generated prompt programmatically.
copilot -p "$prompt" ${MODEL_OVERRIDE:+--model "$MODEL_OVERRIDE"}
Sources: morty.sh:450-453, morty.sh:838-842
Content Filtering
Unlike Cursor, the Copilot CLI often includes interactive terminal characters and "thinking" indicators. Morty implements a filtering mechanism to sanitize the output:
- Filters out lines starting with
?or❯. - Removes "Thinking..." and "Working on it..." status messages.
- Captures the last 10 lines of the main response body to treat as the task result.
Sources: morty.sh:911-925
Parallel Execution with IDE Agents
Both Cursor and Copilot can be used within Morty's parallel execution framework. This leverages git worktree to create isolated environments for multiple agents to work simultaneously.
The run_parallel_agent function changes the working directory to the worktree before invoking the agent or copilot CLI, ensuring that the AI engine only sees and modifies files within its assigned task scope.
Sources: cli/src/execution/parallel.ts:40-75, morty.sh:1033-1080
Configuration and Rules
Both integrations respect the project rules defined in the .morty/ directory (or legacy .ralphy/). These rules are injected into every prompt sent to Cursor or Copilot to ensure consistent coding standards.
Relevant Configuration Fields
| Field | Purpose |
|---|---|
project.language | Informs the agent of the primary language (e.g., TypeScript). |
rules | Array of specific instructions (e.g., "Use server actions"). |
boundaries.never_touch | Files the IDE agents are forbidden from modifying. |
Sources: cli/src/config/types.ts:10-40, cli/src/config/loader.ts:98-115
Summary of Capabilities
The integration of Cursor and Copilot into Morty allows developers to use their preferred IDE-native AI tools within an autonomous framework. Morty handles the "loop" (retry logic, branch management, and conflict resolution) while the IDE agents handle the "logic" (writing code and tests). This relationship is orchestrated via Morty's runtime options, allowing users to toggle engines seamlessly with flags like --cursor or --copilot.
Sources: README.md:310-330, morty.sh:1370-1385