[Server] Untangle origin tracking from Registry#302
Open
chr-hertel wants to merge 1 commit into
Open
Conversation
1864939 to
483922c
Compare
Member
Author
ab11794 to
ea5c5ec
Compare
Drop the isManual flag from ElementReference and the discovery-state methods from RegistryInterface. The Registry becomes a flat last-write-wins map; DiscoveryLoader owns its own owned-set bookkeeping so re-running discovery only removes elements it itself contributed. Adds ChainLoader for explicit composition. Manual-over-discovered precedence is preserved via loader ordering, not a flag on the reference. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ea5c5ec to
2c2456f
Compare
Contributor
|
indeed, its a bit more complex then just a boolean though but I like the approach let me review. |
soyuka
approved these changes
May 12, 2026
Contributor
soyuka
left a comment
There was a problem hiding this comment.
Indeed this can replace my monkey patch its cleaner :)
| */ | ||
| final class DiscoveryLoader implements LoaderInterface | ||
| { | ||
| private DiscoveryState $owned; |
Contributor
There was a problem hiding this comment.
Suggested change
| private DiscoveryState $owned; | |
| private DiscoveryState $owned = new DiscoveryState(); |
| private array $namePatterns = DiscovererInterface::DEFAULT_NAME_PATERNS, | ||
| private LoggerInterface $logger = new NullLogger(), | ||
| ) { | ||
| $this->owned = new DiscoveryState(); |
Contributor
There was a problem hiding this comment.
Suggested change
| $this->owned = new DiscoveryState(); |
| foreach ($loaders as $loader) { | ||
| $loader->load($registry); | ||
| } | ||
| $loader = 1 === \count($loaders) ? $loaders[0] : new ChainLoader($loaders); |
Contributor
There was a problem hiding this comment.
Suggested change
| $loader = 1 === \count($loaders) ? $loaders[0] : new ChainLoader($loaders); | |
| $loader = new ChainLoader($loaders); |
is probably fine
8 tasks
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.
Summary
isManualfromElementReference(and the four subclasses); origin is no longer a property of the element.clear()/getDiscoveryState()/setDiscoveryState()fromRegistryInterface; the Registry is now a flat last-write-wins map.unregisterTool/Resource/ResourceTemplate/Prompt(string)toRegistryInterface.DiscoveryLoaderwith a private owned-set diff so re-runningload()only removes elements this loader itself contributed — preserves runtime registrations between discovery passes.ChainLoaderfor explicit composition;Builder::build()composes loaders internally so the user-facing API is unchanged.[user, discovery, manual]— last-write-wins).Supersedes #251: the runtime-registration regression that PR was fixing dissolves by construction, without adding a second origin flag (
isDiscovered).Test plan
make ci— phpstan clean, php-cs-fixer clean, 652 unit tests / 2146 assertions pass.make inspector-tests— 87 tests pass (7 environmental skips, same asmain).DiscoveryLoaderTest::testLoadDoesNotUnregisterRuntimeAdditionslocks in the regression that [Server] fix: clear() wiping dynamically registered tools by tracking discovered state on references #251 was after.combined-registrationexample still works end-to-end; theconfig://priorityresource correctly resolves to the manual override (3 inspector snapshots updated to reflect this — they were previously showing the discovered version winning, which was a latent bug).Breaking changes
ElementReference->isManualproperty removed.RegistryInterface::register*()signatures lose thebool $isManual = falseparameter.RegistryInterface::clear(),getDiscoveryState(),setDiscoveryState()removed (only correct caller wasDiscoveryLoader, which no longer needs them).Pre-1.0, internal area — no userland impact known beyond what's documented above.