V10.498 add market intel queue writer run readiness gate
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
================================================================================
|
||||
|
||||
【已完成】
|
||||
- V10.498 新增市場情報 MCP Fetch Candidate Queue Writer Run Readiness 安全預覽 gate:只審核 run package review 後的操作員 readiness 證據,確認 run readiness artifact、reviewed sample、備份、read-only preflight 與 post-write smoke 路徑安全,以及 CLI-only / approval token shell-only 邊界;API 不產檔、不讀 token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler。
|
||||
- V10.497 新增市場情報 MCP Fetch Candidate Queue Writer Run Package Review 安全預覽 gate:只審核 CLI review 通過後的 operator run package 草案,要求 package id、artifact manifest、operator shell command sequence、candidate/dedupe keys 與 CLI review 對齊;API 不產檔、不讀 approval token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到 run readiness review。
|
||||
- V10.496 新增市場情報 MCP Fetch Candidate Queue Writer CLI Review 安全預覽 gate:只審核 writer preflight 後的 CLI review 草案,確認 script path、target table、preflight id、payload row count、candidate/dedupe keys 與 command argv;禁止 API 執行 CLI、禁止 `--execute` / `--apply-real-write` / `--approval-token` 進 payload,API 不讀 token、不寫檔、不開 DB、不寫 queue、不掛 scheduler。
|
||||
- V10.495 新增市場情報 MCP Fetch Candidate Queue Writer Preflight 安全預覽 gate:只審核 queue review 後的 writer preflight 草案,確認 target_table、write_mode、dedupe strategy、insert columns、payload rows 與候選 key 對齊;API 不開 DB、不執行 CLI、不建立 queue、不更新 review_state、不寫 DB、不連外、不掛 scheduler。
|
||||
|
||||
@@ -350,7 +350,7 @@ YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY', '')
|
||||
# ==========================================
|
||||
# 系統版本與路徑
|
||||
# ==========================================
|
||||
SYSTEM_VERSION = "V10.497"
|
||||
SYSTEM_VERSION = "V10.498"
|
||||
LOG_FILE_PATH = os.path.join(BASE_DIR, 'logs/system.log')
|
||||
public_url = PUBLIC_URL # 用於模板顯示
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ EwoooC 目前已有 MOMO EDM / 節慶活動資料、`promo_products`、PChome
|
||||
- 2026-05-31 追加 MCP fetch candidate queue writer preflight gate:`services.market_intel.mcp_fetch_candidate_queue_writer_preflight` 與 `/api/market_intel/mcp_fetch_candidate_queue_writer_preflight` 在 queue review 通過後審核 writer preflight 草案,檢查 `target_table=market_alert_review_queue`、`write_mode=cli_only_later`、dedupe strategy、insert columns、payload rows、候選 key 對齊、小批次上限、操作員無寫入/無連外/無 CLI/無排程確認、raw HTML/secret 外洩與 side-effect flags;API/UI 不開 DB、不執行 CLI、不建立 queue、不更新 review_state、不寫 DB、不掛 scheduler,只放行到 CLI writer review。
|
||||
- 2026-05-31 追加 MCP fetch candidate queue writer CLI review gate:`services.market_intel.mcp_fetch_candidate_queue_writer_cli_review` 與 `/api/market_intel/mcp_fetch_candidate_queue_writer_cli_review` 在 writer preflight 通過後審核 CLI review 草案,檢查 script path、target table、preflight id、payload row count、candidate/dedupe keys、`--sample-json`、`--read-only-preflight` 與 forbidden flags;API/UI 不執行 CLI、不讀 approval token、不寫檔、不開 DB、不寫 queue、不掛 scheduler,只放行到 operator run package review。
|
||||
- 2026-05-31 追加 MCP fetch candidate queue writer run package review gate:`services.market_intel.mcp_fetch_candidate_queue_writer_run_package_review` 與 `/api/market_intel/mcp_fetch_candidate_queue_writer_run_package_review` 在 CLI review 通過後審核 operator run package 草案,檢查 package identity、artifact manifest、operator shell command sequence、candidate/dedupe keys、CLI review id 與 preflight id;API/UI 不產檔、不讀 approval token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到 run readiness review。
|
||||
- 2026-05-31 追加 MCP fetch candidate queue writer run readiness gate:`services.market_intel.mcp_fetch_candidate_queue_writer_run_readiness` 與 `/api/market_intel/mcp_fetch_candidate_queue_writer_run_readiness` 在 run package review 通過後審核 operator readiness 證據,檢查 run readiness artifact、reviewed sample、備份、read-only preflight、post-write smoke 路徑、操作員覆核確認、CLI-only 與 approval token shell-only 邊界;API/UI 不產檔、不讀 approval token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到後續 run receipt review。
|
||||
- 2026-05-18 追加 scheduler attach plan preview:`services.market_intel.scheduler_plan` 與 `/api/market_intel/scheduler_plan` 描述未來 `campaign_discovery_daily`、`campaign_product_probe`、`product_match_review_seed` 三個 job 的 cadence、gate、fallback 與安全邊界。此階段不註冊 scheduler job、不啟動 crawler、不連外、不寫 DB;排程掛載必須等 migration、seed、MCP fetch gate、manual sample 與人工批准全過。
|
||||
- 2026-05-18 追加 match review plan preview:`services.market_intel.match_review_plan` 與 `/api/market_intel/match_review_plan` 定義商品比對訊號、分數門檻、`needs_review → confirmed/rejected` HITL 流程與安全邊界。此階段不建立 review queue、不自動 confirmed、不寫 `market_product_matches`、不呼叫 MCP;價格只能作為輔助訊號,不能單獨決定同品比對。
|
||||
- 2026-05-18 追加 opportunity plan preview:`services.market_intel.opportunity_plan` 與 `/api/market_intel/opportunity_plan` 定義競品低價威脅、促銷缺口、深折重疊、活動即將結束四類規則與分級策略。此階段不建立 opportunity queue、不派送 Telegram、不產生 AI 摘要、不寫 DB;高風險項必須先有 confirmed match 與 DB evidence 才能升級。
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
- 2026-05-31 追記:`services/market_intel/mcp_fetch_candidate_queue_writer_preflight.py` 目前 628 行,略過 600 行提醒門檻;暫不拆分的理由是 gate 條件、sample payload 與 side-effect blocklist 需留在單一 preview module 便於審核,下一個 writer CLI review gate 若共用相同常數再抽 `mcp_fetch_candidate_queue_writer_policy.py`。
|
||||
- 2026-05-31 追記:同步市場情報 MCP fetch candidate queue writer CLI review gate 後的 `services/market_intel/deployment_readiness.py` 行數;本次新增 `services/market_intel/mcp_fetch_candidate_queue_writer_cli_review.py` 為 591 行,仍低於 600 行提醒門檻。
|
||||
- 2026-05-31 追記:同步市場情報 MCP fetch candidate queue writer run package review gate 後的 `services/market_intel/deployment_readiness.py` 行數;本次新增 `services/market_intel/mcp_fetch_candidate_queue_writer_run_package_review.py` 為 660 行,略過 600 行提醒門檻。暫不拆分的理由是 run package gate 需要把 CLI review linkage、artifact manifest、operator shell command sequence 與 side-effect blocklist 放在單一 preview module 便於安全審核;若下一段 run readiness review 重複相同 policy,應抽出 writer policy helper。
|
||||
- 2026-05-31 追記:同步市場情報 MCP fetch candidate queue writer run readiness gate 後的 `services/market_intel/deployment_readiness.py` 行數;本次新增 `services/market_intel/mcp_fetch_candidate_queue_writer_run_readiness.py` 為 640 行,略過 600 行提醒門檻。暫不拆分的理由是 readiness gate 需同時審核上一段 run package review linkage、operator artifact path policy、CLI-only/token-only confirmation 與 side-effect blocklist;若後續 run receipt gate 再重複 policy,應抽出 `mcp_fetch_candidate_queue_writer_policy.py`。
|
||||
- 2026-05-24 追記:同步背景 Code Review 111 fallback 保護合併後的 `services/code_review_pipeline_service.py` 行數;此處只更新 inventory,不變更 Code Review 行為。
|
||||
- 2026-05-21 追記:同步 PChome/LUDEYA 商品線名稱漂移比對更新後的 `services/marketplace_product_matcher.py` 行數;此處只更新 inventory,不變更模組化決策。
|
||||
- 2026-05-21 追記:同步 MAC/Yuskin/AHC 名稱漂移與 bundle equivalent matcher 更新後的 `services/marketplace_product_matcher.py` 行數;此處只更新 inventory,不變更模組化決策。
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
- 2026-05-31 起,`V10.495` 新增市場情報 MCP Fetch Candidate Queue Writer Preflight gate:在 queue review 通過後只審核 writer preflight 草案,要求 target table、write mode、dedupe strategy、insert columns、payload rows 與候選 key 完全對齊;仍不開 DB、不執行 CLI、不建立 queue、不更新 review_state、不寫 DB、不連外、不掛 scheduler。
|
||||
- 2026-05-31 起,`V10.496` 新增市場情報 MCP Fetch Candidate Queue Writer CLI Review gate:在 writer preflight 通過後只審核 CLI review 草案,要求 script path、target table、preflight id、row count、candidate/dedupe keys 與 read-only command argv 對齊;仍不執行 CLI、不讀 approval token、不寫檔、不開 DB、不寫 queue、不掛 scheduler。
|
||||
- 2026-05-31 起,`V10.497` 新增市場情報 MCP Fetch Candidate Queue Writer Run Package Review gate:在 CLI review 通過後只審核 operator run package 草案,要求 artifact manifest、operator shell command sequence、package identity、candidate/dedupe keys 與 CLI review 對齊;仍不產檔、不讀 approval token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到 run readiness review。
|
||||
- 2026-05-31 起,`V10.498` 新增市場情報 MCP Fetch Candidate Queue Writer Run Readiness gate:在 run package review 通過後只審核 operator readiness 證據,要求 run readiness artifact、reviewed sample、備份、read-only preflight 與 post-write smoke 路徑安全,並確認 CLI-only、approval token shell-only、無 API/DB/file/scheduler 副作用;仍不產檔、不讀 token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到後續 run receipt review。
|
||||
|
||||
## 3. 12 Agent 決策信封整合
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
## 📅 詳細更新日誌 (考古存檔)
|
||||
|
||||
### 2026-05-24:PChome 近門檻身份回收第二輪
|
||||
- **V10.498 市場情報 MCP Fetch Candidate Queue Writer Run Readiness gate**: 新增 `/api/market_intel/mcp_fetch_candidate_queue_writer_run_readiness` 與 UI preview,只審核 run package review 後的 operator readiness 證據;要求 run readiness artifact、reviewed sample、備份、read-only preflight 與 post-write smoke 路徑安全,並確認 CLI-only、approval token shell-only、無 API/DB/file/scheduler 副作用。API 不產檔、不讀 token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到後續 run receipt review。
|
||||
- **V10.497 市場情報 MCP Fetch Candidate Queue Writer Run Package Review gate**: 新增 `/api/market_intel/mcp_fetch_candidate_queue_writer_run_package_review` 與 UI preview,只審核 CLI review 後的 operator run package 草案;要求 package identity、artifact manifest、operator shell command sequence、candidate/dedupe keys 與 CLI review 完全對齊,且 API 不產檔、不讀 approval token、不執行 CLI、不開 DB、不寫 queue、不掛 scheduler,只放行到 run readiness review。
|
||||
- **V10.496 市場情報 MCP Fetch Candidate Queue Writer CLI Review gate**: 新增 `/api/market_intel/mcp_fetch_candidate_queue_writer_cli_review` 與 UI preview,只審核 writer preflight 後的 CLI review 草案;要求 script path、target table、preflight id、payload row count、candidate/dedupe keys 與 command argv 完全對齊,並禁止 `--execute`、`--apply-real-write`、`--approval-token` 進 API payload,且 API 不執行 CLI、不讀 token、不寫檔、不開 DB、不寫 queue、不掛 scheduler。
|
||||
- **V10.495 市場情報 MCP Fetch Candidate Queue Writer Preflight gate**: 新增 `/api/market_intel/mcp_fetch_candidate_queue_writer_preflight` 與 UI preview,只審核 queue review 後的 writer preflight 草案;要求 `target_table=market_alert_review_queue`、`write_mode=cli_only_later`、dedupe strategy、insert columns、payload rows 與候選 key 完全對齊,且 API 不開 DB、不執行 CLI、不建立 queue、不更新 review_state、不寫 DB、不連外、不掛 scheduler。
|
||||
|
||||
@@ -34,6 +34,9 @@ from services.market_intel.mcp_fetch_candidate_queue_writer_cli_review import (
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_run_package_review import (
|
||||
build_mcp_fetch_candidate_queue_writer_run_package_review_preview,
|
||||
)
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_run_readiness import (
|
||||
build_mcp_fetch_candidate_queue_writer_run_readiness_preview,
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route("/api/market_intel/mcp_fetch_run_package", methods=["GET", "POST"])
|
||||
@@ -398,3 +401,51 @@ def market_intel_mcp_fetch_candidate_queue_writer_run_package_review():
|
||||
phase=service.phase,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@market_intel_bp.route(
|
||||
"/api/market_intel/mcp_fetch_candidate_queue_writer_run_readiness",
|
||||
methods=["GET", "POST"],
|
||||
)
|
||||
@login_required
|
||||
def market_intel_mcp_fetch_candidate_queue_writer_run_readiness():
|
||||
writer_run_package_review_package = {}
|
||||
writer_run_package_review_result = None
|
||||
operator_readiness = {}
|
||||
if request.method == "POST":
|
||||
payload = request.get_json(silent=True) or {}
|
||||
package = (
|
||||
payload.get("writer_run_readiness_package")
|
||||
or payload.get("candidate_queue_writer_run_readiness")
|
||||
or payload.get("writer_run_readiness")
|
||||
or payload.get("run_readiness")
|
||||
or payload
|
||||
)
|
||||
writer_run_package_review_package = (
|
||||
package.get("writer_run_package_review_package")
|
||||
or package.get("candidate_queue_writer_run_package_review")
|
||||
or package.get("writer_run_package_review")
|
||||
or package.get("run_package_review_package")
|
||||
or {}
|
||||
)
|
||||
writer_run_package_review_result = (
|
||||
package.get("writer_run_package_review_result")
|
||||
or package.get("mcp_fetch_candidate_queue_writer_run_package_review")
|
||||
)
|
||||
operator_readiness = (
|
||||
package.get("operator_readiness")
|
||||
or package.get("writer_run_readiness")
|
||||
or package.get("candidate_queue_writer_run_readiness")
|
||||
or package.get("readiness_payload")
|
||||
or {}
|
||||
)
|
||||
|
||||
service = MarketIntelService()
|
||||
return jsonify(
|
||||
build_mcp_fetch_candidate_queue_writer_run_readiness_preview(
|
||||
writer_run_package_review_package=writer_run_package_review_package,
|
||||
writer_run_package_review_result=writer_run_package_review_result,
|
||||
operator_readiness=operator_readiness,
|
||||
phase=service.phase,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -90,6 +90,9 @@ from services.market_intel.mcp_fetch_candidate_queue_writer_cli_review import (
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_run_package_review import (
|
||||
build_mcp_fetch_candidate_queue_writer_run_package_review_preview,
|
||||
)
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_run_readiness import (
|
||||
build_mcp_fetch_candidate_queue_writer_run_readiness_preview,
|
||||
)
|
||||
from services.market_intel.mcp_manual_fetch_handoff import (
|
||||
build_mcp_manual_fetch_handoff_preview,
|
||||
)
|
||||
@@ -237,6 +240,11 @@ PRODUCTION_SMOKE_TARGETS = (
|
||||
+ ("/api/market_intel/mcp_fetch_candidate_queue_writer_run_package_review",)
|
||||
+ PRODUCTION_SMOKE_TARGETS[-1:]
|
||||
)
|
||||
PRODUCTION_SMOKE_TARGETS = (
|
||||
PRODUCTION_SMOKE_TARGETS[:-1]
|
||||
+ ("/api/market_intel/mcp_fetch_candidate_queue_writer_run_readiness",)
|
||||
+ 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):
|
||||
@@ -301,6 +309,11 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
|
||||
phase=service.phase,
|
||||
)
|
||||
)
|
||||
mcp_fetch_candidate_queue_writer_run_readiness = (
|
||||
build_mcp_fetch_candidate_queue_writer_run_readiness_preview(
|
||||
phase=service.phase,
|
||||
)
|
||||
)
|
||||
scheduler_plan = service.build_scheduler_plan()
|
||||
manual_sample_plan = service.build_manual_sample_plan()
|
||||
manual_sample_acceptance = service.build_manual_sample_acceptance()
|
||||
@@ -918,6 +931,55 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
|
||||
"scheduler_attached"
|
||||
]
|
||||
),
|
||||
"mcp_fetch_candidate_queue_writer_run_readiness_preview_safe": bool(
|
||||
mcp_fetch_candidate_queue_writer_run_readiness["mode"]
|
||||
== "mcp_fetch_candidate_queue_writer_run_readiness_preview"
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"payload_persisted"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"run_readiness_persisted"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"run_readiness_artifact_created"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"run_readiness_file_written"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"package_artifact_created"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_writes_file"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_executes_cli"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_reads_approval_token"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_opens_database_connection"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_writes_database"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"api_uses_external_network"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"database_write_executed"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"cli_executed"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"file_written"
|
||||
]
|
||||
and not mcp_fetch_candidate_queue_writer_run_readiness[
|
||||
"scheduler_attached"
|
||||
]
|
||||
),
|
||||
"candidate_queue_writer_postwrite_smoke_planned_safe": bool(
|
||||
candidate_queue_writer_postwrite_smoke["mode"]
|
||||
== "candidate_queue_writer_postwrite_smoke_planned"
|
||||
@@ -1240,6 +1302,7 @@ def build_deployment_readiness_preview(*, service, market_intel_tables, schema_s
|
||||
"mcp_fetch_candidate_queue_writer_preflight": mcp_fetch_candidate_queue_writer_preflight,
|
||||
"mcp_fetch_candidate_queue_writer_cli_review": mcp_fetch_candidate_queue_writer_cli_review,
|
||||
"mcp_fetch_candidate_queue_writer_run_package_review": mcp_fetch_candidate_queue_writer_run_package_review,
|
||||
"mcp_fetch_candidate_queue_writer_run_readiness": mcp_fetch_candidate_queue_writer_run_readiness,
|
||||
"scheduler_plan": scheduler_plan,
|
||||
"manual_sample_plan": manual_sample_plan,
|
||||
"manual_sample_acceptance": manual_sample_acceptance,
|
||||
|
||||
@@ -0,0 +1,639 @@
|
||||
"""市場情報 MCP fetch candidate queue writer run readiness preview。
|
||||
|
||||
本模組只審核 run package review 後的 operator readiness 證據;API/UI
|
||||
不建立 artifact、不寫檔、不執行 CLI、不讀 approval token、不開 DB、不寫
|
||||
queue、不掛 scheduler。
|
||||
"""
|
||||
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_preflight import TARGET_TABLE
|
||||
from services.market_intel.mcp_fetch_candidate_queue_writer_run_package_review import (
|
||||
build_mcp_fetch_candidate_queue_writer_run_package_review_preview,
|
||||
)
|
||||
|
||||
|
||||
MAX_READY_PAYLOAD_ROWS = 80
|
||||
ARTIFACT_PREFIX = "artifacts/market_intel/"
|
||||
BACKUP_PREFIX = "scripts/tools/backups/"
|
||||
|
||||
FORBIDDEN_SECRET_KEYS = (
|
||||
"approval_token",
|
||||
"approval-token",
|
||||
"api_key",
|
||||
"authorization",
|
||||
"bearer",
|
||||
"client_secret",
|
||||
"cookie",
|
||||
"password",
|
||||
"secret",
|
||||
"session_cookie",
|
||||
"token",
|
||||
)
|
||||
|
||||
SAFE_SECRET_METADATA_KEYS = {
|
||||
"approval_token_shell_only_required",
|
||||
"no_approval_token_payload",
|
||||
"operator_confirmed_no_approval_token_payload",
|
||||
"operator_confirmed_one_time_token_shell_only",
|
||||
"one_time_token_shell_only_confirmed",
|
||||
}
|
||||
|
||||
_BLOCKED_SIDE_EFFECT_KEYS = (
|
||||
"allow_api_execution",
|
||||
"allow_cli_execution",
|
||||
"allow_database_write",
|
||||
"allow_external_network_in_api",
|
||||
"allow_scheduler_attach",
|
||||
"api_execution_allowed",
|
||||
"api_executed_cli",
|
||||
"api_executes",
|
||||
"api_executes_cli",
|
||||
"api_opens_database_connection",
|
||||
"api_reads_approval_token",
|
||||
"api_uses_external_network",
|
||||
"api_writes_database",
|
||||
"api_writes_file",
|
||||
"apply_real_write",
|
||||
"attach_scheduler",
|
||||
"candidate_queue_created",
|
||||
"candidate_queue_persisted",
|
||||
"candidate_review_state_updated",
|
||||
"cli_executed",
|
||||
"command_executed",
|
||||
"database_commit_executed",
|
||||
"database_connection_opened",
|
||||
"database_session_created",
|
||||
"database_write_executed",
|
||||
"execute_requested",
|
||||
"executes_now",
|
||||
"external_network_executed",
|
||||
"file_written",
|
||||
"network_request_allowed",
|
||||
"opens_database_connection",
|
||||
"package_artifact_created",
|
||||
"payload_persisted",
|
||||
"ready_for_api_database_write",
|
||||
"ready_for_real_write",
|
||||
"real_write_allowed",
|
||||
"review_state_update_executed",
|
||||
"run_readiness_artifact_created",
|
||||
"run_readiness_file_written",
|
||||
"run_readiness_persisted",
|
||||
"scheduler_attach",
|
||||
"scheduler_attached",
|
||||
"write_database",
|
||||
"writes_database",
|
||||
"writes_executed",
|
||||
"would_write_database",
|
||||
)
|
||||
|
||||
|
||||
def _as_dict(value):
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
def _as_list(value):
|
||||
if value is None:
|
||||
return []
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return list(value)
|
||||
return [value]
|
||||
|
||||
|
||||
def _safe_int(value):
|
||||
try:
|
||||
return int(value or 0)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def _safe_text(value, limit=500):
|
||||
if value is None:
|
||||
return None
|
||||
text = str(value).strip()
|
||||
return text[:limit] if text else None
|
||||
|
||||
|
||||
def _safe_path(value, *, prefixes, suffixes):
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
normalized = value.strip().replace("\\", "/")
|
||||
if not normalized or normalized.startswith("/"):
|
||||
return False
|
||||
parts = [part for part in normalized.split("/") if part]
|
||||
if any(part in (".", "..") for part in parts):
|
||||
return False
|
||||
return normalized.startswith(prefixes) and normalized.endswith(suffixes)
|
||||
|
||||
|
||||
def _contains_forbidden_key(value, forbidden_keys, *, safe_keys=None):
|
||||
safe_keys = safe_keys or set()
|
||||
if isinstance(value, dict):
|
||||
for key, nested in value.items():
|
||||
normalized_key = str(key).lower()
|
||||
if normalized_key in safe_keys and isinstance(nested, bool):
|
||||
continue
|
||||
if any(forbidden_key in normalized_key for forbidden_key in forbidden_keys):
|
||||
return True
|
||||
if _contains_forbidden_key(nested, forbidden_keys, safe_keys=safe_keys):
|
||||
return True
|
||||
elif isinstance(value, list):
|
||||
return any(
|
||||
_contains_forbidden_key(item, forbidden_keys, safe_keys=safe_keys)
|
||||
for item in value
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def _blocked_side_effects(payload):
|
||||
found = []
|
||||
|
||||
def visit(value, path):
|
||||
if isinstance(value, dict):
|
||||
for key, item in value.items():
|
||||
normalized_key = str(key).lower()
|
||||
key_path = f"{path}.{key}" if path else key
|
||||
if normalized_key in _BLOCKED_SIDE_EFFECT_KEYS and bool(item):
|
||||
found.append(key_path)
|
||||
visit(item, key_path)
|
||||
elif isinstance(value, list):
|
||||
for index, item in enumerate(value):
|
||||
visit(item, f"{path}[{index}]")
|
||||
|
||||
visit(payload, "")
|
||||
return found
|
||||
|
||||
|
||||
def _run_package_review_from_inputs(review_package, review_result, phase):
|
||||
if isinstance(review_result, dict) and review_result:
|
||||
return review_result
|
||||
|
||||
review_package = _as_dict(review_package)
|
||||
return build_mcp_fetch_candidate_queue_writer_run_package_review_preview(
|
||||
writer_cli_review_package=(
|
||||
review_package.get("writer_cli_review_package")
|
||||
or review_package.get("candidate_queue_writer_cli_review")
|
||||
or review_package.get("writer_cli_review")
|
||||
or review_package.get("cli_review_package")
|
||||
or {}
|
||||
),
|
||||
writer_cli_review_result=(
|
||||
review_package.get("writer_cli_review_result")
|
||||
or review_package.get("mcp_fetch_candidate_queue_writer_cli_review")
|
||||
),
|
||||
writer_run_package_review=(
|
||||
review_package.get("writer_run_package_review")
|
||||
or review_package.get("candidate_queue_writer_run_package_review")
|
||||
or review_package.get("run_package_review")
|
||||
or review_package.get("package_review")
|
||||
or review_package.get("review_payload")
|
||||
),
|
||||
phase=phase,
|
||||
)
|
||||
|
||||
|
||||
def _sample_run_readiness_package():
|
||||
review_preview = build_mcp_fetch_candidate_queue_writer_run_package_review_preview()
|
||||
review_package = review_preview["sample_writer_run_package_review_package"]
|
||||
review_result = build_mcp_fetch_candidate_queue_writer_run_package_review_preview(
|
||||
writer_cli_review_package=review_package["writer_cli_review_package"],
|
||||
writer_cli_review_result=review_package["writer_cli_review_result"],
|
||||
writer_run_package_review=review_package["writer_run_package_review"],
|
||||
)
|
||||
operator_readiness = {
|
||||
"run_readiness_artifact_path": (
|
||||
ARTIFACT_PREFIX + "candidate-queue-writer-run-readiness-sample.json"
|
||||
),
|
||||
"reviewed_sample_json_path": (
|
||||
ARTIFACT_PREFIX + "candidate-queue-reviewed-sample.json"
|
||||
),
|
||||
"backup_artifact_path": BACKUP_PREFIX + "momo_pro_system_backup_sample.zip",
|
||||
"read_only_preflight_output_path": (
|
||||
ARTIFACT_PREFIX + "candidate-queue-writer-preflight-sample.json"
|
||||
),
|
||||
"postwrite_smoke_plan_path": (
|
||||
ARTIFACT_PREFIX + "candidate-queue-writer-postwrite-smoke-plan.json"
|
||||
),
|
||||
"run_package_reviewed": True,
|
||||
"artifact_manifest_reviewed": True,
|
||||
"command_bundle_reviewed": True,
|
||||
"payload_count_reviewed": True,
|
||||
"target_table_reviewed": True,
|
||||
"backup_artifact_reviewed": True,
|
||||
"read_only_preflight_reviewed": True,
|
||||
"postwrite_smoke_required": True,
|
||||
"one_time_token_shell_only_confirmed": True,
|
||||
"operator_confirmed_no_approval_token_payload": True,
|
||||
"operator_confirmed_no_api_cli_execution": True,
|
||||
"operator_confirmed_no_api_database_write": True,
|
||||
"operator_confirmed_no_api_file_write": True,
|
||||
"operator_confirmed_no_external_network": True,
|
||||
"operator_confirmed_no_scheduler_attach": True,
|
||||
"operator_confirmed_no_persistence": True,
|
||||
"api_execution_allowed": False,
|
||||
"real_write_allowed": False,
|
||||
}
|
||||
return {
|
||||
"writer_run_package_review_package": review_package,
|
||||
"writer_run_package_review_result": review_result,
|
||||
"operator_readiness": operator_readiness,
|
||||
}
|
||||
|
||||
|
||||
def _run_package_review_summary(review_result):
|
||||
review_result = _as_dict(review_result)
|
||||
package = _as_dict(review_result.get("writer_run_package_review_summary"))
|
||||
required_artifacts = [
|
||||
item for item in _as_list(package.get("required_artifacts"))
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
command_bundle = [
|
||||
item for item in _as_list(package.get("command_bundle"))
|
||||
if isinstance(item, dict)
|
||||
]
|
||||
side_effects_clear = bool(
|
||||
not review_result.get("network_request_allowed")
|
||||
and not review_result.get("api_executes_cli")
|
||||
and not review_result.get("api_reads_approval_token")
|
||||
and not review_result.get("api_opens_database_connection")
|
||||
and not review_result.get("api_writes_database")
|
||||
and not review_result.get("api_uses_external_network")
|
||||
and not review_result.get("database_write_executed")
|
||||
and not review_result.get("cli_executed")
|
||||
and not review_result.get("file_written")
|
||||
and not review_result.get("scheduler_attached")
|
||||
and not review_result.get("candidate_queue_created")
|
||||
and not review_result.get("candidate_queue_persisted")
|
||||
and not package.get("blocked_side_effects")
|
||||
)
|
||||
return {
|
||||
"mode": review_result.get("mode"),
|
||||
"accepted": bool(
|
||||
review_result.get(
|
||||
"mcp_fetch_candidate_queue_writer_run_package_review_accepted"
|
||||
)
|
||||
),
|
||||
"ready_for_run_readiness_review": bool(
|
||||
review_result.get("ready_for_candidate_queue_writer_run_readiness_review")
|
||||
),
|
||||
"run_package_id": _safe_text(package.get("run_package_id"), 160),
|
||||
"package_mode": _safe_text(package.get("package_mode"), 160),
|
||||
"target_table": _safe_text(package.get("target_table"), 160),
|
||||
"payload_row_count": _safe_int(package.get("expected_payload_row_count")),
|
||||
"candidate_keys": sorted(
|
||||
key for key in _as_list(package.get("expected_candidate_keys")) if key
|
||||
),
|
||||
"dedupe_keys": sorted(
|
||||
key for key in _as_list(package.get("expected_dedupe_keys")) if key
|
||||
),
|
||||
"required_artifact_count": len(required_artifacts),
|
||||
"command_count": len(command_bundle),
|
||||
"artifacts_operator_created": bool(
|
||||
package.get("artifacts_operator_created")
|
||||
),
|
||||
"command_bundle_api_safe": bool(package.get("command_bundle_api_safe")),
|
||||
"operator_boundaries_confirmed": bool(
|
||||
package.get("operator_boundaries_confirmed")
|
||||
),
|
||||
"promotion_next_gate": _safe_text(package.get("promotion_next_gate"), 160),
|
||||
"side_effects_clear": side_effects_clear,
|
||||
"blocked_reasons": review_result.get("blocked_reasons", []),
|
||||
"required_artifacts": required_artifacts,
|
||||
"command_bundle": command_bundle,
|
||||
}
|
||||
|
||||
|
||||
def _operator_summary(operator_readiness):
|
||||
operator_readiness = _as_dict(operator_readiness)
|
||||
artifact_paths = {
|
||||
"run_readiness_artifact_path": _safe_text(
|
||||
operator_readiness.get("run_readiness_artifact_path")
|
||||
),
|
||||
"reviewed_sample_json_path": _safe_text(
|
||||
operator_readiness.get("reviewed_sample_json_path")
|
||||
),
|
||||
"backup_artifact_path": _safe_text(
|
||||
operator_readiness.get("backup_artifact_path")
|
||||
),
|
||||
"read_only_preflight_output_path": _safe_text(
|
||||
operator_readiness.get("read_only_preflight_output_path")
|
||||
or operator_readiness.get("preflight_artifact_path")
|
||||
),
|
||||
"postwrite_smoke_plan_path": _safe_text(
|
||||
operator_readiness.get("postwrite_smoke_plan_path")
|
||||
or operator_readiness.get("postwrite_smoke_artifact_path")
|
||||
),
|
||||
}
|
||||
confirmations = {
|
||||
"run_package_reviewed": bool(operator_readiness.get("run_package_reviewed")),
|
||||
"artifact_manifest_reviewed": bool(
|
||||
operator_readiness.get("artifact_manifest_reviewed")
|
||||
),
|
||||
"command_bundle_reviewed": bool(
|
||||
operator_readiness.get("command_bundle_reviewed")
|
||||
),
|
||||
"payload_count_reviewed": bool(
|
||||
operator_readiness.get("payload_count_reviewed")
|
||||
),
|
||||
"target_table_reviewed": bool(
|
||||
operator_readiness.get("target_table_reviewed")
|
||||
),
|
||||
"backup_artifact_reviewed": bool(
|
||||
operator_readiness.get("backup_artifact_reviewed")
|
||||
),
|
||||
"read_only_preflight_reviewed": bool(
|
||||
operator_readiness.get("read_only_preflight_reviewed")
|
||||
),
|
||||
"postwrite_smoke_required": bool(
|
||||
operator_readiness.get("postwrite_smoke_required")
|
||||
),
|
||||
"one_time_token_shell_only_confirmed": bool(
|
||||
operator_readiness.get("one_time_token_shell_only_confirmed")
|
||||
or operator_readiness.get("operator_confirmed_one_time_token_shell_only")
|
||||
),
|
||||
"operator_confirmed_no_approval_token_payload": bool(
|
||||
operator_readiness.get("operator_confirmed_no_approval_token_payload")
|
||||
),
|
||||
"operator_confirmed_no_api_cli_execution": bool(
|
||||
operator_readiness.get("operator_confirmed_no_api_cli_execution")
|
||||
),
|
||||
"operator_confirmed_no_api_database_write": bool(
|
||||
operator_readiness.get("operator_confirmed_no_api_database_write")
|
||||
),
|
||||
"operator_confirmed_no_api_file_write": bool(
|
||||
operator_readiness.get("operator_confirmed_no_api_file_write")
|
||||
),
|
||||
"operator_confirmed_no_external_network": bool(
|
||||
operator_readiness.get("operator_confirmed_no_external_network")
|
||||
),
|
||||
"operator_confirmed_no_scheduler_attach": bool(
|
||||
operator_readiness.get("operator_confirmed_no_scheduler_attach")
|
||||
),
|
||||
"operator_confirmed_no_persistence": bool(
|
||||
operator_readiness.get("operator_confirmed_no_persistence")
|
||||
),
|
||||
}
|
||||
return {
|
||||
"provided_keys": sorted(operator_readiness.keys()),
|
||||
**artifact_paths,
|
||||
"run_readiness_artifact_path_safe": _safe_path(
|
||||
artifact_paths["run_readiness_artifact_path"],
|
||||
prefixes=(ARTIFACT_PREFIX,),
|
||||
suffixes=(".json",),
|
||||
),
|
||||
"reviewed_sample_json_path_safe": _safe_path(
|
||||
artifact_paths["reviewed_sample_json_path"],
|
||||
prefixes=(ARTIFACT_PREFIX,),
|
||||
suffixes=(".json",),
|
||||
),
|
||||
"backup_artifact_path_safe": _safe_path(
|
||||
artifact_paths["backup_artifact_path"],
|
||||
prefixes=(BACKUP_PREFIX,),
|
||||
suffixes=(".zip", ".tar.gz"),
|
||||
),
|
||||
"read_only_preflight_output_path_safe": _safe_path(
|
||||
artifact_paths["read_only_preflight_output_path"],
|
||||
prefixes=(ARTIFACT_PREFIX,),
|
||||
suffixes=(".json",),
|
||||
),
|
||||
"postwrite_smoke_plan_path_safe": _safe_path(
|
||||
artifact_paths["postwrite_smoke_plan_path"],
|
||||
prefixes=(ARTIFACT_PREFIX,),
|
||||
suffixes=(".json",),
|
||||
),
|
||||
**confirmations,
|
||||
"api_execution_allowed": bool(operator_readiness.get("api_execution_allowed")),
|
||||
"real_write_allowed": bool(operator_readiness.get("real_write_allowed")),
|
||||
"secret_or_token_submitted_to_api": _contains_forbidden_key(
|
||||
operator_readiness,
|
||||
FORBIDDEN_SECRET_KEYS,
|
||||
safe_keys=SAFE_SECRET_METADATA_KEYS,
|
||||
),
|
||||
"blocked_side_effects": _blocked_side_effects(operator_readiness),
|
||||
}
|
||||
|
||||
|
||||
def _readiness_gates(*, review_received, package, operator):
|
||||
operator_reviewed_package = bool(
|
||||
operator["run_package_reviewed"]
|
||||
and operator["artifact_manifest_reviewed"]
|
||||
and operator["command_bundle_reviewed"]
|
||||
and operator["payload_count_reviewed"]
|
||||
and operator["target_table_reviewed"]
|
||||
)
|
||||
operator_reviewed_artifacts = bool(
|
||||
operator["backup_artifact_reviewed"]
|
||||
and operator["read_only_preflight_reviewed"]
|
||||
and operator["postwrite_smoke_required"]
|
||||
)
|
||||
operator_confirmed_boundaries = bool(
|
||||
operator["one_time_token_shell_only_confirmed"]
|
||||
and operator["operator_confirmed_no_approval_token_payload"]
|
||||
and operator["operator_confirmed_no_api_cli_execution"]
|
||||
and operator["operator_confirmed_no_api_database_write"]
|
||||
and operator["operator_confirmed_no_api_file_write"]
|
||||
and operator["operator_confirmed_no_external_network"]
|
||||
and operator["operator_confirmed_no_scheduler_attach"]
|
||||
and operator["operator_confirmed_no_persistence"]
|
||||
)
|
||||
return [
|
||||
{
|
||||
"key": "writer_run_package_review_payload_or_result_received",
|
||||
"label": "已提供 writer run package review package 或已審核結果",
|
||||
"passed": review_received,
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_accepted",
|
||||
"label": "writer run package review gate 必須已通過",
|
||||
"passed": package["accepted"],
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_ready_for_run_readiness",
|
||||
"label": "run package review 只放行到 run readiness review",
|
||||
"passed": package["ready_for_run_readiness_review"],
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_target_table_safe",
|
||||
"label": "target table 必須是 market_alert_review_queue",
|
||||
"passed": package["target_table"] == TARGET_TABLE,
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_payload_small_batch",
|
||||
"label": "payload row count 必須介於 1 與安全上限",
|
||||
"passed": bool(0 < package["payload_row_count"] <= MAX_READY_PAYLOAD_ROWS),
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_artifact_manifest_available",
|
||||
"label": "run package 必須包含操作員 artifact manifest",
|
||||
"passed": bool(
|
||||
package["required_artifact_count"] >= 3
|
||||
and package["artifacts_operator_created"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_command_bundle_available",
|
||||
"label": "run package 必須包含 API-safe command bundle",
|
||||
"passed": bool(package["command_count"] >= 3 and package["command_bundle_api_safe"]),
|
||||
},
|
||||
{
|
||||
"key": "writer_run_package_review_side_effect_free",
|
||||
"label": "run package review 未顯示 API 執行、寫 DB 或掛 scheduler",
|
||||
"passed": package["side_effects_clear"],
|
||||
},
|
||||
{
|
||||
"key": "operator_readiness_received",
|
||||
"label": "已提供操作員 readiness 證據",
|
||||
"passed": bool(operator["provided_keys"]),
|
||||
},
|
||||
{
|
||||
"key": "run_readiness_artifact_path_safe",
|
||||
"label": "run readiness artifact path 必須在 market intel artifact 目錄",
|
||||
"passed": operator["run_readiness_artifact_path_safe"],
|
||||
},
|
||||
{
|
||||
"key": "reviewed_sample_json_path_safe",
|
||||
"label": "reviewed sample JSON path 必須在 market intel artifact 目錄",
|
||||
"passed": operator["reviewed_sample_json_path_safe"],
|
||||
},
|
||||
{
|
||||
"key": "backup_artifact_path_safe",
|
||||
"label": "備份 artifact path 必須在 scripts/tools/backups 目錄",
|
||||
"passed": operator["backup_artifact_path_safe"],
|
||||
},
|
||||
{
|
||||
"key": "read_only_preflight_output_path_safe",
|
||||
"label": "read-only preflight output path 必須在 market intel artifact 目錄",
|
||||
"passed": operator["read_only_preflight_output_path_safe"],
|
||||
},
|
||||
{
|
||||
"key": "postwrite_smoke_plan_path_safe",
|
||||
"label": "post-write smoke plan path 必須在 market intel artifact 目錄",
|
||||
"passed": operator["postwrite_smoke_plan_path_safe"],
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_package_review",
|
||||
"label": "操作員已覆核 run package、artifact manifest、command bundle 與 payload",
|
||||
"passed": operator_reviewed_package,
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_artifacts_and_preflight",
|
||||
"label": "操作員已確認備份、read-only preflight 與 post-write smoke",
|
||||
"passed": operator_reviewed_artifacts,
|
||||
},
|
||||
{
|
||||
"key": "operator_confirmed_shell_only_boundaries",
|
||||
"label": "操作員確認 CLI-only、token shell-only、無 API/DB/scheduler 副作用",
|
||||
"passed": operator_confirmed_boundaries,
|
||||
},
|
||||
{
|
||||
"key": "operator_readiness_no_api_execution_or_real_write",
|
||||
"label": "readiness payload 不得允許 API execution 或 real write",
|
||||
"passed": bool(
|
||||
not operator["api_execution_allowed"]
|
||||
and not operator["real_write_allowed"]
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "secret_or_token_not_submitted_to_api",
|
||||
"label": "readiness payload 不得包含 secret、cookie、password 或 token key",
|
||||
"passed": not operator["secret_or_token_submitted_to_api"],
|
||||
},
|
||||
{
|
||||
"key": "operator_readiness_side_effect_free",
|
||||
"label": "readiness payload 不得要求 API 寫檔、執行、寫 DB 或掛 scheduler",
|
||||
"passed": not operator["blocked_side_effects"],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def build_mcp_fetch_candidate_queue_writer_run_readiness_preview(
|
||||
*,
|
||||
writer_run_package_review_package=None,
|
||||
writer_run_package_review_result=None,
|
||||
operator_readiness=None,
|
||||
phase=None,
|
||||
):
|
||||
"""建立 fetch candidate queue writer run readiness review;不執行寫入。"""
|
||||
writer_run_package_review_package = _as_dict(writer_run_package_review_package)
|
||||
review_result_received = bool(
|
||||
isinstance(writer_run_package_review_result, dict)
|
||||
and writer_run_package_review_result
|
||||
)
|
||||
operator_readiness = _as_dict(operator_readiness)
|
||||
review_result = _run_package_review_from_inputs(
|
||||
writer_run_package_review_package,
|
||||
writer_run_package_review_result,
|
||||
phase,
|
||||
)
|
||||
review_received = bool(
|
||||
writer_run_package_review_package or review_result_received
|
||||
)
|
||||
payload_received = bool(review_received or operator_readiness)
|
||||
package = _run_package_review_summary(review_result)
|
||||
operator = _operator_summary(operator_readiness)
|
||||
gates = _readiness_gates(
|
||||
review_received=review_received,
|
||||
package=package,
|
||||
operator=operator,
|
||||
)
|
||||
blocked_reasons = [gate["key"] for gate in gates if not gate["passed"]]
|
||||
accepted = bool(payload_received and not blocked_reasons)
|
||||
|
||||
return {
|
||||
"mode": (
|
||||
"mcp_fetch_candidate_queue_writer_run_readiness_review"
|
||||
if payload_received
|
||||
else "mcp_fetch_candidate_queue_writer_run_readiness_preview"
|
||||
),
|
||||
"phase": phase,
|
||||
"writer_run_readiness_payload_received": payload_received,
|
||||
"writer_run_package_review_received": review_received,
|
||||
"operator_readiness_received": bool(operator["provided_keys"]),
|
||||
"writer_run_package_review_accepted": package["accepted"],
|
||||
"mcp_fetch_candidate_queue_writer_run_readiness_accepted": accepted,
|
||||
"candidate_queue_writer_run_readiness_ready": accepted,
|
||||
"ready_for_candidate_queue_writer_operator_run": accepted,
|
||||
"ready_for_candidate_queue_writer_run_receipt_review": accepted,
|
||||
"ready_for_api_database_write": False,
|
||||
"ready_for_real_write": False,
|
||||
"ready_for_scheduler_attach": False,
|
||||
"network_request_allowed": False,
|
||||
"operator_shell_database_write_required": accepted,
|
||||
"api_executes_cli": False,
|
||||
"api_reads_approval_token": False,
|
||||
"api_opens_database_connection": False,
|
||||
"api_writes_database": False,
|
||||
"api_writes_file": False,
|
||||
"api_uses_external_network": False,
|
||||
"payload_row_count": package["payload_row_count"],
|
||||
"gate_count": len(gates),
|
||||
"passed_gate_count": sum(1 for gate in gates if gate["passed"]),
|
||||
"blocked_reasons": blocked_reasons,
|
||||
"gates": gates,
|
||||
"writer_run_package_review_summary": package,
|
||||
"operator_readiness_summary": operator,
|
||||
"sample_writer_run_readiness_package": _sample_run_readiness_package(),
|
||||
"next_operator_steps": [
|
||||
"Run readiness 通過後,操作員才可在 shell 依 run package 執行 writer CLI",
|
||||
"一次性 approval token 只能在 shell 注入,不得提交給 API/UI",
|
||||
"CLI 寫入後必須保存 writer output,再回貼到下一個 run receipt review gate",
|
||||
"API/UI 仍不得建立 artifact、寫檔、執行 CLI、讀 token、開 DB 或寫 queue",
|
||||
],
|
||||
"payload_persisted": False,
|
||||
"run_readiness_persisted": False,
|
||||
"run_readiness_artifact_created": False,
|
||||
"run_readiness_file_written": False,
|
||||
"run_receipt_file_written": False,
|
||||
"package_artifact_created": False,
|
||||
"database_session_created": False,
|
||||
"database_commit_executed": False,
|
||||
"database_write_executed": False,
|
||||
"external_network_executed": False,
|
||||
"cli_executed": False,
|
||||
"file_written": False,
|
||||
"writes_executed": False,
|
||||
"would_write_database": False,
|
||||
"scheduler_attached": False,
|
||||
"candidate_queue_created": False,
|
||||
"candidate_queue_persisted": False,
|
||||
"candidate_review_state_updated": False,
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
"""市場情報 rollout phase 單一來源。"""
|
||||
|
||||
MARKET_INTEL_PHASE = "phase_130_market_intel_mcp_fetch_candidate_queue_writer_run_package_review"
|
||||
MARKET_INTEL_PHASE = "phase_131_market_intel_mcp_fetch_candidate_queue_writer_run_readiness_review"
|
||||
|
||||
@@ -916,6 +916,32 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="market-intel-panel" data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness>
|
||||
<div class="market-intel-preview-head">
|
||||
<div>
|
||||
<p class="market-intel-muted momo-mono mb-1">MCP / WRITER RUN READINESS</p>
|
||||
<h2 class="market-intel-preview-title">MCP Candidate Queue Writer Run Readiness</h2>
|
||||
</div>
|
||||
<button class="market-intel-icon-button" type="button" title="重新整理 MCP Writer Run Readiness" data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-refresh>
|
||||
<i class="fas fa-rotate-right" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="market-intel-preview-meta" data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-meta>
|
||||
<span class="market-intel-pill">loading</span>
|
||||
</div>
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-body>
|
||||
<div class="market-intel-empty">讀取 MCP Writer Run Readiness 中...</div>
|
||||
</div>
|
||||
<div class="market-intel-control-row mt-3">
|
||||
<textarea class="market-intel-json-input" rows="9" spellcheck="false" data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-input placeholder="writer run package review and readiness JSON"></textarea>
|
||||
<div class="market-intel-control-actions">
|
||||
<button class="market-intel-icon-button" type="button" title="審核 MCP Writer Run Readiness JSON" data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-review>
|
||||
<i class="fas fa-check" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="market-intel-panel" data-market-intel-manual-sample>
|
||||
<div class="market-intel-preview-head">
|
||||
<div>
|
||||
@@ -1434,6 +1460,7 @@
|
||||
const mcpFetchCandidateQueueWriterPreflightRoot = document.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-preflight]');
|
||||
const mcpFetchCandidateQueueWriterCliReviewRoot = document.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-cli-review]');
|
||||
const mcpFetchCandidateQueueWriterRunPackageReviewRoot = document.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-package-review]');
|
||||
const mcpFetchCandidateQueueWriterRunReadinessRoot = document.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness]');
|
||||
const manualSampleRoot = document.querySelector('[data-market-intel-manual-sample]');
|
||||
const sampleAcceptanceRoot = document.querySelector('[data-market-intel-sample-acceptance]');
|
||||
const sampleReviewRoot = document.querySelector('[data-market-intel-sample-review]');
|
||||
@@ -1450,7 +1477,7 @@
|
||||
const liveInventoryRoot = document.querySelector('[data-market-intel-live-inventory]');
|
||||
const approvalRoot = document.querySelector('[data-market-intel-approval]');
|
||||
const deployRoot = document.querySelector('[data-market-intel-deploy]');
|
||||
if (!root && !writerRoot && !cliRoot && !dbProbeRoot && !seedDiffRoot && !legacyBridgeRoot && !mcpReadinessRoot && !mcpPreflightRoot && !mcpActivationRoot && !mcpFetchGateRoot && !mcpCompletionRoot && !mcpActivationEvidenceRoot && !mcpRuntimeSmokeRoot && !mcpRuntimePromotionRoot && !mcpManualFetchHandoffRoot && !mcpFetchTargetReviewRoot && !mcpFetchRunPackageRoot && !mcpFetchRunReadinessRoot && !mcpFetchRunReceiptRoot && !mcpFetchResultParserReviewRoot && !mcpFetchCandidateHandoffReviewRoot && !mcpFetchCandidateQueueReviewRoot && !mcpFetchCandidateQueueWriterPreflightRoot && !mcpFetchCandidateQueueWriterCliReviewRoot && !mcpFetchCandidateQueueWriterRunPackageReviewRoot && !manualSampleRoot && !sampleAcceptanceRoot && !sampleReviewRoot && !schedulerRoot && !matchReviewRoot && !opportunityRoot && !opportunityScoringRoot && !opportunityEvidenceRoot && !opportunityAlertRoot && !migrationRoot && !migrationDrillRoot && !catalogReviewRoot && !liveSmokeRoot && !liveInventoryRoot && !approvalRoot && !deployRoot) return;
|
||||
if (!root && !writerRoot && !cliRoot && !dbProbeRoot && !seedDiffRoot && !legacyBridgeRoot && !mcpReadinessRoot && !mcpPreflightRoot && !mcpActivationRoot && !mcpFetchGateRoot && !mcpCompletionRoot && !mcpActivationEvidenceRoot && !mcpRuntimeSmokeRoot && !mcpRuntimePromotionRoot && !mcpManualFetchHandoffRoot && !mcpFetchTargetReviewRoot && !mcpFetchRunPackageRoot && !mcpFetchRunReadinessRoot && !mcpFetchRunReceiptRoot && !mcpFetchResultParserReviewRoot && !mcpFetchCandidateHandoffReviewRoot && !mcpFetchCandidateQueueReviewRoot && !mcpFetchCandidateQueueWriterPreflightRoot && !mcpFetchCandidateQueueWriterCliReviewRoot && !mcpFetchCandidateQueueWriterRunPackageReviewRoot && !mcpFetchCandidateQueueWriterRunReadinessRoot && !manualSampleRoot && !sampleAcceptanceRoot && !sampleReviewRoot && !schedulerRoot && !matchReviewRoot && !opportunityRoot && !opportunityScoringRoot && !opportunityEvidenceRoot && !opportunityAlertRoot && !migrationRoot && !migrationDrillRoot && !catalogReviewRoot && !liveSmokeRoot && !liveInventoryRoot && !approvalRoot && !deployRoot) return;
|
||||
|
||||
const meta = root ? root.querySelector('[data-market-intel-preview-meta]') : null;
|
||||
const body = root ? root.querySelector('[data-market-intel-preview-body]') : null;
|
||||
@@ -1581,6 +1608,12 @@
|
||||
const mcpFetchCandidateQueueWriterRunPackageReviewReview = mcpFetchCandidateQueueWriterRunPackageReviewRoot ? mcpFetchCandidateQueueWriterRunPackageReviewRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-package-review-review]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunPackageReviewRefresh = mcpFetchCandidateQueueWriterRunPackageReviewRoot ? mcpFetchCandidateQueueWriterRunPackageReviewRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-package-review-refresh]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunPackageReviewEndpoint = "{{ url_for('market_intel.market_intel_mcp_fetch_candidate_queue_writer_run_package_review') }}";
|
||||
const mcpFetchCandidateQueueWriterRunReadinessMeta = mcpFetchCandidateQueueWriterRunReadinessRoot ? mcpFetchCandidateQueueWriterRunReadinessRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-meta]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunReadinessBody = mcpFetchCandidateQueueWriterRunReadinessRoot ? mcpFetchCandidateQueueWriterRunReadinessRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-body]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunReadinessInput = mcpFetchCandidateQueueWriterRunReadinessRoot ? mcpFetchCandidateQueueWriterRunReadinessRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-input]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunReadinessReview = mcpFetchCandidateQueueWriterRunReadinessRoot ? mcpFetchCandidateQueueWriterRunReadinessRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-review]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunReadinessRefresh = mcpFetchCandidateQueueWriterRunReadinessRoot ? mcpFetchCandidateQueueWriterRunReadinessRoot.querySelector('[data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-refresh]') : null;
|
||||
const mcpFetchCandidateQueueWriterRunReadinessEndpoint = "{{ url_for('market_intel.market_intel_mcp_fetch_candidate_queue_writer_run_readiness') }}";
|
||||
const manualSampleMeta = manualSampleRoot ? manualSampleRoot.querySelector('[data-market-intel-manual-sample-meta]') : null;
|
||||
const manualSampleBody = manualSampleRoot ? manualSampleRoot.querySelector('[data-market-intel-manual-sample-body]') : null;
|
||||
const manualSampleRefresh = manualSampleRoot ? manualSampleRoot.querySelector('[data-market-intel-manual-sample-refresh]') : null;
|
||||
@@ -4300,6 +4333,133 @@
|
||||
}
|
||||
};
|
||||
|
||||
const renderMcpFetchCandidateQueueWriterRunReadinessMeta = data => {
|
||||
mcpFetchCandidateQueueWriterRunReadinessMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
`accepted=${data.mcp_fetch_candidate_queue_writer_run_readiness_accepted ? 'yes' : 'no'}`,
|
||||
`gates=${data.passed_gate_count || 0}/${data.gate_count || 0}`,
|
||||
`rows=${data.payload_row_count || 0}`,
|
||||
`operator=${data.ready_for_candidate_queue_writer_operator_run ? 'ready' : 'blocked'}`,
|
||||
`db=${data.api_writes_database ? 'write' : 'blocked'}`
|
||||
].map(item => `<span class="market-intel-pill">${escapeHtml(item)}</span>`).join('');
|
||||
};
|
||||
|
||||
const renderMcpFetchCandidateQueueWriterRunReadinessBody = data => {
|
||||
const blockers = (data.blocked_reasons || []).join(' / ');
|
||||
const gates = data.gates || [];
|
||||
const pkg = data.writer_run_package_review_summary || {};
|
||||
const operator = data.operator_readiness_summary || {};
|
||||
const artifacts = [
|
||||
['run_readiness_artifact_path', operator.run_readiness_artifact_path, operator.run_readiness_artifact_path_safe],
|
||||
['reviewed_sample_json_path', operator.reviewed_sample_json_path, operator.reviewed_sample_json_path_safe],
|
||||
['backup_artifact_path', operator.backup_artifact_path, operator.backup_artifact_path_safe],
|
||||
['read_only_preflight_output_path', operator.read_only_preflight_output_path, operator.read_only_preflight_output_path_safe],
|
||||
['postwrite_smoke_plan_path', operator.postwrite_smoke_plan_path, operator.postwrite_smoke_plan_path_safe]
|
||||
];
|
||||
const steps = data.next_operator_steps || [];
|
||||
const renderCheck = (key, label, status) => `
|
||||
<div class="market-intel-check">
|
||||
<div>
|
||||
<strong>${escapeHtml(key)}</strong>
|
||||
<small>${escapeHtml(label || '')}</small>
|
||||
</div>
|
||||
<span>${escapeHtml(status)}</span>
|
||||
</div>
|
||||
`;
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = `
|
||||
<div class="market-intel-empty mb-3">此 run readiness 只審核操作員準備證據;API 不建立 artifact、不寫檔、不執行 CLI、不讀 approval token、不開 DB、不寫 queue、不掛 scheduler。${blockers ? `阻擋:${escapeHtml(blockers)}` : ''}</div>
|
||||
<div class="market-intel-deploy-grid">
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-gates>
|
||||
<p class="market-intel-deploy-section-title">READINESS GATES</p>
|
||||
<div class="market-intel-check-list">${
|
||||
gates.length
|
||||
? gates.map(item => renderCheck(item.key, item.label, item.passed ? 'PASS' : 'BLOCK')).join('')
|
||||
: '<div class="market-intel-empty">尚未提供 readiness gates。</div>'
|
||||
}</div>
|
||||
</div>
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-package>
|
||||
<p class="market-intel-deploy-section-title">RUN PACKAGE REVIEW</p>
|
||||
<div class="market-intel-check-list">
|
||||
${renderCheck('run_package_review', `${pkg.accepted ? 'accepted' : 'pending'} / rows=${pkg.payload_row_count || 0}`, pkg.accepted ? 'ACCEPTED' : 'PENDING')}
|
||||
${renderCheck('target_table', pkg.target_table || 'missing', pkg.target_table === 'market_alert_review_queue' ? 'SAFE' : 'BLOCK')}
|
||||
${renderCheck('api_boundary', 'no CLI / no token / no DB / no scheduler', pkg.side_effects_clear ? 'CLOSED' : 'BLOCK')}
|
||||
</div>
|
||||
</div>
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-operator>
|
||||
<p class="market-intel-deploy-section-title">OPERATOR CONFIRMATIONS</p>
|
||||
<div class="market-intel-check-list">
|
||||
${renderCheck('run_package_reviewed', 'package / manifest / command / payload / table', operator.run_package_reviewed && operator.artifact_manifest_reviewed && operator.command_bundle_reviewed && operator.payload_count_reviewed && operator.target_table_reviewed ? 'CONFIRMED' : 'BLOCK')}
|
||||
${renderCheck('preflight_and_backup', 'backup / read-only preflight / post-write smoke', operator.backup_artifact_reviewed && operator.read_only_preflight_reviewed && operator.postwrite_smoke_required ? 'CONFIRMED' : 'BLOCK')}
|
||||
${renderCheck('shell_only_boundaries', 'token shell-only, no API CLI/DB/file/scheduler', operator.one_time_token_shell_only_confirmed && operator.operator_confirmed_no_api_cli_execution && operator.operator_confirmed_no_api_database_write && operator.operator_confirmed_no_scheduler_attach ? 'CLOSED' : 'BLOCK')}
|
||||
</div>
|
||||
</div>
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-artifacts>
|
||||
<p class="market-intel-deploy-section-title">ARTIFACT PATHS</p>
|
||||
<div class="market-intel-check-list">
|
||||
${artifacts.map(item => renderCheck(item[0], item[1] || 'missing', item[2] ? 'SAFE' : 'BLOCK')).join('')}
|
||||
</div>
|
||||
</div>
|
||||
<div data-market-intel-mcp-fetch-candidate-queue-writer-run-readiness-next>
|
||||
<p class="market-intel-deploy-section-title">BOUNDARY / NEXT</p>
|
||||
<div class="market-intel-check-list">
|
||||
${renderCheck('operator_run', data.ready_for_candidate_queue_writer_operator_run ? 'shell writer CLI allowed after this gate' : 'blocked', data.ready_for_candidate_queue_writer_operator_run ? 'READY' : 'BLOCK')}
|
||||
${renderCheck('api_side_effects', 'no artifact / no file / no CLI / no token / no DB / no queue', data.run_readiness_artifact_created || data.api_executes_cli || data.api_reads_approval_token || data.api_writes_database || data.api_writes_file ? 'BLOCK' : 'CLOSED')}
|
||||
${steps.map((item, index) => renderCheck(`step_${index + 1}`, item, 'NEXT')).join('')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
if (mcpFetchCandidateQueueWriterRunReadinessInput && !mcpFetchCandidateQueueWriterRunReadinessInput.value.trim() && data.sample_writer_run_readiness_package) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessInput.value = JSON.stringify(data.sample_writer_run_readiness_package, null, 2);
|
||||
}
|
||||
};
|
||||
|
||||
const loadMcpFetchCandidateQueueWriterRunReadiness = async () => {
|
||||
if (!mcpFetchCandidateQueueWriterRunReadinessMeta || !mcpFetchCandidateQueueWriterRunReadinessBody) return;
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = '<div class="market-intel-empty">讀取 MCP Writer Run Readiness 中...</div>';
|
||||
try {
|
||||
const response = await fetch(mcpFetchCandidateQueueWriterRunReadinessEndpoint, { credentials: 'same-origin' });
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const data = await response.json();
|
||||
renderMcpFetchCandidateQueueWriterRunReadinessMeta(data);
|
||||
renderMcpFetchCandidateQueueWriterRunReadinessBody(data);
|
||||
} catch (error) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = `<div class="market-intel-empty">MCP Writer Run Readiness 讀取失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const reviewMcpFetchCandidateQueueWriterRunReadiness = async () => {
|
||||
if (!mcpFetchCandidateQueueWriterRunReadinessMeta || !mcpFetchCandidateQueueWriterRunReadinessBody || !mcpFetchCandidateQueueWriterRunReadinessInput) return;
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(mcpFetchCandidateQueueWriterRunReadinessInput.value || '{}');
|
||||
} catch (error) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessMeta.innerHTML = '<span class="market-intel-pill">json_error</span>';
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = `<div class="market-intel-empty">JSON 格式錯誤:${escapeHtml(error.message)}</div>`;
|
||||
return;
|
||||
}
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = '<div class="market-intel-empty">審核 MCP Writer Run Readiness 中...</div>';
|
||||
try {
|
||||
const response = await fetch(mcpFetchCandidateQueueWriterRunReadinessEndpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({ writer_run_readiness_package: parsed })
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok && !data.mode) throw new Error(`HTTP ${response.status}`);
|
||||
renderMcpFetchCandidateQueueWriterRunReadinessMeta(data);
|
||||
renderMcpFetchCandidateQueueWriterRunReadinessBody(data);
|
||||
} catch (error) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessMeta.innerHTML = '<span class="market-intel-pill">error</span>';
|
||||
mcpFetchCandidateQueueWriterRunReadinessBody.innerHTML = `<div class="market-intel-empty">MCP Writer Run Readiness 審核失敗:${escapeHtml(error.message)}</div>`;
|
||||
}
|
||||
};
|
||||
|
||||
const renderManualSampleMeta = data => {
|
||||
manualSampleMeta.innerHTML = [
|
||||
`mode=${data.mode || 'unknown'}`,
|
||||
@@ -13787,6 +13947,12 @@
|
||||
if (mcpFetchCandidateQueueWriterRunPackageReviewReview) {
|
||||
mcpFetchCandidateQueueWriterRunPackageReviewReview.addEventListener('click', reviewMcpFetchCandidateQueueWriterRunPackageReview);
|
||||
}
|
||||
if (mcpFetchCandidateQueueWriterRunReadinessRefresh) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessRefresh.addEventListener('click', loadMcpFetchCandidateQueueWriterRunReadiness);
|
||||
}
|
||||
if (mcpFetchCandidateQueueWriterRunReadinessReview) {
|
||||
mcpFetchCandidateQueueWriterRunReadinessReview.addEventListener('click', reviewMcpFetchCandidateQueueWriterRunReadiness);
|
||||
}
|
||||
if (manualSampleRefresh) {
|
||||
manualSampleRefresh.addEventListener('click', loadManualSample);
|
||||
}
|
||||
@@ -14055,6 +14221,7 @@
|
||||
loadMcpFetchCandidateQueueWriterPreflight();
|
||||
loadMcpFetchCandidateQueueWriterCliReview();
|
||||
loadMcpFetchCandidateQueueWriterRunPackageReview();
|
||||
loadMcpFetchCandidateQueueWriterRunReadiness();
|
||||
loadManualSample();
|
||||
loadSampleAcceptance();
|
||||
loadSampleReview();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user