From a17782173b294a0402b8465cd12f746227bbfeb2 Mon Sep 17 00:00:00 2001 From: Pauline Vos Date: Mon, 2 Nov 2026 19:36:28 +0000 Subject: [PATCH 1/2] feat: show hot topics and headline discussions --- KNOWLEDGE_BASE.md | 4 +- app/Http/Controllers/HeadlineController.php | 21 ++++ app/Http/Middleware/HandleInertiaRequests.php | 8 ++ app/Queries/CommitSearchQuery.php | 12 ++- app/Queries/HeadlinePageQuery.php | 43 ++++++++ app/Queries/HotHeadlinesQuery.php | 7 +- resources/js/components/app-aside.tsx | 101 +----------------- .../js/components/commit-search-results.tsx | 80 ++++++++++++++ resources/js/components/hot-topics.tsx | 38 +++++++ resources/js/pages/headline/show.tsx | 46 ++++++++ resources/js/pages/search/index.tsx | 82 +------------- resources/js/types/global.d.ts | 1 + routes/web.php | 6 ++ .../Controllers/HeadlineControllerTest.php | 68 ++++++++++++ tests/Unit/HotTopics.test.tsx | 49 +++++++++ .../Middleware/HandleInertiaRequestsTest.php | 43 +++++++- tests/Unit/Queries/CommitSearchQueryTest.php | 9 ++ tests/Unit/Queries/HotHeadlinesQueryTest.php | 14 +-- tests/Unit/StandaloneCommitGraphs.test.tsx | 2 +- 19 files changed, 438 insertions(+), 196 deletions(-) create mode 100644 app/Http/Controllers/HeadlineController.php create mode 100644 app/Queries/HeadlinePageQuery.php create mode 100644 resources/js/components/commit-search-results.tsx create mode 100644 resources/js/components/hot-topics.tsx create mode 100644 resources/js/pages/headline/show.tsx create mode 100644 tests/Feature/Controllers/HeadlineControllerTest.php create mode 100644 tests/Unit/HotTopics.test.tsx diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index bca91878c0..a59f47583f 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -206,7 +206,9 @@ Commits, replies, quotes, scheduling, terminal submissions, and app (signed API) Approved top-level commits about technology, current affairs or substantive real-world events can receive brief, shared subject headlines. Technical and developer topics carry the most weight. /dev/null community activity also qualifies, including livestreams, Tom, app betas and feature updates. Quote commits include the directly quoted post's text when it is approved and still available, so a brief reaction can share the subject of the post it quotes. Replies, casual small talk and evergreen lifestyle or hobby advice are skipped. OpenAI's Decisions API assesses this text for suitability and checks the closest existing headline names, shortlisted by semantic similarity; when none match, DeepSeek through OpenCode generates a headline from the same text. Posts can be processed together, and similar newly generated headlines share the first headline rather than creating duplicates. No account metadata is sent. A headline expires after fourteen days without a new commit link. This categorization does not change the original post and does not yet add visible headline labels to the interface. -Hot topics can also receive a short AI-written recap based on approved, available top-level commits from the past eight hours. An AI usefulness check skips topics without enough substance to summarize. Recaps aim to explain the underlying situation or event in one or two short sentences, rather than cataloguing individual posts. They are not independently verified reporting and can be reused for up to two hours. Only post text and the headline are sent to the AI providers, without account metadata. Removing a source commit, rejecting it, or deleting its author's account clears the associated recap. This runs in the background; hot-topic recaps are not yet displayed in the interface. +The desktop sidebar shows signed-in members up to five **Hot topics** above **Who to follow**. These aggregate approved top-level commits posted in the past eight hours, with extra weight for trending discussions. Only each author's strongest post contributes to a topic's ranking, so repeated posts from one profile do not lift it. The list respects mutes and blocks. The sidebar no longer repeats your own profile summary; your profile is still available from the main navigation. + +Hot topics can also receive a short AI-written recap based on approved, available top-level commits from the past eight hours. An AI usefulness check skips topics without enough substance to summarize. Recaps aim to explain the underlying situation or event in one or two short sentences, rather than cataloguing individual posts. They are not independently verified reporting and can be reused for up to two hours. Only post text and the headline are sent to the AI providers, without account metadata. Removing a source commit, rejecting it, or deleting its author's account clears the associated recap. Signed-in members can open a headline to read its available recap above semantic search results from the past week. Expired recaps are omitted, and a recap is hidden if linked public posts include an author the viewer has muted or blocked. The results respect visibility, mutes and blocks too. Sources: [composer](resources/js/components/commit-composer.tsx), [commit model](app/Models/Commit.php), [commit validation](app/Http/Requests/CreateCommitRequest.php), [text normalization](app/Services/CommitBodies.php), [submission throttle](app/Http/Middleware/ThrottleCommits.php). diff --git a/app/Http/Controllers/HeadlineController.php b/app/Http/Controllers/HeadlineController.php new file mode 100644 index 0000000000..441f090d2d --- /dev/null +++ b/app/Http/Controllers/HeadlineController.php @@ -0,0 +1,21 @@ +get($headline, $user)) + ->withViewData(['robots' => 'noindex, follow']); + } +} diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 967a22efcc..d6ebdad631 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -15,6 +15,7 @@ use App\Queries\BioProfilesQuery; use App\Queries\ConversationsQuery; use App\Queries\DevelopersCountQuery; +use App\Queries\HotHeadlinesQuery; use App\Queries\LiveFollowingQuery; use App\Queries\NotificationGroupsQuery; use App\Queries\SuggestedUsersQuery; @@ -127,6 +128,13 @@ public function share(Request $request): array 'showsWhoToFollow' => $showsWhoToFollow, ...$user instanceof User && $hasAside ? [ 'liveFollowing' => Inertia::once(fn (): Collection => resolve(LiveFollowingQuery::class)->get($user))->until(60), + 'hotTopics' => Inertia::once(fn (): array => array_map( + fn (array $headline): array => [ + 'id' => $headline['id'], + 'name' => $headline['name'], + ], + resolve(HotHeadlinesQuery::class)->get($user), + ))->until(60), ] : [], 'dimsLanes' => $request->cookie('lane_dimming') !== 'false', 'repliesPerPage' => RepliesPerPage::of($request)->value, diff --git a/app/Queries/CommitSearchQuery.php b/app/Queries/CommitSearchQuery.php index 9591747a1d..32624af4b9 100644 --- a/app/Queries/CommitSearchQuery.php +++ b/app/Queries/CommitSearchQuery.php @@ -8,6 +8,7 @@ use App\Contracts\Services\RelevanceProvider; use App\Models\Commit; use App\Models\User; +use Carbon\CarbonInterface; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -39,7 +40,7 @@ public function __construct(private EmbeddingProvider $embeddings, private Relev * * @return Collection */ - public function get(string|Commit $term, ?User $viewer, int $limit = 20): Collection + public function get(string|Commit $term, ?User $viewer, int $limit = 20, ?CarbonInterface $since = null): Collection { $source = $term instanceof Commit ? Commit::query()->whereKey($term->id)->first(['id', 'body', 'embedding', 'parent_id', 'root_id']) @@ -58,13 +59,13 @@ public function get(string|Commit $term, ?User $viewer, int $limit = 20): Collec /** @var list $vector */ $vector = $source->embedding ?? Cache::remember('search-embedding:'.hash('sha256', $term), self::CACHE_SECONDS, fn (): array => $this->embeddings->embed($term)); - $candidates = DB::transaction(function () use ($source, $vector, $viewer, $limit): Collection { - if ($source instanceof Commit) { + $candidates = DB::transaction(function () use ($source, $vector, $viewer, $limit, $since): Collection { + if ($source instanceof Commit || $since instanceof CarbonInterface) { DB::statement('set local hnsw.iterative_scan = strict_order'); } return Commit::query() - ->whereIn('commits.id', $this->nearest($vector, $viewer, $limit * 2, $source)) + ->whereIn('commits.id', $this->nearest($vector, $viewer, $limit * 2, $source, $since)) ->visibleTo($viewer) ->withoutMutedAuthorsFor($viewer) ->withVisibleReplyCount($viewer) @@ -87,10 +88,11 @@ public function get(string|Commit $term, ?User $viewer, int $limit = 20): Collec * * @param list $vector */ - private function nearest(array $vector, ?User $viewer, int $count, ?Commit $source): CommitBuilder + private function nearest(array $vector, ?User $viewer, int $count, ?Commit $source, ?CarbonInterface $since): CommitBuilder { return Commit::query() ->select('id') + ->when($since, fn (CommitBuilder $query, CarbonInterface $since): CommitBuilder => $query->where('created_at', '>=', $since)) ->when($source, fn (CommitBuilder $query, Commit $source): CommitBuilder => $query ->topLevel() ->whereKeyNot($source->threadRootId()) diff --git a/app/Queries/HeadlinePageQuery.php b/app/Queries/HeadlinePageQuery.php new file mode 100644 index 0000000000..2a6ddb8f7e --- /dev/null +++ b/app/Queries/HeadlinePageQuery.php @@ -0,0 +1,43 @@ +} + */ + public function get(Headline $headline, User $viewer): array + { + $summary = null; + + if ($headline->summary !== null && $headline->summary_created_at?->gt(now()->subHours(Headline::SUMMARY_HOURS))) { + // Without stored provenance, check all linked posts rather than risk repeating a hidden author's words. + $hasHiddenSources = $headline->commits()->topLevel()->approved() + ->whereNotIn('commits.id', $headline->commits()->select('commits.id')->visibleTo($viewer)->withoutMutedAuthorsFor($viewer)) + ->exists(); + + if (! $hasHiddenSources) { + $summary = $headline->summary; + } + } + + return [ + 'name' => $headline->name, + 'summary' => $summary, + 'commits' => $this->search->get($headline->name, $viewer, since: now()->subWeek()), + ]; + } +} diff --git a/app/Queries/HotHeadlinesQuery.php b/app/Queries/HotHeadlinesQuery.php index eb26fd16df..604e23d649 100644 --- a/app/Queries/HotHeadlinesQuery.php +++ b/app/Queries/HotHeadlinesQuery.php @@ -25,7 +25,7 @@ public function __construct(private TheAlgorithm $theAlgorithm) * Ties use author breadth and name, never post count or recency, so repeated weaker posts cannot lift a headline. * Rankings are deterministic, without the Trending log's random draw or network adjustments. * - * @return list + * @return list */ public function get(?User $viewer = null): array { @@ -44,11 +44,11 @@ public function get(?User $viewer = null): array ->selectRaw('max(commits.hot_score) as hot_score, count(*) as commits_count') ->groupBy('commit_headline.headline_id', 'commits.author_id'); - /** @var list $rows */ + /** @var list $rows */ $rows = DB::query() ->fromSub($contributions, 'contributions') ->join('headlines', 'headlines.id', '=', 'contributions.headline_id') - ->select('headlines.name') + ->select('headlines.id', 'headlines.name') ->selectRaw('sum(contributions.commits_count)::bigint as commits_count, count(*) as authors_count, sum(1 + greatest(0::float8, contributions.hot_score - ?::float8)) as score', [$baseline]) ->groupBy('headlines.id', 'headlines.name') ->orderByDesc('score') @@ -58,6 +58,7 @@ public function get(?User $viewer = null): array ->get()->all(); return array_map(fn (object $row): array => [ + 'id' => $row->id, 'name' => $row->name, 'commits_count' => $row->commits_count, 'score' => $row->score, diff --git a/resources/js/components/app-aside.tsx b/resources/js/components/app-aside.tsx index 7c9fb48168..c426fbb170 100644 --- a/resources/js/components/app-aside.tsx +++ b/resources/js/components/app-aside.tsx @@ -6,22 +6,15 @@ import ChangelogController from '@/actions/App/Http/Controllers/ChangelogControl import PartnerController from '@/actions/App/Http/Controllers/PartnerController'; import PrivacyController from '@/actions/App/Http/Controllers/PrivacyController'; import TermsController from '@/actions/App/Http/Controllers/TermsController'; -import UserFollowersController from '@/actions/App/Http/Controllers/UserFollowersController'; -import UserFollowingController from '@/actions/App/Http/Controllers/UserFollowingController'; -import { BioText } from '@/components/bio-text'; import { GitHubIcon } from '@/components/github-icon'; +import { HotTopics } from '@/components/hot-topics'; import { LiveFollowing } from '@/components/live-following'; import { Button } from '@/components/ui/button'; -import { UserAvatar } from '@/components/user-avatar'; import { WhoToFollow } from '@/components/who-to-follow'; import { WordmarkText } from '@/components/wordmark-text'; -import { useSharedState } from '@/hooks/use-shared-state'; -import { commitStateKey } from '@/lib/commit-state'; import { useKeyLabels } from '@/lib/keyboard'; -import { exactCountTitle, formatCount, formatExactCount } from '@/lib/numbers'; -import { laneColor } from '@/lib/utils'; +import { formatExactCount } from '@/lib/numbers'; import { login } from '@/routes'; -import { show } from '@/routes/user'; export function AppAside({ onShowShortcuts, @@ -30,13 +23,9 @@ export function AppAside({ onShowShortcuts: () => void; onSearch: () => void; }) { - const { user, bioProfiles } = usePage().props.auth; + const { user } = usePage().props.auth; const { developersCount } = usePage().props; const keys = useKeyLabels(); - const [commitsCount] = useSharedState( - commitStateKey('commits_count', user?.id ?? ''), - user?.commits_count ?? 0, - ); return (