feat: Add disable_permalinks config flag (#313)

Signed-off-by: phernandez <paul@basicmachines.co>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Paul Hernandez
2025-10-03 22:11:47 -05:00
committed by GitHub
parent 33ee1e0831
commit 903591384d
12 changed files with 432 additions and 26 deletions
+27 -16
View File
@@ -42,6 +42,7 @@ class EntityService(BaseService[EntityModel]):
relation_repository: RelationRepository,
file_service: FileService,
link_resolver: LinkResolver,
app_config: Optional[BasicMemoryConfig] = None,
):
super().__init__(entity_repository)
self.observation_repository = observation_repository
@@ -49,6 +50,7 @@ class EntityService(BaseService[EntityModel]):
self.entity_parser = entity_parser
self.file_service = file_service
self.link_resolver = link_resolver
self.app_config = app_config
async def detect_file_path_conflicts(self, file_path: str) -> List[Entity]:
"""Detect potential file path conflicts for a given file path.
@@ -145,9 +147,9 @@ class EntityService(BaseService[EntityModel]):
)
# Try to find existing entity using smart resolution
existing = await self.link_resolver.resolve_link(
schema.file_path
) or await self.link_resolver.resolve_link(schema.permalink)
existing = await self.link_resolver.resolve_link(schema.file_path)
if not existing and schema.permalink:
existing = await self.link_resolver.resolve_link(schema.permalink)
if existing:
logger.debug(f"Found existing entity: {existing.file_path}")
@@ -194,9 +196,15 @@ class EntityService(BaseService[EntityModel]):
relations=[],
)
# Get unique permalink (prioritizing content frontmatter)
permalink = await self.resolve_permalink(file_path, content_markdown)
schema._permalink = permalink
# Get unique permalink (prioritizing content frontmatter) unless disabled
if self.app_config and self.app_config.disable_permalinks:
# Use empty string as sentinel to indicate permalinks are disabled
# The permalink property will return None when it sees empty string
schema._permalink = ""
else:
# Generate and set permalink
permalink = await self.resolve_permalink(file_path, content_markdown)
schema._permalink = permalink
post = await schema_to_markdown(schema)
@@ -254,15 +262,16 @@ class EntityService(BaseService[EntityModel]):
relations=[],
)
# Check if we need to update the permalink based on content frontmatter
# Check if we need to update the permalink based on content frontmatter (unless disabled)
new_permalink = entity.permalink # Default to existing
if content_markdown and content_markdown.frontmatter.permalink:
# Resolve permalink with the new content frontmatter
resolved_permalink = await self.resolve_permalink(file_path, content_markdown)
if resolved_permalink != entity.permalink:
new_permalink = resolved_permalink
# Update the schema to use the new permalink
schema._permalink = new_permalink
if self.app_config and not self.app_config.disable_permalinks:
if content_markdown and content_markdown.frontmatter.permalink:
# Resolve permalink with the new content frontmatter
resolved_permalink = await self.resolve_permalink(file_path, content_markdown)
if resolved_permalink != entity.permalink:
new_permalink = resolved_permalink
# Update the schema to use the new permalink
schema._permalink = new_permalink
# Create post with new content from schema
post = await schema_to_markdown(schema)
@@ -746,8 +755,10 @@ class EntityService(BaseService[EntityModel]):
# 6. Prepare database updates
updates = {"file_path": destination_path}
# 7. Update permalink if configured or if entity has null permalink
if app_config.update_permalinks_on_move or old_permalink is None:
# 7. Update permalink if configured or if entity has null permalink (unless disabled)
if not app_config.disable_permalinks and (
app_config.update_permalinks_on_move or old_permalink is None
):
# Generate new permalink from destination path
new_permalink = await self.resolve_permalink(destination_path)