Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix: reconcile data model with design doc (PatchOp, PatchSource, encoding, weights)

riley022747230e35aeff
diff --git a/memory-layer/src/main/scala/ix/memory/model/GraphPatch.scala b/memory-layer/src/main/scala/ix/memory/model/GraphPatch.scala
index e8f7428d..150b629b 100644
--- a/memory-layer/src/main/scala/ix/memory/model/GraphPatch.scala
+++ b/memory-layer/src/main/scala/ix/memory/model/GraphPatch.scala
@@ -8,29 +8,51 @@ import io.circe.syntax._
sealed trait PatchOp
object PatchOp {
- final case class UpsertNode(node: GraphNode) extends PatchOp
- final case class UpsertEdge(edge: GraphEdge) extends PatchOp
- final case class DeleteNode(nodeId: NodeId) extends PatchOp
- final case class DeleteEdge(edgeId: EdgeId) extends PatchOp
- final case class AssertClaim(claim: Claim) extends PatchOp
+ final case class UpsertNode(id: NodeId, kind: NodeKind, name: String, attrs: Map[String, Json]) extends PatchOp
+ final case class UpsertEdge(id: EdgeId, src: NodeId, dst: NodeId, predicate: EdgePredicate, attrs: Map[String, Json]) extends PatchOp
+ final case class DeleteNode(id: NodeId) extends PatchOp
+ final case class DeleteEdge(id: EdgeId) extends PatchOp
+ final case class AssertClaim(entityId: NodeId, field: String, value: Json, confidence: Option[Double]) extends PatchOp
final case class RetractClaim(claimId: ClaimId) extends PatchOp
implicit val encoder: Encoder[PatchOp] = Encoder.instance {
- case UpsertNode(node) => Json.obj("type" -> "UpsertNode".asJson, "node" -> node.asJson)
- case UpsertEdge(edge) => Json.obj("type" -> "UpsertEdge".asJson, "edge" -> edge.asJson)
- case DeleteNode(nodeId) => Json.obj("type" -> "DeleteNode".asJson, "nodeId" -> nodeId.asJson)
- case DeleteEdge(edgeId) => Json.obj("type" -> "DeleteEdge".asJson, "edgeId" -> edgeId.asJson)
- case AssertClaim(claim) => Json.obj("type" -> "AssertClaim".asJson, "claim" -> claim.asJson)
+ case UpsertNode(id, kind, name, attrs) =>
+ Json.obj("type" -> "UpsertNode".asJson, "id" -> id.asJson, "kind" -> kind.asJson, "name" -> name.asJson, "attrs" -> attrs.asJson)
+ case UpsertEdge(id, src, dst, predicate, attrs) =>
+ Json.obj("type" -> "UpsertEdge".asJson, "id" -> id.asJson, "src" -> src.asJson, "dst" -> dst.asJson, "predicate" -> predicate.asJson, "attrs" -> attrs.asJson)
+ case DeleteNode(id) => Json.obj("type" -> "DeleteNode".asJson, "id" -> id.asJson)
+ case DeleteEdge(id) => Json.obj("type" -> "DeleteEdge".asJson, "id" -> id.asJson)
+ case AssertClaim(entityId, field, value, confidence) =>
+ Json.obj("type" -> "AssertClaim".asJson, "entityId" -> entityId.asJson, "field" -> field.asJson, "value" -> value.asJson, "confidence" -> confidence.asJson)
case RetractClaim(claimId) => Json.obj("type" -> "RetractClaim".asJson, "claimId" -> claimId.asJson)
}
implicit val decoder: Decoder[PatchOp] = Decoder.instance { (c: HCursor) =>
c.downField("type").as[String].flatMap {
- case "UpsertNode" => c.downField("node").as[GraphNode].map(UpsertNode)
- case "UpsertEdge" => c.downField("edge").as[GraphEdge].map(UpsertEdge)
- case "DeleteNode" => c.downField("nodeId").as[NodeId].map(DeleteNode)
- case "DeleteEdge" => c.downField("edgeId").as[EdgeId].map(DeleteEdge)
- case "AssertClaim" => c.downField("claim").as[Claim].map(AssertClaim)
+ case "UpsertNode" =>
+ for {
+ id <- c.downField("id").as[NodeId]
+ kind <- c.downField("kind").as[NodeKind]
+ name <- c.downField("name").as[String]
+ attrs <- c.downField("attrs").as[Map[String, Json]]
+ } yield UpsertNode(id, kind, name, attrs)
+ case "UpsertEdge" =>
+ for {
+ id <- c.downField("id").as[EdgeId]
+ src <- c.downField("src").as[NodeId]
+ dst <- c.downField("dst").as[NodeId]
+ predicate <- c.downField("predicate").as[EdgePredicate]
+ attrs <- c.downField("attrs").as[Map[String, Json]]
+ } yield UpsertEdge(id, src, dst, predicate, attrs)
+ case "DeleteNode" => c.downField("id").as[NodeId].map(DeleteNode)
+ case "DeleteEdge" => c.downField("id").as[EdgeId].map(DeleteEdge)
+ case "AssertClaim" =>
+ for {
+ entityId <- c.downField("entityId").as[NodeId]
+ field <- c.downField("field").as[String]
+ value <- c.downField("value").as[Json]
+ confidence <- c.downField("confidence").as[Option[Double]]
+ } yield AssertClaim(entityId, field, value, confidence)
case "RetractClaim" => c.downField("claimId").as[ClaimId].map(RetractClaim)
case other => Left(DecodingFailure(s"Unknown PatchOp type: $other", c.history))
}
@@ -38,8 +60,10 @@ object PatchOp {
}
final case class PatchSource(
- uri: String,
- ref: Option[String]
+ uri: String,
+ sourceHash: Option[String],
+ extractor: String,
+ sourceType: SourceType
)
object PatchSource {
diff --git a/memory-layer/src/main/scala/ix/memory/model/Node.scala b/memory-layer/src/main/scala/ix/memory/model/Node.scala
index f4bb419e..bf482568 100644
--- a/memory-layer/src/main/scala/ix/memory/model/Node.scala
+++ b/memory-layer/src/main/scala/ix/memory/model/Node.scala
@@ -18,27 +18,27 @@ object NodeKind {
case object Endpoint extends NodeKind
private val nameMap: Map[String, NodeKind] = Map(
- "Module" -> Module,
- "File" -> File,
- "Class" -> Class,
- "Function" -> Function,
- "Variable" -> Variable,
- "Config" -> Config,
- "ConfigEntry" -> ConfigEntry,
- "Service" -> Service,
- "Endpoint" -> Endpoint
+ "module" -> Module,
+ "file" -> File,
+ "class" -> Class,
+ "function" -> Function,
+ "variable" -> Variable,
+ "config" -> Config,
+ "config_entry" -> ConfigEntry,
+ "service" -> Service,
+ "endpoint" -> Endpoint
)
implicit val encoder: Encoder[NodeKind] = Encoder[String].contramap {
- case Module => "Module"
- case File => "File"
- case Class => "Class"
- case Function => "Function"
- case Variable => "Variable"
- case Config => "Config"
- case ConfigEntry => "ConfigEntry"
- case Service => "Service"
- case Endpoint => "Endpoint"
+ case Module => "module"
+ case File => "file"
+ case Class => "class"
+ case Function => "function"
+ case Variable => "variable"
+ case Config => "config"
+ case ConfigEntry => "config_entry"
+ case Service => "service"
+ case Endpoint => "endpoint"
}
implicit val decoder: Decoder[NodeKind] = Decoder[String].emap { s =>
diff --git a/memory-layer/src/main/scala/ix/memory/model/Provenance.scala b/memory-layer/src/main/scala/ix/memory/model/Provenance.scala
index ea931763..5934ff30 100644
--- a/memory-layer/src/main/scala/ix/memory/model/Provenance.scala
+++ b/memory-layer/src/main/scala/ix/memory/model/Provenance.scala
@@ -23,35 +23,35 @@ object SourceType {
case Config => 0.85
case Doc => 0.70
case Test => 0.95
- case Schema => 0.90
+ case Schema => 0.85
case Commit => 0.80
- case Comment => 0.60
- case Inferred => 0.50
- case Human => 0.75
+ case Comment => 0.50
+ case Inferred => 0.40
+ case Human => 0.80
}
private val nameMap: Map[String, SourceType] = Map(
- "Code" -> Code,
- "Config" -> Config,
- "Doc" -> Doc,
- "Test" -> Test,
- "Schema" -> Schema,
- "Commit" -> Commit,
- "Comment" -> Comment,
- "Inferred" -> Inferred,
- "Human" -> Human
+ "code" -> Code,
+ "config" -> Config,
+ "doc" -> Doc,
+ "test" -> Test,
+ "schema" -> Schema,
+ "commit" -> Commit,
+ "comment" -> Comment,
+ "inferred" -> Inferred,
+ "human" -> Human
)
implicit val encoder: Encoder[SourceType] = Encoder[String].contramap {
- case Code => "Code"
- case Config => "Config"
- case Doc => "Doc"
- case Test => "Test"
- case Schema => "Schema"
- case Commit => "Commit"
- case Comment => "Comment"
- case Inferred => "Inferred"
- case Human => "Human"
+ case Code => "code"
+ case Config => "config"
+ case Doc => "doc"
+ case Test => "test"
+ case Schema => "schema"
+ case Commit => "commit"
+ case Comment => "comment"
+ case Inferred => "inferred"
+ case Human => "human"
}
implicit val decoder: Decoder[SourceType] = Decoder[String].emap { s =>
diff --git a/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala b/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala
index 7b9539ea..122358a9 100644
--- a/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/model/ModelSpec.scala
@@ -133,53 +133,29 @@ class ModelSpec extends AnyFlatSpec with Matchers {
val edgeId = EdgeId(UUID.randomUUID())
val claimId = ClaimId(UUID.randomUUID())
- val prov = Provenance(
- sourceUri = "git://repo/file.scala",
- sourceHash = Some("def456"),
- extractor = "tree-sitter",
- sourceType = SourceType.Code,
- observedAt = Instant.parse("2025-06-01T12:00:00Z")
- )
+ val dstId = NodeId(UUID.randomUUID())
val ops: Vector[PatchOp] = Vector(
PatchOp.UpsertNode(
- GraphNode(
- id = nodeId,
- kind = NodeKind.Function,
- tenant = tenantId,
- attrs = Json.obj("name" -> Json.fromString("foo")),
- provenance = prov,
- createdRev = Rev(1L),
- deletedRev = None,
- createdAt = Instant.parse("2025-06-01T12:00:00Z"),
- updatedAt = Instant.parse("2025-06-01T12:00:00Z")
- )
+ id = nodeId,
+ kind = NodeKind.Function,
+ name = "foo",
+ attrs = Map("lang" -> Json.fromString("scala"))
),
PatchOp.UpsertEdge(
- GraphEdge(
- id = edgeId,
- src = nodeId,
- dst = NodeId(UUID.randomUUID()),
- predicate = EdgePredicate("CALLS"),
- tenant = tenantId,
- attrs = Json.obj(),
- provenance = prov,
- createdRev = Rev(1L),
- deletedRev = None
- )
+ id = edgeId,
+ src = nodeId,
+ dst = dstId,
+ predicate = EdgePredicate("CALLS"),
+ attrs = Map.empty[String, Json]
),
PatchOp.DeleteNode(nodeId),
PatchOp.DeleteEdge(edgeId),
PatchOp.AssertClaim(
- Claim(
- id = claimId,
- entityId = nodeId,
- statement = "function foo is pure",
- status = ClaimStatus.Active,
- provenance = prov,
- createdRev = Rev(1L),
- deletedRev = None
- )
+ entityId = nodeId,
+ field = "purity",
+ value = Json.fromString("pure"),
+ confidence = Some(0.9)
),
PatchOp.RetractClaim(claimId)
)
@@ -189,7 +165,12 @@ class ModelSpec extends AnyFlatSpec with Matchers {
tenant = tenantId,
actor = "extractor:tree-sitter",
timestamp = Instant.parse("2025-06-01T12:00:00Z"),
- source = PatchSource(uri = "git://repo", ref = Some("main")),
+ source = PatchSource(
+ uri = "git://repo",
+ sourceHash = Some("abc123"),
+ extractor = "tree-sitter",
+ sourceType = SourceType.Code
+ ),
baseRev = Rev(0L),
ops = ops,
replaces = Vector.empty,