Self-healing scaffolding: recreate missing agent files on first read#412
Merged
Conversation
get_option('active_plugins') only returns subsite-specific plugins on
multisite. Network-activated plugins are stored separately in
active_sitewide_plugins site option. Merges both lists so the scaffolded
SOUL.md reflects all plugins the agent will encounter.
…t read Agent files (SOUL.md, USER.md, MEMORY.md) were only created during the WordPress activation hook. If the plugin was deployed via Homeboy, rsync, or git pull without triggering activation, the agent silently operated without its identity files. Add lazy self-healing via DirectoryManager::ensure_agent_files() — a static once-per-request check that recreates missing files from scaffold defaults. Hooked into all read paths: - CoreMemoryFilesDirective (every AI call) - AgentMemory constructor (CLI/API memory operations) - FileAbilities listAgentFiles/getAgentFile (REST API) Also upgrades AgentMemory::ensure_file_exists() to use rich scaffold content instead of a bare stub, and adds logging for both creation events and persistent missing-file warnings. Closes #408
Closed
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #408 — Agent files (SOUL.md, USER.md, MEMORY.md) were only created during
register_activation_hook. If the plugin was deployed via Homeboy, rsync, or git pull without triggering activation, the agent silently operated without its identity files.Changes
DirectoryManager::ensure_agent_files()— New static method with a once-per-request flag. Callsdatamachine_ensure_default_memory_files()lazily on the first access. Repeated calls are free (static bool guard).CoreMemoryFilesDirective::get_outputs()— Callsensure_agent_files()before reading memory files. This is the universal funnel for all AI calls. Also now logs a warning if files are still missing after the scaffolding attempt.AgentMemoryconstructor — Callsensure_agent_files()on instantiation. Covers all CLI and API memory operations.FileAbilities::listAgentFiles()/getAgentFile()— Callsensure_agent_files()before listing or retrieving agent files via REST API.AgentMemory::ensure_file_exists()— Upgraded from bare# Agent Memory\nstub to usingdatamachine_get_scaffold_defaults()content, so a recreated MEMORY.md includes the standard sections (State, Lessons Learned, Context).datamachine_ensure_default_memory_files()— Addednotice-level logging when files are recreated, providing visibility into self-healing events.How it works
Coverage
CoreMemoryFilesDirective::get_outputs()wp datamachine memory *AgentMemoryconstructorGET /files/agentFileAbilities::listAgentFiles()GET /files/agent/{file}FileAbilities::getAgentFile()PUT /files/agent/{file}AgentMemory::ensure_file_exists()(write path)