On this page
Config link and contract hooks๏
๐ก Intermediate ยท Lesson 34
SpellbookConfiguration hooks, families 3+4: LINKING and CONTRACTS - the dynamic arc becomes observable. Register on the owner book and watch its side of the story: on_conduit_post_link - a link opened on_contract_created - a spell entered a contract on_contract_removed - it left on_conduit_post_unlink - the link died (lesson 27's sever) This closes the loop: everything lessons 21-27 DO, these hooks SEE.
Before you run๏
Use the Intermediate guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.
Run the saved script๏
python UX_and_AIX_experiences/02_intermediate/34_config_link_and_contract_hooks.py
py -3.14t UX_and_AIX_experiences/02_intermediate/34_config_link_and_contract_hooks.py
Public surface๏
linking + contract hooks across link -> pull -> sever
Code๏
1"""
2TIER: intermediate (34)
3GOAL: SpellbookConfiguration hooks, families 3+4: LINKING and
4 CONTRACTS - the dynamic arc becomes observable. Register on the
5 owner book and watch its side of the story:
6 on_conduit_post_link - a link opened
7 on_contract_created - a spell entered a contract
8 on_contract_removed - it left
9 on_conduit_post_unlink - the link died (lesson 27's sever)
10 This closes the loop: everything lessons 21-27 DO, these hooks
11 SEE.
12SURFACE EXERCISED: linking + contract hooks across link -> pull ->
13 sever
14"""
15import sys
16from pathlib import Path
17
18sys.path.insert(0, str(Path(__file__).parent)) # local helper (see _dynamic_world)
19from _dynamic_world import dynamic_spellbook
20
21import melder as md
22
23
24class SharedThing:
25 pass
26
27
28def main() -> None:
29 seen = []
30
31 owner_book = dynamic_spellbook()
32 config = owner_book.get_configuration()
33 for name in ("on_conduit_post_link", "on_contract_created",
34 "on_contract_removed", "on_conduit_post_unlink"):
35 config.add_hook(owner_book.id, name,
36 (lambda n: lambda *a, **k: seen.append(n))(name))
37
38 spell_id = owner_book.bind(spell=SharedThing, existence="unique")
39 owner = owner_book.conjure(dynamic=True, name="hook-owner")
40 borrower = dynamic_spellbook().conjure(name="hook-borrower")
41
42 owner.link(borrower)
43 borrower.add_spell_to_contract(spell_id=spell_id, conduit=owner,
44 permissions="create")
45 owner.sever_link(borrower)
46
47 print("the dynamic arc, observed:", seen)
48 assert "on_conduit_post_link" in seen
49 print("link/contract hooks fired - the arc is watchable end to end")
50
51
52if __name__ == "__main__":
53 main()
Check the outcome๏
The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.