AI-assisted code generation with historical patterns.
The Pattern Oracle leverages the Temporal AI system (SDS-015) to provide similarity-based recommendations during code generation, helping developers and AI agents learn from historical patterns.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ββββββββββββββββββββ ββββββββββββββββββββ
β Generation β β β Pattern Oracle β
β Planner β β (Temporal AI) β
ββββββββββββββββββββ ββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Vector Store β
β (redb + HNSW) β
ββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Pattern β
β Recommendations β
ββββββββββββββββββββ
1
2
3
4
5
6
7
8
9
10
11
# Initialize the pattern store
just temporal-ai-init
# Query for similar patterns
just temporal-ai-query "payment processing service" 5
# View statistics
just temporal-ai-stats
# Refresh metrics from telemetry
just temporal-ai-refresh-metrics
1
2
3
4
5
6
7
interface PatternRecommendationRequest {
generation_intent: string; // SEAβ’ DSL or natural language
bounded_context: string; // Target bounded context
artifact_type: 'entity' | 'flow' | 'adapter' | 'service' | 'test';
top_k?: number; // Number of results (default: 5)
min_score?: number; // Minimum similarity (default: 0.7)
}
1
2
3
4
5
6
interface PatternRecommendation {
pattern_id: string; // ifl:hash identity
combined_score: number; // Similarity score (0-1)
risk_level: 'Low' | 'Medium' | 'High';
template_path: string; // Path to template
}
1
2
3
4
5
6
7
8
9
10
just temporal-ai-query "create a case management service" 5
# Output:
# ββββββββββββββββββββββ¬ββββββββ¬βββββββββββ¬βββββββββββββββββββββββββββ
# β Pattern ID β Score β Risk β Template β
# ββββββββββββββββββββββΌββββββββΌβββββββββββΌβββββββββββββββββββββββββββ€
# β ifl:abc123... β 0.92 β Low β templates/service/node β
# β ifl:def456... β 0.87 β Low β templates/domain/entity β
# β ifl:ghi789... β 0.76 β Medium β templates/adapter/pg β
# ββββββββββββββββββββββ΄ββββββββ΄βββββββββββ΄βββββββββββββββββββββββββββ
1
2
3
4
5
6
7
8
9
10
11
12
13
from temporal_ai import PatternOracle
oracle = PatternOracle()
recommendations = await oracle.query(
intent="case management service with CQRS",
context="cognitive-extension",
artifact_type="service",
top_k=5
)
for rec in recommendations:
if rec.combined_score >= 0.7:
print(f"Recommended: {rec.template_path}")
The Pattern Oracle learns from successful generations:
1
2
3
4
5
6
1. Developer requests generation
2. Planner queries Pattern Oracle
3. Oracle returns recommendations
4. Generator uses patterns
5. Successful generation recorded
6. Pattern embeddings updated
Flow "RecordPatternUsage" from "CodeGenerator" to "VectorStore"
@rationale "Post-generation hook stores pattern usage for learning"
@cqrs { "kind": "event" }
@outbox { "mode": "required" }
| ID | Invariant | Enforcement |
|---|---|---|
| INV-VP-01 | Pattern recommendations MUST respect LocalFirstPrivacy | Embedding-based queries only |
| INV-VP-02 | Generation MUST record outcomes for learning | Post-gen hook triggers RecordPatternUsage |
| INV-VP-03 | High-risk patterns MUST be flagged | RecommendationSafetyGate (SDS-015) |
Policy "PatternRelevanceThreshold" per Constraint Obligation priority 10 as:
forall r in recommendations:
if r.combined_score >= 0.7 then r.eligible_for_injection = true
Policy "PatternIntegrity" per Constraint Obligation priority 10 as:
forall p in patterns:
exists s in specs: (p.source_spec = s.id)