Skip to content

Add an output filter for glab #203

Description

@Koukyosyumei

Add an output filter for glab

h5i compresses noisy command output before it reaches an agent's context (this powers h5i capture run). Filters are small declarative TOML rule files under assets/filters/, embedded into the binary at build time. This is a self-contained good-first-issue: add a filter for glab. No changes to core logic are needed.

Why

The GitLab CLI prints decorated tables and banners; the signal is the result rows, IDs/URLs, and errors.

What to keep / strip

  • Keep (the signal): result identifiers/URLs, status, and error messages.
  • Strip (the noise): ANSI decoration, table padding, and blank lines.

Steps

  1. Create assets/filters/glab.toml.
  2. Match the command with a match_command regex, e.g. match_command = "^glab\\b". Make it match typical invocations but not unrelated commands.
  3. Use the fields below to strip the noise and keep the signal.
  4. Add 2–3 inline golden tests ([[tests.glab]]): a normal run, an error/failure run, and a clean/empty run if relevant.

Available fields (see src/filter_rules.rs)

description, match_command, strip_ansi, replace (pattern/replacement), match_output (pattern/message/unless), strip_lines_matching, keep_lines_matching, truncate_lines_at, head_lines, tail_lines, max_lines, on_empty.

Copy an existing filter as a starting point — e.g. eslint.toml (line-strip style) or ping.toml (tail-only style).

Golden-test shape

[filters.glab]
description = ""
match_command = "^glab\\b"
strip_ansi = true
strip_lines_matching = [ "^\\s*$" ]

[[tests.glab]]
name = "keeps the summary, drops the noise"
input = """…raw output…"""
expected = """…filtered output…"""

How to verify

cargo test builtin_golden_tests_pass     # runs every filter's inline golden tests
cargo test --test filter_quality         # token-cut + signal-preservation checks

(On low-RAM machines, build single-job: cargo build -j1.)

Reference

The upstream rtk project has a glab adapter — see its src/filters/ and src/cmds/ for inspiration on what matters in the output. h5i's filters are derived from rtk (see assets/filters/NOTICE).

Acceptance criteria

  • assets/filters/glab.toml added with a clear description
  • match_command matches typical glab invocations and not unrelated ones
  • At least 2 golden tests pass (normal + error/edge)
  • Real token reduction on a sizeable run, with the important signal preserved

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions