Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
feat: add CompactScoredClaim and compactClaims output mode
riley0227547ad485686b
diff --git a/memory-layer/src/main/scala/ix/memory/context/ContextService.scala b/memory-layer/src/main/scala/ix/memory/context/ContextService.scalaindex 6c9994c8..c885181b 100644--- a/memory-layer/src/main/scala/ix/memory/context/ContextService.scala+++ b/memory-layer/src/main/scala/ix/memory/context/ContextService.scala@@ -108,8 +108,19 @@ class ContextService(decisions: Vector[DecisionReport] = allNodes.filter(_.kind == NodeKind.Decision).map(toDecisionReport(_, rev))intents: Vector[IntentReport] = allNodes.filter(_.kind == NodeKind.Intent).map(toIntentReport)+ // Shape claims and compactClaims based on depth+ claimsOut: List[ScoredClaim] = effectiveDepth match {+ case "compact" => Nil+ case _ => rankedTrimmed.toList+ }+ compactClaimsOut: List[CompactScoredClaim] = effectiveDepth match {+ case "full" => Nil+ case _ => rankedTrimmed.map(_.toCompact).toList+ }+} yield StructuredContext(- claims = rankedTrimmed.toList,+ claims = claimsOut,+ compactClaims = compactClaimsOut,conflicts = conflictsTrimmed.toList,decisions = decisions.toList,intents = intents.toList,diff --git a/memory-layer/src/main/scala/ix/memory/model/StructuredContext.scala b/memory-layer/src/main/scala/ix/memory/model/StructuredContext.scalaindex a4cf87f4..967a382f 100644--- a/memory-layer/src/main/scala/ix/memory/model/StructuredContext.scala+++ b/memory-layer/src/main/scala/ix/memory/model/StructuredContext.scala@@ -1,14 +1,73 @@package ix.memory.model-import io.circe.{Decoder, Encoder}+import io.circe.{Decoder, Encoder, Json}import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}+import io.circe.syntax._++final case class CompactScoredClaim(+ entityId: NodeId,+ field: String,+ value: Json,+ score: Double,+ confidence: CompactConfidence,+ path: Option[String],+ lineRange: Option[(Int, Int)]+)++object CompactScoredClaim {++ /** Truncate string JSON values longer than 120 characters. */+ def truncateValue(v: Json): Json =+ v.asString match {+ case Some(s) if s.length > 120 => Json.fromString(s.take(120) + "...")+ case _ => v+ }++ implicit val encoder: Encoder[CompactScoredClaim] = Encoder.instance { csc =>+ val fields = List(+ "entityId" -> csc.entityId.asJson,+ "field" -> Json.fromString(csc.field),+ "value" -> truncateValue(csc.value),+ "score" -> Json.fromDoubleOrNull(csc.score),+ "confidence" -> csc.confidence.asJson+ ) +++ csc.path.map(p => "path" -> Json.fromString(p)).toList +++ csc.lineRange.map { case (s, e) => "lineRange" -> Json.arr(Json.fromInt(s), Json.fromInt(e)) }.toList++ Json.obj(fields: _*)+ }++ implicit val decoder: Decoder[CompactScoredClaim] = Decoder.instance { c =>+ for {+ entityId <- c.get[NodeId]("entityId")+ field <- c.get[String]("field")+ value <- c.get[Json]("value")+ score <- c.get[Double]("score")+ confidence <- c.get[CompactConfidence]("confidence")+ path <- c.get[Option[String]]("path")+ lineRange <- c.downField("lineRange").as[Option[List[Int]]].map(_.collect {+ case List(s, e) => (s, e)+ })+ } yield CompactScoredClaim(entityId, field, value, score, confidence, path, lineRange)+ }+}final case class ScoredClaim(claim: Claim,confidence: ConfidenceBreakdown,relevance: Double = 1.0,finalScore: Double = 0.0-)+) {+ def toCompact: CompactScoredClaim = CompactScoredClaim(+ entityId = claim.entityId,+ field = claim.statement,+ value = claim.value,+ score = finalScore,+ confidence = confidence.toCompact,+ path = Some(claim.provenance.sourceUri),+ lineRange = None+ )+}object ScoredClaim {implicit val encoder: Encoder[ScoredClaim] = deriveEncoder[ScoredClaim]@@ -94,6 +153,7 @@ object EdgeSummary {final case class StructuredContext(claims: List[ScoredClaim],+ compactClaims: List[CompactScoredClaim] = Nil,conflicts: List[ConflictReport],decisions: List[DecisionReport],intents: List[IntentReport],@@ -110,6 +170,7 @@ object StructuredContext {implicit val decoder: Decoder[StructuredContext] = Decoder.instance { c =>for {claims <- c.getOrElse[List[ScoredClaim]]("claims")(Nil)+ compactClaims <- c.getOrElse[List[CompactScoredClaim]]("compactClaims")(Nil)conflicts <- c.getOrElse[List[ConflictReport]]("conflicts")(Nil)decisions <- c.getOrElse[List[DecisionReport]]("decisions")(Nil)intents <- c.getOrElse[List[IntentReport]]("intents")(Nil)@@ -120,6 +181,7 @@ object StructuredContext {metadata <- c.get[ContextMetadata]("metadata")} yield StructuredContext(claims = claims,+ compactClaims = compactClaims,conflicts = conflicts,decisions = decisions,intents = intents,diff --git a/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala b/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scalaindex 3e233ddf..269225ca 100644--- a/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala+++ b/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala@@ -278,4 +278,35 @@ class ModelSpec extends AnyFlatSpec with Matchers {compact.nonTrivialFactors should have size 2compact.nonTrivialFactors.map(_._1) should contain allOf ("recency", "corroboration")}++ // ── CompactScoredClaim ────────────────────────────────────────────++ "ScoredClaim" should "produce compact scored claim with summary fields" in {+ import java.time.Instant+ val claim = Claim(+ id = ClaimId(UUID.randomUUID()),+ entityId = NodeId(UUID.randomUUID()),+ statement = "content",+ value = Json.fromString("a very long content blob that should not appear in compact mode but this is just test data"),+ confidence = Some(0.9),+ status = ClaimStatus.Active,+ provenance = Provenance("src/main/Foo.scala", Some("abc123"), "tree-sitter/1.0", SourceType.Code, Instant.now()),+ createdRev = Rev(1L),+ deletedRev = None+ )+ val breakdown = ConfidenceBreakdown(+ baseAuthority = Factor(0.9, "Code"),+ verification = Factor(1.0, "n/a"),+ recency = Factor(1.0, "fresh"),+ corroboration = Factor(1.0, "single"),+ conflictPenalty = Factor(1.0, "none"),+ intentAlignment = Factor(1.0, "none")+ )+ val scored = ScoredClaim(claim, breakdown, 1.0, 0.9)+ val compact = scored.toCompact+ compact.entityId shouldBe claim.entityId+ compact.field shouldBe "content"+ compact.score shouldBe 0.9+ compact.path shouldBe Some("src/main/Foo.scala")+ }}