新增市場情報 AI summary Telegram dispatch archive summary
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
This commit is contained in:
@@ -320,7 +320,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
|
||||
# ==========================================
|
||||
# 系統版本與路徑
|
||||
# ==========================================
|
||||
SYSTEM_VERSION = "V10.318"
|
||||
SYSTEM_VERSION = "V10.319"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -221,6 +221,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch run receipt:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt` 審核人工 Telegram 派送後貼回的 message id、channel、summary hash、receipt artifact 與 token 外洩風險。此 receipt 只允許放行到後續 Telegram dispatch closeout;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch closeout:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout` 在人工 Telegram receipt 通過後整理 closeout artifact、receipt archive、message visibility、duplicate dispatch 與 post-closeout monitoring gate。此 closeout 只允許放行到後續封存/報表 gate;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch archive:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive` 在 closeout 通過後整理 message id、channel、summary hash、receipt/closeout/message preview/archive artifact path 與 duplicate/monitoring audit manifest。此 archive 只輸出封存預覽並放行到後續 archive summary / 報表輸入 gate;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler。
|
||||
- 2026-05-20 追加 candidate queue review AI summary persistence Telegram dispatch archive summary:`services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary` 與 `/api/market_intel/manual_sample_review/candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary` 在 archive 通過後整理 message identity、dispatch audit、artifact manifest 與後續 report input 所需 sections。此 archive summary 只準備報表/summary input;API/UI 不讀 approval/Telegram token、不呼叫 LLM、不補發或重送 Telegram、不開 DB、不寫檔、不更新 `review_state`、不 commit、不掛 scheduler,後續報表輸入必須另開 gate。
|
||||
|
||||
### Phase 4:Coupang / Shopee Adapter
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ from services.market_intel.candidate_queue_review_ai_summary_persistence_telegra
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive import (
|
||||
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive,
|
||||
)
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary import (
|
||||
build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary,
|
||||
)
|
||||
|
||||
|
||||
def _build_ai_summary_persistence_run_readiness(
|
||||
@@ -299,6 +302,37 @@ def _build_ai_summary_persistence_telegram_dispatch_closeout(
|
||||
)
|
||||
|
||||
|
||||
def _build_ai_summary_persistence_telegram_dispatch_archive(
|
||||
*,
|
||||
service,
|
||||
sample_result,
|
||||
operator_evidence,
|
||||
writer_output,
|
||||
smoke_result,
|
||||
payload_error,
|
||||
limit,
|
||||
execute_requested,
|
||||
apply_real_write,
|
||||
):
|
||||
closeout = _build_ai_summary_persistence_telegram_dispatch_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,
|
||||
)
|
||||
return build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive(
|
||||
telegram_dispatch_closeout=closeout,
|
||||
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_run_readiness",
|
||||
@@ -536,7 +570,7 @@ 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()
|
||||
)
|
||||
closeout = _build_ai_summary_persistence_telegram_dispatch_closeout(
|
||||
data = _build_ai_summary_persistence_telegram_dispatch_archive(
|
||||
service=service,
|
||||
sample_result=sample_result,
|
||||
operator_evidence=operator_evidence,
|
||||
@@ -547,8 +581,36 @@ def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_tel
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
)
|
||||
data = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive(
|
||||
telegram_dispatch_closeout=closeout,
|
||||
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_archive_summary",
|
||||
methods=["POST"],
|
||||
)
|
||||
@login_required
|
||||
def market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary():
|
||||
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()
|
||||
)
|
||||
archive = _build_ai_summary_persistence_telegram_dispatch_archive(
|
||||
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_archive_summary(
|
||||
telegram_dispatch_archive=archive,
|
||||
operator_evidence=operator_evidence,
|
||||
execute_requested=execute_requested,
|
||||
apply_real_write=apply_real_write,
|
||||
|
||||
@@ -0,0 +1,526 @@
|
||||
"""候選審核 queue AI summary Telegram dispatch archive summary preview。
|
||||
|
||||
本模組只在 Telegram dispatch archive 通過後整理可供後續報表/summary 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"
|
||||
TARGET_TABLE = "market_alert_review_queue"
|
||||
TARGET_COLUMN = "metadata_json"
|
||||
SUMMARY_METADATA_KEY = "ai_summary_review"
|
||||
|
||||
|
||||
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 _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 _side_effects_clear(*payloads):
|
||||
blocked_keys = (
|
||||
"ready_for_telegram_dispatch",
|
||||
"ready_for_manual_telegram_dispatch",
|
||||
"ready_for_api_database_write",
|
||||
"ready_for_scheduler_attach",
|
||||
"ready_for_llm_call",
|
||||
"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_archive_file_written",
|
||||
"telegram_dispatch_archive_summary_file_written",
|
||||
"telegram_dispatch_closeout_file_written",
|
||||
"telegram_dispatch_receipt_file_written",
|
||||
"telegram_dispatch_run_receipt_file_written",
|
||||
"telegram_message_file_written",
|
||||
"archive_file_written",
|
||||
"archive_record_written",
|
||||
"archive_manifest_written",
|
||||
"archive_summary_file_written",
|
||||
"summary_file_written",
|
||||
"summary_record_written",
|
||||
"summary_manifest_written",
|
||||
"ai_summary_generated",
|
||||
"llm_call_executed",
|
||||
"ollama_call_executed",
|
||||
"gemini_call_executed",
|
||||
"telegram_dispatched",
|
||||
"telegram_dispatch_attempted",
|
||||
"external_network_executed",
|
||||
"database_connection_opened",
|
||||
"database_write_executed",
|
||||
"database_commit_executed",
|
||||
"review_state_update_executed",
|
||||
"scheduler_attached",
|
||||
"writes_executed",
|
||||
"would_write_database",
|
||||
)
|
||||
return all(
|
||||
not _as_dict(payload).get(key)
|
||||
for payload in payloads
|
||||
for key in blocked_keys
|
||||
)
|
||||
|
||||
|
||||
def _archive_payload_summary(telegram_dispatch_archive):
|
||||
archive = _as_dict(telegram_dispatch_archive)
|
||||
manifest = _as_dict(archive.get("telegram_dispatch_archive_manifest"))
|
||||
message = _as_dict(manifest.get("telegram_message"))
|
||||
audit = _as_dict(manifest.get("dispatch_audit"))
|
||||
artifact_paths = _as_dict(manifest.get("artifact_paths"))
|
||||
closeout = _as_dict(archive.get("telegram_dispatch_closeout_summary"))
|
||||
blocked_reasons = _as_list(archive.get("blocked_reasons"))
|
||||
|
||||
return {
|
||||
"provided": bool(archive),
|
||||
"mode": archive.get("mode"),
|
||||
"target_operation": archive.get("target_operation"),
|
||||
"telegram_dispatch_archive_ready": bool(
|
||||
archive.get("telegram_dispatch_archive_ready")
|
||||
),
|
||||
"summary_persistence_telegram_dispatch_archive_ready": bool(
|
||||
archive.get("summary_persistence_telegram_dispatch_archive_ready")
|
||||
),
|
||||
"archive_manifest_ready": bool(archive.get("archive_manifest_ready")),
|
||||
"ready_for_summary_persistence_telegram_dispatch_archive_summary": bool(
|
||||
archive.get(
|
||||
"ready_for_summary_persistence_telegram_dispatch_archive_summary"
|
||||
)
|
||||
),
|
||||
"ready_for_next_manual_phase": bool(archive.get("ready_for_next_manual_phase")),
|
||||
"statement_count": _safe_int(archive.get("statement_count")),
|
||||
"expected_summary_payload_hash": archive.get("expected_summary_payload_hash"),
|
||||
"blocked_count": len(blocked_reasons),
|
||||
"closeout_mode": closeout.get("mode"),
|
||||
"closeout_passed": bool(closeout.get("closeout_passed")),
|
||||
"message": {
|
||||
"message_id": _safe_text(message.get("message_id"), 120),
|
||||
"chat_id": _safe_text(message.get("chat_id"), 120),
|
||||
"telegram_channel_label": _safe_text(
|
||||
message.get("telegram_channel_label"),
|
||||
180,
|
||||
),
|
||||
"summary_payload_hash": _safe_text(
|
||||
message.get("summary_payload_hash"),
|
||||
80,
|
||||
),
|
||||
"summary_payload_hash_matches_expected": bool(
|
||||
message.get("summary_payload_hash_matches_expected")
|
||||
),
|
||||
},
|
||||
"dispatch_audit": {
|
||||
"manual_dispatch_proven": bool(audit.get("manual_dispatch_proven")),
|
||||
"api_dispatch_blocked": bool(audit.get("api_dispatch_blocked")),
|
||||
"duplicate_dispatch_ruled_out": bool(
|
||||
audit.get("duplicate_dispatch_ruled_out")
|
||||
),
|
||||
"receipt_archived": bool(audit.get("receipt_archived")),
|
||||
"post_closeout_monitoring_confirmed": bool(
|
||||
audit.get("post_closeout_monitoring_confirmed")
|
||||
),
|
||||
},
|
||||
"artifact_paths": {
|
||||
"telegram_dispatch_receipt_artifact_path": artifact_paths.get(
|
||||
"telegram_dispatch_receipt_artifact_path"
|
||||
),
|
||||
"telegram_dispatch_closeout_artifact_path": artifact_paths.get(
|
||||
"telegram_dispatch_closeout_artifact_path"
|
||||
),
|
||||
"telegram_message_preview_artifact_path": artifact_paths.get(
|
||||
"telegram_message_preview_artifact_path"
|
||||
),
|
||||
"telegram_dispatch_archive_artifact_path": artifact_paths.get(
|
||||
"telegram_dispatch_archive_artifact_path"
|
||||
),
|
||||
},
|
||||
"safe_boundaries": _as_list(archive.get("safe_boundaries")),
|
||||
"side_effects_clear": _side_effects_clear(archive),
|
||||
}
|
||||
|
||||
|
||||
def _operator_summary(operator_evidence):
|
||||
operator_evidence = _as_dict(operator_evidence)
|
||||
return {
|
||||
"provided_keys": sorted(operator_evidence.keys()),
|
||||
"telegram_dispatch_archive_summary_artifact_path": _safe_text(
|
||||
operator_evidence.get("telegram_dispatch_archive_summary_artifact_path")
|
||||
or operator_evidence.get(
|
||||
"ai_summary_telegram_dispatch_archive_summary_artifact_path"
|
||||
)
|
||||
or operator_evidence.get("archive_summary_artifact_path")
|
||||
),
|
||||
"operator_confirmed_telegram_dispatch_archive_summary": bool(
|
||||
operator_evidence.get(
|
||||
"operator_confirmed_telegram_dispatch_archive_summary"
|
||||
)
|
||||
or operator_evidence.get(
|
||||
"operator_confirmed_ai_summary_telegram_dispatch_archive_summary"
|
||||
)
|
||||
),
|
||||
"operator_confirmed_summary_is_read_only": bool(
|
||||
operator_evidence.get("operator_confirmed_summary_is_read_only")
|
||||
or operator_evidence.get("operator_confirmed_archive_summary_is_read_only")
|
||||
or operator_evidence.get("operator_confirmed_archive_is_read_only")
|
||||
),
|
||||
"operator_confirmed_message_and_artifacts_reviewed": bool(
|
||||
operator_evidence.get("operator_confirmed_message_and_artifacts_reviewed")
|
||||
or operator_evidence.get("operator_confirmed_message_id_archived")
|
||||
),
|
||||
"operator_confirmed_dispatch_audit_reviewed": bool(
|
||||
operator_evidence.get("operator_confirmed_dispatch_audit_reviewed")
|
||||
or operator_evidence.get("operator_confirmed_dispatch_audit_archived")
|
||||
),
|
||||
"operator_confirmed_report_input_requires_separate_gate": bool(
|
||||
operator_evidence.get(
|
||||
"operator_confirmed_report_input_requires_separate_gate"
|
||||
)
|
||||
),
|
||||
"operator_confirmed_no_token_in_artifacts": bool(
|
||||
operator_evidence.get("operator_confirmed_no_token_in_artifacts")
|
||||
or operator_evidence.get("operator_confirmed_no_token_in_receipt")
|
||||
),
|
||||
"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")
|
||||
),
|
||||
"archive_summary_notes_recorded": bool(
|
||||
_safe_text(operator_evidence.get("archive_summary_notes"))
|
||||
or _safe_text(operator_evidence.get("archive_notes"))
|
||||
),
|
||||
"forbidden_token_submitted_to_api": _contains_forbidden_token_key(
|
||||
operator_evidence
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _summary_sections(archive_summary):
|
||||
message = archive_summary["message"]
|
||||
audit = archive_summary["dispatch_audit"]
|
||||
artifact_paths = archive_summary["artifact_paths"]
|
||||
artifact_count = sum(1 for value in artifact_paths.values() if value)
|
||||
return [
|
||||
{
|
||||
"key": "telegram_message_identity",
|
||||
"title": "Telegram message identity",
|
||||
"facts": [
|
||||
f"message_id={message['message_id'] or 'missing'}",
|
||||
f"chat_id={message['chat_id'] or 'missing'}",
|
||||
f"channel={message['telegram_channel_label'] or 'missing'}",
|
||||
f"summary_hash_matched={message['summary_payload_hash_matches_expected']}",
|
||||
],
|
||||
},
|
||||
{
|
||||
"key": "dispatch_audit",
|
||||
"title": "Dispatch audit",
|
||||
"facts": [
|
||||
f"manual_dispatch_proven={audit['manual_dispatch_proven']}",
|
||||
f"api_dispatch_blocked={audit['api_dispatch_blocked']}",
|
||||
f"duplicate_ruled_out={audit['duplicate_dispatch_ruled_out']}",
|
||||
f"monitoring_confirmed={audit['post_closeout_monitoring_confirmed']}",
|
||||
],
|
||||
},
|
||||
{
|
||||
"key": "artifact_manifest",
|
||||
"title": "Artifact manifest",
|
||||
"facts": [
|
||||
f"artifact_path_count={artifact_count}",
|
||||
f"statement_count={archive_summary['statement_count']}",
|
||||
],
|
||||
},
|
||||
{
|
||||
"key": "runtime_safety",
|
||||
"title": "Runtime safety",
|
||||
"facts": [
|
||||
"llm_call_executed=false",
|
||||
"telegram_dispatched=false",
|
||||
"database_write_executed=false",
|
||||
"scheduler_attached=false",
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _summary_gates(archive_summary, operator, apply_real_write):
|
||||
message = archive_summary["message"]
|
||||
audit = archive_summary["dispatch_audit"]
|
||||
artifact_paths = archive_summary["artifact_paths"]
|
||||
return [
|
||||
{
|
||||
"key": "telegram_dispatch_archive_preview_provided",
|
||||
"label": "必須提供 Telegram dispatch archive preview",
|
||||
"passed": bool(
|
||||
archive_summary["provided"]
|
||||
and archive_summary["mode"]
|
||||
== "candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_preview"
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_ready",
|
||||
"label": "Telegram dispatch archive 必須已通過",
|
||||
"passed": bool(
|
||||
archive_summary["telegram_dispatch_archive_ready"]
|
||||
and archive_summary[
|
||||
"summary_persistence_telegram_dispatch_archive_ready"
|
||||
]
|
||||
and archive_summary["archive_manifest_ready"]
|
||||
and archive_summary[
|
||||
"ready_for_summary_persistence_telegram_dispatch_archive_summary"
|
||||
]
|
||||
and archive_summary["ready_for_next_manual_phase"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_message_identity_complete",
|
||||
"label": "archive summary 必須包含 message id、chat/channel 與 hash match",
|
||||
"passed": bool(
|
||||
message["message_id"]
|
||||
and message["chat_id"]
|
||||
and message["telegram_channel_label"]
|
||||
and message["summary_payload_hash"]
|
||||
and message["summary_payload_hash_matches_expected"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_audit_complete",
|
||||
"label": "archive summary 必須保留人工派送、API 未派送、無重複與監控證據",
|
||||
"passed": bool(
|
||||
audit["manual_dispatch_proven"]
|
||||
and audit["api_dispatch_blocked"]
|
||||
and audit["duplicate_dispatch_ruled_out"]
|
||||
and audit["receipt_archived"]
|
||||
and audit["post_closeout_monitoring_confirmed"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_artifact_paths_complete",
|
||||
"label": "receipt、closeout、message preview 與 archive artifact path 必須齊備",
|
||||
"passed": all(artifact_paths.values()),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_side_effects_clear",
|
||||
"label": "archive payload 不得顯示 Telegram、DB、LLM、檔案或 scheduler 副作用",
|
||||
"passed": archive_summary["side_effects_clear"],
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_telegram_dispatch_archive_summary",
|
||||
"label": "操作員確認本階段只整理 archive summary input",
|
||||
"passed": bool(
|
||||
operator["operator_confirmed_telegram_dispatch_archive_summary"]
|
||||
and operator["operator_confirmed_summary_is_read_only"]
|
||||
and operator["operator_confirmed_message_and_artifacts_reviewed"]
|
||||
and operator["operator_confirmed_dispatch_audit_reviewed"]
|
||||
and operator["operator_confirmed_report_input_requires_separate_gate"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_archive_summary_runtime_boundaries",
|
||||
"label": "操作員確認本階段不派送 Telegram、不寫 DB、不呼叫 LLM、不掛 scheduler",
|
||||
"passed": bool(
|
||||
operator["operator_confirmed_no_token_in_artifacts"]
|
||||
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": "telegram_dispatch_archive_summary_artifact_path_recorded",
|
||||
"label": "archive summary artifact path 必須由操作員提供",
|
||||
"passed": bool(operator["telegram_dispatch_archive_summary_artifact_path"]),
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_summary_no_token_submitted_to_api",
|
||||
"label": "archive summary payload 不得包含 approval 或 Telegram token key",
|
||||
"passed": not operator["forbidden_token_submitted_to_api"],
|
||||
},
|
||||
{
|
||||
"key": "telegram_dispatch_archive_summary_apply_real_write_not_requested_from_api",
|
||||
"label": "API/UI archive summary 不接受 apply_real_write",
|
||||
"passed": not apply_real_write,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary(
|
||||
*,
|
||||
telegram_dispatch_archive,
|
||||
operator_evidence=None,
|
||||
execute_requested=False,
|
||||
apply_real_write=False,
|
||||
):
|
||||
"""建立 Telegram dispatch archive summary gate;不執行任何副作用。"""
|
||||
archive_summary = _archive_payload_summary(telegram_dispatch_archive)
|
||||
operator = _operator_summary(operator_evidence)
|
||||
sections = _summary_sections(archive_summary)
|
||||
gates = _summary_gates(archive_summary, operator, bool(apply_real_write))
|
||||
blocked_reasons = [gate["key"] for gate in gates if not gate["passed"]]
|
||||
summary_ready = bool(not blocked_reasons)
|
||||
|
||||
return {
|
||||
"mode": "candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary_preview",
|
||||
"target_table": TARGET_TABLE,
|
||||
"target_column": TARGET_COLUMN,
|
||||
"target_json_path": [SUMMARY_METADATA_KEY],
|
||||
"target_operation": "prepare_manual_ai_summary_telegram_dispatch_archive_summary_input",
|
||||
"execute_requested": bool(execute_requested),
|
||||
"apply_real_write_requested": bool(apply_real_write),
|
||||
"archive_summary_reviewed": True,
|
||||
"telegram_dispatch_archive_summary_ready": summary_ready,
|
||||
"summary_persistence_telegram_dispatch_archive_summary_ready": summary_ready,
|
||||
"summary_input_ready": summary_ready,
|
||||
"ready_for_next_manual_phase": summary_ready,
|
||||
"ready_for_summary_persistence_telegram_dispatch_report_input": summary_ready,
|
||||
"ready_for_ai_summary_generation": False,
|
||||
"ready_for_llm_call": False,
|
||||
"ready_for_telegram_dispatch": False,
|
||||
"ready_for_manual_telegram_dispatch": False,
|
||||
"ready_for_api_database_write": False,
|
||||
"ready_for_scheduler_attach": False,
|
||||
"ready_for_real_write": 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,
|
||||
"telegram_dispatch_archive_summary_file_written": False,
|
||||
"archive_summary_file_written": False,
|
||||
"telegram_dispatch_archive_file_written": False,
|
||||
"telegram_dispatch_closeout_file_written": False,
|
||||
"telegram_dispatch_receipt_file_written": False,
|
||||
"telegram_message_file_written": False,
|
||||
"archive_file_written": False,
|
||||
"archive_record_written": False,
|
||||
"archive_manifest_written": False,
|
||||
"summary_file_written": False,
|
||||
"summary_record_written": False,
|
||||
"summary_manifest_written": False,
|
||||
"summary_persistence_record_written": False,
|
||||
"metadata_patch_written": False,
|
||||
"ai_summary_generated": False,
|
||||
"llm_call_executed": False,
|
||||
"ollama_call_executed": False,
|
||||
"gemini_call_executed": False,
|
||||
"telegram_dispatched": False,
|
||||
"telegram_dispatch_attempted": False,
|
||||
"review_state_update_executed": False,
|
||||
"read_only_query_executed": False,
|
||||
"database_connection_opened": False,
|
||||
"database_session_created": False,
|
||||
"explicit_transaction_opened": False,
|
||||
"transaction_opened": False,
|
||||
"transaction_committed": False,
|
||||
"database_write_executed": False,
|
||||
"database_commit_executed": False,
|
||||
"database_rollback_executed": False,
|
||||
"external_network_executed": False,
|
||||
"scheduler_attached": False,
|
||||
"writes_executed": False,
|
||||
"would_write_database": False,
|
||||
"statement_count": archive_summary["statement_count"],
|
||||
"expected_summary_payload_hash": archive_summary[
|
||||
"expected_summary_payload_hash"
|
||||
],
|
||||
"blocked_reasons": blocked_reasons,
|
||||
"gates": gates,
|
||||
"telegram_dispatch_archive_summary": archive_summary,
|
||||
"telegram_dispatch_archive_summary_sections": sections,
|
||||
"operator_telegram_dispatch_archive_summary": operator,
|
||||
"promotion_gate": {
|
||||
"allowed": summary_ready,
|
||||
"next_manual_phase": "summary_persistence_telegram_dispatch_report_input",
|
||||
"requires_real_db_write": False,
|
||||
"requires_scheduler_attach": False,
|
||||
"requires_operator_approval": True,
|
||||
"future_report_input_requires_separate_gate": True,
|
||||
"api_must_not_dispatch_telegram": True,
|
||||
},
|
||||
"next_operator_steps": [
|
||||
"保存 Telegram dispatch archive summary artifact path",
|
||||
"確認 summary sections 只包含 message identity、audit 與 artifact path 摘要",
|
||||
"後續若要輸出報表或週報輸入,必須另開 report input gate",
|
||||
"不得從 archive summary API 呼叫 LLM、補發 Telegram、寫 DB 或寫 artifact",
|
||||
],
|
||||
"safe_boundaries": [
|
||||
"do_not_read_approval_token_from_telegram_dispatch_archive_summary_api",
|
||||
"do_not_read_telegram_token_from_telegram_dispatch_archive_summary_api",
|
||||
"do_not_call_llm_from_telegram_dispatch_archive_summary",
|
||||
"do_not_dispatch_telegram_from_telegram_dispatch_archive_summary_api",
|
||||
"do_not_retry_telegram_dispatch_from_archive_summary_api",
|
||||
"do_not_open_database_connection_from_telegram_dispatch_archive_summary",
|
||||
"do_not_write_archive_summary_artifact_from_api",
|
||||
"do_not_update_review_state_from_telegram_dispatch_archive_summary",
|
||||
"do_not_attach_scheduler_from_telegram_dispatch_archive_summary",
|
||||
"future_report_input_must_use_separate_gate",
|
||||
"telegram_dispatch_archive_summary_preview_only",
|
||||
"no_remove_orphans",
|
||||
"no_momo_db_lifecycle_change",
|
||||
],
|
||||
}
|
||||
@@ -36,6 +36,7 @@ from services.market_intel.candidate_queue_review_ai_summary_persistence_telegra
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive
|
||||
from services.market_intel.candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary import build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary
|
||||
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
|
||||
@@ -63,7 +64,7 @@ BLOCKED_RUN_REVIEW_KEYS = (
|
||||
"summary_persistence_transaction_file_written",
|
||||
"summary_persistence_writer_preflight_file_written",
|
||||
"summary_persistence_run_package_file_written",
|
||||
"summary_persistence_run_readiness_file_written", "run_readiness_file_written", "summary_persistence_run_receipt_file_written", "run_receipt_file_written", "receipt_file_written", "summary_persistence_closeout_file_written", "closeout_file_written", "telegram_dispatch_gate_file_written", "telegram_dispatch_run_package_file_written", "telegram_dispatch_run_readiness_file_written", "telegram_dispatch_run_receipt_file_written", "telegram_dispatch_receipt_file_written", "telegram_dispatch_closeout_file_written", "telegram_dispatch_archive_file_written", "telegram_message_file_written", "archive_file_written", "archive_record_written", "archive_manifest_written",
|
||||
"summary_persistence_run_readiness_file_written", "run_readiness_file_written", "summary_persistence_run_receipt_file_written", "run_receipt_file_written", "receipt_file_written", "summary_persistence_closeout_file_written", "closeout_file_written", "telegram_dispatch_gate_file_written", "telegram_dispatch_run_package_file_written", "telegram_dispatch_run_readiness_file_written", "telegram_dispatch_run_receipt_file_written", "telegram_dispatch_receipt_file_written", "telegram_dispatch_closeout_file_written", "telegram_dispatch_archive_file_written", "telegram_dispatch_archive_summary_file_written", "telegram_message_file_written", "archive_file_written", "archive_record_written", "archive_manifest_written", "archive_summary_file_written",
|
||||
"summary_persistence_record_written",
|
||||
"metadata_patch_written",
|
||||
"transaction_file_written",
|
||||
@@ -87,7 +88,7 @@ BLOCKED_RUN_REVIEW_KEYS = (
|
||||
"writes_executed",
|
||||
"would_write_database",
|
||||
)
|
||||
PRODUCTION_SMOKE_TARGETS = ("/health", "/market_intel", "/api/market_intel/status", "/api/market_intel/deployment_readiness", "/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/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/migration_apply_drill", "/api/market_intel/migration_catalog_review", "/api/market_intel/migration_live_smoke", "/api/market_intel/live_db_inventory", "/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/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_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", "/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", "/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_decision_writer_status")
|
||||
PRODUCTION_SMOKE_TARGETS = ("/health", "/market_intel", "/api/market_intel/status", "/api/market_intel/deployment_readiness", "/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/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/migration_apply_drill", "/api/market_intel/migration_catalog_review", "/api/market_intel/migration_live_smoke", "/api/market_intel/live_db_inventory", "/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/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_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", "/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", "/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", "/api/market_intel/manual_sample_review/candidate_queue_review_decision_writer_status")
|
||||
|
||||
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))
|
||||
@@ -257,6 +258,7 @@ def build_deployment_readiness_preview(
|
||||
candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt(telegram_dispatch_run_readiness=candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_readiness)
|
||||
candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout(telegram_dispatch_run_receipt=candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt)
|
||||
candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive(telegram_dispatch_closeout=candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout)
|
||||
candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary = build_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary(telegram_dispatch_archive=candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive)
|
||||
checks = {
|
||||
"schema_smoke_passed": bool(schema_smoke["passed"]),
|
||||
"feature_flags_default_safe": bool(
|
||||
@@ -500,6 +502,7 @@ def build_deployment_readiness_preview(
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt_preview"),
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout_preview"),
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_preview"),
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary_preview_safe": _run_review_preview_safe(candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary, "candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary_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",
|
||||
@@ -762,6 +765,7 @@ def build_deployment_readiness_preview(
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt": candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt,
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout": candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout,
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive": candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive,
|
||||
"candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary": candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary,
|
||||
"candidate_queue_review_decision_writer_status": candidate_queue_review_decision_writer_status,
|
||||
"match_review_plan": match_review_plan,
|
||||
"opportunity_plan": opportunity_plan,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""市場情報 rollout phase 單一來源。"""
|
||||
|
||||
MARKET_INTEL_PHASE = "phase_95_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive"
|
||||
MARKET_INTEL_PHASE = "phase_96_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary"
|
||||
|
||||
@@ -724,6 +724,9 @@
|
||||
<button class="market-intel-icon-button" type="button" title="封存 queue review AI summary Telegram dispatch archive" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-archive>
|
||||
<i class="fas fa-folder-tree" aria-hidden="true"></i>
|
||||
</button>
|
||||
<button class="market-intel-icon-button" type="button" title="整理 queue review AI summary Telegram dispatch archive summary" data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-archive-summary>
|
||||
<i class="fas fa-file-lines" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1093,6 +1096,7 @@
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchRunReceipt = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-run-receipt]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchCloseout = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-closeout]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchive = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-archive]') : null;
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary = sampleReviewRoot ? sampleReviewRoot.querySelector('[data-market-intel-sample-candidate-queue-review-ai-summary-persistence-telegram-dispatch-archive-summary]') : 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') }}";
|
||||
@@ -1139,6 +1143,7 @@
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchRunReceiptEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_run_receipt') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchCloseoutEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_closeout') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive') }}";
|
||||
const sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummaryEndpoint = "{{ url_for('market_intel_review.market_intel_manual_sample_candidate_queue_review_ai_summary_persistence_telegram_dispatch_archive_summary') }}";
|
||||
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;
|
||||
@@ -6762,6 +6767,146 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const gates = data.gates || [];
|
||||
const archive = data.telegram_dispatch_archive_summary || {};
|
||||
const message = archive.message || {};
|
||||
const audit = archive.dispatch_audit || {};
|
||||
const operator = data.operator_telegram_dispatch_archive_summary || {};
|
||||
const sections = data.telegram_dispatch_archive_summary_sections || [];
|
||||
sampleReviewMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`summary=${data.telegram_dispatch_archive_summary_ready ? 'ready' : 'blocked'}`,
|
||||
`report=${data.ready_for_summary_persistence_telegram_dispatch_report_input ? 'ready' : 'blocked'}`,
|
||||
`message=${message.message_id || 'missing'}`,
|
||||
`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 archive summary input;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">SUMMARY 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">尚未提供 archive summary gate。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">ARCHIVE INPUT</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['provided', archive.provided],
|
||||
['mode', archive.mode || 'missing'],
|
||||
['archive_ready', archive.telegram_dispatch_archive_ready],
|
||||
['manifest_ready', archive.archive_manifest_ready],
|
||||
['statement_count', archive.statement_count || 0],
|
||||
['side_effects_clear', archive.side_effects_clear]
|
||||
].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">MESSAGE / AUDIT</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['message_id', message.message_id || 'missing'],
|
||||
['chat_id', message.chat_id || 'missing'],
|
||||
['channel', message.telegram_channel_label || 'missing'],
|
||||
['hash_match', message.summary_payload_hash_matches_expected],
|
||||
['manual_dispatch', audit.manual_dispatch_proven],
|
||||
['api_blocked', audit.api_dispatch_blocked],
|
||||
['duplicate_ruled_out', audit.duplicate_dispatch_ruled_out],
|
||||
['monitoring', audit.post_closeout_monitoring_confirmed]
|
||||
].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">SUMMARY SECTIONS</p>
|
||||
<div class="market-intel-check-list">${
|
||||
sections.map(section => `
|
||||
<div class="market-intel-check">
|
||||
<div>
|
||||
<strong>${escapeHtml(section.key || 'section')}</strong>
|
||||
<small>${escapeHtml((section.facts || []).join(' / '))}</small>
|
||||
</div>
|
||||
<span>INPUT</span>
|
||||
</div>
|
||||
`).join('') || '<div class="market-intel-empty">尚未提供 summary sections。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div>
|
||||
<p class="market-intel-deploy-section-title">OPERATOR SUMMARY</p>
|
||||
<div class="market-intel-check-list">
|
||||
${[
|
||||
['summary_confirmed', operator.operator_confirmed_telegram_dispatch_archive_summary],
|
||||
['read_only', operator.operator_confirmed_summary_is_read_only],
|
||||
['artifacts_reviewed', operator.operator_confirmed_message_and_artifacts_reviewed],
|
||||
['audit_reviewed', operator.operator_confirmed_dispatch_audit_reviewed],
|
||||
['separate_report_gate', operator.operator_confirmed_report_input_requires_separate_gate],
|
||||
['no_token', operator.operator_confirmed_no_token_in_artifacts],
|
||||
['no_api_dispatch', operator.operator_confirmed_no_api_telegram_dispatch],
|
||||
['no_db_llm_scheduler', operator.operator_confirmed_no_api_db_write && operator.operator_confirmed_no_llm_call && operator.operator_confirmed_no_scheduler_attach],
|
||||
['summary_path', operator.telegram_dispatch_archive_summary_artifact_path || 'missing']
|
||||
].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 loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary = 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 archive summary 中...</div>';
|
||||
try {
|
||||
const response = await fetch(`${sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummaryEndpoint}?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}`);
|
||||
renderCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary(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 archive summary 失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderCandidateQueueReviewDecisionWriter = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const summary = data.statement_summary || {};
|
||||
@@ -8501,6 +8646,9 @@
|
||||
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchive) {
|
||||
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchive.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchive);
|
||||
}
|
||||
if (sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary) {
|
||||
sampleCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary.addEventListener('click', loadCandidateQueueReviewAiSummaryPersistenceTelegramDispatchArchiveSummary);
|
||||
}
|
||||
if (schedulerRefresh) {
|
||||
schedulerRefresh.addEventListener('click', loadScheduler);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user