GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(opencode): filter instruction files by reader audience by iceteaSA · Pull Request #38957 · anomalyco/opencode

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Jul 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #38961

Related: #4096 (context control for subagents — shapes context volume from the dispatch side; this shapes ownership from the file side).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Lets an instruction file declare who it is for, so a nested AGENTS.md written for the orchestrator does not get delivered to every subagent:

---
opencode:
  audience:
    - role: main
    - role: subagent
      agent: "review*"
---

role is main / subagent / all; agent is a glob. Entries OR together, keys within one entry AND together. A file with no opencode: metadata is included everywhere, byte-identical to today — no behaviour change unless you opt in.

Three decisions worth calling out, because each has a wrong-looking-but-tempting alternative:

Reader role is structural, not configured. It comes from session.parentID == null, not from the agent's mode. A mode: "primary" agent dispatched as a subagent is a subagent — deriving role from config would get that backwards, and the whole point is to reason about the delivery, not the label.

An unknown key under opencode: is fatal and names the file. audiance: is valid YAML, so a permissive schema cannot distinguish a typo from an absent directive — and failing open silently reinstates exactly the delivery the directive was written to prevent. opencode: {} is treated as absence and included, since an empty map asserts nothing.

Filtering happens on every delivery path, not just the obvious one. buildSystem() is the path people think of; two others leak without it, and both were found by inspection rather than by a failing test:

  • Instruction.resolve() — nested AGENTS.md surfaced through the read tool. Needed a reader on Tool.Context, supplied by the production constructors and failing closed when absent.
  • createUserMessage's file: attachment path — hardcoded role: "main", so a subagent leaked main-only instructions whenever a dispatch carried an @file reference.

AudienceError is delivered as a typed failure rather than a defect, so a malformed file surfaces as a normal error at the call site.

Known limitation, documented in rules.mdx: the V2 SessionCore assembles system context through a separate path (packages/core/src/instruction-context.ts) with no audience filtering. That is bounded today because V2 has no task tool, so every V2 session is structurally main — but it stops being bounded the moment V2 gains dispatch. packages/core cannot import from packages/opencode, so sharing the filter means moving it into core; that is a larger change than this PR should carry.

How did you verify your code works?

  • New packages/opencode/test/session/instruction-audience.test.ts covers parsing, role/agent matching, wildcard semantics, OR/AND composition, directive stripping, and malformed-metadata failures.
  • Two-way mutation-tested intersection test in instruction.test.ts: neutering the audience filter leaks wrong-audience project files; neutering the origin filter leaks config files into project scope. Each failure names which filter died.
  • Red-first proof for both leak paths — subagents receiving nested main-only instructions through resolve(), and through an @file attachment — each failing before the fix and passing after.
  • Whole-branch mutation check: making the filter a no-op turns 11 tests red across audience exclusion, frontmatter stripping, and typed-failure delivery; restoring returns 99 pass / 0 fail.
  • bun test in packages/opencode: 3243 pass / 0 fail (dev baseline 3207). bun typecheck clean in packages/opencode and packages/core.
  • Docs updated in packages/web/src/content/docs/rules.mdx, including the V2 limitation above.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iceteaSA reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@iceteaSA iceteaSA mentioned this pull request Jul 26, 2026
[FEATURE]: Instruction files cannot declare which agents they are for #38961
Closed
1 task done
@iceteaSA
iceteaSA force-pushed the instruction-audience branch from 3472beb to 9f30f79 Compare July 26, 2026 12:22
@iceteaSA
iceteaSA marked this pull request as ready for review July 26, 2026 14:35
@iceteaSA
iceteaSA force-pushed the instruction-audience branch from 9f30f79 to 8d0fddb Compare July 26, 2026 14:50
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
📊 AI CLI 工具社区动态日报 2026-07-27 litang9/big_model_radar#271
Open
@iceteaSA
iceteaSA force-pushed the instruction-audience branch 2 times, most recently from 136a4f0 to 94b55aa Compare August 8, 2026 20:06
@iceteaSA
iceteaSA force-pushed the instruction-audience branch from 8aa941e to 20e7891 Compare August 19, 2026 18:18
iceteaSA added 2 commits August 22, 2026 16:48
@iceteaSA
feat(opencode): filter instruction files by reader audience
aa3cb48
Adds an opencode.audience frontmatter directive so an instruction file can
declare who it is for: a role (main / subagent / all) and an agent glob,
matched as OR across entries and AND within one.

Reader role is derived structurally from whether the session has a parent, so
a primary-mode agent dispatched as a child is correctly a subagent. Absent
metadata means included everywhere, byte-identical; an unknown key under
opencode is fatal and names the file, because a typo like `audiance` parses
as valid YAML and failing open would silently reinstate the delivery the
directive exists to prevent.

Filtering covers system-prompt assembly, nearby-file resolution through the
read tool, and the prompt attachment path. The V2 SessionCore assembly path
is a separate implementation and is not covered.
@iceteaSA
docs: note that audience role reflects session shape, not work kind
c6c6859
@iceteaSA
iceteaSA force-pushed the instruction-audience branch from 20e7891 to c6c6859 Compare August 22, 2026 19:32
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Aug 26, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Instruction files cannot declare which agents they are for

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@iceteaSA
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.