Skip to content

[P2-7] MemoryProvider trait + system-prompt injection hook + SDK plugins.registerMemoryProvider #41

@justrach

Description

@justrach

Parent: #34
Priority: P2 (extensibility — required for graff-honcho)
Branch base: release/0.1.53

Why

Hermes' Honcho integration is a MemoryProvider plugin that injects two layers (base + dialectic) into the system prompt every turn. To support graff-honcho (or any other memory backend) without forking codegraff, we need a typed extension point.

Scope

Rust side

  • forge_domain::MemoryProvider trait:
    #[async_trait]
    pub trait MemoryProvider: Send + Sync {
        fn id(&self) -> &str;
        async fn on_system_prompt_assemble(&self, ctx: &SystemPromptCtx) -> Option<String>;
        async fn on_session_start(&self, cid: ConversationId) -> Result<()>;
        async fn on_session_end(&self, cid: ConversationId) -> Result<()>;
        async fn on_user_message(&self, cid: ConversationId, content: &str) -> Result<()>;
        async fn on_assistant_message(&self, cid: ConversationId, content: &str) -> Result<()>;
    }
  • Single-active-provider rule (matches Hermes). Configured via forge_config.
  • Injection point: in forge_app::compact / system-prompt assembly, append all MemoryProvider::on_system_prompt_assemble outputs as Layer 3 below the user system prompt and skill context.

SDK side

  • graff.plugins.registerMemoryProvider({ id, hooks }) — the SDK wraps a JS implementation in a Rust shim that satisfies the trait via N-API ThreadsafeFunction.
  • TS interface mirrors the Rust trait.

Acceptance

  • Built-in default NoopMemoryProvider ships with codegraff
  • A toy TS provider can register and its on_system_prompt_assemble output appears in the next LLM call's system prompt
  • Activating a new provider deactivates the previous one

Metadata

Metadata

Assignees

No one assigned

    Labels

    severity: highSignificant impact; core functionality is impaired.type: featureBrand new functionality, features, pages, workflows, endpoints, etc.work: complicatedThe situation is complicated, good practices used.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions