Skip to content

fix(prompt): bound agent context to explicit @ references#18958

Open
Haohao-end wants to merge 3 commits intoanomalyco:devfrom
Haohao-end:fix/18910-reference-scope-lock
Open

fix(prompt): bound agent context to explicit @ references#18958
Haohao-end wants to merge 3 commits intoanomalyco:devfrom
Haohao-end:fix/18910-reference-scope-lock

Conversation

@Haohao-end
Copy link

Issue for this PR

Closes #18910

Type of change

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

What does this PR do?

This fixes a prompt-scoping issue for explicit @file / @directory references.

Right now resolvePromptParts() expands explicit references into message parts, but there is no strong reminder telling the model that those references are the intended working set for the current turn. Because of that, the model can still greedily expand into sibling directories, parent directories, or unrelated files even when the user already pointed it at a specific file or directory.

This change does three small things:

  • resolvePromptParts() now preserves source text metadata for explicit @... file and directory references
  • createUserMessage() injects a short synthetic <system-reminder> only when the current user message contains explicit file references from @...
  • default.txt gets one short rule reinforcing that explicit references should be treated as the initial working set

Why this works:
the fix binds the reminder to the current turn’s explicit references instead of all later-read files. That means the model is told to start from the user-provided scope and avoid broadening unless that scope is not enough to complete the task.

I also added focused regression tests for:

  • injecting the reminder when the user explicitly references a file and a directory
  • not injecting the reminder for ordinary file parts that were not created from explicit @... references

How did you verify your code works?

I tested this locally with:

  • cd packages/opencode && bun test test/session/prompt.test.ts
  • cd packages/opencode && bun typecheck

The branch also passed the pre-push typecheck:

  • bun turbo typecheck

Screenshots / recordings

Not a UI change.

Checklist

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

If you do not follow this template your PR will be automatically rejected.

@Haohao-end
Copy link
Author

Local verification for this change passed:

  • cd packages/opencode && bun test test/session/prompt.test.ts
  • cd packages/opencode && bun typecheck
  • bun turbo typecheck

After updating the branch to the latest dev, the remaining failing checks appear unrelated to this prompt-scoping change:

  • nix-eval fails in nix/opencode.nix with unknown hash algorithm 'got'
  • test fails in cross-spawn spawner > large output > does not deadlock on large stdout

My change only touches:

  • packages/opencode/src/session/prompt.ts
  • packages/opencode/src/session/prompt/default.txt
  • packages/opencode/test/session/prompt.test.ts

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.

Big Pickle overstepping file/directory reference

1 participant