Skip to content

TrueHOOHA/shanxi-securities-tushare-skill / sxsc-tushare-analysis

sxsc-tushare-analysis

Verified

对用户提到的标的(沪深股票、指数、公募基金、期货)进行综合分析,输出带 ECharts 图表的 HTML 分析报告。 触发条件:用户说"分析""研究""评估""看看XX怎么样""XX基本面""XX技术面""XX估值""XX财务""深度研究""对比"等分析类请求,且标的属于 A 股/指数/公募基金/期货。 本 skill 自动调用 sxsc_tushare 取数并输出完整报告,接管数据获取与分析全流程。当本 skill 被触发时,数据获取类 skill 不应同时激活——分析已包含数据。

scripts/result_model.py

View on GitHub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
统一结果模型:为分析 skill 提供一致的状态、结构和错误处理。

核心设计:
- ResultStatus:五态枚举(success / empty / permission_denied / insufficient_history / error)
- DimensionResult:每个分析维度的标准输出容器
- safe_result:装饰器,把函数异常自动映射为 DimensionResult(error 态,异常类型与消息写入 note)
"""

import functools
import sys
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Callable, Dict, List, Optional


class ResultStatus(str, Enum):
    """维度执行后的五态之一。"""

    SUCCESS = "success"
    EMPTY = "empty"                     # 接口返回空
    PERMISSION_DENIED = "permission_denied"  # 无权限/配额不足
    INSUFFICIENT_HISTORY = "insufficient_history"  # 历史数据不足
    ERROR = "error"                     # 其他错误


@dataclass
class DimensionResult:
    """单个分析维度的标准结果。"""

    status: ResultStatus
    title: str                          # 维度中文名,如"行情趋势"
    conclusion: str = ""                # 一句话结论
    data: Optional[Dict[str, Any]] = None  # 结构化数据
    tables: List[Dict[str, Any]] = field(default_factory=list)  # 可渲染的表格列表
    risks: List[str] = field(default_factory=list)  # 该维度发现的风险信号
    note: str = ""                      # 对空结果/异常的说明
    insights: List[str] = field(default_factory=list)  # 因子化洞察,由各维度因子计算填入

    def is_ok(self) -> bool:
        return self.status == ResultStatus.SUCCESS

    def to_dict(self) -> Dict[str, Any]:
        return {
            "status": self.status.value,
            "title": self.title,
            "conclusion": self.conclusion,
            "data": self.data,
            "tables": self.tables,
            "risks": self.risks,
            "note": self.note,
            "insights": self.insights,
        }

    @classmethod
    def success(
        cls,
        title: str,
        conclusion: str = "",
        data: Optional[Dict[str, Any]] = None,
        tables: Optional[List[Dict[str, Any]]] = None,
        risks: Optional[List[str]] = None,
        note: str = "",
        insights: Optional[List[str]] = None,
    ) -> "DimensionResult":
        return cls(
            status=ResultStatus.SUCCESS,
            title=title,
            conclusion=conclusion,
            data=data or {},
            tables=tables or [],
            risks=risks or [],
            note=note,
            insights=insights or [],
        )

    @classmethod
    def empty(cls, title: str, note: str = "无数据") -> "DimensionResult":
        return cls(status=ResultStatus.EMPTY, title=title, note=note)

    @classmethod
    def permission_denied(cls, title: str, note: str = "权限不足") -> "DimensionResult":
        return cls(status=ResultStatus.PERMISSION_DENIED, title=title, note=note)

    @classmethod
    def insufficient_history(cls, title: str, note: str = "历史数据不足") -> "DimensionResult":
        return cls(status=ResultStatus.INSUFFICIENT_HISTORY, title=title, note=note)

    @classmethod
    def error(cls, title: str, note: str = "") -> "DimensionResult":
        return cls(status=ResultStatus.ERROR, title=title, note=note)


def safe_result(title: str):
    """装饰器:捕获异常并转为 DimensionResult.error。

    异常信息不留白:类型与消息写入 DimensionResult.note(报告的风险提示/备注节会呈现),
    同时打到 stderr,避免真实 bug 被当成"维度不可用"静默吞掉。

    用法:
        @safe_result("行情趋势")
        def analyze_trend(...) -> DimensionResult:
            ...
    """
    def decorator(fn: Callable[..., DimensionResult]) -> Callable[..., DimensionResult]:
        @functools.wraps(fn)  # 保留 __name__/__doc__,否则被装饰方法全变成 "wrapper"
        def wrapper(*args, **kwargs) -> DimensionResult:
            try:
                return fn(*args, **kwargs)
            except Exception as e:
                note = f"{type(e).__name__}: {e}"
                print(f"[result_model] 维度「{title}」执行异常({getattr(fn, '__name__', '?')}): {note}",
                      file=sys.stderr)
                return DimensionResult.error(title, note=note)
        return wrapper
    return decorator
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall