zettelkasten.sharing.bundle¶
zettelkasten.sharing.bundle ¶
On-disk bundle format for Zettelkasten sharing: filter -> encrypt (publish)
and decrypt -> materialize a .zettelkasten cache.
Mirrors :mod:memory.sharing.bundle. A producer publishes a filtered,
per-recipient-encrypted slice of its committed .zettelkasten store; a
consumer git-fetches the bundle and decrypts only the units its key can open,
materializing a .zettelkasten-shaped cache that
:func:zettelkasten.federation.configured_repos surfaces like any other peer.
Unit kinds¶
v1 corpus kinds: note (a box *.md note), source_meta (a box
_meta.yaml), project (a _projects/<name>.yaml manifest), and
citation (a _citations/<id>.yaml entity).
v2 editorial kinds: review (a _reviews/<name>.yaml literature-review
manifest+overlay), organization (a
_organizations/<owner_type>/<owner_name>/<id>.json matrix definition),
table (a review's _reviews/<name>.tables.json grid), and outline (a
review's _reviews/<name>.outlines.json sidecar). The regenerable derived
artifacts (a review/outline .md, an org index.json / _migrated.json
/ _ported_spines.json marker) are NOT shipped.
v3 binary/dataset kind: sidecar — a per-note BINARY blob shipped verbatim
alongside its owning note, tagged by a subtype in the encrypted placement
header. Three subtypes: equation_png (an equation note's committed
<box>/_equations/<note_id>.png crop), dataset_file (a dataset note's
committed <box>/<data.path> raw bytes for a plain local file), and
dvc_pointer (only the <box>/<data.path>.dvc pointer — the tracked bytes
stay in DVC and are pulled by the recipient). A dataset is treated as DVC (ships
the pointer only) IFF an adjacent <data.path>.dvc exists on disk — mirroring
:mod:zettelkasten.datasets, which distinguishes a DVC dataset by that pointer
rather than the optional declared backend — so a sidecar/omitted-backend
note with a sibling .dvc never ships raw bytes.
A single sidecar kind (rather than three kinds) keeps ONE decrypt placement
/reconcile path; the payload is raw bytes round-tripped with no scrub. An
api-backed dataset's bytes live in the gitignored, re-derivable .angelo
cache and are NEVER shipped (the note ships alone). Synapse and
spine/source.node_id remain DEFERRED.
On-disk bundle layout¶
::
<bundle_root>/
manifest.json # cleartext structural index: [{kind, path}]
units/<digest>.age # one age ciphertext per shared unit
Each units/*.age is an age ciphertext of a small envelope: a
single-line JSON header carrying the unit's PLACEMENT (kind + box/name/id) plus
the newline-separated payload bytes (the scrubbed on-disk file). The placement
lives INSIDE the ciphertext — the cleartext manifest carries only {kind,
path} (no box/note ids/recipients), the same privacy-first design as memory.
A note's box is NOT recoverable from its markdown alone, which is why it is
carried in the encrypted header rather than the clear manifest. Unit filenames
are sha256("<kind>:<unit_key>") digests: stable across republishes (good git
deltas) and opaque to anyone who does not already know the id.
Filtering happens BEFORE any encryption (ungranted units are physically omitted,
never encrypted-and-dropped), and each retained unit is scrubbed PER-UNIT of any
reference to a unit not visible to all of its recipients (see
:mod:zettelkasten.sharing.scrub). Revocation is forward-only (same accepted
limitation as memory: a bundle repo's git history retains old ciphertexts).
BundleUnit
dataclass
¶
A pointer to one encrypted unit inside a bundle (kind + relative path).
Source code in zettelkasten/sharing/bundle.py
BundleManifest
dataclass
¶
The cleartext manifest.json at the bundle root.
Source code in zettelkasten/sharing/bundle.py
BuildResult
dataclass
¶
Summary of a :func:build_bundle run (returned in memory, never written).
Source code in zettelkasten/sharing/bundle.py
DecryptResult
dataclass
¶
Summary of a :func:decrypt_bundle run.
Source code in zettelkasten/sharing/bundle.py
read_manifest ¶
read_manifest(bundle_dir: Path | str) -> BundleManifest
Read and parse a bundle's cleartext manifest.json.
Source code in zettelkasten/sharing/bundle.py
build_bundle ¶
build_bundle(output_dir: Path | str, *, registry: IdentityRegistry, store_root: Path | str | None = None, sharing: SharingConfig | None = None, producer_id: str | None = None) -> BuildResult
Filter store units by grants, encrypt per recipient, and write a bundle.
Pipeline (filtering happens BEFORE any encryption):
- Enumerate
note/source_meta/project/citationunits fromstore_root(default: the local.zettelkastenstore). - Resolve each unit's recipient id set from
sharing(default: parsed fromstore_root/config.yaml), expanding afirmscope to theregistrymembers. Units resolving to no registered recipient are dropped (physically omitted). - For each retained unit compute its ALLOWED set — the unit-keys whose
recipient set is a superset of this unit's recipients — scrub cross-unit
references down to that set (see :mod:
zettelkasten.sharing.scrub), wrap the scrubbed bytes in a placement envelope, encrypt to the recipients' public keys and writeunits/<digest>.age. - Write the cleartext
manifest.json.
This function OWNS output_dir/units and output_dir/manifest.json —
the units directory is rebuilt from scratch on every call so stale/revoked
units never linger. Other files (e.g. .git) are left untouched. With no
sharing policy configured it writes an empty bundle.
Source code in zettelkasten/sharing/bundle.py
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | |
decrypt_bundle ¶
decrypt_bundle(bundle_dir: Path | str, out_root: Path | str, *, identity: LocalIdentity | Any | None = None, private_key: str | None = None) -> DecryptResult
Decrypt every unit this key can open and materialize a .zettelkasten cache.
Units are written into <out_root>/.zettelkasten/ as
<box>/<id>.md (notes), <box>/_meta.yaml (source meta),
_projects/<name>.yaml (projects) and _citations/<id>.yaml
(citations), so :func:zettelkasten.federation.configured_repos renders the
result like any other peer. Each unit's placement is read from its decrypted
envelope header and validated / path-jailed before use.
The cache is RECONCILED to the current bundle: stale units (dropped from a newer, re-scoped bundle or no longer openable by this key) are evicted from each owned location. A transient I/O fault during the pass SKIPS eviction that run (never destroys valid cached plaintext); revocation still works on any clean pass. A missing/corrupt manifest is treated as an empty bundle (still reconciled); an unreadable manifest (transient I/O) aborts without reconciling.
Provide the key via identity (a :class:LocalIdentity / pyrage
identity), private_key (an AGE-SECRET-KEY-... string), or neither (to
load ~/.angelo/identity.yaml).
Source code in zettelkasten/sharing/bundle.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 | |
open_bundle ¶
open_bundle(bundle_dir: Path | str, out_root: Path | str, *, identity: LocalIdentity | Any | None = None, private_key: str | None = None) -> DecryptResult
Alias for :func:decrypt_bundle.