diff --git a/hooks/dm-agent-sync.sh b/hooks/dm-agent-sync.sh index 3e496e9..313731d 100755 --- a/hooks/dm-agent-sync.sh +++ b/hooks/dm-agent-sync.sh @@ -54,6 +54,19 @@ detect_wp_cmd() { WP_CMD=$(detect_wp_cmd) || exit 0 +# --------------------------------------------------------------------------- +# Refresh composable files before computing @ includes +# --------------------------------------------------------------------------- +# SectionRegistry callbacks can read live state (Intelligence sources, skill +# inventory, etc.). DM regenerates composable files when their feeder state +# fires a registered invalidation hook, but those hooks only run inside a +# WordPress request. State changed via direct DB edits, cron, or external +# processes would leave the on-disk file stale. Running `agent compose` here +# guarantees AGENTS.md (and any sibling composable files) match live state +# at the moment the coding-agent session starts. + +$WP_CMD datamachine agent compose >/dev/null 2>&1 || true + # --------------------------------------------------------------------------- # Query active agents from Data Machine # --------------------------------------------------------------------------- diff --git a/kimaki/plugins/dm-agent-sync.ts b/kimaki/plugins/dm-agent-sync.ts index 5885e1c..e73a691 100644 --- a/kimaki/plugins/dm-agent-sync.ts +++ b/kimaki/plugins/dm-agent-sync.ts @@ -41,6 +41,15 @@ const dmAgentSync: Plugin = async ({ $ }) => { return { config: async (config) => { try { + // Refresh composable files before the session reads them. + // DM SectionRegistry callbacks render live state (configured sources, + // skills, config). DM's own invalidation hooks cover state changes + // that happen inside a WordPress request, but cron jobs, direct DB + // edits, or other external processes would leave AGENTS.md stale. + // Running compose here guarantees the file matches live state at the + // moment OpenCode loads the session prompt. + await $`wp datamachine agent compose --allow-root 2>/dev/null`.quiet().nothrow(); + // Query all agents from Data Machine. const agentsRaw = await $`wp datamachine agents list --format=json --allow-root 2>/dev/null`.quiet().nothrow().text();