Automatic Stack Detection
Relevant source files
The following files were used as context for generating this wiki page:
Automatic Stack Detection is a core initialization feature in Morty that scans a target project's root directory to identify its programming language, framework, and standard development commands (test, lint, and build). This system ensures that when Morty is initialized in a "brownfield" or existing project, the AI agents are immediately aware of the project's technical context and can execute relevant CLI tools without manual configuration.
Sources: cli/src/config/detector.ts:16-24, morty.sh:162-171, README.md:46-51
Detection Architecture
The detection logic is triggered during the initialization phase (via morty --init). It operates by looking for specific "sentinel" files associated with major ecosystems.
Core Detection Logic
The system evaluates the project in a specific order, generally prioritizing package managers and configuration files:
- Node.js/JavaScript/TypeScript: Triggered by
package.json. - Python: Triggered by
pyproject.toml,requirements.txt, orsetup.py. - Go: Triggered by
go.mod. - Rust: Triggered by
Cargo.toml.
Sources: cli/src/config/detector.ts:26-55, morty.sh:176-248
Detection Flow Diagram
The following diagram illustrates the decision tree used to identify the project stack and extract relevant metadata.
Ecosystem-Specific Detection
Node.js Ecosystem
For Node.js projects, the detector parses package.json to extract the project name and identify frameworks by checking dependencies and devDependencies. It prioritizes meta-frameworks (e.g., Next.js, Nuxt, Remix) over base libraries like React or Vue. It also checks for the existence of bun.lockb to determine if bun should be used for testing instead of npm.
Sources: cli/src/config/detector.ts:58-106, morty.sh:176-227
Python, Go, and Rust
For non-Node ecosystems, the detector sets standard industry commands:
| Ecosystem | Sentinel Files | Default Test Command | Default Lint Command |
|---|---|---|---|
| Python | pyproject.toml, requirements.txt, setup.py | pytest | ruff check . |
| Go | go.mod | go test ./... | golangci-lint run |
| Rust | Cargo.toml | cargo test | cargo clippy |
Sources: cli/src/config/detector.ts:108-135, morty.sh:229-248
Data Persistence and Usage
Once detection is complete, the results are encapsulated in a DetectedProject object and used to populate the .morty/config.yaml file. This configuration is then used by Morty's execution loop to provide context to the AI and run automated checks.
Configuration Structure
The detected data is mapped to the following schema:
| Field | Description | Source |
|---|---|---|
name | Project identifier | package.json name or directory name |
language | Primary language | Detection of .ts, .py, .go, .rs files |
framework | Web or app framework | Dependency analysis |
testCmd | Command to run tests | Script detection or ecosystem defaults |
lintCmd | Command to run linting | Script detection or ecosystem defaults |
buildCmd | Command to build project | Script detection or ecosystem defaults |
Sources: cli/src/config/types.ts:6-22, cli/src/config/writer.ts:16-44, cli/src/config/detector.ts:4-13
Initialization Sequence
The following sequence diagram shows how the initConfig function coordinates with the detectProject utility to set up the environment.
Summary
Automatic Stack Detection is the gateway for Morty's autonomous operations in existing repositories. By accurately identifying the environment through sentinel file analysis, Morty reduces the friction of manual setup, allowing AI agents to understand the project's language, framework constraints, and preferred tooling immediately upon initialization.
Sources: cli/README.md:38-44, README.md:46-51, morty.sh:248-261