flowharness-core 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.
- core/__init__.py +180 -0
- core/actors.py +68 -0
- core/aggregate.py +26 -0
- core/candidate.py +26 -0
- core/cell.py +21 -0
- core/content_hash.py +36 -0
- core/errors.py +27 -0
- core/external_findings.py +242 -0
- core/findings.py +59 -0
- core/journal.py +103 -0
- core/messages.py +14 -0
- core/ports.py +89 -0
- core/py.typed +0 -0
- core/signing.py +30 -0
- core/values.py +28 -0
- flowharness_core-0.1.0.dist-info/METADATA +24 -0
- flowharness_core-0.1.0.dist-info/RECORD +19 -0
- flowharness_core-0.1.0.dist-info/WHEEL +4 -0
- flowharness_core-0.1.0.dist-info/licenses/LICENSE +202 -0
core/__init__.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""flowharness shared core (FLOWHARNESS_SPEC.md §6.1).
|
|
2
|
+
|
|
3
|
+
Domain primitives shared by every bounded context. This facade re-exports the
|
|
4
|
+
pure (stdlib-only) modules; SQL infrastructure (core.sql_unit_of_work,
|
|
5
|
+
core.sqlite_engine, core.journal_store, core.rls) is imported by its submodule
|
|
6
|
+
path, never from here. Kept true by tests/architecture/test_domain_purity.py.
|
|
7
|
+
|
|
8
|
+
Two re-export tiers, split by the *published* public surface:
|
|
9
|
+
|
|
10
|
+
* The unconditional block is the OSS surface — the trust primitives the two
|
|
11
|
+
published CLIs (`flowharness`, `flowharness-ci`) and the published contexts
|
|
12
|
+
(inspection, portability, evaluation.domain) actually need.
|
|
13
|
+
* The guarded block below is PLATFORM-ONLY. Those modules are pruned out of the
|
|
14
|
+
`flowharness-core` wheel/sdist (see `[tool.uv.build-backend]` in
|
|
15
|
+
platform/core/pyproject.toml), so on a PyPI install the imports raise
|
|
16
|
+
ModuleNotFoundError and are swallowed — `import core` still works and the OSS
|
|
17
|
+
names still resolve. In the workspace every module is present, so dev
|
|
18
|
+
behaviour is byte-identical to before. `__all__` deliberately keeps listing
|
|
19
|
+
the platform-only names: it documents the *workspace* surface, and the
|
|
20
|
+
published surface is pinned separately by tests/packaging/test_public_surface_manifest.py.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from core.actors import Actor, ActorKind, Money, actor_from_json, actor_to_json
|
|
24
|
+
from core.aggregate import EventRecorder
|
|
25
|
+
from core.candidate import CandidateKind, CandidateRef
|
|
26
|
+
from core.cell import Cell
|
|
27
|
+
from core.content_hash import ContentHashable
|
|
28
|
+
from core.errors import DomainError
|
|
29
|
+
from core.external_findings import (
|
|
30
|
+
EXTERNAL_SEVERITY_MAP_VERSION,
|
|
31
|
+
SeverityResolution,
|
|
32
|
+
canonical_tool_slug,
|
|
33
|
+
normalize_tool_slug,
|
|
34
|
+
resolve_external_severity,
|
|
35
|
+
)
|
|
36
|
+
from core.findings import EvidenceBundle, EvidenceRef, Finding, SourceAnchor
|
|
37
|
+
from core.journal import (
|
|
38
|
+
GENESIS_HASH,
|
|
39
|
+
DomainEventEnvelope,
|
|
40
|
+
canonical_json,
|
|
41
|
+
ensure_json_canonical,
|
|
42
|
+
entry_hash,
|
|
43
|
+
)
|
|
44
|
+
from core.messages import Command, Event
|
|
45
|
+
from core.ports import (
|
|
46
|
+
Check,
|
|
47
|
+
Corpus,
|
|
48
|
+
EvidenceSource,
|
|
49
|
+
Gate,
|
|
50
|
+
GateOutcome,
|
|
51
|
+
GatePolicy,
|
|
52
|
+
IndexReader,
|
|
53
|
+
SignalSink,
|
|
54
|
+
UnitOfWork,
|
|
55
|
+
)
|
|
56
|
+
from core.signing import sign_report, verify_signature
|
|
57
|
+
from core.values import BasisPoints, Severity, Verdict
|
|
58
|
+
|
|
59
|
+
# --- Platform-only re-exports (pruned from the published `flowharness-core` dist) ---
|
|
60
|
+
# Provenance: public-surface decision 2026-07-30 (funnel-open / platform-closed). The
|
|
61
|
+
# `as X` aliases are load-bearing: mypy runs with no_implicit_reexport=true, and inside a
|
|
62
|
+
# try/except mypy cannot rely on `__all__`, so each name needs the PEP 484 explicit
|
|
63
|
+
# re-export form. Do NOT collapse them.
|
|
64
|
+
try:
|
|
65
|
+
from core.access import AccessDenied as AccessDenied
|
|
66
|
+
from core.access import AccessPolicy as AccessPolicy
|
|
67
|
+
from core.access import AccessRequest as AccessRequest
|
|
68
|
+
from core.access import Decision as Decision
|
|
69
|
+
from core.access_resolvers import DEFAULT_RESOLVERS as DEFAULT_RESOLVERS
|
|
70
|
+
from core.access_resolvers import ActorAccess as ActorAccess
|
|
71
|
+
from core.access_resolvers import GrantRecord as GrantRecord
|
|
72
|
+
from core.access_resolvers import SubjectContext as SubjectContext
|
|
73
|
+
from core.access_resolvers import grant_resolver as grant_resolver
|
|
74
|
+
from core.access_resolvers import namespace_can_use as namespace_can_use
|
|
75
|
+
from core.access_resolvers import namespace_resolver as namespace_resolver
|
|
76
|
+
from core.access_resolvers import project_link_resolver as project_link_resolver
|
|
77
|
+
from core.canonical_payload import CanonicalPayload as CanonicalPayload
|
|
78
|
+
from core.entitlements import Edition as Edition
|
|
79
|
+
from core.entitlements import Entitlement as Entitlement
|
|
80
|
+
from core.entitlements import EntitlementError as EntitlementError
|
|
81
|
+
from core.entitlements import EntitlementPolicy as EntitlementPolicy
|
|
82
|
+
from core.ids import ApiTokenId as ApiTokenId
|
|
83
|
+
from core.ids import AssetId as AssetId
|
|
84
|
+
from core.ids import MemberId as MemberId
|
|
85
|
+
from core.ids import OrgId as OrgId
|
|
86
|
+
from core.ids import ProjectId as ProjectId
|
|
87
|
+
from core.ids import TeamId as TeamId
|
|
88
|
+
from core.ids import TraceId as TraceId
|
|
89
|
+
from core.messagebus import MessageBus as MessageBus
|
|
90
|
+
from core.sharing import Grantee as Grantee
|
|
91
|
+
from core.sharing import GranteeKind as GranteeKind
|
|
92
|
+
from core.sharing import Namespace as Namespace
|
|
93
|
+
from core.sharing import NamespaceKind as NamespaceKind
|
|
94
|
+
from core.sharing import Permission as Permission
|
|
95
|
+
from core.sharing import ScopeKind as ScopeKind
|
|
96
|
+
from core.sharing import ScopeSelector as ScopeSelector
|
|
97
|
+
from core.sharing import SubjectRef as SubjectRef
|
|
98
|
+
from core.sharing import Visibility as Visibility
|
|
99
|
+
from core.sharing import permission_rank as permission_rank
|
|
100
|
+
except ModuleNotFoundError: # pragma: no cover — only on a pruned PyPI install
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
__all__ = [
|
|
104
|
+
"DEFAULT_RESOLVERS",
|
|
105
|
+
"EXTERNAL_SEVERITY_MAP_VERSION",
|
|
106
|
+
"GENESIS_HASH",
|
|
107
|
+
"AccessDenied",
|
|
108
|
+
"AccessPolicy",
|
|
109
|
+
"AccessRequest",
|
|
110
|
+
"Actor",
|
|
111
|
+
"ActorAccess",
|
|
112
|
+
"ActorKind",
|
|
113
|
+
"ApiTokenId",
|
|
114
|
+
"AssetId",
|
|
115
|
+
"BasisPoints",
|
|
116
|
+
"CandidateKind",
|
|
117
|
+
"CandidateRef",
|
|
118
|
+
"CanonicalPayload",
|
|
119
|
+
"Cell",
|
|
120
|
+
"Check",
|
|
121
|
+
"Command",
|
|
122
|
+
"ContentHashable",
|
|
123
|
+
"Corpus",
|
|
124
|
+
"Decision",
|
|
125
|
+
"DomainError",
|
|
126
|
+
"DomainEventEnvelope",
|
|
127
|
+
"Edition",
|
|
128
|
+
"Entitlement",
|
|
129
|
+
"EntitlementError",
|
|
130
|
+
"EntitlementPolicy",
|
|
131
|
+
"Event",
|
|
132
|
+
"EventRecorder",
|
|
133
|
+
"EvidenceBundle",
|
|
134
|
+
"EvidenceRef",
|
|
135
|
+
"EvidenceSource",
|
|
136
|
+
"Finding",
|
|
137
|
+
"Gate",
|
|
138
|
+
"GateOutcome",
|
|
139
|
+
"GatePolicy",
|
|
140
|
+
"GrantRecord",
|
|
141
|
+
"Grantee",
|
|
142
|
+
"GranteeKind",
|
|
143
|
+
"IndexReader",
|
|
144
|
+
"MemberId",
|
|
145
|
+
"MessageBus",
|
|
146
|
+
"Money",
|
|
147
|
+
"Namespace",
|
|
148
|
+
"NamespaceKind",
|
|
149
|
+
"OrgId",
|
|
150
|
+
"Permission",
|
|
151
|
+
"ProjectId",
|
|
152
|
+
"ScopeKind",
|
|
153
|
+
"ScopeSelector",
|
|
154
|
+
"Severity",
|
|
155
|
+
"SeverityResolution",
|
|
156
|
+
"SignalSink",
|
|
157
|
+
"SourceAnchor",
|
|
158
|
+
"SubjectContext",
|
|
159
|
+
"SubjectRef",
|
|
160
|
+
"TeamId",
|
|
161
|
+
"TraceId",
|
|
162
|
+
"UnitOfWork",
|
|
163
|
+
"Verdict",
|
|
164
|
+
"Visibility",
|
|
165
|
+
"actor_from_json",
|
|
166
|
+
"actor_to_json",
|
|
167
|
+
"canonical_json",
|
|
168
|
+
"canonical_tool_slug",
|
|
169
|
+
"ensure_json_canonical",
|
|
170
|
+
"entry_hash",
|
|
171
|
+
"grant_resolver",
|
|
172
|
+
"namespace_can_use",
|
|
173
|
+
"namespace_resolver",
|
|
174
|
+
"normalize_tool_slug",
|
|
175
|
+
"permission_rank",
|
|
176
|
+
"project_link_resolver",
|
|
177
|
+
"resolve_external_severity",
|
|
178
|
+
"sign_report",
|
|
179
|
+
"verify_signature",
|
|
180
|
+
]
|
core/actors.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Actor and Money value objects (FLOWHARNESS_SPEC.md §6.0, §6.1).
|
|
2
|
+
|
|
3
|
+
Every state transition records an Actor (no anonymous writes, §6.1 global invariants).
|
|
4
|
+
Money is float-free: integer micro-units (1_000_000 == 1.00) at a single currency.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from enum import StrEnum
|
|
9
|
+
|
|
10
|
+
from core.errors import DomainError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ActorKind(StrEnum):
|
|
14
|
+
HUMAN = "human"
|
|
15
|
+
AGENT = "agent"
|
|
16
|
+
SYSTEM = "system"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True)
|
|
20
|
+
class Actor:
|
|
21
|
+
actor_id: str
|
|
22
|
+
kind: ActorKind
|
|
23
|
+
display_ref: str
|
|
24
|
+
|
|
25
|
+
def __post_init__(self) -> None:
|
|
26
|
+
if not self.actor_id:
|
|
27
|
+
raise DomainError("actor_id_blank")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True, slots=True)
|
|
31
|
+
class Money:
|
|
32
|
+
micro_units: int # 1_000_000 == 1.00; may be negative for credits
|
|
33
|
+
currency: str # ISO 4217 alpha-3
|
|
34
|
+
|
|
35
|
+
def __post_init__(self) -> None:
|
|
36
|
+
if not (len(self.currency) == 3 and self.currency.isalpha() and self.currency.isupper()):
|
|
37
|
+
raise DomainError("money_currency_not_iso_4217")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# --- R05.3 (D-R5-4): the canonical Actor⇄dict codec ---
|
|
41
|
+
#
|
|
42
|
+
# The journal envelope contract is a THREE-KEY dict: {"actor_id", "kind", "display_ref"}.
|
|
43
|
+
# Six modules had their own encode/decode helpers with subtly different names; this is
|
|
44
|
+
# the one shape. `actor_to_json` is byte-identical to every prior helper.
|
|
45
|
+
# `actor_from_json` is STRICT (no coercion of malformed input) — untrusted-input paths
|
|
46
|
+
# (e.g. catalog closure restore) keep their local `str(...)` coercion before delegating.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def actor_to_json(actor: Actor) -> dict[str, str]:
|
|
50
|
+
"""Encode an Actor to the journal envelope's actor sub-dict."""
|
|
51
|
+
return {
|
|
52
|
+
"actor_id": actor.actor_id,
|
|
53
|
+
"kind": actor.kind.value,
|
|
54
|
+
"display_ref": actor.display_ref,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def actor_from_json(value: object) -> Actor:
|
|
59
|
+
"""Decode the journal envelope's actor sub-dict back to an Actor. Strict on
|
|
60
|
+
types — malformed input raises. Untrusted-input paths (air-gap bundles) MUST
|
|
61
|
+
coerce inputs BEFORE calling this."""
|
|
62
|
+
if not isinstance(value, dict):
|
|
63
|
+
raise DomainError("actor_from_json_not_a_dict")
|
|
64
|
+
return Actor(
|
|
65
|
+
actor_id=value["actor_id"],
|
|
66
|
+
kind=ActorKind(value["kind"]),
|
|
67
|
+
display_ref=value["display_ref"],
|
|
68
|
+
)
|
core/aggregate.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Aggregate-root event recording (FLOWHARNESS_SPEC.md §6.1, §8.1).
|
|
2
|
+
|
|
3
|
+
`EventRecorder` is the mixin aggregate roots use to record past-tense events + a monotonic
|
|
4
|
+
`sequence_no`, drained via `pull_events`. Extracted at the third aggregate (Organization, ApiToken,
|
|
5
|
+
now Team/Project) so it lives once, in `core`, so any context reuses it without importing another.
|
|
6
|
+
The concrete aggregate (a slotted dataclass) supplies `_events` + `sequence_no`; this mixin adds
|
|
7
|
+
the methods (empty `__slots__` → no instance state, no layout conflict).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from core.messages import Event
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EventRecorder:
|
|
14
|
+
__slots__ = ()
|
|
15
|
+
|
|
16
|
+
_events: list[Event]
|
|
17
|
+
sequence_no: int
|
|
18
|
+
|
|
19
|
+
def _record(self, event: Event) -> None:
|
|
20
|
+
self._events.append(event)
|
|
21
|
+
self.sequence_no += 1 # type: ignore[misc] # WHY: mixin contract — the concrete slotted dataclass supplies _events/sequence_no slots (module docstring)
|
|
22
|
+
|
|
23
|
+
def pull_events(self) -> list[Event]:
|
|
24
|
+
drained = self._events
|
|
25
|
+
self._events = [] # type: ignore[misc] # WHY: mixin contract — the concrete slotted dataclass supplies _events/sequence_no slots (module docstring)
|
|
26
|
+
return drained
|
core/candidate.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""CandidateRef — an opaque cross-context pointer to what an EvalRun evaluates (§6.6).
|
|
2
|
+
|
|
3
|
+
`RELEASE` / `PROPOSAL` only in p1 (the `reranker_version` candidate arrives with the Selection
|
|
4
|
+
context, phase 4). `ref` is an opaque id string — Evaluation never imports Catalog (§5), so it
|
|
5
|
+
cannot (and must not) dereference it; the edge / gate resolve liveness when needed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
from core.errors import DomainError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CandidateKind(Enum):
|
|
15
|
+
RELEASE = "release"
|
|
16
|
+
PROPOSAL = "proposal"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True)
|
|
20
|
+
class CandidateRef:
|
|
21
|
+
kind: CandidateKind
|
|
22
|
+
ref: str
|
|
23
|
+
|
|
24
|
+
def __post_init__(self) -> None:
|
|
25
|
+
if not self.ref:
|
|
26
|
+
raise DomainError("candidate_ref_blank")
|
core/cell.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Cell — the (harness, model) comparison/routing coordinate (FLOWHARNESS_SPEC §6 glossary).
|
|
2
|
+
|
|
3
|
+
The unit of honest comparison: an EvalRun (and, later, a GenerationTrace / MatrixCell) binds an
|
|
4
|
+
exact `Cell` so two candidates are only ever compared within the same (harness, model) slot.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from core.errors import DomainError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class Cell:
|
|
14
|
+
harness: str
|
|
15
|
+
model: str
|
|
16
|
+
|
|
17
|
+
def __post_init__(self) -> None:
|
|
18
|
+
if not self.harness:
|
|
19
|
+
raise DomainError("cell_harness_blank")
|
|
20
|
+
if not self.model:
|
|
21
|
+
raise DomainError("cell_model_blank")
|
core/content_hash.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""ContentHashable — the single canonical content-address algorithm (FLOWHARNESS_SPEC §7.4, D8-14).
|
|
2
|
+
|
|
3
|
+
A content hash is a PROPERTY OF THE DATA, not a server-or-client computation: this mixin owns the
|
|
4
|
+
one algorithm — sha256 over `core.canonical_json`, `sha256:`-prefixed — so any two parties (the
|
|
5
|
+
platform, the CLI, the Rust port) holding the same content produce the same hash BY CONSTRUCTION. A
|
|
6
|
+
subclass mixes it in and implements `_hash_payload()` — the canonical, JSON-safe projection it
|
|
7
|
+
addresses (e.g. excluding identifiers it does not want in the content address). Centralizing the
|
|
8
|
+
algorithm here gives one place for the cross-language byte-parity contract (and the float-free
|
|
9
|
+
rule).
|
|
10
|
+
|
|
11
|
+
The projection is validated with `ensure_json_canonical` BEFORE serialising, so the content address
|
|
12
|
+
is canonical-by-construction for every subclass: a non-str dict key (which JSON silently coerces, so
|
|
13
|
+
`{1: ...}` and `{"1": ...}` collide) or any float raises a stable-coded `DomainError` here
|
|
14
|
+
rather than producing a colliding/ill-defined hash or a raw `TypeError`. Valid payloads pass through
|
|
15
|
+
untouched, so the digest stays byte-identical to the unvalidated form.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import hashlib
|
|
19
|
+
|
|
20
|
+
from core.journal import canonical_json, ensure_json_canonical
|
|
21
|
+
|
|
22
|
+
__all__ = ["ContentHashable"]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ContentHashable:
|
|
26
|
+
__slots__ = () # keep frozen/slotted dataclass subclasses fully slotted
|
|
27
|
+
|
|
28
|
+
def _hash_payload(self) -> object:
|
|
29
|
+
"""The canonical, JSON-safe projection this VO addresses. Subclasses must implement."""
|
|
30
|
+
raise NotImplementedError
|
|
31
|
+
|
|
32
|
+
def content_hash(self) -> str:
|
|
33
|
+
payload = self._hash_payload()
|
|
34
|
+
# canonical-by-construction: reject non-str keys / any float before they collide or diverge
|
|
35
|
+
ensure_json_canonical(payload)
|
|
36
|
+
return "sha256:" + hashlib.sha256(canonical_json(payload).encode()).hexdigest()
|
core/errors.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Domain error type — exceptions express domain concepts (P&G ch.1)."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DomainError(Exception):
|
|
5
|
+
"""Raised when a domain invariant is violated.
|
|
6
|
+
|
|
7
|
+
`code` is a stable snake_case identifier suitable for wire contracts — the machine surface,
|
|
8
|
+
unchanged by any diagnostic. `detail` is an OPTIONAL, diagnostic-only enrichment: it never
|
|
9
|
+
participates in the contract (no consumer parses it structurally), it only makes `str(e)` and
|
|
10
|
+
the problem+json `detail` member more legible.
|
|
11
|
+
|
|
12
|
+
Diagnostic-not-contract convention for `detail`: space-separated ``key=value`` pairs, values
|
|
13
|
+
`!r`-quoted, in a deterministic fixed key order, and free of timestamps or memory addresses so
|
|
14
|
+
the string is byte-stable and diff-friendly (e.g. ``detail=f"entity=asset slug={slug!r}"``).
|
|
15
|
+
|
|
16
|
+
Hard no-secret rule: secret-adjacent sites — api-token / webhook / license / signing bytes —
|
|
17
|
+
MUST omit `detail` or carry only a sha256-prefix plus a coarse length-bucket fingerprint,
|
|
18
|
+
never the raw value and never the exact length. The precedent is `finding_fingerprint`
|
|
19
|
+
(`platform/inspection/src/inspection/domain/baseline.py:19-29`), which redacts to
|
|
20
|
+
``sha256:`` + a truncated digest; `hashlib` is stdlib, so this redaction is honorable even
|
|
21
|
+
from pure domain code.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, code: str, *, detail: str | None = None) -> None:
|
|
25
|
+
super().__init__(code if detail is None else f"{code}: {detail}")
|
|
26
|
+
self.code = code
|
|
27
|
+
self.detail = detail
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""external_severity_map.v1 — third-party scanner signals → core.Severity (product/01 §4.7.3).
|
|
2
|
+
|
|
3
|
+
THE single authority for external-finding severity. Shared by flowharness_ci `ingest-findings`
|
|
4
|
+
(now) and platform_api evidence intake (docs/product/06, later): both may import `core`; neither
|
|
5
|
+
may import the other (import-linter contracts), so `core` is the only non-forking home (decision
|
|
6
|
+
M2). Ships as versioned policy data (M3): a change here moves the committed golden vectors + the
|
|
7
|
+
version string — a review event by construction, not a data hot-edit.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from collections.abc import Callable
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from decimal import Decimal, InvalidOperation
|
|
16
|
+
|
|
17
|
+
from core.errors import DomainError
|
|
18
|
+
from core.values import Severity
|
|
19
|
+
|
|
20
|
+
EXTERNAL_SEVERITY_MAP_VERSION: str = "external_severity_map.v1"
|
|
21
|
+
|
|
22
|
+
# SARIF `security-severity` (a STRING property) >= 9.0 lifts any level to CRITICAL (§4.7.3).
|
|
23
|
+
# Compared as Decimal (never float): the value is used ONLY for this comparison and never enters
|
|
24
|
+
# a hashed payload, so `core` hard-rule 2 (float-free canonical bytes) holds (decision M5).
|
|
25
|
+
_SECURITY_SEVERITY_CRITICAL = Decimal("9.0")
|
|
26
|
+
|
|
27
|
+
_TOOL_SLUG_RE = re.compile(r"[^a-z0-9]+") # any run of non-[a-z0-9] → one underscore
|
|
28
|
+
|
|
29
|
+
# Inverts inspection/domain/renderers/sarif.py `_SARIF_LEVEL`: CRITICAL and ERROR both render as
|
|
30
|
+
# "error" there, so the security-severity override above is the ONLY way to recover CRITICAL
|
|
31
|
+
# from a SARIF stream (§4.7.3).
|
|
32
|
+
_SARIF_LEVEL_TO_SEVERITY: dict[str, Severity] = {
|
|
33
|
+
"none": Severity.INFO,
|
|
34
|
+
"note": Severity.INFO,
|
|
35
|
+
"warning": Severity.WARN,
|
|
36
|
+
"error": Severity.ERROR,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Snyk agent-scan issue-code grammar (issue-codes.md): W-prefixed codes advise, E-prefixed codes
|
|
40
|
+
# are defects. Prefix-anchored (no `$`) so a suffixed variant of a known code keeps its class.
|
|
41
|
+
_SNYK_WARN_CODE_RE = re.compile(r"[Ww]\d+")
|
|
42
|
+
_SNYK_ERROR_CODE_RE = re.compile(r"[Ee]\d+")
|
|
43
|
+
# Snyk agent-scan curated-critical issue codes (tool-poisoning / injection-in-skill classes,
|
|
44
|
+
# §4.7.3: https://github.com/snyk/agent-scan/blob/main/docs/issue-codes.md) — versioned HERE,
|
|
45
|
+
# not hardcoded at a call site, so this set is the reviewable policy diff.
|
|
46
|
+
_SNYK_CRITICAL_CODES = frozenset({"E001", "E004"})
|
|
47
|
+
|
|
48
|
+
_AGUARA_SEVERITIES: dict[str, Severity] = {
|
|
49
|
+
"low": Severity.INFO,
|
|
50
|
+
"medium": Severity.WARN,
|
|
51
|
+
"high": Severity.ERROR,
|
|
52
|
+
"critical": Severity.CRITICAL,
|
|
53
|
+
}
|
|
54
|
+
# Identical to aguara's table TODAY, but an independently versioned policy row — the two tools'
|
|
55
|
+
# scales may diverge in a future map version, so no aliasing (§4.7.3 keeps one row per tool).
|
|
56
|
+
_MEDUSA_SEVERITIES: dict[str, Severity] = {
|
|
57
|
+
"low": Severity.INFO,
|
|
58
|
+
"medium": Severity.WARN,
|
|
59
|
+
"high": Severity.ERROR,
|
|
60
|
+
"critical": Severity.CRITICAL,
|
|
61
|
+
}
|
|
62
|
+
# Inkog's recognized structural cost-risk classes (§4.7.3: unbounded-loop / recursion /
|
|
63
|
+
# token-bombing). Substring markers, so class-name variants (e.g. "INKOG-RECURSION-001") still
|
|
64
|
+
# resolve; anything else falls through to unmapped.
|
|
65
|
+
_INKOG_STRUCTURAL_MARKERS: tuple[str, ...] = ("loop", "recursion", "token")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True, slots=True)
|
|
69
|
+
class SeverityResolution:
|
|
70
|
+
"""The mapped severity plus whether the source signal was unmapped (§4.7.3 last row).
|
|
71
|
+
|
|
72
|
+
`unmapped` drives the runner's `severity_unmapped` evidence marker AND the `[external]`
|
|
73
|
+
`unmapped_severities` gate key; the severity itself is WARN in the unmapped case.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
severity: Severity
|
|
77
|
+
unmapped: bool
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def normalize_tool_slug(name: str) -> str:
|
|
81
|
+
"""`tool.driver.name` / `--tool` → the `[a-z0-9_]+` slug shared with product/06 §4.3.
|
|
82
|
+
|
|
83
|
+
Lowercase, every non-[a-z0-9] run → one '_', strip leading/trailing '_'. Raises
|
|
84
|
+
DomainError("external_tool_slug_blank") when nothing survives (a slug is required).
|
|
85
|
+
|
|
86
|
+
>>> normalize_tool_slug("Snyk Agent Scan")
|
|
87
|
+
'snyk_agent_scan'
|
|
88
|
+
"""
|
|
89
|
+
slug = _TOOL_SLUG_RE.sub("_", name.strip().lower()).strip("_")
|
|
90
|
+
if not slug:
|
|
91
|
+
raise DomainError(
|
|
92
|
+
"external_tool_slug_blank", detail=f"name={name!r} expected={'[a-z0-9_]+'!r}"
|
|
93
|
+
)
|
|
94
|
+
return slug
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def canonical_tool_slug(name: str) -> str:
|
|
98
|
+
"""Resolve a SARIF `tool.driver.name` to the canonical registry slug it maps to (RV-1).
|
|
99
|
+
|
|
100
|
+
`normalize_tool_slug` yields the grammar-legal slug; but a driver name that is not verbatim
|
|
101
|
+
the registry key (the short "Snyk", the accented "Aguará" → "aguar") would miss its native
|
|
102
|
+
resolver, so the curated-critical `E001` would fall back to SARIF-level rating (a gate
|
|
103
|
+
under-rating). This consults the versioned `_DRIVER_ALIASES` table; a genuinely-unknown tool
|
|
104
|
+
is returned unchanged (SARIF-level mapping is the correct outcome there). Blank → DomainError.
|
|
105
|
+
|
|
106
|
+
>>> canonical_tool_slug("Snyk")
|
|
107
|
+
'snyk_agent_scan'
|
|
108
|
+
"""
|
|
109
|
+
slug = normalize_tool_slug(name)
|
|
110
|
+
if slug in _CANONICAL_SLUGS:
|
|
111
|
+
return slug
|
|
112
|
+
return _DRIVER_ALIASES.get(slug, slug)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def resolve_external_severity(
|
|
116
|
+
tool: str,
|
|
117
|
+
*,
|
|
118
|
+
sarif_level: str | None = None,
|
|
119
|
+
security_severity: str | None = None,
|
|
120
|
+
native_severity: str | None = None,
|
|
121
|
+
native_code: str | None = None,
|
|
122
|
+
) -> SeverityResolution:
|
|
123
|
+
"""Map one external result's raw signals to a `core.Severity` per the §4.7.3 table.
|
|
124
|
+
|
|
125
|
+
Precedence: security-severity >= 9.0 override → per-tool native code/severity → SARIF
|
|
126
|
+
level → unmapped (WARN + unmapped=True). The runner extracts the raw signals; this owns
|
|
127
|
+
the policy. A blank/non-normalizable `tool` raises DomainError("external_tool_slug_blank").
|
|
128
|
+
|
|
129
|
+
>>> resolve_external_severity("sarif_generic", sarif_level="warning")
|
|
130
|
+
SeverityResolution(severity=<Severity.WARN: 'warn'>, unmapped=False)
|
|
131
|
+
"""
|
|
132
|
+
slug = canonical_tool_slug(tool) # driver-name variant → registry key, so E001 isn't missed
|
|
133
|
+
if _security_severity_critical(security_severity):
|
|
134
|
+
return SeverityResolution(Severity.CRITICAL, unmapped=False)
|
|
135
|
+
mapped = _resolve_native(slug, native_severity, native_code) or _resolve_sarif(sarif_level)
|
|
136
|
+
if mapped is not None:
|
|
137
|
+
return SeverityResolution(mapped, unmapped=False)
|
|
138
|
+
return SeverityResolution(Severity.WARN, unmapped=True) # §4.7.3 unknown/absent row
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _security_severity_critical(security_severity: str | None) -> bool:
|
|
142
|
+
"""True when `security-severity` orders at or above 9.0 as a Decimal (§4.7.3 override).
|
|
143
|
+
|
|
144
|
+
The guard spans BOTH the parse and the comparison: NaN raises InvalidOperation at `>=`,
|
|
145
|
+
not at construction (plan §12 R2). Any unparseable or unordered value is "no override" —
|
|
146
|
+
the caller falls through to the next precedence step. `Infinity` >= 9.0 is True
|
|
147
|
+
(conservative → CRITICAL, pinned by T3).
|
|
148
|
+
"""
|
|
149
|
+
if security_severity is None:
|
|
150
|
+
return False
|
|
151
|
+
try:
|
|
152
|
+
return Decimal(str(security_severity)) >= _SECURITY_SEVERITY_CRITICAL
|
|
153
|
+
except (InvalidOperation, ValueError, TypeError):
|
|
154
|
+
return False
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _resolve_native(
|
|
158
|
+
slug: str, native_severity: str | None, native_code: str | None
|
|
159
|
+
) -> Severity | None:
|
|
160
|
+
"""Dispatch to the tool's policy row; None when the tool or its signal is unrecognized."""
|
|
161
|
+
resolver = _NATIVE_RESOLVERS.get(slug)
|
|
162
|
+
if resolver is None:
|
|
163
|
+
return None
|
|
164
|
+
return resolver(native_severity, native_code)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _resolve_sarif(sarif_level: str | None) -> Severity | None:
|
|
168
|
+
"""SARIF `level` → Severity per the §4.7.3 rows; unknown/absent level → None."""
|
|
169
|
+
if sarif_level is None:
|
|
170
|
+
return None
|
|
171
|
+
return _SARIF_LEVEL_TO_SEVERITY.get(sarif_level.strip().lower())
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _resolve_snyk(native_severity: str | None, native_code: str | None) -> Severity | None:
|
|
175
|
+
"""Snyk agent-scan issue code → Severity; curated-critical set beats the E-prefix rule.
|
|
176
|
+
|
|
177
|
+
Curated-critical is matched on the EXTRACTED leading ``E###`` token — the SAME prefix the
|
|
178
|
+
E-rule uses — so a suffixed variant (``E001-skill-poisoning``) still rates CRITICAL, not
|
|
179
|
+
ERROR (RV-2). An exact ``in`` over the whole ruleId would silently demote it past
|
|
180
|
+
``max_error``.
|
|
181
|
+
"""
|
|
182
|
+
if native_code is None:
|
|
183
|
+
return None
|
|
184
|
+
code = native_code.strip()
|
|
185
|
+
if _SNYK_WARN_CODE_RE.match(code):
|
|
186
|
+
return Severity.WARN
|
|
187
|
+
error = _SNYK_ERROR_CODE_RE.match(code)
|
|
188
|
+
if error is None:
|
|
189
|
+
return None
|
|
190
|
+
if error.group().upper() in _SNYK_CRITICAL_CODES:
|
|
191
|
+
return Severity.CRITICAL
|
|
192
|
+
return Severity.ERROR
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _resolve_aguara(native_severity: str | None, native_code: str | None) -> Severity | None:
|
|
196
|
+
"""Aguara low/medium/high/critical → Severity; unrecognized → None."""
|
|
197
|
+
if native_severity is None:
|
|
198
|
+
return None
|
|
199
|
+
return _AGUARA_SEVERITIES.get(native_severity.strip().lower())
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _resolve_medusa(native_severity: str | None, native_code: str | None) -> Severity | None:
|
|
203
|
+
"""Medusa low/medium/high/critical → Severity; unrecognized → None."""
|
|
204
|
+
if native_severity is None:
|
|
205
|
+
return None
|
|
206
|
+
return _MEDUSA_SEVERITIES.get(native_severity.strip().lower())
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _resolve_inkog(native_severity: str | None, native_code: str | None) -> Severity | None:
|
|
210
|
+
"""Inkog structural classes (loop/recursion/token markers in either signal) → ERROR."""
|
|
211
|
+
signal = " ".join(part for part in (native_code, native_severity) if part).lower()
|
|
212
|
+
if any(marker in signal for marker in _INKOG_STRUCTURAL_MARKERS):
|
|
213
|
+
return Severity.ERROR
|
|
214
|
+
return None
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# Open/closed per-tool policy registry (plan §12 R2): adding a tool is one row here plus its
|
|
218
|
+
# resolver — no branch edits. `sarif_generic` deliberately has NO row: SARIF level +
|
|
219
|
+
# security-severity are its only signals (§4.7.3).
|
|
220
|
+
_NATIVE_RESOLVERS: dict[str, Callable[[str | None, str | None], Severity | None]] = {
|
|
221
|
+
"snyk_agent_scan": _resolve_snyk,
|
|
222
|
+
"aguara": _resolve_aguara,
|
|
223
|
+
"medusa": _resolve_medusa,
|
|
224
|
+
"inkog": _resolve_inkog,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
# The canonical slug set = the native-resolver keys plus `sarif_generic` (which has no resolver
|
|
228
|
+
# but IS a known tool identity). A slug already in here is authoritative — no alias lookup.
|
|
229
|
+
_CANONICAL_SLUGS: frozenset[str] = frozenset({*_NATIVE_RESOLVERS, "sarif_generic"})
|
|
230
|
+
|
|
231
|
+
# Known driver-name variants → canonical registry slug (versioned policy data alongside the map,
|
|
232
|
+
# §4.7.3). EXPLICIT mapping, never fuzzy/substring: a near-name like "snyky" is a DIFFERENT tool
|
|
233
|
+
# and must NOT be aliased to Snyk. A new driver spelling = one row here, a reviewable diff.
|
|
234
|
+
_DRIVER_ALIASES: dict[str, str] = {
|
|
235
|
+
"snyk": "snyk_agent_scan",
|
|
236
|
+
"snyk_agent_scan": "snyk_agent_scan",
|
|
237
|
+
"aguara": "aguara",
|
|
238
|
+
"aguar": "aguara",
|
|
239
|
+
"medusa": "medusa",
|
|
240
|
+
"inkog": "inkog",
|
|
241
|
+
"inkog_io": "inkog",
|
|
242
|
+
}
|
core/findings.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Finding and EvidenceBundle (FLOWHARNESS_SPEC.md §6.1).
|
|
2
|
+
|
|
3
|
+
Finding is the universal output of every Check; EvidenceBundle is the
|
|
4
|
+
universal input of every Gate.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from core.errors import DomainError
|
|
10
|
+
from core.values import Severity
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True, slots=True)
|
|
14
|
+
class SourceAnchor:
|
|
15
|
+
"""File/line anchor for a Finding (CI governance spec §3.6) — 1-based, end-inclusive."""
|
|
16
|
+
|
|
17
|
+
path: str
|
|
18
|
+
line: int
|
|
19
|
+
end_line: int | None = None
|
|
20
|
+
|
|
21
|
+
def __post_init__(self) -> None:
|
|
22
|
+
if not self.path:
|
|
23
|
+
raise DomainError("anchor_path_blank")
|
|
24
|
+
if self.line <= 0:
|
|
25
|
+
raise DomainError("anchor_line_invalid")
|
|
26
|
+
if self.end_line is not None and self.end_line < self.line:
|
|
27
|
+
raise DomainError("anchor_end_line_before_start")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True, slots=True)
|
|
31
|
+
class Finding:
|
|
32
|
+
check_id: str
|
|
33
|
+
subject_ref: str
|
|
34
|
+
severity: Severity
|
|
35
|
+
dimension: str
|
|
36
|
+
evidence: str
|
|
37
|
+
suggested_action: str
|
|
38
|
+
anchor: SourceAnchor | None = None
|
|
39
|
+
|
|
40
|
+
def __post_init__(self) -> None:
|
|
41
|
+
if not self.check_id:
|
|
42
|
+
raise DomainError("finding_check_id_blank")
|
|
43
|
+
if not self.subject_ref:
|
|
44
|
+
raise DomainError("finding_subject_ref_blank")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True, slots=True)
|
|
48
|
+
class EvidenceRef:
|
|
49
|
+
kind: str
|
|
50
|
+
ref: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass(frozen=True, slots=True)
|
|
54
|
+
class EvidenceBundle:
|
|
55
|
+
items: tuple[EvidenceRef, ...]
|
|
56
|
+
|
|
57
|
+
def __post_init__(self) -> None:
|
|
58
|
+
if not isinstance(self.items, tuple):
|
|
59
|
+
raise DomainError("evidence_bundle_items_not_a_tuple")
|
core/journal.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Event Journal envelope + tamper-evident hash chain (FLOWHARNESS_SPEC.md §6.1, §9.3).
|
|
2
|
+
|
|
3
|
+
One envelope per domain event (one table, three roles: outbox, audit, projection feed —
|
|
4
|
+
§9.3). The journal is never used for rehydration: aggregates stay state-stored. A
|
|
5
|
+
deterministic `entry_hash` over (prev_hash, canonical envelope) chains the per-org log so
|
|
6
|
+
any retroactive edit changes every subsequent hash. occurred_at is injected (the domain
|
|
7
|
+
mints no timestamps — a clock is wired at the boundary).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
from collections.abc import Mapping
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
|
|
16
|
+
from core.actors import Actor, actor_to_json
|
|
17
|
+
from core.errors import DomainError
|
|
18
|
+
|
|
19
|
+
# per-org chain seed: an all-zero digest, same shape as every entry hash
|
|
20
|
+
GENESIS_HASH = "sha256:" + "0" * 64
|
|
21
|
+
_EVENT_TYPE = re.compile(r"^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\.v[0-9]+$")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def ensure_json_canonical(value: object) -> None:
|
|
25
|
+
"""Reject any payload shape that would make the entry hash non-deterministic or non-portable
|
|
26
|
+
across languages: non-str dict keys (json coerces `1` and `"1"` to the same key — a silent
|
|
27
|
+
collision), any float (the domain is float-free — hard rule 2; CPython float-repr is not
|
|
28
|
+
byte-portable to the Rust port), or types JSON cannot represent. Booleans, ints and None are
|
|
29
|
+
fine."""
|
|
30
|
+
if isinstance(value, Mapping):
|
|
31
|
+
for key, item in value.items():
|
|
32
|
+
if not isinstance(key, str):
|
|
33
|
+
raise DomainError("event_payload_key_not_str")
|
|
34
|
+
ensure_json_canonical(item)
|
|
35
|
+
elif isinstance(value, (list, tuple)):
|
|
36
|
+
for item in value:
|
|
37
|
+
ensure_json_canonical(item)
|
|
38
|
+
elif value is None or isinstance(value, (str, bool, int)):
|
|
39
|
+
return
|
|
40
|
+
elif isinstance(value, float):
|
|
41
|
+
# Float-free domain (hard rule 2): no float may enter a content hash, entry hash, or
|
|
42
|
+
# wire payload — CPython float-repr can diverge from serde_json (1e-07 vs 1e-7), which
|
|
43
|
+
# would break §7.4 byte-parity. Convert at the edge (BasisPoints / micro-units / str).
|
|
44
|
+
raise DomainError("event_payload_float_forbidden")
|
|
45
|
+
else:
|
|
46
|
+
raise DomainError("event_payload_value_not_json")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True, slots=True)
|
|
50
|
+
class DomainEventEnvelope:
|
|
51
|
+
event_id: str
|
|
52
|
+
org_id: str
|
|
53
|
+
occurred_at: str # ISO-8601 UTC; injected, never minted in the domain
|
|
54
|
+
actor: Actor
|
|
55
|
+
aggregate_type: str
|
|
56
|
+
aggregate_id: str
|
|
57
|
+
sequence_no: int # per aggregate, monotonic
|
|
58
|
+
event_type: str # '<context>.<subject_verb_ed>.v<N>' (§4.2.3)
|
|
59
|
+
payload: Mapping[str, object]
|
|
60
|
+
causation_id: str | None
|
|
61
|
+
correlation_id: str | None
|
|
62
|
+
|
|
63
|
+
def __post_init__(self) -> None:
|
|
64
|
+
if not self.event_id:
|
|
65
|
+
raise DomainError("event_id_blank")
|
|
66
|
+
if not self.org_id:
|
|
67
|
+
raise DomainError("event_org_id_blank")
|
|
68
|
+
if self.sequence_no < 0:
|
|
69
|
+
raise DomainError("event_sequence_no_negative")
|
|
70
|
+
if not _EVENT_TYPE.match(self.event_type):
|
|
71
|
+
raise DomainError("event_type_malformed")
|
|
72
|
+
ensure_json_canonical(self.payload)
|
|
73
|
+
|
|
74
|
+
def canonical(self) -> dict:
|
|
75
|
+
return {
|
|
76
|
+
"event_id": self.event_id,
|
|
77
|
+
"org_id": self.org_id,
|
|
78
|
+
"occurred_at": self.occurred_at,
|
|
79
|
+
"actor": actor_to_json(self.actor), # R05.3 (D-R5-4): the one codec
|
|
80
|
+
"aggregate_type": self.aggregate_type,
|
|
81
|
+
"aggregate_id": self.aggregate_id,
|
|
82
|
+
"sequence_no": self.sequence_no,
|
|
83
|
+
"event_type": self.event_type,
|
|
84
|
+
"payload": self.payload,
|
|
85
|
+
"causation_id": self.causation_id,
|
|
86
|
+
"correlation_id": self.correlation_id,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def canonical_json(obj: object) -> str:
|
|
91
|
+
"""The single canonical JSON form — compact, key-sorted, UTF-8, finite-only. Used both
|
|
92
|
+
for the hash chain and for the wire `payload_json` (governance-contract-v1 §3.3), so the
|
|
93
|
+
two can never drift: the bytes the entry hash is computed over ARE the bytes on the wire."""
|
|
94
|
+
return json.dumps(
|
|
95
|
+
obj, sort_keys=True, ensure_ascii=False, separators=(",", ":"), allow_nan=False
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def entry_hash(envelope: DomainEventEnvelope, prev_hash: str) -> str:
|
|
100
|
+
# One canonical byte string per (prev_hash, envelope) so the chain is reproducible here
|
|
101
|
+
# and byte-equal to the Rust port (§7.4).
|
|
102
|
+
body = {"prev_hash": prev_hash, "envelope": envelope.canonical()}
|
|
103
|
+
return "sha256:" + hashlib.sha256(canonical_json(body).encode()).hexdigest()
|
core/messages.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Command and Event base types (FLOWHARNESS_SPEC.md §8.1, P&G ch.10).
|
|
2
|
+
|
|
3
|
+
Commands ≠ Events: commands are imperative with exactly one handler and propagate
|
|
4
|
+
errors; events are past-tense with zero-to-many handlers whose failures are isolated.
|
|
5
|
+
Concrete messages are frozen dataclasses subclassing these markers.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Command:
|
|
10
|
+
"""Imperative request; exactly one handler; errors propagate to the caller."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Event:
|
|
14
|
+
"""Past-tense fact; zero-to-many handlers; handler failures are isolated."""
|
core/ports.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Shared ports (FLOWHARNESS_SPEC.md §6.1).
|
|
2
|
+
|
|
3
|
+
Ports are capability nouns (§4.2.5), defined here as structural Protocols and
|
|
4
|
+
implemented per context or in infrastructure. Findings are the universal Check
|
|
5
|
+
output; EvidenceBundle the universal Gate input. Lifecycle and Repository are
|
|
6
|
+
intentionally absent: the spec extracts Lifecycle at its second real instance, and
|
|
7
|
+
Repository is defined per context's application layer (one per aggregate root).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from collections.abc import Iterable, Sequence
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Protocol, runtime_checkable
|
|
13
|
+
|
|
14
|
+
from core.findings import EvidenceBundle, Finding
|
|
15
|
+
from core.journal import DomainEventEnvelope
|
|
16
|
+
from core.values import Verdict
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@runtime_checkable
|
|
20
|
+
class GatePolicy(Protocol):
|
|
21
|
+
"""A versioned policy document interpreted by a generic engine (§4.2.7)."""
|
|
22
|
+
|
|
23
|
+
version: str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class GateOutcome:
|
|
28
|
+
"""A Gate's decision plus the journal envelopes the gate minted for it. The gate stays pure (it
|
|
29
|
+
opens no UoW); the caller stages `journal` into its OWN transaction, so the gate-decision event
|
|
30
|
+
commits atomically with the command that consumed the verdict (D9b-5/D9b-6). The envelopes are
|
|
31
|
+
opaque `core.DomainEventEnvelope`s, so a consumer (e.g. Catalog) need not import the gate's
|
|
32
|
+
context to stage them — context independence holds."""
|
|
33
|
+
|
|
34
|
+
verdict: Verdict
|
|
35
|
+
journal: tuple[DomainEventEnvelope, ...] = ()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@runtime_checkable
|
|
39
|
+
class Check(Protocol):
|
|
40
|
+
def run(self, subject: object, ctx: object) -> list[Finding]: ...
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@runtime_checkable
|
|
44
|
+
class Gate(Protocol):
|
|
45
|
+
def evaluate(self, evidence: EvidenceBundle, policy: GatePolicy) -> GateOutcome: ...
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@runtime_checkable
|
|
49
|
+
class SignalSink(Protocol):
|
|
50
|
+
"""Accepts raw behavioural signals (usage, cost, latency) for later aggregation."""
|
|
51
|
+
|
|
52
|
+
def emit(self, signals: Sequence[object]) -> None: ...
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@runtime_checkable
|
|
56
|
+
class IndexReader(Protocol):
|
|
57
|
+
"""Reads an aggregated metric for a subject over a window (the signals projection)."""
|
|
58
|
+
|
|
59
|
+
def read(self, subject: str, metric: str, window: str) -> object: ...
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@runtime_checkable
|
|
63
|
+
class EvidenceSource(Protocol):
|
|
64
|
+
"""Yields evidence items (traces, transcripts, attestations) for an evaluation window.
|
|
65
|
+
|
|
66
|
+
First implementations land with the evidence-pack spec
|
|
67
|
+
(docs/product/04-evidence-and-attestation.md, D-P4-1 — per-context adapters in the
|
|
68
|
+
Compliance context; see also docs/back/07-rollout-progressive-delivery.md:904); the
|
|
69
|
+
port is their frozen vocabulary."""
|
|
70
|
+
|
|
71
|
+
def collect(self, window: str) -> Sequence[object]: ...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@runtime_checkable
|
|
75
|
+
class Corpus(Protocol):
|
|
76
|
+
"""Provides the case specs an evaluation runs an asset against (§6.1)."""
|
|
77
|
+
|
|
78
|
+
def cases(self) -> Iterable[object]: ...
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@runtime_checkable
|
|
82
|
+
class UnitOfWork(Protocol):
|
|
83
|
+
"""Atomic transaction boundary (P&G ch.6): a context manager with an explicit
|
|
84
|
+
commit and a drain of the events its aggregates raised."""
|
|
85
|
+
|
|
86
|
+
def __enter__(self) -> "UnitOfWork": ...
|
|
87
|
+
def __exit__(self, *exc: object) -> object: ...
|
|
88
|
+
def commit(self) -> None: ...
|
|
89
|
+
def collect_new_events(self) -> Sequence[object]: ...
|
core/py.typed
ADDED
|
File without changes
|
core/signing.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""HMAC-SHA256 detached signing over canonical bytes, keyed by the runner's raw token (D9a-2).
|
|
2
|
+
|
|
3
|
+
Pure + stdlib only, lifted here from evaluation.domain.signing (D3, SIG-1) so any context can
|
|
4
|
+
sign or verify without depending on evaluation. The platform recomputes the tag with the raw
|
|
5
|
+
token it already receives to authenticate the request, so there is no separate signing-key
|
|
6
|
+
store; the raw key never leaves the edge boundary. Comparison is constant-time; a malformed or
|
|
7
|
+
empty signature simply fails to verify. evaluation.domain.signing re-exports both names, keeping
|
|
8
|
+
every existing caller byte-compatible.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
import hmac
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def sign_report(canonical_payload: bytes, key: str) -> str:
|
|
16
|
+
"""Return the lowercase hex HMAC-SHA256 tag of ``canonical_payload`` under ``key``.
|
|
17
|
+
|
|
18
|
+
Example: ``sign_report(b'{"pass_rate_bp":10000}', "tok_secret")`` -> a 64-char hex digest.
|
|
19
|
+
"""
|
|
20
|
+
return hmac.new(key.encode("utf-8"), canonical_payload, hashlib.sha256).hexdigest()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def verify_signature(canonical_payload: bytes, key: str, signature_hex: str) -> bool:
|
|
24
|
+
"""Constant-time-check ``signature_hex`` against the tag recomputed from payload+key.
|
|
25
|
+
|
|
26
|
+
Tolerates surrounding whitespace and uppercase hex; a malformed/empty candidate returns False.
|
|
27
|
+
Example: ``verify_signature(payload, key, sign_report(payload, key))`` -> True.
|
|
28
|
+
"""
|
|
29
|
+
expected = sign_report(canonical_payload, key)
|
|
30
|
+
return hmac.compare_digest(expected, signature_hex.strip().lower())
|
core/values.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Scalar value objects shared by every context (FLOWHARNESS_SPEC.md §6.0, §6.1)."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from enum import StrEnum
|
|
5
|
+
|
|
6
|
+
from core.errors import DomainError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Severity(StrEnum):
|
|
10
|
+
INFO = "info"
|
|
11
|
+
WARN = "warn"
|
|
12
|
+
ERROR = "error"
|
|
13
|
+
CRITICAL = "critical"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Verdict(StrEnum):
|
|
17
|
+
PASS = "pass"
|
|
18
|
+
FAIL = "fail"
|
|
19
|
+
NEEDS_HUMAN = "needs_human"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class BasisPoints:
|
|
24
|
+
value: int # 10_000 == 100%
|
|
25
|
+
|
|
26
|
+
def __post_init__(self) -> None:
|
|
27
|
+
if not 0 <= self.value <= 10_000_000: # allow >100% for ratios
|
|
28
|
+
raise DomainError("basis_points_out_of_range")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flowharness-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared core for flowharness — domain primitives, Finding, Check/Gate ports
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Project-URL: Homepage, https://github.com/flowharness-ai
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# flowharness-core
|
|
16
|
+
|
|
17
|
+
Shared core domain kernel for flowharness — provides canonical Finding objects, Check/Gate/UnitOfWork ports, canonical JSON serialization, HMAC signing/verification, and value objects (Severity, Verdict, BasisPoints) that every bounded context depends on.
|
|
18
|
+
|
|
19
|
+
This is an **internal library package** of the FlowHarness toolchain, published to PyPI as a transitive dependency of [`flowharness`](https://github.com/flowharness-ai) (the scan CLI) and [`flowharness-ci-runner`](https://github.com/flowharness-ai). Install those packages instead of depending on `flowharness-core` directly.
|
|
20
|
+
|
|
21
|
+
> **Note:** this package currently installs a top-level module named `core`. Prefer `uvx` (isolated environments) over `pip install` into a shared venv until the 0.2 module-namespace rename lands.
|
|
22
|
+
|
|
23
|
+
**License:** Apache-2.0
|
|
24
|
+
**Homepage:** https://github.com/flowharness-ai
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
core/__init__.py,sha256=VtyP8-HKO6zzJTraHewriJERVCeOcDTDBaIEmaUEr4s,6351
|
|
2
|
+
core/actors.py,sha256=YxJhIX6YooYpKO9pNYd0YOcULJS5MLaPryIqCCbyk7I,2244
|
|
3
|
+
core/aggregate.py,sha256=3dWT4IakJY_pbhz5j4OETE4wyOzg4PKu86Sk7e5hxIQ,1161
|
|
4
|
+
core/candidate.py,sha256=3eg3cTqSKIgjYJjSuq4901qL-qI2bgXvTE8omyvTNmk,756
|
|
5
|
+
core/cell.py,sha256=sS07A2w0Dsqc8c_hIbYW91PFta9gyMZQ3QCWqS3nDnU,640
|
|
6
|
+
core/content_hash.py,sha256=B-1_PE57It6Rb9gZmLxTkv--btAEhnFW25yiOJ77xpo,1852
|
|
7
|
+
core/errors.py,sha256=txsDkILjwQ9ayIfRbxmVDvjZWZ4-2XU-3OsVkjNvPo0,1500
|
|
8
|
+
core/external_findings.py,sha256=raH8sAgkSRL-0PAqts6dxMjxGYsIxmH6ImzrE-s0vNE,10579
|
|
9
|
+
core/findings.py,sha256=ogcgQY9QZbKP0klPo703aiodFF9CI_dRTnShEZLCWmA,1573
|
|
10
|
+
core/journal.py,sha256=RR88h4DoMf-EMRhBhCnmxrmF3ud_qZEhpxNLz-5xyDk,4457
|
|
11
|
+
core/messages.py,sha256=oIbFylYkgpFt5NqvKx0CXbEgKN90eEhEmqpDw-_R2Ig,511
|
|
12
|
+
core/ports.py,sha256=em5QjE037o6oSJY7Aunw4dAaroFVzZL4OgXUE_97mUk,3134
|
|
13
|
+
core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
core/signing.py,sha256=hRc7EBcDFzgIPjwK5cS74bjklUKy9sM3VItHv1rb2kE,1472
|
|
15
|
+
core/values.py,sha256=wZsfOH2FFhEFJKpzoAAAaJaSqEOUKgQFeYDQoPoVaSM,646
|
|
16
|
+
flowharness_core-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
17
|
+
flowharness_core-0.1.0.dist-info/WHEEL,sha256=oy45bIW3ehK02fnLDUKD-FzeaR3VpJxY5Jdblkktnpw,80
|
|
18
|
+
flowharness_core-0.1.0.dist-info/METADATA,sha256=km4VGLZzqqL7xFXGf663_KOhvEb4PZ-eXCf3k2yNaE4,1376
|
|
19
|
+
flowharness_core-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|