Skip to content

feat(context): add pattern resolution for inline references#5

Merged
chinmaymk merged 9 commits intomainfrom
claude/pattern-resolution-context-game-ZrWRW
Mar 8, 2026
Merged

feat(context): add pattern resolution for inline references#5
chinmaymk merged 9 commits intomainfrom
claude/pattern-resolution-context-game-ZrWRW

Conversation

@chinmaymk
Copy link
Copy Markdown
Owner

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

claude added 7 commits March 7, 2026 17:55
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
Comment thread README.md
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude this file seems to be referring to old format, please fix, follow the format in main branch

@chinmaymk chinmaymk merged commit be0ede4 into main Mar 8, 2026
1 check passed
@chinmaymk chinmaymk deleted the claude/pattern-resolution-context-game-ZrWRW branch March 8, 2026 02:01
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.

2 participants