apexe 0.6.1

Outside-In CLI-to-Agent Bridge
{
  "schema_version": "1.0",
  "command": "grep",
  "variant": "bsd",
  "match": {
    "platform": ["macos", "freebsd"],
    "probe": {
      "args": ["--version"],
      "expect": "success",
      "output_contains": "BSD grep"
    },
    "binary_globs": ["/usr/bin/grep", "/bin/grep"]
  },
  "mode": "authoritative",
  "confidence": "verified",
  "provenance": {
    "platform": "macos",
    "tool_version": "macOS 26.3",
    "source": "man-page",
    "checked_on": "2026-07-27",
    "command": "man -P cat grep | col -b",
    "environment": "macOS 26.3 (Darwin arm64), system /usr/bin/grep, banner 'grep (BSD grep, GNU compatible) 2.6.0-FreeBSD'",
    "notes": "Flags transcribed from the block after 'The following options are available:'. This page has no COMPATIBILITY or LEGACY DESCRIPTION section; STANDARDS was read for flags documented outside that block and records only which flags extend POSIX, that all long options exist for GNU compatibility, and that the historic [-ruy] flags are still supported though discouraged -- all three are already in the option block. The option set is closed by the binary: the getopt(3) option string is '0123456789A:B:C:D:EFGHIJLMOSRUVXZabcd:e:f:hilm:nopqrsuvwxyz' and the long option table carries 47 names, every one of which was run and accepted. mode is therefore authoritative. The leading digits are real standalone options here: 'grep -1 pattern file' prints one line of context, the same as -C1. They are a family of numeric context sizes rather than named options, so the overlay format cannot carry them. Two long options are accepted by the binary but appear NOWHERE in the macOS 26.3 man page, which is the same failure mode as BSD 'touch -f': --with-filename and --unix-byte-offsets. Both were run against the binary and behave identically to the short options they pair with here -- 'grep --with-filename' prints the same 'g2.txt:hello' as 'grep -H', and 'grep --unix-byte-offsets -b' prints the same offset as 'grep -u -b' -- so they are listed as the long forms of -H and -u rather than with an invented meaning. -C requires a value ('grep -C pattern file' fails with 'Invalid argument'), and accepts it attached or separated; --context by contrast takes an OPTIONAL value, so bare '--context' selects unlimited context while '--context=1' selects one line. --color and --colour also take an optional attached value, and 'grep --color always' reads always as the pattern. conflicts_with comes from this page's own prose and was then tested against the binary. Declared: -n with -c, -L, -l and -q, from '-n ... This option is ignored if -c, -L, -l, or -q is specified' -- the binary accepts the pairing and silently drops the line numbers, which is the same shape as GNU cp's '-f ... is ignored when the -n option is also used', already recorded as a conflict in cp@gnu.json; and -w with -x, from '-w ... This option has no effect if -x is also specified', confirmed because 'grep -w -x hello' matches only the whole-line form. Candidates tested and REJECTED: -E, -F and -G coexist here in every ordering, with the last one winning, so no matcher conflict is declared -- GNU grep diagnoses exactly those pairs with 'conflicting matchers specified', which is why the two variants differ; -l with -L (the later option wins); -c with -o and with -l; and -O, -p and -S, which the man page describes as three answers to the same symlink question but which the binary accepts together. BSD grep ANSWERS --version, with 'grep (BSD grep, GNU compatible) 2.6.0-FreeBSD'; the probe therefore expects success plus that banner, and the same banner is what makes the scanner classify it bsd -- the BSD test runs before the GNU test precisely so that 'GNU compatible' does not win. --help is accepted but prints the usage line and exits 1. annotations: grep opens every operand read-only and has no option that names an output file, so readonly is true; requires_approval is stated false to override the scanner's flag heuristic, which would otherwise escalate on -r/-R/--recursive even though recursion here only widens what is read. conflicts_with was extended in a later pass, after the field's definition widened to cover override groups as well as diagnosed errors: apexe's input is a JSON object, which carries no ordering, so for a last-one-wins group which flag actually wins is decided by the order the caller happened to write the keys in. Every pair added then was run in BOTH orders against the reference build recorded above, and only pairs whose outcome depends on that order, or where one side is silently discarded, were added. value_optional was added on 2026-08-24 and established behaviourally on the build recorded above, since a BSD man page has no notation for an optional option argument: each candidate was run in BOTH spellings and marked only when the separated form demonstrably lost the value. `grep --context 1 hello g.txt` is \"grep: hello: No such file or directory\" (exit 2) -- the value consumed the pattern position -- while `grep --context=1 hello g.txt` succeeds; --color and --colour behave the same. --context here is the OPPOSITE of GNU grep, which spells it '--context=NUM' with a required value and accepts the separated form; the two variants must not be copied from one another on this point. --after-context and --before-context were tested and NOT marked -- both accept the separated form -- as were --devices, --directories, --exclude, --exclude-dir, --include, --include-dir, --label, --max-count and --binary-files. --regexp and --file were tested and NOT marked: both spellings fail identically there, which is the required-value signature, not an optional one."
  },
  "description": "The grep utility searches any given input files, selecting lines that match one or more patterns. By default, a pattern matches an input line if the regular expression (RE) in the pattern matches the input line without its trailing newline. An empty expression matches every line. Each input line that matches at least one of the patterns is written to the standard output. grep is used for simple patterns and basic regular expressions (BREs); egrep can handle extended regular expressions (EREs); fgrep is quicker than both but can only handle fixed patterns. If no file arguments are specified, the standard input is used. grep exits 0 when one or more lines were selected, 1 when no lines were selected, and greater than 1 when an error occurred.",
  "flags": [
    { "short": "-A", "long": "--after-context", "type": "integer", "value_name": "num", "description": "Print num lines of trailing context after each match. See also the -B and -C options." },
    { "short": "-a", "long": "--text", "type": "boolean", "description": "Treat all files as ASCII text. Normally grep will simply print \"Binary file ... matches\" if files contain binary characters. Use of this option forces grep to output lines matching the specified pattern." },
    { "short": "-B", "long": "--before-context", "type": "integer", "value_name": "num", "description": "Print num lines of leading context before each match. See also the -A and -C options." },
    { "short": "-b", "long": "--byte-offset", "type": "boolean", "description": "The offset in bytes of a matched pattern is displayed in front of the respective matched line." },
    { "short": "-C", "type": "integer", "value_name": "num", "description": "Print num lines of leading and trailing context surrounding each match. See also the -A and -B options. The value is required and may be attached or separated." },
    { "long": "--context", "type": "integer", "value_name": "num", "value_optional": true, "description": "Print num lines of leading and trailing context surrounding each match. Unlike -C the value is OPTIONAL and must be attached, as in --context=1; bare --context selects unlimited context." },
    { "short": "-c", "long": "--count", "type": "boolean", "conflicts_with": ["-n", "-l", "-L", "-o", "-q"], "description": "Only a count of selected lines is written to standard output." },
    { "long": "--color", "type": "enum", "value_name": "when", "value_optional": true, "enum_values": ["never", "always", "auto"], "description": "Mark up the matching text with the expression stored in the GREP_COLOR environment variable. The value is optional and must be attached, as in --color=always; a space-separated value is read as the pattern instead." },
    { "long": "--colour", "type": "enum", "value_name": "when", "value_optional": true, "enum_values": ["never", "always", "auto"], "description": "The same as --color. The value is optional and must be attached, as in --colour=always." },
    { "short": "-D", "long": "--devices", "type": "enum", "value_name": "action", "enum_values": ["read", "skip"], "description": "Specify the demanded action for devices, FIFOs and sockets. The default action is \"read\", which means that they are read as if they were normal files. If the action is set to \"skip\", devices are silently skipped." },
    { "short": "-d", "long": "--directories", "type": "enum", "value_name": "action", "enum_values": ["read", "skip", "recurse"], "description": "Specify the demanded action for directories. It is \"read\" by default, which means that the directories are read in the same manner as normal files. Other possible values are \"skip\" to silently ignore the directories, and \"recurse\" to read them recursively, which has the same effect as the -R and -r option." },
    { "short": "-E", "long": "--extended-regexp", "type": "boolean", "description": "Interpret pattern as an extended regular expression (i.e., force grep to behave as egrep). Unlike GNU grep this does not clash with -F or -G; the last matcher option given wins." },
    { "short": "-e", "long": "--regexp", "type": "string", "value_name": "pattern", "repeatable": true, "description": "Specify a pattern used during the search of the input: an input line is selected if it matches any of the specified patterns. This option is most useful when multiple -e options are used to specify multiple patterns, or when a pattern begins with a dash." },
    { "long": "--exclude", "type": "string", "value_name": "pattern", "repeatable": true, "description": "If specified, it excludes files matching the given filename pattern from the search. Note that --exclude and --include patterns are processed in the order given. If a name matches multiple patterns, the latest matching rule wins. If no --include pattern is specified, all files are searched that are not excluded. Patterns are matched to the full path specified, not only to the filename component." },
    { "long": "--exclude-dir", "type": "string", "value_name": "pattern", "repeatable": true, "description": "If -R is specified, it excludes directories matching the given filename pattern from the search. Note that --exclude-dir and --include-dir patterns are processed in the order given. If a name matches multiple patterns, the latest matching rule wins." },
    { "short": "-F", "long": "--fixed-strings", "type": "boolean", "description": "Interpret pattern as a set of fixed strings (i.e., force grep to behave as fgrep). Unlike GNU grep this does not clash with -E or -G; the last matcher option given wins." },
    { "short": "-f", "long": "--file", "type": "path", "value_name": "file", "repeatable": true, "description": "Read one or more newline separated patterns from file. Empty pattern lines match every input line. Newlines are not considered part of a pattern. If file is empty, nothing is matched." },
    { "short": "-G", "long": "--basic-regexp", "type": "boolean", "description": "Interpret pattern as a basic regular expression (i.e., force grep to behave as traditional grep). Unlike GNU grep this does not clash with -E or -F; the last matcher option given wins." },
    { "short": "-H", "long": "--with-filename", "type": "boolean", "conflicts_with": ["-h"], "description": "Always print filename headers with output lines. The man page documents -H with no long form; --with-filename is accepted by the binary and produces identical output." },
    { "short": "-h", "long": "--no-filename", "type": "boolean", "conflicts_with": ["-H"], "description": "Never print filename headers (i.e., filenames) with output lines." },
    { "long": "--help", "type": "boolean", "description": "Print a brief help message. It is a single usage line, not a per-option description, and the binary exits 1 after printing it." },
    { "short": "-I", "type": "boolean", "description": "Ignore binary files. This option is equivalent to the \"--binary-files=without-match\" option." },
    { "short": "-i", "long": "--ignore-case", "type": "boolean", "description": "Perform case insensitive matching. By default, grep is case sensitive." },
    { "long": "--include", "type": "string", "value_name": "pattern", "repeatable": true, "description": "If specified, only files matching the given filename pattern are searched. Note that --include and --exclude patterns are processed in the order given. If a name matches multiple patterns, the latest matching rule wins. Patterns are matched to the full path specified, not only to the filename component." },
    { "long": "--include-dir", "type": "string", "value_name": "pattern", "repeatable": true, "description": "If -R is specified, only directories matching the given filename pattern are searched. Note that --include-dir and --exclude-dir patterns are processed in the order given. If a name matches multiple patterns, the latest matching rule wins." },
    { "short": "-J", "long": "--bz2decompress", "type": "boolean", "description": "Decompress the bzip2(1) compressed file before looking for the text." },
    { "short": "-L", "long": "--files-without-match", "type": "boolean", "conflicts_with": ["-n", "-c", "-l", "-o", "-q"], "description": "Only the names of files not containing selected lines are written to standard output. Pathnames are listed once per file searched. If the standard input is searched, the string \"(standard input)\" is written unless a --label is specified." },
    { "short": "-l", "long": "--files-with-matches", "type": "boolean", "conflicts_with": ["-n", "-c", "-L", "-o", "-q"], "description": "Only the names of files containing selected lines are written to standard output. grep will only search a file until a match has been found, making searches potentially less expensive. Pathnames are listed once per file searched. If the standard input is searched, the string \"(standard input)\" is written unless a --label is specified." },
    { "long": "--label", "type": "string", "value_name": "label", "description": "Label to use in place of \"(standard input)\" for a file name where a file name would normally be printed. This option applies to -H, -L, and -l. The value may be attached or separated." },
    { "long": "--mmap", "type": "boolean", "description": "Use mmap(2) instead of read(2) to read input, which can result in better performance under some circumstances but can cause undefined behaviour." },
    { "short": "-M", "long": "--lzma", "type": "boolean", "description": "Decompress the LZMA compressed file before looking for the text." },
    { "short": "-m", "long": "--max-count", "type": "integer", "value_name": "num", "description": "Stop reading the file after num matches." },
    { "short": "-n", "long": "--line-number", "type": "boolean", "conflicts_with": ["-c", "-L", "-l", "-q"], "description": "Each output line is preceded by its relative line number in the file, starting at line 1. The line number counter is reset for each file processed. This option is ignored if -c, -L, -l, or -q is specified." },
    { "long": "--null", "type": "boolean", "description": "Prints a zero-byte after the file name." },
    { "short": "-O", "type": "boolean", "description": "If -R is specified, follow symbolic links only if they were explicitly listed on the command line. The default is not to follow symbolic links." },
    { "short": "-o", "long": "--only-matching", "type": "boolean", "conflicts_with": ["-c", "-l", "-L", "-q"], "description": "Prints only the matching part of the lines." },
    { "short": "-p", "type": "boolean", "description": "If -R is specified, no symbolic links are followed. This is the default." },
    { "short": "-q", "long": "--quiet", "type": "boolean", "conflicts_with": ["-n", "-c", "-l", "-L", "-o"], "description": "Quiet mode: suppress normal output. grep will only search a file until a match has been found, making searches potentially less expensive." },
    { "long": "--silent", "type": "boolean", "description": "The same as -q and --quiet: quiet mode, suppress normal output." },
    { "short": "-R", "long": "--recursive", "type": "boolean", "description": "Recursively search subdirectories listed (i.e., force grep to behave as rgrep)." },
    { "short": "-r", "type": "boolean", "description": "The same as -R: recursively search subdirectories listed." },
    { "short": "-S", "type": "boolean", "description": "If -R is specified, all symbolic links are followed. The default is not to follow symbolic links." },
    { "short": "-s", "long": "--no-messages", "type": "boolean", "description": "Silent mode. Nonexistent and unreadable files are ignored (i.e., their error messages are suppressed)." },
    { "short": "-U", "long": "--binary", "type": "boolean", "description": "Search binary files, but do not attempt to print them." },
    { "short": "-u", "long": "--unix-byte-offsets", "type": "boolean", "description": "This option has no effect and is provided only for compatibility with GNU grep. The man page documents -u with no long form; --unix-byte-offsets is accepted by the binary and behaves identically." },
    { "short": "-V", "long": "--version", "type": "boolean", "description": "Display version information and exit. This build answers with 'grep (BSD grep, GNU compatible) 2.6.0-FreeBSD'." },
    { "short": "-v", "long": "--invert-match", "type": "boolean", "description": "Selected lines are those not matching any of the specified patterns." },
    { "short": "-w", "long": "--word-regexp", "type": "boolean", "conflicts_with": ["-x"], "description": "The expression is searched for as a word (as if surrounded by '[[:<:]]' and '[[:>:]]'). This option has no effect if -x is also specified." },
    { "short": "-x", "long": "--line-regexp", "type": "boolean", "conflicts_with": ["-w"], "description": "Only input lines selected against an entire fixed string or regular expression are considered to be matching lines." },
    { "short": "-y", "type": "boolean", "description": "Equivalent to -i. Obsoleted." },
    { "short": "-z", "long": "--null-data", "type": "boolean", "description": "Treat input and output data as sequences of lines terminated by a zero-byte instead of a newline." },
    { "short": "-X", "long": "--xz", "type": "boolean", "description": "Decompress the xz(1) compressed file before looking for the text." },
    { "short": "-Z", "long": "--decompress", "type": "boolean", "description": "Force grep to behave as zgrep." },
    { "long": "--binary-files", "type": "enum", "value_name": "value", "enum_values": ["binary", "without-match", "text"], "description": "Controls searching and printing of binary files. binary (the default) searches binary files but does not print them, without-match does not search binary files, and text treats all files as text." },
    { "long": "--line-buffered", "type": "boolean", "description": "Force output to be line buffered. By default, output is line buffered when standard output is a terminal and block buffered otherwise." }
  ],
  "positional_args": [
    { "name": "pattern", "type": "string", "required": false, "description": "The pattern to search for. Not given when -e or -f supplies the patterns instead, in which case the first operand is read as a file name." },
    { "name": "file", "type": "path", "variadic": true, "required": false, "description": "Files to search. If no file arguments are specified, the standard input is used. A single dash (-) may be used in place of a file name anywhere a file name is accepted, including for -f." }
  ],
  "annotations": {
    "readonly": true,
    "destructive": false,
    "idempotent": true,
    "requires_approval": false
  }
}