Skip to content

feat(browser): network --filter <fields> for agent-native request discovery#1103

Merged
jackwener merged 1 commit intomainfrom
feat/browser-network-filter
Apr 20, 2026
Merged

feat(browser): network --filter <fields> for agent-native request discovery#1103
jackwener merged 1 commit intomainfrom
feat/browser-network-filter

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

Agents on a page with a wall of network requests know which fields a target request's body should carry (e.g. author, text, likes) but not which of the captured requests is the one. This adds opencli browser network --filter <fields> so they can narrow the list directly instead of scrolling shapes.

opencli browser network --filter author,text,likes
# → only entries whose shape has ALL three fields as some path segment
  • Matching: "any-segment" — field matches if it equals any segment of any shape path. Array indices [N] are stripped; $[\"nick name\"] unwraps. So $.data.items[0].author.name contains data, items, author, name.
  • Combination: AND across fields.
  • Case-sensitive (JSON keys are).
  • Parse: ,-split, trim, drop empties, dedupe preserving first-seen order.
  • Errors:
    • invalid_filter for \"\" / whitespace-only / ,,,
    • invalid_args when combined with --detail (mutually exclusive — one fetches a key, one narrows a list)
  • Empty match is not an errorentries: [], count: 0, exit 0.
  • Envelope adds filter: [...] (echo) and filter_dropped: N (dropped by --filter, separate from the existing static-resource filtered_out).
  • Cache still stores the unfiltered capture, so later --detail <key> resolves requests that --filter hid.
  • --raw / --all compose normally.

Test plan

  • node node_modules/vitest/vitest.mjs run src/browser/shape-filter.test.ts src/cli.test.ts — 2 files / 68 tests pass
  • New unit module src/browser/shape-filter.ts covers parse, segment extraction (dotted, array indices, bracket keys), AND matching, case sensitivity
  • New integration tests in src/cli.test.ts cover: AND narrowing, container-segment match, 0-match empty result (not error), case sensitivity, --filter + --raw, --filter + --detail → invalid_args, invalid_filter for empty / commas-only, and that --detail still finds keys hidden by --filter (cache stays unfiltered)
  • Skill docs updated (opencli-adapter-author/references/api-discovery.md, opencli-autofix/SKILL.md) with the new flag
  • TypeScript `tsc --noEmit` clean

… discovery

Agents often know what fields a target request's body should contain
but not which captured request carries it. --filter lets them declare
the field set and get back only matching entries.

Matching is "any-segment": a field matches when it equals any segment
name of any inferShape() path (ignoring root $, array indices, and
bracket-quoted key syntax). Multiple fields AND together. Case-sensitive.

- invalid_filter for empty / commas-only values
- invalid_args when combined with --detail (mutually exclusive)
- 0 matches is a valid empty result, not an error
- persisted cache stays unfiltered so later --detail lookups still resolve

Envelope gains `filter` (echo) and `filter_dropped` (count of entries
passing the static-resource filter but not --filter). Existing --raw
and --all compose normally.
@jackwener jackwener merged commit 37020c4 into main Apr 20, 2026
13 checks passed
luxiaolei pushed a commit to luxiaolei/OpenCLI that referenced this pull request Apr 21, 2026
… discovery (jackwener#1103)

Agents often know what fields a target request's body should contain
but not which captured request carries it. --filter lets them declare
the field set and get back only matching entries.

Matching is "any-segment": a field matches when it equals any segment
name of any inferShape() path (ignoring root $, array indices, and
bracket-quoted key syntax). Multiple fields AND together. Case-sensitive.

- invalid_filter for empty / commas-only values
- invalid_args when combined with --detail (mutually exclusive)
- 0 matches is a valid empty result, not an error
- persisted cache stays unfiltered so later --detail lookups still resolve

Envelope gains `filter` (echo) and `filter_dropped` (count of entries
passing the static-resource filter but not --filter). Existing --raw
and --all compose normally.

(cherry picked from commit 37020c4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant