返回 last30days-skill
registers.py
根目录 / skills / last30days / scripts / lib / registers.py
1 """Named audience registers for standard research brief synthesis."""
2
3 from __future__ import annotations
4
5 from dataclasses import dataclass
6 from types import MappingProxyType
7 from typing import Mapping
8
9
10 SectionName = str
11
12
13 @dataclass(frozen=True)
14 class AudienceRegister:
15 """A bounded renderer/synthesis preset for one intended audience."""
16
17 name: str
18 section_order: tuple[SectionName, ...]
19 item_budgets: Mapping[SectionName, int]
20 emphasis_weights: Mapping[str, float]
21
22 def budget_for(self, section: SectionName, fallback: int) -> int:
23 return self.item_budgets.get(section, fallback)
24
25 def emphasis_for(self, source: str) -> float:
26 return self.emphasis_weights.get(source, 1.0)
27
28
29 _DEFAULT_ORDER = (
30 "hiring_signals",
31 "clusters",
32 "stats",
33 "best_takes",
34 "top_comments",
35 "source_outcomes",
36 "source_coverage",
37 )
38
39
40 def _preset(
41 name: str,
42 *,
43 section_order: tuple[SectionName, ...] = _DEFAULT_ORDER,
44 item_budgets: Mapping[SectionName, int] | None = None,
45 emphasis_weights: Mapping[str, float] | None = None,
46 ) -> AudienceRegister:
47 return AudienceRegister(
48 name=name,
49 section_order=section_order,
50 item_budgets=MappingProxyType(dict(item_budgets or {})),
51 emphasis_weights=MappingProxyType(dict(emphasis_weights or {})),
52 )
53
54
55 _REGISTERS = {
56 "default": _preset("default"),
57 "exec": _preset(
58 "exec",
59 section_order=(
60 "stats",
61 "clusters",
62 "hiring_signals",
63 "source_outcomes",
64 "source_coverage",
65 "best_takes",
66 "top_comments",
67 ),
68 item_budgets={"clusters": 5, "best_takes": 2, "top_comments": 3},
69 emphasis_weights={
70 "polymarket": 1.50,
71 "jobs": 1.30,
72 "github": 1.20,
73 "grounding": 1.10,
74 },
75 ),
76 "dev": _preset(
77 "dev",
78 section_order=(
79 "clusters",
80 "source_outcomes",
81 "source_coverage",
82 "hiring_signals",
83 "stats",
84 "top_comments",
85 "best_takes",
86 ),
87 item_budgets={"clusters": 10, "best_takes": 3, "top_comments": 4},
88 emphasis_weights={
89 "github": 1.60,
90 "hackernews": 1.35,
91 "arxiv": 1.30,
92 "devto": 1.25,
93 "v2ex": 1.15,
94 "juejin": 1.15,
95 "grounding": 1.10,
96 },
97 ),
98 "creator": _preset(
99 "creator",
100 section_order=(
101 "best_takes",
102 "top_comments",
103 "stats",
104 "clusters",
105 "hiring_signals",
106 "source_outcomes",
107 "source_coverage",
108 ),
109 item_budgets={"clusters": 6, "best_takes": 5, "top_comments": 40},
110 emphasis_weights={
111 "tiktok": 1.60,
112 "instagram": 1.50,
113 "youtube": 1.40,
114 "x": 1.20,
115 "reddit": 1.10,
116 },
117 ),
118 # ELI5 historically changed only the agent's prose. Keep the renderer
119 # descriptor identical to default and express its voice in SKILL.md.
120 "eli5": _preset("eli5"),
121 }
122
123 REGISTER_NAMES = tuple(_REGISTERS)
124
125
126 def get_register(name: str | None = None) -> AudienceRegister:
127 """Return a named register, rejecting unsupported/free-form templates."""
128
129 normalized = (name or "default").strip().lower()
130 try:
131 return _REGISTERS[normalized]
132 except KeyError as exc:
133 choices = ", ".join(REGISTER_NAMES)
134 raise ValueError(
135 f"unknown audience register {name!r}; choose one of: {choices}"
136 ) from exc
137
137 lines PYTHON