Skip to content

BUZZ-231: add command for count - #528

Merged
sarahweeks-prolific merged 6 commits into
feat/buzz-231-audience-breakdown-commandfrom
feat/buzz-231-audience-count
Sep 30, 2026
Merged

sarahweeks-prolific merged 6 commits into
feat/buzz-231-audience-breakdown-commandfrom
feat/buzz-231-audience-count

Conversation

@sarahweeks-prolific

@sarahweeks-prolific sarahweeks-prolific commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary
Adds prolific audience count, a wrapper over POST /api/v1/eligibility-count/ that counts how many participants match a set of filters, without creating a study or saving a filter set (BUZZ-231). Counts an unsaved set of filters via -t/--template-path or --filters, or a saved filter set via --filter-set — the latter reads eligible_participant_count straight off the existing filter-set response, so it stays one request rather than a count call per filter.

$ prolific audience count -t docs/examples/audience-count.json -w
Eligible participants: 1234

$ prolific audience count --filter-set --json
{"count":42,"below_privacy_threshold":false}
The API floors counts below 5 to 0, so --json carries below_privacy_threshold next to count — a bare {"count": 0} would read as "nobody is eligible" to an agent when the truth may be "four people are".

Breaking change: this PR removes the old eligibility-count command. audience count is a strict superset — same -t/-w flags, same template format — so prolific eligibility-count -t filters.json -w becomes prolific audience count -t filters.json -w . Noted under ## next in CHANGELOG.md. The old command's help text said the privacy floor was 25; the published spec says 5 in two independent places (the count endpoint description and the filter-set response field), so audience count uses 5 — removing the old command also removes that contradiction from the codebase rather than leaving two commands disagreeing on the same number.

Implementation
New cmd/audience package: an audience parent command (pure router) with count as a subcommand, following the documented Two-Level Command Structure
Filters can be provided three ways: -t/--template-path (file), --filters (raw JSON array, for scripting without a temp file — mirrors the pattern used by audience breakdown in #527), or --filter-set (by ID). Mutually exclusive; exactly one is required
Removes cmd/eligibilitycount/; reuses the existing GetEligibilityCount, EligibilityCountPayload and GetFilterSet client methods as-is — no client/payload/response/model changes
-j is bound by hand rather than through shared.AddOutputFlags, which claims -t for --table and would collide with --template-path; noted in a comment at the flag
Composite and/or groups still can't be expressed via -t or --filters, since model.Filter has no selected_filters — pre-existing and shared with the old eligibility-count, stated explicitly in the command's --help
docs/examples/audience-count.json example template
contract_test/contract_test.go and the README coverage table also gained skip entries for five operations that appeared in the live spec independently of this feature (four aiTaskBuilder_* export-job operations, plus messages_CreateConversation) — unrelated schema drift that was blocking make test, not part of this feature
Known overlap with #527: both PRs create cmd/audience/audience.go and touch the same lines in cmd/root.go (registering count vs breakdown respectively). Whichever merges second needs to reconcile both AddCommand calls into one file.

Testing
cmd/audience/count_test.go covers all three input paths, the payload actually sent over the wire, JSON and human-readable rendering at and above the privacy floor, empty-filters-not-nil, input validation (no input, any two inputs together, missing workspace), config/JSON parse failures, and API errors from both endpoints. make build, go vet ./..., gofmt, and the full test suite (including contract_test) pass locally.

🤖 Generated with Claude Code

@prolific-snyk

prolific-snyk commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Reconcile the privacy threshold before approval; help and README updates are also outstanding.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds prolific audience count for counting eligible participants from filter templates or saved filter sets.

Changes:

  • Adds audience/count commands with human-readable and JSON output.
  • Adds privacy-threshold metadata, tests, and an example template.
  • Registers the new command.

Open items include reconciling the privacy threshold and updating command help and README listings.

File Description
docs/​examples/​audience-count.json Example filter template
cmd/​root.go Registers the audience command
cmd/​audience/​count.go Implements counting, validation, API calls, and rendering
cmd/​audience/​count_test.go Tests command behavior and output
cmd/​audience/​audience.go Defines the audience command group

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/audience/audience.go
Comment on lines +12 to +15
cmd := &cobra.Command{
Use: "audience",
Short: "Understand your audience of eligible participants",
}
@sarahweeks-prolific
sarahweeks-prolific marked this pull request as ready for review September 29, 2026 08:22
@sarahweeks-prolific
sarahweeks-prolific requested a review from a team as a code owner September 29, 2026 08:22
@sarahweeks-prolific
sarahweeks-prolific force-pushed the feat/buzz-231-audience-count branch from 5f8d446 to 40e9f23 Compare September 29, 2026 08:38
@sarahweeks-prolific
sarahweeks-prolific requested a review from a team September 29, 2026 10:40
@sarahweeks-prolific
sarahweeks-prolific force-pushed the feat/buzz-231-audience-count branch from 33b7b23 to 5c90d47 Compare September 30, 2026 10:45
@sarahweeks-prolific
sarahweeks-prolific changed the base branch from main to feat/buzz-231-audience-breakdown-command September 30, 2026 12:50
@sarahweeks-prolific
sarahweeks-prolific merged commit cc88f11 into feat/buzz-231-audience-breakdown-command Sep 30, 2026
6 checks passed
@sarahweeks-prolific
sarahweeks-prolific deleted the feat/buzz-231-audience-count branch September 30, 2026 12:53
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.

3 participants