Skip to content

[#33] Add writer type filter and agent badge#124

Merged
realproject7 merged 2 commits intomainfrom
task/33-writer-type-filter-badge
Mar 15, 2026
Merged

[#33] Add writer type filter and agent badge#124
realproject7 merged 2 commits intomainfrom
task/33-writer-type-filter-badge

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • Add writer filter (All / Human only / Agent only) to the discover page, wired to ?writer=all|human|agent query param
  • Extract inline agent badge markup into a reusable AgentBadge component
  • Filter Supabase queries by writer_type (0 = human, 1 = agent) on new/completed tabs; post-filter trending/rising results
  • TabNav now preserves extra query params (writer filter persists across tab switches)

Fixes #33

Test plan

  • Visit /discover — writer filter shows below tabs with "All" active by default
  • Click "Human only" — URL updates to ?tab=new&writer=human, only writer_type=0 stories shown
  • Click "Agent only" — URL updates to ?tab=new&writer=agent, only writer_type=1 stories shown
  • Switch tabs while a writer filter is active — filter persists in URL
  • Verify agent badge renders on StoryCard and story detail page for agent-written stories
  • Verify no badge appears for human-written stories

🤖 Generated with Claude Code

Fixes #33

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

Verdict: REQUEST CHANGES

Summary

The new/filter-completed paths are correct, and CI passed, but the trending/rising writer filter is implemented after ranking the global candidate set rather than in the underlying Supabase candidate query. That means writer=agent or writer=human can miss valid results and return an under-filled or incorrect top list.

Findings

  • [medium] Trending/rising writer filtering happens too late, so filtered rankings are not actually correct
    • File: src/app/discover/page.tsx:113
    • Suggestion: Thread the writer filter into the ranking candidate fetch in lib/ranking.ts so the Supabase storyline query itself is constrained by writer_type before scoring/sorting. Filtering after getTrendingStorylines(..., 50) / getRisingStorylines(..., 50) only considers the global top 50 candidates, not the top writer-filtered set.

Decision

Request changes because issue #33 explicitly calls for filtering by writer_type, and the current trending/rising implementation can drop valid stories for the selected writer type.

Move writer_type filtering from post-filter (after ranking) into the
Supabase candidate query so trending/rising tabs rank the full pool
of matching stories instead of filtering a pre-ranked global top-50.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

T2b Review: REQUEST CHANGES

Agree with T2a — the post-filter on trending/rising is the blocking issue.

Blocking:
The filterByWriter(all, writer).slice(0, 20) pattern fetches 50 pre-ranked results then filters. If only 3 of 50 match the writer type, users see 3 results instead of 20, and valid stories ranked 51+ are invisible. Thread writerType into fetchCandidatesAndRatings in lib/ranking.ts so .eq("writer_type", ...) is applied before .limit(50).

Non-blocking:

  • filterByWriter JSDoc says "client-side" but it runs in a Server Component — minor but misleading.

Everything else looks good:

  • AgentBadge: clean, properly typed, reusable
  • Query param handling: whitelist-validated, no injection risk
  • WriterFilter + TabNav integration: correct URL construction, filter persists across tab switches
  • Import paths all correct

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

Verdict: APPROVE

Summary

The follow-up fix resolves the correctness issue in the writer filter implementation by applying writer_type in the ranking candidate query before scoring and sorting. The discover-page filter, badge extraction, and query-param persistence now align with issue #33, and CI passed.

Findings

  • None.

Decision

Approve because the implementation now satisfies the acceptance criteria end-to-end, stays focused, and the lint-and-typecheck check passed.

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

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

T2b Re-review: APPROVE

Fix is correct — writerType now threaded into fetchCandidatesAndRatings with .eq("writer_type", ...) applied before .limit(50). Post-filter removed entirely. Same pattern applied to new/completed tabs in queryTab. All 4 tabs now filter at the DB level. Ship it.

@realproject7 realproject7 merged commit 196f112 into main Mar 15, 2026
1 check 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.

[P6-2] Writer Type Filter & Agent Badge

2 participants