supermemory icon indicating copy to clipboard operation
supermemory copied to clipboard

Governance hook: add memory IDs and unify the packages/tools vs apps/mcp hook contracts

Open AyushKashyapII opened this issue 3 months ago • 1 comments

Context

Follow-up from #1348 / #1363. The governance hook shipped in #1363 with a plain profile => profile signature. During review, @Palo-Alto-AI-Research-Lab,@nagasatish007 (TealTiger), and @tonydzi converged on a richer "disposition envelope" return type as the eventual right design — something like:

interface GovernedRetrievalResult {
  results: RetrievalResult[]
  dispositions: { id: string; status: "kept" | "redacted" | "blocked"; rule?: string }[]
  mode: "OBSERVE" | "MONITOR" | "ENFORCE"
  status: "success" | "failed_open" | "failed_closed"
}```

We deliberately did not build that in [#1363](https://github.com/AyushKashyapII/supermemory/issues/1363), because two prerequisites
don't exist yet, and building the envelope before them means shipping dispositions with nothing to attach to. This issue tracks those two
prerequisites. It does not include building the envelope itself that's a follow-up on top of this one.

Problem 1 — no stable ID to key a disposition on ProfileStructure (packages/tools/src/shared/types.ts) represents a memory as { memory: string; metadata?: Record<string, unknown> } — no id.The MCP app's Profile (apps/mcp/src/server/client/index.ts) is { static: string[]; dynamic: string[] } — bare strings, no id and no metadata slot either. Only MCP's SearchResult.results[] carries an id today, via Memory.id.

A disposition entry needs to say "memory X was blocked." Without a stable id, that can only be expressed positionally (index into the array), which
breaks the moment a hook reorders or drops entries — position and identity silently diverge.

Scope: thread a real id through ProfileStructure.profile.static/.dynamic and through MCP's Profile, from wherever the API response already has one,
without changing existing hook behavior.

Problem 2 — two divergent hook contracts packages/tools exposes one MemoryGovernanceHook over ProfileStructure
with context { containerTag, queryText, mode }. apps/mcp exposes onSearch/onProfile over its own SearchResult/ProfileResponse types,
with context { containerTag?, query? } — no mode. A governance provider can't register the same middleware against both without writing an adapter, and that adapter is exactly where disposition data would get lost.

Scope: converge these onto one shared hook shape (types + context) that both packages/tools and apps/mcp consume, so a provider registers once.

Non-goals
Building the disposition envelope itself (follow-up on top of this issue).
Any change to what governance providers currently receive/return — this is additive plumbing (ids, shared types), not a behavior change.
Why now, not later
No one is blocked on this today — the current plain hook works and TealTiger's confirmed they're building tealtiger-supermemory against it
as-is. The reason to do this soon: once a real integration ships against the current shape, changing it becomes a breaking change. Doing this now, before any real adopter depends on the exact shape, is close to free.

AyushKashyapII avatar Aug 12 '26 07:08 AyushKashyapII

ENG-1190

linear-code[bot] avatar Aug 12 '26 07:08 linear-code[bot]