Agent Skill
2/7/2026compiler
.NET Compiler for PowerShell code, combines all required files from imports into a single output with post-processors.
A
amtsupport
1GitHub Stars
1Views
npx skills add AMTSupport/scripts
SKILL.md
| Name | compiler |
| Description | .NET Compiler for PowerShell code, combines all required files from imports into a single output with post-processors. |
name: compiler description: .NET Compiler for PowerShell code, combines all required files from imports into a single output with post-processors.
When to use me
Use this when working with files under src/Compiler/ or tests/Compiler/ or asked questions about compiled scripts.
Overview
C# project that compiles PowerShell scripts into self-contained executables. Resolves module dependencies, performs AST analysis, and embeds local/remote modules.
Architecture
Entry Point
Program.Main → CLI parsing → file gathering → ResolvableParent orchestration → async compilation
Key Phases
- File Gathering: Collect
.ps1files, skip#!ignoreheaders - Parsing: Build PowerShell AST via
System.Management.Automation.Language - Resolution: Discover dependencies via
Using modulestatements,#Requires - AST Transformation: Rewrite paths, add metadata, minimize output
- Analysis: Run rule visitors, collect
Issueobjects - Output: Emit CRLF-normalized UTF-8 BOM files
Key Types
| Type | Purpose |
|---|---|
ModuleSpec / PathedModuleSpec | Module identity + version + hash |
RequirementGroup | Typed requirement sets with ordering |
Resolvable* | Pre-compiled (Local/Remote/Script) |
Compiled* | Final immutable representations |
Rule / RuleVisitor | AST-based static analysis |
Code Patterns
Error Handling
Use Fin<T> / Option<T> monadic patterns:
if (maybeValue.IsErr(out var error, out var value)) {
Errors.Add(error);
return;
}
Hash Stability
ComputedHashcombines content + requirements + dependency hashes- Never mutate
ContentBytesafter hash consumption - Exception:
CompleteCompileAfterResolutionfor remote manifest rewrite
Thread Safety
- Mutate graphs only within locked sections
- Use
ConcurrentBag<Error>for diagnostics - Prefer
Task.Runbatches for parallelism
Adding Features
New Requirement Type
- Subclass
Requirementwith stableHashandWeight - Implement
GetInsertableLine()for PowerShell output - Add detection in
ResolveRequirements - Override
IsCompatibleWithif needed
New Analyser Rule
public sealed class MyRule : Rule {
public override bool SupportsModule<T>(T mod) => mod is CompiledLocalModule;
public override bool ShouldProcess(Ast node, IEnumerable<Suppression> suppressions)
=> /* filter */;
public override IEnumerable<Issue> Analyse(Ast node, IEnumerable<Compiled> imports) {
if (/* condition */)
yield return Issue.Warning("Message", node.Extent, AstHelper.FindRoot(node));
}
}
Register in Analyser.cs Rules list.
Commands
- Build:
dotnet build scripts.sln - Test:
dotnet test - Single test:
dotnet test --filter "FullyQualifiedName~TestName" - Debug: Run with
-vv(DEBUG) or-vvv(TRACE)
Risk Levels
| Change Type | Risk |
|---|---|
| New rule (read-only) | Low |
| New requirement type | Medium |
| Graph algorithm changes | High — requires tests |
Key Files
Program.cs— entry point, CLI, outputModule/Resolvable/*.cs— dependency resolutionModule/Compiled/*.cs— final representationsAnalyser/Rules/*.cs— static analysis rulesResources/ScriptTemplate.ps1— output template
Non-Obvious Behaviors
- Local module versions fixed to
0.0.1; uniqueness viaComputedHash - Graph topological sort is reversed for embedding order
$Script:EMBEDDED_MODULESincludes root script first$Script:REMOVE_ORDERis reverse topological excluding root
Skills Info
Original Name:compilerAuthor:amtsupport
Download