zettelkasten.tables_nested_spines¶
zettelkasten.tables_nested_spines ¶
Nested-spine composition walker + integrity (the isolation seam).
Mechanically split out of tables.py with IDENTICAL semantics: the read-only
detect_nested_spines walker, nested_spine_integrity composition check,
and the propagate_stale_rollup drift roll-up.
detect_nested_spines ¶
detect_nested_spines(get_graph: GetGraph, localize: 'Callable[[str], str] | None' = None, *, members: 'list[dict[str, Any]]', scope_uids: 'set[str] | None' = None) -> dict[str, Any]
Assemble the multi-tier nested-spine composition from a set of spines.
Walks the cross-graph PRIMARY component-of edges (design §7/§8): a spine
with NO primary parent is a ROOT (whether it has primary children — the top of
a nested composition — or none — a degenerate/standalone single-node root); one
nested-spine descriptor is emitted per root, expandable to full depth (N-tier —
sector>theme>component and deeper, not just 2 tiers). Everything is uid-keyed
("<graph>::<id>") and depth-annotated so a Graph-3 overlay endpoint and a
Graph-4 N-ring radial / outline can consume it directly.
members are the composition's spine orgs (each a dict with a spine_ref
graph name, and optionally id / title), mirroring
:func:spine_group_matrix. scope_uids (optional) is the set of base-note
"<home>::<id>" uids in scope; any in scope but claimed by NO spine lands in
the top-level "Unplaced notes" bucket (design §5). When None the Unplaced
bucket is omitted (scope is caller-defined and unknown to the walker).
Lazy degradation (design §5, Seam 4): a spine whose primary parent graph is deleted / unresolvable is NOT dropped — it degrades to an "Unassigned" bucket at read time; edges are never scrubbed. Cross-graph cycles are guarded (uid-keyed visited sets), never infinite-looping.
Returns {kind, roots, unassigned, unplaced, index, placement} where roots
is a list of spine descriptor trees (one per parentless spine), unassigned
a list of bucket descriptors (dangling-parent and cycle spines, each holding its
own subtree), unplaced a bucket descriptor or None, index a flat
uid-keyed lookup of every emitted spine node, and placement the
{note_uid: owner_uid} partition.
Source code in zettelkasten/tables_nested_spines.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
nested_spine_integrity ¶
nested_spine_integrity(composition: 'dict[str, Any]', *, members: 'list[dict[str, Any]]') -> 'dict[str, Any]'
Composition-completeness check over a :func:detect_nested_spines result.
Phase-5 integrity (design documents/260702_nested-spines.md §10/§5): every
seeded spine must have a home — placed in a root chain, a degenerate
standalone root, or an explicit Unassigned bucket (missing-parent / cycle) —
and nothing may be silently dropped (a seed whose apex the walker could not
resolve, so it emitted NO node for it). This is a PURE, deterministic rollup
ON TOP of the walker output (§11: the walker itself is the isolation seam and is
never modified here); it loads no graphs and does no I/O.
composition is the walker's {kind, roots, unassigned, unplaced, index,
placement} dict. members is the SAME seed list passed to the walker (it
does not echo its seeds), each an org dict with a spine_ref graph name and
optional id/org_id. A member with a non-empty spine_ref is a seed;
an empty spine_ref is an invalid-seed.
seeds_accounted_for covers ONLY the structural fate of the SEEDED spines:
it is True iff every non-empty-spine_ref seed maps to its OWN distinct
emitted home (a root chain, a standalone root, or a known Unassigned bucket) —
i.e. no seed is silently dropped (walker resolved no apex → emitted no node)
and no two seeds collided onto ONE emitted uid. Because the walker emits
exactly one node per spine graph (spine.find_apex_id yields one apex per
graph and the org↔graph map keeps only the FIRST seed), two members sharing one
spine_ref collapse onto a single home; the later seed(s) are a silent loss
and are surfaced as collided (counted in counts["collided"], and each
colliding org marked in status under a "<home-uid>::collided::<org_id>"
key so the lost org is visible). seeds_accounted_for intentionally does NOT
gate on unplaced_notes — that is a separate advisory count of in-scope base
notes claimed by no spine, and the dashboard route passes scope_uids=None so
the walker omits the Unplaced bucket and this count is always 0 there.
complete is a DEPRECATED alias of seeds_accounted_for (kept, with the
identical value, for one release so existing readers keep working). It always
over-promised — it means "every seed is accounted for", NOT "the graph is
healthy" — so it is renamed to seeds_accounted_for; migrate readers to the
new key and stop consuming complete.
There is intentionally NO cycles_incomplete flag. An earlier draft shipped
one to flag a supposed root-attached-cycle BLIND SPOT (a cross-graph cycle whose
entry is a parentless root, rendered as a broken child chain rather than an
Unassigned(cycle) bucket), computed by following index[...]["parent"] up from
each placed spine and reporting a loop. That guard was a false-negative dead
guard: real roots carry parent=None and :func:detect_nested_spines renders
children acyclically, so a placed node's canonical parent chain ALWAYS
terminates at a parentless root — a genuine cross-graph cycle instead lands in
unassigned and is reported in cycles. The only input that ever tripped
the flag True was a walker-impossible hand-built composition. Computing it
CORRECTLY would require the raw component-of parent relations, which this
layer does not have (it is pure over the walker output and does no I/O) — and
recovering them would mean changing the walker's traversal or return shape, the
byte-identical isolation seam (§11) this function must not touch. Rather than
ship a guard that is False on every real composition, the key was removed;
genuine cross-graph cycles remain fully covered by cycles.
This is a PURE, deterministic rollup ON TOP of the walker output (§11: the walker is the isolation seam, never modified here); it loads no graphs and does no I/O.
Returns {total_seeded, counts, orphans, cycles, unplaced_notes,
seeds_accounted_for, complete, status} — see the module design doc for field
semantics.
Source code in zettelkasten/tables_nested_spines.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
propagate_stale_rollup ¶
Roll each node's per-spine stale flag UP its nested-spine subtree.
Phase-5 drift (design §10: "per-row staleness propagates up the chain"). A
post-order DFS over roots + unassigned subtrees sets, for every node,
node["stale_rollup"] = bool(node.get("stale") or any(child stale_rollup)).
A bucket (kind == "unassigned") has no org so its own stale defaults
False, but it still rolls up its children. PURE of I/O and in-place: assumes
the caller has already set each spine node's stale (an advisory, cost-free
drift peek), so this is deterministic and unit-testable on a plain dict.