diff --git a/apps/api/src/api/v1/agents.py b/apps/api/src/api/v1/agents.py index 39d2e0918..a0c1acf77 100644 --- a/apps/api/src/api/v1/agents.py +++ b/apps/api/src/api/v1/agents.py @@ -118,6 +118,9 @@ from src.services.ai_agent_reviewer_queue_no_write_readback import ( from src.services.ai_agent_result_capture_no_write_readback import ( load_latest_ai_agent_result_capture_no_write_readback, ) +from src.services.ai_agent_result_capture_promotion_approval_gate import ( + load_latest_ai_agent_result_capture_promotion_approval_gate, +) from src.services.ai_agent_runtime_readback_approval_package import ( load_latest_ai_agent_runtime_readback_approval_package, ) @@ -1623,6 +1626,36 @@ async def get_agent_result_capture_no_write_readback() -> dict[str, Any]: ) from exc +@router.get( + "/agent-result-capture-promotion-approval-gate", + response_model=dict[str, Any], + summary="取得 AI Agent result capture promotion approval gate", + description=( + "讀取最新已提交的 P2-119 result capture promotion approval gate;" + "此端點只回傳 promotion approval packet、acceptance template、verifier、" + "blocked promotion write 與 operator handoff,不寫 result capture、learning、" + "PlayBook trust、Gateway queue,不送 Telegram、不呼叫 Bot API、不讀 canonical runtime target、" + "不讀 secret。" + ), +) +async def get_agent_result_capture_promotion_approval_gate() -> dict[str, Any]: + """Return the latest read-only result capture promotion approval gate package.""" + try: + payload = await asyncio.to_thread(load_latest_ai_agent_result_capture_promotion_approval_gate) + return redact_public_lan_topology(payload) + except FileNotFoundError as exc: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=str(exc), + ) from exc + except (json.JSONDecodeError, ValueError) as exc: + logger.error("ai_agent_result_capture_promotion_approval_gate_invalid", error=str(exc)) + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="AI Agent result capture promotion approval gate 無效", + ) from exc + + @router.get( "/agent-owner-approved-fixture-dry-run", response_model=dict[str, Any], diff --git a/apps/api/src/services/ai_agent_result_capture_promotion_approval_gate.py b/apps/api/src/services/ai_agent_result_capture_promotion_approval_gate.py new file mode 100644 index 000000000..404d54890 --- /dev/null +++ b/apps/api/src/services/ai_agent_result_capture_promotion_approval_gate.py @@ -0,0 +1,365 @@ +""" +AI Agent result capture promotion approval gate snapshot. + +Loads the latest committed P2-119 result capture promotion approval package. This +module validates committed evidence only; it never writes result captures, +writes learning records, updates PlayBook trust, writes Gateway queues, sends +Telegram messages, reads canonical runtime targets, reads secrets, or performs +destructive operations. +""" + +from __future__ import annotations + +import json +from pathlib import Path +from typing import Any + +from src.services.snapshot_paths import default_evaluations_dir + +_DEFAULT_EVALUATIONS_DIR = default_evaluations_dir(Path(__file__)) +_SNAPSHOT_PATTERN = "ai_agent_result_capture_promotion_approval_gate_*.json" +_SCHEMA_VERSION = "ai_agent_result_capture_promotion_approval_gate_v1" +_RUNTIME_AUTHORITY = "result_capture_promotion_approval_gate_only_no_capture_or_learning_write" +_TARGET_PROMOTION = "result_capture_promotion_preview" + + +def load_latest_ai_agent_result_capture_promotion_approval_gate( + evaluations_dir: Path | None = None, +) -> dict[str, Any]: + """Load the newest committed result capture promotion approval gate package.""" + directory = evaluations_dir or _DEFAULT_EVALUATIONS_DIR + candidates = sorted(directory.glob(_SNAPSHOT_PATTERN)) + if not candidates: + raise FileNotFoundError(f"no AI Agent result capture promotion approval gate snapshots found in {directory}") + + latest = candidates[-1] + with latest.open(encoding="utf-8") as handle: + payload = json.load(handle) + + if not isinstance(payload, dict): + raise ValueError(f"{latest}: expected JSON object") + + label = str(latest) + _require_schema(payload, label) + _require_prior(payload, label) + _require_truth(payload, label) + _require_promotion_packets(payload, label) + _require_acceptance_templates(payload, label) + _require_verifier_checks(payload, label) + _require_blockers(payload, label) + _require_actions(payload, label) + _require_display_redaction(payload, label) + _require_no_forbidden_display_terms(payload, label) + _require_rollup_consistency(payload, label) + return payload + + +def _require_schema(payload: dict[str, Any], label: str) -> None: + if payload.get("schema_version") != _SCHEMA_VERSION: + raise ValueError(f"{label}: expected schema_version={_SCHEMA_VERSION}") + status = payload.get("program_status") or {} + expected = { + "current_priority": "P2", + "current_task_id": "P2-119", + "next_task_id": "P2-120", + "read_only_mode": True, + "runtime_authority": _RUNTIME_AUTHORITY, + "overall_completion_percent": 100, + } + mismatches = _mismatches(status, expected) + if mismatches: + raise ValueError(f"{label}: program_status mismatch: {mismatches}") + if not status.get("status_note"): + raise ValueError(f"{label}: program_status.status_note is required") + + +def _require_prior(payload: dict[str, Any], label: str) -> None: + prior = payload.get("prior_result_capture_no_write_readback") or {} + expected = { + "schema_version": "ai_agent_result_capture_no_write_readback_v1", + "result_capture_readback_fixture_count": 5, + "capture_field_mapping_count": 5, + "readback_verifier_check_count": 5, + "blocked_result_capture_write_count": 5, + "operator_action_count": 5, + "result_capture_write_count": 0, + "learning_write_count": 0, + "playbook_trust_write_count": 0, + "reviewer_queue_write_count": 0, + "gateway_queue_write_count": 0, + "telegram_send_count": 0, + "bot_api_call_count": 0, + "report_receipt_write_count": 0, + } + mismatches = _mismatches(prior, expected) + if mismatches: + raise ValueError(f"{label}: prior_result_capture_no_write_readback mismatch: {mismatches}") + if not prior.get("readiness_note"): + raise ValueError(f"{label}: prior_result_capture_no_write_readback.readiness_note is required") + + +def _require_truth(payload: dict[str, Any], label: str) -> None: + truth = payload.get("promotion_truth") or {} + required_true = { + "p2_118_result_capture_readback_loaded", + "promotion_approval_package_ready", + "acceptance_gate_template_ready", + "promotion_verifier_ready", + "operator_handoff_ready", + "rollback_and_reverify_required", + } + missing = sorted(field for field in required_true if truth.get(field) is not True) + if missing: + raise ValueError(f"{label}: promotion ready flags must remain true: {missing}") + for field in {"owner_approval_received", "capture_promotion_approved"}: + if truth.get(field) is not False: + raise ValueError(f"{label}: {field} must remain false before promotion write") + + required_false = { + "canonical_runtime_target_read_enabled", + "live_query_enabled", + "reviewer_queue_write_enabled", + "gateway_queue_write_enabled", + "telegram_send_enabled", + "bot_api_call_enabled", + "report_receipt_write_enabled", + "result_capture_write_enabled", + "learning_write_enabled", + "playbook_trust_write_enabled", + "production_write_enabled", + "secret_read_enabled", + "destructive_operation_enabled", + } + unsafe = sorted(field for field in required_false if truth.get(field) is not False) + if unsafe: + raise ValueError(f"{label}: live read/send/write flags must remain false: {unsafe}") + + zero_counts = { + "owner_approval_received_count", + "capture_promotion_approved_count", + "canonical_runtime_target_read_count", + "live_query_count", + "reviewer_queue_write_count", + "gateway_queue_write_count", + "telegram_send_count", + "bot_api_call_count", + "report_receipt_write_count", + "result_capture_write_count", + "learning_write_count", + "playbook_trust_write_count", + "production_write_count", + } + non_zero = sorted(field for field in zero_counts if truth.get(field) != 0) + if non_zero: + raise ValueError(f"{label}: promotion live counters must remain zero: {non_zero}") + if not truth.get("truth_note"): + raise ValueError(f"{label}: promotion_truth.truth_note is required") + + +def _require_promotion_packets(payload: dict[str, Any], label: str) -> None: + packets = payload.get("promotion_approval_packets") or [] + required = { + "promotion_packet_action_required", + "promotion_packet_no_action_review", + "promotion_packet_verifier_degraded", + "promotion_packet_route_lock", + "promotion_packet_owner_acceptance", + } + packet_ids = {packet.get("packet_id") for packet in packets} + if packet_ids != required: + raise ValueError(f"{label}: promotion approval packets must match {sorted(required)}") + for packet in packets: + packet_id = packet.get("packet_id") + if packet.get("promotion_mode") != "approval_gate_only": + raise ValueError(f"{label}: packet {packet_id} must remain approval_gate_only") + if packet.get("result_capture_write_enabled") is not False: + raise ValueError(f"{label}: packet {packet_id} must not enable result capture write") + if packet.get("status") not in {"ready_for_owner_review", "approval_required", "blocked_by_policy"}: + raise ValueError(f"{label}: packet {packet_id} status is invalid") + if not packet.get("required_decision") or not packet.get("approval_lane"): + raise ValueError(f"{label}: packet {packet_id} must include approval lane and required decision") + if not _is_redacted_sha256(packet.get("evidence_hash")): + raise ValueError(f"{label}: packet {packet_id} must expose redacted evidence_hash") + + +def _require_acceptance_templates(payload: dict[str, Any], label: str) -> None: + templates = payload.get("acceptance_gate_templates") or [] + required = { + "owner_acceptance_record_template", + "capture_write_scope_template", + "learning_write_scope_template", + "playbook_trust_scope_template", + "rollback_and_verifier_template", + } + template_ids = {template.get("template_id") for template in templates} + if template_ids != required: + raise ValueError(f"{label}: acceptance gate templates must match {sorted(required)}") + for template in templates: + template_id = template.get("template_id") + if template.get("target_promotion") != _TARGET_PROMOTION: + raise ValueError(f"{label}: template {template_id} must target {_TARGET_PROMOTION}") + if template.get("promotion_write_enabled") is not False: + raise ValueError(f"{label}: template {template_id} must not enable promotion write") + if template.get("status") not in {"ready", "approval_required", "blocked_by_policy"}: + raise ValueError(f"{label}: template {template_id} status is invalid") + if not template.get("required_owner") or not template.get("required_fields"): + raise ValueError(f"{label}: template {template_id} required owner and fields are required") + if not _is_redacted_sha256(template.get("evidence_hash")): + raise ValueError(f"{label}: template {template_id} must expose redacted evidence_hash") + + +def _require_verifier_checks(payload: dict[str, Any], label: str) -> None: + checks = payload.get("promotion_verifier_checks") or [] + required = { + "no_result_capture_write_before_approval", + "no_learning_write_before_approval", + "no_playbook_trust_before_approval", + "no_gateway_queue_before_approval", + "promotion_redaction_completeness", + } + verifier_ids = {check.get("verifier_id") for check in checks} + if verifier_ids != required: + raise ValueError(f"{label}: promotion verifier checks must match {sorted(required)}") + for check in checks: + verifier_id = check.get("verifier_id") + if check.get("live_execution_enabled") is not False: + raise ValueError(f"{label}: verifier {verifier_id} must not enable live execution") + if check.get("status") not in {"ready", "approval_required", "blocked_by_policy"}: + raise ValueError(f"{label}: verifier {verifier_id} status is invalid") + if not check.get("verifies") or not check.get("failure_if_missing"): + raise ValueError(f"{label}: verifier {verifier_id} must include verifies and failure_if_missing") + if not _is_redacted_sha256(check.get("evidence_hash")): + raise ValueError(f"{label}: verifier {verifier_id} must expose redacted evidence_hash") + + +def _require_blockers(payload: dict[str, Any], label: str) -> None: + blockers = payload.get("blocked_promotion_writes") or [] + required = { + "result_capture_promotion_not_authorized", + "learning_promotion_not_authorized", + "playbook_trust_promotion_not_authorized", + "gateway_queue_promotion_not_authorized", + "production_promotion_not_authorized", + } + blocker_ids = {blocker.get("blocker_id") for blocker in blockers} + if blocker_ids != required: + raise ValueError(f"{label}: blocked promotion writes must match {sorted(required)}") + for blocker in blockers: + blocker_id = blocker.get("blocker_id") + if blocker.get("status") not in {"approval_required", "blocked_by_policy"}: + raise ValueError(f"{label}: blocker {blocker_id} status is invalid") + if blocker.get("severity") not in {"high", "critical"}: + raise ValueError(f"{label}: blocker {blocker_id} severity is invalid") + if not blocker.get("blocked_action") or not blocker.get("blocked_until"): + raise ValueError(f"{label}: blocker {blocker_id} must include blocked_action and blocked_until") + if not _is_redacted_sha256(blocker.get("evidence_hash")): + raise ValueError(f"{label}: blocker {blocker_id} must expose redacted evidence_hash") + + +def _require_actions(payload: dict[str, Any], label: str) -> None: + actions = payload.get("operator_actions") or [] + required = { + "review_promotion_approval_packet", + "verify_no_write_promotion_counts", + "confirm_acceptance_scope", + "check_promotion_redaction_contract", + "promote_to_p2_120", + } + action_ids = {action.get("action_id") for action in actions} + if action_ids != required: + raise ValueError(f"{label}: operator actions must match {sorted(required)}") + for action in actions: + action_id = action.get("action_id") + if action.get("runtime_promotion_write_allowed") is not False: + raise ValueError(f"{label}: action {action_id} must not allow runtime promotion write") + if not action.get("operator_instruction"): + raise ValueError(f"{label}: action {action_id} operator_instruction is required") + + +def _require_display_redaction(payload: dict[str, Any], label: str) -> None: + contract = payload.get("display_redaction_contract") or {} + expected = { + "redaction_required": True, + "raw_prompt_display_allowed": False, + "private_reasoning_display_allowed": False, + "secret_value_display_allowed": False, + "raw_runtime_payload_display_allowed": False, + "internal_collaboration_content_display_allowed": False, + } + mismatches = _mismatches(contract, expected) + if mismatches: + raise ValueError(f"{label}: display_redaction_contract mismatch: {mismatches}") + if not contract.get("frontend_display_policy"): + raise ValueError(f"{label}: display_redaction_contract.frontend_display_policy is required") + + +def _require_rollup_consistency(payload: dict[str, Any], label: str) -> None: + rollups = payload.get("rollups") or {} + packets = payload.get("promotion_approval_packets") or [] + templates = payload.get("acceptance_gate_templates") or [] + verifiers = payload.get("promotion_verifier_checks") or [] + blockers = payload.get("blocked_promotion_writes") or [] + actions = payload.get("operator_actions") or [] + expected = { + "promotion_approval_packet_count": len(packets), + "acceptance_gate_template_count": len(templates), + "promotion_verifier_check_count": len(verifiers), + "blocked_promotion_write_count": len(blockers), + "operator_action_count": len(actions), + "approval_required_packet_count": sum(1 for item in packets if item.get("status") == "approval_required"), + "blocked_packet_count": sum(1 for item in packets if item.get("status") == "blocked_by_policy"), + "approval_required_template_count": sum(1 for item in templates if item.get("status") == "approval_required"), + "blocked_template_count": sum(1 for item in templates if item.get("status") == "blocked_by_policy"), + "approval_required_verifier_count": sum(1 for item in verifiers if item.get("status") == "approval_required"), + "critical_blocker_count": sum(1 for item in blockers if item.get("severity") == "critical"), + "owner_approval_received_count": 0, + "capture_promotion_approved_count": 0, + "canonical_runtime_target_read_count": 0, + "live_query_count": 0, + "reviewer_queue_write_count": 0, + "gateway_queue_write_count": 0, + "telegram_send_count": 0, + "bot_api_call_count": 0, + "report_receipt_write_count": 0, + "result_capture_write_count": 0, + "learning_write_count": 0, + "playbook_trust_write_count": 0, + "production_write_count": 0, + "secret_read_count": 0, + "destructive_operation_count": 0, + } + mismatches = _mismatches(rollups, expected) + if mismatches: + raise ValueError(f"{label}: rollup counts mismatch: {mismatches}") + + +def _require_no_forbidden_display_terms(payload: dict[str, Any], label: str) -> None: + serialized = json.dumps(payload, ensure_ascii=False) + forbidden = { + "work_window_transcript", + "session_id", + "browser_context", + "authorization_header", + "raw Telegram payload", + "private reasoning", + "raw prompt", + "chain-of-thought", + } + hits = sorted(term for term in forbidden if term in serialized) + if hits: + raise ValueError(f"{label}: forbidden display terms present: {hits}") + + +def _is_redacted_sha256(value: Any) -> bool: + if not isinstance(value, str) or not value.startswith("sha256:"): + return False + digest = value.removeprefix("sha256:") + return len(digest) == 64 and all(char in "0123456789abcdef" for char in digest) + + +def _mismatches(payload: dict[str, Any], expected: dict[str, Any]) -> dict[str, dict[str, Any]]: + return { + key: {"expected": value, "actual": payload.get(key)} + for key, value in expected.items() + if payload.get(key) != value + } diff --git a/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate.py b/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate.py new file mode 100644 index 000000000..53bb5cfe1 --- /dev/null +++ b/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate.py @@ -0,0 +1,113 @@ +import copy +import json +from pathlib import Path + +import pytest + +from src.services.ai_agent_result_capture_promotion_approval_gate import ( + load_latest_ai_agent_result_capture_promotion_approval_gate, +) + + +REPO_ROOT = Path(__file__).resolve().parents[3] +FIXTURE = REPO_ROOT / "docs/evaluations/ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + + +def test_load_latest_ai_agent_result_capture_promotion_approval_gate_snapshot() -> None: + data = load_latest_ai_agent_result_capture_promotion_approval_gate() + + assert data["schema_version"] == "ai_agent_result_capture_promotion_approval_gate_v1" + assert data["program_status"]["current_task_id"] == "P2-119" + assert data["program_status"]["next_task_id"] == "P2-120" + assert data["program_status"]["overall_completion_percent"] == 100 + assert data["program_status"]["read_only_mode"] is True + + rollups = data["rollups"] + assert rollups["promotion_approval_packet_count"] == 5 + assert rollups["acceptance_gate_template_count"] == 5 + assert rollups["promotion_verifier_check_count"] == 5 + assert rollups["blocked_promotion_write_count"] == 5 + assert rollups["operator_action_count"] == 5 + assert rollups["approval_required_packet_count"] == 2 + assert rollups["blocked_packet_count"] == 2 + assert rollups["approval_required_template_count"] == 2 + assert rollups["blocked_template_count"] == 2 + assert rollups["approval_required_verifier_count"] == 2 + assert rollups["critical_blocker_count"] == 3 + + assert {template["target_promotion"] for template in data["acceptance_gate_templates"]} == { + "result_capture_promotion_preview" + } + assert {packet["promotion_mode"] for packet in data["promotion_approval_packets"]} == { + "approval_gate_only" + } + + zero_fields = [ + "owner_approval_received_count", + "capture_promotion_approved_count", + "canonical_runtime_target_read_count", + "live_query_count", + "reviewer_queue_write_count", + "gateway_queue_write_count", + "telegram_send_count", + "bot_api_call_count", + "report_receipt_write_count", + "result_capture_write_count", + "learning_write_count", + "playbook_trust_write_count", + "production_write_count", + "secret_read_count", + "destructive_operation_count", + ] + for field in zero_fields: + assert rollups[field] == 0 + + +def test_result_capture_promotion_gate_rejects_capture_write_enabled(tmp_path: Path) -> None: + source = json.loads(FIXTURE.read_text(encoding="utf-8")) + source["promotion_approval_packets"][0]["result_capture_write_enabled"] = True + target = tmp_path / "ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + target.write_text(json.dumps(source), encoding="utf-8") + + with pytest.raises(ValueError, match="must not enable result capture write"): + load_latest_ai_agent_result_capture_promotion_approval_gate(tmp_path) + + +def test_result_capture_promotion_gate_rejects_truth_write_flag(tmp_path: Path) -> None: + source = json.loads(FIXTURE.read_text(encoding="utf-8")) + source["promotion_truth"]["result_capture_write_enabled"] = True + target = tmp_path / "ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + target.write_text(json.dumps(source), encoding="utf-8") + + with pytest.raises(ValueError, match="live read/send/write flags"): + load_latest_ai_agent_result_capture_promotion_approval_gate(tmp_path) + + +def test_result_capture_promotion_gate_rejects_target_promotion_drift(tmp_path: Path) -> None: + source = json.loads(FIXTURE.read_text(encoding="utf-8")) + source["acceptance_gate_templates"][0]["target_promotion"] = "live_result_capture_promotion" + target = tmp_path / "ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + target.write_text(json.dumps(source), encoding="utf-8") + + with pytest.raises(ValueError, match="must target result_capture_promotion_preview"): + load_latest_ai_agent_result_capture_promotion_approval_gate(tmp_path) + + +def test_result_capture_promotion_gate_rejects_rollup_drift(tmp_path: Path) -> None: + source = json.loads(FIXTURE.read_text(encoding="utf-8")) + source["rollups"]["promotion_approval_packet_count"] = 4 + target = tmp_path / "ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + target.write_text(json.dumps(source), encoding="utf-8") + + with pytest.raises(ValueError, match="rollup counts mismatch"): + load_latest_ai_agent_result_capture_promotion_approval_gate(tmp_path) + + +def test_result_capture_promotion_gate_rejects_forbidden_display_terms(tmp_path: Path) -> None: + source = copy.deepcopy(json.loads(FIXTURE.read_text(encoding="utf-8"))) + source["operator_actions"][0]["operator_instruction"] = "do not expose session_id" + target = tmp_path / "ai_agent_result_capture_promotion_approval_gate_2026-06-13.json" + target.write_text(json.dumps(source), encoding="utf-8") + + with pytest.raises(ValueError, match="forbidden display terms"): + load_latest_ai_agent_result_capture_promotion_approval_gate(tmp_path) diff --git a/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate_api.py b/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate_api.py new file mode 100644 index 000000000..7cdf421c3 --- /dev/null +++ b/apps/api/tests/test_ai_agent_result_capture_promotion_approval_gate_api.py @@ -0,0 +1,44 @@ +import pytest +from httpx import ASGITransport, AsyncClient + +from src.main import app + + +@pytest.mark.asyncio +async def test_get_agent_result_capture_promotion_approval_gate_api() -> None: + transport = ASGITransport(app=app) + async with AsyncClient(transport=transport, base_url="http://test") as client: + response = await client.get("/api/v1/agents/agent-result-capture-promotion-approval-gate") + + assert response.status_code == 200 + data = response.json() + assert data["schema_version"] == "ai_agent_result_capture_promotion_approval_gate_v1" + assert data["program_status"]["current_task_id"] == "P2-119" + assert data["program_status"]["next_task_id"] == "P2-120" + assert data["program_status"]["overall_completion_percent"] == 100 + + rollups = data["rollups"] + assert rollups["promotion_approval_packet_count"] == 5 + assert rollups["acceptance_gate_template_count"] == 5 + assert rollups["promotion_verifier_check_count"] == 5 + assert rollups["blocked_promotion_write_count"] == 5 + assert rollups["operator_action_count"] == 5 + assert rollups["critical_blocker_count"] == 3 + assert rollups["owner_approval_received_count"] == 0 + assert rollups["capture_promotion_approved_count"] == 0 + assert rollups["canonical_runtime_target_read_count"] == 0 + assert rollups["live_query_count"] == 0 + assert rollups["reviewer_queue_write_count"] == 0 + assert rollups["gateway_queue_write_count"] == 0 + assert rollups["telegram_send_count"] == 0 + assert rollups["bot_api_call_count"] == 0 + assert rollups["report_receipt_write_count"] == 0 + assert rollups["result_capture_write_count"] == 0 + assert rollups["learning_write_count"] == 0 + assert rollups["playbook_trust_write_count"] == 0 + assert rollups["production_write_count"] == 0 + + assert {template["target_promotion"] for template in data["acceptance_gate_templates"]} == { + "result_capture_promotion_preview" + } + assert {packet["result_capture_write_enabled"] for packet in data["promotion_approval_packets"]} == {False} diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json index b222006d4..72057823e 100644 --- a/apps/web/messages/en.json +++ b/apps/web/messages/en.json @@ -5641,6 +5641,40 @@ "blockedAction": "blocked:{value}", "runtimeCaptureWriteAllowed": "runtime capture write={value}" } + }, + "resultCapturePromotionApprovalGate": { + "title": "P2-119 result capture promotion approval gate", + "source": "產生 {generated};目前 {current};下一步 {next}", + "priorTitle": "前一關 result capture readback", + "truthTitle": "Promotion approval truth", + "metrics": { + "overall": "完成度", + "packets": "Promotion packets", + "templates": "Acceptance templates", + "verifiers": "Verifiers", + "blockers": "Blocked writes", + "actions": "操作選項", + "approvalRequired": "需批准", + "blocked": "阻擋", + "liveWrites": "Live promotion / write" + }, + "flags": { + "packageReady": "package ready={value}", + "templateReady": "template ready={value}" + }, + "labels": { + "targetPromotion": "目標 promotion:{value}", + "resultWrites": "result write={value}", + "learningWrites": "learning write={value}", + "trustWrites": "trust write={value}", + "approvalLane": "lane:{value}", + "captureWriteEnabled": "capture write={value}", + "promotionWriteEnabled": "promotion write={value}", + "requiredOwner": "owner:{value}", + "requiredFields": "fields:{value}", + "blockedAction": "blocked:{value}", + "runtimePromotionWriteAllowed": "runtime promotion write={value}" + } } } }, diff --git a/apps/web/messages/zh-TW.json b/apps/web/messages/zh-TW.json index b222006d4..72057823e 100644 --- a/apps/web/messages/zh-TW.json +++ b/apps/web/messages/zh-TW.json @@ -5641,6 +5641,40 @@ "blockedAction": "blocked:{value}", "runtimeCaptureWriteAllowed": "runtime capture write={value}" } + }, + "resultCapturePromotionApprovalGate": { + "title": "P2-119 result capture promotion approval gate", + "source": "產生 {generated};目前 {current};下一步 {next}", + "priorTitle": "前一關 result capture readback", + "truthTitle": "Promotion approval truth", + "metrics": { + "overall": "完成度", + "packets": "Promotion packets", + "templates": "Acceptance templates", + "verifiers": "Verifiers", + "blockers": "Blocked writes", + "actions": "操作選項", + "approvalRequired": "需批准", + "blocked": "阻擋", + "liveWrites": "Live promotion / write" + }, + "flags": { + "packageReady": "package ready={value}", + "templateReady": "template ready={value}" + }, + "labels": { + "targetPromotion": "目標 promotion:{value}", + "resultWrites": "result write={value}", + "learningWrites": "learning write={value}", + "trustWrites": "trust write={value}", + "approvalLane": "lane:{value}", + "captureWriteEnabled": "capture write={value}", + "promotionWriteEnabled": "promotion write={value}", + "requiredOwner": "owner:{value}", + "requiredFields": "fields:{value}", + "blockedAction": "blocked:{value}", + "runtimePromotionWriteAllowed": "runtime promotion write={value}" + } } } }, diff --git a/apps/web/src/app/[locale]/governance/tabs/automation-inventory-tab.tsx b/apps/web/src/app/[locale]/governance/tabs/automation-inventory-tab.tsx index 7b8735c25..bd7401701 100644 --- a/apps/web/src/app/[locale]/governance/tabs/automation-inventory-tab.tsx +++ b/apps/web/src/app/[locale]/governance/tabs/automation-inventory-tab.tsx @@ -66,6 +66,7 @@ import { type AiAgentFailureReceiptNoSendReplaySnapshot, type AiAgentReviewerQueueNoWriteReadbackSnapshot, type AiAgentResultCaptureNoWriteReadbackSnapshot, + type AiAgentResultCapturePromotionApprovalGateSnapshot, type AiAgentOwnerApprovedFixturePromotionGateSnapshot, type AiAgentRuntimeWorkerShadowGateSnapshot, type AiAgentRuntimeVerifierEvidenceReviewSnapshot, @@ -454,6 +455,7 @@ export function AutomationInventoryTab() { const [failureReceiptNoSendReplay, setFailureReceiptNoSendReplay] = useState(null) const [reviewerQueueNoWriteReadback, setReviewerQueueNoWriteReadback] = useState(null) const [resultCaptureNoWriteReadback, setResultCaptureNoWriteReadback] = useState(null) + const [resultCapturePromotionApprovalGate, setResultCapturePromotionApprovalGate] = useState(null) const [reportTruthActionabilityReview, setReportTruthActionabilityReview] = useState(null) const [ownerDryRunPackage, setOwnerDryRunPackage] = useState(null) const [hostStatefulInventory, setHostStatefulInventory] = useState(null) @@ -509,6 +511,7 @@ export function AutomationInventoryTab() { apiClient.getAiAgentFailureReceiptNoSendReplay(), apiClient.getAiAgentReviewerQueueNoWriteReadback(), apiClient.getAiAgentResultCaptureNoWriteReadback(), + apiClient.getAiAgentResultCapturePromotionApprovalGate(), apiClient.getAiAgentReportTruthActionabilityReview(), apiClient.getAiAgentOwnerApprovedFixtureDryRun(), apiClient.getAiAgentHostStatefulVersionInventory(), @@ -563,6 +566,7 @@ export function AutomationInventoryTab() { failureReceiptNoSendReplayResult, reviewerQueueNoWriteReadbackResult, resultCaptureNoWriteReadbackResult, + resultCapturePromotionApprovalGateResult, reportTruthActionabilityReviewResult, ownerDryRunPackageResult, hostStatefulInventoryResult, @@ -614,6 +618,7 @@ export function AutomationInventoryTab() { setFailureReceiptNoSendReplay(failureReceiptNoSendReplayResult.status === 'fulfilled' ? failureReceiptNoSendReplayResult.value : null) setReviewerQueueNoWriteReadback(reviewerQueueNoWriteReadbackResult.status === 'fulfilled' ? reviewerQueueNoWriteReadbackResult.value : null) setResultCaptureNoWriteReadback(resultCaptureNoWriteReadbackResult.status === 'fulfilled' ? resultCaptureNoWriteReadbackResult.value : null) + setResultCapturePromotionApprovalGate(resultCapturePromotionApprovalGateResult.status === 'fulfilled' ? resultCapturePromotionApprovalGateResult.value : null) setReportTruthActionabilityReview(reportTruthActionabilityReviewResult.status === 'fulfilled' ? reportTruthActionabilityReviewResult.value : null) setOwnerDryRunPackage(ownerDryRunPackageResult.status === 'fulfilled' ? ownerDryRunPackageResult.value : null) setHostStatefulInventory(hostStatefulInventoryResult.status === 'fulfilled' ? hostStatefulInventoryResult.value : null) @@ -663,6 +668,7 @@ export function AutomationInventoryTab() { failureReceiptNoSendReplayResult, reviewerQueueNoWriteReadbackResult, resultCaptureNoWriteReadbackResult, + resultCapturePromotionApprovalGateResult, reportTruthActionabilityReviewResult, ownerDryRunPackageResult, hostStatefulInventoryResult, @@ -1905,7 +1911,7 @@ export function AutomationInventoryTab() { ) } - if (error || !snapshot || !backlog || !backupTargets || !backupReadiness || !backupPolicy || !offsiteEscrow || !giteaHealth || !observabilityMatrix || !providerRouteMatrix || !deploymentLayout || !proactiveOperations || !interactionLearningProof || !liveReadModelGate || !redisDryRunGate || !learningWritebackPackage || !telegramReceiptPackage || !ownerApprovedLearningDryRun || !runtimeWriteGateReview || !postWriteVerifierPackage || !runtimeVerifierEvidenceReview || !reportAutomationReview || !reportStatusBoard || !reportRuntimeReadiness || !reportRuntimeDryRun || !reportRuntimeFixtureReadback || !runtimeWorkerShadowGate || !operationPermissionModel || !candidateOperationDryRunEvidence || !taskResultAuditTrail || !matchedPlaybookLearningGap || !criticReviewerResultCapture || !ownerApprovedResultCaptureDryRun || !ownerApprovedResultCaptureReadback || !runtimeReadbackApprovalPackage || !runtimeReadbackImplementationReview || !reportLiveDeliveryApprovalPackage || !runtimeReadbackFixtureApproval || !runtimeReadbackPromotionGate || !ownerApprovedFixturePromotionGate || !canonicalRuntimeReadbackOwnerAcceptance || !failureReceiptNoSendReplay || !reviewerQueueNoWriteReadback || !resultCaptureNoWriteReadback || !reportTruthActionabilityReview || !ownerDryRunPackage || !hostStatefulInventory || !serviceHealthGapMatrix || !serviceHealthNotificationPolicy) { + if (error || !snapshot || !backlog || !backupTargets || !backupReadiness || !backupPolicy || !offsiteEscrow || !giteaHealth || !observabilityMatrix || !providerRouteMatrix || !deploymentLayout || !proactiveOperations || !interactionLearningProof || !liveReadModelGate || !redisDryRunGate || !learningWritebackPackage || !telegramReceiptPackage || !ownerApprovedLearningDryRun || !runtimeWriteGateReview || !postWriteVerifierPackage || !runtimeVerifierEvidenceReview || !reportAutomationReview || !reportStatusBoard || !reportRuntimeReadiness || !reportRuntimeDryRun || !reportRuntimeFixtureReadback || !runtimeWorkerShadowGate || !operationPermissionModel || !candidateOperationDryRunEvidence || !taskResultAuditTrail || !matchedPlaybookLearningGap || !criticReviewerResultCapture || !ownerApprovedResultCaptureDryRun || !ownerApprovedResultCaptureReadback || !runtimeReadbackApprovalPackage || !runtimeReadbackImplementationReview || !reportLiveDeliveryApprovalPackage || !runtimeReadbackFixtureApproval || !runtimeReadbackPromotionGate || !ownerApprovedFixturePromotionGate || !canonicalRuntimeReadbackOwnerAcceptance || !failureReceiptNoSendReplay || !reviewerQueueNoWriteReadback || !resultCaptureNoWriteReadback || !resultCapturePromotionApprovalGate || !reportTruthActionabilityReview || !ownerDryRunPackage || !hostStatefulInventory || !serviceHealthGapMatrix || !serviceHealthNotificationPolicy) { return (
@@ -2561,6 +2567,35 @@ export function AutomationInventoryTab() { + resultCaptureNoWriteReadback.rollups.playbook_trust_write_count + resultCaptureNoWriteReadback.rollups.production_write_count ) + const resultPromotionOverall = resultCapturePromotionApprovalGate.program_status.overall_completion_percent + const resultPromotionPackets = resultCapturePromotionApprovalGate.rollups.promotion_approval_packet_count + const resultPromotionTemplates = resultCapturePromotionApprovalGate.rollups.acceptance_gate_template_count + const resultPromotionVerifiers = resultCapturePromotionApprovalGate.rollups.promotion_verifier_check_count + const resultPromotionBlockers = resultCapturePromotionApprovalGate.rollups.blocked_promotion_write_count + const resultPromotionActions = resultCapturePromotionApprovalGate.rollups.operator_action_count + const resultPromotionApprovalRequired = ( + resultCapturePromotionApprovalGate.rollups.approval_required_packet_count + + resultCapturePromotionApprovalGate.rollups.approval_required_template_count + + resultCapturePromotionApprovalGate.rollups.approval_required_verifier_count + ) + const resultPromotionBlocked = ( + resultCapturePromotionApprovalGate.rollups.blocked_packet_count + + resultCapturePromotionApprovalGate.rollups.blocked_template_count + + resultCapturePromotionApprovalGate.rollups.critical_blocker_count + ) + const resultPromotionLiveWrites = ( + resultCapturePromotionApprovalGate.rollups.canonical_runtime_target_read_count + + resultCapturePromotionApprovalGate.rollups.live_query_count + + resultCapturePromotionApprovalGate.rollups.reviewer_queue_write_count + + resultCapturePromotionApprovalGate.rollups.gateway_queue_write_count + + resultCapturePromotionApprovalGate.rollups.telegram_send_count + + resultCapturePromotionApprovalGate.rollups.bot_api_call_count + + resultCapturePromotionApprovalGate.rollups.report_receipt_write_count + + resultCapturePromotionApprovalGate.rollups.result_capture_write_count + + resultCapturePromotionApprovalGate.rollups.learning_write_count + + resultCapturePromotionApprovalGate.rollups.playbook_trust_write_count + + resultCapturePromotionApprovalGate.rollups.production_write_count + ) const reportTruthOverall = reportTruthActionabilityReview.program_status.overall_completion_percent const reportTruthFindings = reportTruthActionabilityReview.rollups.zero_signal_finding_count const reportTruthCritical = reportTruthActionabilityReview.rollups.critical_finding_count @@ -6979,6 +7014,140 @@ export function AutomationInventoryTab() {
+
+
+
+ + + {t('resultCapturePromotionApprovalGate.title')} + +
+ +
+ +
+ } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> +
+ +
+
+ {t('resultCapturePromotionApprovalGate.priorTitle')} + + {resultCapturePromotionApprovalGate.prior_result_capture_no_write_readback.readiness_note} + +
+ + + +
+
+ +
+ {t('resultCapturePromotionApprovalGate.truthTitle')} + + {resultCapturePromotionApprovalGate.promotion_truth.truth_note} + +
+ + + + + + +
+
+
+ +
+ {resultCapturePromotionApprovalGate.promotion_approval_packets.slice(0, 3).map(packet => ( +
+
+ + {packet.display_name} + + +
+ + {packet.required_decision} + +
+ + + +
+
+ ))} +
+ +
+ {resultCapturePromotionApprovalGate.acceptance_gate_templates.slice(0, 5).map(template => ( +
+
+ + {template.display_name} + + +
+
+ + + + +
+
+ ))} +
+ +
+ {resultCapturePromotionApprovalGate.blocked_promotion_writes.slice(0, 3).map(blocker => ( +
+
+ + {blocker.display_name} + + +
+
+ + +
+
+ ))} +
+ +
+ {resultCapturePromotionApprovalGate.operator_actions.slice(0, 3).map(action => ( +
+
+ + {action.display_name} + + +
+ + {action.operator_instruction} + + +
+ ))} +
+
+
diff --git a/apps/web/src/lib/api-client.ts b/apps/web/src/lib/api-client.ts index 8f40b55cc..d93b5aab8 100644 --- a/apps/web/src/lib/api-client.ts +++ b/apps/web/src/lib/api-client.ts @@ -490,6 +490,11 @@ export const apiClient = { return handleResponse(res) }, + async getAiAgentResultCapturePromotionApprovalGate() { + const res = await fetch(`${API_BASE_URL}/agents/agent-result-capture-promotion-approval-gate`) + return handleResponse(res) + }, + async getAiAgentOwnerApprovedFixtureDryRun() { const res = await fetch(`${API_BASE_URL}/agents/agent-owner-approved-fixture-dry-run`) return handleResponse(res) @@ -5303,6 +5308,161 @@ export interface AiAgentResultCaptureNoWriteReadbackSnapshot { } } +export interface AiAgentResultCapturePromotionApprovalGateSnapshot { + schema_version: 'ai_agent_result_capture_promotion_approval_gate_v1' + generated_at: string + program_status: { + overall_completion_percent: number + current_priority: 'P0' | 'P1' | 'P2' | 'P3' + current_task_id: 'P2-119' + next_task_id: 'P2-120' + read_only_mode: true + runtime_authority: 'result_capture_promotion_approval_gate_only_no_capture_or_learning_write' + status_note: string + } + source_refs: string[] + prior_result_capture_no_write_readback: { + schema_version: string + result_capture_readback_fixture_count: number + capture_field_mapping_count: number + readback_verifier_check_count: number + blocked_result_capture_write_count: number + operator_action_count: number + result_capture_write_count: number + learning_write_count: number + playbook_trust_write_count: number + reviewer_queue_write_count: number + gateway_queue_write_count: number + telegram_send_count: number + bot_api_call_count: number + report_receipt_write_count: number + readiness_note: string + } + promotion_truth: { + p2_118_result_capture_readback_loaded: boolean + promotion_approval_package_ready: boolean + acceptance_gate_template_ready: boolean + promotion_verifier_ready: boolean + operator_handoff_ready: boolean + rollback_and_reverify_required: boolean + owner_approval_received: boolean + capture_promotion_approved: boolean + canonical_runtime_target_read_enabled: boolean + live_query_enabled: boolean + reviewer_queue_write_enabled: boolean + gateway_queue_write_enabled: boolean + telegram_send_enabled: boolean + bot_api_call_enabled: boolean + report_receipt_write_enabled: boolean + result_capture_write_enabled: boolean + learning_write_enabled: boolean + playbook_trust_write_enabled: boolean + production_write_enabled: boolean + secret_read_enabled: boolean + destructive_operation_enabled: boolean + owner_approval_received_count: number + capture_promotion_approved_count: number + canonical_runtime_target_read_count: number + live_query_count: number + reviewer_queue_write_count: number + gateway_queue_write_count: number + telegram_send_count: number + bot_api_call_count: number + report_receipt_write_count: number + result_capture_write_count: number + learning_write_count: number + playbook_trust_write_count: number + production_write_count: number + truth_note: string + } + promotion_approval_packets: Array<{ + packet_id: string + display_name: string + owner_agent: 'openclaw' | 'hermes' | 'nemotron' + source_capture_fixture_id: string + status: 'ready_for_owner_review' | 'approval_required' | 'blocked_by_policy' + approval_lane: string + promotion_mode: 'approval_gate_only' + result_capture_write_enabled: false + required_decision: string + evidence_hash: string + }> + acceptance_gate_templates: Array<{ + template_id: string + display_name: string + status: 'ready' | 'approval_required' | 'blocked_by_policy' + source_packet_id: string + target_promotion: string + promotion_write_enabled: false + required_owner: string + required_fields: string[] + evidence_hash: string + }> + promotion_verifier_checks: Array<{ + verifier_id: string + display_name: string + owner_agent: 'openclaw' | 'hermes' | 'nemotron' + status: 'ready' | 'approval_required' | 'blocked_by_policy' + verifies: string + failure_if_missing: string + live_execution_enabled: false + evidence_hash: string + }> + blocked_promotion_writes: Array<{ + blocker_id: string + display_name: string + severity: 'high' | 'critical' + status: 'approval_required' | 'blocked_by_policy' + blocked_action: string + blocked_until: string + evidence_hash: string + }> + operator_actions: Array<{ + action_id: string + display_name: string + owner_agent: 'openclaw' | 'hermes' | 'nemotron' + operator_instruction: string + runtime_promotion_write_allowed: false + }> + display_redaction_contract: { + redaction_required: true + raw_prompt_display_allowed: false + private_reasoning_display_allowed: false + secret_value_display_allowed: false + raw_runtime_payload_display_allowed: false + internal_collaboration_content_display_allowed: false + frontend_display_policy: string + } + rollups: { + promotion_approval_packet_count: number + acceptance_gate_template_count: number + promotion_verifier_check_count: number + blocked_promotion_write_count: number + operator_action_count: number + approval_required_packet_count: number + blocked_packet_count: number + approval_required_template_count: number + blocked_template_count: number + approval_required_verifier_count: number + critical_blocker_count: number + owner_approval_received_count: number + capture_promotion_approved_count: number + canonical_runtime_target_read_count: number + live_query_count: number + reviewer_queue_write_count: number + gateway_queue_write_count: number + telegram_send_count: number + bot_api_call_count: number + report_receipt_write_count: number + result_capture_write_count: number + learning_write_count: number + playbook_trust_write_count: number + production_write_count: number + secret_read_count: number + destructive_operation_count: number + } +} + export interface AiAgentOwnerApprovedFixtureDryRunSnapshot { schema_version: 'ai_agent_owner_approved_fixture_dry_run_v1' generated_at: string diff --git a/docs/evaluations/ai_agent_result_capture_promotion_approval_gate_2026-06-13.json b/docs/evaluations/ai_agent_result_capture_promotion_approval_gate_2026-06-13.json new file mode 100644 index 000000000..e2dc8c392 --- /dev/null +++ b/docs/evaluations/ai_agent_result_capture_promotion_approval_gate_2026-06-13.json @@ -0,0 +1,391 @@ +{ + "schema_version": "ai_agent_result_capture_promotion_approval_gate_v1", + "generated_at": "2026-06-13T22:20:00+08:00", + "program_status": { + "overall_completion_percent": 100, + "current_priority": "P2", + "current_task_id": "P2-119", + "next_task_id": "P2-120", + "read_only_mode": true, + "runtime_authority": "result_capture_promotion_approval_gate_only_no_capture_or_learning_write", + "status_note": "P2-119 只建立 result capture promotion 的批准閘門、acceptance template、verifier 與阻擋條件;不得寫 result capture、learning、PlayBook trust、Gateway queue、Telegram 或 production。" + }, + "source_refs": [ + "docs/evaluations/ai_agent_result_capture_no_write_readback_2026-06-13.json", + "docs/evaluations/ai_agent_reviewer_queue_no_write_readback_2026-06-13.json", + "docs/evaluations/ai_agent_critic_reviewer_result_capture_2026-06-13.json", + "docs/superpowers/specs/2026-04-15-MASTER-ai-autonomous-flywheel-v2.md#38-建立-reviewer-queue-no-write-readback" + ], + "prior_result_capture_no_write_readback": { + "schema_version": "ai_agent_result_capture_no_write_readback_v1", + "result_capture_readback_fixture_count": 5, + "capture_field_mapping_count": 5, + "readback_verifier_check_count": 5, + "blocked_result_capture_write_count": 5, + "operator_action_count": 5, + "result_capture_write_count": 0, + "learning_write_count": 0, + "playbook_trust_write_count": 0, + "reviewer_queue_write_count": 0, + "gateway_queue_write_count": 0, + "telegram_send_count": 0, + "bot_api_call_count": 0, + "report_receipt_write_count": 0, + "readiness_note": "P2-118 已正式驗證 result capture no-write readback;P2-119 只把 promotion approval、acceptance template、verifier 與人工操作選項固定成可審查證據。" + }, + "promotion_truth": { + "p2_118_result_capture_readback_loaded": true, + "promotion_approval_package_ready": true, + "acceptance_gate_template_ready": true, + "promotion_verifier_ready": true, + "operator_handoff_ready": true, + "rollback_and_reverify_required": true, + "owner_approval_received": false, + "capture_promotion_approved": false, + "canonical_runtime_target_read_enabled": false, + "live_query_enabled": false, + "reviewer_queue_write_enabled": false, + "gateway_queue_write_enabled": false, + "telegram_send_enabled": false, + "bot_api_call_enabled": false, + "report_receipt_write_enabled": false, + "result_capture_write_enabled": false, + "learning_write_enabled": false, + "playbook_trust_write_enabled": false, + "production_write_enabled": false, + "secret_read_enabled": false, + "destructive_operation_enabled": false, + "owner_approval_received_count": 0, + "capture_promotion_approved_count": 0, + "canonical_runtime_target_read_count": 0, + "live_query_count": 0, + "reviewer_queue_write_count": 0, + "gateway_queue_write_count": 0, + "telegram_send_count": 0, + "bot_api_call_count": 0, + "report_receipt_write_count": 0, + "result_capture_write_count": 0, + "learning_write_count": 0, + "playbook_trust_write_count": 0, + "production_write_count": 0, + "truth_note": "promotion approval gate 已可審查;真正 result capture write、learning write、PlayBook trust write、Gateway queue write 與 Telegram send 仍全部為 0。" + }, + "promotion_approval_packets": [ + { + "packet_id": "promotion_packet_action_required", + "display_name": "Action-required promotion packet", + "owner_agent": "openclaw", + "source_capture_fixture_id": "result_capture_action_required_preview", + "status": "ready_for_owner_review", + "approval_lane": "manual_repair_result_promotion", + "promotion_mode": "approval_gate_only", + "result_capture_write_enabled": false, + "required_decision": "確認修復結果、verifier、人工下一步與回滾條件後,才可進 promotion 候選。", + "evidence_hash": "sha256:7171717171717171717171717171717171717171717171717171717171717171" + }, + { + "packet_id": "promotion_packet_no_action_review", + "display_name": "No-action promotion review", + "owner_agent": "hermes", + "source_capture_fixture_id": "result_capture_no_action_review", + "status": "approval_required", + "approval_lane": "manual_no_action_acceptance", + "promotion_mode": "approval_gate_only", + "result_capture_write_enabled": false, + "required_decision": "補齊 no-action 的判讀理由、風險剩餘量與下一次觀察條件,未補齊前不得 promotion。", + "evidence_hash": "sha256:7272727272727272727272727272727272727272727272727272727272727272" + }, + { + "packet_id": "promotion_packet_verifier_degraded", + "display_name": "Verifier degraded promotion hold", + "owner_agent": "nemotron", + "source_capture_fixture_id": "result_capture_verifier_degraded_hold", + "status": "blocked_by_policy", + "approval_lane": "rollback_or_reverify_acceptance", + "promotion_mode": "approval_gate_only", + "result_capture_write_enabled": false, + "required_decision": "degraded verifier 必須先決定 rollback、reverify 或補 MCP evidence;未完成前不得 promotion。", + "evidence_hash": "sha256:7373737373737373737373737373737373737373737373737373737373737373" + }, + { + "packet_id": "promotion_packet_route_lock", + "display_name": "SRE route lock promotion packet", + "owner_agent": "openclaw", + "source_capture_fixture_id": "result_capture_route_lock_review", + "status": "approval_required", + "approval_lane": "sre_route_lock_acceptance", + "promotion_mode": "approval_gate_only", + "result_capture_write_enabled": false, + "required_decision": "確認 AwoooI SRE 戰情室為唯一告警路由,舊 bot 與舊群組不得承接 promotion。", + "evidence_hash": "sha256:7474747474747474747474747474747474747474747474747474747474747474" + }, + { + "packet_id": "promotion_packet_owner_acceptance", + "display_name": "Owner acceptance promotion packet", + "owner_agent": "nemotron", + "source_capture_fixture_id": "result_capture_owner_acceptance_pending", + "status": "blocked_by_policy", + "approval_lane": "owner_acceptance_result_hold", + "promotion_mode": "approval_gate_only", + "result_capture_write_enabled": false, + "required_decision": "確認 result capture owner、rollback owner、redaction、learning write 邊界與 PlayBook trust 邊界後才可進下一關。", + "evidence_hash": "sha256:7575757575757575757575757575757575757575757575757575757575757575" + } + ], + "acceptance_gate_templates": [ + { + "template_id": "owner_acceptance_record_template", + "display_name": "Owner acceptance record template", + "status": "approval_required", + "source_packet_id": "promotion_packet_owner_acceptance", + "target_promotion": "result_capture_promotion_preview", + "promotion_write_enabled": false, + "required_owner": "result_capture_owner", + "required_fields": [ + "owner", + "decision", + "decision_reason", + "rollback_owner", + "redacted_evidence_refs" + ], + "evidence_hash": "sha256:7676767676767676767676767676767676767676767676767676767676767676" + }, + { + "template_id": "capture_write_scope_template", + "display_name": "Capture write scope template", + "status": "ready", + "source_packet_id": "promotion_packet_action_required", + "target_promotion": "result_capture_promotion_preview", + "promotion_write_enabled": false, + "required_owner": "operator_owner", + "required_fields": [ + "incident", + "capture_scope", + "verifier_state", + "manual_next_action" + ], + "evidence_hash": "sha256:7777777777777777777777777777777777777777777777777777777777777777" + }, + { + "template_id": "learning_write_scope_template", + "display_name": "Learning write scope template", + "status": "blocked_by_policy", + "source_packet_id": "promotion_packet_no_action_review", + "target_promotion": "result_capture_promotion_preview", + "promotion_write_enabled": false, + "required_owner": "hermes_owner", + "required_fields": [ + "learning_candidate", + "owner_review", + "staleness_guard", + "citation_refs" + ], + "evidence_hash": "sha256:7878787878787878787878787878787878787878787878787878787878787878" + }, + { + "template_id": "playbook_trust_scope_template", + "display_name": "PlayBook trust scope template", + "status": "blocked_by_policy", + "source_packet_id": "promotion_packet_verifier_degraded", + "target_promotion": "result_capture_promotion_preview", + "promotion_write_enabled": false, + "required_owner": "playbook_owner", + "required_fields": [ + "playbook", + "trust_delta", + "success_signal", + "rollback_signal" + ], + "evidence_hash": "sha256:7979797979797979797979797979797979797979797979797979797979797979" + }, + { + "template_id": "rollback_and_verifier_template", + "display_name": "Rollback and verifier template", + "status": "approval_required", + "source_packet_id": "promotion_packet_verifier_degraded", + "target_promotion": "result_capture_promotion_preview", + "promotion_write_enabled": false, + "required_owner": "rollback_owner", + "required_fields": [ + "rollback_plan", + "reverify_plan", + "blocked_until", + "owner_acceptance" + ], + "evidence_hash": "sha256:7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a" + } + ], + "promotion_verifier_checks": [ + { + "verifier_id": "no_result_capture_write_before_approval", + "display_name": "No result capture write before approval", + "owner_agent": "openclaw", + "status": "ready", + "verifies": "result_capture_write_count remains zero before approval", + "failure_if_missing": "若 result capture write 不是 0,必須停止 promotion 並標記 unauthorized result capture write。", + "live_execution_enabled": false, + "evidence_hash": "sha256:7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b" + }, + { + "verifier_id": "no_learning_write_before_approval", + "display_name": "No learning write before approval", + "owner_agent": "hermes", + "status": "ready", + "verifies": "learning_write_count remains zero before approval", + "failure_if_missing": "若 learning write 不是 0,必須退回 owner acceptance 與 KM review gate。", + "live_execution_enabled": false, + "evidence_hash": "sha256:7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c" + }, + { + "verifier_id": "no_playbook_trust_before_approval", + "display_name": "No PlayBook trust before approval", + "owner_agent": "nemotron", + "status": "approval_required", + "verifies": "playbook_trust_write_count remains zero before approval", + "failure_if_missing": "若 PlayBook trust write 不是 0,必須封鎖 promotion 並退回 trust review。", + "live_execution_enabled": false, + "evidence_hash": "sha256:7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d" + }, + { + "verifier_id": "no_gateway_queue_before_approval", + "display_name": "No Gateway queue before approval", + "owner_agent": "openclaw", + "status": "approval_required", + "verifies": "gateway_queue_write_count remains zero before approval", + "failure_if_missing": "若 Gateway queue write 不是 0,必須退回 reviewer queue readback。", + "live_execution_enabled": false, + "evidence_hash": "sha256:7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7e" + }, + { + "verifier_id": "promotion_redaction_completeness", + "display_name": "Promotion redaction completeness", + "owner_agent": "hermes", + "status": "ready", + "verifies": "each promotion packet has redacted evidence and owner acceptance fields", + "failure_if_missing": "若缺少 redaction、owner 或 rollback 欄位,不能進入 P2-120。", + "live_execution_enabled": false, + "evidence_hash": "sha256:7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" + } + ], + "blocked_promotion_writes": [ + { + "blocker_id": "result_capture_promotion_not_authorized", + "display_name": "Result capture promotion not authorized", + "severity": "critical", + "status": "blocked_by_policy", + "blocked_action": "result_capture_promotion_write", + "blocked_until": "owner_acceptance_record_approved", + "evidence_hash": "sha256:8080808080808080808080808080808080808080808080808080808080808080" + }, + { + "blocker_id": "learning_promotion_not_authorized", + "display_name": "Learning promotion not authorized", + "severity": "critical", + "status": "blocked_by_policy", + "blocked_action": "learning_write_promotion", + "blocked_until": "learning_writeback_owner_approved", + "evidence_hash": "sha256:8181818181818181818181818181818181818181818181818181818181818181" + }, + { + "blocker_id": "playbook_trust_promotion_not_authorized", + "display_name": "PlayBook trust promotion not authorized", + "severity": "high", + "status": "approval_required", + "blocked_action": "playbook_trust_promotion", + "blocked_until": "playbook_owner_acceptance_approved", + "evidence_hash": "sha256:8282828282828282828282828282828282828282828282828282828282828282" + }, + { + "blocker_id": "gateway_queue_promotion_not_authorized", + "display_name": "Gateway queue promotion not authorized", + "severity": "high", + "status": "approval_required", + "blocked_action": "gateway_queue_promotion", + "blocked_until": "reviewer_queue_owner_approved", + "evidence_hash": "sha256:8383838383838383838383838383838383838383838383838383838383838383" + }, + { + "blocker_id": "production_promotion_not_authorized", + "display_name": "Production promotion not authorized", + "severity": "critical", + "status": "blocked_by_policy", + "blocked_action": "production_result_promotion", + "blocked_until": "runtime_write_gate_approved", + "evidence_hash": "sha256:8484848484848484848484848484848484848484848484848484848484848484" + } + ], + "operator_actions": [ + { + "action_id": "review_promotion_approval_packet", + "display_name": "Review promotion approval packet", + "owner_agent": "openclaw", + "operator_instruction": "檢查 promotion packet 是否有 owner、decision、rollback、redacted evidence 與 verifier 結論;未齊全就維持 blocked。", + "runtime_promotion_write_allowed": false + }, + { + "action_id": "verify_no_write_promotion_counts", + "display_name": "Verify no-write promotion counts", + "owner_agent": "nemotron", + "operator_instruction": "確認 result capture、learning、PlayBook trust、Gateway、Telegram、Bot API 與 production write count 全部仍為 0。", + "runtime_promotion_write_allowed": false + }, + { + "action_id": "confirm_acceptance_scope", + "display_name": "Confirm acceptance scope", + "owner_agent": "hermes", + "operator_instruction": "確認 owner acceptance 只涵蓋指定 incident / playbook / learning scope,不可擴張成 blanket approval。", + "runtime_promotion_write_allowed": false + }, + { + "action_id": "check_promotion_redaction_contract", + "display_name": "Check promotion redaction contract", + "owner_agent": "openclaw", + "operator_instruction": "確認前端只顯示遮蔽後證據、摘要與 owner 欄位,不外露內部協作或敏感 payload。", + "runtime_promotion_write_allowed": false + }, + { + "action_id": "promote_to_p2_120", + "display_name": "Promote to P2-120", + "owner_agent": "nemotron", + "operator_instruction": "若 P2-119 的 promotion approval gate 全部通過,下一步才能建立 P2-120 的 owner-approved promotion dry-run。", + "runtime_promotion_write_allowed": false + } + ], + "display_redaction_contract": { + "redaction_required": true, + "raw_prompt_display_allowed": false, + "private_reasoning_display_allowed": false, + "secret_value_display_allowed": false, + "raw_runtime_payload_display_allowed": false, + "internal_collaboration_content_display_allowed": false, + "frontend_display_policy": "治理頁只顯示 promotion packet、owner、decision、blocked reason、verifier 與遮蔽後 evidence hash;不得顯示內部協作內容、敏感 payload 或 secret。" + }, + "rollups": { + "promotion_approval_packet_count": 5, + "acceptance_gate_template_count": 5, + "promotion_verifier_check_count": 5, + "blocked_promotion_write_count": 5, + "operator_action_count": 5, + "approval_required_packet_count": 2, + "blocked_packet_count": 2, + "approval_required_template_count": 2, + "blocked_template_count": 2, + "approval_required_verifier_count": 2, + "critical_blocker_count": 3, + "owner_approval_received_count": 0, + "capture_promotion_approved_count": 0, + "canonical_runtime_target_read_count": 0, + "live_query_count": 0, + "reviewer_queue_write_count": 0, + "gateway_queue_write_count": 0, + "telegram_send_count": 0, + "bot_api_call_count": 0, + "report_receipt_write_count": 0, + "result_capture_write_count": 0, + "learning_write_count": 0, + "playbook_trust_write_count": 0, + "production_write_count": 0, + "secret_read_count": 0, + "destructive_operation_count": 0 + } +} diff --git a/docs/schemas/ai_agent_result_capture_promotion_approval_gate_v1.schema.json b/docs/schemas/ai_agent_result_capture_promotion_approval_gate_v1.schema.json new file mode 100644 index 000000000..d51f8b4eb --- /dev/null +++ b/docs/schemas/ai_agent_result_capture_promotion_approval_gate_v1.schema.json @@ -0,0 +1,359 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://awoooi.wooo.work/schemas/ai_agent_result_capture_promotion_approval_gate_v1.schema.json", + "title": "AI Agent Result Capture Promotion Approval Gate v1", + "type": "object", + "additionalProperties": false, + "required": [ + "schema_version", + "generated_at", + "program_status", + "source_refs", + "prior_result_capture_no_write_readback", + "promotion_truth", + "promotion_approval_packets", + "acceptance_gate_templates", + "promotion_verifier_checks", + "blocked_promotion_writes", + "operator_actions", + "display_redaction_contract", + "rollups" + ], + "properties": { + "schema_version": { + "const": "ai_agent_result_capture_promotion_approval_gate_v1" + }, + "generated_at": { + "type": "string", + "minLength": 1 + }, + "program_status": { + "type": "object", + "additionalProperties": false, + "required": [ + "overall_completion_percent", + "current_priority", + "current_task_id", + "next_task_id", + "read_only_mode", + "runtime_authority", + "status_note" + ], + "properties": { + "overall_completion_percent": { + "const": 100 + }, + "current_priority": { + "const": "P2" + }, + "current_task_id": { + "const": "P2-119" + }, + "next_task_id": { + "const": "P2-120" + }, + "read_only_mode": { + "const": true + }, + "runtime_authority": { + "const": "result_capture_promotion_approval_gate_only_no_capture_or_learning_write" + }, + "status_note": { + "type": "string", + "minLength": 1 + } + } + }, + "source_refs": { + "$ref": "#/$defs/string_array" + }, + "prior_result_capture_no_write_readback": { + "type": "object" + }, + "promotion_truth": { + "type": "object" + }, + "promotion_approval_packets": { + "type": "array", + "minItems": 5, + "items": { + "$ref": "#/$defs/promotion_approval_packet" + } + }, + "acceptance_gate_templates": { + "type": "array", + "minItems": 5, + "items": { + "$ref": "#/$defs/acceptance_gate_template" + } + }, + "promotion_verifier_checks": { + "type": "array", + "minItems": 5, + "items": { + "$ref": "#/$defs/promotion_verifier_check" + } + }, + "blocked_promotion_writes": { + "type": "array", + "minItems": 5, + "items": { + "$ref": "#/$defs/blocked_promotion_write" + } + }, + "operator_actions": { + "type": "array", + "minItems": 5, + "items": { + "$ref": "#/$defs/operator_action" + } + }, + "display_redaction_contract": { + "type": "object" + }, + "rollups": { + "type": "object" + } + }, + "$defs": { + "string_array": { + "type": "array", + "minItems": 1, + "items": { + "type": "string", + "minLength": 1 + } + }, + "hash": { + "type": "string", + "pattern": "^sha256:[0-9a-f]{64}$" + }, + "owner_agent": { + "enum": [ + "openclaw", + "hermes", + "nemotron" + ] + }, + "status": { + "enum": [ + "ready", + "ready_for_owner_review", + "approval_required", + "blocked_by_policy" + ] + }, + "severity": { + "enum": [ + "high", + "critical" + ] + }, + "promotion_approval_packet": { + "type": "object", + "additionalProperties": false, + "required": [ + "packet_id", + "display_name", + "owner_agent", + "source_capture_fixture_id", + "status", + "approval_lane", + "promotion_mode", + "result_capture_write_enabled", + "required_decision", + "evidence_hash" + ], + "properties": { + "packet_id": { + "type": "string" + }, + "display_name": { + "type": "string" + }, + "owner_agent": { + "$ref": "#/$defs/owner_agent" + }, + "source_capture_fixture_id": { + "type": "string" + }, + "status": { + "$ref": "#/$defs/status" + }, + "approval_lane": { + "type": "string" + }, + "promotion_mode": { + "const": "approval_gate_only" + }, + "result_capture_write_enabled": { + "const": false + }, + "required_decision": { + "type": "string", + "minLength": 1 + }, + "evidence_hash": { + "$ref": "#/$defs/hash" + } + } + }, + "acceptance_gate_template": { + "type": "object", + "additionalProperties": false, + "required": [ + "template_id", + "display_name", + "status", + "source_packet_id", + "target_promotion", + "promotion_write_enabled", + "required_owner", + "required_fields", + "evidence_hash" + ], + "properties": { + "template_id": { + "type": "string" + }, + "display_name": { + "type": "string" + }, + "status": { + "$ref": "#/$defs/status" + }, + "source_packet_id": { + "type": "string" + }, + "target_promotion": { + "const": "result_capture_promotion_preview" + }, + "promotion_write_enabled": { + "const": false + }, + "required_owner": { + "type": "string" + }, + "required_fields": { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + }, + "evidence_hash": { + "$ref": "#/$defs/hash" + } + } + }, + "promotion_verifier_check": { + "type": "object", + "additionalProperties": false, + "required": [ + "verifier_id", + "display_name", + "owner_agent", + "status", + "verifies", + "failure_if_missing", + "live_execution_enabled", + "evidence_hash" + ], + "properties": { + "verifier_id": { + "type": "string" + }, + "display_name": { + "type": "string" + }, + "owner_agent": { + "$ref": "#/$defs/owner_agent" + }, + "status": { + "$ref": "#/$defs/status" + }, + "verifies": { + "type": "string", + "minLength": 1 + }, + "failure_if_missing": { + "type": "string", + "minLength": 1 + }, + "live_execution_enabled": { + "const": false + }, + "evidence_hash": { + "$ref": "#/$defs/hash" + } + } + }, + "blocked_promotion_write": { + "type": "object", + "additionalProperties": false, + "required": [ + "blocker_id", + "display_name", + "severity", + "status", + "blocked_action", + "blocked_until", + "evidence_hash" + ], + "properties": { + "blocker_id": { + "type": "string" + }, + "display_name": { + "type": "string" + }, + "severity": { + "$ref": "#/$defs/severity" + }, + "status": { + "$ref": "#/$defs/status" + }, + "blocked_action": { + "type": "string", + "minLength": 1 + }, + "blocked_until": { + "type": "string", + "minLength": 1 + }, + "evidence_hash": { + "$ref": "#/$defs/hash" + } + } + }, + "operator_action": { + "type": "object", + "additionalProperties": false, + "required": [ + "action_id", + "display_name", + "owner_agent", + "operator_instruction", + "runtime_promotion_write_allowed" + ], + "properties": { + "action_id": { + "type": "string" + }, + "display_name": { + "type": "string" + }, + "owner_agent": { + "$ref": "#/$defs/owner_agent" + }, + "operator_instruction": { + "type": "string", + "minLength": 1 + }, + "runtime_promotion_write_allowed": { + "const": false + } + } + } + } +}