Skip to content

fix(core): render granular instruction updates - #42383

Merged
kitlangton merged 4 commits into
v2from
instruction-deltas
Aug 13, 2026
Merged

fix(core): render granular instruction updates#42383
kitlangton merged 4 commits into
v2from
instruction-deltas

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What

Instruction changes now append only the affected file deltas instead of repeating every loaded AGENTS.md file in full.

For each modified file, OpenCode renders both a three-context unified diff and the complete new instructions, then uses whichever final message is shorter. Added and removed files use explicit messages.

Before / After

Before: Editing one line in one instruction file appended a complete replacement containing every global and project instruction file. The session learned the correct new state, but paid the token cost of unrelated unchanged files.

After: Unchanged files are omitted. A localized edit usually appends a small diff, while a rewrite or tiny file appends the complete new instructions when that is shorter. Additions and removals remain explicit.

How

  • packages/core/src/instruction-discovery.ts compares the previous and current file arrays by path.
  • Modified files use the existing diff dependency to produce unified patches with three lines of context.
  • The renderer compares the complete diff and replacement messages and emits the shorter one.
  • Added files include their complete contents; removed files name the source that no longer applies.
  • packages/core/test/instruction-discovery.test.ts covers diff selection, replacement selection, and the real watcher-driven update/delete flow.

Scope

This does not attempt to attribute file changes to the session that made them or suppress self-authored updates. Durable instruction state, chronological updates, and compaction behavior are unchanged.

Testing

  • bun run test in packages/core: 1,709 passed, 16 skipped
  • bun run test test/instruction-discovery.test.ts in packages/core: 10 passed
  • bun typecheck in packages/core
  • Repository pre-push typecheck: 34 tasks passed
  • bunx prettier --check packages/core/src/instruction-discovery.ts packages/core/test/instruction-discovery.test.ts
  • git diff --check

Flow

flowchart LR
  A[Read instruction files] --> B[Compare with admitted values]
  B --> C{Change type}
  C -->|Modified| D[Render diff and replacement]
  D --> E[Append shorter message]
  C -->|Added| F[Append new instructions]
  C -->|Removed| G[Append removal notice]
  E --> H[Durable chronological update]
  F --> H
  G --> H
Loading

@kitlangton
kitlangton enabled auto-merge (squash) August 13, 2026 18:09
@kitlangton
kitlangton merged commit f240806 into v2 Aug 13, 2026
10 checks passed
@kitlangton
kitlangton deleted the instruction-deltas branch August 13, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant