egzoscore 0.2.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.
- egzos/__init__.py +11 -0
- egzos/_ids.py +29 -0
- egzos/_signals.py +39 -0
- egzos/_term.py +33 -0
- egzos/_types.py +1023 -0
- egzos/api/__init__.py +150 -0
- egzos/api/app.py +1574 -0
- egzos/api/blobs.py +92 -0
- egzos/api/throttle.py +190 -0
- egzos/auth.py +176 -0
- egzos/authz/__init__.py +5 -0
- egzos/authz/presence.py +778 -0
- egzos/authz/values.py +32 -0
- egzos/backends/__init__.py +8 -0
- egzos/backends/base.py +91 -0
- egzos/backends/postgres.py +490 -0
- egzos/backends/sqlite.py +524 -0
- egzos/binding.py +309 -0
- egzos/cli/__init__.py +1092 -0
- egzos/cli/__main__.py +11 -0
- egzos/confirm.py +455 -0
- egzos/container.py +222 -0
- egzos/identity.py +1104 -0
- egzos/ledger.py +167 -0
- egzos/mcp/__init__.py +3 -0
- egzos/mcp/http.py +90 -0
- egzos/mcp/server.py +287 -0
- egzos/model.py +242 -0
- egzos/py.typed +0 -0
- egzos/resolver.py +115 -0
- egzos/store/__init__.py +10 -0
- egzos/store/autotitle.py +31 -0
- egzos/store/blobs.py +120 -0
- egzos/store/find.py +120 -0
- egzos/store/items.py +233 -0
- egzos/store/nodes.py +193 -0
- egzos/store/objects.py +143 -0
- egzos/store/uploads.py +369 -0
- egzos/trust.py +675 -0
- egzos/web/__init__.py +88 -0
- egzos/web/app.py +965 -0
- egzos/web/static/htmx.LICENSE +13 -0
- egzos/web/static/htmx.min.js +1 -0
- egzos/web/static/lifeboat.css +140 -0
- egzos/web/static/lifeboat.js +12 -0
- egzos/web/strings.py +133 -0
- egzos/web/templates/_manifest_row.html +3 -0
- egzos/web/templates/_shell.html +29 -0
- egzos/web/templates/_window.html +7 -0
- egzos/web/templates/base.html +24 -0
- egzos/web/templates/error.html +10 -0
- egzos/web/templates/home.html +39 -0
- egzos/web/templates/item.html +91 -0
- egzos/web/templates/notfound.html +6 -0
- egzos/web/templates/pending.html +107 -0
- egzos/web/tokens.css +294 -0
- egzoscore-0.2.0.dist-info/METADATA +135 -0
- egzoscore-0.2.0.dist-info/RECORD +62 -0
- egzoscore-0.2.0.dist-info/WHEEL +4 -0
- egzoscore-0.2.0.dist-info/entry_points.txt +2 -0
- egzoscore-0.2.0.dist-info/licenses/LICENSE +65 -0
- egzoscore-0.2.0.dist-info/licenses/NOTICE +6 -0
egzos/_types.py
ADDED
|
@@ -0,0 +1,1023 @@
|
|
|
1
|
+
# Copyright 2026 Ali Sasanian
|
|
2
|
+
# SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
|
|
3
|
+
"""
|
|
4
|
+
Shared types — owned by a1p-planner.
|
|
5
|
+
|
|
6
|
+
The typed face of ``spec/contracts/``. Nothing here is invented: every name below is derived from
|
|
7
|
+
the running walking skeleton (``chief/walking-skeleton``) and carries the contract document it
|
|
8
|
+
belongs to. Shapes marked in the contracts as *decided, not running* are typed here too, so that
|
|
9
|
+
Phase 1 builds against the frozen surface rather than the skeleton's.
|
|
10
|
+
|
|
11
|
+
**Frozen at 0.3 with the contracts it types** (Chief, 2026-10-08; ``spec/contracts/README.md``).
|
|
12
|
+
A change to a vocabulary here is a change to a frozen contract: a ``contract-change`` escalation,
|
|
13
|
+
never a drive-by.
|
|
14
|
+
|
|
15
|
+
Covers all six documents: ``context-item.md``, ``capabilities.md``, ``events.md`` (issue #26),
|
|
16
|
+
``storage.md`` (issue #27), ``container.md`` (issue #28) and ``authorization-server.md`` (#67 and
|
|
17
|
+
#61, with the 0.3 decisions written in by #109). Consolidated by #30: one naming convention
|
|
18
|
+
(``SCREAMING_CASE`` runtime values derived from ``CamelCase`` types), no Literal union defined
|
|
19
|
+
twice, and ``__all__`` complete (``tests/_types/test_exports.py``) and isort-sorted (ruff RUF022).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from collections.abc import Iterable, Iterator, Mapping
|
|
25
|
+
from contextlib import AbstractContextManager
|
|
26
|
+
from types import MappingProxyType
|
|
27
|
+
from typing import Any, Literal, NamedTuple, NotRequired, Protocol, TypedDict, get_args
|
|
28
|
+
|
|
29
|
+
# The runtime tuples below are DERIVED from their Literal unions, never written out twice: a
|
|
30
|
+
# vocabulary that can drift from its own type is a vocabulary that will.
|
|
31
|
+
|
|
32
|
+
# --- capabilities, principals, tokens (spec/contracts/capabilities.md) ---------------------
|
|
33
|
+
|
|
34
|
+
Capability = Literal["fetch", "remember", "organize", "publish", "curate", "admin"]
|
|
35
|
+
#: The ladder order. Six is the ENTIRE vocabulary (v0.3 §5, DECIDED); `structure` is a per-node
|
|
36
|
+
#: scope-policy floor (F2), not a seventh capability.
|
|
37
|
+
CAPABILITIES: tuple[Capability, ...] = get_args(Capability)
|
|
38
|
+
|
|
39
|
+
Role = Literal["reader", "contributor", "operator", "curator", "admin"]
|
|
40
|
+
#: Expanded at mint time — the token carries capabilities, never the bundle name.
|
|
41
|
+
ROLE_BUNDLES: dict[Role, frozenset[Capability]] = {
|
|
42
|
+
"reader": frozenset({"fetch"}),
|
|
43
|
+
"contributor": frozenset({"fetch", "remember"}),
|
|
44
|
+
"operator": frozenset({"fetch", "remember", "organize", "publish"}),
|
|
45
|
+
"curator": frozenset({"fetch", "remember", "organize", "publish", "curate"}),
|
|
46
|
+
"admin": frozenset(CAPABILITIES),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Principal = Literal["interactive", "client", "none"]
|
|
50
|
+
#: `none` is an AUDIT ENTRY's principal, never a token's (capabilities.md §3, [0.3 · 34]): the
|
|
51
|
+
#: pre-authorization appends that have no caller to name (authorization-server.md §12.2).
|
|
52
|
+
PRINCIPALS: tuple[Principal, ...] = get_args(Principal)
|
|
53
|
+
|
|
54
|
+
#: What a token, an audience member or an item's provenance can carry: `none` excluded by type, so
|
|
55
|
+
#: a token minted for nobody is a type error rather than a value a check has to remember to refuse.
|
|
56
|
+
TokenPrincipal = Literal["interactive", "client"]
|
|
57
|
+
TOKEN_PRINCIPALS: tuple[TokenPrincipal, ...] = get_args(TokenPrincipal)
|
|
58
|
+
|
|
59
|
+
#: Outside the capability vocabulary by construction: no token reaches these, `admin` included.
|
|
60
|
+
#: A client principal can only propose. Not configurable, at any deployment.
|
|
61
|
+
HUMAN_ONLY_ACTS: tuple[str, ...] = ("gate.confirm", "yes.consume", "approve.pending")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Token(TypedDict):
|
|
65
|
+
"""`scopes` are node ids; coverage is computed down the path AT CHECK TIME. `["*"]` = owner."""
|
|
66
|
+
|
|
67
|
+
id: str
|
|
68
|
+
principal: TokenPrincipal
|
|
69
|
+
owner: str
|
|
70
|
+
client: str
|
|
71
|
+
capabilities: list[Capability]
|
|
72
|
+
scopes: list[str]
|
|
73
|
+
created_at: str
|
|
74
|
+
last_used: str | None
|
|
75
|
+
revoked: bool
|
|
76
|
+
expires_at: str | None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# --- the item (spec/contracts/context-item.md) ---------------------------------------------
|
|
80
|
+
|
|
81
|
+
Kind = Literal["memory", "preference", "skill", "artifact", "integration", "alias", "rule"]
|
|
82
|
+
KINDS: tuple[Kind, ...] = get_args(Kind)
|
|
83
|
+
|
|
84
|
+
TrustStatus = Literal["unverified", "verified", "quarantined"]
|
|
85
|
+
TRUST_STATUSES: tuple[TrustStatus, ...] = get_args(TrustStatus)
|
|
86
|
+
|
|
87
|
+
#: Rules are served verified-only at EVERY scope, overriding the per-container serving policy.
|
|
88
|
+
VERIFIED_ONLY_KINDS: frozenset[Kind] = frozenset({"rule"})
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class TextContent(TypedDict):
|
|
92
|
+
body: str
|
|
93
|
+
auto_title: str
|
|
94
|
+
title_engine: str
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class ArtifactContent(TypedDict):
|
|
98
|
+
"""`inline` is present ONLY when size <= blobs.inline_max_bytes AND mime matches text/*."""
|
|
99
|
+
|
|
100
|
+
sha256: str
|
|
101
|
+
mime: str
|
|
102
|
+
size: int
|
|
103
|
+
filename: str
|
|
104
|
+
auto_title: str
|
|
105
|
+
title_engine: str
|
|
106
|
+
inline: NotRequired[str]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class Provenance(TypedDict):
|
|
110
|
+
"""All six keys present, null where unknown — never absent-vs-unset."""
|
|
111
|
+
|
|
112
|
+
actor: str | None
|
|
113
|
+
principal: TokenPrincipal | None
|
|
114
|
+
client: str | None
|
|
115
|
+
derived_from: str | None
|
|
116
|
+
imported_from: str | None
|
|
117
|
+
approved_by: str | None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Trust(TypedDict):
|
|
121
|
+
"""`promoted_at`/`manifest` accompany `verified`; `reason`/`at` accompany `quarantined`."""
|
|
122
|
+
|
|
123
|
+
status: TrustStatus
|
|
124
|
+
promoted_at: NotRequired[str]
|
|
125
|
+
manifest: NotRequired[str]
|
|
126
|
+
reason: NotRequired[str]
|
|
127
|
+
at: NotRequired[str]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Lifecycle(TypedDict):
|
|
131
|
+
created_at: str
|
|
132
|
+
updated_at: str
|
|
133
|
+
version: int
|
|
134
|
+
tombstoned: NotRequired[bool]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class ContextItem(TypedDict):
|
|
138
|
+
"""`scope` is a LOCATION, not an identity. Unknown fields survive round-trip (see below)."""
|
|
139
|
+
|
|
140
|
+
id: str
|
|
141
|
+
kind: Kind
|
|
142
|
+
scope: str
|
|
143
|
+
content: TextContent | ArtifactContent
|
|
144
|
+
key: str | None
|
|
145
|
+
tags: list[str]
|
|
146
|
+
provenance: Provenance
|
|
147
|
+
trust: Trust
|
|
148
|
+
lifecycle: Lifecycle
|
|
149
|
+
visibility: dict[str, Any]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
#: Fields an implementation knows. Anything else on the wire MUST be preserved verbatim and written
|
|
153
|
+
#: back unchanged — the contract fixes the behaviour, not the carrier the skeleton calls `extra`.
|
|
154
|
+
CONTEXT_ITEM_FIELDS: tuple[str, ...] = (
|
|
155
|
+
"id",
|
|
156
|
+
"kind",
|
|
157
|
+
"scope",
|
|
158
|
+
"content",
|
|
159
|
+
"key",
|
|
160
|
+
"tags",
|
|
161
|
+
"provenance",
|
|
162
|
+
"trust",
|
|
163
|
+
"lifecycle",
|
|
164
|
+
"visibility",
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class ResolvedItem(TypedDict):
|
|
169
|
+
"""One item as a resolution returns it (container.md §4).
|
|
170
|
+
|
|
171
|
+
`shadowed_by` is a property of THIS resolution, not of the item: the same item is shadowed in
|
|
172
|
+
one chain and the winner in another. It is the id of the item that beat this one on its
|
|
173
|
+
`(kind, key)` pair, or `None` for the winner and for every item without a `key`. `layer` and
|
|
174
|
+
`layer_type` are here for the same reason — where this copy was found is not the item's own
|
|
175
|
+
business. `layer_type` is a `ContainerType` or a `RootType`, as `Node.type` is, and is the key
|
|
176
|
+
`SERVING_POLICY` is read by. Nothing here is ever persisted onto the `ContextItem`.
|
|
177
|
+
|
|
178
|
+
The item's trust status is deliberately NOT a key here. It has one home,
|
|
179
|
+
`item["trust"]["status"]`, and a `TrustStatus` restated on the envelope would be the same fact
|
|
180
|
+
in two places with no rule for which wins when they differ — the copy a resolver snapshots
|
|
181
|
+
before serialisation, and serves a quarantined item under. Read it from the item. The walking
|
|
182
|
+
skeleton's resolver does emit a `trust` key here; the 0.3 freeze removed it (container.md §4),
|
|
183
|
+
and Phase 1's resolver drops it.
|
|
184
|
+
|
|
185
|
+
The envelope AROUND this list (`{scope, chain, items, withheld}`) is deliberately not typed
|
|
186
|
+
here: `container.md` §4's `TODO(a1p)` on whether a silent refusal carries `withheld` is
|
|
187
|
+
`[OPEN->0.3]`, and typing the response would answer it by accident.
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
item: ContextItem
|
|
191
|
+
layer: str
|
|
192
|
+
layer_type: str
|
|
193
|
+
shadowed_by: str | None
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class BlobGrant(TypedDict):
|
|
197
|
+
"""Minted by TRUST, never by Store/Vault (F5). Store renders it; it decides nothing.
|
|
198
|
+
|
|
199
|
+
`sig` is an HMAC over the descriptor with a container key ([0.3 · 45]); the grant id is not the
|
|
200
|
+
bearer secret. Redeemed at the REST door, once, within `BLOB_GRANT_LIFETIME_SECONDS` (rest.md
|
|
201
|
+
§6).
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
sha256: str
|
|
205
|
+
item: str
|
|
206
|
+
token: str
|
|
207
|
+
expires_at: str
|
|
208
|
+
sig: str
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
#: rest.md §6 — a `BlobGrant`'s `expires_at` is its mint time plus this, and the first verified
|
|
212
|
+
#: redemption spends it. A fixed contract value, never a config key: the Chief on #165 item 1,
|
|
213
|
+
#: option (a), 2026-10-09. A leaked grant URL is dead after one pull or five minutes at most.
|
|
214
|
+
BLOB_GRANT_LIFETIME_SECONDS: int = 300
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# --- the audit chain (spec/contracts/events.md) ---------------------------------------------
|
|
218
|
+
|
|
219
|
+
Event = Literal[
|
|
220
|
+
"container.init",
|
|
221
|
+
"node.create",
|
|
222
|
+
"item.add",
|
|
223
|
+
"blob.put",
|
|
224
|
+
"context.fetch",
|
|
225
|
+
"blob.pull",
|
|
226
|
+
"item.move",
|
|
227
|
+
"gate.pass.silent",
|
|
228
|
+
"gate.propose",
|
|
229
|
+
"approval.promote",
|
|
230
|
+
"approval.execute",
|
|
231
|
+
"approval.deny",
|
|
232
|
+
"approval.stale",
|
|
233
|
+
"trust.quarantine",
|
|
234
|
+
"step_up",
|
|
235
|
+
"token.mint",
|
|
236
|
+
"token.revoke",
|
|
237
|
+
"item.tombstone",
|
|
238
|
+
"blob.grant",
|
|
239
|
+
"authz.login",
|
|
240
|
+
"authz.redeem",
|
|
241
|
+
"authz.refuse",
|
|
242
|
+
"authz.release",
|
|
243
|
+
"authz.reject",
|
|
244
|
+
"authz.render",
|
|
245
|
+
"authz.tally",
|
|
246
|
+
"authz.revoke_refuse",
|
|
247
|
+
"authz.grant",
|
|
248
|
+
"client.register",
|
|
249
|
+
"config.set",
|
|
250
|
+
"rest.tally",
|
|
251
|
+
"identity.grant",
|
|
252
|
+
"identity.revoke",
|
|
253
|
+
"gate.pass.confirmed",
|
|
254
|
+
"item.copy",
|
|
255
|
+
"identity.credential",
|
|
256
|
+
"upload.put",
|
|
257
|
+
"upload.discard",
|
|
258
|
+
]
|
|
259
|
+
#: An append whose event name is not here MUST be rejected. `approval.stale` is a TOCTOU refusal,
|
|
260
|
+
#: split from a human `approval.deny` (freeze item 39); `step_up` runs (the MVP tap, ahead of 2.2);
|
|
261
|
+
#: `blob.grant` runs with the REST door's grants (F5, rest.md §6). The eight `authz.*` names that
|
|
262
|
+
#: do not run and `client.register` are IN the vocabulary, so a validator built on this tuple
|
|
263
|
+
#: accepts them: decided at the 0.3 freeze
|
|
264
|
+
#: (authorization-server.md §12 rows (a), (b), (d)–(h), §11.9, §9.3 and §5;
|
|
265
|
+
#: [0.3 · 29, 31, 33, 36], #140, #144), with no AS in this tree to emit them; so is `config.set`
|
|
266
|
+
#: (container.md §8, [0.3 · 40]), with no config surface; and so is `rest.tally`, the REST door's
|
|
267
|
+
#: per-window tally (rest.md §2, the Chief on #165 items 2 and 3), with no REST door in this tree.
|
|
268
|
+
#: `config.set` runs since `egzoscore config set` and `egzoscore link` (contract v1.1);
|
|
269
|
+
#: `identity.grant` and `identity.revoke` are `identity.md` §4's, running with the grants they
|
|
270
|
+
#: record.
|
|
271
|
+
#: events.md §1 says the same thing from the contract's side.
|
|
272
|
+
EVENTS: tuple[Event, ...] = get_args(Event)
|
|
273
|
+
|
|
274
|
+
#: The only events an entry with `principal: none` may carry (events.md §2): the caller-less rows
|
|
275
|
+
#: (a), (b), (d), (e) and (h) of authorization-server.md §12.2, and the REST door's tally (rest.md
|
|
276
|
+
#: §2, #165). An append with `principal: none` under any other event MUST be rejected — a read or an
|
|
277
|
+
#: act is never unattributed. The converse binds too: an append under one of these six MUST carry
|
|
278
|
+
#: `principal: none` (events.md §2). [0.3 · 34]
|
|
279
|
+
PRINCIPAL_NONE_EVENTS: tuple[Event, ...] = (
|
|
280
|
+
"authz.login",
|
|
281
|
+
"authz.redeem",
|
|
282
|
+
"authz.refuse",
|
|
283
|
+
"authz.release",
|
|
284
|
+
"authz.tally",
|
|
285
|
+
"rest.tally",
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
#: Genesis `prev_hash`: 64 ASCII zeros.
|
|
289
|
+
GENESIS_HASH: str = "0" * 64
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class AuditEntry(TypedDict):
|
|
293
|
+
"""hash = sha256(prev_hash || canonical(entry minus `hash` and `seq`)).
|
|
294
|
+
|
|
295
|
+
`canonical` is contract, not implementation: sorted keys, no whitespace, non-ASCII preserved.
|
|
296
|
+
Never put a token value, a grant signature or blob bytes in `details`.
|
|
297
|
+
"""
|
|
298
|
+
|
|
299
|
+
seq: int
|
|
300
|
+
ts: str
|
|
301
|
+
event: Event
|
|
302
|
+
actor: str
|
|
303
|
+
principal: Principal # `none` only under PRINCIPAL_NONE_EVENTS (events.md §2)
|
|
304
|
+
subject: str | None
|
|
305
|
+
scope: str | None
|
|
306
|
+
details: dict[str, Any]
|
|
307
|
+
prev_hash: str
|
|
308
|
+
hash: str
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
# --- containers, the chain and the gate (spec/contracts/container.md) -----------------------
|
|
312
|
+
|
|
313
|
+
ContainerType = Literal["inbox", "thread", "project", "team", "org", "exo", "uxo", "global"]
|
|
314
|
+
#: Declaration order IS ring rank. `enterprise` is omitted from the vocabulary (v0.5 §A); `uxo`
|
|
315
|
+
#: keeps rank 6 and is never instantiated (R11), so the ranks around it stay stable.
|
|
316
|
+
CONTAINER_TYPES: tuple[ContainerType, ...] = get_args(ContainerType)
|
|
317
|
+
#: An ATTRIBUTE — UI order and the gate's outward test — never the resolution order (container.md
|
|
318
|
+
#: §1). The chain is the tree walk, and its ranks need not be monotonic.
|
|
319
|
+
RING_RANK: dict[ContainerType, int] = {t: i for i, t in enumerate(CONTAINER_TYPES)}
|
|
320
|
+
|
|
321
|
+
RootType = Literal["user", "global"]
|
|
322
|
+
#: Tree roots. `user` is the personal tree (`user:self`) and is NOT a ring: it has no entry in
|
|
323
|
+
#: RING_RANK and still rides along in every chain (container.md §2).
|
|
324
|
+
ROOT_TYPES: tuple[RootType, ...] = get_args(RootType)
|
|
325
|
+
|
|
326
|
+
ServingPolicy = Literal["serve-unverified", "verified-only"]
|
|
327
|
+
#: Keyed by container type AND by the `user` root (F4). A type absent from this mapping MUST be
|
|
328
|
+
#: treated as `verified-only`: the lookup fails closed, so a forgotten entry withholds, never leaks.
|
|
329
|
+
SERVING_POLICY: dict[str, ServingPolicy] = {
|
|
330
|
+
"inbox": "serve-unverified",
|
|
331
|
+
"thread": "serve-unverified",
|
|
332
|
+
"project": "serve-unverified",
|
|
333
|
+
"team": "verified-only",
|
|
334
|
+
"org": "verified-only",
|
|
335
|
+
"exo": "verified-only",
|
|
336
|
+
"uxo": "verified-only",
|
|
337
|
+
"global": "verified-only",
|
|
338
|
+
"user": "verified-only", # F4 — the personal root rides along everywhere: reach → verification
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
class Node(TypedDict):
|
|
343
|
+
"""A container. `parent` is the ONLY location state; the path is computed from it, so moving a
|
|
344
|
+
node is a metadata update (v0.4 §16). `type` is a `ContainerType` or a `RootType`.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
id: str
|
|
348
|
+
type: str
|
|
349
|
+
name: str
|
|
350
|
+
parent: str | None
|
|
351
|
+
created_at: str
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class AudienceMember(TypedDict):
|
|
355
|
+
"""One live token whose coverage reaches a node — people AND agents, never a count."""
|
|
356
|
+
|
|
357
|
+
token: str
|
|
358
|
+
owner: str
|
|
359
|
+
client: str
|
|
360
|
+
principal: TokenPrincipal
|
|
361
|
+
role: Role
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
ProposalStatus = Literal["open", "executed", "denied", "stale"]
|
|
365
|
+
#: `stale` is written when approval recomputes the manifest and it no longer matches — the TOCTOU
|
|
366
|
+
#: close is contract, not an implementation detail (container.md §6).
|
|
367
|
+
PROPOSAL_STATUSES: tuple[ProposalStatus, ...] = get_args(ProposalStatus)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
class Proposal(TypedDict):
|
|
371
|
+
"""A move parked at the gate: nonzero audience delta, awaiting a human-only confirm. `manifest`
|
|
372
|
+
binds the approval to `{items, target, audience}`; `execute` recomputes it and refuses on
|
|
373
|
+
mismatch. `approved_by`/`executed_at` appear only once executed.
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
id: str
|
|
377
|
+
status: ProposalStatus
|
|
378
|
+
kind: Literal["move"]
|
|
379
|
+
items: list[str]
|
|
380
|
+
from_: str
|
|
381
|
+
to: str
|
|
382
|
+
from_path: str
|
|
383
|
+
to_path: str
|
|
384
|
+
audience: list[AudienceMember]
|
|
385
|
+
audience_delta: list[AudienceMember]
|
|
386
|
+
blast_radius: int
|
|
387
|
+
manifest: str
|
|
388
|
+
proposed_by: dict[str, Any]
|
|
389
|
+
reason: str
|
|
390
|
+
created_at: str
|
|
391
|
+
executed_at: NotRequired[str]
|
|
392
|
+
approved_by: NotRequired[str]
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
#: The wire key is `from`, which is a Python keyword; `Proposal` spells it `from_` and every
|
|
396
|
+
#: (de)serializer MUST map the two. Named here so no implementation invents a third spelling.
|
|
397
|
+
PROPOSAL_WIRE_KEY_FROM: str = "from"
|
|
398
|
+
|
|
399
|
+
StructureFloor = Literal["thread", "project", "team", "org", "exo"]
|
|
400
|
+
#: F2: a per-node scope-policy floor, NOT a seventh capability. Creating a container strictly above
|
|
401
|
+
#: the floor by ring rank, at that parent, needs `admin`. Keeps the vocabulary six wide.
|
|
402
|
+
STRUCTURE_FLOORS: tuple[StructureFloor, ...] = get_args(StructureFloor)
|
|
403
|
+
|
|
404
|
+
PersonalRootMode = Literal["between", "sovereign"]
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
class ContainerConfig(TypedDict):
|
|
408
|
+
"""The one config object F1, F2, F5 and R11 each needed (container.md §8).
|
|
409
|
+
|
|
410
|
+
*Decided, not running* — the skeleton has no config surface and every value below is a constant
|
|
411
|
+
in `model.py`. `CONTAINER_CONFIG_DEFAULTS` is exactly what it runs, so the shipped default and
|
|
412
|
+
the observed behaviour are the same thing.
|
|
413
|
+
"""
|
|
414
|
+
|
|
415
|
+
#: F1 — `sovereign` puts the personal root before the org ancestors. Per container.
|
|
416
|
+
chain_personal_root: PersonalRootMode
|
|
417
|
+
#: F1 — an org forbids the inversion inside its own subtree. Per org node.
|
|
418
|
+
org_policy_sovereign_chain: Literal["allow", "deny"]
|
|
419
|
+
#: F2 — per node, inherited by the subtree.
|
|
420
|
+
node_policy_structure_floor: StructureFloor
|
|
421
|
+
#: F5 — at or below this, and `text/*` only, a fetch carries the bytes inline.
|
|
422
|
+
blobs_inline_max_bytes: int
|
|
423
|
+
#: R11 — staged blobs: 30 days cold, then purge.
|
|
424
|
+
blobs_staging_retention_days: int
|
|
425
|
+
#: R11 — per source→destination ring pair, manifest-shape bounded, org-configurable to ZERO.
|
|
426
|
+
step_up_window_seconds: int
|
|
427
|
+
#: identity.md §2 — the issuer URL; absent, no provider (the container's own `Token` only).
|
|
428
|
+
identity_issuer: str | None
|
|
429
|
+
#: identity.md §2 — this container's own OAuth client at the provider (§3a).
|
|
430
|
+
identity_client_id: str | None
|
|
431
|
+
#: identity.md §2 — the `aud` an access token must carry.
|
|
432
|
+
identity_audience: str
|
|
433
|
+
#: identity.md §2 — the signing algorithms accepted, space-separated; never `none` or `HS*`.
|
|
434
|
+
identity_algorithms: str
|
|
435
|
+
#: identity.md §2 — the origins the REST door answers CORS for (§6), space-separated.
|
|
436
|
+
identity_browser_origins: str
|
|
437
|
+
#: identity.md §2 — the origin clients reach the container at; absent, the one `serve` binds.
|
|
438
|
+
identity_origin: str | None
|
|
439
|
+
#: identity.md §2, §5 — whether the confirm accepts the button proof; `false`: biometric only.
|
|
440
|
+
confirm_allow_button: bool
|
|
441
|
+
#: rest.md §4.4 — the largest artifact one upload may carry, in bytes.
|
|
442
|
+
blobs_upload_max_bytes: int
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
CONTAINER_CONFIG_DEFAULTS: ContainerConfig = {
|
|
446
|
+
"chain_personal_root": "between",
|
|
447
|
+
"org_policy_sovereign_chain": "allow", # Chief decision [0.3 · 4], container.md §8
|
|
448
|
+
"node_policy_structure_floor": "project",
|
|
449
|
+
"blobs_inline_max_bytes": 64 * 1024,
|
|
450
|
+
"blobs_staging_retention_days": 30,
|
|
451
|
+
"step_up_window_seconds": 300,
|
|
452
|
+
"identity_issuer": None,
|
|
453
|
+
"identity_client_id": None,
|
|
454
|
+
"identity_audience": "authenticated",
|
|
455
|
+
"identity_algorithms": "ES256 RS256",
|
|
456
|
+
"identity_browser_origins": "https://egzos.io",
|
|
457
|
+
"identity_origin": None,
|
|
458
|
+
"confirm_allow_button": True,
|
|
459
|
+
"blobs_upload_max_bytes": 100 * 1024 * 1024,
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
#: Wire key -> `ContainerConfig` field. **The dotted names are canonical** (container.md §8): they
|
|
463
|
+
#: are what a config file and the wire carry, and no other spelling of them is a key.
|
|
464
|
+
#: `ContainerConfig` underscores them only because a dotted name is not a Python identifier — the
|
|
465
|
+
#: same situation as the wire's `from` against `Proposal.from_`, named by `PROPOSAL_WIRE_KEY_FROM`.
|
|
466
|
+
#:
|
|
467
|
+
#: A loader that does not consult this mapping does not read §8's keys at all: it silently ignores
|
|
468
|
+
#: every one of them and serves `CONTAINER_CONFIG_DEFAULTS`. That is the failure this constant
|
|
469
|
+
#: exists to prevent — an org that sets `step_up.window_seconds` to `0` gets `0`, not the 300 it
|
|
470
|
+
#: refused.
|
|
471
|
+
#:
|
|
472
|
+
#: Loading rule, from the same clause: **absence is tested by absence, never by truthiness.** `0`,
|
|
473
|
+
#: `""` and `False` are values. `cfg.get(wire_key) or default` is wrong for every row below and
|
|
474
|
+
#: silently wrong for the one row where it matters most.
|
|
475
|
+
CONTAINER_CONFIG_FIELD_FROM_WIRE_KEY: dict[str, str] = {
|
|
476
|
+
"chain.personal_root": "chain_personal_root",
|
|
477
|
+
"org.policy.sovereign_chain": "org_policy_sovereign_chain",
|
|
478
|
+
"node.policy.structure_floor": "node_policy_structure_floor",
|
|
479
|
+
"blobs.inline_max_bytes": "blobs_inline_max_bytes",
|
|
480
|
+
"blobs.staging_retention_days": "blobs_staging_retention_days",
|
|
481
|
+
"step_up.window_seconds": "step_up_window_seconds",
|
|
482
|
+
"identity.issuer": "identity_issuer",
|
|
483
|
+
"identity.client_id": "identity_client_id",
|
|
484
|
+
"identity.audience": "identity_audience",
|
|
485
|
+
"identity.algorithms": "identity_algorithms",
|
|
486
|
+
"identity.browser_origins": "identity_browser_origins",
|
|
487
|
+
"identity.origin": "identity_origin",
|
|
488
|
+
"confirm.allow_button": "confirm_allow_button",
|
|
489
|
+
"blobs.upload_max_bytes": "blobs_upload_max_bytes",
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
# --- what the retired authorization server left (authorization-server.md, identity.md §9) -------
|
|
494
|
+
#
|
|
495
|
+
# The AS is retired and its code removed (identity.md §9). What stays is what a living contract
|
|
496
|
+
# still names: the throttle vocabulary and rates the REST door runs on (rest.md §2 item 7), and the
|
|
497
|
+
# closed cause and decision vocabularies `events.md` §1 cites for its `authz.*` rows. The AS-only
|
|
498
|
+
# shapes (client registrations, metadata, codes, sessions, user codes, lifetimes) went with it.
|
|
499
|
+
|
|
500
|
+
#: §12.1 rule 5 — the closed `surface` vocabulary a throttle-release entry carries, and (§12.2)
|
|
501
|
+
#: a1p's reading of what `actor` carries on every pre-authorization append, as a `Literal` alias
|
|
502
|
+
#: read back with `get_args`, matching the pattern `Capability`/`CAPABILITIES` and
|
|
503
|
+
#: `Principal`/`PRINCIPALS` already use above: a typo at a call site that writes `details.surface`
|
|
504
|
+
#: is a type error, not a string `str` would accept silently. `tap` is the step-up tap's page,
|
|
505
|
+
#: throttled unconditionally by `consent.md`'s D-C6 rather than by this contract; if §10.5's
|
|
506
|
+
#: `[LEAN]` is not taken the tap rides a channel of its own instead of these AS endpoints, but the
|
|
507
|
+
#: word is still used there — D-C6's release entry is `consent.md` §14.8 (e), the same event this
|
|
508
|
+
#: vocabulary pins, and the tap spec §14.5 binds to it by citing the decision rather than restating
|
|
509
|
+
#: it in an entry of its own — never unused, only ridden elsewhere. `revoke` is §11.9's page
|
|
510
|
+
#: (decided at §9.2), the fifth word ([0.3 · 11]). `rest` is the REST door's, the sixth: one surface
|
|
511
|
+
#: covering the sweep at its 401 and descriptor redemption (rest.md §2, the Chief on #165 item 3).
|
|
512
|
+
#: The caller's network identifier is NEVER the actor ([0.3 · 34]): a network identifier may key a
|
|
513
|
+
#: throttle bucket (§11.0, [0.3 · 24]) and never enters the chain. The event NAMES these entries
|
|
514
|
+
#: append under are `Event`'s `authz.*` members (§12, [0.3 · 33]), and `rest.tally` for the REST
|
|
515
|
+
#: door's per-window tally.
|
|
516
|
+
ThrottleSurface = Literal["login", "device", "authorize", "tap", "revoke", "rest"]
|
|
517
|
+
AS_THROTTLE_SURFACES: tuple[ThrottleSurface, ...] = get_args(ThrottleSurface)
|
|
518
|
+
|
|
519
|
+
#: §11.0 and rest.md §2 item 7 (#141): every surface counts over one fixed window, and a bucket that
|
|
520
|
+
#: engages holds until its window closes. Decided by the Chief on #141, 2026-10-09.
|
|
521
|
+
AS_THROTTLE_WINDOW_SECONDS: int = 300
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
class ThrottleRate(NamedTuple):
|
|
525
|
+
"""§11.0's two buckets, both enforced: counted attempts admitted per window."""
|
|
526
|
+
|
|
527
|
+
container_global: int
|
|
528
|
+
per_source: int # keyed on the transport source address, never on a caller-supplied value
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
#: §11.0's rate table, all six decided: `rest` by the Chief on #141, the five AS surfaces as a1p
|
|
532
|
+
#: proposed them, confirmed by the Chief on #184 (2026-10-09), tightest on `login` and `device`.
|
|
533
|
+
#: rest.md §2 item 7's per-token bucket is not here: its rate is open on #141. Read-only, so no
|
|
534
|
+
#: caller can loosen a bound at runtime.
|
|
535
|
+
AS_THROTTLE_RATES: Mapping[ThrottleSurface, ThrottleRate] = MappingProxyType(
|
|
536
|
+
{
|
|
537
|
+
"login": ThrottleRate(container_global=30, per_source=5),
|
|
538
|
+
"device": ThrottleRate(container_global=30, per_source=5),
|
|
539
|
+
"authorize": ThrottleRate(container_global=300, per_source=30),
|
|
540
|
+
"tap": ThrottleRate(container_global=60, per_source=10),
|
|
541
|
+
"revoke": ThrottleRate(container_global=120, per_source=20),
|
|
542
|
+
"rest": ThrottleRate(container_global=300, per_source=30),
|
|
543
|
+
}
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
#: §12's table, rows (a), (b), (d) and (f) — the closed `details.cause` vocabulary each pre-token
|
|
547
|
+
#: effect appends under, as `Literal` aliases read back with `get_args`, matching the pattern
|
|
548
|
+
#: `Capability`/`CAPABILITIES` and `Principal`/`PRINCIPALS` already use above: a typo at a call site
|
|
549
|
+
#: that writes `details.cause` is a type error, not a string `str` would accept silently. Row (d)'s
|
|
550
|
+
#: `token_presented` is this Part's own addition over `consent.md` §14.8 (d)'s six — named as the
|
|
551
|
+
#: addition it is at row (d) itself, not silently absorbed into the tuple. Row (f)'s two, not three:
|
|
552
|
+
#: `expiry` is not a cause here, because §11.5 clamps an over-long expiry rather than ever rejecting
|
|
553
|
+
#: it for that reason alone (row (f)'s own paragraph). These four are closed; the event *names*
|
|
554
|
+
#: these causes travel under are §12's ([0.3 · 33]): `authz.login`, `authz.redeem`, `authz.refuse`
|
|
555
|
+
#: and `authz.reject` in `Event`.
|
|
556
|
+
LoginCause = Literal["wrong", "unknown", "throttled"]
|
|
557
|
+
AS_LOGIN_CAUSES: tuple[LoginCause, ...] = get_args(LoginCause)
|
|
558
|
+
|
|
559
|
+
DeviceRedemptionCause = Literal["invalid", "expired", "used", "malformed", "throttled"]
|
|
560
|
+
AS_DEVICE_REDEMPTION_CAUSES: tuple[DeviceRedemptionCause, ...] = get_args(DeviceRedemptionCause)
|
|
561
|
+
|
|
562
|
+
AuthorizePretrustCause = Literal[
|
|
563
|
+
"unknown_client",
|
|
564
|
+
"redirect_mismatch",
|
|
565
|
+
"malformed",
|
|
566
|
+
"missing_pkce",
|
|
567
|
+
"throttled",
|
|
568
|
+
"replayed",
|
|
569
|
+
"token_presented",
|
|
570
|
+
]
|
|
571
|
+
AS_AUTHORIZE_PRETRUST_CAUSES: tuple[AuthorizePretrustCause, ...] = get_args(AuthorizePretrustCause)
|
|
572
|
+
|
|
573
|
+
AuthorizePosttrustCause = Literal["vocabulary", "scope"]
|
|
574
|
+
AS_AUTHORIZE_POSTTRUST_CAUSES: tuple[AuthorizePosttrustCause, ...] = get_args(
|
|
575
|
+
AuthorizePosttrustCause
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
#: §11.9 item 3 — the closed `details.cause` of `authz.revoke_refuse`, the owner-path revoke
|
|
579
|
+
#: refusal (#144, a1p). `unknown`: no token has that id; `unreachable`: one exists and the session
|
|
580
|
+
#: may not reach it; `throttled`: the attempt that engages the `revoke` throttle (§12.1 rule 3).
|
|
581
|
+
#: Both of the first two get the same response (§7.1); the cause is the owner's ledger's, never
|
|
582
|
+
#: the page's.
|
|
583
|
+
RevokeRefusalCause = Literal["unknown", "unreachable", "throttled"]
|
|
584
|
+
AS_REVOKE_REFUSAL_CAUSES: tuple[RevokeRefusalCause, ...] = get_args(RevokeRefusalCause)
|
|
585
|
+
|
|
586
|
+
#: §9.3 — `authz.grant`'s closed `details.decision` ([0.3 · 29]). One event with two outcomes, not
|
|
587
|
+
#: an `authz.grant`/`authz.deny` pair: the halves carry identical fields and differ only in outcome.
|
|
588
|
+
GrantDecision = Literal["granted", "denied"]
|
|
589
|
+
AS_GRANT_DECISIONS: tuple[GrantDecision, ...] = get_args(GrantDecision)
|
|
590
|
+
|
|
591
|
+
#: §5 — `client.register`'s closed `details.op` ([0.3 · 31]). `redirect_uris` beside it is the
|
|
592
|
+
#: allowlist AFTER the change, empty on `remove`.
|
|
593
|
+
ClientRegisterOp = Literal["add", "amend", "remove"]
|
|
594
|
+
AS_CLIENT_REGISTER_OPS: tuple[ClientRegisterOp, ...] = get_args(ClientRegisterOp)
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
# --- the storage boundary (spec/contracts/storage.md) ---------------------------------------
|
|
598
|
+
#
|
|
599
|
+
# F3 splits the skeleton's ONE wide `Backend` Protocol into `ItemStore` (pluggable, delegable) and
|
|
600
|
+
# `ContainerState` (never delegated); `BlobStore` was already separate. The METHODS below are
|
|
601
|
+
# verbatim from the running code; the PARTITION is decided, not running. `audit_append` sits in
|
|
602
|
+
# `ContainerState` so the chain's integrity never depends on whoever wrote the backend — this
|
|
603
|
+
# amends v0.4 §11. See storage.md §1.
|
|
604
|
+
#
|
|
605
|
+
# These Protocols stay HERE when Phase 5 moves the implementations to Vault (R5): the seam is the
|
|
606
|
+
# type, and the type sits above both modules, so Store/Trust/Ledger never import Vault for a name.
|
|
607
|
+
|
|
608
|
+
# `Node` and `Proposal` are defined above, with `container.md`. `storage.md` §3's signatures were
|
|
609
|
+
# final before their referents existed and carried provisional `dict[str, Any]` aliases; issue #28
|
|
610
|
+
# replaces the aliases, and no signature below changed.
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
class ItemStore(Protocol):
|
|
614
|
+
"""Pluggable and delegable: sqlite -> postgres+pgvector -> mem0/zep.
|
|
615
|
+
|
|
616
|
+
A filter, never a decision. The backend returns CANDIDATES; the resolver applies precedence,
|
|
617
|
+
trust and key-override above it (v0.4 §11). Every getter returns `None`/a shorter list for
|
|
618
|
+
absent, tombstoned and out-of-coverage alike — a distinguishable "exists but forbidden" is
|
|
619
|
+
enumeration by another name (storage.md §5).
|
|
620
|
+
"""
|
|
621
|
+
|
|
622
|
+
def put(self, item: ContextItem) -> None: ...
|
|
623
|
+
def get(self, item_id: str) -> ContextItem | None: ...
|
|
624
|
+
def query(
|
|
625
|
+
self,
|
|
626
|
+
scopes: Iterable[str],
|
|
627
|
+
*,
|
|
628
|
+
kinds: Iterable[Kind] | None = None,
|
|
629
|
+
key: str | None = None,
|
|
630
|
+
statuses: Iterable[TrustStatus] | None = None,
|
|
631
|
+
text: str | None = None,
|
|
632
|
+
include_tombstoned: bool = False,
|
|
633
|
+
) -> list[ContextItem]: ...
|
|
634
|
+
def tombstone(self, item_id: str) -> bool: ...
|
|
635
|
+
#: ^ internal to this boundary. No surface may reflect it to an external caller.
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
class ContainerState(Protocol):
|
|
639
|
+
"""The container's own state: nodes, tokens, proposals and the audit chain.
|
|
640
|
+
|
|
641
|
+
sqlite by default, postgres at Phase 5, **never delegated to a third-party store** (F3).
|
|
642
|
+
"""
|
|
643
|
+
|
|
644
|
+
# nodes
|
|
645
|
+
def put_node(self, node: Node) -> None: ...
|
|
646
|
+
def get_node(self, node_id: str) -> Node | None: ...
|
|
647
|
+
def list_nodes(self, parent: str | None = None, type: str | None = None) -> list[Node]: ...
|
|
648
|
+
def find_root(self, type: str) -> Node | None: ...
|
|
649
|
+
|
|
650
|
+
# tokens
|
|
651
|
+
def put_token(self, token: Token) -> None: ...
|
|
652
|
+
def get_token(self, token_id: str) -> Token | None: ...
|
|
653
|
+
def list_tokens(self) -> list[Token]: ...
|
|
654
|
+
|
|
655
|
+
# pending proposals (cross-audience moves, staged artifacts)
|
|
656
|
+
def put_proposal(self, proposal: Proposal) -> None: ...
|
|
657
|
+
def get_proposal(self, proposal_id: str) -> Proposal | None: ...
|
|
658
|
+
def list_proposals(self, status: str | None = None) -> list[Proposal]: ...
|
|
659
|
+
|
|
660
|
+
# audit chain — append-only; the LEDGER computes the chain, the store only appends
|
|
661
|
+
def audit_append(self, entry: AuditEntry) -> AuditEntry: ...
|
|
662
|
+
#: ^ the input carries no `seq`: the store assigns it, returns the stored entry (events.md §3),
|
|
663
|
+
#: and raises `ChainConflict` when an entry already follows its `prev_hash` (storage.md §3.6)
|
|
664
|
+
def audit_last(self) -> AuditEntry | None: ...
|
|
665
|
+
def audit_iter(self) -> Iterator[AuditEntry]: ...
|
|
666
|
+
def audit_tail(self, n: int) -> list[AuditEntry]: ...
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
class BlobStore(Protocol):
|
|
670
|
+
"""Content-addressed bytes over `sha256/<hash>`, staged under `staging/<hash>`.
|
|
671
|
+
|
|
672
|
+
Issues NOTHING. Trust mints a `BlobGrant`; Store/Vault renders it and decides nothing (F5) —
|
|
673
|
+
signed-URL issuance passes Trust's capability check, because artifact download IS fetch. The
|
|
674
|
+
mint (`blob.grant`) and the redemption (`blob.pull`) are two separate audit events.
|
|
675
|
+
|
|
676
|
+
The staging prefix is invisible to resolution: `get`/`exists` address `sha256/<hash>` ONLY, and
|
|
677
|
+
no flag or alternate method reads `staging/`. A staged blob is unaddressable until `promote`.
|
|
678
|
+
|
|
679
|
+
Moves to Vault whole at Phase 5 (R5) — no back-reference into nodes, resolver or items, and
|
|
680
|
+
addressing is by `sha256` alone.
|
|
681
|
+
"""
|
|
682
|
+
|
|
683
|
+
def put(self, data: bytes) -> str: ...
|
|
684
|
+
def stage(self, data: bytes) -> str: ...
|
|
685
|
+
def promote(self, sha: str) -> bool: ...
|
|
686
|
+
#: ^ True if staged bytes moved, False if nothing was staged there. Internal caller only
|
|
687
|
+
#: ([0.3 · 43]): the result never crosses an external boundary.
|
|
688
|
+
def get(self, sha: str) -> bytes | None: ...
|
|
689
|
+
def exists(self, sha: str) -> bool: ...
|
|
690
|
+
#: ^ an existence oracle over guessable addresses: never reachable from an external path.
|
|
691
|
+
def discard(self, sha: str) -> bool: ...
|
|
692
|
+
#: ^ deletes STAGED bytes only, never promoted ones ([0.3 · 44]); True if there were any.
|
|
693
|
+
#: Internal: rest.md §4.4's discard of an orphan and a staged item's tombstone.
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
#: The two contracts F3 split out of the skeleton's union, and the third seam that was already
|
|
697
|
+
#: separate. Ordered as storage.md §1 lists them.
|
|
698
|
+
STORAGE_CONTRACTS: tuple[str, ...] = ("ItemStore", "ContainerState", "BlobStore")
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
# --- the door's throttle state (storage.md §3.1) --------------------------------------------
|
|
702
|
+
#
|
|
703
|
+
# The retired authorization server's `ASState` and `ASGateState` are gone (identity.md §9). Their
|
|
704
|
+
# throttle counters stay, because the REST door runs on them (rest.md §2 item 7): durable container
|
|
705
|
+
# state on the `ContainerState` substrate, never process memory (the Chief on #173, option (A)).
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
class ThrottleState(Protocol):
|
|
709
|
+
"""The door's throttle counters (rest.md §2 item 7). No rate and no window length here: those
|
|
710
|
+
are `AS_THROTTLE_RATES` and `AS_THROTTLE_WINDOW_SECONDS`, read by the door; the three keys are
|
|
711
|
+
opaque to the store."""
|
|
712
|
+
|
|
713
|
+
def throttle_incr(self, surface: ThrottleSurface, bucket_key: str, window_key: str) -> int: ...
|
|
714
|
+
#: ^ increments and returns the new count, atomically
|
|
715
|
+
def throttle_count(self, surface: ThrottleSurface, bucket_key: str, window_key: str) -> int: ...
|
|
716
|
+
def throttle_buckets(
|
|
717
|
+
self, surface: ThrottleSurface, window_key: str
|
|
718
|
+
) -> list[tuple[str, int]]: ...
|
|
719
|
+
#: ^ every bucket counted in one window, with its count: what a window's close reads
|
|
720
|
+
def throttle_windows(self, surface: ThrottleSurface) -> list[str]: ...
|
|
721
|
+
#: ^ every window with a counter on this surface
|
|
722
|
+
def throttle_forget(self, surface: ThrottleSurface, window_key: str) -> None: ...
|
|
723
|
+
#: ^ drops one window's counters: a closed window's, once its release and tally are appended
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
# --- who may call the container, and its settings (storage.md §3.2) -------------------------
|
|
727
|
+
#
|
|
728
|
+
# identity.md §4's two records and container.md §8's settings, durable container state on the
|
|
729
|
+
# `ContainerState` substrate and never delegated (F3), like the throttle above.
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
class UserGrant(TypedDict):
|
|
733
|
+
"""identity.md §4: what a provider user may do here. `sub` is the provider's user id."""
|
|
734
|
+
|
|
735
|
+
sub: str
|
|
736
|
+
name: str # rest.md §4.3's display name; untrusted display data
|
|
737
|
+
capabilities: list[Capability]
|
|
738
|
+
scopes: list[str]
|
|
739
|
+
created_at: str
|
|
740
|
+
revoked: bool
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
#: identity.md §4: the two kinds of registration, told apart by `kind`.
|
|
744
|
+
RegistrationKind = Literal["agent", "terminal"]
|
|
745
|
+
REGISTRATION_KINDS: tuple[RegistrationKind, ...] = get_args(RegistrationKind)
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
class AgentRegistration(TypedDict):
|
|
749
|
+
"""identity.md §4: an agent's OAuth client, admitted here for the one user it serves. A
|
|
750
|
+
record kept before terminals were registered carries no `kind`, and is an agent's
|
|
751
|
+
(storage.md §3.2)."""
|
|
752
|
+
|
|
753
|
+
client_id: str
|
|
754
|
+
sub: str
|
|
755
|
+
kind: NotRequired[Literal["agent"]]
|
|
756
|
+
name: str
|
|
757
|
+
capabilities: list[Capability]
|
|
758
|
+
scopes: list[str]
|
|
759
|
+
created_at: str
|
|
760
|
+
revoked: bool
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
class TerminalRegistration(TypedDict):
|
|
764
|
+
"""identity.md §4: a terminal's own OAuth client, the person it serves at that terminal. It
|
|
765
|
+
holds no capabilities or scopes: its token holds its person's grant as it stands."""
|
|
766
|
+
|
|
767
|
+
client_id: str
|
|
768
|
+
sub: str
|
|
769
|
+
kind: Literal["terminal"]
|
|
770
|
+
name: str # the terminal's own claim; untrusted display data
|
|
771
|
+
created_at: str
|
|
772
|
+
revoked: bool
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
#: Either registration, as storage.md §3.2's three methods take and return it.
|
|
776
|
+
Registration = AgentRegistration | TerminalRegistration
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
class IdentityState(Protocol):
|
|
780
|
+
"""identity.md §4's grants and registrations. The getters return revoked records too: the
|
|
781
|
+
caller judges liveness, and a revoked record is kept so its history reads back. The three
|
|
782
|
+
registration methods keep both kinds under one key; a caller that wants one kind filters on
|
|
783
|
+
`kind` (storage.md §3.2)."""
|
|
784
|
+
|
|
785
|
+
def put_user_grant(self, grant: UserGrant) -> None: ...
|
|
786
|
+
#: ^ insert or replace, keyed on `sub`
|
|
787
|
+
def get_user_grant(self, sub: str) -> UserGrant | None: ...
|
|
788
|
+
def list_user_grants(self) -> list[UserGrant]: ...
|
|
789
|
+
def put_agent_registration(self, registration: Registration) -> None: ...
|
|
790
|
+
#: ^ insert or replace, keyed on `(client_id, sub)`
|
|
791
|
+
def get_agent_registration(self, client_id: str, sub: str) -> Registration | None: ...
|
|
792
|
+
def list_agent_registrations(self, client_id: str | None = None) -> list[Registration]: ...
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
class ConfigState(Protocol):
|
|
796
|
+
"""container.md §8's object as set: wire key -> value. A key never set is absent, and the
|
|
797
|
+
reader serves `CONTAINER_CONFIG_DEFAULTS` for it (absence by absence, never by truthiness)."""
|
|
798
|
+
|
|
799
|
+
def get_config(self) -> dict[str, Any]: ...
|
|
800
|
+
def put_config(self, key: str, value: Any) -> None: ...
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
class ConfirmChallenge(TypedDict):
|
|
804
|
+
"""rest.md §4.2: a challenge the confirm's first leg issued, bound to that one request."""
|
|
805
|
+
|
|
806
|
+
id: str
|
|
807
|
+
principal: str # the `Token.id` the first leg answered (a grant's is `user:<sub>`, …)
|
|
808
|
+
act: str # `move`, `copy`, `approve`, `deny`, `promote`
|
|
809
|
+
subject: str # the item or proposal
|
|
810
|
+
destination: str | None # the scope a move or copy lands in
|
|
811
|
+
delta: list[str] # the audience members who would newly see it, sorted
|
|
812
|
+
expires_at: str
|
|
813
|
+
spent: NotRequired[bool]
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
class ConfirmCredential(TypedDict):
|
|
817
|
+
"""identity.md §5: a WebAuthn credential a person registered for the confirm. Public: the key
|
|
818
|
+
verifies an assertion and proves nothing by itself. Never served (rest.md §4.3's shape omits
|
|
819
|
+
the key and the credential id)."""
|
|
820
|
+
|
|
821
|
+
id: str # this container's id for it
|
|
822
|
+
person: str # the interactive principal's owner: `user:<sub>`, or the owner token's
|
|
823
|
+
credential_id: str # base64url, as the authenticator names it
|
|
824
|
+
public_key: str # base64url COSE key
|
|
825
|
+
sign_count: int
|
|
826
|
+
rp_id: str # the relying party it was created for: the browser origin's host
|
|
827
|
+
name: str # display data the person chose
|
|
828
|
+
created_at: str
|
|
829
|
+
last_used: str | None
|
|
830
|
+
removed: bool
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
class ConfirmState(Protocol):
|
|
834
|
+
"""rest.md §4.2's challenges and §4.3's credentials, on the `ContainerState` substrate
|
|
835
|
+
(storage.md §3.3)."""
|
|
836
|
+
|
|
837
|
+
def put_challenge(self, challenge: ConfirmChallenge) -> None: ...
|
|
838
|
+
def spend_challenge(self, challenge_id: str) -> ConfirmChallenge | None: ...
|
|
839
|
+
#: ^ marks it spent and returns it AS IT STOOD, atomically: of two concurrent spends of one
|
|
840
|
+
#: challenge, exactly one sees `spent` false. `None` for an id never issued.
|
|
841
|
+
def forget_challenges(self, expired_before: str) -> None: ...
|
|
842
|
+
#: ^ drops every challenge that expired before this time, spent or not
|
|
843
|
+
def put_credential(self, credential: ConfirmCredential) -> None: ...
|
|
844
|
+
#: ^ insert or replace, keyed on `id`
|
|
845
|
+
def get_credential(self, credential_id: str) -> ConfirmCredential | None: ...
|
|
846
|
+
def list_credentials(self, person: str | None = None) -> list[ConfirmCredential]: ...
|
|
847
|
+
#: ^ every credential the person registered (everyone's, with no person), removed ones
|
|
848
|
+
#: included; the caller judges
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
class UploadRecord(TypedDict):
|
|
852
|
+
"""rest.md §4.4: one artifact upload, from its open to its item or its discard."""
|
|
853
|
+
|
|
854
|
+
id: str
|
|
855
|
+
principal: str # the `Token.id` that opened it: its bytes and its item are that caller's alone
|
|
856
|
+
actor: str
|
|
857
|
+
scope: str
|
|
858
|
+
name: str # untrusted display data
|
|
859
|
+
mime: str
|
|
860
|
+
size: int
|
|
861
|
+
sha256: str
|
|
862
|
+
opened_at: str
|
|
863
|
+
expires_at: str
|
|
864
|
+
staged: bool # its bytes are staged (the `PUT` spent)
|
|
865
|
+
item: str | None # the item written from it (the item step spent)
|
|
866
|
+
promoted: bool # its item's bytes were promoted at once: a person's (§4.4 item 3)
|
|
867
|
+
discarded: bool
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
class UploadState(Protocol):
|
|
871
|
+
"""rest.md §4.4's uploads (storage.md §3.4)."""
|
|
872
|
+
|
|
873
|
+
def put_upload(self, upload: UploadRecord) -> None: ...
|
|
874
|
+
def get_upload(self, upload_id: str) -> UploadRecord | None: ...
|
|
875
|
+
def list_uploads(self, principal: str | None = None) -> list[UploadRecord]: ...
|
|
876
|
+
def spend_upload(self, upload_id: str, step: str) -> bool: ...
|
|
877
|
+
#: ^ `step` is `bytes` or `item`: marks it, atomically, and is True only for the call that
|
|
878
|
+
#: found it unmarked, so of two concurrent spends of one step exactly one proceeds. The
|
|
879
|
+
#: caller writes the outcome (`staged`, `item`) with `put_upload` in the same transaction.
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
class GrantState(Protocol):
|
|
883
|
+
"""rest.md §6's spent grants (storage.md §3.5), keyed on the sha256 of a descriptor's `sig`,
|
|
884
|
+
never the `sig`: with the other four fields it is the credential."""
|
|
885
|
+
|
|
886
|
+
def spend_grant(self, sig_hash: str, expires_at: str) -> bool: ...
|
|
887
|
+
#: ^ records it, atomically, and is True only for the call that found it unrecorded: of two
|
|
888
|
+
#: concurrent spends of one grant exactly one proceeds. It commits on its own: never called
|
|
889
|
+
#: inside a transaction that may roll back, since a later refusal still spends the grant.
|
|
890
|
+
def forget_grants(self, expired_before: str) -> None: ...
|
|
891
|
+
#: ^ drops the records of grants that expired before this time
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
#: storage.md §3.1–§3.5. Kept apart from `STORAGE_CONTRACTS`, which is the frozen 0.3 set.
|
|
895
|
+
DOOR_STATE_CONTRACTS: tuple[str, ...] = (
|
|
896
|
+
"ThrottleState", "IdentityState", "ConfigState", "ConfirmState", "UploadState", "GrantState"
|
|
897
|
+
)
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
# --- one writer per container (storage.md §3.6, v0.7 §AF) -----------------------------------
|
|
901
|
+
#
|
|
902
|
+
# The skeleton's `Backend` already runs `atomic()` and raises `ChainConflict`; both are declared
|
|
903
|
+
# here so a second substrate builds against the type, not against `backends/`. Kept out of
|
|
904
|
+
# `STORAGE_CONTRACTS` and `DOOR_STATE_CONTRACTS`: F3's three stand, and so does §3's count.
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
class ChainConflict(Exception):
|
|
908
|
+
"""`audit_append` lost a race: another writer appended after the same head. The ledger
|
|
909
|
+
re-reads the head and re-chains; the chain never forks."""
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
class StorageBusy(Exception):
|
|
913
|
+
"""The container's write lock was not taken within its bound (storage.md §3.6). Every backend
|
|
914
|
+
raises this, never its driver's own error; nothing was written, and the door answers `503`."""
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
class Transactional(Protocol):
|
|
918
|
+
"""The container's one write lock, on the `ContainerState` substrate (storage.md §3.6).
|
|
919
|
+
|
|
920
|
+
`atomic()` holds it from entry to exit, taken before the block's first read, so a check that
|
|
921
|
+
reads, then writes, still holds at its write. A nested block joins the outer one, never a
|
|
922
|
+
savepoint: the act commits once, when the outermost block exits, and an exception leaving that
|
|
923
|
+
block rolls back every write to this substrate inside it; a `BlobStore` call is not one. A
|
|
924
|
+
block is one caller's, on the connection that holds the lock. A write outside any block
|
|
925
|
+
commits alone, under the same lock. A writer waits a bounded time for the lock, then raises.
|
|
926
|
+
"""
|
|
927
|
+
|
|
928
|
+
def atomic(self) -> AbstractContextManager[None]: ...
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
__all__ = [
|
|
932
|
+
"AS_AUTHORIZE_POSTTRUST_CAUSES",
|
|
933
|
+
"AS_AUTHORIZE_PRETRUST_CAUSES",
|
|
934
|
+
"AS_CLIENT_REGISTER_OPS",
|
|
935
|
+
"AS_DEVICE_REDEMPTION_CAUSES",
|
|
936
|
+
"AS_GRANT_DECISIONS",
|
|
937
|
+
"AS_LOGIN_CAUSES",
|
|
938
|
+
"AS_REVOKE_REFUSAL_CAUSES",
|
|
939
|
+
"AS_THROTTLE_RATES",
|
|
940
|
+
"AS_THROTTLE_SURFACES",
|
|
941
|
+
"AS_THROTTLE_WINDOW_SECONDS",
|
|
942
|
+
"BLOB_GRANT_LIFETIME_SECONDS",
|
|
943
|
+
"CAPABILITIES",
|
|
944
|
+
"CONTAINER_CONFIG_DEFAULTS",
|
|
945
|
+
"CONTAINER_CONFIG_FIELD_FROM_WIRE_KEY",
|
|
946
|
+
"CONTAINER_TYPES",
|
|
947
|
+
"CONTEXT_ITEM_FIELDS",
|
|
948
|
+
"DOOR_STATE_CONTRACTS",
|
|
949
|
+
"EVENTS",
|
|
950
|
+
"GENESIS_HASH",
|
|
951
|
+
"HUMAN_ONLY_ACTS",
|
|
952
|
+
"KINDS",
|
|
953
|
+
"PRINCIPALS",
|
|
954
|
+
"PRINCIPAL_NONE_EVENTS",
|
|
955
|
+
"PROPOSAL_STATUSES",
|
|
956
|
+
"PROPOSAL_WIRE_KEY_FROM",
|
|
957
|
+
"REGISTRATION_KINDS",
|
|
958
|
+
"RING_RANK",
|
|
959
|
+
"ROLE_BUNDLES",
|
|
960
|
+
"ROOT_TYPES",
|
|
961
|
+
"SERVING_POLICY",
|
|
962
|
+
"STORAGE_CONTRACTS",
|
|
963
|
+
"STRUCTURE_FLOORS",
|
|
964
|
+
"TOKEN_PRINCIPALS",
|
|
965
|
+
"TRUST_STATUSES",
|
|
966
|
+
"VERIFIED_ONLY_KINDS",
|
|
967
|
+
"AgentRegistration",
|
|
968
|
+
"ArtifactContent",
|
|
969
|
+
"AudienceMember",
|
|
970
|
+
"AuditEntry",
|
|
971
|
+
"AuthorizePosttrustCause",
|
|
972
|
+
"AuthorizePretrustCause",
|
|
973
|
+
"BlobGrant",
|
|
974
|
+
"BlobStore",
|
|
975
|
+
"Capability",
|
|
976
|
+
"ChainConflict",
|
|
977
|
+
"ClientRegisterOp",
|
|
978
|
+
"ConfigState",
|
|
979
|
+
"ConfirmChallenge",
|
|
980
|
+
"ConfirmCredential",
|
|
981
|
+
"ConfirmState",
|
|
982
|
+
"ContainerConfig",
|
|
983
|
+
"ContainerState",
|
|
984
|
+
"ContainerType",
|
|
985
|
+
"ContextItem",
|
|
986
|
+
"DeviceRedemptionCause",
|
|
987
|
+
"Event",
|
|
988
|
+
"GrantDecision",
|
|
989
|
+
"GrantState",
|
|
990
|
+
"IdentityState",
|
|
991
|
+
"ItemStore",
|
|
992
|
+
"Kind",
|
|
993
|
+
"Lifecycle",
|
|
994
|
+
"LoginCause",
|
|
995
|
+
"Node",
|
|
996
|
+
"PersonalRootMode",
|
|
997
|
+
"Principal",
|
|
998
|
+
"Proposal",
|
|
999
|
+
"ProposalStatus",
|
|
1000
|
+
"Provenance",
|
|
1001
|
+
"Registration",
|
|
1002
|
+
"RegistrationKind",
|
|
1003
|
+
"ResolvedItem",
|
|
1004
|
+
"RevokeRefusalCause",
|
|
1005
|
+
"Role",
|
|
1006
|
+
"RootType",
|
|
1007
|
+
"ServingPolicy",
|
|
1008
|
+
"StorageBusy",
|
|
1009
|
+
"StructureFloor",
|
|
1010
|
+
"TerminalRegistration",
|
|
1011
|
+
"TextContent",
|
|
1012
|
+
"ThrottleRate",
|
|
1013
|
+
"ThrottleState",
|
|
1014
|
+
"ThrottleSurface",
|
|
1015
|
+
"Token",
|
|
1016
|
+
"TokenPrincipal",
|
|
1017
|
+
"Transactional",
|
|
1018
|
+
"Trust",
|
|
1019
|
+
"TrustStatus",
|
|
1020
|
+
"UploadRecord",
|
|
1021
|
+
"UploadState",
|
|
1022
|
+
"UserGrant",
|
|
1023
|
+
]
|