Skip to content

briefs --category: an empty answer for an unknown category says so (warning, categories_seen) - #34

Merged
makriman merged 2 commits into
mainfrom
fix/30-briefs-unknown-category
Dec 5, 2026
Merged

makriman merged 2 commits into
mainfrom
fix/30-briefs-unknown-category

Conversation

@makriman

@makriman makriman commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Problem

briefs --category nonexistentcat returns {"ok":true,"count":0,"items":[],"next_cursor":null} with exit 0. That is the same answer as a real category with nothing in it, so an agent cannot tell a typo from a quiet day. The valid categories are not documented anywhere in this repository either.

Root cause

The CLI passes --category to the API unchecked (cmdBriefs, and io.sh the same way), and the API filters on it. Nothing in the CLI knows which categories exist: there is no category list in this repository and no API route that returns one. That is why the issue's ideal fix, an exit 2 that names the valid categories, cannot be built honestly on the CLI side alone.

Change

This is the part the CLI can do on its own.

  • When a --category filter returns nothing on the first page, the CLI makes one more request for the newest 100 briefs and compares the category with theirs, ignoring case. If it is not among them, the answer carries a warning naming the category and the categories seen, plus categories_seen as an array. The exit code stays 0, because a real but quiet category can also be missing from the newest 100. The warning says "check the spelling", not "invalid".
  • Against an older API that does not page, the CLI already fetches the newest 100 to filter locally, so it reuses them and makes no extra request.
  • io.sh does the same with jq. The sample request runs in a subshell on purpose: if it fails, the original answer is printed without a hint. Without jq, io.sh prints the API's JSON unchanged, as documented.
  • --text prints the warning under "No briefs matched."
  • README and SKILL.md say that --category matches a brief's category exactly, ignoring case, and give a one-liner to list the categories in use. skill/SKILL.md was regenerated with indianopinion skill install --print.
  • CHANGELOG.md has an Unreleased entry.

Tests

test/briefs-category.test.mjs:

  • An unknown category gives an empty answer, exit 0, a warning and categories_seen ['Business', 'India', 'Politics']. Checked for the CLI and io.sh against the paging stub, and for the CLI against the older non-paging stub.
  • A known category in another case (politics) filters with no warning.
  • A real category that is empty only because of another filter (--category Business --q metro) gets no warning.
  • The text view prints the warning.

Before the change, the first and last tests fail.

The REST stub's paging /briefs now filters by category (exact, ignoring case, on section). That models what the issue reports from the live API (Governance and governance both match).

Commands run on this branch:

  • npm test (Node 22.23.4, jq 1.7, ../mcp installed): 36 tests, 36 pass, 0 skipped.
  • npm pack --dry-run: the same 6 files.
  • Not run: shellcheck, Node 20 and 24, and anything against the live API.

For the reviewer

  • The live API was not called for this change. How the live route matches category (exact name, ignoring case) is taken from the issue's report and from the CLI's own local-filter fallback, not re-checked.
  • The extra request happens only for an empty first page with --category, so the cost is one request on a path that has already found nothing.
  • What remains is an owner decision: an API route that returns the category list, or a list shipped in the CLI. With either one, the CLI could validate --category and exit 2 as the issue asks, and the MCP search_briefs tool could do the same. A list hard-coded here would go stale without anyone noticing, so this PR does not add one.

Refs #30

The API keeps no list of categories, so a misspelt --category returned
an empty page with exit 0, the same answer as a real category with
nothing in it. When a category filter finds nothing on the first page,
the CLI and io.sh (with jq) now compare it with the categories of the
newest 100 briefs and, if it is not among them, add a warning and
categories_seen. The exit code stays 0. README and SKILL.md say how
--category matches and how to list the categories in use.

The REST stub's paging /briefs now filters by category, case-insensitive
on the section, as the issue reports the live route does.

Test: test/briefs-category.test.mjs.
@makriman

makriman commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Review by Grok Bot (Indian Opinion QA agent)

Tested at head 29d8a25. Verdict: works.

Fixes: Refs #30 (a partial fix, as the PR says). An empty --category answer now carries warning and categories_seen when the category is not among the newest 100 briefs. Exit 2 with a list of valid categories would need an API route that doesn't exist yet.

What I checked

  • npm test: this head 36 tests, 35 pass, 0 fail, 1 skipped (the MCP bridge test, which skips on main too). Main: 32 tests, 31 pass.
  • Against the live public API (read-only GETs):
    • briefs --category nonexistentcat --json (CLI): main {"ok":true,"count":0,"items":[],"next_cursor":null}. This head returns the same, plus a warning and categories_seen with 8 entries: Business & Economy, Entertainment, Governance, Health & Science, India, Politics, Sports, World & Diplomacy.
    • io.sh briefs --category nonexistentcat: main count 0 and no hint. This head count 0 with 8 categories_seen.
    • briefs --category politics --limit 1 (lower case): 1 item and no warning on this head. Case-insensitive matching works live.
  • shellcheck io.sh: the same 5 notes as main.

Not checked

  • The failure path where the sample request itself errors. I read the code: it runs in a subshell and falls back to the plain answer. I didn't force that failure.

Review

  • The "newest 100" heuristic is honest about its limit. The warning says "check the spelling", not "invalid", and the exit code stays 0. That fits.
  • The README and SKILL.md lines are accurate to what I saw live.

Automated checks (this head vs current main)

Command This PR main
npm ci exit 0 exit 0
npm test exit 0: ℹ tests 36; ℹ pass 35; ℹ fail 0 exit 0: ℹ tests 32; ℹ pass 31; ℹ fail 0
npm audit --omit=dev found 0 vulnerabilities found 0 vulnerabilities

I'm Grok Bot, the automated QA agent for Indian Opinion. This is a comment-only review. I don't approve, request changes or merge. Local stack: PHP 8.4.28, Composer 2.11.3, MariaDB 11.8.9, Node 24.22.1, WordPress 7.1.5.

@makriman
makriman marked this pull request as ready for review December 5, 2026 20:17
@makriman
makriman merged commit a9add35 into main Dec 5, 2026
4 checks passed
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