feat: entity enrichment — metadata, relationships, and self-entity#470
Merged
Conversation
Wire up the existing metadata JSON column end-to-end:
- Curator extracts description/role metadata for entities
- Metadata merged on dedup (existing non-empty values win)
- CLI: --metadata flag on add, new edit subcommand
- Dashboard: structured metadata display + edit form
Add entity-to-entity relationships:
- New entity_relations table (migration v28)
- Directed pairs with relation types (friend, colleague, manager, etc.)
- Curator extracts relationships from conversation
- CLI: relation add/rm subcommands
- Dashboard: relationships section on entity detail page
Add self-entity (entity_type='self'):
- Auto-created from git config user.name/email
- Configurable via .lore.json user section
- Anchors relationships ('Melkey is my friend')
- Special formatting in prompt injection ('you (the user)')
Add hybrid entity injection policy:
- Agent system prompt: all entities if <=30, otherwise self + relations +
relevance-ranked remainder (configurable via knowledge.maxEntityInject)
- Curator always gets the full entity list for grounding/dedup
Type-based cross_project defaults:
- person/org/service/tool -> cross-project (user-level)
- repo/infra -> project-scoped by default
47 new tests covering metadata, relations, self-entity, injection policy,
curator integration, merge with relations.
- Move metadata merge inside BEGIN IMMEDIATE transaction (race condition) - Fix cmdEdit double-stringify: pass Record to update(), not JSON string - Self entity created with project_id=NULL (global) to prevent duplicates - Add self-relation guard in addRelation (entity_a != entity_b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enriches the entity system with three interconnected features:
1. Entity Metadata
Wire up the existing
metadataJSON column end-to-end — it existed in the schema but nothing populated it.descriptionandrolemetadata for entitiescreate()finds an existing entity, incoming metadata fills gaps while existing non-empty values win (same intuition as alias dedup)--metadataflag onlore entity add, newlore entity editsubcommand<pre>JSON2. Entity Relationships
New
entity_relationstable (migration v28) for directed entity-to-entity connections.lore entity relation add/rm, relationships shown inlore entity show3. Self-Entity
New
entity_type = 'self'(no extra column needed) identifies the Lore user as an entity.git config user.name/email.lore.jsonusersection (name, email, aliases, metadata)[friend]tags4. Hybrid Entity Injection Policy
knowledge.maxEntityInject), otherwise self + self's relations + relevance-ranked remainder5. Type-Based Scoping Defaults
self/person/org/service/tool→ cross-project by default (user-level)repo/infra→ project-scoped by defaultcrossProjectparam still overridesFiles Changed (12)
packages/core/src/db.tsentity_relationstable + recovery blockpackages/core/src/entities.tspackages/core/src/curator.tsDetectedEntity.metadata,DetectedRelation,filterRelations(),applyOps()packages/core/src/prompt.tspackages/core/src/config.tsusersection +knowledge.maxEntityInjectpackages/core/src/git.tsgetGitUser()— reads git config user.name/emailpackages/core/src/index.tsgetGitUser,clearGitUserCachepackages/gateway/src/cli/entity.ts--metadataon add,editsubcommand,relation add/rmpackages/gateway/src/ui.tspackages/core/test/entities.test.tspackages/core/test/db.test.ts.lore.mdTesting
Closes #459 (entity metadata), related to #462 (entity dedup).