feat(concept): heuristic concept compiler (ACR fold-in)

Promotes recurring validated failure->fix patterns into L3 as retrieval-on-demand
concepts. Deterministic core: ConceptCompilerProjection clusters
RetryAttempted->StageCompleted pairs by fingerprint (gate-agnostic), promotes at
N=3 cross-session validated fixes, never-contradicted. ConceptPromotedEvent is the
sole authoritative write (idempotent under replay); ConceptCompilerService appends
it + best-effort injects to L3 (non-authoritative, inv #6). Wired live in
ServerModule.start() on StageCompleted.

Design: docs/plans/2026-07-12-acr-concept-compiler.md

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DhFXmKe4WisSSPf9LrmmTg
This commit is contained in:
2026-07-15 13:35:17 +04:00
parent d69cb12ce9
commit 3a48ecd24f
9 changed files with 525 additions and 0 deletions
@@ -0,0 +1,33 @@
package com.correx.core.events.events
import com.correx.core.events.types.SessionId
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
/**
* A validated failure→fix pattern the heuristic concept compiler has seen resolved reliably enough to
* promote (design 2026-07-12-acr-concept-compiler.md). The only "write" the compiler makes: a
* deterministic rule firing — a [fingerprint] whose validated-fix count crossed the promotion
* threshold, never contradicted — so it needs no assessor gate (invariant #3/#7 hold trivially:
* nothing model-proposed reaches state here).
*
* Read-only over the log otherwise: the promotion is derivable from the RetryAttempted→StageCompleted
* stream, and this event makes the promotion idempotent under replay (the compiler folds already-emitted
* fingerprints into its promoted set and never re-promotes). Best-effort injected into L3 as a
* retrieval-on-demand concept; the L3 write is non-authoritative (invariant #6) — this event is truth.
*/
@Serializable
@SerialName("ConceptPromoted")
data class ConceptPromotedEvent(
// A dedicated system session (ConceptCompilerService.SYSTEM_SESSION) — concepts are cross-session,
// so they live on their own stream rather than polluting any user session's replay.
val sessionId: SessionId,
// Gate-agnostic fingerprint of the recurring failure (see FailureFingerprint).
val fingerprint: String,
// The gate the failure recurred on ("contract" | "review" | "plan-compile" | "lint" | "static" | …).
val gate: String,
// Templated, retrieval-friendly concept text injected into L3.
val conceptText: String,
// Count of validated fixes observed at promotion time (≥ threshold).
val occurrences: Int,
) : EventPayload
@@ -14,6 +14,7 @@ import com.correx.core.events.events.ArtifactValidatedEvent
import com.correx.core.events.events.ArtifactValidatingEvent
import com.correx.core.events.events.BriefEchoMismatchEvent
import com.correx.core.events.events.BriefGroundingCheckedEvent
import com.correx.core.events.events.ConceptPromotedEvent
import com.correx.core.events.events.StaticAnalysisCompletedEvent
import com.correx.core.events.events.ContractGateEvaluatedEvent
import com.correx.core.events.events.PlanLintCompletedEvent
@@ -128,6 +129,7 @@ val eventModule = SerializersModule {
subclass(SessionNamedEvent::class)
subclass(StageFailedEvent::class)
subclass(StageCompletedEvent::class)
subclass(ConceptPromotedEvent::class)
subclass(TransitionExecutedEvent::class)
subclass(ApprovalRequestedEvent::class)
subclass(ApprovalDecisionResolvedEvent::class)
@@ -0,0 +1,27 @@
package com.correx.core.events.serialization
import com.correx.core.events.events.ConceptPromotedEvent
import com.correx.core.events.events.EventPayload
import com.correx.core.events.types.SessionId
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class ConceptPromotedEventSerializationTest {
private val sample = ConceptPromotedEvent(
sessionId = SessionId("__concept_compiler__"),
fingerprint = "1a2b3c",
gate = "lint",
conceptText = "Recurring lint failure (validated-fixed 3x across sessions): detekt: MagicNumber.",
occurrences = 3,
)
@Test
fun `round-trips as polymorphic EventPayload`() {
val encoded = eventJson.encodeToString(EventPayload.serializer(), sample)
assertTrue(encoded.contains("\"type\":\"ConceptPromoted\""), "SerialName must be present: $encoded")
val decoded = eventJson.decodeFromString(EventPayload.serializer(), encoded)
assertEquals(sample, decoded)
}
}