Add brief inspect command and Artifact report - #129
Open
andrew wants to merge 3 commits into
Open
Conversation
brief inspect <path> reports on a native object or a package archive. A bare ELF/Mach-O/PE file is passed to binary.Inspect and returned as a single-entry Artifact. An archive is opened with git-pkgs/archives, hashed, extracted to a temp directory, and walked; each entry is classified with a 512-byte magic prefix read and native objects are collected into Artifact.NativeObjects with archive-relative paths. The default command auto-routes to inspect when its positional argument is a regular file whose header sniffs as a native object or archive, so brief foo.whl and brief foo.so work without the subcommand. Only the shared -json/-human flags carry over; scan-specific flags are dropped rather than passed to a FlagSet that would reject them. Adds git-pkgs/archives v0.5.0 and promotes git-pkgs/magic to v0.2.0 as direct requires. report.ArtifactHuman runs every object-derived string through sanitize so a hostile soname or dylib path cannot inject terminal escapes.
There was a problem hiding this comment.
Pull request overview
This PR adds an artifact-inspection flow to brief, introducing a new brief inspect <path> subcommand (and auto-routing from the default command) to report native-object metadata for bare binaries and package archives, plus a new brief.Artifact report type with JSON and human output.
Changes:
- Add
brief inspectsubcommand and auto-routebrief <file>to inspect when the argument sniffs as a native object or supported archive. - Introduce
brief.Artifactplus JSON/human formatters (with sanitization in human output). - Add archive extraction + per-entry magic sniffing to find embedded native objects; add tests and benchmarks; update Go module deps.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| report/report.go | Adds ArtifactJSON/ArtifactHuman output formatters for the new artifact report type. |
| cmd/brief/main.go | Routes brief <path> to inspect automatically when the arg is a native object/archive. |
| cmd/brief/inspect.go | Implements brief inspect, archive extraction + walking, and magic-based sniffing/dispatch. |
| cmd/brief/inspect_test.go | Adds unit tests for inspect behavior, sanitization test, and benchmarks. |
| artifact.go | Introduces brief.Artifact report type backing the new inspect output. |
| go.mod | Adds git-pkgs/archives and promotes git-pkgs/magic to a direct dependency. |
| go.sum | Records checksums for new/updated dependencies (archives, magic, xz). |
| .gitignore | Ignores bin/ directory. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ArtifactHuman now runs obj.Go.Version through sanitize; buildinfo is a raw byte blob in the object so a hostile binary could otherwise inject terminal escapes via the go-version field. The sanitize test now populates Go to cover this. Bare-object inputs now set Artifact.SHA256 by seeking the already-open handle back to zero and streaming through crypto/sha256, matching the archive path. inspectAutoArgs emits -- before the positional so a leading-dash filename that reached cmdScan via 'brief -- -foo.so' is not re-parsed as a flag by cmdInspect's FlagSet.
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 step after #126: wire the
binarypackage into abrief inspect <path>subcommand that accepts either a bare native object or a package archive, and addbrief.Artifactas the report type.A bare ELF/Mach-O/PE input goes straight to
binary.Inspectand is returned as a single-entryArtifact. An archive is opened withgit-pkgs/archives, hashed, extracted to a temp directory, and walked; each regular file gets a 512-bytemagic.DetectPrefixread and native hits are collected intoArtifact.NativeObjectswith archive-relative paths.Artifact.Formatis the physical container (zip,gzip,elf, ...); packaging-level identity (wheel/gem/jar) and the extracted-source toolchain scan are the next PR.The default command auto-routes to inspect when its positional argument is a regular file whose header sniffs as a native object or archive, so
brief foo.whlandbrief foo.sowork without the subcommand. Only the shared-json/-humanflags carry over fromcmdScan; scan-specific flags are dropped rather than handed to a FlagSet that would reject them.report.ArtifactHumanruns every object-derived string throughsanitizeso a hostile soname or dylib path cannot inject terminal escapes.go.mod adds
git-pkgs/archives v0.5.0and promotesgit-pkgs/magictov0.2.0as direct requires;ulikunitz/xzarrives indirect via archives.On an orjson manylinux wheel:
Benchmarks (M1 Pro):
The archive number is dominated by
ExtractAllwriting to disk; walking the archive in memory via fs.FS is a later refactor. Two knownbinary/follow-ups surfaced by inspecting brief itself, deferred to the static-hint PR: the regex source strings instatic.gosit in brief's own rodata and match themselves, andscanStaticon a ~60MB Go rodata section takes ~1.5s.