feat(context): add pattern resolution for inline references#5
Merged
feat(context): add pattern resolution for inline references#5
Conversation
Add a resolver system that scans user messages for configurable patterns like @path and url:https://... and resolves them to content before the model sees the message. Ships with two built-in resolvers (file and URL) enabled by default, and supports custom resolvers via TypeScript files. https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
- Extract shared resolvePath() utility, reuse in middleware loader - Fix re-resolution bug: add marker to skip already-resolved messages - Fix TOCTOU: read files directly with try/catch instead of exists() - Parallelize glob file reads with Promise.all - Use Set for O(1) dedup instead of O(n) linear scan - Spread resolver objects instead of mutating imports - Remove redundant regex cloning, reset lastIndex directly https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
…rtial failures - Copy resolver pattern into a new RegExp instead of mutating the original's lastIndex. Ensures the `g` flag is always present, preventing infinite loops when custom resolvers omit it. - Use Promise.allSettled for glob file reads so one unreadable file doesn't discard all other successfully read files. - Add regression tests for both bugs. https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
… loop - Block path traversal: file resolver rejects refs that resolve outside cwd (e.g. @../../etc/passwd) - Add negative lookbehind to @ pattern so email addresses like user@domain.com don't trigger file resolution - Guard against zero-length regex matches that would loop forever - Remove unused builtinResolvers import from index.ts - Add regression tests for all four issues https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
Keep our feature branch additions (Features, Why ra, Pattern Resolution, Architecture sections) while incorporating upstream changes. https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
- Add `resolvers: []` to ContextConfig in discovery.test.ts - Add `usage` and `lastUsage` to LoopContext in resolve-middleware.test.ts https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
- Use `instanceof RegExp` in resolver-loader to reject non-regex
pattern fields (previously only checked truthiness)
- Simplify path traversal guard to `relative(cwd, absPath).startsWith('..')`
instead of string prefix comparison
https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T
chinmaymk
commented
Mar 8, 2026
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.
Add a resolver system that scans user messages for configurable patterns like @path and url:https://... and resolves them to content before the model sees the message. Ships with two built-in resolvers (file and URL) enabled by default, and supports custom resolvers via TypeScript files.
https://claude.ai/code/session_01Paz2SL4gHJZnXyPs1rzA3T