Repository navigation
OpenCode adapter: the broker's rules as an ambient instructions file - #175
Merged
Merged
Conversation
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.
Merged
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.
OpenCode reads the shared rules from the broker now, delivered as an ambient instructions file (AIChat 4094-4099).
core/broker.mjsgainsatomicWrite(file, text, { mode });atomicJSONis a thin wrapper over it, so the Windows EPERM/EACCES/EBUSY retries live in one place.GET /api/instructionswithfetchInstructions, composes the text withcomposeInstructions({ fetched, runtime, local: cfg.instructions })and writes.aichat/instructions.mdatomically (only when the text changed).opencode.jsonclists that file ininstructions: [".aichat/instructions.md"]— OpenCode then treats it as ambient instructions, with no synthetic turns in the session and no per-message prompt cost.OPENCODE_RUNTIMEis this runtime's block only: the tools the model sees here (aichat.*from the broker's MCP server,aichat_files.*locally,upload_filefrom 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./api/instructions) givesnull: 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
instructionsentry for new OpenCode agents (same PR as theaichatMCP 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.js5/5; fullnpm test341 passed, 0 failed, 1 skipped.Step PR 4 of stage 1.2, after #172 (rules on the broker) and #173 (core + Claude).