zettelkasten.outline¶
zettelkasten.outline ¶
Outline GATHER core: the deterministic bullet-outline material engine.
Where :mod:zettelkasten.review persists an author's editorial overlay and
:mod:zettelkasten.claims exposes the per-claim anatomy, this module assembles
the raw material an outline auto-population pass writes FROM. It is the
deterministic GATHER half of the engine-gathers / agent-drafts split: given the
scoped corpus it selects claims (or, when the claim layer is still sparse, the
most salient source notes), groups them into themed sections, and for each unit
produces a grounded bundle — supporting papers, counterclaims (each with its
own evidence), caveats, per-paper CCC skeletons, verbatim quote notes, and
claim-to-claim narrative bridges. The Wave-3 DRAFT pass (an LLM agent under the
assemble-grounded-outline skill) fills only the generative slots left
empty here; it never invents the grounded ones.
The deterministic GATHER half (:func:gather_outline_material) stays pure:
no LLM, no network, no file writes. The Wave-3 layer added here builds ON it: an
INJECTABLE DRAFT pass (:func:draft) hands the gathered material to an
agent that writes the scaffold markdown; an independent, deterministic integrity
post-pass (:func:verify_draft) re-checks that draft against the material
(never trusting the agent to police itself); a :func:compute_generation_signature
cache decides when a redraft is even needed; and :func:build_outline wires
GATHER → cache → DRAFT → integrity → a crash-safe, git-backed _reviews/<name>.md
write reusing the M3a substrate (:func:graph.atomic_write_text,
:func:commit.review_write_lock, :func:commit._schedule_zettel_commit). The
scaffold .md is a REGENERABLE DERIVED ARTIFACT (overwrite-on-regenerate; the
durable AUTHORED state is the _reviews/<name>.yaml overlay).
Like :mod:zettelkasten.papers, :mod:zettelkasten.claims, and
:mod:zettelkasten.review GATHER is parametrized by a get_graph callable. It
reuses the locked anatomy/scoring primitives wholesale —
:func:claims.claim_anatomy for the heavy per-claim assembly,
:func:claims.core_paper_atom / :func:claims.claim_path /
:func:claims.claim_relations for the core paper, reading path, and structural
edges, :func:syllabus.theme_model for the section partition, and
:func:syllabus.situate / :func:syllabus.why_read for the deterministic
per-paper badges. It never re-derives a score or an anatomy.
Two restraint guarantees the output upholds:
- Quotes are RETRIEVED, never GENERATED. A quote row carries the verbatim
note body +
source.page+ note id. When a claim or paper has no quote note on file, the bundle emits an explicit'no quote on file'marker rather than fabricating one. - Every empty/missing field is an EXPLICIT GAP. Generative slots, absent CCC
material, and unresolved references are recorded in
gapsso the DRAFT agent and the downstream integrity pass see gaps, not silent omissions.
Integrity NON-GUARANTEE. The deterministic :func:verify_draft post-pass
polices STRUCTURAL integrity only — chip resolution, verbatim quoting, and header
traceability. It does NOT police prose FAITHFULNESS: fabricated declarative prose
that carries only real [chip]s and no double-quoted spans passes every check
by construction. That class of failure is governed by the DRAFT contract (the
assemble-grounded-outline skill's restraint discipline), not the verifier.
Everything is JSON-serializable (:meth:OutlineMaterial.to_dict, via
:func:dataclasses.asdict plus a leaf-coercion pass) and carries every id it
references — resolvable note ids in note_ids and work/source ids in a
SEPARATE paper_ids field — so an integrity pass and the frontend can resolve
each claim, paper, and quote without conflating the two id spaces.
CCCSkeleton
dataclass
¶
A single paper's CCC evidence card: deterministic slots, empty generative.
The DETERMINISTIC fields are filled from the graph — the citation label, the
:func:syllabus.situate / :func:syllabus.why_read badges, the
definition / mechanism / numbers note slots, the quotes from
this paper, and note_ids for everything referenced. The generative
block is left EMPTY for the Wave-3 agent to draft, and gaps records every
empty slot so nothing is a silent omission.
Source code in zettelkasten/outline/materials.py
ClaimBundle
dataclass
¶
The grounded material for one outline unit (a claim, or a fallback note).
Carries the unit's text + id, its supporting-paper CCC cards (stronger on
top), its counterclaims (each WITH its own evidence) and caveats, the core
paper card, its own verbatim quotes (or marker), the claim-to-claim narrative
bridges + reading path, and the explicit gaps. note_ids lists every
note this bundle references so the integrity pass / frontend can resolve them.
source is "claim" for a claim-layer unit or "fallback" for a
claim-sparse source-note unit; the shape is identical either way.
Source code in zettelkasten/outline/materials.py
OutlineMaterial
dataclass
¶
The full deterministic GATHER result for an outline scope.
sections are the themed groups (in :func:syllabus.theme_model order),
unplaced the bundles whose unit sits in no theme, gaps the
outline-level gap markers, note_ids the union of every resolvable note
ref any bundle references — each a graph-qualified "<graph>::<id>" token
(see :func:_qualify) so a chip names its EXACT source graph and resolves
regardless of the review scope — and paper_ids the union of the
work/source-graph ids the bundles reference (bare folder names like
"alpha", NOT note ids) — kept in a SEPARATE field so the integrity pass
never tries to resolve a paper id as a note, while the frontend can still
resolve every claim, paper, and quote without re-walking the graph.
Source code in zettelkasten/outline/materials.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
to_dict ¶
A plain, guaranteed json.dumps-able dict of the whole material tree.
Runs :func:dataclasses.asdict and then coerces any non-JSON-native
leaf to a string — most importantly a source.page that a YAML
author wrote as a bare ISO date (parsed to datetime.date), which
asdict preserves and json.dumps would otherwise reject.
The nested-composition :class:OutlineSection fields level/tier
are emitted ONLY for a section that is NOT the flat default (i.e.
level != 2 or tier != "leaf"). A flat/single-spine section drops
both keys entirely, so a non-nested build's payload — the DRAFT prompt,
the cached artifact, every downstream consumer — is BYTE-IDENTICAL to
before the nested mode existed (the ancestor_levels == 0 no-op).
Source code in zettelkasten/outline/materials.py
project_section ¶
A single-slice :class:OutlineMaterial for ONE section (or the unplaced bucket).
Returns a new material carrying ONLY section (with unplaced empty),
or — when section is None — only the unplaced bundles (with
sections empty), and with note_ids / paper_ids NARROWED to just
the refs that slice actually cites. This bounds the per-call DRAFT payload
so a large outline can be drafted section-by-section instead of stuffing the
entire (multi-megabyte) material into one prompt and overflowing the draft
model's context window (the failure that makes the agent lose its material
and emit a "re-paste the GATHER material" refusal). The shared scope and
theme_source are preserved verbatim so a projected section fingerprints
(:func:_section_material_signature) identically to its slice in the whole
material; gaps (outline-level) and nesting_degradation are dropped —
they are whole-outline framing, not per-section content.
Source code in zettelkasten/outline/materials.py
OutlineSection
dataclass
¶
A themed section: a theme, its ordered claim bundles, and framing concepts.
concepts are condensed framing tags (see :class:ConceptTag) rendered
under the section intro — distinct from claims, which are the full units.
level is the markdown header depth the section renders at (2 = ##,
the flat/single-spine default). tier is "leaf" for a normal
claim-bearing section (the flat default) or "ancestor" for a nested
composition-tier framing section (see :func:_resolve_nested_ancestors): an
ancestor tier carries no claim bundles — the DRAFT agent synthesizes 1–2
"lecture-note" framing bullets from its subtree. Both fields default to the
flat values, so a non-nested outline (ancestor_levels == 0) is
byte-identical to before.
Source code in zettelkasten/outline/materials.py
QuoteEvidence
dataclass
¶
A verbatim quote note (RETRIEVED) or an explicit no-quote marker.
When present is True the row carries the quote note's verbatim
body plus source.page and the note id so the frontend can resolve
and the integrity pass can verify it. When present is False it is the
explicit 'no quote on file' marker (everything else empty) — never a
fabricated quote.
Source code in zettelkasten/outline/materials.py
Violation
dataclass
¶
A single integrity-post-pass finding against a drafted scaffold.
kind is one of "chip" (an unresolved [note-id] chip),
"quote" (a quoted span not found verbatim in any referenced quote note),
"header" (a claim header that traces to no claim/finding unit), or
"structure" (the header skeleton drifted from the expected section headers
— in a FLAT outline the ## themes; in a NESTED outline the composition
tier tree, where each tier header is known by its (label, depth) — a
missing/reordered tier, or a claim placed at a tier depth). ref is the
offending token/text and line its 1-based line.
Source code in zettelkasten/outline/verify.py
OutlineConflictError ¶
Bases: RuntimeError
The persisted scaffold no longer matches the signature the client saw.
Raised by :func:fix_outline_violation when the caller passes the artifact
signature it loaded and the currently persisted draft has since moved on (a
regenerate/deepen/edit happened in another tab, or a 503-retry races a
completed write). Mapping this to an HTTP 409 lets the UI refuse to apply a
Fix/Remove against stale line numbers — which could delete the wrong content
— and prompt a refresh instead.
Source code in zettelkasten/outline/__init__.py
narrative_ordering ¶
narrative_ordering(bundles: list[ClaimBundle], edges: list[tuple[str, str, str]], *, year_of: Callable[[str], int | None] | None = None, salience_of: Callable[[str], float] | None = None) -> list[ClaimBundle]
Order a section's units foundations-first, counterclaims nested at target.
A pure function over the bundles and their (src_uid, relation, dst_uid)
structural edges. Ordering rules:
- Foundations first. Lineage edges (
depends-on/extends/derives-from/specializes/prerequisite-of/generalizes) establish a foundation→dependent partial order; a topological pass places every foundation before the units that build on it. - Chronological + salient within a tier. Among units with no ordering
edge between them, the earlier (by
year) comes first, then the more salient, then the uid — so the order is fully deterministic. Undated units sort last within their tier. - Counterclaims nested. A unit that contests another in-section unit
(
contradicts/responds-to/qualifies) is placed immediately after its target rather than floating to a tier of its own.
Cycles are broken safely (the smallest remaining unit by the tie-break key is
emitted). Units absent from bundles are ignored. year_of /
salience_of override the per-bundle attributes (handy for tests).
Source code in zettelkasten/outline/gather.py
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 | |
verify_draft ¶
verify_draft(markdown: str, material: OutlineMaterial) -> list[Violation]
Independently re-check a drafted scaffold against the gathered material.
Deterministic and LLM-free — it does NOT trust the agent to police itself (the skill contract is the drafting discipline; THIS is the verifier):
Code-fenced blocks and inline code spans are MASKED before scanning (see
:func:_mask_code), so a scaffold that documents its own conventions — a
header explaining the [graph::id] chip form, a "verbatim" example —
does not self-trip the chip/quote scans. Reserved ALL-CAPS markers
([GAP], [TODO], induction-head [A]/[B] notation; see
:func:_is_sentinel) are structural, not references, and are skipped by the
chip scan entirely.
- chips — every
[note-id]chip must resolve to an id inmaterial.note_ids(a note) ormaterial.paper_ids(a paper); unresolved chips are flagged. Reserved sentinel markers are exempt. - quotes — every double-quoted span (scanned over the WHOLE document, so
a multi-line span is inspected too; smart double-quotes are folded to
straight first so a MISMATCHED-delimiter span — smart-open + straight-close,
or the reverse — cannot evade the scan) must be a VERBATIM excerpt of a
referenced quote note's body: whole-quote equality OR word-boundary
containment of the span's tokens (see :func:
_verbatim_contained), NOT a raw substring. A span that matches nothing — a fabrication, or a cherry-picked/recombined fragment that never ran contiguously — is flagged. - headers — a markdown header that carries a chip is a CLAIM header; if none of its chips trace to a claim/finding UNIT in the material it is flagged as untraceable. A header with no chip is structural (the honesty header, a theme/section title) and is not a claim header.
NON-GUARANTEE: this deterministic pass polices structural integrity (chip
resolution, verbatim quoting, header traceability) — it does NOT police prose
FAITHFULNESS. Fabricated declarative prose that carries only real [chip]s
and no double-quoted spans passes every check here by construction; guarding
against that is the DRAFT contract's job (the assemble-grounded-outline
skill's restraint discipline), not the verifier's.
Returns the violations in document order; the caller marks them (e.g.
:func:build_outline appends them to the artifact) rather than silently
passing a draft that failed the check.
Source code in zettelkasten/outline/verify.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
gather_outline_material ¶
gather_outline_material(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, claim_ids: list[str] | None = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, graphs_dir: 'Path | None' = None, namespace: Callable[[str], str] | None = None, localize: Callable[[str], str] | None = None) -> OutlineMaterial
Deterministic GATHER: the grounded raw material for an outline scope.
Builds the corpus + theme model exactly as :func:papers.assemble_papers
does, ranks the claims, and for each (in salience order, or the exact
claim_ids set/order when given) assembles a grounded :class:ClaimBundle
via :func:claims.claim_anatomy.
Sectioning honors the author's SETTLED structure. When a review name
is given and claim_ids is not pinned, the themed sections — their order,
labels, membership, and per-section claim order — come from
:func:_settled_structure (the Review board's own overlay reconciliation), so
the scaffold's ## skeleton is exactly the themes the author settled on the
board: renamed, reordered, with exclusions/placements applied. Otherwise (no
review, or a pinned claim_ids set) bundles fall back to the graph-derived
:func:syllabus.theme_model grouping (a claim's theme comes from its
core/home/supporting papers), narrative-ordered within each section; claims in
no theme go to unplaced.
Claim-sparse fallback. When claim_ids is not pinned, any theme that
ends with no claim bundles is populated from its source notes
(synthesis/finding/_cross material, salience-ranked) so a 0-claim corpus
still yields themed sections with real material. The bundle shape is
identical; only source ( "claim" vs "fallback" ) differs.
Spine section partition. When a spine ref (an organization id) is given
and claim_ids is not pinned, the section axis switches to that spine's
DIMENSIONS (the section-axis analogue of the matrix's column axis): sections
are the spine's dimension nodes in matrix-column order, each section's content
is the units whose uid is a MEMBER of that dimension (resolved via the same
:func:tables.spine_readback_matrix membership the matrix cells read), and the
apex framing rides on scope['spine']. A spine OVERRIDES both the settled
structure and the theme model; an unresolvable ref degrades to the default.
Theme partition stays the DEFAULT.
Nested composition tiers. When a nesting selection is requested (an
explicit ancestor_uids set OR a non-zero ancestor_levels) and a
spine subject resolves, the subject spine's single-spine dimension
partition becomes the deepest LEAF content and the kept ANCESTOR tiers are
stacked ABOVE it, drawn from the same :func:tables.detect_nested_spines
composition tree the frontend displays. ancestor_uids is the AUTHORITATIVE
selection: the subject's FULL root-first ancestor chain is pruned to exactly
those uids in chain order (unchecked intermediate tiers drop, children reparent
to the nearest kept ancestor — the frontend projectTiers pane). When
ancestor_uids is None the historical int fallback applies
(ancestor_levels == N → the nearest N ancestors, root-first;
ancestor_levels == -1 → every ancestor to the composition root). Each
ancestor tier is an :class:OutlineSection at an increasing markdown level
(root shallowest, ##) with tier == "ancestor" and NO claim bundles —
the DRAFT agent synthesizes 1–2 lecture-note framing bullets from its subtree.
The subject's dimension sections keep their claims (tier == "leaf") but move
to level = 2 + <kept ancestor count>. A flat request (ancestor_uids is
None and ancestor_levels == 0, or an empty ancestor_uids) is a
byte-identical no-op (no ancestor tiers, every section stays ## leaf).
Nesting is ALSO skipped whenever claim_ids is pinned (an explicit set is its
own authoritative ordering) — an explicit no-nest, never a nested-keyed flat.
Pure: no LLM, no network, no writes. JSON-serializable
(:meth:OutlineMaterial.to_dict), carrying every referenced note id.
Source code in zettelkasten/outline/__init__.py
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 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 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 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 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 | |
draft ¶
draft(material: OutlineMaterial, *, draft_fn: 'Callable[[str, str], str] | None' = None, skill_path: 'str | Path | None' = None) -> str
DRAFT the scaffold markdown from gathered material via an INJECTABLE agent.
Loads the assemble-grounded-outline skill as the system context, builds
the agent prompt (the drafting task instruction + the serialized GATHER
material), and calls draft_fn(system, prompt) -> str. draft_fn
defaults to :func:_default_draft_fn (the in-process dashboard agent, imported
lazily) so tests can stub it deterministically. The engine GATHERS; the agent
DRAFTS — this never writes prose itself.
Source code in zettelkasten/outline/__init__.py
draft_section_expansion ¶
draft_section_expansion(material: OutlineMaterial, section_md: str, *, draft_fn: 'Callable[[str, str], str] | None' = None, skill_path: 'str | Path | None' = None) -> str
DEEPEN one section's markdown via the SAME injectable agent as DRAFT.
Loads the restraint contract as system context and builds the DEEPEN prompt
(the deepen instruction + the section being deepened + the serialized GATHER
material), then calls draft_fn(system, prompt) -> str. Mirrors
:func:draft exactly so the two task framings share one agent
config and one stubbing seam in tests; the engine never writes prose itself.
Source code in zettelkasten/outline/__init__.py
compute_generation_signature ¶
compute_generation_signature(get_graph: 'GetGraph | None' = None, *, project: str = '', graph: str = '', name: str = '', claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, localize: 'Callable[[str], str] | None' = None) -> str
hash(graph_sig + meta_sig + citations_sig + overlay_sig + skill_version).
graph_sig— the :func:_scope_fingerprintover the scope (plus the scope descriptor: project/graph/claim_ids/as_of, which also define what is drafted), so any note edit or scope change invalidates the cache.meta_sig— the :func:_scope_meta_fingerprintover the in-scope sources'_meta.yamlfiles, so a year/author/title/coverage edit (which changes the drafted material — citation labels, badges, theme ordering, bundle years — but never touches a*.mdnote) busts the cache.citations_sig— the :func:_citations_fingerprintover the global_citationsstore threaded into the works, so any citation edit busts it.project_sig— the :func:_project_membership_sigover a project scope's_projects/<name>.yamlsource list (GATHER scopes the corpus to exactly this set), so reassigning a project's membership busts the cache even though the project file is observed by no other probe.overlay_sig— the_reviews/<name>.yamleditorial overlay (ordering, scaffolding, tiering, …); an editorial change forces a redraft.skill_version— the content hash of the DRAFT skill contract.spine_sig— folded in ONLY when aspinesection axis is referenced (:func:_spine_signature): the ref + the spine graph's note fingerprint, so selecting/editing a spine busts the cache exactly as a scope/column change does. Absent for every spine-less outline and for the matrix's call here, so their signatures (and caches) are byte-identical to before.ancestor_uids— the RESOLVED, ORDERED (root-first) ancestor uid list the nested build will actually stack (see :func:_resolved_ancestor_uids), folded in ONLY when non-empty. Because it is the resolved uid list — NOT the bare intancestor_levels— two DISTINCT selections of the same SIZE (e.g. a gapped[root, leaf-parent]vs a contiguous[root, mid]) cache distinctly instead of colliding, and the fold condition matches the GATHER nesting guard exactly (a spine subject resolved,claim_idsnot pinned, a non-empty kept chain). An empty resolved list folds NOTHING, so every flat outline (ancestor_levels == 0and noancestor_uids), a pinnedclaim_idsbuild, a spine-less scope, and the matrix's call here all hash byte-identically to before. Resolving requiresget_graph; when it is absent (e.g. the matrix's :func:_table_signaturecall) nothing is folded — the flat key.
Designed so the Wave-5 MCP tool / endpoint is a thin delegate (it passes the
same scope through), mirroring build_syllabus.
Source code in zettelkasten/outline/__init__.py
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 | |
compute_outline_signature ¶
compute_outline_signature(get_graph: 'GetGraph | None' = None, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, localize: 'Callable[[str], str] | None' = None) -> str
The cache key for ONE outline's scaffold.
Folds the shared corpus/overlay :func:compute_generation_signature together
with this outline's identity, its research QUESTION, and (for an additional
outline whose structure is NOT in the manifest overlay) its own merged
overlay. So:
- editing the outline's question forces a redraft of THAT outline;
- the default outline (
outline_id == DEFAULT_OUTLINE_ID, question == the review's own question) keeps using the manifest-overlay-backed corpus signature — its cache key only gains the question term; - the matrix's
_table_signature(which calls :func:compute_generation_signaturedirectly) is UNAFFECTED — the outline question never leaks into it.
Source code in zettelkasten/outline/__init__.py
compute_content_signature ¶
Stable hash of the PERSISTED draft markdown, for the edit-staleness guard.
Distinct from the generation/material :func:compute_outline_signature: that
signature fingerprints the SCOPE inputs and is INVARIANT across a
force/deepen that rewrites the derived prose for the SAME material — so it
cannot tell that a Fix/Remove's line now points at different content. This
hashes the actual persisted .md bytes, so ANY rewrite of the draft (a
regenerate, a deepen, a prior fix) changes it and a stale client's edit is
refused (HTTP 409) instead of editing/deleting the wrong line. It NEVER drives
caching or redraft — that stays the generation signature.
Source code in zettelkasten/outline/__init__.py
build_outline ¶
build_outline(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, force: bool = False, peek: bool = False, draft_fn: 'Callable[[str, str], str] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, namespace: 'Callable[[str], str] | None' = None, localize: 'Callable[[str], str] | None' = None) -> dict[str, Any]
Top-level orchestrator: GATHER → cache check → DRAFT → integrity → write.
Computes the :func:compute_generation_signature; if it matches the stored
signature in _reviews/<name>.yaml and the .md exists (and force
is false), returns the stored markdown with NO agent call (cached=True).
Otherwise it GATHERs the material, DRAFTs the scaffold via
:func:draft (the injectable draft_fn), runs the deterministic
:func:verify_draft integrity pass, annotates any violations into the
artifact, and persists _reviews/<name>.md as a REGENERABLE DERIVED
ARTIFACT (overwrite-on-regenerate) through the M3a substrate
(:func:review_write_lock → :func:atomic_write_text →
:func:_schedule_zettel_commit), also storing the signature under the
manifest's scaffold key through the same write path.
When peek is set the call is COST-FREE and read-only: it computes the
current signature, reads the stored scaffold signature + the cached .md
(if either exists), and reports staleness WITHOUT ever GATHERing, DRAFTing,
writing, committing, or seeding an empty manifest. The dashboard fires this
on plain navigation so opening a never-built/stale review never DRAFTs — only
an explicit force regenerate does.
ancestor_uids/ancestor_levels thread the NESTED composition selection
through GATHER and the cache signature (see :func:gather_outline_material /
:func:compute_generation_signature): a flat request (no ancestor_uids and
ancestor_levels == 0) is the flat single-spine/theme partition,
byte-identical to before; an explicit ancestor_uids prune (authoritative) or
a non-zero ancestor_levels (fallback) stacks the kept ancestor framing tiers
above the subject's leaf partition and caches separately per DISTINCT selection.
Returns {markdown, artifact_path, signature, stale, violations, cached,
exists} (a peek also carries stored_signature). The Wave-5 MCP tool
+ POST endpoint are thin delegates over this.
Source code in zettelkasten/outline/__init__.py
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 | |
stream_outline
async
¶
stream_outline(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, force: bool = False, draft_stream: 'Callable[[str, str], Any] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, namespace: 'Callable[[str], str] | None' = None, localize: 'Callable[[str], str] | None' = None)
The STREAMING orchestrator: same GATHER→cache→DRAFT→integrity→write as
:func:build_outline, but an async generator that yields PROGRESS so the
build is never an opaque, crash-looking black box.
Yields plain event dicts {"event": <name>, "data": {...}} (the route
formats them as SSE — this stays framework-agnostic):
stage— a phase marker (gather→gathered→draft→verify), each with a short humanmessage(and the GATHER counts ongathered) so the UI shows what is happening.token— one assistant delta of the scaffold AS it is drafted, so the prose streams in live.result— the terminal payload, identical in shape to :func:build_outline's return (markdown/signature/violations/cached/…), so the frontend reconciles it exactly like the JSON build.
A cache hit (unchanged signature + extant artifact, force false) emits a
single result with cached=True and no agent call. peek is NOT a
streaming concern — navigation still uses the cost-free JSON
:func:build_outline peek path. Errors are raised; the route wraps them
into a terminal error event.
Source code in zettelkasten/outline/__init__.py
2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 | |
expand_outline_section ¶
expand_outline_section(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, header: str = '', occurrence: int = 0, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, draft_fn: 'Callable[[str, str], str] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, namespace: 'Callable[[str], str] | None' = None, localize: 'Callable[[str], str] | None' = None) -> dict[str, Any]
Re-draft ONE section of the stored scaffold deeper, splicing it back in.
Reads the persisted _reviews/<name>.md, locates the section under
header (:func:_locate_section), GATHERs the scope's material, asks the
agent to DEEPEN only that section (:func:draft_section_expansion), splices
the replacement back into the full document, runs the SAME deterministic
:func:verify_draft integrity pass over the whole spliced doc, and
persists it through the shared :func:_persist_draft write path. The
generation signature is unchanged (the scope inputs did not change — only the
derived prose got richer), so a deepened scaffold does not read as stale.
Returns the same payload shape as :func:build_outline.
Source code in zettelkasten/outline/__init__.py
3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 | |
stream_section_expansion
async
¶
stream_section_expansion(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, header: str = '', occurrence: int = 0, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, draft_stream: 'Callable[[str, str], Any] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, namespace: 'Callable[[str], str] | None' = None, localize: 'Callable[[str], str] | None' = None)
Streaming twin of :func:expand_outline_section (stage/token/result frames).
Same GATHER → DEEPEN → integrity → splice → write as the sync path, but an
async generator that streams the section AS it is re-drafted so the deepen is
not an opaque spinner. The token frames carry the new SECTION's deltas
(not the whole document); the terminal result carries the full spliced
markdown so the frontend swaps the finished document in exactly like a build.
Source code in zettelkasten/outline/__init__.py
3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 | |
fix_outline_violation ¶
fix_outline_violation(get_graph: GetGraph, *, project: str = '', graph: str = '', name: str = '', outline_id: str = DEFAULT_OUTLINE_ID, kind: str = '', ref: str = '', line: 'int | None' = None, action: str = '', expected_content_signature: 'str | None' = None, claim_ids: 'list[str] | None' = None, as_of: 'str | int | None' = None, spine: str = '', spine_mode: str = '', ancestor_levels: int = 0, ancestor_uids: 'list[str] | None' = None, extract_fn: 'Callable[[str, str], str] | None' = None, corpus_fn: 'Callable[[str], tuple[str | None, list[dict[str, Any]]]] | None' = None, graphs_dir: 'Path | None' = None, skill_path: 'str | Path | None' = None, namespace: 'Callable[[str], str] | None' = None, localize: 'Callable[[str], str] | None' = None) -> dict[str, Any]
Resolve ONE integrity violation in the stored scaffold and persist the draft.
Loads the persisted _reviews/<name>.md (banner peeled), rebuilds the scope's
:class:OutlineMaterial, applies the requested action ("fix" or
"remove") to the violation identified by kind/ref/line, re-runs
the deterministic :func:verify_draft pass over the edited draft, re-annotates
any remaining violations, and persists through the SAME crash-safe write path the
build uses. The generation signature is unchanged (only derived prose moved), so
the artifact does not read as stale and the user-DEEPENED provenance map is
preserved.
The load → edit → persist runs under a SINGLE :func:review_write_lock
acquisition, so a concurrent writer can never slip a lost update between the
read and the write. When expected_content_signature is given it is checked
against a :func:compute_content_signature of the CURRENTLY persisted draft
markdown (read fresh INSIDE that lock); a mismatch means the draft moved on
since the client loaded it (stale banner / second tab / 503-retry, OR a
force/deepen that rewrote the prose for the SAME material) and
:class:OutlineConflictError is raised (the route maps it to a 409) rather than
editing stale line numbers and deleting the wrong content. A CONTENT hash —
not the generation signature — is used precisely because the generation
signature stays byte-identical across a force/deepen rewrite of the same
material, so it cannot detect that the client's line now points elsewhere.
A FIX never fabricates: a quote fix only splices a passage re-verified against
the source (grounding.verify_quote) AND present verbatim in a referenced quote
note; a chip fix only rewrites to a unique fuzzy match above a fixed threshold.
When nothing resolves the draft is left untouched (NOT rewritten / committed) and
resolved=False is returned so the UI can fall back to Remove.
Returns the :func:build_outline payload shape plus resolved (bool) and
message (str).
Source code in zettelkasten/outline/__init__.py
3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 | |