Skip to content

RKiding/Awesome-finance-skills / skills/alphaear-reporter

alphaear-reporter

Verified

Plan, write, and edit professional financial reports; generate finance chart configurations. Use when condensing finance analysis into a structured output.

FileKindSize
SKILL.mdskill md1.1 KB
references/PROMPTS.mdmarkdown2.2 KB
scripts/__init__.pyscript0 B
scripts/prompts/fin_agent.pyscript6.6 KB
scripts/prompts/forecast_analyst.pyscript1.9 KB
scripts/prompts/intent_agent.pyscript2.2 KB
scripts/prompts/isq_prompt_generator.pyscript1.8 KB
scripts/prompts/report_agent.pyscript18.1 KB
scripts/prompts/trend_agent.pyscript7.4 KB
scripts/prompts/visualizer.pyscript2.0 KB
scripts/report_agent.pyscript6.7 KB
scripts/schema/isq_template.pyscript13.6 KB
scripts/schema/models.pyscript6.1 KB
scripts/tools/__init__.pyscript448 B
scripts/tools/toolkits.pyscript18.7 KB
scripts/utils/__init__.pyscript25 B
scripts/utils/content_extractor.pyscript4.7 KB
scripts/utils/database_manager.pyscript21.3 KB
scripts/utils/hybrid_search.pyscript8.0 KB
scripts/utils/json_utils.pyscript6.2 KB
scripts/utils/llm/capability.pyscript2.8 KB
scripts/utils/llm/factory.pyscript3.6 KB
scripts/utils/llm/router.pyscript2.8 KB
scripts/utils/logging_setup.pyscript1.0 KB
scripts/utils/news_tools.pyscript9.9 KB
scripts/utils/predictor/evaluation.pyscript5.6 KB
scripts/utils/predictor/kline_generate.pyscript7.6 KB
scripts/utils/predictor/model/__init__.pyscript394 B
scripts/utils/predictor/model/kronos.pyscript30.4 KB
scripts/utils/predictor/model/module.pyscript22.3 KB
scripts/utils/predictor/training.pyscript18.3 KB
scripts/utils/search_tools.pyscript28.6 KB
scripts/utils/sentiment_tools.pyscript9.9 KB
scripts/utils/stock_tools.pyscript9.8 KB
scripts/visualizer.pyscript18.6 KB
tests/test_reporter.pyscript830 B

scripts/report_agent.py

View on GitHub
import hashlib
import json
import re
import pandas as pd
from typing import List, Dict, Any, Optional
from loguru import logger
from types import SimpleNamespace

from .utils.database_manager import DatabaseManager
from .utils.json_utils import extract_json

class ReportUtils:
    """
    研报辅助工具集 (ReportUtils)
    提供格式化、引用管理、 JSON 提取等辅助功能。
    核心生成逻辑(聚类、写作)已移交 Agent 执行。
    """
    
    def __init__(self, db: DatabaseManager):
        self.db = db
        logger.info("📝 ReportUtils initialized")

    @staticmethod
    def _make_cite_key(url: str, title: str = "", source_name: str = "") -> str:
        basis = (url or "").strip() or f"{(title or '').strip()}|{(source_name or '').strip()}"
        digest = hashlib.sha1(basis.encode("utf-8")).hexdigest()[:8]
        return f"SF-{digest}"

    def build_bibliography(self, signals: List[Any]) -> tuple[list[Dict[str, Any]], Dict[int, list[str]]]:
        """Build stable bibliography entries and per-signal cite key mapping."""
        bib_by_key: Dict[str, Dict[str, Any]] = {}
        signal_to_keys: Dict[int, list[str]] = {}

        for sig_idx, signal in enumerate(signals, 1):
            source_items: list[Dict[str, Any]] = []

            if hasattr(signal, "sources") and getattr(signal, "sources"):
                source_items = list(getattr(signal, "sources") or [])
            elif isinstance(signal, dict) and signal.get("sources"):
                src_list = signal.get("sources")
                if isinstance(src_list, list) and src_list:
                    source_items = list(src_list)
            elif isinstance(signal, dict):
                if signal.get("url") or signal.get("title"):
                    source_items = [
                        {
                            "title": signal.get("title"),
                            "url": signal.get("url"),
                            "source_name": signal.get("source") or signal.get("source_name"),
                            "publish_time": signal.get("publish_time"),
                        }
                    ]

            if not source_items:
                continue

            for src in source_items:
                url = (src.get("url") or "").strip()
                title = (src.get("title") or "").strip()
                source_name = (src.get("source_name") or src.get("source") or "").strip()
                publish_time = (src.get("publish_time") or "").strip() if isinstance(src.get("publish_time"), str) else src.get("publish_time")

                key = self._make_cite_key(url=url, title=title, source_name=source_name)
                signal_to_keys.setdefault(sig_idx, [])
                if key not in signal_to_keys[sig_idx]:
                    signal_to_keys[sig_idx].append(key)

                if key in bib_by_key:
                    continue

                # Prefer canonical metadata from DB when possible
                enriched = self.db.lookup_reference_by_url(url) if url else None
                bib_by_key[key] = {
                    "key": key,
                    "url": url or (enriched.get("url") if enriched else ""),
                    "title": (enriched.get("title") if enriched else None) or title or "(无标题)",
                    "source": (enriched.get("source") if enriched else None) or source_name or "(未知来源)",
                    "publish_time": (enriched.get("publish_time") if enriched else None) or publish_time or "",
                }

        return list(bib_by_key.values()), signal_to_keys

    @staticmethod
    def render_references_section(bib_entries: list[Dict[str, Any]]) -> str:
        lines = ["## 参考文献", ""]
        if not bib_entries:
            lines.append("(无)")
            return "\n".join(lines).strip() + "\n"

        for i, entry in enumerate(bib_entries, 1):
            key = entry.get("key")
            title = entry.get("title") or "(无标题)"
            source = entry.get("source") or "(未知来源)"
            url = entry.get("url") or ""
            publish_time = entry.get("publish_time") or ""
            suffix = ""
            if publish_time:
                suffix = f",{publish_time}"
            label = f"[{i}]"
            if url:
                lines.append(f"<a id=\"ref-{key}\"></a>{label} {title} ({source}{suffix}), {url}")
            else:
                lines.append(f"<a id=\"ref-{key}\"></a>{label} {title} ({source}{suffix})")

        return "\n".join(lines).strip() + "\n"

    @staticmethod
    def sanitize_json_chart_blocks(text: str) -> str:
        """Best-effort repair for malformed json-chart fenced blocks."""
        if not text:
            return text
        # (Simplified logic: if closing ``` is missing, append it)
        # Full logic omitted for brevity as it was complex regex, but retaining simple closure fix
        if "```json-chart" in text and text.count("```") % 2 != 0:
            text += "\n```"
        return text

    @staticmethod
    def build_structured_report(report_md: str, signals: List[Dict[str, Any]], clusters: List[Dict[str, Any]]) -> Dict[str, Any]:
        """构建结构化研报输出(便于前端渲染/JSON化)"""
        text = (report_md or "").strip()
        lines = text.splitlines() if text else []

        title = "研报"
        for line in lines:
            if line.startswith("# "):
                title = line.replace("# ", "").strip()
                break

        sections: List[Dict[str, Any]] = []
        current: Dict[str, Any] | None = None
        for line in lines:
            heading = re.match(r"^(#{2,4})\s+(.*)$", line.strip())
            if heading:
                if current:
                    sections.append(current)
                current = {"title": heading.group(2).strip(), "content": []}
                continue
            if current is None:
                current = {"title": "摘要", "content": []}
            current["content"].append(line)
        if current:
            sections.append(current)

        bullets = [
            re.sub(r"^[-*•]\s+", "", l.strip())
            for l in lines
            if l.strip().startswith(("- ", "* ", "• "))
        ]
        bullets = [b for b in bullets if b]

        return {
            "title": title,
            "summary_bullets": bullets[:8],
            "sections": [
                {"title": s["title"], "content": "\n".join(s["content"]).strip()}
                for s in sections
            ]
        }

    @staticmethod
    def _clean_ticker(ticker_raw: str) -> str:
        t = (ticker_raw or "").strip()
        if not t:
            return ""
        digits = "".join([c for c in t if c.isdigit()])
        return digits or t
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall