SDS-027: Isomorphic Semantic Compiler Service
Status: Draft
Version: 1.0
Date: 2025-12-30
Satisfies: PRD-005, ADR-025, ADR-003
Bounded-Context: shared
0. Isomorphism Declaration
| Spec Section |
SEA-DSL Target |
Cardinality |
Verification |
| 2.1 Pipeline |
Flow definition |
1:1 |
Stage names match |
| 3.1 Context |
Entity schema |
1:1 |
Field names + types match |
| 3.2 LogicGate |
Policy nodes |
1:1 |
Boolean expression verbatim |
| 4.1 Gate Defs |
Invariant expressions |
1:1 |
Rules match |
| 6.1-6.3 Data Model |
Entity schemas |
1:1 |
Field names + types match |
| 7. API Contract |
Flow @command/@query |
1:1 |
Input/output schema identical |
0.1 Domain Glossary
| Term |
Definition |
Type |
Canonical? |
| Intention |
Raw user prompt expressing desired outcome |
Entity |
✓ |
| EnrichedPrompt |
Intention with injected context, constraints, and schema |
Entity |
✓ |
| ContextVector |
Composite of semantic memory, temporal state, and causal history |
Value Object |
✓ |
| LogicGate |
Validation checkpoint enforcing an invariant before reification |
Interface |
✓ |
| Reifier |
Component transforming probabilistic LLM output to structured data |
Service |
✓ |
| Artifact |
Structured output with provenance and invariant preservation |
Entity |
✓ |
| Projection |
Transformation of artifact to a specific runtime format |
Algorithm |
✓ |
| GateResult |
Outcome of gate validation (PASS, FAIL, DEFER) |
Value Object |
✓ |
1. System Overview
The Isomorphic Semantic Compiler (ISC) is the Mind of the Cognitive Architecture. It transforms Intention into Artifacts while preserving invariants across the translation.
Unlike traditional compilers that transform source → bytecode, the ISC transforms:
- Intent (Natural Language) → Structured Artifacts (Code, Schema, Contracts)
The “Isomorphism” guarantee: What must remain true survives translation.
2. Core Compilation Model
1
2
| Intention → [Context Injection] → [Logic Gates] → [Reification] → Artifact
I C G R A
|
Formal Definition:
1
| A = R(G(C(I, Spec), Gates))
|
Where:
I: Raw intention (user prompt)
C: Context injection function (enriches with state)
Spec: The structural specification (ERD/Schema)
G: Logic gate validation function
R: Reification function (probabilistic → deterministic)
A: Structured artifact
2.2 Boolean Execution Semantics
The compiler treats execution as a binary state change:
| State |
Meaning |
Representation |
| 0 |
Error / Not-Yet-Executed |
Time-bound (WBS) |
| 1 |
Executed / Reified |
Structure-bound (ERD) |
| -1 |
Invalid / Rejected by Gate |
Violation |
Implication: Time is an error state. Structure is truth. Execution is not a process over time but a phase transition.
3. Core Components
3.1 Context Injector
Purpose: Transform raw intention into enriched prompt with state awareness.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| @dataclass
class ContextVector:
semantic_memory: List[Concept] # Relevant ontology nodes
temporal_state: Dict[str, Any] # Current system state
causal_history: List[Event] # Recent provenance chain
constraint_set: List[Invariant] # Active logic gates
def inject_context(intention: str, spec: Spec, history: EventLog) -> EnrichedPrompt:
"""
C(I, Spec) → I'
No inference without context injection.
"""
vector = ContextVector(
semantic_memory=spec.resolve_concepts(intention),
temporal_state=spec.current_state(),
causal_history=history.recent(limit=10),
constraint_set=spec.active_gates()
)
return EnrichedPrompt(
raw_intention=intention,
context=vector,
schema_constraints=spec.output_schema
)
|
3.2 Logic Gate Validator
Purpose: Filter/validate enriched prompts before reification.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| class LogicGate(ABC):
@abstractmethod
def validate(self, prompt: EnrichedPrompt) -> GateResult:
"""Returns PASS, FAIL, or DEFER (needs human)."""
pass
# Core Gates
class AgencyPreservationGate(LogicGate):
"""Human must approve high-stakes actions."""
def validate(self, prompt: EnrichedPrompt) -> GateResult:
if prompt.is_high_stakes and not prompt.has_human_signature:
return GateResult.DEFER(reason="Requires human approval")
return GateResult.PASS
class StructuralIntegrityGate(LogicGate):
"""Output must conform to schema."""
def validate(self, prompt: EnrichedPrompt) -> GateResult:
if not prompt.output_schema:
return GateResult.FAIL(reason="No output schema defined")
return GateResult.PASS
class ProvenanceGate(LogicGate):
"""Every output must cite its sources."""
def validate(self, prompt: EnrichedPrompt) -> GateResult:
if not prompt.context.causal_history:
return GateResult.FAIL(reason="No provenance chain")
return GateResult.PASS
|
3.3 Reifier
Purpose: Transform probabilistic LLM output into deterministic structured data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| class Reifier:
def reify(
self,
prompt: EnrichedPrompt,
llm_output: str,
substrate: ThermodynamicSubstrate
) -> Union[Artifact, ReificationError]:
"""
R(G(C(I))) → A
Transforms stochastic text into structured artifact.
"""
# Check resource availability
if not substrate.can_afford(prompt.estimated_cost):
return ReificationError("THERMODYNAMIC_CONSTRAINT_VIOLATED")
# Parse output against schema
try:
parsed = prompt.output_schema.parse(llm_output)
except ValidationError as e:
return ReificationError("SCHEMA_VIOLATION", details=str(e))
# Consume substrate
substrate.consume(prompt.actual_cost)
# Create artifact with provenance
return Artifact(
content=parsed,
schema=prompt.output_schema,
provenance=Provenance(
source_intention=prompt.raw_intention,
context_used=prompt.context,
gates_passed=[g.name for g in prompt.gates_passed],
timestamp=now(),
cost=prompt.actual_cost
)
)
|
4. Invariant Logic Gates (Complete Set)
The compiler enforces these invariants at all times:
4.1 Gate Definitions
| Gate |
Invariant |
Failure Mode |
| No Chatbots |
Output must be structured, not conversational |
REJECT |
| Agency Preservation |
High-stakes requires human signature |
DEFER |
| Deterministic Reification |
Output must parse to schema |
REJECT |
| Provenance Traceability |
Every output cites sources |
REJECT |
| Thermodynamic Feasibility |
Resource cost ≤ available capacity |
DEFER |
| Structural Integrity |
Output matches ontology constraints |
REJECT |
4.2 Gate Pipeline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| class GatePipeline:
gates: List[LogicGate]
def validate(self, prompt: EnrichedPrompt) -> PipelineResult:
for gate in self.gates:
result = gate.validate(prompt)
if result == GateResult.FAIL:
return PipelineResult.REJECTED(gate.name, result.reason)
if result == GateResult.DEFER:
return PipelineResult.DEFERRED(gate.name, result.reason)
prompt.gates_passed.append(gate)
return PipelineResult.PASSED(prompt)
|
5. Multi-Runtime Projection
The compiler projects the same semantic structure to multiple runtimes:
5.1 Runtime Targets
| Runtime |
Projection |
Artifact Type |
| Engineering |
Code generation, API contracts |
TypeScript, OpenAPI |
| Marketing |
Content generation, copy |
Markdown, Email |
| Logistics |
Process automation, BOMs |
YAML, CSV |
| Governance |
Policy documents, compliance |
Markdown, JSON-LD |
5.2 Isomorphic Projection Function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| def project(
artifact: Artifact,
target_runtime: Runtime
) -> ProjectedArtifact:
"""
P: A → A_runtime
Structural invariants preserved across projection.
"""
mapper = RUNTIME_MAPPERS[target_runtime]
projected = mapper.transform(artifact)
# Verify invariants survived
assert artifact.invariants.issubset(projected.invariants), \
"Isomorphism violation: invariants lost in projection"
return projected
|
6. Data Models
6.1 Intention
1
2
3
4
5
6
7
| intention:
id: 'int-uuid'
content: 'Create a user login endpoint'
source: 'user'
timestamp: '2025-12-22T10:00:00Z'
priority: 'HIGH'
target_runtime: 'ENGINEERING'
|
6.2 Enriched Prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| enriched_prompt:
intention_id: 'int-uuid'
raw_content: 'Create a user login endpoint'
context:
semantic_memory:
- concept_id: 'User'
- concept_id: 'Authentication'
- concept_id: 'JWT'
temporal_state:
database_schema_version: 5
auth_library: 'passport-jwt@4.0'
causal_history:
- 'PRD-05 authored'
- 'SDS-02 approved'
constraint_set:
- 'ADR-09: Use JWT for auth'
- 'GATE-001: No plain passwords'
output_schema: 'LoginEndpointSchema'
estimated_cost:
compute: 1500
attention: 0.5
|
6.3 Artifact
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| artifact:
id: 'art-uuid'
type: 'CODE'
runtime: 'ENGINEERING'
content:
language: 'typescript'
code: 'export async function login(req, res) { ... }'
schema_id: 'LoginEndpointSchema'
provenance:
source_intention: 'int-uuid'
gates_passed: ['AGENCY', 'STRUCTURAL', 'PROVENANCE']
timestamp: '2025-12-22T10:01:00Z'
cost:
compute: 1423
attention: 0.45
invariants_preserved:
- 'Uses JWT'
- 'No plain passwords'
- 'Follows ADR-09'
|
7. API Contract
7.1 Compile Intention
Request:
1
2
3
4
5
6
| {
"intention": "Create a user login endpoint with JWT",
"target_runtime": "ENGINEERING",
"output_schema": "LoginEndpointSchema",
"priority": "HIGH"
}
|
Response:
1
2
3
4
5
6
7
8
9
10
11
| {
"compilation_id": "uuid",
"status": "COMPILED",
"artifact": {
"id": "art-uuid",
"type": "CODE",
"content": { "code": "..." }
},
"gates_passed": ["AGENCY", "STRUCTURAL", "PROVENANCE"],
"cost_consumed": { "compute": 1423, "attention": 0.45 }
}
|
7.2 Validate Only (Dry Run)
1
| POST /compiler/validate
|
7.3 Project Artifact
Request:
1
2
3
4
| {
"artifact_id": "art-uuid",
"target_runtime": "MARKETING"
}
|
8. Integration Points
| Component |
Relationship |
| Axiological Constitution |
Provides gate priorities and value weights |
| Evolutionary Kernel |
Receives compilation errors as Trauma signals |
| Thermodynamic Substrate |
Checks/consumes resource capacity |
| Semantic Groomer |
Updates prompts based on compilation failures |
| Knowledge Graph |
Source for semantic memory injection |
ADRs
PRDs
Other SDS
References
10. Semantic Authority Integration
This section defines how the compiler synchronizes with the Semantic Core registry (SDS-002) to prevent stale reification.
10.1. Version Binding
The ContextVector MUST include the semanticVersion at query time:
1
2
3
4
5
6
7
| @dataclass
class ContextVector:
semantic_version: int # Version at query time (REQUIRED)
semantic_memory: List[Concept] # Relevant ontology nodes
temporal_state: Dict[str, Any] # Current system state
causal_history: List[Event] # Recent provenance chain
constraint_set: List[Invariant] # Active logic gates
|
10.2. SemanticVersionGate
Add to the gate pipeline (§4.1):
1
2
3
4
5
6
7
8
9
10
11
12
| class SemanticVersionGate(LogicGate):
"""Ensures compiler operates on current semantic model."""
def validate(self, prompt: EnrichedPrompt) -> GateResult:
current = semantic_core.get_version()
if prompt.context.semantic_version < current:
return GateResult.FAIL(
reason=f"Stale semantic model v{prompt.context.semantic_version}, current is v{current}",
remediation="Re-inject context with current version"
)
return GateResult.PASS
|
| Gate |
Invariant |
Failure Mode |
| Semantic Version |
Context must use current semantic model |
REJECT (re-inject required) |
10.3. Cache Invalidation
The compiler MUST subscribe to governance.semantic-model.updated events and invalidate cached semantic memory when received:
1
2
3
4
5
6
7
8
| @event_handler("governance.semantic-model.updated")
def on_semantic_update(event: SemanticModelUpdatedEvent):
# Invalidate any cached concepts
semantic_cache.invalidate(event.data.changed_concepts)
semantic_cache.invalidate_policies(event.data.changed_policies)
# Log version transition
logger.info(f"Semantic model updated: v{event.data.previous_version} → v{event.data.current_version}")
|
10.4. Provenance Extension
Artifact provenance (§6.3) MUST include the semantic version used:
1
2
3
4
5
6
| artifact:
provenance:
semantic_version_used: 6 # For audit trail
source_intention: 'int-uuid'
gates_passed: ['AGENCY', 'STRUCTURAL', 'PROVENANCE', 'SEMANTIC_VERSION']
timestamp: '2025-12-31T10:01:00Z'
|