Skip to main content

Module write_hook

Module write_hook 

Source
Expand description

The MemoryWriteHook trait — the per-write governance seam.

Memory writes are themselves governable events. Before a provider persists a chunk, it calls MemoryWriteHook::before_write(chunk). The hook can:

  • return Ok(WriteDecision::Allow) — the provider persists the chunk verbatim.
  • return Ok(WriteDecision::Redact { reason }) — the provider drops the chunk silently (the before_write event still gets matcher coverage for audit; the chunk just doesn’t land in memory_chunks). Used to honor redact_memory rules.
  • return Err(_) — the write surfaces as a hard error to the caller.

The daemon wires a hook backed by the rule matcher: it synthesises a MemoryWriteAttempted event from the chunk’s kind, source, caller, and content prefix, runs the rule matcher over it, and returns the appropriate decision based on what fired (Veto → Redact; LogOnly → Allow but record the fire).

Without a hook, providers persist every write — the v1 default for tests and for daemons that haven’t wired the rule matcher path yet.

Structs§

ClosureHook
Convenience wrapper for callers that want to plug a closure in without declaring a struct. Useful for tests and for the daemon’s adapter that wraps the rule matcher.

Enums§

WriteDecision
What a MemoryWriteHook tells the provider to do with an incoming chunk.

Traits§

MemoryWriteHook
The hook providers consult before persisting a chunk.