Skip to content

feat: extract DailyMemoryStorage interface with pluggable storage filter#1051

Merged
chubes4 merged 1 commit intomainfrom
feat/daily-memory-storage-interface
Apr 14, 2026
Merged

feat: extract DailyMemoryStorage interface with pluggable storage filter#1051
chubes4 merged 1 commit intomainfrom
feat/daily-memory-storage-interface

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Apr 14, 2026

Summary

One filter to swap the entire daily memory storage backend:

add_filter( 'datamachine_daily_memory_storage', function ( $default, $user_id, $agent_id ) {
    return new MyWordPressDailyMemory( $user_id, $agent_id );
}, 10, 3 );

Supersedes #1050 (closed) which used 5 per-operation filters — that was a code smell pointing at missing abstraction.

What changed

  1. New DailyMemoryStorage interface (inc/Core/FilesRepository/DailyMemoryStorage.php)

    • Contract: read, write, append, delete, list_all, search
    • Same signatures the existing DailyMemory class already has
  2. DailyMemory implements DailyMemoryStorage

    • Zero behavior change — just adds implements DailyMemoryStorage to the class declaration
  3. DailyMemoryAbilities resolves storage via filter

    • New private resolveStorage($user_id, $agent_id) method
    • Fires datamachine_daily_memory_storage filter with the default DailyMemory instance
    • All 5 ability methods use the resolved storage instead of hardcoding new DailyMemory()
    • Safety fallback: if filter returns non-DailyMemoryStorage, falls back to default
  4. Removed datamachine_daily_memory_archived action from DailyMemoryTask

    • Duplicative — the pre_archive filter handles write override, the storage interface handles read-back
    • Added cross-reference to datamachine_daily_memory_storage in the pre_archive docblock

How Intelligence uses this

Intelligence hooks one filter and returns its own DailyMemoryStorage implementation that stores/reads daily memory as WordPress pages. One hook, total replacement. Data Machine doesn't know or care what's behind the interface.

add_filter( 'datamachine_daily_memory_storage', function ( $default, $user_id, $agent_id ) {
    $agent = get_agent( $agent_id );
    if ( $agent && ! empty( $agent['agent_config']['intelligence_kit'] ) ) {
        return new Intelligence_WordPress_Daily_Memory( $user_id, $agent_id );
    }
    return $default; // Non-Intelligence agents keep flat files.
}, 10, 3 );

Files

File Change
inc/Core/FilesRepository/DailyMemoryStorage.php New — interface with 6 methods
inc/Core/FilesRepository/DailyMemory.php Add implements DailyMemoryStorage
inc/Abilities/DailyMemoryAbilities.php resolveStorage() + filter, all methods use it
inc/Engine/AI/System/Tasks/DailyMemoryTask.php Remove datamachine_daily_memory_archived action

Extract a DailyMemoryStorage interface from DailyMemory (flat files)
so the entire daily memory storage backend can be swapped via a single
filter: datamachine_daily_memory_storage.

DailyMemoryAbilities now resolves storage through resolveStorage() which
fires the filter with the default filesystem implementation. Plugins
like Intelligence can return their own DailyMemoryStorage implementation
(WordPress pages, external services, etc.) and own the entire storage
layer — read, write, append, list, search, delete — with one hook.

Also removes the duplicative datamachine_daily_memory_archived action
from DailyMemoryTask. The pre_archive filter handles the write override,
and the storage interface handles everything else.
@chubes4 chubes4 merged commit fefa3b5 into main Apr 14, 2026
1 check passed
@chubes4 chubes4 deleted the feat/daily-memory-storage-interface branch April 14, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant