basic-memory icon indicating copy to clipboard operation
basic-memory copied to clipboard

feat(plugins): capture harness events as producer envelopes (#997)

Open sourrris opened this issue 5 months ago • 0 comments

Summary

This PR implements issue #997 by introducing a shared, opt-in "harness WAL" path for the Claude Code and Codex plugins. It normalizes supported hook events (session_started, compaction_imminent) into Basic Memory producer envelopes and stamps checkpoints with provenance and idempotency metadata.

Proposed Changes

New Files

  • harness_envelope.py: Shared stdlib-only module containing the HarnessEnvelope dataclass, factory, idempotency logic, redaction utils, and event logging logic.
  • tool-ledger.md: ToolLedger picoschema (forward-compat v0).
  • tool-ledger.md: ToolLedger picoschema (forward-compat v0).

Modified Files

  • plugins/claude-code/hooks/pre-compact.sh & session-start.sh:
    • Added BM_HOOK_DIR environment variable passing to resolve the real hook directory inside Python inline heredocs (__file__ resolves to <stdin> otherwise).
    • Integrated harness_envelope to create envelopes, stamp provenance observations, add idempotency metadata to frontmatter, and log events locally if captureEvents is enabled.
  • plugins/codex/hooks/pre-compact.py & session-start.py:
    • Integrated harness_envelope in the Python-native hooks.
  • plugins/claude-code/settings.example.json:
    • Added example settings for captureEvents (defaults to false), redactKeys, redactPaths, and eventRetention.
  • plugins/claude-code/DESIGN.md:
    • Added Section 14 to document the Harness WAL (Write-Ahead Log) design.

Verification Plan

  • Run package checking:
    • just package-check (Passed successfully)
    • just package-check-claude-code (Passed successfully, verified Claude Code manifest schema)
  • Local E2E Tests:
    • Validated envelope creation, idempotency keys, payload redaction, provenance observations, event logging, and pipeline simulation.

Closes #997

sourrris avatar Jun 13 '26 17:06 sourrris