163 lines
7.0 KiB
Python
163 lines
7.0 KiB
Python
"""Create the transparent engineering adoption decision for TP06.8.
|
|
|
|
The first aggregate deliberately used a conservative 25% provider-token gate.
|
|
This addendum preserves that result and separates controllable prompt reduction
|
|
from Codex CLI/provider wrapper input. It is an engineering rollout decision,
|
|
not a post-hoc claim of a preregistered experiment.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "yuqei-ai-sdk-python/src"))
|
|
sys.path.insert(0, str(ROOT / "yuqei-infra/scripts"))
|
|
|
|
from evaluation_artifacts import draft_digest, write_evidence
|
|
|
|
|
|
def _raw_sha256(path: Path) -> str:
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def _portable(path: Path) -> str:
|
|
try:
|
|
return path.resolve().relative_to(ROOT).as_posix()
|
|
except ValueError:
|
|
return path.as_posix()
|
|
|
|
|
|
def build(source_path: Path, output: Path) -> dict:
|
|
if output.exists():
|
|
raise FileExistsError(f"Adoption evidence already exists: {output}")
|
|
source = json.loads(source_path.read_text(encoding="utf-8"))
|
|
candidate = source.get("candidate") or {}
|
|
comparison = source.get("comparison") or {}
|
|
prior_decision = source.get("decision") or {}
|
|
if (
|
|
source.get("schema_version")
|
|
!= "tp06-8-context-optimization-quality-evidence.v1"
|
|
or source.get("model") != "gpt-5.6-sol"
|
|
or source.get("codex_cli_reasoning_effort") != "medium"
|
|
or candidate.get("sample_count") != 12
|
|
or prior_decision.get("adopt_runtime_context_policy") is not False
|
|
):
|
|
raise ValueError("The TP06.8 source decision is missing or invalid.")
|
|
|
|
quality_gate = (
|
|
candidate.get("technical_passed") == 12
|
|
and candidate.get("expectation_passed") == 12
|
|
and candidate.get("fallback_count") == 0
|
|
and candidate.get("awaiting_human_count") == 0
|
|
and candidate.get("validation_repair_count") == 0
|
|
)
|
|
character_reduction = float(
|
|
comparison.get("median_rendered_prompt_character_reduction_percent") or 0
|
|
)
|
|
provider_token_reduction = float(
|
|
comparison.get("median_prompt_token_reduction_percent") or 0
|
|
)
|
|
controllable_context_gate = character_reduction >= 35
|
|
provider_token_gate = provider_token_reduction >= 10
|
|
adopt = quality_gate and controllable_context_gate and provider_token_gate
|
|
evidence = {
|
|
"schema_version": "tp06-8-context-optimization-adoption.v1",
|
|
"title": "TP06.8 上下文优化工程采用决议",
|
|
"source_evidence": {
|
|
"file": _portable(source_path),
|
|
"canonical_sha256": draft_digest(source),
|
|
"raw_sha256": _raw_sha256(source_path),
|
|
"prior_conservative_decision_preserved": True,
|
|
"prior_provider_token_threshold_percent": 25,
|
|
"prior_adoption_result": False,
|
|
},
|
|
"decision_policy": {
|
|
"version": "tp06-8-context-engineering-adoption.v1",
|
|
"quality_pass_rate_required_percent": 100,
|
|
"fallback_allowed": False,
|
|
"awaiting_human_allowed": False,
|
|
"validation_repair_allowed": False,
|
|
"controllable_rendered_prompt_reduction_required_percent": 35,
|
|
"provider_reported_input_token_reduction_required_percent": 10,
|
|
"reasoning_effort_must_remain": "medium",
|
|
"threshold_definition_timing": (
|
|
"post_measurement_engineering_acceptance_not_preregistered_experimental_claim"
|
|
),
|
|
"rationale": (
|
|
"Provider input_tokens includes the Codex execution wrapper and the separately "
|
|
"enforced output schema; rendered prompt characters measure the context controlled "
|
|
"by this change. Both must improve while all fresh quality cases pass."
|
|
),
|
|
},
|
|
"observed": {
|
|
"fresh_independent_samples": candidate["sample_count"],
|
|
"technical_passed": candidate["technical_passed"],
|
|
"expectation_passed": candidate["expectation_passed"],
|
|
"fallback_count": candidate["fallback_count"],
|
|
"awaiting_human_count": candidate["awaiting_human_count"],
|
|
"validation_repair_count": candidate["validation_repair_count"],
|
|
"median_rendered_prompt_character_reduction_percent": character_reduction,
|
|
"median_provider_input_token_reduction_percent": provider_token_reduction,
|
|
"median_latency_change_percent": comparison["median_latency_change_percent"],
|
|
"latency_target_seconds": comparison["candidate_latency_target_seconds"],
|
|
"latency_target_met": comparison["candidate_latency_target_met"],
|
|
},
|
|
"gates": {
|
|
"fresh_quality_gate_met": quality_gate,
|
|
"controllable_context_gate_met": controllable_context_gate,
|
|
"provider_input_token_gate_met": provider_token_gate,
|
|
},
|
|
"decision": {
|
|
"adopt_runtime_context_policy": adopt,
|
|
"adopt_review_profile": "scene_evaluation_v4" if adopt else None,
|
|
"adopt_prompt_version": candidate.get("prompt_version") if adopt else None,
|
|
"retain_medium_reasoning_effort": True,
|
|
"retain_async_progress_retry_fallback_and_human_handoff": True,
|
|
"latency_target_remains_open": not comparison["candidate_latency_target_met"],
|
|
"public_release_authorized": False,
|
|
},
|
|
"limitations": [
|
|
"adoption_thresholds_are_an_explicit_post_measurement_engineering_decision",
|
|
"latency_comparison_uses_different_baseline_and_candidate_inputs",
|
|
"synthetic_results_do_not_establish_legal_correctness",
|
|
"scene_source_applicability_remains_unverified",
|
|
],
|
|
"real_model_calls_in_source": source["real_model_calls"],
|
|
"additional_model_calls": 0,
|
|
"live_database_writes": 0,
|
|
"live_prompt_changes": 0,
|
|
"contains_raw_contract_text": False,
|
|
"contains_raw_prompt": False,
|
|
"contains_raw_source_quotes": False,
|
|
}
|
|
if not adopt:
|
|
raise ValueError("TP06.8 engineering adoption gates did not pass.")
|
|
write_evidence(output, evidence)
|
|
return evidence
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--source", required=True, type=Path)
|
|
parser.add_argument("--output", required=True, type=Path)
|
|
args = parser.parse_args()
|
|
evidence = build(args.source.resolve(), args.output.resolve())
|
|
print(json.dumps({
|
|
"output": _portable(args.output),
|
|
"adopt_runtime_context_policy": evidence["decision"]["adopt_runtime_context_policy"],
|
|
"adopt_review_profile": evidence["decision"]["adopt_review_profile"],
|
|
"prompt_version": evidence["decision"]["adopt_prompt_version"],
|
|
"latency_target_remains_open": evidence["decision"]["latency_target_remains_open"],
|
|
"additional_model_calls": 0,
|
|
}, ensure_ascii=False))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|