mps-aspect-generator
Skill1.7k starsChanged 2 months agoApache-2.0View on GitHub
Use when defining or modifying MPS generators — author a generator module, add or edit root/reduction/weaving/pattern mapping rules, attach template macros ($COPY_SRC, $LOOP, $IF, $PROPERTY, $REF, $SWITCH, $MAP_SRC, $WEAVE, $INSERT, $LABEL, $TRACE, $VAR), wire mapping labels, build template switches, write pre/post mapping scripts, navigate `genContext`, or debug "rule didn't fire", missing references, empty output, infinite reduction loops, and generated-Java compile failures.
Trending
Quiet since October.thin dataabout the whole repository
Who's talking about JetBrains/MPS
- mbeddr/mps-gradle-plugin“Null pointer exception on generate”GitHub · May 18, 2020 · 1 reactions
- nebojsa-vuksic/skill-atlas“Scan every repository of an organization or user”GitHub · Oct 1, 2026
- modelix/modelix.editor“Implement MPS shortcuts”GitHub · Feb 21, 2023
The biggest 3 of 3 mentions linking to the repository that our crawl found. Each line is their own headline.
In this repository83 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- actionsSkill
- bugfix-workflowSkill
- code-styleSkill
- commitsSkill
- debuggingSkill
- mps-aspect-accessoriesSkill
- mps-aspect-actionsSkill
- mps-aspect-behaviorSkill
- mps-aspect-constraintsSkill
- mps-aspect-dataflowSkill
- mps-aspect-editor-menus-and-keymapsSkill
- mps-aspect-editorSkill
- mps-aspect-generation-planSkill
- mps-aspect-intentionsSkill
- mps-aspect-migrationsSkill
- mps-aspect-structure-conceptsSkill
- mps-aspect-textgenSkill
- mps-aspect-typesystemSkill
- mps-baselanguageSkill
- mps-build-languageSkill
- mps-consoleSkill
- mps-distribution-buildSkill
- mps-dsl-memorySkill
- mps-ide-pluginSkill
- mps-lang-core-xmlSkill
- mps-language-analysisSkill
- mps-language-aspects-overviewSkill
- mps-language-inheritanceSkill
- mps-language-modularitySkill
- mps-mcp-workflowSkill
- mps-model-manipulationSkill
- mps-node-editingSkill
- mps-project-managementSkill
- mps-quotationsSkill
- mps-run-configurationsSkill
- mps-testsSkill
- registrySkill
- skill-optimization-studySkill
- ssrSkill
- teamcity-cliSkill
- actionsSkill
- bugfix-workflowSkill
- code-styleSkill
- commitsSkill
- debuggingSkill
- mps-aspect-accessoriesSkill
- mps-aspect-actionsSkill
- mps-aspect-behaviorSkill
- mps-aspect-constraintsSkill
- mps-aspect-dataflowSkill
- mps-aspect-editor-menus-and-keymapsSkill
- mps-aspect-editorSkill
- mps-aspect-generation-planSkill
- mps-aspect-generatorSkill
- mps-aspect-intentionsSkill
- mps-aspect-migrationsSkill
- mps-aspect-structure-conceptsSkill
- mps-aspect-textgenSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Edit the generator, not
source_gen/: If a bug appears in generated Java, the fix almost always belongs in a template, macro body, or … - Very specific: line 32
Reductions can self-loop: when they produce their own concept — break out with DismissTopMappingRule, a marker subconcept, or $COPY_SRC$.
- Very specific: line 39
Create or edit the MappingConfiguration root (mps_mcp_create_root_node with the FQN in references/concept-fqns.md).
- Distinctive: line 40
Add the rule(s):
- Very specific: line 50
If MPS MCP tools are unavailable, do not hand-edit serialized .mps files unless explicitly asked — inspect only and report.
- Very specific: line 58
Tools: Use the generic IDE file tools (exposed by the MPS MCP server, also by IDEA's.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MPS Generator Aspect
Loading companion skills
Companion names in this skill are lazy dependencies: load only those relevant to the current task. If this skill came from an MCP server, use the host's skill loader to resolve the companion's unique discovered entry URI on the same host-assigned originating server. If the host has no server-backed skill loader, stop and report that limitation; do not silently fall back to a filesystem copy. If this skill came from a filesystem catalog, load the named sibling from that same catalog at <skills-root>/<skill-name>/SKILL.md, even if remote skill loaders are also available. Do not invent a tool name or server endpoint.
A generator transforms models written in the source language into models of one or more target languages (usually BaseLanguage or another DSL). It is a separate MPS module — a generator module — owned by the language and driven by templates: target-language code snippets annotated with macros.
Generator architecture (read first)
A generator translates from the problem domain (source language) toward the implementation domain, often as a cascade: each generator lowers the abstraction level by producing its target language, which becomes the next generator's input, until a base language (usually BaseLanguage) is reached and TextGen emits plain text.
A generator definition has a stable part and a variable part:
- the stable part does not change with the model being generated — engines, base classes, helpers. Provide it once in a runtime solution (an MPS
Solutionthe language declares as a runtime module — as MPS-authored source or a bundled JAR), not as a template. - the variable part is the templates + macros, which react to the input model and choose different output.
Idiomatic generators keep the stable part out of the templates and emit thin code that calls into the runtime solution. Before adding rules, decide how much is stable: see the architecture ladder in references/cookbook.md and the stable-vs-variable split + wiring in references/runtime-solutions.md in the mps-aspect-accessories skill root after loading that companion skill from the same origin (worked example: the Kaja language + its JavaKaja runtime).
Critical Directives
- Edit the generator, not
source_gen/. If a bug appears in generated Java, the fix almost always belongs in a template, macro body, or concept behavior. Patch generated output only when explicitly told to. applicableConceptmust be a structure-model node ref (r:<modelUUID>(<lang>.structure)/<nodeId>), never thec:<langUUID>/<conceptId>form. Wrong form → silentUnresolved reference: c:.... Seereferences/rule-consequences.md.- A
TemplateDeclarationused as a reduction target requires at least oneTemplateFragmenton the produced subtree, or the rule fires and emits nothing. - Module dependencies vs. model used-languages are two distinct layers (see
references/module-structure.md). Adding a class to the wrong one yields "cannot resolve" in generated Java or unusable concepts in templates. - Macros attach via the
smodelAttributechild role, and co-located macros are chained in child order — order is semantics.$IF$before$LOOP$gates the whole loop in the outer context;$LOOP$before$IF$evaluates the condition per iteration. The$LOOP$+$COPY_SRC$pair is order-insensitive only because$COPY_SRC$is terminal — don't generalize. Seereferences/macro-catalog.md. - Reductions can self-loop when they produce their own concept — break out with
DismissTopMappingRule, a marker subconcept, or$COPY_SRC$. - Cross-rule/cross-template references go through mapping labels. Direct references survive only within a single fragment.
Common-path workflow
- Locate or create the generator module. List languages with
mps_mcp_get_project_structure(moduleKind="Language")and find yours byname: each language entry carries ageneratorsarray (unconditional — not gated onincludeDependencies) listing every owned generator'snameandreference. Prefer this overstartingPoint="<language-name>"— a language and its owned generator share a base name, so a name starting point can resolve to the generator module instead, and then thegeneratorsarray is never emitted. (If you already hold the language's persistentreference,startingPoint="<reference>"resolves by id and is also unambiguous.) To go the other direction, each generator entry carries asourceLanguagefield (only whenincludeDependencies=true) with the owning language'snameandreference; follow it withmps_mcp_get_project_structure(startingPoint="<sourceLanguage.reference>", includeModels=true). If no generator exists yet:mps_mcp_create_module(type="generator", parentLanguage="<lang>"). - In
template/main@generator.mps(thegeneratormodel stereotype —name@generator; see aspect-model-stereotypes.md for all model identifiers), add the used languages you target (jetbrains.mps.devkit.templatesis the quickest umbrella) and ensure the target language is also a modulegenerate-intodependency on the language.mpl(seereferences/module-structure.md). - Create or edit the
MappingConfigurationroot (mps_mcp_create_root_nodewith the FQN inreferences/concept-fqns.md). - Add the rule(s):
Root_MappingRulefor whole-root mapping;Reduction_MappingRulefor in-place rewrites (inlineRuleConsequenceorTemplateDeclarationReference);Weaving_MappingRuleto add content into an already-generated container.
- Author target-language templates; attach macros as
smodelAttributechildren. Mark the produced subtree withTemplateFragment(orRootTemplateAnnotationon a target root).- A
RootTemplateAnnotationalone does NOT register a root mapping. It only marks a target root as a template; aRoot_MappingRule(step 4) whosetemplatereference points to that annotated root is also required. Without the rule, generation silently produces no output for that root — MAKE still reports success.
- A
- Declare any mapping labels on the
MappingConfiguration; tag writers (labelDeclarationref or$LABEL$macro); read withgenContext.get/pick output <label> for (<input>)inside$REF$or other queries. - Validate with
mps_mcp_check_root_node_problemson theMappingConfigurationand every template (re-run withonlyNodesWithProblems = falseif siblings look "missing"). mps_mcp_alter_nodes MAKEover the generator and a sample model; read the generated text (see Reading generator output below). Use the Generator Tracer /$TRACE$macros to bisect misgenerated fragments.
If MPS MCP tools are unavailable, do not hand-edit serialized .mps files unless explicitly asked — inspect only and report.
Reading generator output
After a MAKE, generators write Java (and TextGen artifacts like .xml, .scxml) to the owning module's source_gen/ directory. No mps_mcp_* tool reads this output — but the MPS MCP server exposes the same generic IDE file tools, so generated text is readable over MCP today. Don't drop to a raw shell find/cat.
Path convention. Output lands at <module-dir>/source_gen/<model-namespace>/<java-package>/<File>.java, where the model namespace's dots become directory separators. Example: model Kaja.sandbox in solution Kajak.sandbox → samples/robot_Kaja/solutions/Kajak.sandbox/source_gen/Kaja/sandbox/sandbox/Karel.java (trailing sandbox/ is the Java package). TextGen artifacts (.scxml, etc.) follow the same layout. A module may override its output root, so if source_gen/ is not beside the module descriptor, check the module's output path.
Tools. Use the generic IDE file tools (exposed by the MPS MCP server, also by IDEA's; pass projectPath to disambiguate) — not mps_mcp_*:
find_files_by_glob— discover what was generated, e.g. project-root-relative**/Kajak.sandbox/source_gen/**/*.java. Note this matches only.java; uselist_directory_treeto also see TextGen artifacts (.scxml,trace.info, …).list_directory_tree— browse the output directory.read_file— read a specific generated file (output is line-capped; use itsmax_lines/start_lineargs for large files).
Staleness. On-disk source_gen/ reflects the last MAKE. Re-run MAKE before reading so the output matches the current model, otherwise you may read stale text.
Related Skills
mps-aspect-generation-plan— priorities, checkpoints, plan contributions; pair this with priority-ordering questions.mps-aspect-textgen— converting the final model to plain text (last pipeline stage).mps-aspect-behavior— put non-trivial per-concept logic in behavior methods called from macros.mps-model-manipulation— smodel-access idioms (SPropertyAccess,SLinkAccess,Node_GetChildrenOperation) inside query bodies; for a macro query body open onlyreferences/dot-expression-basics.mdin themps-model-manipulationskill root after loading that companion skill from the same origin.mps-quotations— quotation/anti-quotation syntax for building nodes inside$INSERT$and$MAP_SRC$.mapperFunction.mps-baselanguage— host language for macro query bodies andRulesFunctions_*helpers.
Reference Index
Start here — most common case: one reduction rule with template macros → read only references/macro-catalog.md, plus references/concept-fqns.md for the blueprint shape; a brand-new generator module → only references/module-structure.md; a rule that did not fire or generated code that will not compile → only references/common-failures.md.
- Generator module structure (descriptor deps, model used-languages, MappingConfiguration roles):
references/module-structure.md— read when setting up a generator or fixing "cannot resolve"/missing-concept issues. - RuleConsequence catalog (
TemplateDeclarationReference,Inline*,AbandonInput,DismissTop) + the criticalapplicableConceptref-form gotcha:references/rule-consequences.md. - Macro catalog and JSON blueprints for COPY_SRC/COPY_SRCL/PROPERTY/IF/LOOP/CALL:
references/macro-catalog.md— read before attaching any macro. $MAP_SRC$in depth (replace input, mapperFunction, postMapperFunction, label-on-site):references/macro-map-src.md.$REF$/ ReferenceMacro in depth (label-based and name-based forms, return types):references/macro-reference.md.- Less-common macros —
$WEAVE$,$VAR$,$TRACE$,$LABEL$,$INSERT$:references/macros-rare.md. - Query-body subconcepts and their implicit parameters (
IfMacro_Condition,SourceSubstituteMacro_*, etc.):references/query-bodies.md. - Mapping labels — declare/write/read pattern,
getvspickvsget list:references/mapping-labels.md. - Weaving rules —
contextNodeQuery, when to use vs. reductions:references/weaving-rules.md. - Template switches — when to switch,
extendsacross generator modules:references/template-switches.md. - Pattern reduction rules — structural-pattern matching with typed holes:
references/pattern-rules.md. - Mapping scripts (pre / post) — bulk passes and
modifiesModel:references/mapping-scripts.md. - Utility models, template functions, fragments — where to place non-trivial generator-time helpers:
references/utility-models.md. genContextoperations catalog (everyGenerationContextOp_*with editor alias and purpose):references/generation-context.md.- Generation algorithm — pipeline stages (selection → implicit grouping/ordering → explicit priorities → step-by-step transformation → TextGen), micro-steps, weaving vs. reduction ordering:
references/algorithm.md. - Cookbook recipes — multi-root, cross-ref, unique IDs, extensible generators, loop-extraction refactor:
references/cookbook.md. - Common failures — symptom-to-cause-to-fix table:
references/common-failures.md. - Validated concept FQNs and minimal
MappingConfigurationblueprint:references/concept-fqns.md. - Calling from/into the generator — behaviors,
RulesFunctions_*, utility models:references/calling-into-generator.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

