Repository navigation
Rework the terminal UI of scan, list, show, get, rollback and vex; faster startup and multi-project scans - #2153
Conversation
aff1dd8 to
fe28187
Compare
PR SummaryMedium Risk Overview Adds patch intelligence to listings: new Interactive New Scan reporting moves row/totals rendering into Performance-oriented API usage: Rollback output counts packages in the success block, optional check marks, and avoids duplicating manifest removal lists when rollbacks already named those packages. Reviewed by Cursor Bugbot for commit 71effb3. Configure here. |
fe28187 to
71effb3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 71effb3. Configure here.
…oject pnpm records a project's own patch of a package as a group of that package's lock key: `a@1.0.0(patch_hash=...)`. It also repeats a patched package's whole key, hash included, inside the peer group of every package that depends on it: `b@2.0.0(a@1.0.0(patch_hash=...))`. The project-patch detector looked for `patch_hash=` anywhere in a key, so each of those dependents was read as patched by the project. A scan leaves a package the project patches itself alone, so the dependents were withheld from Socket patches (twelve packages in one large pnpm monorepo, beside the twenty-one it really patches) and each got a `user_patch_conflict` warning. Only a group at the first level of a key counts now. A pnpm 7 key has no groups and still carries the hash on its version, and `patched: true` is read as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…y to the API client What the terminal UI reads from the patch service, and what lets a scan of several project directories ask about a package once: - `PatchResponse.statistics` and its types: what the patch service measured about a patch (exploits blocked, package tests passing, the size of the change, its run-time cost). - `fetch_patch_statistics`, `fetch_patch_summary` and `fetch_patch_with_sources`: the patch view without its file contents (for measurements and listings) and with each file's content before the patch (for a diff). The authenticated API leaves the contents out on request; the public proxy serves one cached view either way. - `ApiClient::remembering_lookups`: a client that keeps the answers to its batch and per-package searches and answers a later search it has the whole answer to without a request. Off unless asked for. Only answers are kept, never failures, and only for exactly the purl asked. - The selection filter exposes whether it carries reachability findings, and the state of one. - The walk that finds a checkout's project markers runs on as many threads as the crawl's walk pool. It is every hosted or vendored scan's first wait in a large checkout. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Human output only: `--json` envelopes, warnings and events are unchanged. scan - Each patched package is one row (severity, package, advisories, what was measured about the patch, advisories left unpatched), and the run closes with its totals once: packages patched across how many project directories, vulnerabilities fixed, what is left to patch and why, the same for reachable advisories when a selection filter carries findings, and an estimate of the upgrade work the patches stood in for (two hours per patched package, stated as an assumption). - The packages the project patches itself are one note instead of a warning per package. `--verbose` lists them. - The status line opens with an activity mark that a ticker keeps turning for as long as the line shows, so a long step never looks hung. It draws on a terminal only, under one lock with every other status write. - Startup: the search for project directories an agent-mode scan does not cover runs during the patch lookup, the policy step reuses the `node_modules` roots the crawl walked instead of walking again, and the project's own patches are read beside the crawl. - A scan of several project directories crawls them all at once and asks the patch service about each package once for the run, then scans the directories in order as before. list, show - `show <patch>` is new: the advisories a patch fixes, what was measured about it, the files it changes and the diff of each. - On a terminal `list` is a full-screen table that fills in from the patch service (advisories, severity, exploits blocked, tests passing, lines changed, run-time cost, publish date). Enter opens a patch as a page with its summary and diffs. `show` opens the same page. Both redraw when the terminal is resized and leave the scrollback as it was. Pipes, `--yes` and `--verbose` keep the printed listing. get, rollback, vex - `get` shows the measurements of the patches it lists and no longer names each patch again while it downloads and applies. - `rollback` lists the packages it restored once and shows progress. - `vex` holds its advisories while it works and prints them folded by kind, groups the patches it leaves out by reason, and says how to get the patches installed when nothing could be attested. Its record fetch asks for views without file contents. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Patch view - A patch whose `statistics` this build cannot read (a field of another type, an array where an object belongs) no longer fails the whole patch view, which `get`, `show` and `vex` read: each measurement is parsed on its own and one that does not parse is left off. Scan - The prefetch of a multi-directory scan stands down where file descriptors are scarce, as every other part of a run does there. A crawl that runs out of descriptors reads a directory it could not open as absent and comes back short. - Measurement requests keep to the patch API's own window instead of 16 at once (the public proxy's window is small), are not retried (a retry opened the run's one retry window, which the downloads that follow may need), and a listing waits at most 1.5 s for them. - The rows of a dry run and of a report-only scan no longer open with the check mark of a patch in place: the column stays and is blank. Rollback - The status line comes down before a gem's native extension is rebuilt, which reports its own progress, and goes back up for the next package. list and show - The browser cut one read into one key. Several presses that arrive together (a held arrow, a paste, a slow link) were read as a sequence it does not know and dropped, and an escape sequence split across two reads was read as Esc and closed the page. A read is now cut into its keys, each acted on in order, and the start of a sequence at the end of a read waits 40 ms for its rest before it is taken for Esc. - Neither goes full-screen on a terminal that shows no escape sequences (`TERM=dumb`, a console without VT processing): `list` prints its entries and `show` its text, as on a pipe. - `list` puts its table up before it builds the patch service's client, which can mean a request (a token with no organization named has its organization looked up). The first read that needs the client builds it. Advisories are held while the browser has the screen and the one that explains the rows prints once it is gone. Shared - The package naming and folding helpers that scan, list and vex each wrote out are one copy in `ui/text.rs`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`show` and the page a row of `list` opens were one screen fed by two readers, and `show` kept a second, older way to read a patch on a terminal: a menu of its files and an external pager. - One source of patches (`show::Source`) and one reader (`Shown::read`) serve `show`, the page a `list` row opens and the rows of the `list` table. A read the service refuses the run's token is asked of the public service. When that has no such patch either, the refusal is what is reported, not the public service's "no such patch". - `show` has one reading screen, the page. The file menu and the pager are gone: where the page cannot open (a pipe, `--no-pager`, `--yes`, a terminal that shows no escape sequences, Windows) the summary and the selected diffs print at once. - The inline stand-in for the `list` table prints a pick's summary (`show --stat`) instead of every diff. - The worst severity and the advisory ids of a patch follow one rule (`ui::worst_and_ids`) in the `list` row, `show`'s title and the patch menu. An advisory that names no severity leaves none in the title. - The reason a `list` page gives for showing the project's own record is one line ending in one period, whatever the error's text. Tests: Enter on a `list` row and `show <uuid>` draw the same page line for line on a pty; a refused token is read from the public service, and the refusal is reported when that has no such patch; `show --yes` on a terminal prints at once and opens nothing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Some agent harnesses run commands on a pseudo-terminal, and there the CLI took the agent for a person. Measured on one: `list` in a patched project went full-screen and waited for keys nobody presses, and a dry-run scan of a large monorepo wrote 122 KB of which 12 KB was output; the rest was redraws of the status line and color codes, all of it read back into the agent's context. - `ui::attended(stream)` is the one place that says whether a stream is a terminal with a person at it: a terminal, and not one an agent runs the command in. Every presentation choice asks it instead of `is_terminal()`: the status line, color and glyphs, the full-screen `list` and `show`, the arrow-key menus, text fitted to the terminal's width, the measurements a terminal gets, the update notice. With the same scan the agent now reads 11.6 KB and no escape sequence, and `list` prints and exits. - An agent is recognized by a variable it sets for the commands it runs: `AI_AGENT`, then each tool's own (`CLAUDECODE`, `CURSOR_AGENT`, `CODEX_SANDBOX`, `GEMINI_CLI`, `VSCODE_AGENT` and others; the list is `ui::AGENT_ENV_VARS`). A variable an editor sets in every terminal is not used, and neither is the bare `AGENT`. - `SOCKET_PLAIN` overrides the detection, in the vocabulary of the other toggles: truthy asks for plain output anywhere, any other value keeps the terminal output for someone working in a terminal an agent started. Where an agent's variable keeps `list`, `show` or a menu from opening, one line on stderr names the variable and `SOCKET_PLAIN=0`. - Typed yes/no confirmations are not presentation and are unchanged: they are asked on any terminal, and `--yes` answers them. - `--json` is unchanged. Tests: the detection's truth table; on a pty, `list` and `scan` under an agent's variable print without one escape sequence, `SOCKET_PLAIN=0` brings the table back, and `remove` still asks its question; a source scan that no terminal check outside `src/ui/` bypasses `ui::attended`. The hermetic test environment drops the agent variables, so the pty suites test the terminal output whoever runs them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
5c62a5c to
a5a9603
Compare
… from its top Two review comments. - The browser waits 40 ms for the rest of an escape sequence before it takes a lone Esc for the Esc key. A signal that cut that wait short was read as the time having passed, so a terminal resized (or a child exiting) in the middle of an arrow key turned its first byte into Esc and closed the page: the false Esc the wait exists to prevent. The wait is now taken up again for the time that is left. - `get` asked for the measurements of the first 32 patches in the order the search returned them, then listed the patches by package. A long listing could show measurements on rows further down and none on the first ones. The 32 are now the first in the order the listing shows. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
list - What a project records as a patch's uuid comes from its own files. `list` on a terminal put it into the path of a request to the patch service, with the user's token, whatever it was. Only a recorded uuid that is a UUID is asked about now: any other keeps its row and opens as the project's own record. - The browser stays down under `SOCKET_DEBUG`, as the status line does: the debug lines landed in the middle of its frames. show - A search the patch service failed for any reason was asked again of the public service, whose "nothing for this package" then replaced the real error. Only a refused token is, and the refusal stays the answer when the public service has nothing. - `--file` is checked before every form of output: a path the patch does not change is `file_not_in_patch` under `--json` and `--silent` too. - Of several matching patches, with nobody to ask, the best ranked one the account can read is shown: a paid patch ranked first no longer fails the run when a free one is there. - What the service says about a patch (description, license, advisory summaries, file paths) is shown without its control characters. - The page keeps the indentation of code (a tab runs to the next stop) and shows wide characters, which it had blanked. scan - The read made ahead of a multi-directory scan asks the patch service only what each directory's scan would: not about a package the policy or a selection filter leaves out, a project the policy excludes, or a package the project patches itself. What the project patches itself is read once, with the crawl, and handed to the scan. - All of a run's measurement requests share one window. Each round had its own, and a scan of many directories starts a round for each. - A lookup that fails still names the project directories below that the run did not cover, as it did before the search for them moved behind the lookup. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The parent branch landed on main squashed (#2157), so every file it added conflicted add/add. The merge takes the parent's last tip as its base, so only what main changed since then is merged in: #2159's VEX attestation, #2153's terminal UI and the rest. - scan/hosted.rs: keep this branch's removal of the hub notice from the hosted run. A hosted run patches a pinned hub or says why not among its rewriters' warnings, so the notice would repeat or contradict them. - scripts/loc-budget.json: the bazel group's cap is 2486, the count after the merge (this branch's 775 lines over main's 1711). cargo clippy -D warnings, the core lib tests, vendor_jvm_cli, e2e_bazel_maven_beside and the Maven CLI tests pass. Assisted-by: Claude Code:claude-opus-5-5

Reworks the human (non-
--json) output ofscan,get,rollback,listandvex, addsshow, fixes a project-patch detection bug that the old output was drowning in, and makes scans start and finish sooner.--jsonenvelopes, warnings and events are unchanged.What changes for someone at a terminal
scan
--verboselists them.list and show
show <patch>is new: the advisories a patch fixes, what was measured about it, the files it changes and the diff of each.listis a full-screen table that goes up at once with what the project records and fills in from the patch service: advisories, colored severity, exploits blocked, tests passing, lines changed, run-time cost, publish date. Enter opens a patch as a page (summary, measurements, every file's diff;n/pstep between files).showopens the same page: one reader of the patch and one screen serve both. Both redraw when the terminal is resized and leave the scrollback as it was.--yesand--verbosekeep the printed listing and make no request.An AI coding agent's terminal
listorshow, no arrow-key menus. Measured on a pseudo-terminal before the change,listwent full-screen and waited for keys, and a dry-run scan of a large monorepo wrote 122 KB of which 12 KB was output. After it, the scan writes 11.6 KB with no escape sequence, andlistprints and exits.AI_AGENT,CLAUDECODE,CURSOR_AGENT,CODEX_SANDBOX,GEMINI_CLI,VSCODE_AGENTand others).SOCKET_PLAIN=0keeps the terminal output for a person working in a terminal an agent started, andSOCKET_PLAIN=1asks for the plain output anywhere.--yesanswers them.get, rollback, vex
getshows the measurements of the patches it lists and no longer names each patch again while it downloads and applies.rollbacklists the packages it restored once and shows progress.vexprints its advisories folded by kind and the patches it leaves out grouped by reason, and says how to get the patches installed when nothing could be attested.The bug fix
pnpm repeats a patched package's whole lock key, hash included, inside the peer group of every package that depends on it (
b@2.0.0(a@1.0.0(patch_hash=...))). The project-patch detector looked forpatch_hash=anywhere in a key, so every such dependent was treated as patched by the project: withheld from Socket patches, with auser_patch_conflictwarning each. Only a first-level group counts now. In one large pnpm monorepo that was 12 of 33 flagged packages.Speed
Measured on a pnpm monorepo with 17 project directories, optimized builds, dry runs:
vex, totalnode_modulesroots the crawl walked instead of walking the tree again.--max-new-patchesbudget and every write stay ordered.vexfetches patch records without their file contents, which the record does not use.Things a reviewer should know
Saved about 44 hours of engineering time (22 package upgrades at ~2 hours each).uses two hours per patched package. That figure is an assumption, stated in the line and in the docs.scan_hosted_paths_run_once_per_project_directoryexpected one batch lookup per directory; two directories holding the same package now produce one.showand the page alistrow opens share one source of patches, one reader and one screen.showhas no file menu and no external pager: where the page cannot open (a pipe,--no-pager,--yes, a terminal without escape sequences, Windows) the summary and the selected diffs print at once. A token the patch service refuses is read from the public service in both, and when that has no such patch either the refusal is what is reported.AI_AGENTandCLAUDECODE(which the author's own shell sets) come from open-source detection libraries, not vendor documentation. A wrong name is inert, and a false positive costs a person the animation until they setSOCKET_PLAIN=0; wherelist,showor a menu would have opened, one line on stderr names the variable and the override. The bareAGENTis deliberately not used.infoalias.showhas no alias: a test pins that v5 has no subcommand aliases.Code review
/code-review highreturned ten findings. Nine are fixed in the last commit:statisticsthis build could not read (a field of another type, an array where an object belongs) failed the whole patch view, whichget,showandvexread. Each measurement is now parsed on its own, and one that does not parse is left off.rollback's status line stayed up while a gem's native extension was rebuilt, which prints its own progress. It comes down first and goes back up for the next package.read()as one key. Several presses arriving together were dropped, and an escape sequence split across two reads was taken for Esc and closed the page. A read is now cut into its keys, and the start of a sequence at the end of a read waits 40 ms for its rest.listandshowwent full-screen on a terminal that shows no escape sequences (TERM=dumb, a console without VT processing). They print there, as on a pipe.listbuilt the patch service's client, which can mean an organization lookup, before its table went up. The table goes up first and the first read that needs the client builds it. Advisories are held while the browser has the screen.scan,listandvex. They are one copy inui/text.rs.Before merging
/code-review highwas run again on the whole PR once it was approved, and the two inline comments of the automated reviewer were answered. All of it is fixed in the last two commits:getmeasured the first 32 patches in search order, not the first 32 it lists.listsent a project's recorded uuid to the patch service unchecked. The uuid comes from the project's own files, andliston a terminal put it in a request path with the user's token. Only a uuid that is a UUID is asked about now.show. A search the service failed for any reason fell back to the public service, whose empty answer replaced the real error; only a refused token does now.--fileis validated under--jsonand--silenttoo. Of several matching patches the best ranked one the account can read is shown. Text the service supplies is shown without control characters. The page keeps tabs as indentation and shows wide characters.scan. The read made ahead of a multi-directory scan asks only what each directory's scan would ask (not about a package the policy or a filter leaves out, a project the policy excludes, or a package the project patches itself), and hands what it read of the project's own patches to the scan. All of a run's measurement requests share one concurrency window. A failed lookup still names the project directories the run did not cover.SOCKET_DEBUGthe full-screen browser stays down, as the status line does.Still as it was: the read made ahead keeps every directory's crawl in memory until that directory's turn, and works out each directory's lockfile supplement, which the directory's scan works out again. Neither changes a result. Removing them means splitting the scan function into a gather half and an ordered report half, the same refactor as the "Not done" item above.
Verification
main, with the review fixes:cargo fmt --checkand clippy (--workspace --all-features -D warnings) are clean, all 7,968 core unit tests pass, and the whole CLI test suite (214 test binaries, 5,458 tests) passes apart from twoe2e_vendor_cargo_buildtests that need an x86cargothe test machine cannot run.mainmoved: text conflicts inCLI_CONTRACT.mdandscan/hosted.rs, and one call updated for an argumentmainadded):cargo fmt --checkand clippy are clean and every test target type-checks on the pushed head. On the first rebase the 8,010 core unit tests, the 1,002 CLI unit tests and the 24 test suites the change touches (scan, cli, vex, get, rollback, show and the in-process scan, get, redirect, vendor and rollback suites; 1,306 tests) passed. On the pushed head the CLI unit tests and the scan, cli, vex, get, rollback and show suites passed again. The rest of the CLI suite has not been re-run locally on the rebased tree; CI runs it./code-review highon its own; of its seven candidates six are fixed in it and the seventh, that a terminal with no full-screen page gets every diff printed at once, is the deliberate result of having one reading screen. The 1,003 CLI unit tests and the cli, show and help-text suites pass, including a pty test that Enter on alistrow andshow <uuid>draw the same page line for line./code-review highon its own. Of its ten candidates nine are fixed in it (a missed call site, a Windows color gate, the override's vocabulary, variable names, stale wording, a guard test, caching); the tenth, that a person in a terminal an agent started gets no status line during a scan, is answered by the override and by the note onlist,showand menus rather than by a line on every agent's scan.apply.rs, where the compact summary of a nested apply now also carriesmain's newnot in effectandnot applicablebuckets): clippy is clean, every test target type-checks, and the 1,014 CLI unit tests and the cli, scan, apply, get, rollback, remove, update, vex, show, layering and spawn-hygiene suites pass.mainas it stood then. The 1,018 CLI unit tests and 23 suites pass (cli, scan, apply, get, rollback, remove, update, vex, show, the in-process scan, get, redirect and vendor suites, the rollout, vendor, retry andsocket.ymlpolicy suites, layering, spawn hygiene, help text), with new tests for each fix.🤖 Generated with Claude Code