Skip to content

feat: holiday typhoon — 颱風假查詢(即時頁 + 歸檔),v2.1.0 - #8

Merged
lis186 merged 4 commits into
mainfrom
feat/typhoon-command
Oct 28, 2026
Merged

lis186 merged 4 commits into
mainfrom
feat/typhoon-command

Conversation

@lis186

@lis186 lis186 commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

摘要

新增 holiday typhoon [date] [-c, --city <city>],回答「某天某縣市要不要上班、上課」。

  • 今天、明天:直接讀 DGPA 即時頁,結果標 reason: "live";抓不到或格式不認得時退回歸檔並註明。
  • 其他日期:讀 TaiwanTyphoonDays 歸檔(2001-07-30 起)。
  • JSON 頂層直接給結論:work/school 的 status ∈ stopped/conditional/normal/unknown,附 basis(當日公告/前一日預告/無公告)與 reason(為何還可能改變)。寧可回 unknown,也不把「沒資料」說成「照常」。
  • 函式庫匯出 evaluateTyphoon、evaluateLive(純函式)與 TyphoonService,供 taiwan-holiday-mcp 使用。
  • 版號 2.0.0 → 2.1.0(只改版號;未打 tag、未發佈 npm)。

行為變更(影響所有命令)

「今天」改以臺灣時間(Asia/Taipei)計算。過去在 UTC 主機(CI、雲端、透過 npx 呼叫的 LLM 工具)上,臺灣早上 0–8 點的 today/tomorrow/next 會差一天。

設計

API 形狀與驗證方法經 Fable、Astra 兩輪對抗評審後收斂(詳見 PRD 2.2.16)。過程中修掉的問題:

  • raw.githubusercontent 回 text/plain,未強制 JSON 時會拿到字串,大檔當掉、小檔靜默答「照常」(只有端對端測試抓得到)。
  • 當日公告沒有當日記錄時,被推翻的前一日預告會「復活」。
  • 當日公告的記錄全被略過(「尚未宣布消息」)時誤判照常。
  • 全國層級把「所有有公告的縣市都停」說成「全臺停止」。

驗證

  • 單元測試 410 個,本機時區與 TZ=UTC 皆全過;typecheck、lint(無新警告)、build 通過。
  • 即時解析器(逐條移植上游 parse.py):
    • 上游格級 fixtures 11 份(釘住上游 3b635f8),逐欄一致,CI 會跑。
    • 上游 data/ 全量 7,793 筆記錄、1,689 種句子逐欄一致;突變測試確認不是空轉。
    • 2017 年起全部 311 份歷史附件整頁解析與上游一致(本機)。
  • 歸檔結論:全量 510 個日期逐日逐縣市檢查不變式,0 違反。
  • 端對端:對真實 DGPA 即時頁與上游歸檔實測(今天、明天、2024-10-31 臺北、2024-08-09 前日預告、2022-10-17 桃園照常上班停止上課等)。

已知限制/後續

  • 昨天到 21 天前是空窗(即時頁只有今天、明天;歸檔事後才收錄)→ 回 unknown。
  • 未做條件 GET 與「更新時間不倒退」:需要跨呼叫的磁碟快取。
  • 語料測試(tests/corpus/)需設定 TYPHOON_DATA_DIR,CI 不會跑;之後可在 upstream-canary workflow 拉上游 repo 執行。
  • 子區域過濾 --area 尚未實作。
  • 兩個既有測試(dateToNormalized)在非 UTC+ 時區(如洛杉磯)會失敗,是測試寫法依賴時區,與本 PR 無關。

🤖 Generated with Claude Code

Justin Lee and others added 3 commits October 28, 2026 15:52
Query whether work/school stopped on a given day (2001-07-30 onward),
using lis186/TaiwanTyphoonDays. The top level gives a verdict
(stopped / conditional / normal / unknown) with its basis (own
announcement, previous day's forecast, or none) and whether it is
settled, so scripts and LLMs do not have to interpret raw rows.

- Pure evaluateTyphoon() plus a fetching TyphoonService, exported
  from the library.
- Pick the day's own announcement before filtering rows, so an
  overridden forecast never revives.
- No record within 21 days, or a missing current-year file, is
  `unknown`, never `normal`.
- Read raw.githubusercontent (forced JSON: it serves text/plain),
  falling back to jsDelivr on network errors.
- "today" now uses Asia/Taipei for all commands; on UTC hosts it was
  a day behind between 00:00 and 08:00 Taiwan time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`holiday typhoon` now reads https://www.dgpa.gov.tw/typh/daily/nds.html
for today and tomorrow (Taiwan time); other dates still use the archive.
Live results carry `reason: "live"` and `source.kind: "live"`. If the
live page cannot be fetched or its format is not recognised, fall back
to the archive result with a note instead of failing.

- typhoon-live-parser.ts ports upstream parse.py (parse_page down) 1:1,
  keeping its strict grammar.
- evaluateLive() maps page states: 無停班停課訊息 -> normal; city listed
  but only skipped sentences -> unknown; city not listed -> normal (no
  announcement yet); no rows for tomorrow -> unknown; no rows and no
  notice -> format error.
- Contract tests: upstream page fixtures (pinned at 3b635f8) run in CI;
  a corpus test over every upstream sentence runs when
  TYPHOON_DATA_DIR is set.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T09:17:18.203448Z ed77394 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed773943dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +280 to +281
} else if (isToday && r.cities.length === 0) {
const listed = r.city ? page.cities.includes(r.city) : page.cities.length > 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include listed-but-unannounced cities in nationwide verdicts

When the live page contains both a parsed normal city and a city whose only text is 尚未宣布消息。, the nationwide query returns normal for both work and school, even though querying the latter city correctly returns unknown. parseCell omits the pending city's rows, so evaluateTyphoon aggregates only the normal city, and this correction is skipped because r.cities.length is nonzero. Check listed cities without applicable rows when computing the nationwide verdict so an unresolved city cannot become a nationwide all-clear.

Useful? React with 👍 / 👎.

Comment thread src/commands/typhoon.ts
Comment on lines +100 to +104
for (const area of rows) {
table.push([formatDateString(result.date), areaName(area), areaStatus(area)]);
}
}
return table.toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve provisional-status warnings in table output

For -f table, any result containing rows displays only the individual area statuses and returns before rendering the source or notes; unlike the empty-row case, it also omits finalityLabel. Consequently, tomorrow's live forecast and a recent archived forecast appear simply as 停止上班、停止上課, with no indication that they are provisional or may have been superseded. A live-fetch failure's archive-fallback warning is likewise lost. Include the result's finality and relevant notes alongside the table so changing output format does not hide qualifications needed to interpret the answer.

Useful? React with 👍 / 👎.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@lis186
lis186 merged commit a55530d into main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant