[V10.356] add market intel catalog record final closeout gate
All checks were successful
CD Pipeline / deploy (push) Successful in 1m29s

This commit is contained in:
OoO
2026-05-21 10:05:59 +08:00
parent b272abccca
commit 73ec78e8ab
9 changed files with 1400 additions and 109 deletions

View File

@@ -4,6 +4,7 @@
================================================================================
【已完成】
- V10.356 補市場情報 candidate queue review AI summary Telegram dispatch report catalog record final closeout gate新增 read-only report catalog record final closeout builder、POST endpoint、UI 按鈕與 deployment readiness smoke target在 archive summary gate 後覆核 catalog record identity、artifact traceability、sections、DB commit/post-write smoke、pipeline complete 與無後續 follow-upAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 review_state、不掛 scheduler。
- V10.355 補市場情報 candidate queue review AI summary Telegram dispatch report catalog record archive summary gate新增 read-only report catalog record archive summary builder、POST endpoint、UI 按鈕與 deployment readiness smoke target在 archive gate 後整理 catalog record identity、artifact traceability、DB commit/post-write smoke、archive manifest/retention policy 與後續 final closeout separate gateAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 review_state、不掛 scheduler。
- V10.354 補市場情報 candidate queue review AI summary Telegram dispatch report catalog record archive gate新增 read-only report catalog record archive builder、POST endpoint、UI 按鈕與 deployment readiness smoke target在 closeout gate 後審核 closeout/commit/run receipt/writer output/post-write smoke/backup 封存證據、archive manifest/retention policy 與後續 archive summary separate gateAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 review_state、不掛 scheduler。
- V10.353 補市場情報 candidate queue review AI summary Telegram dispatch report catalog record closeout gate新增 read-only report catalog record closeout builder、POST endpoint、UI 按鈕與 deployment readiness smoke target在 commit gate 後審核 catalog record identity、DB commit/post-write smoke 證據、操作員 closeout 確認與後續 archive separate gateAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不補產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 review_state、不掛 scheduler。

View File

@@ -323,7 +323,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
# ==========================================
# 系統版本與路徑
# ==========================================
SYSTEM_VERSION = "V10.355"
SYSTEM_VERSION = "V10.356"
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
public_url = PUBLIC_URL # 用於模板顯示

View File

@@ -12,6 +12,10 @@
## 📅 詳細更新日誌 (考古存檔)
### 2026-05-21市場情報 Telegram dispatch report catalog record final closeout gate
- **V10.356 report catalog record final closeout gate**: 新增 `candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout` service、POST endpoint、UI 按鈕與 deployment readiness smoke target在 archive summary gate 後覆核 catalog record identity、artifact traceability、sections、DB commit/post-write smoke、pipeline complete 與無後續 follow-up。
- **只讀安全邊界**: 本階段是 catalog record pipeline terminal previewAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 `review_state`、不掛 scheduler。
### 2026-05-21市場情報 Telegram dispatch report catalog record archive summary gate
- **V10.355 report catalog record archive summary gate**: 新增 `candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary` service、POST endpoint、UI 按鈕與 deployment readiness smoke target在 archive gate 後整理 catalog record identity、artifact traceability、DB commit/post-write smoke、archive manifest/retention policy 與後續 final closeout separate gate。
- **只讀安全邊界**: 本階段只放行到後續 report catalog record final closeout gateAPI/UI 不讀 approval/Telegram token、不呼叫 LLM、不產報表、不派送 Telegram、不開 DB、不寫檔、不執行 CLI、不寫 catalog record、不 commit、不更新 `review_state`、不掛 scheduler。

View File

@@ -55,6 +55,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_catalog_record_archive_summary import (
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary,
)
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout import (
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout,
)
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,
)
@@ -803,6 +806,61 @@ def _build_ai_summary_persistence_telegram_dispatch_report_catalog_record_archiv
)
def _extract_report_catalog_record_final_closeout_payload(
sample_result,
operator_evidence,
):
operator_evidence = _as_dict(operator_evidence)
sample_result = _as_dict(sample_result)
return _as_dict(
operator_evidence.get("market_intel_report_catalog_record_final_closeout")
or operator_evidence.get(
"telegram_dispatch_report_catalog_record_final_closeout"
)
or operator_evidence.get("report_catalog_record_final_closeout")
or operator_evidence.get("catalog_record_final_closeout")
or sample_result.get("market_intel_report_catalog_record_final_closeout")
or sample_result.get("telegram_dispatch_report_catalog_record_final_closeout")
or sample_result.get("report_catalog_record_final_closeout")
or sample_result.get("catalog_record_final_closeout")
)
def _build_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout(
*,
service,
sample_result,
operator_evidence,
writer_output,
smoke_result,
payload_error,
limit,
execute_requested,
apply_real_write,
):
report_catalog_record_archive_summary = _build_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary(
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_catalog_record_final_closeout(
telegram_dispatch_report_catalog_record_archive_summary=report_catalog_record_archive_summary,
report_catalog_record_final_closeout=_extract_report_catalog_record_final_closeout_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",
@@ -1317,3 +1375,31 @@ def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_tel
)
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_catalog_record_final_closeout",
methods=["POST"],
)
@login_required
def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_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()
)
data = _build_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout(
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["phase"] = service.phase
return jsonify(data), 400 if payload_error else 200

View File

@@ -0,0 +1,683 @@
"""候選審核 queue AI summary Telegram dispatch report catalog record final closeout gate。
本模組只在 catalog record archive summary 通過後整理終局收尾證據;不讀
approval 或 Telegram token、不呼叫 LLM、不派送 Telegram、不開 DB、不寫檔、
不執行 CLI、不補寫 catalog record、不執行 commit、不更新 review_state、
不掛 scheduler。
"""
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary import (
FALSE_RESPONSE_KEYS as REPORT_CATALOG_RECORD_ARCHIVE_SUMMARY_FALSE_RESPONSE_KEYS,
SAFE_APPROVAL_ENV_VAR,
SAFE_TOKEN_METADATA_KEYS,
TARGET_COLUMN,
TARGET_TABLE,
_as_dict,
_as_list,
_contains_forbidden_token_key,
_has_text,
_safe_int,
_safe_text,
_strip_safe_token_boolean_keys,
)
REQUIRED_ARCHIVE_SUMMARY_BOUNDARIES = {
"do_not_read_approval_token_from_report_catalog_record_archive_summary_api",
"do_not_read_telegram_token_from_report_catalog_record_archive_summary_api",
"do_not_call_llm_from_report_catalog_record_archive_summary",
"do_not_generate_report_from_report_catalog_record_archive_summary_api",
"do_not_write_report_catalog_record_archive_summary_artifact_from_api",
"do_not_execute_catalog_record_cli_from_report_catalog_record_archive_summary_api",
"do_not_write_report_catalog_record_from_report_catalog_record_archive_summary_api",
"do_not_commit_catalog_record_from_report_catalog_record_archive_summary_api",
"do_not_dispatch_telegram_from_report_catalog_record_archive_summary_api",
"do_not_open_database_connection_from_report_catalog_record_archive_summary",
"do_not_update_review_state_from_report_catalog_record_archive_summary",
"do_not_attach_scheduler_from_report_catalog_record_archive_summary",
"future_market_intel_report_catalog_record_final_closeout_must_use_separate_gate",
}
FALSE_RESPONSE_KEYS = tuple(
dict.fromkeys(
REPORT_CATALOG_RECORD_ARCHIVE_SUMMARY_FALSE_RESPONSE_KEYS
+ (
"telegram_dispatch_report_catalog_record_final_closeout_gate_file_written",
"report_catalog_record_final_closeout_gate_file_written",
"catalog_record_final_closeout_gate_file_written",
"telegram_dispatch_report_catalog_record_final_closeout_file_written",
"report_catalog_record_final_closeout_file_written",
"catalog_record_final_closeout_file_written",
"catalog_record_final_closeout_record_written",
"catalog_record_final_closeout_executed",
"catalog_record_pipeline_completion_record_written",
"market_intel_catalog_record_pipeline_completed_by_api",
)
)
)
def _archive_summary_snapshot(telegram_dispatch_report_catalog_record_archive_summary):
summary = _as_dict(telegram_dispatch_report_catalog_record_archive_summary)
archive = _as_dict(summary.get("telegram_dispatch_report_catalog_record_archive"))
operator = _as_dict(
summary.get("operator_telegram_dispatch_report_catalog_record_archive_summary")
)
promotion = _as_dict(summary.get("promotion_gate"))
sections = _as_list(
summary.get("telegram_dispatch_report_catalog_record_archive_summary_sections")
)
section_keys = {
str(section.get("key"))
for section in sections
if isinstance(section, dict) and section.get("key")
}
safe_boundaries = set(str(item) for item in _as_list(summary.get("safe_boundaries")))
missing_boundaries = sorted(REQUIRED_ARCHIVE_SUMMARY_BOUNDARIES - safe_boundaries)
blocked_keys = [key for key in FALSE_RESPONSE_KEYS if bool(summary.get(key))]
return {
"provided": bool(summary),
"mode": summary.get("mode"),
"target_operation": summary.get("target_operation"),
"archive_summary_passed": bool(
summary.get("telegram_dispatch_report_catalog_record_archive_summary_passed")
or summary.get(
"summary_persistence_telegram_dispatch_report_catalog_record_archive_summary_passed"
)
or summary.get("report_catalog_record_archive_summary_passed")
),
"ready_for_next_manual_phase": bool(summary.get("ready_for_next_manual_phase")),
"ready_for_market_intel_report_catalog_record_final_closeout": bool(
summary.get("ready_for_market_intel_report_catalog_record_final_closeout")
),
"ready_for_market_intel_report_catalog_record_archive_summary": bool(
summary.get("ready_for_market_intel_report_catalog_record_archive_summary")
),
"statement_count": _safe_int(summary.get("statement_count")),
"expected_summary_payload_hash": _safe_text(
summary.get("expected_summary_payload_hash")
or archive.get("expected_summary_payload_hash"),
80,
),
"writer_record_family": _safe_text(archive.get("writer_record_family"), 80),
"writer_catalog_record_key": _safe_text(
archive.get("writer_catalog_record_key"), 160
),
"writer_target_table": archive.get("writer_target_table"),
"writer_target_column": archive.get("writer_target_column"),
"writer_statement_count": _safe_int(archive.get("writer_statement_count")),
"writer_database_commit_executed": bool(
archive.get("writer_database_commit_executed")
),
"writer_hash_match": bool(archive.get("writer_hash_match")),
"smoke_read_only_query_executed": bool(
archive.get("smoke_read_only_query_executed")
),
"smoke_postwrite_smoke_passed": bool(
archive.get("smoke_postwrite_smoke_passed")
),
"smoke_hash_match": bool(archive.get("smoke_hash_match")),
"archive_passed": bool(archive.get("archive_passed")),
"archive_artifact_path": archive.get("archive_artifact_path"),
"archive_closeout_artifact_path_recorded": bool(
archive.get("archive_closeout_artifact_path_recorded")
),
"archive_commit_artifact_path_recorded": bool(
archive.get("archive_commit_artifact_path_recorded")
),
"archive_run_receipt_artifact_path_recorded": bool(
archive.get("archive_run_receipt_artifact_path_recorded")
),
"archive_writer_output_artifact_path_recorded": bool(
archive.get("archive_writer_output_artifact_path_recorded")
),
"archive_postwrite_smoke_artifact_path_recorded": bool(
archive.get("archive_postwrite_smoke_artifact_path_recorded")
),
"archive_backup_artifact_path_recorded": bool(
archive.get("archive_backup_artifact_path_recorded")
),
"operator_summary_artifact_path": operator.get(
"report_catalog_record_archive_summary_artifact_path"
),
"operator_archive_artifact_path_recorded": bool(
operator.get("report_catalog_record_archive_artifact_path_recorded")
),
"operator_archive_summary_gate": bool(
operator.get("operator_confirmed_report_catalog_record_archive_summary_gate")
),
"operator_archive_reviewed": bool(
operator.get("operator_confirmed_report_catalog_record_archive_reviewed")
),
"operator_traceability_reviewed": bool(
operator.get("operator_confirmed_catalog_record_traceability_reviewed")
),
"operator_archive_summary_read_only": bool(
operator.get("operator_confirmed_catalog_record_archive_summary_read_only")
),
"operator_final_closeout_requires_separate_gate": bool(
operator.get(
"operator_confirmed_catalog_record_final_closeout_requires_separate_gate"
)
),
"section_keys": sorted(section_keys),
"summary_sections_complete": {
"catalog_record_archive_summary_identity",
"catalog_record_archive_summary_traceability",
"catalog_record_archive_summary_integrity",
"catalog_record_archive_summary_safety",
}.issubset(section_keys),
"promotion_allowed": bool(promotion.get("allowed")),
"promotion_next_manual_phase": promotion.get("next_manual_phase"),
"promotion_final_closeout_separate_gate": bool(
promotion.get("report_catalog_record_final_closeout_requires_separate_gate")
),
"promotion_api_must_not_generate_report": bool(
promotion.get("api_must_not_generate_report")
),
"promotion_api_must_not_write_file": bool(
promotion.get("api_must_not_write_file")
),
"promotion_api_must_not_execute_cli": bool(
promotion.get("api_must_not_execute_cli")
),
"promotion_api_must_not_write_catalog_record": bool(
promotion.get("api_must_not_write_catalog_record")
),
"promotion_api_must_not_write_database": bool(
promotion.get("api_must_not_write_database")
),
"promotion_api_must_not_commit_catalog_record": bool(
promotion.get("api_must_not_commit_catalog_record")
),
"promotion_api_must_not_dispatch_telegram": bool(
promotion.get("api_must_not_dispatch_telegram")
),
"safe_boundaries_complete": not missing_boundaries,
"missing_safe_boundaries": missing_boundaries,
"forbidden_token_key_detected": _contains_forbidden_token_key(
_strip_safe_token_boolean_keys(summary)
),
"blocked_response_keys_true": blocked_keys,
**{key: bool(summary.get(key)) for key in FALSE_RESPONSE_KEYS},
}
def _operator_summary(operator_evidence, report_catalog_record_final_closeout=None):
operator_evidence = _as_dict(operator_evidence)
closeout_payload = _as_dict(report_catalog_record_final_closeout)
return {
"provided_keys": sorted(operator_evidence.keys()),
"report_catalog_record_final_closeout_artifact_path": _safe_text(
operator_evidence.get("report_catalog_record_final_closeout_artifact_path")
or operator_evidence.get(
"telegram_dispatch_report_catalog_record_final_closeout_artifact_path"
)
or operator_evidence.get(
"market_intel_report_catalog_record_final_closeout_artifact_path"
)
or closeout_payload.get("report_catalog_record_final_closeout_artifact_path"),
300,
),
"report_catalog_record_archive_summary_artifact_path_recorded": _has_text(
operator_evidence.get("report_catalog_record_archive_summary_artifact_path")
or closeout_payload.get("report_catalog_record_archive_summary_artifact_path")
),
"report_catalog_record_archive_artifact_path_recorded": _has_text(
operator_evidence.get("report_catalog_record_archive_artifact_path")
or closeout_payload.get("report_catalog_record_archive_artifact_path")
),
"report_catalog_record_closeout_artifact_path_recorded": _has_text(
operator_evidence.get("report_catalog_record_closeout_artifact_path")
or closeout_payload.get("report_catalog_record_closeout_artifact_path")
),
"report_catalog_record_commit_artifact_path_recorded": _has_text(
operator_evidence.get("report_catalog_record_commit_artifact_path")
or closeout_payload.get("report_catalog_record_commit_artifact_path")
),
"report_catalog_record_run_receipt_artifact_path_recorded": _has_text(
operator_evidence.get("report_catalog_record_run_receipt_artifact_path")
or closeout_payload.get("report_catalog_record_run_receipt_artifact_path")
),
"catalog_record_writer_output_artifact_path_recorded": _has_text(
operator_evidence.get("catalog_record_writer_output_artifact_path")
or operator_evidence.get("writer_output_json_path")
or closeout_payload.get("catalog_record_writer_output_artifact_path")
),
"catalog_record_postwrite_smoke_artifact_path_recorded": _has_text(
operator_evidence.get("catalog_record_postwrite_smoke_artifact_path")
or operator_evidence.get("postwrite_smoke_json_path")
or closeout_payload.get("catalog_record_postwrite_smoke_artifact_path")
),
"catalog_record_backup_artifact_path_recorded": _has_text(
operator_evidence.get("catalog_record_backup_artifact_path")
or operator_evidence.get("backup_artifact_path")
or closeout_payload.get("catalog_record_backup_artifact_path")
),
"operator_confirmed_report_catalog_record_final_closeout_gate": bool(
operator_evidence.get(
"operator_confirmed_report_catalog_record_final_closeout_gate"
)
or operator_evidence.get(
"operator_confirmed_market_intel_report_catalog_record_final_closeout"
)
or closeout_payload.get(
"operator_confirmed_report_catalog_record_final_closeout_gate"
)
),
"operator_confirmed_report_catalog_record_archive_summary_reviewed": bool(
operator_evidence.get(
"operator_confirmed_report_catalog_record_archive_summary_reviewed"
)
or operator_evidence.get(
"operator_confirmed_catalog_record_archive_summary_reviewed"
)
or closeout_payload.get(
"operator_confirmed_report_catalog_record_archive_summary_reviewed"
)
),
"operator_confirmed_catalog_record_traceability_reviewed": bool(
operator_evidence.get(
"operator_confirmed_catalog_record_traceability_reviewed"
)
or closeout_payload.get("operator_confirmed_catalog_record_traceability_reviewed")
),
"operator_confirmed_catalog_record_pipeline_complete": bool(
operator_evidence.get("operator_confirmed_catalog_record_pipeline_complete")
or operator_evidence.get(
"operator_confirmed_market_intel_catalog_record_pipeline_complete"
)
or closeout_payload.get("operator_confirmed_catalog_record_pipeline_complete")
),
"operator_confirmed_no_pending_catalog_record_followup": bool(
operator_evidence.get(
"operator_confirmed_no_pending_catalog_record_followup"
)
or operator_evidence.get("operator_confirmed_no_followup_required")
or closeout_payload.get(
"operator_confirmed_no_pending_catalog_record_followup"
)
),
"operator_confirmed_catalog_record_final_closeout_read_only": bool(
operator_evidence.get(
"operator_confirmed_catalog_record_final_closeout_read_only"
)
or operator_evidence.get("operator_confirmed_final_closeout_is_read_only")
or closeout_payload.get(
"operator_confirmed_catalog_record_final_closeout_read_only"
)
),
"operator_confirmed_no_token_in_report_catalog_record_final_closeout": bool(
operator_evidence.get(
"operator_confirmed_no_token_in_report_catalog_record_final_closeout"
)
or operator_evidence.get("operator_confirmed_no_token_in_artifacts")
or closeout_payload.get(
"operator_confirmed_no_token_in_report_catalog_record_final_closeout"
)
),
"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")
or closeout_payload.get("operator_confirmed_no_api_report_generation")
),
"operator_confirmed_no_api_file_write": bool(
operator_evidence.get("operator_confirmed_no_api_file_write")
or closeout_payload.get("operator_confirmed_no_api_file_write")
),
"operator_confirmed_no_api_cli_execution": bool(
operator_evidence.get("operator_confirmed_no_api_cli_execution")
or operator_evidence.get("operator_confirmed_no_api_execute_cli")
or closeout_payload.get("operator_confirmed_no_api_cli_execution")
),
"operator_confirmed_no_api_catalog_record_write": bool(
operator_evidence.get("operator_confirmed_no_api_catalog_record_write")
or operator_evidence.get("operator_confirmed_no_api_db_write")
or closeout_payload.get("operator_confirmed_no_api_catalog_record_write")
),
"operator_confirmed_no_api_telegram_dispatch": bool(
operator_evidence.get("operator_confirmed_no_api_telegram_dispatch")
or closeout_payload.get("operator_confirmed_no_api_telegram_dispatch")
),
"operator_confirmed_no_api_db_write": bool(
operator_evidence.get("operator_confirmed_no_api_db_write")
or closeout_payload.get("operator_confirmed_no_api_db_write")
),
"operator_confirmed_no_llm_call": bool(
operator_evidence.get("operator_confirmed_no_llm_call")
or closeout_payload.get("operator_confirmed_no_llm_call")
),
"operator_confirmed_no_scheduler_attach": bool(
operator_evidence.get("operator_confirmed_no_scheduler_attach")
or closeout_payload.get("operator_confirmed_no_scheduler_attach")
),
"final_closeout_notes_recorded": _has_text(
operator_evidence.get("report_catalog_record_final_closeout_notes")
or operator_evidence.get("catalog_record_final_closeout_notes")
or closeout_payload.get("notes")
),
"safe_token_metadata_only": all(
key in SAFE_TOKEN_METADATA_KEYS or key == "approval_env_var"
for key in _strip_safe_token_boolean_keys(operator_evidence)
if "token" in str(key).lower() or str(key).lower() == "approval_env_var"
)
and operator_evidence.get("approval_env_var", SAFE_APPROVAL_ENV_VAR)
== SAFE_APPROVAL_ENV_VAR,
"forbidden_token_submitted_to_api": _contains_forbidden_token_key(
operator_evidence
)
or _contains_forbidden_token_key(closeout_payload),
}
def _closeout_sections(summary, operator):
return [
{
"key": "catalog_record_final_closeout_identity",
"title": "Catalog record final closeout identity",
"facts": [
f"family={summary['writer_record_family'] or 'missing'}",
f"record_key={summary['writer_catalog_record_key'] or 'missing'}",
f"statement_count={summary['writer_statement_count']}",
],
},
{
"key": "catalog_record_final_closeout_traceability",
"title": "Catalog record final closeout traceability",
"facts": [
f"summary_path={operator['report_catalog_record_final_closeout_artifact_path'] or 'missing'}",
f"archive_summary_passed={summary['archive_summary_passed']}",
f"sections_complete={summary['summary_sections_complete']}",
],
},
{
"key": "catalog_record_final_closeout_integrity",
"title": "Catalog record final closeout integrity",
"facts": [
f"db_commit={summary['writer_database_commit_executed']}",
f"smoke_passed={summary['smoke_postwrite_smoke_passed']}",
f"pipeline_complete={operator['operator_confirmed_catalog_record_pipeline_complete']}",
],
},
{
"key": "catalog_record_final_closeout_safety",
"title": "Catalog record final closeout safety",
"facts": [
"report_generated=false",
"api_cli_executed=false",
"api_database_write_executed=false",
"catalog_record_final_closeout_executed=false",
"scheduler_attached=false",
],
},
]
def _closeout_gates(summary, operator, apply_real_write):
return [
{
"key": "report_catalog_record_archive_summary_passed",
"label": "上一關 report catalog record archive summary gate 已通過",
"passed": bool(
summary["provided"]
and summary["mode"]
== "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary_preview"
and summary["archive_summary_passed"]
and summary["ready_for_next_manual_phase"]
and summary["ready_for_market_intel_report_catalog_record_final_closeout"]
and not summary["ready_for_market_intel_report_catalog_record_archive_summary"]
),
},
{
"key": "report_catalog_record_archive_summary_catalog_record_evidence_retained",
"label": "archive summary payload 保留 catalog record identity、DB commit 與 post-write smoke 證據",
"passed": bool(
summary["writer_catalog_record_key"]
and summary["writer_target_table"] == TARGET_TABLE
and summary["writer_target_column"] == TARGET_COLUMN
and summary["writer_statement_count"] > 0
and summary["writer_database_commit_executed"]
and summary["writer_hash_match"]
and summary["smoke_read_only_query_executed"]
and summary["smoke_postwrite_smoke_passed"]
and summary["smoke_hash_match"]
),
},
{
"key": "report_catalog_record_archive_summary_artifacts_verified",
"label": "archive summary payload 保留 archive、closeout、commit、run receipt、writer output、post-write smoke 與 backup trace",
"passed": bool(
summary["archive_passed"]
and summary["archive_artifact_path"]
and summary["archive_closeout_artifact_path_recorded"]
and summary["archive_commit_artifact_path_recorded"]
and summary["archive_run_receipt_artifact_path_recorded"]
and summary["archive_writer_output_artifact_path_recorded"]
and summary["archive_postwrite_smoke_artifact_path_recorded"]
and summary["archive_backup_artifact_path_recorded"]
and summary["operator_summary_artifact_path"]
and summary["operator_archive_artifact_path_recorded"]
),
},
{
"key": "report_catalog_record_archive_summary_sections_complete",
"label": "archive summary sections 已整理 identity、traceability、integrity 與 runtime safety",
"passed": bool(summary["summary_sections_complete"]),
},
{
"key": "report_catalog_record_archive_summary_operator_evidence_retained",
"label": "archive summary payload 保留操作員 archive summary、traceability、read-only 與 final closeout separate gate 確認",
"passed": bool(
summary["operator_archive_summary_gate"]
and summary["operator_archive_reviewed"]
and summary["operator_traceability_reviewed"]
and summary["operator_archive_summary_read_only"]
and summary["operator_final_closeout_requires_separate_gate"]
),
},
{
"key": "report_catalog_record_archive_summary_promotion_gate",
"label": "archive summary promotion gate 僅放行到 final closeout 且要求獨立 gate",
"passed": bool(
summary["promotion_allowed"]
and summary["promotion_next_manual_phase"]
== "market_intel_report_catalog_record_final_closeout"
and summary["promotion_final_closeout_separate_gate"]
and summary["promotion_api_must_not_generate_report"]
and summary["promotion_api_must_not_write_file"]
and summary["promotion_api_must_not_execute_cli"]
and summary["promotion_api_must_not_write_catalog_record"]
and summary["promotion_api_must_not_write_database"]
and summary["promotion_api_must_not_commit_catalog_record"]
and summary["promotion_api_must_not_dispatch_telegram"]
),
},
{
"key": "report_catalog_record_archive_summary_api_side_effects_blocked",
"label": "上一關 archive summary top-level API 沒有執行 CLI、寫檔、寫 DB、commit、派 Telegram 或掛 scheduler",
"passed": bool(
not summary["api_executes_cli"]
and not summary["api_writes_file"]
and not summary["api_writes_database"]
and not summary["api_dispatches_telegram"]
and not summary["database_write_executed"]
and not summary["catalog_record_archive_summary_executed"]
and not summary["scheduler_attached"]
and not summary["blocked_response_keys_true"]
),
},
{
"key": "report_catalog_record_archive_summary_safe_boundaries_complete",
"label": "上一關 archive summary safe boundaries 完整且未夾帶 token key",
"passed": bool(
summary["safe_boundaries_complete"]
and not summary["forbidden_token_key_detected"]
),
},
{
"key": "report_catalog_record_final_closeout_operator_confirmed",
"label": "操作員確認 final closeout gate、完整 traceability、pipeline complete 與無後續 DB follow-up",
"passed": bool(
operator["report_catalog_record_final_closeout_artifact_path"]
and operator[
"report_catalog_record_archive_summary_artifact_path_recorded"
]
and operator["report_catalog_record_archive_artifact_path_recorded"]
and operator["report_catalog_record_closeout_artifact_path_recorded"]
and operator["report_catalog_record_commit_artifact_path_recorded"]
and operator["report_catalog_record_run_receipt_artifact_path_recorded"]
and operator["catalog_record_writer_output_artifact_path_recorded"]
and operator["catalog_record_postwrite_smoke_artifact_path_recorded"]
and operator["catalog_record_backup_artifact_path_recorded"]
and operator[
"operator_confirmed_report_catalog_record_final_closeout_gate"
]
and operator[
"operator_confirmed_report_catalog_record_archive_summary_reviewed"
]
and operator["operator_confirmed_catalog_record_traceability_reviewed"]
and operator["operator_confirmed_catalog_record_pipeline_complete"]
and operator[
"operator_confirmed_no_pending_catalog_record_followup"
]
and operator[
"operator_confirmed_catalog_record_final_closeout_read_only"
]
),
},
{
"key": "report_catalog_record_final_closeout_runtime_boundaries_confirmed",
"label": "操作員確認本 API 不產報表、不寫檔、不執行 CLI、不寫 DB、不派 Telegram、不呼叫 LLM、不掛 scheduler",
"passed": bool(
operator[
"operator_confirmed_no_token_in_report_catalog_record_final_closeout"
]
and operator["operator_confirmed_no_api_report_generation"]
and operator["operator_confirmed_no_api_file_write"]
and operator["operator_confirmed_no_api_cli_execution"]
and operator["operator_confirmed_no_api_catalog_record_write"]
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_catalog_record_final_closeout_no_token_submitted_to_api",
"label": "final closeout gate payload 不得包含 approval 或 Telegram token key",
"passed": not operator["forbidden_token_submitted_to_api"],
},
{
"key": "report_catalog_record_final_closeout_apply_real_write_not_requested_from_api",
"label": "API/UI report catalog record final closeout gate 不接受 apply_real_write",
"passed": not apply_real_write,
},
]
def build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout(
*,
telegram_dispatch_report_catalog_record_archive_summary,
report_catalog_record_final_closeout=None,
operator_evidence=None,
execute_requested=False,
apply_real_write=False,
):
"""建立 Telegram dispatch report catalog record final closeout gate不執行副作用。"""
summary = _archive_summary_snapshot(
telegram_dispatch_report_catalog_record_archive_summary
)
operator = _operator_summary(operator_evidence, report_catalog_record_final_closeout)
sections = _closeout_sections(summary, operator)
gates = _closeout_gates(summary, 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_catalog_record_final_closeout_preview",
"target_table": TARGET_TABLE,
"target_column": TARGET_COLUMN,
"target_json_path": [
"market_intel_ai_summary",
"telegram_dispatch_report_catalog_record_final_closeout",
],
"target_operation": "close_manual_market_intel_report_catalog_record_pipeline",
"execute_requested": bool(execute_requested),
"apply_real_write_requested": bool(apply_real_write),
"report_catalog_record_final_closeout_reviewed": True,
"telegram_dispatch_report_catalog_record_final_closeout_passed": closeout_passed,
"summary_persistence_telegram_dispatch_report_catalog_record_final_closeout_passed": closeout_passed,
"report_catalog_record_final_closeout_passed": closeout_passed,
"market_intel_report_catalog_record_pipeline_complete": closeout_passed,
"ready_for_next_manual_phase": False,
"ready_for_market_intel_report_catalog_record_final_closeout": False,
"ready_for_market_intel_report_catalog_record_archive_summary": False,
"ready_for_market_intel_report_catalog_record_archive": False,
"ready_for_market_intel_report_catalog_record_closeout": False,
"ready_for_market_intel_report_catalog_record_commit": False,
"ready_for_market_intel_report_catalog_record_cli_run": False,
"ready_for_cli_operator_run": False,
"ready_for_real_write": False,
"ready_for_report_generation": False,
"ready_for_telegram_dispatch": False,
"ready_for_api_database_write": False,
"ready_for_scheduler_attach": False,
"ready_for_llm_call": False,
"api_executes_cli": False,
"api_executes_llm": False,
"api_dispatches_telegram": False,
"api_reads_approval_token": False,
"api_writes_file": False,
"api_writes_database": False,
"api_updates_review_state": False,
**{key: False for key in FALSE_RESPONSE_KEYS},
"statement_count": summary["writer_statement_count"]
or summary["statement_count"],
"expected_summary_payload_hash": summary["expected_summary_payload_hash"],
"blocked_reasons": blocked_reasons,
"gates": gates,
"telegram_dispatch_report_catalog_record_archive_summary": summary,
"telegram_dispatch_report_catalog_record_final_closeout_sections": sections,
"operator_telegram_dispatch_report_catalog_record_final_closeout": operator,
"promotion_gate": {
"allowed": closeout_passed,
"next_manual_phase": "market_intel_report_catalog_record_pipeline_complete",
"terminal_gate": True,
"requires_real_db_write": False,
"requires_cli_run": False,
"requires_scheduler_attach": False,
"requires_operator_approval": True,
"requires_postwrite_smoke": False,
"api_must_not_generate_report": True,
"api_must_not_write_file": True,
"api_must_not_execute_cli": True,
"api_must_not_write_catalog_record": True,
"api_must_not_write_database": True,
"api_must_not_dispatch_telegram": True,
"api_must_not_commit_catalog_record": True,
"report_catalog_record_pipeline_complete_no_separate_api_gate": True,
},
"next_operator_steps": [
"保存 report catalog record final closeout artifact path",
"確認 catalog record pipeline 已完成且沒有待補 DB write、Telegram dispatch 或 report generation",
"將後續工作轉為人工營運檢視,不從 API/UI 觸發任何寫入或派送",
"若未來需要重開流程,必須從新的獨立 gate 與人工核准開始",
],
"safe_boundaries": [
"do_not_read_approval_token_from_report_catalog_record_final_closeout_api",
"do_not_read_telegram_token_from_report_catalog_record_final_closeout_api",
"do_not_call_llm_from_report_catalog_record_final_closeout",
"do_not_generate_report_from_report_catalog_record_final_closeout_api",
"do_not_write_report_catalog_record_final_closeout_artifact_from_api",
"do_not_execute_catalog_record_cli_from_report_catalog_record_final_closeout_api",
"do_not_write_report_catalog_record_from_report_catalog_record_final_closeout_api",
"do_not_commit_catalog_record_from_report_catalog_record_final_closeout_api",
"do_not_dispatch_telegram_from_report_catalog_record_final_closeout_api",
"do_not_open_database_connection_from_report_catalog_record_final_closeout",
"do_not_update_review_state_from_report_catalog_record_final_closeout",
"do_not_attach_scheduler_from_report_catalog_record_final_closeout",
"market_intel_report_catalog_record_pipeline_terminal_preview_only",
"no_remove_orphans",
"no_momo_db_lifecycle_change",
],
}

View File

@@ -55,6 +55,7 @@ from services.market_intel.candidate_queue_review_ai_summary_persistence_telegra
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout
from services.market_intel.candidate_queue_review_ai_summary_persistence_transaction import build_candidate_queue_review_ai_summary_persistence_transaction
from services.market_intel.candidate_queue_review_ai_summary_persistence_writer_preflight import build_candidate_queue_review_ai_summary_persistence_writer_preflight
from services.market_intel.candidate_queue_review_ai_summary_run_package import build_candidate_queue_review_ai_summary_run_package
@@ -86,7 +87,7 @@ BLOCKED_RUN_REVIEW_KEYS = (
"telegram_dispatch_report_closeout_file_written",
"report_closeout_file_written",
"telegram_dispatch_report_archive_file_written", "report_archive_file_written", "report_archive_record_written", "report_archive_manifest_written", "telegram_dispatch_report_archive_summary_file_written", "report_archive_summary_file_written", "report_summary_input_file_written", "telegram_dispatch_report_catalog_handoff_file_written", "report_catalog_handoff_file_written", "catalog_handoff_file_written", "telegram_dispatch_report_catalog_index_file_written", "report_catalog_index_file_written", "catalog_index_file_written", "report_catalog_index_manifest_written", "catalog_index_manifest_written", "catalog_index_written", "catalog_manifest_written", "catalog_record_written", "report_catalog_record_written", "report_archive_summary_catalog_handoff_file_written", "telegram_dispatch_report_catalog_write_preflight_file_written", "report_catalog_write_preflight_file_written", "catalog_write_preflight_file_written", "catalog_record_write_preflight_file_written", "telegram_dispatch_report_catalog_record_write_file_written", "report_catalog_record_write_file_written", "catalog_record_write_file_written", "catalog_record_write_executed", "report_catalog_record_write_executed", "telegram_dispatch_report_catalog_record_write_gate_file_written", "report_catalog_record_write_gate_file_written", "catalog_record_write_gate_file_written", "telegram_dispatch_report_catalog_record_run_package_file_written", "report_catalog_record_run_package_file_written", "catalog_record_run_package_file_written", "catalog_record_write_receipt_file_written", "catalog_record_postwrite_smoke_executed", "catalog_record_commit_executed", "telegram_dispatch_report_catalog_record_run_readiness_file_written", "report_catalog_record_run_readiness_file_written", "catalog_record_run_readiness_file_written", "telegram_dispatch_report_catalog_record_run_readiness_gate_file_written", "report_catalog_record_run_readiness_gate_file_written", "catalog_record_run_readiness_gate_file_written", "catalog_record_run_readiness_executed", "catalog_record_run_receipt_written", "catalog_record_postwrite_smoke_written", "telegram_dispatch_report_catalog_record_run_receipt_gate_file_written", "report_catalog_record_run_receipt_gate_file_written", "catalog_record_run_receipt_gate_file_written", "catalog_record_run_receipt_executed", "catalog_record_commit_gate_file_written", "telegram_dispatch_report_catalog_record_run_receipt_file_written", "report_catalog_record_run_receipt_file_written", "catalog_record_run_receipt_file_written", "catalog_record_cli_executed", "catalog_record_writer_cli_executed", "catalog_record_postwrite_smoke_file_written",
"telegram_dispatch_report_catalog_record_commit_gate_file_written", "report_catalog_record_commit_gate_file_written", "telegram_dispatch_report_catalog_record_commit_file_written", "report_catalog_record_commit_file_written", "catalog_record_commit_file_written", "catalog_record_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_closeout_gate_file_written", "report_catalog_record_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_closeout_file_written", "report_catalog_record_closeout_file_written", "catalog_record_closeout_file_written", "catalog_record_closeout_executed", "catalog_record_archive_gate_file_written", "telegram_dispatch_report_catalog_record_archive_gate_file_written", "report_catalog_record_archive_gate_file_written", "telegram_dispatch_report_catalog_record_archive_file_written", "report_catalog_record_archive_file_written", "catalog_record_archive_file_written", "catalog_record_archive_record_written", "catalog_record_archive_manifest_written", "catalog_record_archive_executed", "catalog_record_archive_summary_gate_file_written", "telegram_dispatch_report_catalog_record_archive_summary_gate_file_written", "report_catalog_record_archive_summary_gate_file_written", "telegram_dispatch_report_catalog_record_archive_summary_file_written", "report_catalog_record_archive_summary_file_written", "catalog_record_archive_summary_file_written", "catalog_record_archive_summary_record_written", "catalog_record_archive_summary_executed", "catalog_record_final_closeout_gate_file_written",
"telegram_dispatch_report_catalog_record_commit_gate_file_written", "report_catalog_record_commit_gate_file_written", "telegram_dispatch_report_catalog_record_commit_file_written", "report_catalog_record_commit_file_written", "catalog_record_commit_file_written", "catalog_record_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_closeout_gate_file_written", "report_catalog_record_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_closeout_file_written", "report_catalog_record_closeout_file_written", "catalog_record_closeout_file_written", "catalog_record_closeout_executed", "catalog_record_archive_gate_file_written", "telegram_dispatch_report_catalog_record_archive_gate_file_written", "report_catalog_record_archive_gate_file_written", "telegram_dispatch_report_catalog_record_archive_file_written", "report_catalog_record_archive_file_written", "catalog_record_archive_file_written", "catalog_record_archive_record_written", "catalog_record_archive_manifest_written", "catalog_record_archive_executed", "catalog_record_archive_summary_gate_file_written", "telegram_dispatch_report_catalog_record_archive_summary_gate_file_written", "report_catalog_record_archive_summary_gate_file_written", "telegram_dispatch_report_catalog_record_archive_summary_file_written", "report_catalog_record_archive_summary_file_written", "catalog_record_archive_summary_file_written", "catalog_record_archive_summary_record_written", "catalog_record_archive_summary_executed", "catalog_record_final_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_final_closeout_gate_file_written", "report_catalog_record_final_closeout_gate_file_written", "telegram_dispatch_report_catalog_record_final_closeout_file_written", "report_catalog_record_final_closeout_file_written", "catalog_record_final_closeout_file_written", "catalog_record_final_closeout_record_written", "catalog_record_final_closeout_executed", "catalog_record_pipeline_completion_record_written", "market_intel_catalog_record_pipeline_completed_by_api",
"summary_persistence_record_written",
"metadata_patch_written",
"transaction_file_written",
@@ -127,6 +128,14 @@ PRODUCTION_SMOKE_TARGETS = (
)
+ PRODUCTION_SMOKE_TARGETS[-1:]
)
PRODUCTION_SMOKE_TARGETS = (
PRODUCTION_SMOKE_TARGETS[:-1]
+ (
"/api/market_intel/manual_sample_review/"
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout",
)
+ PRODUCTION_SMOKE_TARGETS[-1:]
)
def _run_review_preview_safe(payload, mode):
return bool(payload["mode"] == mode and all(not payload.get(key) for key in BLOCKED_RUN_REVIEW_KEYS))
def build_deployment_readiness_preview(*, service, market_intel_tables, schema_smoke_builder):
@@ -307,6 +316,7 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout(telegram_dispatch_report_catalog_record_commit=candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_commit)
candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive(telegram_dispatch_report_catalog_record_closeout=candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout)
candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary(telegram_dispatch_report_catalog_record_archive=candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive)
candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout(telegram_dispatch_report_catalog_record_archive_summary=candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary)
checks = {
"schema_smoke_passed": bool(schema_smoke["passed"]),
"feature_flags_default_safe": bool(
@@ -569,6 +579,7 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout_preview"),
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_preview"),
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary_preview"),
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout_preview"),
"candidate_queue_review_decision_writer_cli_status_safe": _run_review_preview_safe(candidate_queue_review_decision_writer_status, "candidate_queue_review_decision_writer_cli_blocked"),
"match_review_plan_preview_safe": bool(
match_review_plan["mode"] == "match_review_plan_preview"
@@ -847,6 +858,7 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout": candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout,
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive": candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive,
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary": candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary,
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout": candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout,
"candidate_queue_review_decision_writer_status": candidate_queue_review_decision_writer_status,
"match_review_plan": match_review_plan,
"opportunity_plan": opportunity_plan,

View File

@@ -1,3 +1,3 @@
"""市場情報 rollout phase 單一來源。"""
MARKET_INTEL_PHASE = "phase_114_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary"
MARKET_INTEL_PHASE = "phase_115_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_closeout"

View File

@@ -781,6 +781,9 @@
<button class="market-intel-icon-button" type="button" title="整理 queue review AI summary Telegram dispatch report catalog record archive summary gate" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-archive-summary>
<i class="fas fa-file-signature" aria-hidden="true"></i>
</button>
<button class="market-intel-icon-button" type="button" title="收尾 queue review AI summary Telegram dispatch report catalog record final closeout gate" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-final-closeout>
<i class="fas fa-circle-check" aria-hidden="true"></i>
</button>
</div>
</div>
</div>
@@ -1169,6 +1172,7 @@
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordCloseout = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-closeout]') : null;
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchive = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-archive]') : null;
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveSummary = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-archive-summary]') : null;
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-report-catalog-record-final-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') }}";
@@ -1234,6 +1238,7 @@
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordCloseoutEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_closeout') }}";
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive') }}";
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveSummaryEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_archive_summary') }}";
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseoutEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_report_catalog_record_final_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;
@@ -9636,6 +9641,154 @@
}
};
const renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout = data => {
const blockers = (data.blocked_reasons || []).join(' / ');
const gates = data.gates || [];
const summary = data.telegram_dispatch_report_catalog_record_archive_summary || {};
const operator = data.operator_telegram_dispatch_report_catalog_record_final_closeout || {};
const promotion = data.promotion_gate || {};
const sections = data.telegram_dispatch_report_catalog_record_final_closeout_sections || [];
sampleReviewMeta.innerHTML = [
`mode=${data.mode || 'unknown'}`,
`closeout=${data.telegram_dispatch_report_catalog_record_final_closeout_passed ? 'pass' : 'blocked'}`,
`summary=${summary.archive_summary_passed ? 'pass' : 'blocked'}`,
`complete=${data.market_intel_report_catalog_record_pipeline_complete ? 'yes' : 'blocked'}`,
`file=${data.catalog_record_final_closeout_file_written ? 'written' : 'blocked'}`
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
sampleReviewBody.innerHTML = `
<div class="market-intel-empty mb-3">此卡只審核 Telegram dispatch report catalog record final closeout gateAPI/UI 不讀 token、不產報表、不寫檔、不執行 CLI、不開 DB、不寫 catalog record、不執行 commit、不派 Telegram、不掛 scheduler。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
<div class="market-intel-deploy-grid">
<div>
<p class="market-intel-deploy-section-title">FINAL 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">尚未提供 final closeout gate。</div>'
}</div>
</div>
<div>
<p class="market-intel-deploy-section-title">ARCHIVE SUMMARY</p>
<div class="market-intel-check-list">
${[
['provided', summary.provided],
['mode', summary.mode || 'missing'],
['passed', summary.archive_summary_passed],
['record_key', summary.writer_catalog_record_key || 'missing'],
['sections', summary.summary_sections_complete],
['safe_boundaries', summary.safe_boundaries_complete]
].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">SECTIONS</p>
<div class="market-intel-operation-list">${
sections.map(section => `
<article class="market-intel-operation">
<strong>${escapeHtml(section.key || 'section')}</strong>
<small>${escapeHtml((section.facts || []).join(' / '))}</small>
</article>
`).join('') || '<div class="market-intel-empty">尚未提供 final closeout sections。</div>'
}</div>
</div>
<div>
<p class="market-intel-deploy-section-title">OPERATOR</p>
<div class="market-intel-check-list">
${[
['final_path', operator.report_catalog_record_final_closeout_artifact_path || 'missing'],
['summary_path', operator.report_catalog_record_archive_summary_artifact_path_recorded],
['traceability', operator.operator_confirmed_catalog_record_traceability_reviewed],
['pipeline', operator.operator_confirmed_catalog_record_pipeline_complete],
['no_followup', operator.operator_confirmed_no_pending_catalog_record_followup],
['read_only', operator.operator_confirmed_catalog_record_final_closeout_read_only]
].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</p>
<div class="market-intel-check-list">
${[
['api_report', data.ready_for_report_generation],
['api_file', data.api_writes_file],
['api_cli', data.api_executes_cli],
['api_db', data.api_writes_database],
['final_exec', data.catalog_record_final_closeout_executed],
['scheduler', data.scheduler_attached]
].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">
${[
['next_phase', promotion.next_manual_phase || 'missing'],
['terminal', promotion.terminal_gate],
['api_commit', promotion.api_must_not_commit_catalog_record],
['api_write', promotion.api_must_not_write_database],
['api_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 loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout = 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 catalog record final closeout gate 中...</div>';
try {
const response = await fetch(`${sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseoutEndpoint}?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}`);
renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout(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 catalog record final closeout gate 失敗:${escapeHtml(error.message)}</div>`;
}
};
const renderCandidateQueueReviewDecisionWriter = data => {
const blockers = (data.blocked_reasons || []).join(' / ');
const summary = data.statement_summary || {};
@@ -11432,6 +11585,9 @@
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveSummary) {
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveSummary.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordArchiveSummary);
}
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout) {
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchReportCatalogRecordFinalCloseout);
}
if (schedulerRefresh) {
schedulerRefresh.addEventListener('click', loadScheduler);
}

File diff suppressed because it is too large Load Diff