Nimonyplugins

From planetis-m/skills · View interactive version

Nimonyplugins is an AI agent skill from the GitHub repository planetis-m/skills. Build and debug Nimony compile-time plugins for code generation and DSL rewrites. Use when replacing Nim macros with Nimony plugins, writing or reviewing template, for-loop, module, type, or import plugins, or diagnosing NIF traversal and generated output.

How to use this skill

Skill file

Nimony Plugins

Rules

Resolve the actual API

../src/nimony/lib/plugins.nim relative to the executable directory.

Otherwise open src/nimony/lib/plugins.nim under the executable directory.

Treat that file as the source of truth.

a separate nimony c invocation and cached executable, even when two paths

contain identical source. Warm builds reuse those executables.

pragma, not the call site.

Choose the plugin contract

There are five plugin kinds:

(stmts <template-name> <args...>). Use callArgs(root) to read the

arguments. Its output is semantically checked again.

(forcall <iterator-name> (callargs ...) (unpackflat|unpacktup ...) <body>).

Use forLoopCallArgs, forLoopVars, and forLoopBody. The body is already

typed; transformed output is semantically checked again.

must return the full module. Output is not checked again.

loadPluginInput() and triggering definitions through

loadTypeDefinitions(). It must return the full module; output is not

checked again.

When multiple templates or iterators name the same plugin path, use

pluginName(root) to dispatch them inside that one executable.

Use the named protocol helpers to access template and for-loop inputs.

Ownership and identity

storage alive; later builder mutation detaches storage as needed.

saveTree accepts its completed output as a sink parameter.

their names with symText and tagText.

from plugin cursors can be reused by builder helpers.

Build NIF

closeTree().

for synthetic output.

takeTree(dest, cursor) to copy and advance.

bounded children.

SymId to addSymDef and every corresponding addSymUse.

Traverse bounded cursors

leaves n advanced past the root.

Prefer Replacer for selective rewrites

the leading name deliberately before processing arguments.

Report errors and write output

contract.

omit line information.

Workflow

  1. Resolve and inspect the exact plugins.nim used by the selected Nimony.
  2. Select the plugin kind and write down its input/output contract.
  3. Expose the pragma from a small user-facing module and keep transformation

logic in a separate plugin module.

  1. Load input with loadPluginInput, loadTypeDefinitions, or loadReplacer.
  2. Use protocol helpers before traversing arguments, variables, or bodies.
  3. Preserve correct subtrees; synthesize only what changes.
  4. Build one complete output. Return errorTree for invalid input, then write

the result with saveTree or saveReplacer.

  1. Compile plugin integration tests with Nimony. A host-Nim test harness can

launch nimony when needed.

Common Mistakes

| Mistake | Correction |

| --- | --- |

| Compiling the plugin module with Nim | Compile plugin modules and integration tests with Nimony |

| Traversing a template root as though every child were an argument | Use callArgs(root); the root also contains the invoked template name |

| Confusing addSubtree with takeTree | Use addSubtree to preserve the cursor position and takeTree to advance it |

| Leaving children unconsumed in into, keepTag, or replaceHead | Consume every bounded child in the body |

| Returning a transformed fragment from a module or type plugin | Return the complete module |

| Reusing a textual name for a generated local | Call genSym() once and use its SymId for the definition and every use |

| Writing output during peek while treating it as a dry run | Keep peek read-only; it restores the source cursor but not r.dest |

References

arguments.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.