Mental Analyzer API
The Mental Analyzer integrates with @mentalmodel/cli to provide semantic understanding of your codebase. It goes beyond file structure and tool sequences to capture what exists (domains), what it does (capabilities), how it’s governed (aspects), and why decisions were made (decisions).Overview
Mental model provides four key layers of codebase understanding:- Domains: Core entities (User, Order, Payment)
- Capabilities: Actions/verbs (Checkout, ProcessPayment)
- Aspects: Cross-cutting concerns (Auth, Validation)
- Decisions: Architecture decisions with rationale
Functions
createMentalAnalyzer
Create a Mental model analyzer. The Mental model provides semantic understanding that goes beyond file structure and tool sequences. It captures what exists (domains), what it does (capabilities), how it is governed (aspects), and why decisions were made (decisions).Path to project with Mental model. Defaults to current working directory.
Example
Methods
The object returned bycreateMentalAnalyzer has the following methods:
isMentalAvailable
Check if the mental CLI is installed and accessible.boolean - True if mental command is available
loadModel
Load Mental model from project usingmental show --json.
MentalModel | null - Parsed Mental model or null if unavailable/failed
getRelevantDomains
Get domains relevant to given file paths. Uses a simple heuristic: matches domain names in file paths (case-insensitive).List of file paths from tool calls
MentalDomain[] - List of relevant domains
getCapabilitiesForDomains
Get capabilities that operate on given domains.Domains to find capabilities for
MentalCapability[] - Capabilities operating on these domains
suggestSkillsForCapability
Suggest potential skills for a capability using keyword matching.Capability to suggest skills for
SkillHint[] - List of skill hints with metadata
Built-in Keyword Mappings
| Keyword | Suggested Skills |
|---|---|
| checkout | payment-processing, cart-management, order-validation |
| payment | stripe-integration, payment-retry, refund-processing |
| auth | jwt-validation, oauth-flow, session-management |
| notification | email-sending, push-notifications, sms-gateway |
| search | elasticsearch-query, full-text-search, faceted-search |
| upload | file-upload, image-processing, s3-upload |
| export | csv-export, pdf-generation, report-builder |
| import | csv-import, data-validation, bulk-insert |
| sync | data-sync, webhook-handler, event-bus |
getAspectsForCapability
Get aspects (cross-cutting concerns) that apply to a capability.Capability to find aspects for
MentalAspect[] - Applicable aspects
getDecisionsForDomain
Get architecture decisions related to a domain.Domain to find decisions for
MentalDecision[] - Related decisions
toDict
Convert loaded Mental model to a plain dictionary.Record<string, unknown> - Mental model as plain object (empty if not loaded)
Types
MentalModel
Complete Mental model of the codebase.MentalDomain
A domain from Mental model (core entity).Domain name (e.g., “User”, “Payment”)
Description of what this domain represents
File paths or identifiers that reference this domain
MentalCapability
A capability from Mental model (action/verb).Capability name (e.g., “ProcessPayment”, “SendNotification”)
Description of what this capability does
Domain names this capability operates on
MentalAspect
A cross-cutting aspect from Mental model.Aspect name (e.g., “Authentication”, “Validation”)
Description of this cross-cutting concern
Capability names this aspect applies to
MentalDecision
An architecture decision from Mental model.Decision identifier
What decision was made
Rationale for the decision
References to related domains/capabilities (e.g., “domain:Payment”)
Links to related documentation
SkillHint
A skill suggestion hint derived from a capability.Suggested skill name (kebab-case)
Source of the hint (always “mental-hint”)
Capability name this hint is derived from
Confidence score (currently always 0.6)
Installation
To use the Mental Analyzer, you need to install the@mentalmodel/cli package:
Integration with Auto-Skill
The Mental Analyzer enhances Auto-Skill’s pattern detection by:- Providing semantic context for detected patterns
- Suggesting skills based on codebase capabilities
- Enriching skill metadata with domain and capability information
- Guiding skill naming based on domain vocabulary