Skip to content

repair-opencode-json.py: orphaned empty agent.build/plan blocks survive #60 prompt migration and silently break dm-agent-sync #112

@chubes4

Description

@chubes4

Summary

After the #60 prompt migration moves agent.build.prompt → top-level instructions[], the now-empty agent.build / agent.plan blocks (containing only mode + model) are intentionally preserved. Those default-equivalent shells then prevent dm-agent-sync.ts from registering DM agent prompts into build/plan, so new sessions launch as the bare build agent without AGENTS.md, SOUL.md, MEMORY.md, etc.

Repro

  1. Fresh install of wp-coding-agents 0.8.1 with --chat-bridge=kimaki on a site with multiple DM agents.
  2. Inspect the generated opencode.json. (On this VPS — /var/www/extrachill.com/opencode.json — it contained:)
    "agent": {
      "build": { "mode": "primary", "model": "anthropic/claude-opus-4-7" },
      "plan":  { "mode": "primary", "model": "anthropic/claude-opus-4-7" }
    }
  3. Start a Kimaki session in that project.
  4. Ask the agent what's in its system prompt. It will not be aware of AGENTS.md, SOUL.md, MEMORY.md, or the WordPress runtime / Data Machine handoff sections that dm-context-filter injects.

Root cause

lib/repair-opencode-json.py::apply_prompt_migration (lines 190–221) deliberately leaves agent.build / agent.plan in place after stripping prompt:

# Clean up empty dicts.
for sub in ("build", "plan"):
    if sub in agent and isinstance(agent[sub], dict) and not agent[sub]:
        pass  # keep mode/model keys

Combined with dm-agent-sync.ts line 129:

if (config.agent.build && config.agent.plan && agents.length === 1) {
  // ... only updates prompt for the single-agent case
}

…multi-agent installs (10 agents on this site) skip the prompt-injection branch entirely. The orphaned shells "win" because they look like user config to the plugin, even though they only carry default-equivalent keys.

Why it matters

This is the second-order regression of #60. The original fix correctly moved memory loading out of agent.build.prompt (preserving Claude Max OAuth), but didn't reconcile that agent.build / agent.plan entries with only mode + model are now no-ops at best and footguns at worst. They serve no purpose — mode: primary and the top-level model are already the OpenCode defaults.

Result on this VPS: every Kimaki session for a month has launched without AGENTS.md in context, despite the file being 9.7 KB of curated Data Machine / Homeboy / Extra Chill CLI documentation.

Proposed fix

In apply_prompt_migration (or a new clean_orphaned_agents step), after stripping prompt, also remove the build / plan entries entirely if they only contain default-equivalent keys (mode: primary and/or a model that matches the top-level model):

top_model = data.get("model")
for sub in ("build", "plan"):
    block = agent.get(sub)
    if not isinstance(block, dict):
        continue
    keys = set(block.keys())
    is_default_only = keys <= {"mode", "model"} and \
                      block.get("mode", "primary") == "primary" and \
                      block.get("model", top_model) == top_model
    if is_default_only:
        del agent[sub]
if not agent:
    data.pop("agent", None)

runtime_generate_config() in runtimes/opencode.sh should also stop emitting these blocks for new installs — they're already removed from runtime_generate_config per #60, but this needs a confirmation pass.

Test plan

  • Existing opencode.json with agent: { build: { mode, model }, plan: { mode, model } }--additive removes the orphaned blocks, prompt migration unchanged.
  • User-customized agent.build (e.g. with custom tools or non-default mode) → preserved untouched.
  • After repair, fresh OpenCode session with multiple DM agents loads AGENTS.md + agent identity files via dm-agent-sync.

Related

Environment

  • wp-coding-agents 0.8.1 (commit b7e5acb)
  • VPS: /var/www/extrachill.com, 10 DM agents, Kimaki bridge
  • Discovered while investigating why an OpenCode session was not aware of the project's AGENTS.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions