Skip to content

adapters core: instructions.mjs, and the Claude adapter on the broker's rules - #173

Merged
delpher merged 2 commits into
masterfrom
instructions/core-claude
Nov 28, 2026
Merged

delpher merged 2 commits into
masterfrom
instructions/core-claude

Conversation

@delpher

@delpher delpher commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Stage 1.2, step 1, part 2 (AIChat 4083). It builds on #172.

src/adapters/core/instructions.mjs is plain JS with no imports at all, like files.mjs and broker.mjs, with types in .d.mts:

  • fetchInstructions({httpBase, token, timeoutMs}) reads GET /api/instructions. It returns null for an old broker (404), no answer in time, no connection or a bad response. In that case the adapter keeps its own text.

  • composeInstructions({fetched, runtime, notices, local, fallback}) builds the text in this order:

    1. the broker's rules;
    2. who the agent is;
    3. ## How your runtime connects you to AIChat with the adapter's block;
    4. notices;
    5. ## Local rules from your owner (they win…).

    It returns { text, parts }. Each part has its source (broker/fallback/adapter/local) and version, for the manager in the following PR, as codex-alexey asked (4031).

  • 4 tests (instructions.test.mjs), added to npm test.

The Claude adapter is the first on it. CLAUDE_RUNTIME contains only what is specific to Claude Code: the <channel> frame, to vs room, attachments, links, game moves, and that the owner is the user of this session with CLAUDE.md as their local rules. Behaviour now comes from the broker's rules. PEER_RULE stays last, as before.

  • 0.32+ broker: rules + self + runtime + notices + PEER_RULE.
  • 0.3–0.31 broker: as before (MECHANICS + self).
  • Even older broker: LEGACY_INSTRUCTIONS, as before.

AGENTS.md (section «Адаптери») says where rules go: behaviour goes in the broker's rules, and the adapter text describes only how its runtime differs.

npm test: 341 pass, 0 fail. typecheck passes.

Next: agy (systemPrompt.append) and OpenCode (.aichat/instructions.md + instructions in opencode.jsonc), each in its own PR.

🤖 Generated with Claude Code

Onashchuk Oleksii and others added 2 commits November 28, 2026 14:12
…'s rules

Stage 1.2, step 1, part 2 (AIChat 4083). core/instructions.mjs fetches the
rules every agent works by (GET /api/instructions, #172) and composes what a
model is told: the rules, who the agent is, the adapter's short block on its
runtime, notices, the owner's local rules last (they win). It returns the
parts with their sources and versions too, for the agent manager. A broker
without /api/instructions gets null and the adapter keeps its own text.

The Claude adapter is the first on it: its block says only what is Claude
Code's own (channel frames, to/room, attachments, links, games); how to behave
comes from the broker. Older brokers get the instructions they got before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…says (its runtime)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@delpher
delpher merged commit c200a94 into master Nov 28, 2026
3 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