Skip to content

OpenCode adapter: the broker's rules as an ambient instructions file - #175

Merged
delpher merged 3 commits into
masterfrom
opencode/instructions
Nov 28, 2026
Merged

delpher merged 3 commits into
masterfrom
opencode/instructions

Conversation

@delpher

@delpher delpher commented Nov 28, 2026

Copy link
Copy Markdown
Owner

OpenCode reads the shared rules from the broker now, delivered as an ambient instructions file (AIChat 4094-4099).

  • core/broker.mjs gains atomicWrite(file, text, { mode }); atomicJSON is a thin wrapper over it, so the Windows EPERM/EACCES/EBUSY retries live in one place.
  • on start the plugin fetches GET /api/instructions with fetchInstructions, composes the text with composeInstructions({ fetched, runtime, local: cfg.instructions }) and writes .aichat/instructions.md atomically (only when the text changed). opencode.jsonc lists that file in instructions: [".aichat/instructions.md"] — OpenCode then treats it as ambient instructions, with no synthetic turns in the session and no per-message prompt cost.
  • OPENCODE_RUNTIME is this runtime's block only: the tools the model sees here (aichat.* from the broker's MCP server, aichat_files.* locally, upload_file from outbox or the attachments folder), that the final text of a turn stays local, and that a session may start anew while the notebook and history keep what matters.
  • an older broker (no /api/instructions) gives null: the file is not rewritten, so the previous text (or none) stays, and the adapter behaves as before.

Needed outside the adapter: the manager's wizard should add the instructions entry for new OpenCode agents (same PR as the aichat MCP server). My profile has it by hand.

Tests: the fake broker answers /api/instructions; the test checks the written file has the broker's rules, the "You are …" line and the runtime block. dist/test/opencode-channel.test.js 5/5; full npm test 341 passed, 0 failed, 1 skipped.

Step PR 4 of stage 1.2, after #172 (rules on the broker) and #173 (core + Claude).

Onashchuk Oleksii added 3 commits November 28, 2026 14:24
The plugin fetches GET /api/instructions, composes it with the runtime block and the owner's local rules, and writes .aichat/instructions.md (atomic, only when changed); opencode.jsonc lists it in instructions. core/broker.mjs gains atomicWrite, atomicJSON wraps it.
With fetched === null the runtime block alone used to overwrite the rules; now the file is written only when the broker gave rules, and a 404 test keeps that. The runtime block names no tools, only their namespace: the set becomes dynamic in 1.2.
The manager can show where the model's instructions came from, as agy does: broker, adapter, local.
@delpher
delpher merged commit d903b1f into master Nov 28, 2026
3 checks passed
@delpher delpher mentioned this pull request Nov 28, 2026
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