Skip to content

fix(upgrade): migrate agent.build.prompt to instructions array#66

Merged
chubes4 merged 1 commit intomainfrom
fix/upgrade-instructions-migration
Apr 24, 2026
Merged

fix(upgrade): migrate agent.build.prompt to instructions array#66
chubes4 merged 1 commit intomainfrom
fix/upgrade-instructions-migration

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Apr 24, 2026

Problem

Existing installs set up before #60 have agent.build.prompt / agent.plan.prompt in their opencode.json. This format pushes custom prompts to the top of system[1], displacing OpenCode's canonical opening. Anthropic's third-party-app detector fingerprints the first bytes of system[1] on Claude Max OAuth requests — when the canonical opening is missing, it routes to extra-usage billing and returns 400.

The upgrade script's Phase 2b skipped the drift check entirely when the primary runtime was claude-code, so installs where kimaki spawns opencode sessions (like chubes.net) were stuck with no automated fix path.

Changes

lib/repair-opencode-json.py — added prompt migration alongside existing plugin check:

  • parse_file_includes() — extracts {file:./path} references from legacy prompt strings
  • check_prompt_migration() — detects agent.build.prompt/agent.plan.prompt presence
  • apply_prompt_migration() — removes prompt keys, sets top-level instructions array
  • Prompt check runs for all runtimes; plugin array check stays opencode-only

upgrade.sh — Phase 2b now runs whenever opencode.json exists:

  • Removed RUNTIME != "opencode" gate on check_opencode_json_drift()
  • Updated docs, help text, and summary warnings to cover both drift vectors
  • --repair-opencode-json now fixes both plugin array and prompt format

Testing

Verified on chubes.net VPS (runtime: claude-code, bridge: kimaki):

  • Old-format opencode.json → diagnostic detects prompt_migration: "needed"
  • --apply → migrates correctly, preserves mode/model/plugin/permissions
  • Re-run on migrated config → reports ok (idempotent)
  • upgrade.sh --dry-run with old config → warns about drift
  • upgrade.sh --dry-run with new config → reports "matches current setup"

agent.build.prompt/agent.plan.prompt in opencode.json pushes custom
prompts to the top of system[1], displacing the canonical OpenCode
opening. Anthropic's third-party-app detector fingerprints the first
bytes of system[1] on Claude Max OAuth requests; when the canonical
opening is missing, it routes to extra-usage billing and returns 400.

The upgrade script previously skipped Phase 2b (opencode.json drift
check) entirely when the primary runtime was claude-code, even though
opencode.json exists and kimaki spawns opencode sessions. This left
existing installs stuck on the old format with no automated fix path.

Changes:
- repair-opencode-json.py: add prompt migration alongside plugin check
  - parse_file_includes() extracts {file:./path} from legacy prompts
  - check_prompt_migration() detects agent.build.prompt/plan.prompt
  - apply_prompt_migration() removes prompt keys, sets instructions array
  - prompt check runs for ALL runtimes; plugin check stays opencode-only
- upgrade.sh: remove runtime gate on check_opencode_json_drift()
  - Phase 2b now runs whenever opencode.json exists on disk
  - Updated docs/help text for --repair-opencode-json to cover migration
  - Summary warns about both plugin and prompt drift

Fixes: wp-coding-agents#60 (automated migration for existing installs)
@chubes4 chubes4 merged commit c0c7bf9 into main Apr 24, 2026
2 checks passed
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