Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add Forge reference and update audit status
Yuechen Li4cb16d3c8276
diff --git a/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentConcepts.cs b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentConcepts.csnew file mode 100644index 00000000..cc908415--- /dev/null+++ b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentConcepts.cs@@ -0,0 +1,32 @@+namespace Aetheris.Forge.Abstractions.FirmamentInterop;++public sealed record ConceptId(string Family, string Concept)+{+ public override string ToString() => $"{Family}<{Concept}>";+}++public enum FirmamentConceptApplicationKind+{+ Manufacturing,+ Feature+}++public sealed record FirmamentConceptApplicationView(+ FirmamentConceptApplicationKind Kind,+ string? Name,+ ConceptId ConceptId,+ IReadOnlyList<FirmamentConceptFieldView> Fields,+ FirmamentSourceSpan? SourceSpan);++public sealed record FirmamentConceptFieldView(+ string Name,+ FirmamentFieldKind Kind,+ FirmamentValue? Value,+ string? TargetSource,+ FirmamentSourceSpan? SourceSpan);++public enum FirmamentFieldKind+{+ Value,+ Target+}diff --git a/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentDiagnostics.cs b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentDiagnostics.csnew file mode 100644index 00000000..79b209f6--- /dev/null+++ b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentDiagnostics.cs@@ -0,0 +1,16 @@+namespace Aetheris.Forge.Abstractions.FirmamentInterop;++public enum FirmamentDiagnosticSeverity+{+ Info,+ Warning,+ Fatal+}++public sealed record FirmamentDiagnostic(+ string Code,+ FirmamentDiagnosticSeverity Severity,+ string Message,+ FirmamentSourceSpan? SourceSpan = null,+ string? Target = null,+ string? FieldName = null);diff --git a/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentValues.cs b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentValues.csnew file mode 100644index 00000000..7d501c98--- /dev/null+++ b/Aetheris.Forge/Abstractions/FirmamentInterop/FirmamentValues.cs@@ -0,0 +1,53 @@+namespace Aetheris.Forge.Abstractions.FirmamentInterop;++public interface IFirmamentVariables+{+ bool TryGet(string name, out FirmamentValue value);+ FirmamentValue GetRequired(string name);+ IReadOnlyList<FirmamentVariable> All { get; }+}++public sealed record FirmamentVariable(+ string Name,+ FirmamentValue Value,+ FirmamentSourceSpan? SourceSpan);++public abstract record FirmamentValue(string Name, FirmamentValueKind Kind)+{+ public FirmamentTolerance? Tolerance { get; init; }+ public FirmamentSourceSpan? SourceSpan { get; init; }+}++public enum FirmamentValueKind+{+ Int,+ Float,+ Length,+ Angle,+ String,+ Bool+}++public sealed record FirmamentScalarValue(+ string Name,+ FirmamentValueKind Kind,+ object? Nominal,+ double? NumericValue,+ string? Unit) : FirmamentValue(Name, Kind);++public sealed record FirmamentTolerance(+ FirmamentToleranceKind Kind,+ double Plus,+ double Minus,+ string? Unit,+ FirmamentValueKind ValueKind,+ FirmamentSourceSpan? SourceSpan);++public enum FirmamentToleranceKind+{+ None,+ Bilateral,+ Asymmetric+}++public sealed record FirmamentSourceSpan(int Start, int Length);diff --git a/Aetheris.Forge/Abstractions/FirmamentInterop/ForgeConceptRegistry.cs b/Aetheris.Forge/Abstractions/FirmamentInterop/ForgeConceptRegistry.csnew file mode 100644index 00000000..47807fb4--- /dev/null+++ b/Aetheris.Forge/Abstractions/FirmamentInterop/ForgeConceptRegistry.cs@@ -0,0 +1,111 @@+namespace Aetheris.Forge.Abstractions.FirmamentInterop;++public interface IForgeConcept+{+ ConceptId Id { get; }+ void Define(ConceptSchemaBuilder schema);+ IEnumerable<FirmamentDiagnostic> Validate(ConceptValidationContext context);+}++public interface IForgeConceptPack+{+ string Id { get; }+ Version Version { get; }+ void Register(IForgeRegistry registry);+}++public interface IForgeRegistry+{+ void Register(IForgeConcept concept);+ bool TryResolve(ConceptId id, out IForgeConcept concept);+}++public sealed class ForgeConceptRegistry : IForgeRegistry+{+ private readonly Dictionary<ConceptId, IForgeConcept> concepts = new();++ public void Register(IForgeConcept concept)+ {+ ArgumentNullException.ThrowIfNull(concept);+ if (concepts.ContainsKey(concept.Id))+ {+ throw new InvalidOperationException($"Forge concept '{concept.Id}' is already registered.");+ }++ concepts.Add(concept.Id, concept);+ }++ public bool TryResolve(ConceptId id, out IForgeConcept concept) => concepts.TryGetValue(id, out concept!);+}++public sealed class ConceptSchemaBuilder+{+ private readonly Dictionary<string, ConceptSchemaField> fields = new(StringComparer.Ordinal);++ public IReadOnlyList<ConceptSchemaField> Fields => fields.Values.OrderBy(schemaField => schemaField.Name, StringComparer.Ordinal).ToArray();++ public ConceptSchemaFieldBuilder RequiredTarget(string name) => Add(name, ConceptSchemaValueKind.Target);+ public ConceptSchemaFieldBuilder RequiredLength(string name) => Add(name, ConceptSchemaValueKind.Length);+ public ConceptSchemaFieldBuilder RequiredAngle(string name) => Add(name, ConceptSchemaValueKind.Angle);+ public ConceptSchemaFieldBuilder RequiredString(string name) => Add(name, ConceptSchemaValueKind.String);+ public ConceptSchemaFieldBuilder RequiredBool(string name) => Add(name, ConceptSchemaValueKind.Bool);+ public ConceptSchemaFieldBuilder RequiredFloat(string name) => Add(name, ConceptSchemaValueKind.Float);+ public ConceptSchemaFieldBuilder RequiredInt(string name) => Add(name, ConceptSchemaValueKind.Int);++ private ConceptSchemaFieldBuilder Add(string name, ConceptSchemaValueKind kind)+ {+ ArgumentException.ThrowIfNullOrWhiteSpace(name);+ if (fields.ContainsKey(name))+ {+ throw new InvalidOperationException($"Concept schema field '{name}' is already defined.");+ }++ fields.Add(name, new ConceptSchemaField(name, kind, true, false));+ return new ConceptSchemaFieldBuilder(this, name);+ }++ internal void RequireTolerance(string name)+ {+ var field = fields[name];+ fields[name] = field with { RequiresTolerance = true };+ }+}++public sealed class ConceptSchemaFieldBuilder+{+ private readonly ConceptSchemaBuilder builder;+ private readonly string name;++ internal ConceptSchemaFieldBuilder(ConceptSchemaBuilder builder, string name)+ {+ this.builder = builder;+ this.name = name;+ }++ public ConceptSchemaFieldBuilder RequireTolerance()+ {+ builder.RequireTolerance(name);+ return this;+ }+}++public sealed record ConceptSchemaField(+ string Name,+ ConceptSchemaValueKind Kind,+ bool Required,+ bool RequiresTolerance);++public enum ConceptSchemaValueKind+{+ Target,+ Length,+ Angle,+ String,+ Bool,+ Float,+ Int+}++public sealed record ConceptValidationContext(+ FirmamentConceptApplicationView Application,+ IFirmamentVariables Variables);diff --git a/Aetheris.Kernel.Firmament.Tests/ForgeCsA1InteropTests.cs b/Aetheris.Kernel.Firmament.Tests/ForgeCsA1InteropTests.csnew file mode 100644index 00000000..f375f3df--- /dev/null+++ b/Aetheris.Kernel.Firmament.Tests/ForgeCsA1InteropTests.cs@@ -0,0 +1,255 @@+using System.Text.Json;+using Aetheris.Forge.Abstractions.FirmamentInterop;+using Aetheris.Kernel.Firmament.FirmamentV2;+using Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop;+using InteropSourceSpan = Aetheris.Forge.Abstractions.FirmamentInterop.FirmamentSourceSpan;++namespace Aetheris.Kernel.Firmament.Tests;++public sealed class ForgeCsA1InteropTests+{+ [Fact]+ public void ForgeCsA1_FirmamentVariables_InteropPreservesTopLevelAndRecordValues()+ {+ var document = ParseDocument("""+ model VariablesInterop {+ units mm+ solid part: Box { size: [100, 60, 10] }++ let holeDiameter: length = 6.0mm tol 0.05mm++ let MountingPattern {+ spacingX: length = 80.0mm tol +0.10mm -0.05mm+ draftAngle: angle = 90deg+ holeCount: int = 4+ label: string = "A"+ inspectionRequired: bool = true+ }+ }+ """);++ var variables = new FirmamentV2VariablesAdapter(document);++ Assert.True(variables.TryGet("holeDiameter", out var holeDiameter));+ var holeDiameterValue = Assert.IsType<FirmamentScalarValue>(holeDiameter);+ Assert.Equal(FirmamentValueKind.Length, holeDiameterValue.Kind);+ Assert.Equal(6.0d, holeDiameterValue.NumericValue);+ Assert.Equal("mm", holeDiameterValue.Unit);+ Assert.NotNull(holeDiameterValue.SourceSpan);+ AssertTolerance(holeDiameterValue.Tolerance, FirmamentToleranceKind.Bilateral, 0.05d, 0.05d, "mm", FirmamentValueKind.Length);++ Assert.True(variables.TryGet("MountingPattern.spacingX", out var spacingX));+ var spacingXValue = Assert.IsType<FirmamentScalarValue>(spacingX);+ Assert.Equal(80.0d, spacingXValue.NumericValue);+ Assert.Equal("mm", spacingXValue.Unit);+ AssertTolerance(spacingXValue.Tolerance, FirmamentToleranceKind.Asymmetric, 0.10d, 0.05d, "mm", FirmamentValueKind.Length);++ Assert.True(variables.TryGet("MountingPattern.draftAngle", out var angle));+ var angleValue = Assert.IsType<FirmamentScalarValue>(angle);+ Assert.Equal(FirmamentValueKind.Angle, angleValue.Kind);+ Assert.Equal(90.0d, angleValue.NumericValue);+ Assert.Equal("deg", angleValue.Unit);++ Assert.True(variables.TryGet("MountingPattern.holeCount", out var count));+ Assert.Equal(4, Assert.IsType<FirmamentScalarValue>(count).Nominal);++ Assert.True(variables.TryGet("MountingPattern.label", out var label));+ Assert.Equal("A", Assert.IsType<FirmamentScalarValue>(label).Nominal);++ Assert.True(variables.TryGet("MountingPattern.inspectionRequired", out var enabled));+ Assert.Equal(true, Assert.IsType<FirmamentScalarValue>(enabled).Nominal);++ Assert.Contains(variables.All, variable => variable.Name == "holeDiameter");+ Assert.Contains(variables.All, variable => variable.Name == "MountingPattern.spacingX");+ Assert.Contains(variables.All, variable => variable.Name == "MountingPattern.draftAngle");+ Assert.Contains(variables.All, variable => variable.Name == "MountingPattern.holeCount");+ Assert.False(variables.TryGet("missingVariable", out _));++ var missing = Assert.Throws<KeyNotFoundException>(() => variables.GetRequired("missingVariable"));+ Assert.Equal("Firmament variable 'missingVariable' was not found.", missing.Message);+ }++ [Fact]+ public void ForgeCsA1_ConceptApplication_InteropPreservesProcessAndHoleConcepts()+ {+ var document = ParseFixture("Language/valid/concept-applications-forge.valid.firmfixture");++ var manufacturing = FirmamentV2ConceptApplicationAdapter.Adapt(Assert.Single(document.ManufacturingConcepts!));+ Assert.Equal(FirmamentConceptApplicationKind.Manufacturing, manufacturing.Kind);+ Assert.Equal(new ConceptId("process", "CNC"), manufacturing.ConceptId);+ Assert.Equal("process<CNC>", manufacturing.ConceptId.ToString());+ Assert.NotNull(manufacturing.SourceSpan);++ var processMaterial = Assert.Single(manufacturing.Fields, field => field.Name == "material");+ Assert.Equal(FirmamentFieldKind.Value, processMaterial.Kind);+ Assert.Equal("Aluminum6061", Assert.IsType<FirmamentScalarValue>(processMaterial.Value).Nominal);++ var feature = FirmamentV2ConceptApplicationAdapter.Adapt(Assert.Single(document.FeatureConcepts!));+ Assert.Equal(FirmamentConceptApplicationKind.Feature, feature.Kind);+ Assert.Equal("mountHole", feature.Name);+ Assert.Equal(new ConceptId("hole", "Countersink"), feature.ConceptId);+ Assert.Equal("hole<Countersink>", feature.ConceptId.ToString());+ Assert.NotNull(feature.SourceSpan);++ var target = Assert.Single(feature.Fields, field => field.Name == "target");+ Assert.Equal(FirmamentFieldKind.Target, target.Kind);+ Assert.Equal("part.region(\"mountHoleA\")", target.TargetSource);+ Assert.NotNull(target.SourceSpan);++ var diameter = Assert.Single(feature.Fields, field => field.Name == "diameter");+ var diameterValue = Assert.IsType<FirmamentScalarValue>(diameter.Value);+ Assert.Equal(FirmamentValueKind.Length, diameterValue.Kind);+ Assert.Equal(6.0d, diameterValue.NumericValue);+ Assert.Equal("mm", diameterValue.Unit);+ AssertTolerance(diameterValue.Tolerance, FirmamentToleranceKind.Bilateral, 0.05d, 0.05d, "mm", FirmamentValueKind.Length);++ var countersinkDiameter = Assert.Single(feature.Fields, field => field.Name == "countersinkDiameter");+ var countersinkValue = Assert.IsType<FirmamentScalarValue>(countersinkDiameter.Value);+ Assert.Equal(10.0d, countersinkValue.NumericValue);+ AssertTolerance(countersinkValue.Tolerance, FirmamentToleranceKind.Bilateral, 0.10d, 0.10d, "mm", FirmamentValueKind.Length);++ var angle = Assert.Single(feature.Fields, field => field.Name == "angle");+ var angleValue = Assert.IsType<FirmamentScalarValue>(angle.Value);+ Assert.Equal(FirmamentValueKind.Angle, angleValue.Kind);+ Assert.Equal(90.0d, angleValue.NumericValue);+ Assert.Equal("deg", angleValue.Unit);+ }++ [Fact]+ public void ForgeCsA1_ConceptIdAndRegistry_InteropAreUsableInProcess()+ {+ var registry = new ForgeConceptRegistry();+ var concept = new FakeConcept(new ConceptId("hole", "Countersink"));++ registry.Register(concept);++ Assert.True(registry.TryResolve(new ConceptId("hole", "Countersink"), out var resolved));+ Assert.Same(concept, resolved);++ var duplicate = Assert.Throws<InvalidOperationException>(() => registry.Register(new FakeConcept(new ConceptId("hole", "Countersink"))));+ Assert.Equal("Forge concept 'hole<Countersink>' is already registered.", duplicate.Message);++ var schema = new ConceptSchemaBuilder();+ concept.Define(schema);+ Assert.Collection(+ schema.Fields,+ field =>+ {+ Assert.Equal("angle", field.Name);+ Assert.Equal(ConceptSchemaValueKind.Angle, field.Kind);+ Assert.False(field.RequiresTolerance);+ },+ field =>+ {+ Assert.Equal("diameter", field.Name);+ Assert.Equal(ConceptSchemaValueKind.Length, field.Kind);+ Assert.True(field.RequiresTolerance);+ },+ field =>+ {+ Assert.Equal("target", field.Name);+ Assert.Equal(ConceptSchemaValueKind.Target, field.Kind);+ Assert.False(field.RequiresTolerance);+ });+ }++ [Fact]+ public void ForgeCsA1_Diagnostics_InteropPreservesSeverityAndMetadata()+ {+ var sourceSpan = new InteropSourceSpan(12, 5);+ var diagnostic = new FirmamentDiagnostic(+ "forge-cs-a1-probe",+ FirmamentDiagnosticSeverity.Warning,+ "Probe message",+ sourceSpan,+ "part.region(\"mountHoleA\")",+ "diameter");++ Assert.Equal(FirmamentDiagnosticSeverity.Warning, diagnostic.Severity);+ Assert.Equal(sourceSpan, diagnostic.SourceSpan);+ Assert.Equal("part.region(\"mountHoleA\")", diagnostic.Target);+ Assert.Equal("diameter", diagnostic.FieldName);++ var json = JsonSerializer.Serialize(diagnostic);+ Assert.Contains("\"Severity\":1", json, StringComparison.Ordinal);+ var roundTrip = JsonSerializer.Deserialize<FirmamentDiagnostic>(json);+ Assert.NotNull(roundTrip);+ Assert.Equal(diagnostic.Target, roundTrip.Target);+ Assert.Equal(diagnostic.FieldName, roundTrip.FieldName);++ var adapted = FirmamentV2DiagnosticAdapter.FromParserDiagnosticCode(+ FirmamentV2Parser.ToleranceDroppedThroughArithmetic,+ new FirmamentV2SourceSpan(40, 8),+ "part.region(\"mountHoleA\")",+ "diameter");++ Assert.Equal(FirmamentDiagnosticSeverity.Warning, adapted.Severity);+ Assert.Equal("part.region(\"mountHoleA\")", adapted.Target);+ Assert.Equal("diameter", adapted.FieldName);+ Assert.Equal(new InteropSourceSpan(40, 8), adapted.SourceSpan);+ }++ private static FirmamentV2Document ParseDocument(string source)+ {+ var result = FirmamentV2Parser.Parse(source);+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ return result.Document!;+ }++ private static FirmamentV2Document ParseFixture(string relative)+ {+ var result = FirmamentV2Parser.Parse(File.ReadAllText(Path.Combine(FindRepoRoot(), "fixtures", "FirmamentV2", relative)));+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ return result.Document!;+ }++ private static string FindRepoRoot()+ {+ var dir = new DirectoryInfo(AppContext.BaseDirectory);+ while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "Aetheris.slnx")))+ {+ dir = dir.Parent;+ }++ return dir?.FullName ?? throw new InvalidOperationException("Could not find repo root.");+ }++ private static void AssertTolerance(+ FirmamentTolerance? actual,+ FirmamentToleranceKind kind,+ double plus,+ double minus,+ string unit,+ FirmamentValueKind valueKind)+ {+ Assert.NotNull(actual);+ Assert.Equal(kind, actual.Kind);+ Assert.Equal(plus, actual.Plus);+ Assert.Equal(minus, actual.Minus);+ Assert.Equal(unit, actual.Unit);+ Assert.Equal(valueKind, actual.ValueKind);+ Assert.NotNull(actual.SourceSpan);+ }++ private sealed class FakeConcept : IForgeConcept+ {+ public FakeConcept(ConceptId id)+ {+ Id = id;+ }++ public ConceptId Id { get; }++ public void Define(ConceptSchemaBuilder schema)+ {+ schema.RequiredTarget("target");+ schema.RequiredLength("diameter").RequireTolerance();+ schema.RequiredAngle("angle");+ }++ public IEnumerable<FirmamentDiagnostic> Validate(ConceptValidationContext context)+ {+ yield break;+ }+ }+}diff --git a/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj b/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csprojindex c1a05ede..93cf8847 100644--- a/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj+++ b/Aetheris.Kernel.Firmament/Aetheris.Kernel.Firmament.csproj@@ -8,5 +8,6 @@<ItemGroup><ProjectReference Include="..\Aetheris.Kernel.Core\Aetheris.Kernel.Core.csproj" /><ProjectReference Include="..\Aetheris.Kernel.StandardLibrary\Aetheris.Kernel.StandardLibrary.csproj" />+ <ProjectReference Include="..\Aetheris.Forge\Aetheris.Forge.csproj" /></ItemGroup></Project>diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2ConceptApplicationAdapter.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2ConceptApplicationAdapter.csnew file mode 100644index 00000000..87a4fff4--- /dev/null+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2ConceptApplicationAdapter.cs@@ -0,0 +1,55 @@+using Aetheris.Forge.Abstractions.FirmamentInterop;++namespace Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop;++public static class FirmamentV2ConceptApplicationAdapter+{+ public static FirmamentConceptApplicationView Adapt(FirmamentV2ManufacturingConceptDeclaration declaration)+ {+ ArgumentNullException.ThrowIfNull(declaration);+ return new FirmamentConceptApplicationView(+ FirmamentConceptApplicationKind.Manufacturing,+ null,+ AdaptConceptId(declaration.Application),+ AdaptFields(declaration.BoundFields ?? []),+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(declaration.SourceSpan));+ }++ public static FirmamentConceptApplicationView Adapt(FirmamentV2FeatureConceptDeclaration declaration)+ {+ ArgumentNullException.ThrowIfNull(declaration);+ return new FirmamentConceptApplicationView(+ FirmamentConceptApplicationKind.Feature,+ declaration.Name,+ AdaptConceptId(declaration.Application),+ AdaptFields(declaration.BoundFields ?? []),+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(declaration.SourceSpan));+ }++ public static ConceptId AdaptConceptId(FirmamentV2ConceptApplication application)+ {+ ArgumentNullException.ThrowIfNull(application);+ return new ConceptId(application.FamilyName, application.ConceptName);+ }++ public static FirmamentConceptFieldView Adapt(FirmamentV2BoundConceptField field)+ {+ ArgumentNullException.ThrowIfNull(field);+ return field.TargetSource is not null+ ? new FirmamentConceptFieldView(+ field.Name,+ FirmamentFieldKind.Target,+ null,+ field.TargetSource,+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(field.Field.SourceSpan))+ : new FirmamentConceptFieldView(+ field.Name,+ FirmamentFieldKind.Value,+ field.BoundValue is null ? null : FirmamentV2InteropValueAdapter.AdaptValue(field.Name, field.BoundValue),+ null,+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(field.Field.SourceSpan));+ }++ private static IReadOnlyList<FirmamentConceptFieldView> AdaptFields(IReadOnlyList<FirmamentV2BoundConceptField> fields) =>+ fields.Select(Adapt).OrderBy(field => field.Name, StringComparer.Ordinal).ToArray();+}diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.csnew file mode 100644index 00000000..5a6f6540--- /dev/null+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2DiagnosticAdapter.cs@@ -0,0 +1,49 @@+using Aetheris.Forge.Abstractions.FirmamentInterop;++namespace Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop;++public static class FirmamentV2DiagnosticAdapter+{+ public static FirmamentDiagnostic FromValidationDiagnostic(+ FirmamentV2ValidationDiagnostic diagnostic,+ FirmamentV2SourceSpan? sourceSpan = null,+ string? target = null,+ string? fieldName = null)+ {+ ArgumentNullException.ThrowIfNull(diagnostic);+ return new FirmamentDiagnostic(+ diagnostic.Code,+ diagnostic.Severity switch+ {+ "fatal" => FirmamentDiagnosticSeverity.Fatal,+ "warning" => FirmamentDiagnosticSeverity.Warning,+ _ => FirmamentDiagnosticSeverity.Info+ },+ diagnostic.Message,+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(sourceSpan),+ target,+ fieldName);+ }++ public static FirmamentDiagnostic FromParserDiagnosticCode(+ string diagnosticCode,+ FirmamentV2SourceSpan? sourceSpan = null,+ string? target = null,+ string? fieldName = null) =>+ new(+ diagnosticCode,+ FirmamentV2Parser.IsFatalDiagnosticCode(diagnosticCode) ? FirmamentDiagnosticSeverity.Fatal : FirmamentDiagnosticSeverity.Warning,+ MessageFor(diagnosticCode),+ FirmamentV2InteropValueAdapter.AdaptSourceSpan(sourceSpan),+ target,+ fieldName);++ private static string MessageFor(string diagnosticCode) => diagnosticCode switch+ {+ FirmamentV2Parser.PmiDimensionMissingTolerance => "PMI dimension resolves to a value without tolerance evidence.",+ FirmamentV2Parser.ConceptMissingRequiredField => "Forge concept application is missing a required descriptor field.",+ FirmamentV2Parser.PmiUnknownDatum => "PMI relation references an unknown datum.",+ FirmamentV2Parser.ToleranceDroppedThroughArithmetic => "A toleranced value was used in arithmetic and only the nominal value was preserved.",+ _ => diagnosticCode+ };+}diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2InteropValueAdapter.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2InteropValueAdapter.csnew file mode 100644index 00000000..d8dabad4--- /dev/null+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2InteropValueAdapter.cs@@ -0,0 +1,72 @@+using Aetheris.Forge.Abstractions.FirmamentInterop;+using InteropSourceSpan = Aetheris.Forge.Abstractions.FirmamentInterop.FirmamentSourceSpan;++namespace Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop;++internal static class FirmamentV2InteropValueAdapter+{+ public static FirmamentVariable AdaptVariable(string name, FirmamentV2BoundLet boundLet) =>+ new(name, AdaptValue(name, boundLet), AdaptSourceSpan(boundLet.SourceSpan));++ public static FirmamentValue AdaptValue(string name, FirmamentV2BoundLet boundLet) =>+ AdaptValue(name, boundLet.Value, boundLet.Tolerance, boundLet.SourceSpan);++ public static FirmamentValue AdaptValue(string name, FirmamentV2BoundExpression expression) =>+ AdaptValue(name, expression.Value, expression.AliasTolerance, expression.SourceSpan);++ private static FirmamentValue AdaptValue(string name, FirmamentV2LiteralValue literal, FirmamentV2Tolerance? tolerance, FirmamentV2SourceSpan sourceSpan)+ {+ return new FirmamentScalarValue(+ name,+ AdaptKind(literal.Type),+ literal.Value,+ AdaptNumericValue(literal),+ literal.Unit)+ {+ Tolerance = AdaptTolerance(tolerance),+ SourceSpan = AdaptSourceSpan(sourceSpan)+ };+ }++ public static FirmamentTolerance? AdaptTolerance(FirmamentV2Tolerance? tolerance) =>+ tolerance is null+ ? null+ : new(+ tolerance.Kind switch+ {+ FirmamentV2ToleranceKind.Bilateral => FirmamentToleranceKind.Bilateral,+ FirmamentV2ToleranceKind.Asymmetric => FirmamentToleranceKind.Asymmetric,+ _ => FirmamentToleranceKind.None+ },+ tolerance.Plus,+ tolerance.Minus,+ tolerance.Unit,+ AdaptKind(tolerance.Type),+ AdaptSourceSpan(tolerance.SourceSpan));++ public static InteropSourceSpan? AdaptSourceSpan(FirmamentV2SourceSpan? sourceSpan) =>+ sourceSpan is null ? null : new InteropSourceSpan(sourceSpan.Start, sourceSpan.Length);++ public static FirmamentValueKind AdaptKind(FirmamentV2PrimitiveType primitiveType) =>+ primitiveType switch+ {+ FirmamentV2PrimitiveType.Int => FirmamentValueKind.Int,+ FirmamentV2PrimitiveType.Float => FirmamentValueKind.Float,+ FirmamentV2PrimitiveType.Length => FirmamentValueKind.Length,+ FirmamentV2PrimitiveType.Angle => FirmamentValueKind.Angle,+ FirmamentV2PrimitiveType.String => FirmamentValueKind.String,+ FirmamentV2PrimitiveType.Bool => FirmamentValueKind.Bool,+ _ => throw new ArgumentOutOfRangeException(nameof(primitiveType), primitiveType, "Unsupported Firmament V2 primitive type.")+ };++ private static double? AdaptNumericValue(FirmamentV2LiteralValue literal) =>+ literal.NumericValue ?? literal.Value switch+ {+ int value => value,+ long value => value,+ float value => value,+ double value => value,+ decimal value => (double)value,+ _ => null+ };+}diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2VariablesAdapter.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2VariablesAdapter.csnew file mode 100644index 00000000..2aa8e44b--- /dev/null+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentInterop/FirmamentV2VariablesAdapter.cs@@ -0,0 +1,55 @@+using Aetheris.Forge.Abstractions.FirmamentInterop;++namespace Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop;++public sealed class FirmamentV2VariablesAdapter : IFirmamentVariables+{+ private readonly IReadOnlyList<FirmamentVariable> all;+ private readonly IReadOnlyDictionary<string, FirmamentVariable> byName;++ public FirmamentV2VariablesAdapter(FirmamentV2Document document)+ {+ ArgumentNullException.ThrowIfNull(document);++ var variables = new List<FirmamentVariable>();+ foreach (var boundLet in document.BoundLets ?? [])+ {+ variables.Add(FirmamentV2InteropValueAdapter.AdaptVariable(boundLet.Name, boundLet));+ }++ foreach (var record in document.BoundLetRecords ?? [])+ {+ foreach (var field in record.Fields.Values.OrderBy(field => field.Name, StringComparer.Ordinal))+ {+ variables.Add(FirmamentV2InteropValueAdapter.AdaptVariable($"{record.Name}.{field.Name}", field));+ }+ }++ all = variables.OrderBy(variable => variable.Name, StringComparer.Ordinal).ToArray();+ byName = all.ToDictionary(variable => variable.Name, StringComparer.Ordinal);+ }++ public IReadOnlyList<FirmamentVariable> All => all;++ public bool TryGet(string name, out FirmamentValue value)+ {+ if (byName.TryGetValue(name, out var variable))+ {+ value = variable.Value;+ return true;+ }++ value = null!;+ return false;+ }++ public FirmamentValue GetRequired(string name)+ {+ if (TryGet(name, out var value))+ {+ return value;+ }++ throw new KeyNotFoundException($"Firmament variable '{name}' was not found.");+ }+}diff --git a/docs/implementation/forge-cs-a0-current-implementation-audit.md b/docs/implementation/forge-cs-a0-current-implementation-audit.mdindex 25aeddef..8bd844ff 100644--- a/docs/implementation/forge-cs-a0-current-implementation-audit.md+++ b/docs/implementation/forge-cs-a0-current-implementation-audit.md@@ -3,6 +3,8 @@Milestone: **FORGE-CS-A0**Scope: audit/design only for the Phase 2 C# interop abstraction layer.+Status note, July 7 2026: **FORGE-CS-A1 has now implemented the first read-only interop facades and V2 adapters described here.** The A0 attachment-point analysis remains the rationale and reference map for those adapters.+Phase 2 doctrine remains:```textdiff --git a/docs/implementation/forge-cs-a1-readonly-interop-facades.md b/docs/implementation/forge-cs-a1-readonly-interop-facades.mdnew file mode 100644index 00000000..2fb872b6--- /dev/null+++ b/docs/implementation/forge-cs-a1-readonly-interop-facades.md@@ -0,0 +1,172 @@+# FORGE-CS-A1 read-only interop facades++Milestone: **FORGE-CS-A1**++Phase 2 doctrine remains:++```text+Firmament remains data.+C# owns logic.+Forge is the interop boundary.+```++## Purpose++FORGE-CS-A1 adds the first read-only C# interop layer over existing Firmament V2 bound state. The goal is to let later Phase 2 concept logic read typed values, concept applications, diagnostics, and registry contracts without duplicating the parser or binder.++This milestone is adapter-only. It does not change Firmament syntax, parser behavior, binder behavior, runtime behavior, CLI behavior, validation-report policy, or AP242 export behavior.++## Types added++Runtime interop contracts now live under:++```text+Aetheris.Forge.Abstractions.FirmamentInterop+```++Added contracts:++- `IFirmamentVariables`+- `FirmamentVariable`+- `FirmamentValue`, `FirmamentScalarValue`, `FirmamentValueKind`+- `FirmamentTolerance`, `FirmamentToleranceKind`+- `FirmamentSourceSpan`+- `ConceptId`+- `FirmamentConceptApplicationView`+- `FirmamentConceptFieldView`+- `FirmamentConceptApplicationKind`+- `FirmamentFieldKind`+- `FirmamentDiagnostic`+- `FirmamentDiagnosticSeverity`+- `IForgeConcept`+- `IForgeConceptPack`+- `IForgeRegistry`+- `ForgeConceptRegistry`+- `ConceptSchemaBuilder`+- `ConceptSchemaField`+- `ConceptValidationContext`++Concrete V2 adapters now live under:++```text+Aetheris.Kernel.Firmament.FirmamentV2.FirmamentInterop+```++Added adapters:++- `FirmamentV2VariablesAdapter`+- `FirmamentV2ConceptApplicationAdapter`+- `FirmamentV2DiagnosticAdapter`++## Adapter attachment points++A1 attaches to existing Phase 1 bound state only:++- `FirmamentV2Document.BoundLets`+- `FirmamentV2Document.BoundLetRecords`+- `FirmamentV2ManufacturingConceptDeclaration`+- `FirmamentV2FeatureConceptDeclaration`+- `FirmamentV2BoundConceptField`+- `FirmamentV2LiteralValue`+- `FirmamentV2Tolerance`+- `FirmamentV2SourceSpan`++No second binder or alternate parse path was added.++## Value and tolerance preservation++`FirmamentV2VariablesAdapter` exposes:++- top-level lets by name such as `holeDiameter`;+- dotted record fields such as `MountingPattern.spacingX`;+- `All` with both top-level names and dotted names.++The adapter preserves:++- primitive kind;+- nominal value;+- numeric value when available;+- unit text;+- tolerance kind, plus, minus, unit, and value kind;+- source span.++Dimensional values are not flattened to raw `double`. Length and angle values remain typed `FirmamentScalarValue` instances with `Kind`, `Nominal`, `NumericValue`, `Unit`, and optional `Tolerance`.++## Concept application facade++`FirmamentV2ConceptApplicationAdapter` projects current bound concept declarations into read-only views:++- `process<CNC>` becomes `new ConceptId("process", "CNC")`;+- `feature mountHole: hole<Countersink>` becomes a feature application view with `Name = "mountHole"`;+- target fields remain target-source strings;+- value fields remain typed `FirmamentValue` instances;+- aliased tolerance evidence on concept fields is preserved through `BoundValue.AliasTolerance`;+- source spans are carried forward where available.++This facade does not replace `FirmamentV2ForgeConceptRegistry` and does not invoke validators from the CLI.++## Diagnostic facade++`FirmamentDiagnostic` is the new structured diagnostic shape for later A2/A3 work. A1 also adds `FirmamentV2DiagnosticAdapter` helpers to map:++- existing `FirmamentV2ValidationDiagnostic` rows;+- parser diagnostic codes plus fatal/warning classification.++The facade preserves code, severity, message, source span, target metadata, and field metadata.++## Registry contracts++A1 adds the in-process registry contracts plus a minimal `ForgeConceptRegistry` implementation for deterministic registration and lookup inside the current process.++Current behavior:++- registration is explicit and in-process only;+- duplicate `ConceptId` registration throws a deterministic `InvalidOperationException`;+- no external assembly loading occurs;+- no plugin discovery occurs;+- no Roslyn compilation occurs.++`ConceptSchemaBuilder` is intentionally minimal for A1, but already supports:++- required target;+- required length;+- required angle;+- required string;+- required bool;+- required float;+- required int;+- tolerance-required markers.++Schema enforcement is not wired into runtime validation yet.++## Tests++Focused adapter tests were added in:++```text+Aetheris.Kernel.Firmament.Tests/ForgeCsA1InteropTests.cs+```++The tests cover:++- variable interop over top-level lets and dotted record fields;+- value/unit/tolerance/source-span preservation;+- concept application and field adaptation for `process<CNC>` and `hole<Countersink>`;+- in-process registry registration, resolution, and deterministic duplicate behavior;+- diagnostic facade metadata and serialization basics.++## Explicit non-scope++A1 intentionally does not add:++- CLI invocation of C# validators;+- C# validator execution through the validation report;+- plugin loading;+- external assembly loading;+- Roslyn compilation;+- template behavior;+- mutation or source patching;+- parser changes;+- binder changes;+- runtime changes;+- AP242 export changes.