"""FR-196 拆卡底表：design.md §6、Notion 子卡、工作坊四欄都從這張表產，改一處三處一致。
🔴 只放開發卡：驗收、套件發版、改回釘版不開卡，見 design.md §7「合回後收口清單」。
三期全部在本檔（決策者 2026-11-11 先裁分批、再改三期都開）：批 1～4 第一期、批 5～8 第二期（F-5 退役在批 8）、批 8～10 第三期。
每張卡：id／階段／批／repo／標題／reuse-extend-new／改哪些既有檔／新開哪些檔／依賴／驗收／model／effort／理由。
批（Stage）＝能同時跑的那一組：不改同一檔、不依賴對方產出、不搶同一外部資源。階段只是分組標籤。
repo 值：main（BE）、fe、jedi-packages。
"""
CARDS = [
# ───────── 第一期 P1 看得見 ─────────
dict(id="E-1", phase="P1", stage=1, repo="main", model="sonnet", effort="low",
  title="環境卡：主系統開發期改走 jedi-notification-center 本機路徑（套件是新的，先在套件 repo 工作區建空骨架讓 import 得到）",
  ren="reuse：既有 poetry path dependency 形式（pyproject.toml 第 122～136 行註解掉那組的寫法）；指向套件工作坊工作區 `jedi-python-package/.worktrees/<母卡號>/jedi-notification-center`",
  edit=["pyproject.toml（加一行 path dependency；不 commit，`git update-index --assume-unchanged`）"], new=[],
  deps=[], why="機械性：加一行、poetry update 指定套件名、驗 import 路徑；套件骨架 P-1 同批在建，本卡只要 import 得到空套件",
  accept="`python -c 'import jedi_notification_center as m; print(m.__file__)'` 印出的路徑在 `jedi-python-package/.worktrees/` 底下；`python main.py` 起得來；`git status` 不見 pyproject.toml"),
dict(id="P-1", phase="P1", stage=1, repo="jedi-packages", model="opus", effort="high",
  title="jedi-notification-center 0.1.0 套件骨架：七張 port 介面、adapters 契約、domain entity、五張表 model 與 migration SQL、`notify()` 入口、事件型錄與收件匣 repo（不含 REST）",
  ren="new（新套件，照型）：目錄與 plugin 契約照 jedi-bulletin（`plugin/contract.py` adapters dataclass 守門四件無預設值、`plugin/migrations.py::iter_migrations()`、`plugin/runtime.py`）；repo 繼承 jedi-common `BaseRepositoryImpl`；migration SQL 的 RLS／GRANT 照 jedi-bulletin `migrations/002`；port 命名照 jedi-bulletin `domain/ports.py`",
  edit=["jedi-python-package/pyproject.toml（workspace 若有列套件清單則加一列；沒有就不動）", "jedi-python-package/README.md（25 支名冊加一列）"],
  new=["jedi-notification-center/pyproject.toml（0.1.0；依賴 jedi-common、jedi-notification>=1.2.4）", "jedi-notification-center/jedi_notification_center/__init__.py（export notify、register、NotificationCenterAdapters、Role）", "jedi-notification-center/jedi_notification_center/domain/ports.py（IRecipientDirectory／ITemplateRenderer／ILinkResolver／IDeliveryGateway／IRealtimeNotifier／IClock／ITenantContext）", "jedi-notification-center/jedi_notification_center/domain/entities/（notification_event、inbox_item、user_setting、user_profile、maintenance 五個 entity＋query entity）", "jedi-notification-center/jedi_notification_center/domain/repositories/（五張 repo 介面）", "jedi-notification-center/jedi_notification_center/infra/models/（五張 SQLAlchemy model，design.md §5.2 表 5-1～5-4＋notification_maintenance）", "jedi-notification-center/jedi_notification_center/infra/repository/（五張 repo impl；inbox 的 list 走 (recipient_user_id, archived_at, read_at, created_at desc) 索引）", "jedi-notification-center/jedi_notification_center/infra/mapper/", "jedi-notification-center/jedi_notification_center/app/service/notify_service.py（`notify()`：查型錄 → 展開 Role → 查每人設定或預設 → 渲染 → 寫 inbox → 交 delivery port；型錄查不到寫 warning 回 None；recipients 空直接 return）", "jedi-notification-center/jedi_notification_center/plugin/contract.py、assembly.py、runtime.py、migrations.py", "jedi-notification-center/migrations/001-notification-center-tables.sql（五張表＋索引）、002-notification-center-rls-grants.sql", "jedi-notification-center/tests/（port 假件；notify 寫 inbox、必收覆寫設定、型錄查不到不炸、Role 展開）", "jedi-notification-center/README.md（照 jedi-notification README 的「兩種用法」骨架）"],
  deps=[], why="跨層設計：port 邊界與 notify 行為一次定好，後面主系統與 FE 都照它接；要過 jedi-package-dev 守門",
  accept="套件 tests 綠（含：必收事件就算設定關了 inapp 仍寫 inbox；型錄查不到回 None 且 log warning；Role('tenant_admin') 經 port 展開；recipients 空不寫）；`iter_migrations()` 回兩支；用套件 harness 或 sqlite 跑一次 `notify()` 後 inbox 有一列且 title 已渲染；0.1.0 不發版（收口才發）"),
dict(id="S-1", phase="P1", stage=2, repo="main", model="sonnet", effort="medium",
  title="主線 seed migration：事件型錄 23 列（design.md 事件型錄＋表 5-1 欄位）、system_menus 兩個 group（NOTIFICATION_CATEGORY 5 值、NOTIFICATION_DIGEST 3 值）、能力點 notification.inbox.read（全員）與 notification.banner.publish；🔴 manifest.tsv owner",
  ren="reuse：seed 先例 `scripts/sql/2026-05-22-seed-oscal-ssp-roles.sql`（ON CONFLICT DO NOTHING）；能力點 seed 照 FR-194 `2026-11-10-fr194-ui-routes-entry-gates.sql` 的名稱比對寫法；表本身由 P-1 的套件 migration 建，本卡只灌資料，所以本卡要先把 P-1 的 001／002 以主線 manifest 形式登記（照 `2026-09-10-fr080-cm1625-bulletin-org-units-soft-ref.sql` 套件表隨主線 manifest 走的先例）。`link_route` 對照（填死不留空）：task.*／stage.entered／scan.critical_found／scan.task_completed → `my-tasks`（params query：project／job／execution）；project.* → `project-auditor-overview-round`（params：id＝project_uid、roundUid）；agent.* → `remote-agent-manage`；system.update_available → `product-update`；license.expiring → `license-status`；system.maintenance_scheduled → `home`；account.password_expiring → `user-profile`；bulletin.published → `bulletin-view`（params：uid）；feedback.replied → `home`",
  edit=["scripts/sql/manifest.tsv（🔴 本案第一期唯一 owner：登記 P-1 兩支＋本卡兩支，共四行）"],
  new=["scripts/sql/2026-11-12-fr196-notification-center-tables.sql（內容＝複製 P-1 的 001＋002，主線 manifest 可追）", "scripts/sql/2026-11-12-fr196-seed-notification-events.sql（23 列型錄：code／category／mandatory／三個 default／merge_window_sec／link_route／link_params_template／四個 i18n key／sort；兩個 system_menus group；兩顆能力點；Administrator 授權）"],
  deps=["P-1"], why="資料類、照先例；link_route 對照已填死在 ren 欄，i18n key 用固定形式 `notification_center.events.<code>.title`，填錯症狀是點通知跳不到頁且無錯誤",
  accept="`psql --single-transaction -v ON_ERROR_STOP=1` 用 cmmgr 只套 DEV 過；`select count(*) from public.notification_events`＝23、`mandatory`＝8；`select count(*) from system_menus where \"group\" in ('NOTIFICATION_CATEGORY','NOTIFICATION_DIGEST')`＝8；能力點兩顆存在且 Administrator 有；連跑兩次冪等；回寫明講「出貨基線待重產」；manifest 四行格式與既有列一致"),
dict(id="P-2", phase="P1", stage=2, repo="jedi-packages", model="opus", effort="medium",
  title="jedi-notification-center REST 層：收件匣八條端點（unread-count／inbox/list／inbox/recent／read／archive／batch／settings GET／settings PUT）、serializer、能力點清單、register() 掛 blueprint；0.1.0 內",
  ren="extend（P-1 的套件）：route 形狀照 jedi-bulletin `api/`（MethodResource＋marshmallow、守門 decorator 由 adapters 給、回應走 response_builder）；分頁照主系統 `docs/claude/api-patterns.md`（POST list 帶 page／page_size、EnvelopeSchema）；settings GET 回 23 列＝型錄 left join 個人設定",
  edit=["jedi-notification-center/jedi_notification_center/plugin/assembly.py（create_blueprint）", "jedi-notification-center/jedi_notification_center/plugin/contract.py（CAPABILITIES 兩顆、mount_api）", "jedi-notification-center/jedi_notification_center/__init__.py"],
  new=["jedi-notification-center/jedi_notification_center/api/routes/inbox_routes.py", "jedi-notification-center/jedi_notification_center/api/routes/settings_routes.py", "jedi-notification-center/jedi_notification_center/api/serializers/", "jedi-notification-center/jedi_notification_center/app/service/inbox_service.py（list／recent／read／archive／batch；uid 不是本人的回 404 不分）", "jedi-notification-center/jedi_notification_center/app/service/settings_service.py（GET 合併預設；PUT 必收事件 inapp／email 與型錄不符回 412）", "jedi-notification-center/jedi_notification_center/common/error_code.py（NC_404001／NC_412001／NC_400001／NC_403001）", "jedi-notification-center/tests/test_api_*.py"],
  deps=["P-1"], why="端點契約要讓 FE 與主系統照它寫；守門四件無預設值的 register 行為要測",
  accept="套件 tests 綠（含：未帶 token 401 不是 500；別人的 uid 404；必收事件 PUT 關 email 回 412 NC_412001；batch read_all scope=category 只標該類）；harness 起來 curl 八條都回信封形狀；`notification.inbox.read` 在 CAPABILITIES"),
dict(id="M-1", phase="P1", stage=3, repo="main", model="opus", effort="high",
  title="主系統掛載 jedi-notification-center：core/plugins/notification_center.py（七張 port 實作＋register）、DI container、unread-count 的 todo 數接既有 task queue、錯誤碼檔與 FE error-code.json 四條",
  ren="照型 new：接線檔照 `core/plugins/bulletin.py`（build_adapters＋mount＋PLUGIN、`host_defaults()`）；port 實作 reuse：`IRecipientDirectory` 包 `core/plugins/license.py::TenantAdminDirectory`＋`UserDomainService.get_user_by_ids`＋`ProjectParticipantDomainService`；`ITemplateRenderer` 包 flask-babel `_()` 用型錄的 i18n key；`ILinkResolver` 讀型錄 `link_route`／`link_params_template` 做字串替換；`IDeliveryGateway` 包 `app/notification/service/notification_service.py` 的 `send_mail_notification`／discord／telegram；`IRealtimeNotifier` no-op；`IClock` 既有 now_provider；todo 數 reuse `/flow-engine/task/queue` 背後的 query",
  edit=["core/plugins/__init__.py（PLUGINS 加一列）", "di_containers/containers.py（加 notification_center_container）", "config/app_modules.py（若套件 blueprint 要登記則加；照 bulletin 的做法）"],
  new=["core/plugins/notification_center.py", "core/plugins/_notification_center_ports.py（七張 port 實作，每張一個 class，檔不超 400 行）", "di_containers/notification_center/notification_center_containers.py", "common/code/notification_center_error_code.py（re-export 套件的四顆，字串值凍結）", "test/test_notification_center_mount.py（register 守門四件缺一拒掛；port 實作對 DEV 查得到管理員）"],
  deps=["P-1", "P-2", "S-1"], why="跨層：port 實作橫跨 iam／license／flow_engine／notification 四個模組；DI 簽章漂移是靜默的，驗收要實打端點",
  accept="重啟 BE 後 `curl -H 'Authorization: Bearer <token>' /api/1.0/notification-center/unread-count` 回 `{status:true,data:{unread:0,todo:N}}`（N 與鈴鐺現在的待辦數相同）；`GET /settings` 回 23 列；DEV 用 cmmgr 手插一列 inbox 給自己後 `unread`＝1、`inbox/recent` 看得到、PATCH read 後 `unread`＝0；`cm_app` 身分 SELECT inbox 只看到自己租戶；FE `src/config/locales/i18n/{zh-tw,en}/error-code.json` 多四條（🔴 本卡是 error-code.json 的 owner，F-3 不碰）"),
dict(id="F-3", phase="P1", stage=3, repo="fe", model="sonnet", effort="medium",
  title="FE 登記型檔 owner：api.js 常數、路由 /notification 與 /user/notification-settings（後者先指佔位頁）、menu.json 中英文、notification-center.json 中英文（含 23 個事件名與 5 個類別名）、使用者選單加「通知設定」項；🔴 本期唯一能動這五個檔的卡",
  ren="extend：照既有登記形狀各加項；佔位頁是一個只有標題的 Vue（第二期 F-4 換成真頁）；i18n 23 個事件名對 S-1 的 title_key",
  edit=["src/config/api/api.js（NOTIFICATION_CENTER_UNREAD_COUNT／INBOX_LIST／INBOX_RECENT／INBOX_ITEM／INBOX_BATCH／SETTINGS）", "src/config/router/index.js（兩條路由）", "src/config/locales/i18n/zh-tw/menu.json、en/menu.json（🔴 兩邊都補）", "src/layout/AppTopbar.vue（genUserMenu 加「通知設定」一項；不碰鈴鐺那段，F-1 碰）"],
  new=["src/config/locales/i18n/zh-tw/notification-center.json、en/notification-center.json", "src/views/user-manage/NotificationSettingsView.vue（佔位：標題＋「第二期」一行）"],
  deps=["S-1"], why="機械性登記；但 menu.json 漏英文是每次都漏的坑，驗收要兩邊都查",
  accept="`npm run build` 過、`npm run lint` 無新 error；`grep -c notification src/config/locales/i18n/en/menu.json` 與 zh-tw 相同；`/notification` 與 `/user/notification-settings` 兩條路由進得去（前者先空頁，F-2 填）；使用者選單看得到「通知設定」；23 個事件名 key 與 DEV `notification_events.title_key` 逐一對得上（回寫附對照）"),
dict(id="F-1", phase="P1", stage=4, repo="fe", model="opus", effort="medium",
  title="FE 鈴鐺元件 NotificationBell.vue 取代 AppTopbar 第 484～540 行與 TopbarStageQueue.vue：紅點＝unread、下拉最近十筆＋類別分段、全部標已讀、查看全部、通知設定、底部「我的待辦任務（todo）」；composable 每 60 秒輪詢",
  ren="new 一支元件取代舊段（AppTopbar 598 行已接近上限，鈴鐺整段抽出去）；reuse 既有 `v-styleclass` 下拉與 `v-badge`；分段用 SegmentButtons（small）；`useNotificationCenter.js` 輪詢照 `useUserUtil().getTaskQueue` 的呼叫方式；`TopbarStageQueue.vue` 退役刪檔",
  edit=["src/layout/AppTopbar.vue（第 484～540 行整段換成 `<NotificationBell/>`；`getStageQueue`、`stageQueue`、`messages` 相關程式刪）"],
  new=["src/layout/NotificationBell.vue", "src/composables/useNotificationCenter.js（unread／todo／recent；60 秒 setInterval，unmount 清）"],
  deps=["M-1", "F-3"], why="畫面可見的第一塊；要照雛形 index.html 結構、文案依 F-3 的 i18n；AppTopbar 超標只刪不加",
  accept="登入後鈴鐺紅點數＝`unread-count.unread`；DEV 手插一列後 60 秒內紅點變；點開看到那列（圖示、標題、來源、相對時間、未讀點）、類別分段切換有效；點「全部標為已讀」紅點歸零；最底一行「我的待辦任務（N）」N＝`todo`、點了到 my-tasks；`TopbarStageQueue.vue` 已刪且 grep 無引用；`grep -n 'border-left\\|font-size' src/layout/NotificationBell.vue` 為 0；文案全來自 notification-center.json"),
dict(id="F-2", phase="P1", stage=4, repo="fe", model="opus", effort="medium",
  title="FE 通知中心頁 NotificationInboxView.vue（路由 /notification）：未讀／全部／已封存分段、類別下拉、搜尋、今天／昨天／更早分組、每列前往／標已讀／封存、勾選批次",
  ren="new 頁面（照雛形 index.html 畫面 2 結構）；reuse `dark-card`、SegmentButtons（small）、IconField 搜尋、既有 DataTable 不用（分組清單用 list）；點「前往」用 `link.route`＋`link.params` 做 `router.push`，先 PATCH read",
  edit=[], new=["src/views/notification/NotificationInboxView.vue", "src/views/notification/InboxItemRow.vue（一列：圖示、標題、摘要、時間、動作；每列不超 150 行）"],
  deps=["M-1", "F-3"], why="畫面與資料形狀都定了；要守 UI 規範（上下疊、不自訂字級、禁左框）",
  accept="`/notification` 列出 DEV 手插的幾列並正確分組；切「未讀」只剩未讀；類別篩選有效；搜尋標題有效；單列「標已讀」後該列變灰、鈴鐺紅點同步少一（透過 composable）；勾兩列批次封存後切「已封存」看得到；點「前往」跳到 link 指的頁且回來那列已讀；`grep -rn 'border-left\\|font-size\\|max-width' src/views/notification/` 為 0；空清單顯示 i18n 的空狀態文案"),
dict(id="M-2", phase="P1", stage=4, repo="main", model="opus", effort="medium",
  title="主系統第一期四個事件接入 notify()：task.assigned（workflow_execution_service:1246）、stage.entered（stage_entered_notify_service:117）、scan.critical_found（scan_alert_app_service:74）、bulletin.published（core/plugins/bulletin.py add 之後）；既有 Email 照舊寄不動",
  ren="extend 四處：在既有寄信那段旁邊加一行 `notify(...)`（第一期不拔 Email，第二期才改成由中心決定）；收件人 reuse 各處已算好的清單（user_id 不是信箱——stage_entered 與 scan_alert 現在拿的是 email，要回頭用它們上游的 user 物件）；公告收件人展開走主系統側一支小 query（send_scope ALL＝租戶全員、ORG_UNIT＝橋表部門成員）放 `_notification_center_ports.py` 的 recipient directory",
  edit=["app/flow_engine/service/workflow_execution_service.py（1246 附近加一行；🔴 檔 1,321 行超標，只加呼叫、不加邏輯）", "app/flow_engine/service/stage_entered_notify_service.py（117 附近）", "app/task_alert/service/scan_alert_app_service.py（74 附近）", "core/plugins/bulletin.py（jedi-bulletin 沒有 after-add 掛點（已查，SchemaExtensions 只管 schema）：在主系統側用一個薄 wrapper 包 `bulletin_service.add_bulletin`，成功後呼叫 notify；wrapper 放新檔 `app/notification_center/service/bulletin_published_notifier.py`，接線檔只換 services provider 那一行）", "core/plugins/_notification_center_ports.py（recipient directory 加 bulletin_scope 展開）"],
  new=["test/test_notification_center_events.py（四個事件各一條：呼叫後 inbox 多列且 recipient 是 user_id）", "app/notification_center/service/bulletin_published_notifier.py", "app/notification_center/service/task_event_params.py（參數組裝，讓超標檔只加一行）"],
  deps=["M-1"], why="四處改一行但收件人從信箱改回 user_id 要追上游；公告包一層 wrapper 已定死做法，不留分岔",
  accept="DEV 實測：指派一張任務給自己 → inbox 多一列 event_code=task.assigned、recipient_user_id＝我、link 指到 my-tasks 帶 project／job／execution；流程進到我負責的站 → stage.entered 一列；掃描警示（可用既有手動觸發）→ scan.critical_found 一列且 mandatory=true；發一則公告（ALL）→ 租戶每人一列；既有信照常寄（看 `task_alert_notifications` 仍有新列）；四條測試綠；`wc -l` 四個被改檔的行數增加 ≤ 3 行"),
# ───────── 第二期 P2 全部事件改走中心、通知設定頁 ─────────
dict(id="P-3", phase="P2", stage=5, repo="jedi-packages", model="opus", effort="high",
  title="jedi-notification-center 外送層：Email／chat 由中心照設定決定寄不寄、立即或排進 outbound；outbound 走宿主 port（主系統接 FR-137 表）；摘要批次鍵與勿擾時段計算；settings PUT 真正生效",
  ren="extend（套件）：`notify()` 第一期只寫 inbox＋立即交 delivery；本卡在中間加「外送決策」：每位收件人每個管道查設定→必收強制→digest／quiet 算 `scheduled_at`→寫 `IOutboundStore` port（新第八張 port：`enqueue(inbox_id, channel, address, scheduled_at, digest_batch)`／`claim_due(now)`／`mark(id, result, error)`）；立即的當場交 delivery 並 mark",
  edit=["jedi-notification-center/jedi_notification_center/app/service/notify_service.py", "jedi-notification-center/jedi_notification_center/domain/ports.py（加 IOutboundStore）", "jedi-notification-center/jedi_notification_center/plugin/contract.py（adapters 加 outbound_store）"],
  new=["jedi-notification-center/jedi_notification_center/app/service/outbound_policy.py（digest／quiet 算時間，純函式）", "jedi-notification-center/jedi_notification_center/app/service/digest_sender.py（claim_due → 同 digest_batch 合成一封 → delivery → mark；供宿主排程呼叫）", "jedi-notification-center/tests/test_outbound_policy.py（daily 09:00、weekly 週一、quiet 22:00～08:00 跨午夜、必收事件 email 關不掉）"],
  deps=["P-2"], why="純套件邏輯，時間計算要測；外送存哪裡交宿主，套件不認識 FR-137 表",
  accept="套件 tests 綠（含：設定 email=False 的事件不進 outbound；必收仍進；daily 的 scheduled_at 是下一個 09:00；quiet 內的 email 推到 quiet_to；同人同批 digest_batch 相同）；`digest_sender.run(now)` 對假 store 合成一封含兩筆標題"),
dict(id="S-2", phase="P2", stage=5, repo="main", model="sonnet", effort="medium",
  title="主線 migration：compliance.task_alert_notifications 擴四欄（inbox_id／channel／scheduled_at／digest_batch）＋result 多 skipped；system_configs NOTIFICATION_CENTER 三個 key seed（inbox_retention_days 90／delivery_retention_days 180／agent_offline_minutes 15）；🔴 manifest owner（第二期）",
  ren="extend 既有表（設計 §5.2 表 5-5）：ALTER ADD COLUMN 四欄皆可 null、既有列不動；唯一索引 `uq_task_alert_notifications_scan_recipient` 保留；system_configs seed 照 FR-020 NOTIFY_CONFIG 的 group／key 形狀",
  edit=["scripts/sql/manifest.tsv（兩行）"],
  new=["scripts/sql/2026-11-13-fr196-task-alert-outbound-columns.sql", "scripts/sql/2026-11-13-fr196-seed-notification-center-configs.sql"],
  deps=["S-1"], why="資料類照先例；擴欄不破舊資料是鐵律（每版可直升）",
  accept="DEV 套過後 `\\d compliance.task_alert_notifications` 多四欄且皆 nullable；既有列數不變；`select count(*) from system_configs where \"group\"='NOTIFICATION_CENTER'`＝3（ROOT 租戶）；連跑兩次冪等；回寫「出貨基線待重產」"),
dict(id="F-4", phase="P2", stage=5, repo="fe", model="opus", effort="medium",
  title="FE 通知設定頁 NotificationSettingsView.vue 換成真頁：23 行分 5 組三個 InputSwitch、必收鎖＋Tag、Email 摘要分段、勿擾兩個時間、chat_available 提示、儲存",
  ren="extend F-3 的佔位頁（同檔換內容）；照雛形第三個分頁；分組標題只是文字不是開關；儲存打 `PUT /settings` 全表覆寫；412 時 toast 既有 error-code i18n",
  edit=["src/views/user-manage/NotificationSettingsView.vue（F-3 建的佔位）"],
  new=["src/views/user-manage/NotificationSettingRow.vue（一列三開關＋鎖）"],
  deps=["F-3", "M-1"], why="畫面與 API 都定了；要守 UI 規範",
  accept="頁面列 23 行、5 個分組標題、8 行帶鎖與「必收」Tag 且開關 disabled；關一個 Email 存檔後重整仍是關；摘要選每日後 profile 回 daily；chat 未設時那欄灰且下方提示；`grep -rn 'border-left\\|font-size' src/views/user-manage/NotificationSetting*` 為 0"),
dict(id="M-3", phase="P2", stage=6, repo="main", model="opus", effort="high",
  title="主系統外送接線：IOutboundStore 實作寫 FR-137 表（claim 去重沿用）、既有 Email 改由中心決定（移除第一期四處的「照舊寄」）、排程 core/scheduler_notification.py 三個 tick（摘要每小時、清理每日 03:00、Agent 離線每分鐘）",
  ren="extend：`_notification_center_ports.py` 加 `OutboundStore`（包 `task_alert_notification_domain_service.claim`／`mark`，address 用既有 `recipient_email`，新四欄一起寫）；第一期 M-2 加的四處 notify 旁邊的既有寄信呼叫拿掉（改由中心寄）；排程照 `core/scheduler_update.py` 形狀新檔；清理用 system_configs 的兩個天數，批次 delete 每批 5000",
  edit=["core/plugins/_notification_center_ports.py", "core/plugins/notification_center.py（adapters 加 outbound_store）", "core/app_factory.py（註冊 scheduler_notification，照 scheduler_update 那一行）", "app/flow_engine/service/workflow_execution_service.py（1246 附近：拿掉既有寄信，只留 notify）", "app/flow_engine/service/stage_entered_notify_service.py（同）", "app/task_alert/service/scan_alert_app_service.py（同）"],
  new=["core/scheduler_notification.py", "test/test_notification_center_scheduler.py（清理只刪已讀逾期；離線 tick 對 last_seen_at 超過分鐘數的 agent 發一次且不重發）"],
  deps=["P-3", "S-2", "M-2"], why="跨層：外送層、排程、三處既有寄信拔除；錯了症狀是信寄兩封或不寄",
  accept="DEV：指派任務給自己（Email 設定開）→ 收到一封且 `task_alert_notifications` 多一列帶 inbox_id／channel=email；關掉 Email 再指派 → 沒信、inbox 有；設 daily → 列的 scheduled_at 是明早 09:00；把 retention 設 1、造一筆兩天前已讀 → 跑 tick 消失、未讀不消失；停一台 Agent 容器 16 分鐘 → 管理員 inbox 多一列 agent.offline，再等一分鐘不重發；三條測試綠；BE 重啟無錯"),
dict(id="M-4", phase="P2", stage=7, repo="main", model="opus", effort="high",
  title="主系統其餘寄信點改接 notify()（第 5～14 處）：批次指派、到期提醒（排程與手動）、批次完成、專案啟動、支援到期、新版可更新、本機管理員登入、Agent 憑證到期；各處既有寄信拔除、收件人改 user_id；既有 notified_version／cert_expiry_notified_at 不再更新",
  ren="extend 十處各改一行＋拿掉既有寄信；收件人：PM／專案成員走 `Role('project_members', project_uid)`，管理員走 `Role('tenant_admin')`／`('platform_admin')`；到期提醒的 digest 改由中心的 daily 摘要承接（既有 `send_digest` 合信邏輯第二期起只被 OutboundStore 用）；Discord／Telegram 兩處改 chat 管道",
  edit=["app/flow_engine/service/workflow_execution_service.py（1183 批次）", "app/task_alert/service/job_due_reminder_service.py", "app/task_alert/service/manual_job_due_reminder_service.py（155）", "app/flow_control/service/job_batch_complete_service.py（221）", "app/flow_control/service/project_service.py（684、726）", "app/task_alert/service/support_end_reminder_service.py（73）", "app/product_update/service/product_update_flow.py（370；notified_version 不再寫）", "core/plugins/_agent_local_admin_notice.py", "core/scheduler_agent.py（cert expiry tick 改呼叫 notify；套件內的戳不動）"],
  new=["app/notification_center/service/event_params.py（十處參數組裝集中，超標檔只加一行）", "test/test_notification_center_events_p2.py（十個事件各一條）"],
  deps=["M-3"], why="十處散在六個模組，每處的收件人來源不同；拔既有寄信要確認沒有第二個呼叫端",
  accept="十個事件 DEV 各觸發一次（可用既有手動端點或排程 tick）→ inbox 各多一列、event_code 正確、必收的 mandatory=true；`task_alert_notifications` 新列都有 inbox_id；舊的 `triggered_by` 手動列照常；`grep -rn send_mail_notification app/ core/` 只剩 OTP、設密碼、測試信三處；十條測試綠"),
dict(id="M-5", phase="P2", stage=7, repo="main", model="opus", effort="medium",
  title="主系統今天沒有的事件補發（第二期）：關卡送審核可退回、輪次結束結案、結案報告產出、檢測任務完成、Agent 更新完成與失敗、密碼到期與帳號鎖定",
  ren="extend 各處加一行 notify：關卡在 `app/flow_control/service/review_step_service.py` 的送審／核可／退回三個 method；輪次結束在 `app/flow_engine/service/stage_advance_service.py` 結案分支；結案報告在 `app/project_summary_report` 匯出成功處；檢測完成在 `app/flow_control/service/job_service.py` 完成分支（檢測類任務）；Agent 更新結果在 `app/product_update/service/agent_rollout_service.py::record_result`；密碼到期與鎖定在 `common/iam_ports.py` 的 iam port adapter（主系統已在這裡實作 iam 的 INotifier，jedi-iam 不動）",
  edit=["app/flow_control/service/review_step_service.py", "app/flow_engine/service/stage_advance_service.py", "app/project_summary_report/service/（匯出 service）", "app/flow_control/service/job_service.py", "app/product_update/service/agent_rollout_service.py", "common/iam_ports.py"],
  new=["test/test_notification_center_events_gaps.py（六個事件各一條）"],
  deps=["M-3"], why="六處各在不同模組；密碼到期那處要確認 iam port 真的會被呼叫（jedi-iam INotifier 契約）",
  accept="DEV：送審一張任務 → 下一關的人 inbox 多一列 task.review_step；退回 → 原處理人一列；一輪結案 → 成員各一列 project.round_closed；匯出結案報告 → PM 一列；Agent 更新回報失敗 → 管理員一列 mandatory；密碼到期前 N 天登入 → 本人一列（走 iam 既有的到期判定）；六條測試綠"),
dict(id="M-6", phase="P2", stage=7, repo="main", model="sonnet", effort="low",
  title="退役第一期前的舊鈴鐺端點與查詢：GET /flow-engine/stage-notifications/mine、MyStageNotificationsQuery、MyStageNotificationsAppService、DI 登記；FE api.js 的 STAGE_NOTIFICATIONS_MINE 由 F-5 刪",
  ren="刪除（reuse 無）：路由、app service、query、DI 三處移除；`compliance.task_alert_notifications` 表不動",
  edit=["api/flow_engine/routes/flow_engine_route.py", "di_containers/containers.py（或對應 container）"],
  new=[], deps=["M-3"], why="機械性刪除；grep 無引用才刪",
  accept="`grep -rn stage-notifications\\|MyStageNotifications api app infra di_containers` 為 0；BE 起得來；既有 test 綠"),
dict(id="F-5", phase="P2", stage=8, repo="fe", model="sonnet", effort="low",
  title="FE 退役舊鈴鐺殘留：api.js 刪 STAGE_NOTIFICATIONS_MINE；i18n 刪 top_menu.stage_queue_tag／no_message 若無他處用；清掉 AppTopbar 殘留 import",
  ren="刪除；grep 無引用才刪",
  edit=["src/config/api/api.js", "src/config/locales/i18n/zh-tw/*.json、en/*.json（只刪確認無引用的鍵）", "src/layout/AppTopbar.vue（殘留 import）"],
  new=[], deps=["F-1", "M-6"], why="機械性",
  accept="`npm run build`、`lint` 過；`grep -rn STAGE_NOTIFICATIONS_MINE\\|stage_queue_tag src` 為 0"),
# ───────── 第三期 P3 即時、橫幅、合併 ─────────
dict(id="P-4", phase="P3", stage=8, repo="jedi-packages", model="opus", effort="medium",
  title="jedi-notification-center 合併：同收件人同 merge_key 在 merge_window_sec 內且未讀 → merged_count+1、更新 title（範本吃 {count}）與 created_at，不新增；Email 不合併；型錄 23 列中四個任務類事件 seed 設 300 秒（由 S-3 寫）",
  ren="extend `notify_service`：寫 inbox 前查一次；`ITemplateRenderer.render` 多收 `count`",
  edit=["jedi-notification-center/jedi_notification_center/app/service/notify_service.py", "jedi-notification-center/jedi_notification_center/infra/repository/inbox_repo_impl.py（find_mergeable）", "jedi-notification-center/jedi_notification_center/domain/ports.py（render 簽名加 count）"],
  new=["jedi-notification-center/tests/test_merge.py"],
  deps=["P-3"], why="套件邏輯＋一個 repo 查詢；視窗邊界要測",
  accept="tests：五分鐘內同任務兩次 assigned → 一列 merged_count=2；已讀後再來 → 新列；視窗外 → 新列；不同收件人各自一列"),
dict(id="P-5", phase="P3", stage=8, repo="jedi-packages", model="opus", effort="medium",
  title="jedi-notification-center 即時 namespace：realtime/handler.py 繼承 jedi-iam AuthenticatedNamespace，連線 join user:<id>；IRealtimeNotifier 的 SocketIO 實作 emit {event: unread_changed} 到該 room（只推訊號不推內容）",
  ren="照型 new：handler 照 jedi-survey `fill_survey_socketio_handler.py`（on_connect／join_room／emit）；套件只提供 handler 類與 notifier 實作，登記在宿主",
  edit=["jedi-notification-center/jedi_notification_center/plugin/contract.py（export handler 類名）"],
  new=["jedi-notification-center/jedi_notification_center/realtime/handler.py", "jedi-notification-center/jedi_notification_center/realtime/socketio_notifier.py", "jedi-notification-center/tests/test_realtime.py（notifier 對假 socketio emit 一次、payload 無內容）"],
  deps=["P-3"], why="資安邊界：頻道只有訊號；握手走 iam 驗證",
  accept="tests 綠；payload 只有 `{\"event\":\"unread_changed\"}`；handler 未帶 token 連線被 AuthenticatedNamespace 拒"),
dict(id="S-3", phase="P3", stage=8, repo="main", model="sonnet", effort="low",
  title="主線 seed：型錄四個任務類事件 merge_window_sec=300；notification_maintenance 表若 P-1 未建則補（P-1 已含則本卡只改型錄）；🔴 manifest owner（第三期）",
  ren="extend seed：UPDATE 四列；表已在 P-1 建則略",
  edit=["scripts/sql/manifest.tsv（一行）"], new=["scripts/sql/2026-11-14-fr196-seed-merge-window.sql"],
  deps=["S-2"], why="資料類",
  accept="DEV `select code from notification_events where merge_window_sec=300`＝4 列；冪等"),
dict(id="M-7", phase="P3", stage=9, repo="main", model="opus", effort="medium",
  title="主系統第三期接線：socketio_namespaces 登記 /socket/notification-center、IRealtimeNotifier 換 SocketIO 實作、POST /maintenance 與 GET /maintenance/current 兩條產品端 route＋能力點守門、Nuitka include 清單",
  ren="extend：`config/socketio_namespaces.py` 加一列（字串 import）；`_notification_center_ports.py` 的 RealtimeNotifier 換實作；新 route 照 `api/notify_config/routes/notify_config_route.py` 形狀；守門用 `common.authz` capability 軸；maintenance 寫表後 `notify(system.maintenance_scheduled, Role('tenant_all'))`",
  edit=["config/socketio_namespaces.py", "core/plugins/_notification_center_ports.py", "core/plugins/notification_center.py", "config/app_modules.py（新 blueprint 登記）"],
  new=["api/notification_center/__init__.py", "api/notification_center/routes/maintenance_route.py", "api/notification_center/serializers/maintenance.py", "app/notification_center/service/maintenance_app_service.py", "test/test_notification_center_maintenance.py（無能力點 403；建一筆後 current 回它；過期不回）"],
  deps=["P-4", "P-5", "S-3", "M-4"], why="跨層：socket 登記紅線（handler 建構要晚於 DI wiring）、新 blueprint、能力點守門",
  accept="`RUN_MODE=socketio python main.py` 起得來且 `scripts/build/socketio_probe.py` 改連新 namespace 通；兩個瀏覽器：A 指派給 B，B 三秒內紅點變（不重整）；`POST /maintenance` 無能力點 403、有則 200 且全租戶 inbox 各一列；`GET /maintenance/current` 回該筆；三條測試綠"),
dict(id="F-6", phase="P3", stage=10, repo="fe", model="opus", effort="medium",
  title="FE 第三期：composable 改訂 SocketIO unread_changed 後再拉（輪詢降為 5 分鐘備援）；兩支橫幅 UpdateAvailableBanner（讀 product-update status，只平台管理員）與 MaintenanceBanner（讀 /maintenance/current）掛進 AppLayout 第 124 行那排；系統設定「排定維護」小表單；鈴鐺列顯示 merged_count",
  ren="extend `useNotificationCenter.js`（socket 照 `useSurveySocket.js` 的 io 用法）；兩支橫幅照 `AiQuotaBanner.vue`（`hint-bar`、關閉記 sessionStorage）；表單照 `notify-config/NotifyConfigForm.vue` 形狀放系統設定；api.js／menu.json／i18n 新鍵本卡自己加（第三期 FE 只有本卡，無撞）",
  edit=["src/composables/useNotificationCenter.js", "src/layout/AppLayout.vue（第 124 行那排加兩行）", "src/layout/NotificationBell.vue（merged_count 顯示「有 N 項更新」）", "src/config/api/api.js", "src/config/router/index.js", "src/config/locales/i18n/zh-tw/menu.json、en/menu.json", "src/config/locales/i18n/zh-tw/notification-center.json、en/notification-center.json"],
  new=["src/components/product-update/UpdateAvailableBanner.vue", "src/components/system/MaintenanceBanner.vue", "src/views/system-config/MaintenanceScheduleForm.vue"],
  deps=["F-4", "F-5", "M-7"], why="socket 重連與多分頁要處理；橫幅照既有形狀；menu.json 中英文",
  accept="兩個瀏覽器 A 指派給 B，B 不重整三秒內紅點變；斷網 10 秒再連回，紅點仍正確（備援輪詢）；平台管理員登入看到新版橫幅、一般使用者看不到；管理員建一筆明天的維護 → 全員頂部橫幅、關閉後重整不再出現但收件匣有；鈴鐺一列顯示「有 2 項更新」；`grep -rn border-left src/components/product-update src/components/system` 為 0；menu.json 中英文都有"),
]

if __name__ == "__main__":
    import collections
    by = collections.defaultdict(list)
    for c in CARDS: by[c["stage"]].append(c)
    ids = {c["id"] for c in CARDS}
    for c in CARDS:
        for d in c["deps"]:
            assert d in ids, (c["id"], d)
            dep = next(x for x in CARDS if x["id"]==d)
            assert dep["stage"] < c["stage"], f"{c['id']} (stage {c['stage']}) depends on {d} (stage {dep['stage']})"
    clash = 0
    for st, cs in sorted(by.items()):
        seen = {}
        for c in cs:
            for f in c["edit"]:
                key = (c["repo"], f.split(" ")[0].split("（")[0])
                if key in seen: print(f"⚠ 批 {st}: {c['id']} 與 {seen[key]} 都改 {key}"); clash += 1
                seen[key] = c["id"]
    print("cards", len(CARDS), "stages", len(by), "clashes", clash)
    for st, cs in sorted(by.items()): print(f"批 {st}: " + ", ".join(f"{c['id']}({c['repo']})" for c in cs))
