Files
Jyotisha/scripts/startrack_monthly_log.py
T
ClaudeandClaude Opus 5.5 6a57faacdb feat(consult): run the astrologer's upstream skill in full (BUG-1696, BUG-1697, BUG-1698)
- root SKILL.md is her upstream file (body byte-identical to the 5fb8379c mirror; description quoted so YAML parses and Mastra can load the skill)
- chat binds the whole SKILL.md plus references/product_runtime_contract.md (safety-only) instead of a ~477-character excerpt
- every turn carries her full strict-workflow-router (synced to upstream) and the domain's event-judgment file; product lists follow as an extra layer
- import her 10 sub-skills, family router, interpretation status contract, technique ontology and the 54 files her method names
- tests/test_upstream_skill_parity.py (in the quick gate) fails whenever her skill and ours drift
- 18 frontend guards that locked the excerpt design updated with 原值/新值/原因 notes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 14:02:26 +08:00

196 lines
8.3 KiB
Python

#!/usr/bin/env python3
"""Helpers for the Startrack monthly log contract."""
from __future__ import annotations
from copy import deepcopy
from typing import Any
STARTRACK_PRESETS = {
"a4": {"width_mm": 210, "height_mm": 297, "reflow_mode": "portrait_relayout"},
"a5": {"width_mm": 148, "height_mm": 210, "reflow_mode": "portrait_relayout"},
"a6": {"width_mm": 105, "height_mm": 148, "reflow_mode": "portrait_relayout"},
"a7": {"width_mm": 74, "height_mm": 105, "reflow_mode": "portrait_relayout"},
"a6_personal": {"width_mm": 95, "height_mm": 171, "reflow_mode": "portrait_relayout"},
"tn_regular": {"width_mm": 110, "height_mm": 210, "reflow_mode": "portrait_relayout"},
"tn_passport": {"width_mm": 89, "height_mm": 124, "reflow_mode": "portrait_relayout"},
}
STARTRACK_DESIGN_TOKENS = {
"safe_area_mm": {"top": 8, "right": 8, "bottom": 10, "left": 8},
"bleed_mm": {"top": 3, "right": 3, "bottom": 3, "left": 3},
"blank_area_min_height_mm": 88,
"blank_area_style": "lined",
"font_family": ["Noto Sans SC", "PingFang SC", "Segoe UI", "sans-serif"],
"page_personality": "standard_planner",
"header_band_mm": 14,
"entry_gap_mm": 8,
"corner_radius_mm": 3,
"editable_layers": [
"page_frame",
"header",
"meta",
"content_blocks",
"tags",
"meaning_notes",
"blank_areas",
"guides",
],
}
STARTRACK_FALLBACK_COPY = {
"theme_summary": "本月适合把重点放在可被验证的星象节奏与现实反馈上。",
"interpretation": "这一天更适合记录事件发生的节奏、主观感受与外部反馈。",
"meaning_note": "建议回看触发点、回应方式,以及这组星象如何影响你的判断与行动。",
"keyword_tags": ["timing", "observation"],
}
STARTRACK_THEME_TEMPLATES = {
"career": {
"interpretation": "这一天适合记录职业推进、任务执行与现实责任带来的变化。",
"meaning_note": "建议观察工作节奏、职业判断,以及外部要求如何影响你的执行方式。",
"keyword_tags": ["career", "execution"],
},
"relationship": {
"interpretation": "这一天更容易感受到关系互动、回应方式与边界变化。",
"meaning_note": "建议观察互动边界、情绪回应,以及关系中的现实反馈如何出现。",
"keyword_tags": ["relationship", "boundary"],
},
"finance": {
"interpretation": "这一天适合记录财务流动、资源配置与回报感的变化。",
"meaning_note": "建议回看资源分配、支出判断,以及财务主题如何影响你的安全感。",
"keyword_tags": ["finance", "resources"],
},
"review": {
"interpretation": "这一天更适合整理线索、回看过程,并复盘本轮星象如何兑现。",
"meaning_note": "建议做阶段复盘,回看哪些判断成立、哪些地方需要重新整合。",
"keyword_tags": ["review", "integration"],
},
}
def _design_tokens_for_preset(preset_key: str) -> dict[str, Any]:
base = deepcopy(STARTRACK_DESIGN_TOKENS)
if preset_key in {"a7", "tn_passport"}:
base["layout_density"] = "compact"
base["blank_area_min_height_mm"] = 52
base["safe_area_mm"] = {"top": 5, "right": 5, "bottom": 6, "left": 5}
base["page_personality"] = "traveler_notebook" if preset_key == "tn_passport" else "compact_planner"
base["header_band_mm"] = 16
base["entry_gap_mm"] = 7
base["corner_radius_mm"] = 4
elif preset_key in {"a4", "tn_regular"}:
base["layout_density"] = "spacious"
base["blank_area_min_height_mm"] = 112
base["safe_area_mm"] = {"top": 10, "right": 10, "bottom": 12, "left": 10}
base["page_personality"] = "traveler_notebook" if preset_key == "tn_regular" else "wide_planner"
base["header_band_mm"] = 20
base["entry_gap_mm"] = 12
base["corner_radius_mm"] = 6
elif preset_key == "a6_personal":
base["layout_density"] = "balanced"
base["page_personality"] = "personal_planner"
base["header_band_mm"] = 18
base["entry_gap_mm"] = 10
base["corner_radius_mm"] = 5
base["safe_area_mm"] = {"top": 7, "right": 7, "bottom": 9, "left": 7}
else:
base["layout_density"] = "balanced"
return base
def _resolve_theme_template(entry: dict[str, Any]) -> dict[str, Any]:
for theme in entry.get("themes") or []:
template = STARTRACK_THEME_TEMPLATES.get(str(theme))
if template:
return template
return STARTRACK_FALLBACK_COPY
def _copy_recommendation_fields(source: dict[str, Any]) -> dict[str, Any]:
"""Keep technique-derived advice optional and evidence-linked."""
recommendations = source.get("recommendations")
if not isinstance(recommendations, list):
recommendations = source.get("action_items")
if not isinstance(recommendations, list):
recommendations = []
evidence_refs = source.get("recommendation_evidence_refs")
if not isinstance(evidence_refs, list):
evidence_refs = source.get("evidence_refs") if isinstance(source.get("evidence_refs"), list) else []
return {
"recommendations": deepcopy(recommendations),
"recommendation_evidence_refs": deepcopy(evidence_refs),
}
def build_startrack_monthly_log_contract(
*,
monthly_summary: dict[str, Any],
daily_entries: list[dict[str, Any]],
month_end: dict[str, Any],
profile_source: str,
target_month: str,
calculation_snapshot: dict[str, Any],
preset_key: str = "a5",
) -> dict[str, Any]:
preset = deepcopy(STARTRACK_PRESETS.get(preset_key, STARTRACK_PRESETS["a5"]))
design_tokens = _design_tokens_for_preset(preset_key)
normalized_summary = deepcopy(monthly_summary)
normalized_summary["theme_summary"] = normalized_summary.get("theme_summary") or STARTRACK_FALLBACK_COPY["theme_summary"]
normalized_summary["theme_tags"] = list(normalized_summary.get("theme_tags") or STARTRACK_FALLBACK_COPY["keyword_tags"])
normalized_summary.update(_copy_recommendation_fields(normalized_summary))
normalized_month_end = deepcopy(month_end)
normalized_month_end.update(_copy_recommendation_fields(normalized_month_end))
return {
"package_type": "startrack_monthly_log",
"document_meta": {
"package_type": "startrack_monthly_log",
"preset_key": preset_key,
"page_size_mm": {
"width": preset["width_mm"],
"height": preset["height_mm"],
},
"reflow_mode": preset["reflow_mode"],
"export_formats": ["svg", "pdf", "png"],
"design_intent": "printable_and_reeditable",
"quick_export": {
"label": "快速导出",
"preset_key": "a5",
"format": "pdf",
"preset_candidates": ["a5", "a6_personal", "tn_passport"],
},
},
"page_types": [
"monthly_overview",
"daily_record",
"month_end_verification",
],
"profile_source": profile_source,
"target_month": target_month,
"calculation_snapshot": deepcopy(calculation_snapshot),
"monthly_overview": normalized_summary,
"daily_entries": [
{
**deepcopy(entry),
"interpretation": deepcopy(entry.get("interpretation") or _resolve_theme_template(entry)["interpretation"]),
"keyword_tags": list(entry.get("keyword_tags") or _resolve_theme_template(entry)["keyword_tags"]),
"meaning_note": deepcopy(entry.get("meaning_note") or entry.get("interpretation") or _resolve_theme_template(entry)["meaning_note"]),
**_copy_recommendation_fields(entry),
"blank_area_required": True,
"blank_area": {
"style": design_tokens["blank_area_style"],
"editable": True,
"min_height_mm": design_tokens["blank_area_min_height_mm"],
},
}
for entry in daily_entries
],
"month_end": normalized_month_end,
"design_tokens": design_tokens,
"export_manifest": {
"formats": ["svg", "pdf", "png"],
"preset_keys": list(STARTRACK_PRESETS.keys()),
},
}