feat(mcp): add diff_ports for observing what a change did - #68
Merged
Merged
Conversation
The first call records a baseline, the next reports what opened, closed, or changed owner since. A port whose PID changed is reported as replaced, not as a close plus an open, so a restart is distinguishable from a shutdown. Diffing across a changed `all` setting is refused: every connection would otherwise appear newly opened, which reads as a finding and is an artefact.
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.
Second of Tier 3. An agent could already list ports, but not answer the question people actually ask: "what did starting that actually change?" Doing it by hand means calling
list_portstwice and diffing JSON in the model's head, which is exactly the kind of thing models get subtly wrong.diff_portsrecords a baseline on the first call and reports what changed on the next.A restart is not a close plus an open
The design decision worth reviewing. Keying by
(port, protocol)means a service that came back on the same port keeps its key and changes its PID — reported as replaced:{"baseline_age_seconds":2,"opened":[],"closed":[],"replaced":[ {"port":3000,"protocol":"TCP", "before":{"pid":6,"process":"node"}, "after":{"pid":45,"process":"node"}}]}Reported as a close and an open, that would read as "your service went down and something else took the port" — a materially different and alarming claim. Verified against a real restart: pid 6 → 45 on port 3000.
Keying on
(port, protocol)rather than port alone also means a service dropping its IPv6 listener while keeping IPv4 shows up, instead of being masked.Baselines with a different view are refused
Testing surfaced a footgun: baseline with
all=false, then diff withall=true, and every established connection on the machine appears as newly opened. That looks like a real finding and is an artefact. It now refuses with something actionable:Notes
compute_diff) with no I/O or shared state, so it is unit-tested directly;tool_diff_portsonly handles the baseline around it.HashMaporder is not stable, and unsorted output would appear to change between two identical calls.--read-onlyservers: it only reads the machine. The baseline is the server's own memory of a previous look, not a change to anything.instructionsstring now mentionsdiff_portsand thekill_portdry run — that string is what the model reads at initialize, and an unmentioned tool is a rarely-used one.Verification
One long-lived server driven over a FIFO, with real services starting and stopping between calls — the baseline lives in the process, so a canned pipe cannot test it:
191 tests, fmt/clippy clean, macOS + Windows type-check.
Remaining in Tier 3: process tree in
inspect_port.