types.py python
128 lines 3.6 KB
Raw
sha256:8461d44b77376fbf06fa7c3e085d309e3010fd8d5886d63c63e69ce118811ad4 docs: record AFF-b feature-tip SHAs after AFF-b-ISR commit. Human 3 days ago
1 """Shared types for the L2 honesty module."""
2
3 from __future__ import annotations
4
5 from dataclasses import dataclass, field
6 from typing import Any, Literal
7
8 HonestyErrorToken = Literal[
9 "usage",
10 "config",
11 "refused",
12 "missing_verdict",
13 "missing_verification_evidence",
14 "missing_deploy_health",
15 "missing_independent_second_review",
16 "missing_adversarial_freeze",
17 "approval_integrity",
18 "ledger_broken",
19 "role_violation",
20 "evidence_free",
21 "io",
22 None,
23 ]
24
25 ENTRY_KINDS = frozenset(
26 {
27 "genesis",
28 "task_assigned",
29 "verdict",
30 "dispute_opened",
31 "overseer_ruling",
32 "approval_recorded",
33 "board_advance",
34 "hook_check",
35 "verification_evidence",
36 "independent_second_review",
37 "freeze_review",
38 "adversarial_freeze",
39 }
40 )
41
42 VERIFICATION_ARTIFACT_TYPES = frozenset({"test_output", "deploy_health", "screenshot"})
43 BV_VERDICTS = frozenset({"pass", "findings", "blocked"})
44 ISR_VERDICTS = frozenset({"pass", "findings", "blocked"})
45 FREEZE_VERDICTS = frozenset({"pass", "findings", "blocked"})
46 AFF_VERDICTS = frozenset({"pass", "findings", "blocked", "skip"})
47 AFF_POSTURES = frozenset({"attack"})
48
49 ACTOR_ROLES = frozenset({"owner", "overseer", "producer", "verifier"})
50
51 HOOK_NAMES = frozenset({"board_done", "handoff", "register"})
52
53
54 class EntryValidationError(Exception):
55 """Raised when an append body fails schema or role checks."""
56
57 def __init__(self, exit_code: int, message: str) -> None:
58 super().__init__(message)
59 self.exit_code = exit_code
60
61
62 @dataclass
63 class HonestyStatusJson:
64 """Frozen honesty-status JSON schema payload (§K9.9)."""
65
66 ok: bool
67 exit_code: int
68 command: str = "honesty-status"
69 hook: str | None = None
70 artifact: str | None = None
71 artifact_sha256: str | None = None
72 producer_session: str | None = None
73 matched_verdict_hash: str | None = None
74 error: HonestyErrorToken = None
75 verification_evidence: dict[str, Any] | None = None
76 deploy_health: dict[str, Any] | None = None
77 independent_second_review: dict[str, Any] | None = None
78 adversarial_freeze: dict[str, Any] | None = None
79
80 def to_dict(self) -> dict[str, Any]:
81 payload: dict[str, Any] = {
82 "ok": self.ok,
83 "exit_code": self.exit_code,
84 "command": self.command,
85 "hook": self.hook,
86 "artifact": self.artifact,
87 "artifact_sha256": self.artifact_sha256,
88 "producer_session": self.producer_session,
89 "matched_verdict_hash": self.matched_verdict_hash,
90 "error": self.error,
91 }
92 if self.verification_evidence is not None:
93 payload["verification_evidence"] = self.verification_evidence
94 if self.deploy_health is not None:
95 payload["deploy_health"] = self.deploy_health
96 if self.independent_second_review is not None:
97 payload["independent_second_review"] = self.independent_second_review
98 if self.adversarial_freeze is not None:
99 payload["adversarial_freeze"] = self.adversarial_freeze
100 return payload
101
102
103 @dataclass
104 class HonestyStatusResult:
105 """Outcome of ``run_honesty_status``."""
106
107 exit_code: int
108 json_payload: HonestyStatusJson
109 stderr_extra: str = ""
110
111
112 @dataclass
113 class LedgerAppendOptions:
114 """Input for ``append_entry``."""
115
116 kind: str
117 body: dict[str, Any] = field(default_factory=dict)
118 from_stdin: bool = False
119 file_path: str | None = None
120
121
122 @dataclass
123 class LedgerResult:
124 """Generic ledger command outcome."""
125
126 exit_code: int
127 stdout_lines: list[str] = field(default_factory=list)
128 stderr_extra: str = ""
File History 1 commit
sha256:8461d44b77376fbf06fa7c3e085d309e3010fd8d5886d63c63e69ce118811ad4 docs: record AFF-b feature-tip SHAs after AFF-b-ISR commit. Human 3 days ago