Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /promptdriven_pdd /pdd /commands /contracts.py
| """Deterministic contract checks for ``pdd contracts check`` and ``pdd checkup contract check``.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Optional | |
| import click | |
| from ..contract_check import ContractResult, check_directory, check_prompt, check_stories | |
| from ..contract_ir import parse_prompt_contracts | |
| from ..waiver_policy import summarize_waivers | |
| def _exit_code(results: list[ContractResult], *, strict: bool) -> int: | |
| errors = sum(result.error_count for result in results) | |
| warnings = sum(result.warn_count for result in results) | |
| if errors or (strict and warnings): | |
| return 2 | |
| return 1 if warnings else 0 | |
| def contracts_cli() -> None: | |
| """Deterministic contract section checks for prompt files.""" | |
| def contracts_check( | |
| target: str, | |
| as_json: bool, | |
| strict: bool, | |
| stories_dir: Optional[str], | |
| ) -> None: | |
| """Check contract sections for deterministic structural defects.""" | |
| target_path = Path(target) | |
| if target_path.is_file(): | |
| results = [check_prompt(target_path, strict=strict)] | |
| else: | |
| results = check_directory(target_path, strict=strict) | |
| if stories_dir is not None: | |
| prompts_dir = target_path if target_path.is_dir() else target_path.parent | |
| results.extend(check_stories(Path(stories_dir), prompts_dir, strict=strict)) | |
| waiver_rows_by_path: dict[str, list[dict[str, object]]] = {} | |
| for result in results: | |
| if result.path.suffix != ".prompt": | |
| continue | |
| ir = parse_prompt_contracts(result.path) | |
| waiver_rows_by_path[str(result.path)] = summarize_waivers(ir.waivers, ir.known_rule_ids) | |
| if as_json: | |
| payload: list[dict[str, object]] = [] | |
| for result in results: | |
| row = result.as_dict() | |
| row["waivers"] = waiver_rows_by_path.get(str(result.path), []) | |
| payload.append(row) | |
| click.echo(json.dumps(payload, indent=2)) | |
| else: | |
| for result in results: | |
| click.echo( | |
| f"{result.path}: {result.warn_count} warning(s), " | |
| f"{result.error_count} error(s)" | |
| ) | |
| waiver_rows = waiver_rows_by_path.get(str(result.path), []) | |
| if waiver_rows: | |
| click.echo(" Waivers:") | |
| for waiver in waiver_rows: | |
| expires = waiver.get("expires") or "-" | |
| click.echo( | |
| " " | |
| f"{waiver.get('id')}: rule={waiver.get('rule_id')} " | |
| f"status={waiver.get('status')} expires={expires}" | |
| ) | |
| for issue in result.issues: | |
| click.echo(f" {issue.level.upper()} {issue.code}: {issue.message}") | |
| raise click.exceptions.Exit(_exit_code(results, strict=strict)) | |
Xet Storage Details
- Size:
- 3.33 kB
- Xet hash:
- c9d77dc153c592ce83598b711be177f1d07b5497b92f941cba89fb9ac1da8ac0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.