truth-firewall 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- truth_firewall/__init__.py +7 -0
- truth_firewall/__main__.py +4 -0
- truth_firewall/audit.py +30 -0
- truth_firewall/claims/__init__.py +6 -0
- truth_firewall/claims/coverage.py +40 -0
- truth_firewall/claims/deterministic.py +822 -0
- truth_firewall/claims/extractor.py +22 -0
- truth_firewall/claims/normalization.py +426 -0
- truth_firewall/claims/prompts.py +47 -0
- truth_firewall/claims/proposition.py +324 -0
- truth_firewall/claims/semantic.py +76 -0
- truth_firewall/cli.py +204 -0
- truth_firewall/codex_worker.py +75 -0
- truth_firewall/completion.py +229 -0
- truth_firewall/constants.py +40 -0
- truth_firewall/contract_coverage.py +278 -0
- truth_firewall/coverage_authority.py +379 -0
- truth_firewall/demo.py +107 -0
- truth_firewall/errors.py +29 -0
- truth_firewall/evidence/__init__.py +5 -0
- truth_firewall/evidence/collectors/__init__.py +15 -0
- truth_firewall/evidence/collectors/filesystem.py +218 -0
- truth_firewall/evidence/collectors/git.py +98 -0
- truth_firewall/evidence/collectors/process.py +117 -0
- truth_firewall/evidence/collectors/runtime.py +42 -0
- truth_firewall/evidence/collectors/structure.py +131 -0
- truth_firewall/evidence/collectors/test_runner.py +610 -0
- truth_firewall/evidence/executable_identity.py +168 -0
- truth_firewall/evidence/execution_environment.py +82 -0
- truth_firewall/evidence/git_identity.py +80 -0
- truth_firewall/evidence/io.py +123 -0
- truth_firewall/evidence/ledger.py +66 -0
- truth_firewall/evidence/local.py +47 -0
- truth_firewall/evidence/provenance.py +264 -0
- truth_firewall/evidence/pytest_result.py +112 -0
- truth_firewall/evidence/retriever.py +113 -0
- truth_firewall/evidence_requirements.py +63 -0
- truth_firewall/fixtures/demo/contradicted.json +30 -0
- truth_firewall/fixtures/demo/legitimate_hypothesis.json +20 -0
- truth_firewall/fixtures/demo/mixed.json +38 -0
- truth_firewall/fixtures/demo/overclaimed_completion.json +40 -0
- truth_firewall/fixtures/demo/scoped_absence.json +37 -0
- truth_firewall/fixtures/demo/supported_factual.json +28 -0
- truth_firewall/fixtures/demo/unsupported_causal.json +33 -0
- truth_firewall/generic_completion.py +467 -0
- truth_firewall/integrations/__init__.py +5 -0
- truth_firewall/integrations/codex.py +371 -0
- truth_firewall/integrations/cursor.py +366 -0
- truth_firewall/integrations/local_test_results.py +117 -0
- truth_firewall/lifecycle.py +298 -0
- truth_firewall/onboarding.py +133 -0
- truth_firewall/pilot.py +261 -0
- truth_firewall/pipeline.py +432 -0
- truth_firewall/policy/__init__.py +5 -0
- truth_firewall/policy/engine.py +41 -0
- truth_firewall/providers/__init__.py +6 -0
- truth_firewall/providers/base.py +18 -0
- truth_firewall/providers/config.py +40 -0
- truth_firewall/providers/fake.py +52 -0
- truth_firewall/providers/openai_compatible.py +133 -0
- truth_firewall/py.typed +0 -0
- truth_firewall/redaction.py +36 -0
- truth_firewall/rewrite/__init__.py +5 -0
- truth_firewall/rewrite/rewriter.py +151 -0
- truth_firewall/safety.py +69 -0
- truth_firewall/schemas.py +606 -0
- truth_firewall/storage.py +139 -0
- truth_firewall/supervised_worker.py +333 -0
- truth_firewall/verification/__init__.py +5 -0
- truth_firewall/verification/contracts.py +40 -0
- truth_firewall/verification/entailment.py +357 -0
- truth_firewall/verification/rules.py +971 -0
- truth_firewall/verification/verifier.py +99 -0
- truth_firewall/workspace.py +90 -0
- truth_firewall-0.1.0.dist-info/METADATA +141 -0
- truth_firewall-0.1.0.dist-info/RECORD +80 -0
- truth_firewall-0.1.0.dist-info/WHEEL +5 -0
- truth_firewall-0.1.0.dist-info/entry_points.txt +2 -0
- truth_firewall-0.1.0.dist-info/licenses/LICENSE +21 -0
- truth_firewall-0.1.0.dist-info/top_level.txt +1 -0
truth_firewall/audit.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Local audit artifacts for one check, with contained exclusive run storage."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from truth_firewall.storage import ensure_directory, ensure_root, write_text
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def write_audit(directory: Path, artifacts: dict[str, Any], *, permitted_root: Path | None = None) -> None:
|
|
13
|
+
configured = permitted_root if permitted_root is not None else directory.parent
|
|
14
|
+
relative = directory.relative_to(configured)
|
|
15
|
+
root = ensure_root(configured)
|
|
16
|
+
directory = ensure_directory(root, root / relative, exclusive=True)
|
|
17
|
+
mapping = {
|
|
18
|
+
"meta.json": artifacts.get("meta", {}),
|
|
19
|
+
"claims.json": artifacts.get("claims", []),
|
|
20
|
+
"evidence.json": artifacts.get("evidence", []),
|
|
21
|
+
"candidates.json": artifacts.get("candidates", {}),
|
|
22
|
+
"assessments.json": artifacts.get("assessments", []),
|
|
23
|
+
"decisions.json": artifacts.get("decisions", []),
|
|
24
|
+
"coverage.json": artifacts.get("coverage", []),
|
|
25
|
+
"errors.json": artifacts.get("errors", []),
|
|
26
|
+
}
|
|
27
|
+
for name, payload in mapping.items():
|
|
28
|
+
write_text(root, directory / name, json.dumps(payload, indent=2, ensure_ascii=False, default=str))
|
|
29
|
+
write_text(root, directory / "response.txt", str(artifacts.get("response", "")))
|
|
30
|
+
write_text(root, directory / "grounded.txt", str(artifacts.get("grounded", "")))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Find assertive residual source text that no extracted claim covers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from truth_firewall.claims.deterministic import may_contain_unextracted_fact
|
|
8
|
+
from truth_firewall.schemas import Claim
|
|
9
|
+
|
|
10
|
+
_CONNECTOR_ONLY = re.compile(r"[\W_]*(?:(?:and|but|or|while|although|because|therefore|then|also)[\W_]*)*", re.I)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def uncovered_assertive_spans(response_text: str, claims: list[Claim]) -> list[tuple[int, int]]:
|
|
14
|
+
"""A partial extraction must not disable the zero-claim safety principle."""
|
|
15
|
+
covered: list[tuple[int, int]] = []
|
|
16
|
+
for claim in claims:
|
|
17
|
+
start, end = claim.source_start, claim.source_end
|
|
18
|
+
if (start is None or end is None or start < 0 or end > len(response_text)
|
|
19
|
+
or response_text[start:end] != claim.raw_text):
|
|
20
|
+
continue
|
|
21
|
+
covered.append((start, end))
|
|
22
|
+
if not covered:
|
|
23
|
+
return [] # The pipeline's existing zero-claim guard handles this case.
|
|
24
|
+
covered.sort()
|
|
25
|
+
merged = [covered[0]]
|
|
26
|
+
for start, end in covered[1:]:
|
|
27
|
+
left, right = merged[-1]
|
|
28
|
+
if start <= right:
|
|
29
|
+
merged[-1] = (left, max(right, end))
|
|
30
|
+
else:
|
|
31
|
+
merged.append((start, end))
|
|
32
|
+
gaps: list[tuple[int, int]] = []
|
|
33
|
+
cursor = 0
|
|
34
|
+
for start, end in [*merged, (len(response_text), len(response_text))]:
|
|
35
|
+
if cursor < start:
|
|
36
|
+
gap = response_text[cursor:start]
|
|
37
|
+
if _CONNECTOR_ONLY.fullmatch(gap) is None and may_contain_unextracted_fact(gap):
|
|
38
|
+
gaps.append((cursor, start))
|
|
39
|
+
cursor = end
|
|
40
|
+
return gaps
|