Skip to content

Run hooks from entangled.toml when there are multiple files - #110

Merged
jhidding merged 1 commit into
mainfrom
fix/hooks-multiple-files
Nov 15, 2026
Merged

jhidding merged 1 commit into
mainfrom
fix/hooks-multiple-files

Conversation

@jhidding

Copy link
Copy Markdown
Contributor

Summary

In a project with more than one Markdown file, hooks enabled in entangled.toml never ran on_tangle. For example, the repl hook never wrote its session file, and entangled sync then deleted the file as an orphan. The brei and build hooks were affected the same way.

The cause:

  • Document starts with a default Context, whose hooks are only shebang.
  • __post_init__ sets the config from entangled.toml through the config setter, which changed context.config without creating the hooks that config enables.
  • With one input file, load() replaces the context, which hid the problem.
  • With more files, each file is read with its own context, which has the right hooks and shares their state. But tangle() runs on_tangle on the document's own hooks.

The setter now builds a new Context. That creates the hooks for the new config and shares their state with the hooks used while reading.

Tests

  • test_session_with_multiple_files tangles two pages, one with a REPL session, and checks the session file. It fails without the fix.
  • Tested by hand with the Zensical template: adding a second page no longer deletes the session.

🤖 Generated with Claude Code

Document started with a default Context, and setting its config did not
create the hooks enabled there. With a single input file the context was
replaced while loading, but with more files on_tangle only ran for the
default hooks, so e.g. REPL session files were not written and then
deleted as orphans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhidding
jhidding merged commit 3c90fae into main Nov 15, 2026
9 checks passed
@jhidding
jhidding deleted the fix/hooks-multiple-files branch November 15, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant