Skip to content

skywain/trip-planner-skill

trip-planner

Unverified

End-to-end international trip planning: turns "I want to go to X for N days" into a verified, bookable plan — route skeleton across cities, flight price scans (international + domestic legs), train-vs-fly decisions, hour-by-hour daily timelines with opening hours, dwell times, holiday collisions and tappable turn-by-turn map links (小时级行程+地图导航+离线KML), hotel shortlists by neighborhood, budget rollup, and a booking checklist with deep links. Use this whenever the user asks to plan a trip, vacation, itinerary or honeymoon, compare flight dates/prices, pick between cities or routes, schedule a travel day hour by hour, fill a spare block of time ("I'm near X with 2 free hours"), turn a finished plan into a designed page (eight themed renders: illustrated / clay / noir / glass / journal / zine / splash / portal — 插画/黏土/夜航/玻璃/手账/Zine/闪屏/穿越版), or asks 旅行规划/行程安排/机票比价/去某国玩N天怎么安排/现在有空档干嘛/把行程做成好看的网页 — even if they only mention one piece (just flights, just hotels, or just navigation), the playbook and verification rules here still apply.

FileKindSize
SKILL.mdskill md32.9 KB
assets/plan.example.jsonconfig12.1 KB
examples/README.mdmarkdown13.0 KB
examples/china-2026/china-splash.htmlother937.1 KB
examples/china-2026/china.art.jsonconfig6.4 KB
examples/china-2026/china.geo.jsonconfig58.3 KB
examples/fixtures/bad/bracketed-note.geo.jsonconfig7.8 KB
examples/fixtures/bad/brief-card-not-text.geo.jsonconfig943 B
examples/fixtures/bad/decision-point-date-two-days-before.geo.jsonconfig848 B
examples/fixtures/bad/decision-point-day-date-not-iso.geo.jsonconfig7.8 KB
examples/fixtures/bad/decision-point-no-if-no.geo.jsonconfig715 B
examples/fixtures/bad/decision-point-same-what.geo.jsonconfig8.2 KB
examples/fixtures/bad/decision-point-src-not-http.geo.jsonconfig803 B
examples/fixtures/bad/decision-point-t-not-hhmm.geo.jsonconfig764 B
examples/fixtures/bad/decision-points-null.geo.jsonconfig594 B
examples/fixtures/bad/driver-enum.geo.jsonconfig711 B
examples/fixtures/bad/driver-self-no-driving-card.geo.jsonconfig736 B
examples/fixtures/bad/driving-card-no-as-of.geo.jsonconfig861 B
examples/fixtures/bad/driving-card-no-desk.geo.jsonconfig800 B
examples/fixtures/bad/driving-card-no-legality-line.geo.jsonconfig811 B
examples/fixtures/bad/driving-card-no-verdict.geo.jsonconfig939 B
examples/fixtures/bad/driving-card-zh-verdict-trailing.geo.jsonconfig967 B
examples/fixtures/bad/hotel-checkout-null.geo.jsonconfig786 B
examples/fixtures/bad/hours-as-of-not-date.geo.jsonconfig674 B
examples/fixtures/bad/hours-bare-string.geo.jsonconfig655 B
examples/fixtures/bad/hours-src-not-http.geo.jsonconfig662 B
examples/fixtures/bad/hours-text-empty.geo.jsonconfig647 B
examples/fixtures/bad/kind-enum.geo.jsonconfig7.9 KB
examples/fixtures/bad/must-false.geo.jsonconfig914 B
examples/fixtures/bad/must-no-stand.geo.jsonconfig755 B
examples/fixtures/bad/must-no-view.geo.jsonconfig758 B
examples/fixtures/bad/must-not-boolean.geo.jsonconfig798 B
examples/fixtures/bad/must-see-unmatched.geo.jsonconfig963 B
examples/fixtures/bad/must-see-view-empty.geo.jsonconfig910 B
examples/fixtures/bad/pending-no-checklist-row.geo.jsonconfig1021 B
examples/fixtures/bad/refundable-not-boolean.geo.jsonconfig686 B
examples/fixtures/bad/rental-leg-no-driving-card.geo.jsonconfig829 B
examples/fixtures/bad/review-counts-disagree.geo.jsonconfig1.0 KB
examples/fixtures/bad/review-lens-enum.geo.jsonconfig1.1 KB
examples/fixtures/bad/review-no-driving-lens.geo.jsonconfig1.3 KB
examples/fixtures/bad/review-not-object.geo.jsonconfig611 B
examples/fixtures/bad/review-single-pass-with-counts.geo.jsonconfig1.0 KB
examples/fixtures/bad/review-two-lenses.geo.jsonconfig959 B
examples/fixtures/bad/self-drive-no-driving-card.geo.jsonconfig635 B
examples/fixtures/bad/sub-stop-no-name.geo.jsonconfig763 B
examples/fixtures/bad/sub-stop-no-query.geo.jsonconfig763 B
examples/fixtures/bad/sub-stops-null.geo.jsonconfig578 B
examples/fixtures/bad/tour-confirmed-prefix.geo.jsonconfig902 B
examples/fixtures/bad/tour-not-boolean.geo.jsonconfig562 B
examples/fixtures/bad/tour-on-day-object.geo.jsonconfig7.8 KB
examples/fixtures/bad/tour-unconfirmed.geo.jsonconfig837 B
examples/fixtures/strict/clean.plan.geo.jsonconfig4.5 KB
examples/fixtures/strict/hours-as-of-after-asof.geo.jsonconfig4.1 KB
examples/fixtures/strict/hours-missing-in-window.geo.jsonconfig4.0 KB
examples/fixtures/strict/hours-stale-as-of.geo.jsonconfig4.1 KB
examples/fixtures/strict/no-generated.geo.jsonconfig3.8 KB
examples/fixtures/strict/refundable-no-clause.geo.jsonconfig3.8 KB
examples/fixtures/strict/rows-without-clock-or-kind.geo.jsonconfig3.7 KB
examples/fixtures/strict/self-drive-not-legal-no-decision.geo.jsonconfig4.4 KB
examples/fixtures/strict/t-n-date-mismatch.geo.jsonconfig3.8 KB
examples/fixtures/strict/tour-no-review.geo.jsonconfig3.4 KB
examples/fixtures/substops.plan.geo.jsonconfig9.1 KB
examples/gates-sample.icsother11.5 KB
examples/japan-2026/japan-illustrated.htmlother1.4 MB
examples/japan-2026/japan.art.jsonconfig6.2 KB
examples/japan-2026/japan.geo.jsonconfig65.5 KB
examples/kyoto-sample.htmlother13.0 KB
examples/kyoto-sample.kmlother1012 B
examples/kyoto-sample.plan.geo.jsonconfig7.2 KB
examples/mexico-2026/mexico-journal.htmlother2.0 MB
examples/mexico-2026/mexico.art.jsonconfig9.4 KB
examples/mexico-2026/mexico.geo.jsonconfig77.1 KB
examples/morocco-2026/morocco-glass.htmlother1.3 MB
examples/morocco-2026/morocco-portal.htmlother13.8 KB
examples/morocco-2026/morocco.art.jsonconfig3.8 KB
examples/morocco-2026/morocco.geo.jsonconfig85.1 KB
examples/nordic-2026/nordic-noir.htmlother686.8 KB
examples/nordic-2026/nordic.art.jsonconfig8.7 KB
examples/nordic-2026/nordic.geo.jsonconfig58.5 KB
examples/turkey-2026/turkey-clay.htmlother1.3 MB
examples/turkey-2026/turkey.art.jsonconfig3.5 KB
examples/turkey-2026/turkey.geo.jsonconfig75.8 KB
examples/vietnam-2026/vietnam-zine.htmlother2.5 MB
examples/vietnam-2026/vietnam.art.jsonconfig10.8 KB
examples/vietnam-2026/vietnam.geo.jsonconfig85.1 KB
references/art-schema.mdmarkdown318 B
references/country-quick-notes.mdmarkdown58.6 KB
references/cover-titles.mdmarkdown10.6 KB
references/data-sources.mdmarkdown49.2 KB
references/navigation.mdmarkdown23.6 KB
references/output-template.mdmarkdown49.2 KB
references/phase-0-intake.mdmarkdown12.4 KB
references/phase-1-brief.mdmarkdown22.8 KB
references/phase-3-legs.mdmarkdown10.5 KB
references/phase-4-days.mdmarkdown13.6 KB
references/phase-6-assemble.mdmarkdown22.3 KB
references/scheduling.mdmarkdown28.8 KB
references/themes.mdmarkdown37.9 KB
scripts/build_site.pyscript47.8 KB
scripts/flight_scan.pyscript18.9 KB
scripts/plan_lint.pyscript58.4 KB
scripts/render_plan.pyscript28.2 KB
scripts/route_tools.pyscript90.0 KB

scripts/render_plan.py

View on GitHub
#!/usr/bin/env python3
"""Render a trip plan JSON into one self-contained, printable, phone-friendly HTML
file. Part of the trip-planner skill; stdlib only, Python 3.9+.

  python3 render_plan.py plan.json -o trip.html [--lang zh|en]

UI language: --lang > plan["lang"] > plan["meta"]["lang"] > zh. Only the page's own
chrome (section names, table headers, pills, footer) is translated; plan content is
printed as written. Keys mirror themes/theme_common.STRINGS where a shared name exists.

The SAME plan JSON feeds route_tools.py (which reads days[].stops) — keeping one
canonical file is what stops the map links, the KML and the written plan from
drifting apart. Every field is optional: render early and often, and the sections you
have not filled in yet simply do not appear.

Schema (all keys optional except days[].date):
{
 "trip": "Japan 12 days",
 "prefs": {"must_see", ...},   // Phase 0 intake — read by plan_lint, not rendered
 "meta": {"dates","party","route","budget_total","fx","generated","self_check","review"},
 "decisions": ["open-jaw into KIX out of NRT: refunds a backtracking day", ...],
 "checklist": [{"item","deadline","price","link","link_text","note","refundable"}],
 "legs":      [{"type","date","carrier","from","to","dep","arr","price","bags",
                "link","note","backup","refundable"}],
 "days": [{"date","city","label","sun","day_map","ribbon","rain_alt","late_cut",
           "decision_points",
           // HONEST total: on-foot ×1.3 + strolls + in-venue. Either a number or
           // {"total": 7.5, "how": "on foot 2.1×1.3 + in-station 0.8 + in-venue 4.0"}
           "walking_km": 5.4,
           "travel_day": true,
           "timeline": [{"t","what","kind":"anchor|hop|meal|free","price","note",
                         "tag":"pinned|opener|skippable|swap→X",
                         "verify":"verified|est","link",
                         "map": false,     // map:false = flight/rail hop covered by
                                           // legs — excluded from links --write
                         "hours", "tour", "sub_stops", "sub_map"}],
                                           // sub_stops: the points inside one sight,
                                           // listed under the row; fields defined only in
                                           // references/output-template.md §city-block
           "hop_links": ["url", ...],      // parked by route_tools when rows and
                                           // mapped hops don't align; rendered as
                                           // a hop-by-hop maps row under the day card
           "stops": [{"name","query","lat","lon","mode","driver"}]}],   // mirrors the
                                                        // timeline's places, in visit order
 "hotels": [{"base","area","why","options":[{"name","band","link","checkout","bag_hold"}]}],
 "budget": [{"cat","per_person","total","note"}],
 "brief":  {"visa","emergency","safety","health","holidays","weather","money",
            "connectivity","insurance","baggage", ...},   # canonical order: output-template §Brief templates
 "unverified": ["teamLab hours could not be confirmed", ...]
}
"""
import argparse
import html
import json
import math
import sys
from pathlib import Path

# UI strings. zh values are the historical ones — do not touch them (the kyoto sample
# render must stay byte-identical); en is the same shell in English.
STRINGS = {
    "zh": {
        "html_lang": "zh",
        "link": "地图/链接", "verify.est": "est.", "verify.verified": "verified",
        "map.cap": "示意图 · 约 {km:.1f} km 跨度 · 真实导航见上方链接",
        "sec.decisions": "为你做的决定 / Decisions made for you",
        "sec.checklist": "预订清单 / Booking checklist",
        "th.item": "项目", "th.deadline": "截止/提前量", "th.price": "价格", "th.link": "链接",
        "btn.book": "预订",
        "sec.legs": "航班与城际交通 / Flights & intercity",
        "th.date": "日期", "th.route": "行程", "th.carrier": "承运",
        "leg.backup": "备选: ", "link.view": "查看",
        "sec.days": "每日行程 / Day by day",
        "map.here": "↗地图", "map.day": "整日路线图", "hop.map": "逐跳导航: ",
        "hop.n": "第{}跳",
        "sub.must": "必看", "sub.stand": "站位: ", "sub.walk": "步行 {} 分钟",
        "sub.written": "已书面确认", "sub.pending": "待确认", "sub.chain": "按顺序步行导航",
        "hours.label": "开放时间", "hours.unverified": "开放时间未核实", "hours.open": "无固定开放时间",
        "decide.by": "{t} 前决定", "decide.check": "查看", "decide.if_no": "否则",
        "decide.cutoff": "截止", "link.source": "来源",
        "stay.checkout": "退房", "stay.bag_hold": "寄存行李",
        "walk.how": "步行约 {} km<span class=\"note\"> — {}</span>",
        "walk": "步行约 {} km(含街道系数、散步段与馆内)",
        "rain_alt": "雨天备选: ",
        "sec.hotels": "住宿 / Hotels",
        "sec.budget": "预算 / Budget",
        "th.cat": "类别", "th.pp": "每人", "th.total": "合计", "th.note": "备注",
        "sec.brief": "目的地简报 / Country brief",
        "sec.unverified": "⚠️ 未核实项 / Unverified",
        "footer": "生成于 {} · 价格会变,链接才是准绳 · 离线地图: 把 trip.kml 导入 "
                  "Organic Maps 或 Google My Maps · 日出日落数据 sunrise-sunset.org · 地理编码 "
                  "© OpenStreetMap contributors{}",
    },
    "en": {
        "html_lang": "en",
        "link": "map/link", "verify.est": "est.", "verify.verified": "verified",
        "map.cap": "schematic · about {km:.1f} km across · real navigation in the links above",
        "sec.decisions": "Decisions made for you",
        "sec.checklist": "Booking checklist",
        "th.item": "Item", "th.deadline": "Deadline / lead time", "th.price": "Price", "th.link": "Link",
        "btn.book": "book",
        "sec.legs": "Flights & intercity",
        "th.date": "Date", "th.route": "Route", "th.carrier": "Carrier",
        "leg.backup": "Backup: ", "link.view": "view",
        "sec.days": "Day by day",
        "map.here": "↗map", "map.day": "full-day route map", "hop.map": "hop-by-hop maps: ",
        "hop.n": "hop {}",
        "sub.must": "must-see", "sub.stand": "Stand here: ", "sub.walk": "{} min walk",
        "sub.written": "confirmed in writing", "sub.pending": "to confirm",
        "sub.chain": "walk this chain",
        "hours.label": "Hours", "hours.unverified": "hours unverified", "hours.open": "open access",
        "decide.by": "Decide by {t}", "decide.check": "check", "decide.if_no": "if no",
        "decide.cutoff": "cut-off", "link.source": "source",
        "stay.checkout": "Check-out", "stay.bag_hold": "Bags",
        "walk.how": "walk ~{} km<span class=\"note\"> — {}</span>",
        "walk": "walk ~{} km (street factor, strolls and in-venue included)",
        "rain_alt": "Rain plan: ",
        "sec.hotels": "Hotels",
        "sec.budget": "Budget",
        "th.cat": "Category", "th.pp": "Per person", "th.total": "Total", "th.note": "Note",
        "sec.brief": "Country brief",
        "sec.unverified": "⚠️ Unverified",
        "footer": "Generated {} · prices move, the links are the truth · offline map: import "
                  "trip.kml into Organic Maps or Google My Maps · sun times sunrise-sunset.org · "
                  "geocoding © OpenStreetMap contributors{}",
    },
}
_LANG = "zh"


def set_lang(lang):
    global _LANG
    _LANG = lang if lang in STRINGS else "zh"
    return _LANG


def T(key):
    return STRINGS.get(_LANG, {}).get(key, STRINGS["zh"][key])


CSS = """
:root{--bg:#fff;--fg:#1c1c1e;--dim:#6b6b70;--line:#e3e3e6;--card:#fafafa;
--accent:#2b6cb0;--warn:#b45309;--pin:#b91c1c;--ok:#15803d}
@media (prefers-color-scheme:dark){:root{--bg:#16171a;--fg:#e9e9ec;--dim:#9c9ca3;
--line:#2c2d31;--card:#1d1e22;--accent:#7aa7d9;--warn:#d99b3f;--pin:#e08585;--ok:#6cc08b}}
*{box-sizing:border-box}
body{margin:0;padding:20px 16px 60px;background:var(--bg);color:var(--fg);
font:16px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC",
"Hiragino Sans","Noto Sans CJK SC",sans-serif;-webkit-text-size-adjust:100%}
main{max-width:760px;margin:0 auto}
h1{font-size:1.6rem;margin:0 0 4px}h2{font-size:1.15rem;margin:32px 0 10px;
padding-bottom:5px;border-bottom:2px solid var(--line)}
h3{font-size:1rem;margin:0 0 6px}
a{color:var(--accent);overflow-wrap:anywhere}
a:focus-visible,button:focus-visible,summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sub{color:var(--dim);font-size:.9rem;margin:0 0 2px}
.metagrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));
gap:6px 18px;margin:14px 0 0;font-size:.92rem}
.metagrid div{color:var(--dim)}.metagrid b{color:var(--fg);font-weight:600}
.scroll{overflow-x:auto;-webkit-overflow-scrolling:touch}
table{border-collapse:collapse;width:100%;font-size:.92rem}
th,td{text-align:left;padding:7px 9px;border-bottom:1px solid var(--line);
vertical-align:top}
th{font-size:.78rem;text-transform:uppercase;letter-spacing:.04em;color:var(--dim)}
.day{background:var(--card);border-left:4px solid var(--accent);border-radius:6px;
padding:12px 14px;margin:0 0 16px}
.day.travel{border-left-color:var(--warn)}
.day h3{display:flex;flex-wrap:wrap;gap:8px;align-items:baseline}
.day h3 .sun{font-weight:400;color:var(--dim);font-size:.85rem}
.tl{width:100%;font-size:.92rem}
.tl td{border-bottom:1px solid var(--line);padding:6px 8px 6px 0}
.tl tr:last-child td{border-bottom:0}
.tl .t{white-space:nowrap;font-variant-numeric:tabular-nums;color:var(--dim);
width:1%;padding-right:12px}
.tl tr.hop td{color:var(--dim);font-size:.87rem}
.tl tr.meal .what::before{content:"🍽 "}
.note{color:var(--dim);font-size:.87rem}
.pill{display:inline-block;font-size:.72rem;padding:1px 7px;border-radius:20px;
border:1px solid var(--line);margin-left:6px;white-space:nowrap;color:var(--dim)}
.pill.pinned{color:var(--pin);border-color:var(--pin)}
.pill.opener{color:var(--warn);border-color:var(--warn)}
.pill.verified{color:var(--ok);border-color:var(--ok)}
.ribbon{font-size:.87rem;color:var(--dim);margin:10px 0 0;overflow-wrap:anywhere}
.daymap{display:block;margin:10px 0 0;max-width:100%}
.daymap polyline{fill:none;stroke:var(--accent);stroke-width:2;stroke-dasharray:5 4;
opacity:.8}
.daymap circle{fill:var(--accent);opacity:.92}
.daymap text{fill:var(--bg);font-size:12px;font-weight:600}
.daymap text.cap{fill:var(--dim);font-size:11px;font-weight:400}
.dayfoot{font-size:.87rem;margin:8px 0 0}
.warn{color:var(--warn)}
ul{padding-left:20px;margin:8px 0}li{margin:3px 0}
footer{margin:40px 0 0;padding-top:12px;border-top:1px solid var(--line);
color:var(--dim);font-size:.83rem}
input[type=checkbox]{width:17px;height:17px}
@media print{body{padding:0;font-size:11pt}a{color:inherit;text-decoration:none}
h2{page-break-after:avoid}.day{page-break-inside:avoid;background:none;
border:1px solid #ccc}footer{page-break-before:avoid}}
"""

JS = """
(function(){var k='tripcheck:'+document.title;
var s=JSON.parse(localStorage.getItem(k)||'{}');
document.querySelectorAll('input[type=checkbox][data-k]').forEach(function(b){
 if(s[b.dataset.k])b.checked=true;
 b.addEventListener('change',function(){s[b.dataset.k]=b.checked;
  localStorage.setItem(k,JSON.stringify(s));});});})();
"""


def e(v):
    return html.escape(str(v)) if v is not None else ""


def link(url, label=None):
    if not url:
        return ""
    return '<a href="{}" target="_blank" rel="noopener">{}</a>'.format(
        e(url), e(label or T("link")))


def pills(item):
    out = ""
    tag = item.get("tag")
    if tag:
        t = str(tag)
        cls = "pinned" if t.startswith("pinned") else (
            "opener" if t.startswith("opener") else "")
        out += '<span class="pill {}">{}</span>'.format(cls, e(tag))
    v = item.get("verify")
    if v:
        label = T("verify.verified") if v == "verified" else T("verify.est")
        out += '<span class="pill {}">{}</span>'.format(
            "verified" if v == "verified" else "", label)
    return out


def _http(v):
    return isinstance(v, str) and v.startswith(("https://", "http://"))


def sub_stops(row):
    """row["sub_stops"] as an <ol> under the row, or "" when the row has none
    or the value is malformed (plan_lint reports it; this never raises). The
    plain-page twin of themes/theme_common.sub_stops_html — same content, but
    on this page's .pill / .note classes, so no CSS is added."""
    subs = row.get("sub_stops")
    if not isinstance(subs, list):
        return ""
    tour = row.get("tour") is True
    items = []
    for s in subs:
        name = (s.get("name") or s.get("query")) if isinstance(s, dict) else None
        if not name:
            continue
        must = s.get("must") is True
        li = ('<span role="img" aria-label="{0}" title="{0}">★</span> '.format(
            e(T("sub.must"))) if must else "") + "<b>{}</b>".format(e(name))
        view = s.get("view")
        if isinstance(view, str) and view.strip():   # a phrase, so it may wrap
            li += '<span class="pill" style="white-space:normal">{}</span>'.format(e(view))
        if _http(s.get("link")):
            li += " " + link(s["link"], T("map.here"))
        meta = []
        walk = s.get("walk_min")
        if walk not in (None, "") and not isinstance(walk, bool):
            meta.append(e(T("sub.walk").format(walk)))
        conf = s.get("confirmed")
        if tour and (must or conf):
            conf = conf.strip() if isinstance(conf, str) else ""
            low = conf.lower()                  # plan_lint reads the prefix case-insensitively
            done = low.startswith("in writing")
            for pre in ("in writing", "pending"):
                if low.startswith(pre):
                    conf = conf[len(pre):]
                    break
            conf = conf.strip(" ·:-—")
            meta.append(e(T("sub.written" if done else "sub.pending"))
                        + (" · " + e(conf) if conf else ""))
        if meta:
            li += '<span class="note"> · {}</span>'.format(" · ".join(meta))
        if s.get("stand"):
            li += '<div class="note">{}{}</div>'.format(e(T("sub.stand")), e(s["stand"]))
        items.append("<li>{}</li>".format(li))
    if not items:
        return ""
    chain = ('<div class="note">{}</div>'.format(link(row["sub_map"], T("sub.chain")))
             if _http(row.get("sub_map")) else "")
    return ('<ol style="margin:4px 0 2px;padding-left:20px">{}</ol>{}'
            .format("".join(items), chain))


# The twins of theme_common.hours_html / decision_points_html / stay_rules_html:
# same content on this page's classes, "" when the key is absent or malformed.
def hours(row):
    """row["hours"] as one .note line under the row."""
    h = row.get("hours") if isinstance(row, dict) else None
    if h in ("unverified", "open access"):
        return '<div class="note">{}</div>'.format(
            e(T("hours.unverified" if h == "unverified" else "hours.open")))
    if not (isinstance(h, dict) and isinstance(h.get("text"), str) and h["text"].strip()):
        return ""
    out = "{}: {}".format(e(T("hours.label")), e(h["text"]))
    asof = h.get("as_of") if isinstance(h.get("as_of"), str) else ""
    if _http(h.get("src")):
        out += " · " + link(h["src"], asof.strip() or T("link.source"))
    elif asof.strip():
        out += " · " + e(asof)
    return '<div class="note">{}</div>'.format(out)


def decision_points(day):
    """day["decision_points"] as a strip above the timeline, one line per point."""
    dps = day.get("decision_points") if isinstance(day, dict) else None
    lines = []
    for x in dps if isinstance(dps, list) else []:
        t, what = (x.get("t"), x.get("what")) if isinstance(x, dict) else (None, None)
        if not (isinstance(t, str) and t.strip() and isinstance(what, str) and what.strip()):
            continue
        date = x.get("date")
        if isinstance(date, str) and date.strip() and date != day.get("date"):
            t = "{} {}".format(date, t)
        bits = ["{}: {}".format(e(T(k)), e(x[f])) for f, k in
                (("check", "decide.check"), ("if_no", "decide.if_no"), ("by", "decide.cutoff"))
                if isinstance(x.get(f), str) and x[f].strip()]
        if _http(x.get("src")):
            bits.append(link(x["src"], T("link.source")))
        lines.append("<div><b>{}</b> · {}{}</div>".format(
            e(T("decide.by").format(t=t)), e(what),
            '<span class="note"> · {}</span>'.format(" · ".join(bits)) if bits else ""))
    if not lines:
        return ""
    return ('<div style="margin:0 0 8px;padding-left:8px;border-left:3px solid var(--warn);'
            'font-size:.87rem">{}</div>'.format("".join(lines)))


def stay_rules(option):
    """A hotel option's checkout / bag_hold as two .note lines under it."""
    if not isinstance(option, dict):
        return ""
    return "".join('<div class="note">{}: {}</div>'.format(e(T(k)), e(option[f])) for f, k in
                   (("checkout", "stay.checkout"), ("bag_hold", "stay.bag_hold"))
                   if isinstance(option.get(f), str) and option[f].strip())


def section(title, body):
    return "<h2>{}</h2>\n{}".format(e(title), body) if body else ""


def day_svg(stops, w=680, h=170, pad=26):
    """A schematic of the day's shape from the stop coordinates — numbered dots in
    visiting order, joined in sequence. Deliberately NOT a street map: it has no
    tiles, so it works offline and inside a strict CSP, and it answers the only
    question a glance can answer — does today zig-zag across town or flow in a line?
    Real navigation stays in the per-hop links."""
    pts = [(float(s["lat"]), float(s["lon"]), s.get("name", ""))
           for s in stops
           if isinstance(s, dict) and s.get("lat") is not None
           and s.get("lon") is not None]
    if len(pts) < 2:
        return ""
    lats = [p[0] for p in pts]
    lons = [p[1] for p in pts]
    mlat = sum(lats) / len(lats)
    kx = math.cos(math.radians(mlat))            # equirectangular: shrink lon
    xs = [p[1] * kx for p in pts]
    ys = [-p[0] for p in pts]
    spanx, spany = max(xs) - min(xs), max(ys) - min(ys)
    if spanx <= 0 and spany <= 0:
        return ""
    scale = min((w - 2 * pad) / spanx if spanx > 0 else 1e9,
                (h - 2 * pad) / spany if spany > 0 else 1e9)
    cx = (w - spanx * scale) / 2 - min(xs) * scale
    cy = (h - spany * scale) / 2 - min(ys) * scale
    xy = [(x * scale + cx, y * scale + cy) for x, y in zip(xs, ys)]
    # scale bar: 1 degree of latitude ≈ 111.2 km, and y is in degrees of latitude
    km_across = spany * 111.2 if spany > 0 else spanx / kx * 111.2
    poly = " ".join("{:.1f},{:.1f}".format(x, y) for x, y in xy)
    dots = "".join(
        '<circle cx="{:.1f}" cy="{:.1f}" r="11"/>'
        '<text x="{:.1f}" y="{:.1f}" text-anchor="middle" dy="4">{}</text>'
        '<title>{}</title>'.format(x, y, x, y, i, e(p[2]))
        for i, ((x, y), p) in enumerate(zip(xy, pts), 1))
    return ((
        '<svg class="daymap" viewBox="0 0 {w} {h}" width="100%" height="{h}" '
        'role="img" aria-label="route shape"><polyline points="{poly}"/>{dots}'
        '<text class="cap" x="8" y="{cap}">' + T("map.cap") + '</text></svg>').format(
            w=w, h=h, poly=poly, dots=dots, cap=h - 7, km=max(km_across, 0.1)))


def render(p):
    meta = p.get("meta") or {}
    trip = p.get("trip") or "Trip plan"
    out = ['<main>', "<h1>{}</h1>".format(e(trip))]
    if meta.get("route"):
        out.append('<p class="sub">{}</p>'.format(e(meta["route"])))
    mg = [(k, meta.get(k)) for k in
          ("dates", "party", "budget_total", "fx", "self_check")]
    mg = [(k, v) for k, v in mg if v]
    if mg:
        out.append('<div class="metagrid">' + "".join(
            "<div>{}<br><b>{}</b></div>".format(e(k.replace("_", " ")), e(v))
            for k, v in mg) + "</div>")

    if p.get("decisions"):
        out.append(section(T("sec.decisions"),
                           "<ul>" + "".join("<li>{}</li>".format(e(d))
                                            for d in p["decisions"]) + "</ul>"))

    if p.get("checklist"):
        rows = []
        for i, c in enumerate(p["checklist"]):
            rows.append(
                "<tr><td><input type=checkbox data-k='c{}'></td><td>{}{}</td>"
                "<td>{}</td><td>{}</td><td>{}</td></tr>".format(
                    i, e(c.get("item")),
                    '<div class="note">{}</div>'.format(e(c["note"]))
                    if c.get("note") else "",
                    e(c.get("deadline")), e(c.get("price")),
                    link(c.get("link"), c.get("link_text") or T("btn.book"))))
        out.append(section(
            T("sec.checklist"),
            '<div class="scroll"><table><tr><th></th><th>{}</th><th>{}'
            "</th><th>{}</th><th>{}</th></tr>".format(
                T("th.item"), T("th.deadline"), T("th.price"), T("th.link"))
            + "".join(rows) + "</table></div>"))

    if p.get("legs"):
        rows = []
        for l in p["legs"]:
            route = "{} → {}".format(e(l.get("from")), e(l.get("to")))
            times = " ".join(x for x in [e(l.get("dep")), "→", e(l.get("arr"))] if x)
            extra = " · ".join(x for x in [e(l.get("bags")), e(l.get("note"))] if x)
            back = ('<div class="note">{}{}</div>'.format(T("leg.backup"), e(l["backup"]))
                    if l.get("backup") else "")
            rows.append(
                "<tr><td>{}<div class='note'>{}</div></td><td>{}<div class='note'>"
                "{}</div></td><td>{}</td><td>{}{}</td><td>{}</td></tr>".format(
                    e(l.get("date")), e(l.get("type")), route, times,
                    e(l.get("carrier")), e(l.get("price")),
                    '<div class="note">{}</div>'.format(extra) if extra else "",
                    link(l.get("link"), T("link.view")) + back))
        out.append(section(
            T("sec.legs"),
            '<div class="scroll"><table><tr><th>{}</th><th>{}</th><th>{}</th>'
            "<th>{}</th><th>{}</th></tr>".format(
                T("th.date"), T("th.route"), T("th.carrier"), T("th.price"), T("th.link"))
            + "".join(rows) + "</table></div>"))

    if p.get("days"):
        cards = []
        for d in p["days"]:
            head = " · ".join(x for x in [e(d.get("date")), e(d.get("city")),
                                          e(d.get("label"))] if x)
            sun = ('<span class="sun">{}</span>'.format(e(d["sun"]))
                   if d.get("sun") else "")
            rows = []
            for it in d.get("timeline", []):
                kind = it.get("kind", "anchor")
                what = e(it.get("what"))
                if it.get("link"):
                    what += " " + link(it["link"], T("map.here"))
                bits = [x for x in [e(it.get("price")), e(it.get("note"))] if x]
                if bits:
                    what += '<div class="note">{}</div>'.format(" — ".join(bits))
                rows.append('<tr class="{}"><td class="t">{}</td>'
                            '<td class="what">{}{}{}{}</td></tr>'.format(
                                e(kind), e(it.get("t")), what, pills(it), hours(it),
                                sub_stops(it)))
            foot = []
            if d.get("day_map"):
                foot.append(link(d["day_map"], T("map.day")))
            if d.get("hop_links"):
                foot.append(T("hop.map") + " ".join(
                    link(u, T("hop.n").format(i + 1))
                    for i, u in enumerate(d["hop_links"])))
            wk = d.get("walking_km")
            if isinstance(wk, dict):
                foot.append(T("walk.how").format(
                    e(wk.get("total")), e(wk.get("how", ""))))
            elif wk:
                foot.append(T("walk").format(e(wk)))
            if d.get("rain_alt"):
                foot.append(T("rain_alt") + e(d["rain_alt"]))
            fl = ('<div class="dayfoot">{}</div>'.format(" · ".join(foot))
                  if foot else "")
            lc = ('<div class="dayfoot warn">{}</div>'.format(e(d["late_cut"]))
                  if d.get("late_cut") else "")
            if d.get("ribbon"):
                lc = '<div class="ribbon">{}</div>'.format(e(d["ribbon"])) + lc
            cards.append(
                '<div class="day{}"><h3>{} {}</h3>{}<table class="tl">{}</table>'
                "{}{}{}</div>".format(" travel" if d.get("travel_day") else "",
                                      head, sun, decision_points(d), "".join(rows), fl, lc,
                                      day_svg(d.get("stops") or [])))
        out.append(section(T("sec.days"), "".join(cards)))

    if p.get("hotels"):
        blocks = []
        for h in p["hotels"]:
            opts = "".join(
                "<li>{} — {} {}{}</li>".format(e(o.get("name")), e(o.get("band")),
                                               link(o.get("link"), T("link.view")), stay_rules(o))
                for o in h.get("options", []))
            blocks.append("<h3>{} · {}</h3><p class='note'>{}</p><ul>{}</ul>".format(
                e(h.get("base")), e(h.get("area")), e(h.get("why")), opts))
        out.append(section(T("sec.hotels"), "".join(blocks)))

    if p.get("budget"):
        rows = "".join(
            "<tr><td>{}</td><td>{}</td><td>{}</td><td class='note'>{}</td></tr>"
            .format(e(b.get("cat")), e(b.get("per_person")), e(b.get("total")),
                    e(b.get("note"))) for b in p["budget"])
        out.append(section(
            T("sec.budget"),
            '<div class="scroll"><table><tr><th>{}</th><th>{}</th><th>{}</th>'
            "<th>{}</th></tr>".format(T("th.cat"), T("th.pp"), T("th.total"), T("th.note"))
            + rows + "</table></div>"))

    if p.get("brief"):
        rows = "".join("<li><b>{}</b>: {}</li>".format(e(k), e(v))
                       for k, v in p["brief"].items() if v)
        out.append(section(T("sec.brief"), "<ul>" + rows + "</ul>"))

    if p.get("unverified"):
        out.append(section(T("sec.unverified"),
                           "<ul>" + "".join("<li>{}</li>".format(e(u))
                                            for u in p["unverified"]) + "</ul>"))

    out.append(
        "<footer>" + T("footer").format(
            e(meta.get("generated", "")),
            " · " + e(meta["self_check"]) if meta.get("self_check") else "")
        + "</footer></main>")
    return ("<!doctype html><html lang=\"{}\"><head><meta charset=\"utf-8\">"
            "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
            "<title>{}</title><style>{}</style></head><body>{}"
            "<script>{}</script></body></html>").format(
                T("html_lang"), e(trip), CSS, "\n".join(out), JS)


def main():
    ap = argparse.ArgumentParser(
        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    ap.add_argument("plan")
    ap.add_argument("-o", "--out", default="trip.html")
    ap.add_argument("--force", action="store_true",
                    help="render even with template scaffolding still in the plan")
    ap.add_argument("--lang", default=None, choices=sorted(STRINGS),
                    help="UI language (default: plan.lang > plan.meta.lang > zh)")
    a = ap.parse_args()
    try:
        plan = json.loads(Path(a.plan).read_text(encoding="utf-8"))
    except Exception as ex:
        sys.exit("Bad plan JSON ({}) — see this script's docstring for the schema."
                 .format(ex))
    if not isinstance(plan, dict):
        sys.exit("Plan JSON must be an object with a \"days\" list.")
    set_lang(a.lang or plan.get("lang") or (plan.get("meta") or {}).get("lang") or "zh")
    # Scaffolding must never reach a traveller. Both of these mean the template was
    # edited field-by-field and something got missed.
    blob = json.dumps(plan, ensure_ascii=False)
    leftovers = []
    if "_readme" in plan:
        leftovers.append('the template\'s "_readme" key is still present')
    if "PLACEHOLDER" in blob:
        leftovers.append("{} PLACEHOLDER value(s) never filled in".format(
            blob.count("PLACEHOLDER")))
    if leftovers and not a.force:
        sys.exit("Refusing to render — " + "; ".join(leftovers)
                 + ".\nFix them, or pass --force to render anyway.")
    for w in leftovers:
        print("WARNING (forced): " + w)
    Path(a.out).write_text(render(plan), encoding="utf-8")
    print("wrote {} ({} days)".format(a.out, len(plan.get("days") or [])))


if __name__ == "__main__":
    main()
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall