Repository: emcie-co/parlant
File: server/src/emcie/server/indexer.py (Python)

Code before:
                        indirect=False, source=item[0]
                    )
                )
                connections.extend(
                    await self._guideline_connection_store.list_connections(
                        indirect=False, target=item[0]
                    )
                )
                await asyncio.gather(
                    *(self._guideline_connection_store.delete_connection(c.id) for c in connections)
                )
            except ValueError:  # in case connections with the guideline id do not exist
                pass

    async def _index_guideline_connections(
        self,
        guidelines: Sequence[Guideline],
        last_know_state_of_set: list[GuidelineIndexEntryItem],
    ) -> None:
        introduced, existsing, deleted = self._assess_guideline_modifications(
            guidelines, last_know_state_of_set
        )

        await self._remove_deleted_guidelines_connections(deleted)

        for p in await self._guideline_connection_proposer.propose_connections(
            introduced_guidelines=introduced, existing_guidelines=existsing
        ):
            self.logger.debug(f"Add guideline connection between source: {p.source} and {p.target}")

            await self._guideline_connection_store.update_connection(
                source=p.source,
                target=p.target,
                kind=p.kind,
            )


class Indexer:
    def __init__(
        self,
        index_file: Path,
        logger: Logger,
        guideline_store: GuidelineStore,
        guideline_connection_store: GuidelineConnectionStore,
        agent_store: AgentStore,
    ) -> None:
        self._index_file = index_file
        self._guideline_indexer = GuidelineIndexer(
            logger,
            guideline_store,
            guideline_connection_store,

Review comment (bug):
Excluding certain exceptions, such as very trivial getters, I usually don't like to `for x in return_iter()`, because, when debugging, it forces you to go item by item to figure out what's in the list, instead of just hovering on it (or printing it in the console). For trivial list-getters it's not an issue, because you can quickly call the function yourself from the console, but in this case we're talking about a potentially lengthy operation. So to improve the ergonomics, I'd first assign this to a variable.

Code after:
                        indirect=False, source=item[0]
                    )
                )
                connections.extend(
                    await self._guideline_connection_store.list_connections(
                        indirect=False, target=item[0]
                    )
                )
                await asyncio.gather(
                    *(self._guideline_connection_store.delete_connection(c.id) for c in connections)
                )
            except ValueError:  # in case connections with the guideline id do not exist
                pass

    async def _index_guideline_connections(
        self,
        guidelines: Sequence[Guideline],
        last_know_state_of_set: list[GuidelineIndexEntryItem],
    ) -> None:
        introduced, existsing, deleted = self._assess_guideline_modifications(
            guidelines, last_know_state_of_set
        )

        await self._remove_deleted_guidelines_connections(deleted)

        proposed_connections = await self._guideline_connection_proposer.propose_connections(
            introduced_guidelines=introduced, existing_guidelines=existsing
        )

        for p in proposed_connections:
            self.logger.debug(f"Add guideline connection between source: {p.source} and {p.target}")

            await self._guideline_connection_store.update_connection(
                source=p.source,
                target=p.target,
                kind=p.kind,
            )


class Indexer:
    def __init__(
        self,
        index_file: Path,
        logger: Logger,
        guideline_store: GuidelineStore,
        guideline_connection_store: GuidelineConnectionStore,
        agent_store: AgentStore,
    ) -> None:
        self._index_file = index_file
        self._guideline_indexer = GuidelineIndexer(
            logger,