新增市場情報 report closeout gate
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
================================================================================
|
||||
|
||||
【已完成】
|
||||
- V10.332 補市場情報 candidate queue review AI summary Telegram dispatch report closeout:新增 read-only report closeout builder、POST endpoint、UI 按鈕與 deployment readiness smoke target,在 report run receipt 後審核 closeout artifact、receipt/report artifact path、hash/章節覆核、後續 report archive separate gate 與 runtime boundary;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補產報表、不派送 Telegram、不開 DB、不寫檔、不更新 review_state、不掛 scheduler。
|
||||
- V10.331 強化 PChome 比價 matcher 邊界:正式端 pilot 先刷新 30 筆過期 identity_v2、補抓 15 筆高價未配對 SKU,確認 structured diagnostics 開始寫入;針對「同品牌、同核心多組件、無任何否決理由、價格正常」但因規格文字不完整卡在 0.74x 的候選,新增 strong_component_line_match 窄門補分,避免 Gennies 類完整套組被誤留在低信心,同時維持雙入組對單品、容量衝突、不同品牌與補充瓶硬否決。
|
||||
- V10.330 補市場情報 candidate queue review AI summary Telegram dispatch report run receipt:新增 read-only report run receipt builder、POST endpoint、UI 按鈕與 deployment readiness smoke target,在 report run readiness 後審核人工/獨立 job 產出的 report receipt、artifact path/hash、必要章節、summary hash 與 runtime boundary;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補產報表、不派送 Telegram、不開 DB、不寫檔、不更新 review_state、不掛 scheduler。
|
||||
- V10.329 優化 `/growth_analysis` 冷快取策略:source fingerprint 未變時,成長分析共享快取由 30 分鐘延長為 6 小時有效;每日匯入仍會主動清除快取,避免資料更新後沿用舊圖表,同時降低正式端重啟或冷 worker 重新掃 `realtime_sales_monthly` 的 14 秒級等待。
|
||||
|
||||
@@ -320,7 +320,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
|
||||
# ==========================================
|
||||
# 系統版本與路徑
|
||||
# ==========================================
|
||||
SYSTEM_VERSION = "V10.331"
|
||||
SYSTEM_VERSION = "V10.332"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -226,6 +226,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch report run package:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package`、`routes.market_intel_review_report_routes` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package` 在 report input 通過後整理 run package contract、evidence refs、package sections 與後續 report run readiness gate。此 run package 只準備報表執行審核包;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不產報表、不更新 `review_state`、不 commit、不掛 scheduler,真正報表產製必須另開 readiness gate。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch report run readiness:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_readiness`、`routes.market_intel_review_report_routes` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_readiness` 在 report run package 通過後整理 report generation readiness manifest、manual report command boundary、artifact path gate 與後續 report run receipt gate。此 run readiness 只檢查可否進入後續人工/獨立 job 報表產製;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不產報表、不更新 `review_state`、不 commit、不掛 scheduler,真正產出結果必須另開 receipt gate。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch report run receipt:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt`、`routes.market_intel_review_report_routes` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt` 在 report run readiness 通過後審核人工/獨立 job 產出的 report receipt、report artifact path/hash、必要章節、summary hash 與 runtime boundary。此 receipt 只允許放行到後續 market intel report closeout;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補產報表、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch report closeout:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout`、`routes.market_intel_review_report_routes` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout` 在 report run receipt 通過後審核 closeout artifact、receipt/report artifact path、hash 與章節覆核、archive separate gate 與 runtime boundary。此 closeout 只允許放行到後續 market intel report archive;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補產報表、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler,後續 report archive 必須另開 gate。
|
||||
|
||||
### Phase 4:Coupang / Shopee Adapter
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
| `edm_routes.py` | EDM 與節慶儀表板 | `/edm`, `/festival` |
|
||||
| `monthly_routes.py` | 月結分析 | `/monthly_summary_analysis`, `/api/monthly_summary_data` |
|
||||
| `daily_sales_routes.py` | 當日業績 | `/daily_sales`, `/daily_sales/export*` |
|
||||
| `market_intel_routes.py` | 市場情報 Phase 100 主路由與基礎 preview API | `/market_intel`, `/market_intel/*`, `/api/market_intel/status`, `/api/market_intel/schema`, `/api/market_intel/schema_smoke`, `/api/market_intel/schema_db_probe`, `/api/market_intel/platform_seed_db_diff`, `/api/market_intel/legacy_source_bridge`, `/api/market_intel/mcp_readiness`, `/api/market_intel/mcp_tool_contract`, `/api/market_intel/mcp_deploy_preflight`, `/api/market_intel/mcp_activation_runbook`, `/api/market_intel/mcp_fetch_gate`, `/api/market_intel/scheduler_plan`, `/api/market_intel/manual_sample_plan`, `/api/market_intel/manual_sample_acceptance`, `/api/market_intel/manual_sample_review`, `/api/market_intel/manual_sample_review/evaluate`, `/api/market_intel/manual_sample_review/candidate_handoff`, `/api/market_intel/manual_sample_review/candidate_queue_draft`, `/api/market_intel/manual_sample_review/candidate_queue_approval`, `/api/market_intel/manual_sample_review/candidate_queue_transaction`, `/api/market_intel/manual_sample_review/candidate_queue_writer_status`, `/api/market_intel/manual_sample_review/candidate_queue_writer_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_writer_postwrite_smoke`, `/api/market_intel/manual_sample_review/candidate_queue_writer_operator_drill`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_closeout`, `/api/market_intel/manual_sample_review/candidate_queue_review_handoff`, `/api/market_intel/match_review_plan`, `/api/market_intel/opportunity_plan`, `/api/market_intel/opportunity_scoring_plan`, `/api/market_intel/opportunity_evidence_plan`, `/api/market_intel/opportunity_alert_plan`, `/api/market_intel/adapters`, `/api/market_intel/dry_run_plan`, `/api/market_intel/discovery_plan`, `/api/market_intel/manual_discovery`, `/api/market_intel/candidate_preview`, `/api/market_intel/platform_seed_plan`, `/api/market_intel/platform_seed_write_guard`, `/api/market_intel/platform_seed_writer_plan`, `/api/market_intel/migration_blueprint`, `/api/market_intel/migration_apply_drill`, `/api/market_intel/migration_catalog_review`, `/api/market_intel/migration_live_smoke`, `/api/market_intel/live_db_inventory`, `/api/market_intel/seed_writer_cli_status`, `/api/market_intel/write_approval_runbook`, `/api/market_intel/deployment_readiness` |
|
||||
| `market_intel_routes.py` | 市場情報 Phase 101 主路由與基礎 preview API | `/market_intel`, `/market_intel/*`, `/api/market_intel/status`, `/api/market_intel/schema`, `/api/market_intel/schema_smoke`, `/api/market_intel/schema_db_probe`, `/api/market_intel/platform_seed_db_diff`, `/api/market_intel/legacy_source_bridge`, `/api/market_intel/mcp_readiness`, `/api/market_intel/mcp_tool_contract`, `/api/market_intel/mcp_deploy_preflight`, `/api/market_intel/mcp_activation_runbook`, `/api/market_intel/mcp_fetch_gate`, `/api/market_intel/scheduler_plan`, `/api/market_intel/manual_sample_plan`, `/api/market_intel/manual_sample_acceptance`, `/api/market_intel/manual_sample_review`, `/api/market_intel/manual_sample_review/evaluate`, `/api/market_intel/manual_sample_review/candidate_handoff`, `/api/market_intel/manual_sample_review/candidate_queue_draft`, `/api/market_intel/manual_sample_review/candidate_queue_approval`, `/api/market_intel/manual_sample_review/candidate_queue_transaction`, `/api/market_intel/manual_sample_review/candidate_queue_writer_status`, `/api/market_intel/manual_sample_review/candidate_queue_writer_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_writer_postwrite_smoke`, `/api/market_intel/manual_sample_review/candidate_queue_writer_operator_drill`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_writer_run_closeout`, `/api/market_intel/manual_sample_review/candidate_queue_review_handoff`, `/api/market_intel/match_review_plan`, `/api/market_intel/opportunity_plan`, `/api/market_intel/opportunity_scoring_plan`, `/api/market_intel/opportunity_evidence_plan`, `/api/market_intel/opportunity_alert_plan`, `/api/market_intel/adapters`, `/api/market_intel/dry_run_plan`, `/api/market_intel/discovery_plan`, `/api/market_intel/manual_discovery`, `/api/market_intel/candidate_preview`, `/api/market_intel/platform_seed_plan`, `/api/market_intel/platform_seed_write_guard`, `/api/market_intel/platform_seed_writer_plan`, `/api/market_intel/migration_blueprint`, `/api/market_intel/migration_apply_drill`, `/api/market_intel/migration_catalog_review`, `/api/market_intel/migration_live_smoke`, `/api/market_intel/live_db_inventory`, `/api/market_intel/seed_writer_cli_status`, `/api/market_intel/write_approval_runbook`, `/api/market_intel/deployment_readiness` |
|
||||
| `market_intel_review_routes.py` | 市場情報人工 queue review 只讀延伸 API | `/api/market_intel/manual_sample_review/candidate_queue_review_inventory`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_approval`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_transaction`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_status`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_postwrite_smoke`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_operator_drill`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_run_closeout` |
|
||||
| `market_intel_review_post_routes.py` | 市場情報 review_state closeout 後只讀延伸 API(掛在 `market_intel_review_bp`) | `/api/market_intel/manual_sample_review/candidate_queue_review_decision_post_closeout_inventory`, `/api/market_intel/manual_sample_review/candidate_queue_review_completion_archive`, `/api/market_intel/manual_sample_review/candidate_queue_review_archive_summary`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_output_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_transaction`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_writer_preflight`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_run_package` |
|
||||
| `market_intel_review_post_ai_routes.py` | 市場情報 AI summary persistence / Telegram dispatch 後續只讀延伸 API(掛在 `market_intel_review_bp`) | `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_run_closeout`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_gate`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary` |
|
||||
| `market_intel_review_report_routes.py` | 市場情報 report input / report run package / report run readiness / report run receipt 後續只讀延伸 API(掛在 `market_intel_review_bp`) | `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_input`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt` |
|
||||
| `market_intel_review_report_routes.py` | 市場情報 report input / report run package / report run readiness / report run receipt / report closeout 後續只讀延伸 API(掛在 `market_intel_review_bp`) | `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_input`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_readiness`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt`, `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout` |
|
||||
| `api_routes.py` | 通用任務與查詢 API | `/api/run_task`, `/api/history/*` |
|
||||
| `export_routes.py` | 匯出功能 | `/api/export/*` |
|
||||
| `import_routes.py` | 匯入功能 | `/api/import_excel`, `/api/import/monthly_summary` |
|
||||
|
||||
@@ -16,6 +16,9 @@ from services.market_intel.candidate_queue_review_ai_summary_persistence_telegra
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_input import (
|
||||
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_input,
|
||||
)
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout import (
|
||||
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout,
|
||||
)
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package import (
|
||||
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package,
|
||||
)
|
||||
@@ -172,6 +175,43 @@ def _extract_report_run_receipt_payload(sample_result, operator_evidence):
|
||||
)
|
||||
|
||||
|
||||
def _build_ai_summary_persistence_telegram_dispatch_report_run_receipt(
|
||||
*,
|
||||
service,
|
||||
sample_result,
|
||||
operator_evidence,
|
||||
writer_output,
|
||||
smoke_result,
|
||||
payload_error,
|
||||
limit,
|
||||
execute_requested,
|
||||
apply_real_write,
|
||||
):
|
||||
report_run_readiness = (
|
||||
_build_ai_summary_persistence_telegram_dispatch_report_run_readiness(
|
||||
service=service,
|
||||
sample_result=sample_result,
|
||||
operator_evidence=operator_evidence,
|
||||
writer_output=writer_output,
|
||||
smoke_result=smoke_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
)
|
||||
return build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt(
|
||||
telegram_dispatch_report_run_readiness=report_run_readiness,
|
||||
report_run_receipt=_extract_report_run_receipt_payload(
|
||||
sample_result,
|
||||
operator_evidence,
|
||||
),
|
||||
operator_evidence=operator_evidence,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
|
||||
|
||||
@market_intel_review_bp.route(
|
||||
"/api/market_intel/manual_sample_review/"
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_input",
|
||||
@@ -281,25 +321,47 @@ def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_tel
|
||||
sample_result, operator_evidence, writer_output, smoke_result, payload_error, limit = (
|
||||
_extract_run_payload()
|
||||
)
|
||||
report_run_readiness = (
|
||||
_build_ai_summary_persistence_telegram_dispatch_report_run_readiness(
|
||||
service=service,
|
||||
sample_result=sample_result,
|
||||
operator_evidence=operator_evidence,
|
||||
writer_output=writer_output,
|
||||
smoke_result=smoke_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
data = _build_ai_summary_persistence_telegram_dispatch_report_run_receipt(
|
||||
service=service,
|
||||
sample_result=sample_result,
|
||||
operator_evidence=operator_evidence,
|
||||
writer_output=writer_output,
|
||||
smoke_result=smoke_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
data = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt(
|
||||
telegram_dispatch_report_run_readiness=report_run_readiness,
|
||||
report_run_receipt=_extract_report_run_receipt_payload(
|
||||
sample_result,
|
||||
operator_evidence,
|
||||
),
|
||||
data["phase"] = service.phase
|
||||
return jsonify(data), 400 if payload_error else 200
|
||||
|
||||
|
||||
@market_intel_review_bp.route(
|
||||
"/api/market_intel/manual_sample_review/"
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout",
|
||||
methods=["POST"],
|
||||
)
|
||||
@login_required
|
||||
def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout():
|
||||
service = MarketIntelService()
|
||||
execute_requested = request.args.get("execute", "false").lower() == "true"
|
||||
apply_real_write = request.args.get("apply_real_write", "false").lower() == "true"
|
||||
sample_result, operator_evidence, writer_output, smoke_result, payload_error, limit = (
|
||||
_extract_run_payload()
|
||||
)
|
||||
report_run_receipt = _build_ai_summary_persistence_telegram_dispatch_report_run_receipt(
|
||||
service=service,
|
||||
sample_result=sample_result,
|
||||
operator_evidence=operator_evidence,
|
||||
writer_output=writer_output,
|
||||
smoke_result=smoke_result,
|
||||
payload_error=payload_error,
|
||||
limit=limit,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
data = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout(
|
||||
telegram_dispatch_report_run_receipt=report_run_receipt,
|
||||
operator_evidence=operator_evidence,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
|
||||
@@ -0,0 +1,481 @@
|
||||
"""候選審核 queue AI summary Telegram dispatch report closeout preview。
|
||||
|
||||
本模組只在 report run receipt 通過後整理 report closeout gate;不讀 approval
|
||||
或 Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、
|
||||
不更新 review_state、不掛 scheduler。
|
||||
"""
|
||||
|
||||
|
||||
FORBIDDEN_TOKEN_KEYWORDS = (
|
||||
"approval_token",
|
||||
"approval-token",
|
||||
"market_intel_queue_write_approval",
|
||||
"telegram_bot_token",
|
||||
"telegram-token",
|
||||
"telegram_token",
|
||||
"bot_token",
|
||||
)
|
||||
SAFE_TOKEN_METADATA_KEYS = {
|
||||
"approval_token_present",
|
||||
"approval_token_valid",
|
||||
"approval_token_secret_configured",
|
||||
"telegram_token_present",
|
||||
"telegram_token_configured",
|
||||
}
|
||||
SAFE_APPROVAL_ENV_VAR = "MARKET_INTEL_QUEUE_WRITE_APPROVAL"
|
||||
REQUIRED_RECEIPT_BOUNDARIES = {
|
||||
"do_not_read_approval_token_from_report_run_receipt_api",
|
||||
"do_not_read_telegram_token_from_report_run_receipt_api",
|
||||
"do_not_call_llm_from_report_run_receipt",
|
||||
"do_not_generate_report_from_report_run_receipt_api",
|
||||
"do_not_write_report_artifact_from_report_run_receipt_api",
|
||||
"do_not_dispatch_telegram_from_report_run_receipt_api",
|
||||
"do_not_open_database_connection_from_report_run_receipt",
|
||||
"do_not_update_review_state_from_report_run_receipt",
|
||||
"do_not_attach_scheduler_from_report_run_receipt",
|
||||
}
|
||||
TARGET_TABLE = "market_alert_review_queue"
|
||||
TARGET_COLUMN = "metadata_json"
|
||||
SUMMARY_METADATA_KEY = "ai_summary_review"
|
||||
FALSE_RESPONSE_KEYS = (
|
||||
"ready_for_report_generation",
|
||||
"ready_for_manual_report_generation",
|
||||
"ready_for_ai_summary_generation",
|
||||
"ready_for_llm_call",
|
||||
"ready_for_telegram_dispatch",
|
||||
"ready_for_manual_telegram_dispatch",
|
||||
"ready_for_api_database_write",
|
||||
"ready_for_scheduler_attach",
|
||||
"ready_for_real_write",
|
||||
"api_executes_cli",
|
||||
"api_executes_llm",
|
||||
"api_dispatches_telegram",
|
||||
"api_reads_approval_token",
|
||||
"api_writes_file",
|
||||
"api_writes_database",
|
||||
"api_updates_review_state",
|
||||
"telegram_dispatch_report_closeout_file_written",
|
||||
"report_closeout_file_written",
|
||||
"closeout_file_written",
|
||||
"report_run_receipt_file_written",
|
||||
"report_receipt_file_written",
|
||||
"report_output_file_written",
|
||||
"report_file_written",
|
||||
"report_record_written",
|
||||
"report_manifest_written",
|
||||
"archive_file_written",
|
||||
"archive_record_written",
|
||||
"archive_manifest_written",
|
||||
"summary_file_written",
|
||||
"summary_record_written",
|
||||
"summary_manifest_written",
|
||||
"summary_persistence_record_written",
|
||||
"metadata_patch_written",
|
||||
"ai_summary_generated",
|
||||
"llm_call_executed",
|
||||
"ollama_call_executed",
|
||||
"gemini_call_executed",
|
||||
"telegram_dispatched",
|
||||
"telegram_dispatch_attempted",
|
||||
"review_state_update_executed",
|
||||
"read_only_query_executed",
|
||||
"database_connection_opened",
|
||||
"database_session_created",
|
||||
"explicit_transaction_opened",
|
||||
"transaction_opened",
|
||||
"transaction_committed",
|
||||
"database_write_executed",
|
||||
"database_commit_executed",
|
||||
"database_rollback_executed",
|
||||
"external_network_executed",
|
||||
"scheduler_attached",
|
||||
"writes_executed",
|
||||
"would_write_database",
|
||||
)
|
||||
|
||||
|
||||
def _as_dict(value):
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
def _as_list(value):
|
||||
if value is None:
|
||||
return []
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return list(value)
|
||||
return [value]
|
||||
|
||||
|
||||
def _safe_int(value):
|
||||
try:
|
||||
return int(value or 0)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def _safe_text(value, limit=300):
|
||||
if value is None:
|
||||
return None
|
||||
text = str(value).strip()
|
||||
return text[:limit] if text else None
|
||||
|
||||
|
||||
def _has_text(value):
|
||||
return bool(isinstance(value, str) and value.strip())
|
||||
|
||||
|
||||
def _contains_forbidden_token_key(value):
|
||||
if isinstance(value, dict):
|
||||
for key, nested in value.items():
|
||||
normalized_key = str(key).lower()
|
||||
if normalized_key in SAFE_TOKEN_METADATA_KEYS and isinstance(nested, bool):
|
||||
continue
|
||||
if normalized_key == "approval_env_var" and nested == SAFE_APPROVAL_ENV_VAR:
|
||||
continue
|
||||
if any(token_key in normalized_key for token_key in FORBIDDEN_TOKEN_KEYWORDS):
|
||||
return True
|
||||
if _contains_forbidden_token_key(nested):
|
||||
return True
|
||||
elif isinstance(value, list):
|
||||
return any(_contains_forbidden_token_key(item) for item in value)
|
||||
return False
|
||||
|
||||
|
||||
def _receipt_summary(report_run_receipt):
|
||||
receipt_payload = _as_dict(report_run_receipt)
|
||||
report_receipt = _as_dict(
|
||||
receipt_payload.get("telegram_dispatch_report_run_receipt_summary")
|
||||
)
|
||||
readiness = _as_dict(
|
||||
receipt_payload.get("telegram_dispatch_report_run_readiness_summary")
|
||||
)
|
||||
safe_boundaries = set(
|
||||
str(item) for item in _as_list(receipt_payload.get("safe_boundaries"))
|
||||
)
|
||||
missing_boundaries = sorted(REQUIRED_RECEIPT_BOUNDARIES - safe_boundaries)
|
||||
|
||||
return {
|
||||
"provided": bool(receipt_payload),
|
||||
"mode": receipt_payload.get("mode"),
|
||||
"target_operation": receipt_payload.get("target_operation"),
|
||||
"receipt_passed": bool(
|
||||
receipt_payload.get("telegram_dispatch_report_run_receipt_passed")
|
||||
or receipt_payload.get(
|
||||
"summary_persistence_telegram_dispatch_report_run_receipt_passed"
|
||||
)
|
||||
or receipt_payload.get("report_run_receipt_passed")
|
||||
),
|
||||
"ready_for_market_intel_report_closeout": bool(
|
||||
receipt_payload.get("ready_for_market_intel_report_closeout")
|
||||
),
|
||||
"ready_for_next_manual_phase": bool(
|
||||
receipt_payload.get("ready_for_next_manual_phase")
|
||||
),
|
||||
"statement_count": _safe_int(receipt_payload.get("statement_count")),
|
||||
"expected_summary_payload_hash": _safe_text(
|
||||
receipt_payload.get("expected_summary_payload_hash")
|
||||
or report_receipt.get("expected_summary_payload_hash"),
|
||||
80,
|
||||
),
|
||||
"readiness_mode": readiness.get("mode"),
|
||||
"readiness_ready": bool(
|
||||
readiness.get("telegram_dispatch_report_run_readiness_ready")
|
||||
and readiness.get("ready_for_market_intel_report_run_receipt")
|
||||
),
|
||||
"readiness_manifest_version": readiness.get("manifest_version"),
|
||||
"target_report_family": report_receipt.get("target_report_family"),
|
||||
"language": report_receipt.get("language"),
|
||||
"report_receipt_provided": bool(report_receipt.get("provided")),
|
||||
"report_receipt_mode": report_receipt.get("mode"),
|
||||
"report_generated": bool(report_receipt.get("report_generated")),
|
||||
"report_output_artifact_path": report_receipt.get(
|
||||
"report_output_artifact_path"
|
||||
),
|
||||
"report_output_hash": report_receipt.get("report_output_hash"),
|
||||
"summary_payload_hash": report_receipt.get("summary_payload_hash"),
|
||||
"summary_payload_hash_matches_expected": bool(
|
||||
report_receipt.get("summary_payload_hash_matches_expected")
|
||||
),
|
||||
"required_report_sections_present": bool(
|
||||
report_receipt.get("required_report_sections_present")
|
||||
),
|
||||
"section_keys": _as_list(report_receipt.get("section_keys")),
|
||||
"approval_or_telegram_token_key_detected": bool(
|
||||
report_receipt.get("approval_or_telegram_token_key_detected")
|
||||
),
|
||||
"safe_boundaries_complete": not missing_boundaries,
|
||||
"missing_safe_boundaries": missing_boundaries,
|
||||
"blocked_count": len(_as_list(receipt_payload.get("blocked_reasons"))),
|
||||
**{key: bool(receipt_payload.get(key)) for key in FALSE_RESPONSE_KEYS},
|
||||
}
|
||||
|
||||
|
||||
def _operator_closeout_summary(operator_evidence):
|
||||
operator_evidence = _as_dict(operator_evidence)
|
||||
return {
|
||||
"provided_keys": sorted(operator_evidence.keys()),
|
||||
"report_closeout_artifact_path_recorded": _has_text(
|
||||
operator_evidence.get("report_closeout_artifact_path")
|
||||
or operator_evidence.get(
|
||||
"telegram_dispatch_report_closeout_artifact_path"
|
||||
)
|
||||
or operator_evidence.get("market_intel_report_closeout_artifact_path")
|
||||
),
|
||||
"report_run_receipt_artifact_path_recorded": _has_text(
|
||||
operator_evidence.get("report_run_receipt_artifact_path")
|
||||
or operator_evidence.get(
|
||||
"telegram_dispatch_report_run_receipt_artifact_path"
|
||||
)
|
||||
),
|
||||
"report_output_artifact_path_recorded": _has_text(
|
||||
operator_evidence.get("report_output_artifact_path")
|
||||
or operator_evidence.get("telegram_dispatch_report_output_artifact_path")
|
||||
),
|
||||
"operator_confirmed_report_closeout": bool(
|
||||
operator_evidence.get("operator_confirmed_report_closeout")
|
||||
or operator_evidence.get(
|
||||
"operator_confirmed_market_intel_report_closeout"
|
||||
)
|
||||
),
|
||||
"operator_confirmed_report_receipt_archived": bool(
|
||||
operator_evidence.get("operator_confirmed_report_receipt_archived")
|
||||
or operator_evidence.get("operator_confirmed_receipt_archived")
|
||||
),
|
||||
"operator_confirmed_report_output_hash_matched": bool(
|
||||
operator_evidence.get("operator_confirmed_report_output_hash_matched")
|
||||
or operator_evidence.get("operator_confirmed_summary_hash_matched")
|
||||
),
|
||||
"operator_confirmed_report_sections_reviewed": bool(
|
||||
operator_evidence.get("operator_confirmed_report_sections_reviewed")
|
||||
),
|
||||
"operator_confirmed_report_archive_requires_separate_gate": bool(
|
||||
operator_evidence.get(
|
||||
"operator_confirmed_report_archive_requires_separate_gate"
|
||||
)
|
||||
),
|
||||
"operator_confirmed_no_token_in_report_closeout": bool(
|
||||
operator_evidence.get("operator_confirmed_no_token_in_report_closeout")
|
||||
or operator_evidence.get("operator_confirmed_no_token_in_artifacts")
|
||||
),
|
||||
"operator_confirmed_no_api_report_generation": bool(
|
||||
operator_evidence.get("operator_confirmed_no_api_report_generation")
|
||||
or operator_evidence.get("operator_confirmed_no_api_report_write")
|
||||
),
|
||||
"operator_confirmed_no_api_telegram_dispatch": bool(
|
||||
operator_evidence.get("operator_confirmed_no_api_telegram_dispatch")
|
||||
),
|
||||
"operator_confirmed_no_api_db_write": bool(
|
||||
operator_evidence.get("operator_confirmed_no_api_db_write")
|
||||
),
|
||||
"operator_confirmed_no_llm_call": bool(
|
||||
operator_evidence.get("operator_confirmed_no_llm_call")
|
||||
),
|
||||
"operator_confirmed_no_scheduler_attach": bool(
|
||||
operator_evidence.get("operator_confirmed_no_scheduler_attach")
|
||||
),
|
||||
"closeout_notes_recorded": _has_text(
|
||||
operator_evidence.get("report_closeout_notes")
|
||||
or operator_evidence.get("closeout_notes")
|
||||
),
|
||||
"forbidden_token_submitted_to_api": _contains_forbidden_token_key(
|
||||
operator_evidence
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _closeout_gates(receipt, operator, apply_real_write):
|
||||
return [
|
||||
{
|
||||
"key": "report_run_receipt_preview_provided",
|
||||
"label": "必須提供上一階段 report run receipt preview",
|
||||
"passed": bool(
|
||||
receipt["provided"]
|
||||
and receipt["mode"]
|
||||
== "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt_preview"
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_passed",
|
||||
"label": "report run receipt 必須已通過",
|
||||
"passed": receipt["receipt_passed"],
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_ready_for_closeout",
|
||||
"label": "report run receipt 必須只放行到 report closeout",
|
||||
"passed": bool(
|
||||
receipt["ready_for_market_intel_report_closeout"]
|
||||
and receipt["ready_for_next_manual_phase"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_artifact_verified",
|
||||
"label": "receipt 必須有 report artifact path/hash、章節與 summary hash",
|
||||
"passed": bool(
|
||||
receipt["report_receipt_provided"]
|
||||
and receipt["report_generated"]
|
||||
and receipt["report_output_artifact_path"]
|
||||
and receipt["report_output_hash"]
|
||||
and receipt["summary_payload_hash_matches_expected"]
|
||||
and receipt["required_report_sections_present"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_runtime_boundaries_clear",
|
||||
"label": "receipt 不得顯示 API 產報表、DB、Telegram、LLM、scheduler 或檔案副作用",
|
||||
"passed": bool(
|
||||
not receipt["ready_for_report_generation"]
|
||||
and not receipt["ready_for_api_database_write"]
|
||||
and not receipt["ready_for_telegram_dispatch"]
|
||||
and not receipt["ready_for_scheduler_attach"]
|
||||
and not receipt["api_executes_cli"]
|
||||
and not receipt["api_executes_llm"]
|
||||
and not receipt["api_dispatches_telegram"]
|
||||
and not receipt["api_reads_approval_token"]
|
||||
and not receipt["api_writes_file"]
|
||||
and not receipt["api_writes_database"]
|
||||
and not receipt["api_updates_review_state"]
|
||||
and not receipt["report_file_written"]
|
||||
and not receipt["report_record_written"]
|
||||
and not receipt["report_manifest_written"]
|
||||
and not receipt["ai_summary_generated"]
|
||||
and not receipt["llm_call_executed"]
|
||||
and not receipt["telegram_dispatched"]
|
||||
and not receipt["telegram_dispatch_attempted"]
|
||||
and not receipt["database_connection_opened"]
|
||||
and not receipt["database_write_executed"]
|
||||
and not receipt["database_commit_executed"]
|
||||
and not receipt["review_state_update_executed"]
|
||||
and not receipt["scheduler_attached"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_safe_boundaries_complete",
|
||||
"label": "receipt 必須保留 report/token/DB/scheduler 安全邊界",
|
||||
"passed": receipt["safe_boundaries_complete"],
|
||||
},
|
||||
{
|
||||
"key": "report_run_receipt_no_token_key",
|
||||
"label": "receipt 不得包含 approval 或 Telegram token key",
|
||||
"passed": not receipt["approval_or_telegram_token_key_detected"],
|
||||
},
|
||||
{
|
||||
"key": "report_closeout_artifacts_recorded",
|
||||
"label": "操作員需記錄 closeout、receipt 與 report output artifact path",
|
||||
"passed": bool(
|
||||
operator["report_closeout_artifact_path_recorded"]
|
||||
and operator["report_run_receipt_artifact_path_recorded"]
|
||||
and operator["report_output_artifact_path_recorded"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_report_closeout",
|
||||
"label": "操作員確認 report closeout、receipt 封存、hash 與章節",
|
||||
"passed": bool(
|
||||
operator["operator_confirmed_report_closeout"]
|
||||
and operator["operator_confirmed_report_receipt_archived"]
|
||||
and operator["operator_confirmed_report_output_hash_matched"]
|
||||
and operator["operator_confirmed_report_sections_reviewed"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_report_archive_requires_separate_gate",
|
||||
"label": "操作員確認後續 report archive 必須另開 gate",
|
||||
"passed": operator[
|
||||
"operator_confirmed_report_archive_requires_separate_gate"
|
||||
],
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_report_closeout_runtime_boundaries",
|
||||
"label": "操作員確認本階段不產報表、不派送 Telegram、不寫 DB、不呼叫 LLM、不掛 scheduler",
|
||||
"passed": bool(
|
||||
operator["operator_confirmed_no_token_in_report_closeout"]
|
||||
and operator["operator_confirmed_no_api_report_generation"]
|
||||
and operator["operator_confirmed_no_api_telegram_dispatch"]
|
||||
and operator["operator_confirmed_no_api_db_write"]
|
||||
and operator["operator_confirmed_no_llm_call"]
|
||||
and operator["operator_confirmed_no_scheduler_attach"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "report_closeout_no_token_submitted_to_api",
|
||||
"label": "closeout payload 不得包含 approval 或 Telegram token key",
|
||||
"passed": not operator["forbidden_token_submitted_to_api"],
|
||||
},
|
||||
{
|
||||
"key": "report_closeout_apply_real_write_not_requested_from_api",
|
||||
"label": "API/UI report closeout 不接受 apply_real_write",
|
||||
"passed": not apply_real_write,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout(
|
||||
*,
|
||||
telegram_dispatch_report_run_receipt,
|
||||
operator_evidence=None,
|
||||
execute_requested=False,
|
||||
apply_real_write=False,
|
||||
):
|
||||
"""建立 Telegram dispatch report closeout gate;不執行任何副作用。"""
|
||||
receipt = _receipt_summary(telegram_dispatch_report_run_receipt)
|
||||
operator = _operator_closeout_summary(operator_evidence)
|
||||
gates = _closeout_gates(receipt, operator, bool(apply_real_write))
|
||||
blocked_reasons = [gate["key"] for gate in gates if not gate["passed"]]
|
||||
closeout_passed = bool(not blocked_reasons)
|
||||
|
||||
return {
|
||||
"mode": "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout_preview",
|
||||
"target_table": TARGET_TABLE,
|
||||
"target_column": TARGET_COLUMN,
|
||||
"target_json_path": [
|
||||
SUMMARY_METADATA_KEY,
|
||||
"telegram_dispatch_report_closeout",
|
||||
],
|
||||
"target_operation": "closeout_manual_market_intel_report",
|
||||
"execute_requested": bool(execute_requested),
|
||||
"apply_real_write_requested": bool(apply_real_write),
|
||||
"report_closeout_reviewed": True,
|
||||
"telegram_dispatch_report_closeout_passed": closeout_passed,
|
||||
"summary_persistence_telegram_dispatch_report_closeout_passed": closeout_passed,
|
||||
"report_closeout_passed": closeout_passed,
|
||||
"ready_for_next_manual_phase": closeout_passed,
|
||||
"ready_for_market_intel_report_archive": closeout_passed,
|
||||
**{key: False for key in FALSE_RESPONSE_KEYS},
|
||||
"statement_count": receipt["statement_count"],
|
||||
"expected_summary_payload_hash": receipt["expected_summary_payload_hash"],
|
||||
"blocked_reasons": blocked_reasons,
|
||||
"gates": gates,
|
||||
"telegram_dispatch_report_run_receipt_summary": receipt,
|
||||
"operator_telegram_dispatch_report_closeout": operator,
|
||||
"promotion_gate": {
|
||||
"allowed": closeout_passed,
|
||||
"next_manual_phase": "market_intel_report_archive",
|
||||
"requires_real_db_write": False,
|
||||
"requires_scheduler_attach": False,
|
||||
"requires_operator_approval": True,
|
||||
"api_must_not_generate_report": True,
|
||||
"api_must_not_dispatch_telegram": True,
|
||||
"report_archive_requires_separate_gate": True,
|
||||
},
|
||||
"next_operator_steps": [
|
||||
"保存 report closeout artifact path",
|
||||
"確認 report receipt、report output artifact、hash 與章節都已封存",
|
||||
"下一階段 report archive 才整理長期封存;本 API 不寫檔、不補產報表",
|
||||
"若任何 closeout gate 阻擋,停在 receipt 階段並保留 feature flags 關閉",
|
||||
],
|
||||
"safe_boundaries": [
|
||||
"do_not_read_approval_token_from_report_closeout_api",
|
||||
"do_not_read_telegram_token_from_report_closeout_api",
|
||||
"do_not_call_llm_from_report_closeout",
|
||||
"do_not_generate_report_from_report_closeout_api",
|
||||
"do_not_write_report_artifact_from_report_closeout_api",
|
||||
"do_not_dispatch_telegram_from_report_closeout_api",
|
||||
"do_not_open_database_connection_from_report_closeout",
|
||||
"do_not_update_review_state_from_report_closeout",
|
||||
"do_not_attach_scheduler_from_report_closeout",
|
||||
"future_market_intel_report_archive_must_use_separate_gate",
|
||||
"report_closeout_preview_only",
|
||||
"no_remove_orphans",
|
||||
"no_momo_db_lifecycle_change",
|
||||
],
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
"""市場情報 rollout phase 單一來源。"""
|
||||
|
||||
MARKET_INTEL_PHASE = "phase_100_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt"
|
||||
MARKET_INTEL_PHASE = "phase_101_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout"
|
||||
|
||||
@@ -739,6 +739,9 @@
|
||||
<button class="market-intel-icon-button" type="button" title="審核 queue review AI summary Telegram dispatch report run receipt" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-run-receipt>
|
||||
<i class="fas fa-receipt" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button class="market-intel-icon-button" type="button" title="收尾 queue review AI summary Telegram dispatch report closeout" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-closeout>
|
||||
<i class="fas fa-flag-checkered" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1113,6 +1116,7 @@
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunPackage = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-run-package]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReadiness = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-run-readiness]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReceipt = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-run-receipt]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-closeout]') : null;
|
||||
const sampleReviewEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_review') }}";
|
||||
const sampleReviewEvaluateEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_review_evaluate') }}";
|
||||
const sampleCandidateHandoffEndpoint = "{{ url_for('market_intel.market_intel_manual_sample_candidate_handoff') }}";
|
||||
@@ -1164,6 +1168,7 @@
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunPackageEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_package') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReadinessEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_readiness') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReceiptEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_run_receipt') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseoutEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_closeout') }}";
|
||||
const schedulerMeta = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-meta]') : null;
|
||||
const schedulerBody = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-body]') : null;
|
||||
const schedulerRefresh = schedulerRoot ? schedulerRoot.querySelector('[data-market-intel-scheduler-refresh]') : null;
|
||||
@@ -7558,6 +7563,151 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const gates = data.gates || [];
|
||||
const receipt = data.telegram_dispatch_report_run_receipt_summary || {};
|
||||
const operator = data.operator_telegram_dispatch_report_closeout || {};
|
||||
const promotion = data.promotion_gate || {};
|
||||
sampleReviewMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`closeout=${data.telegram_dispatch_report_closeout_passed ? 'pass' : 'blocked'}`,
|
||||
`archive=${data.ready_for_market_intel_report_archive ? 'ready' : 'blocked'}`,
|
||||
`report=${data.ready_for_report_generation ? 'generated' : 'blocked'}`,
|
||||
`telegram=${data.telegram_dispatched ? 'sent' : 'blocked'}`
|
||||
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
|
||||
sampleReviewBody.innerHTML = `
|
||||
<div class="market-intel-empty mb-3">此卡只收尾 Telegram dispatch report closeout;API/UI 不讀 token、不呼叫 LLM、不開 DB、不寫檔、不產報表、不補發 Telegram、不掛 scheduler。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
|
||||
<div class="market-intel-deploy-grid">
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">REPORT CLOSEOUT GATES</p>
|
||||
<div class="market-intel-check-list">${
|
||||
gates.map(item => `
|
||||
<div class="market-intel-check">
|
||||
<div>
|
||||
<strong>${escapeHtml(item.key)}</strong>
|
||||
<small>${escapeHtml(item.label)}</small>
|
||||
</div>
|
||||
<span>${item.passed ? 'PASS' : 'BLOCK'}</span>
|
||||
</div>
|
||||
`).join('') || '<div class="market-intel-empty">尚未提供 closeout gate。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">RECEIPT SUMMARY</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['provided', receipt.provided],
|
||||
['mode', receipt.mode || 'missing'],
|
||||
['receipt_passed', receipt.receipt_passed],
|
||||
['closeout_ready', receipt.ready_for_market_intel_report_closeout],
|
||||
['family', receipt.target_report_family || 'missing'],
|
||||
['language', receipt.language || 'missing'],
|
||||
['report_path', receipt.report_output_artifact_path || 'missing'],
|
||||
['summary_hash_match', receipt.summary_payload_hash_matches_expected],
|
||||
['sections_present', receipt.required_report_sections_present]
|
||||
].map(([key, value]) => `
|
||||
<div class="market-intel-check">
|
||||
<div><strong>${escapeHtml(key)}</strong></div>
|
||||
<span>${escapeHtml(String(value))}</span>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">OPERATOR CLOSEOUT</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['closeout_path', operator.report_closeout_artifact_path_recorded],
|
||||
['receipt_path', operator.report_run_receipt_artifact_path_recorded],
|
||||
['output_path', operator.report_output_artifact_path_recorded],
|
||||
['closeout_confirmed', operator.operator_confirmed_report_closeout],
|
||||
['receipt_archived', operator.operator_confirmed_report_receipt_archived],
|
||||
['hash_confirmed', operator.operator_confirmed_report_output_hash_matched],
|
||||
['sections_reviewed', operator.operator_confirmed_report_sections_reviewed],
|
||||
['archive_separate_gate', operator.operator_confirmed_report_archive_requires_separate_gate],
|
||||
['no_token_or_runtime_side_effect', operator.operator_confirmed_no_token_in_report_closeout && operator.operator_confirmed_no_api_report_generation && operator.operator_confirmed_no_api_telegram_dispatch && operator.operator_confirmed_no_api_db_write && operator.operator_confirmed_no_llm_call && operator.operator_confirmed_no_scheduler_attach]
|
||||
].map(([key, value]) => `
|
||||
<div class="market-intel-check">
|
||||
<div><strong>${escapeHtml(key)}</strong></div>
|
||||
<span>${escapeHtml(String(value))}</span>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">RUNTIME BOUNDARY</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['api_writes_file', data.api_writes_file],
|
||||
['api_calls_llm', data.api_executes_llm],
|
||||
['api_dispatches_telegram', data.api_dispatches_telegram],
|
||||
['api_writes_database', data.api_writes_database],
|
||||
['database_write', data.database_write_executed],
|
||||
['scheduler_attached', data.scheduler_attached],
|
||||
['report_file_written', data.report_file_written],
|
||||
['closeout_file_written', data.report_closeout_file_written]
|
||||
].map(([key, value]) => `
|
||||
<div class="market-intel-check">
|
||||
<div><strong>${escapeHtml(key)}</strong></div>
|
||||
<span>${escapeHtml(String(value))}</span>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">PROMOTION</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['allowed', promotion.allowed],
|
||||
['next_phase', promotion.next_manual_phase || 'missing'],
|
||||
['requires_operator_approval', promotion.requires_operator_approval],
|
||||
['archive_separate_gate', promotion.report_archive_requires_separate_gate],
|
||||
['api_must_not_generate_report', promotion.api_must_not_generate_report],
|
||||
['api_must_not_dispatch_telegram', promotion.api_must_not_dispatch_telegram]
|
||||
].map(([key, value]) => `
|
||||
<div class="market-intel-check">
|
||||
<div><strong>${escapeHtml(key)}</strong></div>
|
||||
<span>${escapeHtml(String(value))}</span>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
const loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout = async () => {
|
||||
if (!sampleReviewMeta || !sampleReviewBody || !sampleReviewInput) return;
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(sampleReviewInput.value || '{}');
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">json_error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">JSON 格式錯誤:${escapeHtml(error.message)}</div>`;
|
||||
return;
|
||||
}
|
||||
const body = parsed && parsed.sample_result ? parsed : { sample_result: parsed };
|
||||
sampleReviewBody.innerHTML = '<div class="market-intel-empty">收尾 queue review AI summary Telegram dispatch report closeout 中...</div>';
|
||||
try {
|
||||
const response = await fetch(`${sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseoutEndpoint}?execute=false&apply_real_write=false`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok && !data.mode) throw new Error(`HTTP ${response.status}`);
|
||||
renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout(data);
|
||||
} catch (error) {
|
||||
sampleReviewMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
sampleReviewBody.innerHTML = `<div class="market-intel-empty">queue review AI summary Telegram dispatch report closeout 失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateQueueReviewDecisionWriter = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const summary = data.statement_summary || {};
|
||||
@@ -9312,6 +9462,9 @@
|
||||
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReceipt) {
|
||||
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReceipt.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportRunReceipt);
|
||||
}
|
||||
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout) {
|
||||
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCloseout);
|
||||
}
|
||||
if (schedulerRefresh) {
|
||||
schedulerRefresh.addEventListener('click', loadScheduler);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user