Merge pull request #1000 from oraios/copilot/fix-news-display-logic

Filter news items by installation date
This commit is contained in:
Dominik Jain authored and GitHub committed 2026-02-13 00:12:13 +01:00
commit 05031e6afb
2 files changed
+30 -4

No files matched your search

+14 -1
View File
@@ -8,7 +8,7 @@ import shutil
from collections.abc import Iterator, Sequence
from copy import deepcopy
from dataclasses import dataclass, field
from datetime import datetime
from datetime import UTC, datetime
from enum import Enum
from functools import cached_property
from pathlib import Path
@@ -511,6 +511,19 @@ class SerenaConfig(ToolInclusionDefinition, ModeSelectionDefinition, ToStringMix
CONFIG_FIELDS_WITH_TYPE_CONVERSION = {"projects", "language_backend"}
# *** methods ***
@classmethod
def get_config_file_creation_date(cls) -> datetime | None:
"""
:return: the creation date of the configuration file, or None if the configuration file does not exist
"""
config_file_path = cls._determine_config_file_path()
if not os.path.exists(config_file_path):
return None
# for unix systems st_ctime is the inode change time (change of metadata),
# which is good enough for our purposes
creation_timestamp = os.stat(config_file_path).st_ctime
return datetime.fromtimestamp(creation_timestamp, UTC)
@property
def config_file_path(self) -> str | None:
+16 -3
View File
@@ -10,7 +10,7 @@ from pydantic import BaseModel
from sensai.util import logging
from serena.analytics import ToolUsageStats
from serena.config.serena_config import LanguageBackend, SerenaPaths
from serena.config.serena_config import LanguageBackend, SerenaConfig, SerenaPaths
from serena.constants import SERENA_DASHBOARD_DIR
from serena.task_executor import TaskExecutor
from serena.util.logging import MemoryLogHandler
@@ -324,12 +324,25 @@ class SerenaDashboardAPI:
def _get_unread_news_ids() -> list[int]:
all_news_files = (Path(SERENA_DASHBOARD_DIR) / "news").glob("*.html")
all_news_ids = [int(f.stem) for f in all_news_files]
"""News ids are ints of format YYYYMMDD (publication dates)"""
# Filter news items by installation date
serena_config_creation_date = SerenaConfig.get_config_file_creation_date()
if serena_config_creation_date is None:
# should not normally happen, since config file should exist when the dashboard is started
# We assume a fresh installation in this case
log.error("Serena config file not found when starting the dashboard")
return []
serena_config_creation_date_int = int(serena_config_creation_date.strftime("%Y%m%d"))
# Only include news items published on or after the installation date
post_installation_news_ids = [news_id for news_id in all_news_ids if news_id >= serena_config_creation_date_int]
news_snippet_id_file = SerenaPaths().news_snippet_id_file
if not os.path.exists(news_snippet_id_file):
return all_news_ids
return post_installation_news_ids
with open(news_snippet_id_file, encoding="utf-8") as f:
last_read_news_id = int(f.read().strip())
return [news_id for news_id in all_news_ids if news_id > last_read_news_id]
return [news_id for news_id in post_installation_news_ids if news_id > last_read_news_id]
try:
unread_news_ids = _get_unread_news_ids()