Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24kchengYe MemoMind ExtensionContext

From Leeroopedia
Knowledge Sources
Domains Software_Architecture, Extensibility
Last Updated 2026-10-28 00:00 GMT

Overview

Abstract context providing controlled API access to extensions — security boundary between extension code and system internals.

Description

The ExtensionContext ABC (with `DefaultExtensionContext` implementation) provides extensions with safe access to system internals: database migration runner, memory engine reference, and connection pool getter. Extensions use this context instead of direct access to internal components, providing a stable API and security boundary. Tenant extensions use `run_migration()` to provision per-tenant schemas.

Usage

Access via `self.context` in any Extension subclass. The context is set automatically by the extension loader after instantiation.

Code Reference

Source Location

  • Repository: MemoMind
  • File: engine/hindsight_api/extensions/context.py
  • Lines: L1-157

Signature

class ExtensionContext(ABC):
    @abstractmethod
    async def run_migration(self, schema: str) -> None: ...
    @abstractmethod
    def get_memory_engine(self) -> MemoryEngineInterface: ...

Import

from hindsight_api.extensions.context import ExtensionContext

I/O Contract

Outputs

Name Type Description
run_migration() None Creates schema and runs pending migrations
get_memory_engine() MemoryEngineInterface Memory engine for DB operations

Usage Examples

Using Context in a Tenant Extension

from hindsight_api.extensions.base import Extension

class MyTenantExtension(Extension):
    async def provision_tenant(self, tenant_id: str) -> str:
        schema = f"tenant_{tenant_id}"
        await self.context.run_migration(schema)
        return schema

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment