Skip to content

Give duplicated Python helpers one home each, and fit generated thread titles - #5293

Merged
max-sixty merged 2 commits into
mainfrom
agent-a1b4e55a1debae46d
Nov 4, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-a1b4e55a1debae46d

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Part of the 2026-11-03 sweep for duplicate implementations (#5291 changes how review and Tend look for them). Each question below was answered in more than one place in src/leaf/, hooks/ or the dev commands, and the copies had drifted; each now has one home that every caller uses.

  • Thread title limit. registry.kernel.title_limit() reads the kernel registry's maxLength on the thread_title event's title, and thread.fit_title is the one fit: it collapses whitespace and cuts at a word, ending in an ellipsis. The clerk and the page server's generated titles (thread_titles.write_title) both use it, and the CLI's --title help and events.md take the number from it. The six registry copies of the title schema stay inline: no kind's record refers to another's by $ref, and the protocol baseline compares a reference by its text.
  • Path locks. locations.path_lock(*paths) holds one lock per path_lock_key under /tmp/leaf-path-locks-<uid>, taken in sorted order. package_write_lock and file-binding saves both use it.
  • Initialized pages. event_log.initialized(page_dir) says whether a page's log is a file. The CLI's page argument, page init, reconnect advice, owned_pages, the package gate, command timing and the dev commands call it.
  • Log parse. event_log._stored_events is the one parse of the log (torn lines, seq by line number). interaction_log.read_interactions reads through read_stored_events instead of splitting the log itself, and each semantic row's event carries its seq in place of a separate event_seq.
  • Claims directory. state.claims_home() is the resolved claims/ that service.claim_path, session_claims, standing_claims and the watch read.
  • Lock loop. state.flocked_descriptor(path, flags) is the one loop that locks, checks the path still names the file, retries, and unlocks before closing; flocked and leases.page_locked use it.
  • Timestamps. interaction_log.interaction_time and the Codex transcript check parse Leaf's date-time format with registry.schema.aware_instant instead of their own parsers; since Read a page without validating its layer's registry, and load jsonschema only to validate #5272, importing registry.schema no longer loads jsonschema.
  • Hook words. hooks/claude-code.ts can import neither a Python constant nor the page's modules, so its copies stay, and its tests now hold them to their homes: the module test and the claude-code journey read harness.NUDGE_WORDS and reply_phases.LEAF_WAKE. The band words' comment no longer claims they are an All pages row's.

Behavior changes:

  • A generated thread title over 80 characters, or broken over lines, was refused at admission and left its thread untitled. It is now fitted and written.
  • A save to a bound file used to lock under state_home()/files, keyed by the path as stored. It now locks in the machine-local directory, keyed by the resolved path, case-folded on a case-insensitive volume, so two Leafs with different state homes serialize their saves of one file. The eval sandbox allows the new lock directory's name.
  • A directory holding events.jsonl but no layer.json now counts as a page for the package gate, so its page-owned paths are protected.
  • A watch with no session used the unresolved claims directory, so on a state home under a symlink, such as one in /tmp on macOS, it never matched change notifications, which name resolved paths. It now does.
  • flocked flushes what a block wrote before releasing the lock, and a descriptor that lost its path is unlocked before it is closed.
  • page interactions --since and --until refuse a time without the T separator, as the format does.

Tests: test_thread_titles adds a generated title that is fitted rather than refused, which failed before this change. test_clerk's title test drives a long title through the clerk's answer instead of the private helper. test_file_bindings finds the save's lock under PATH_LOCKS, and the package-lock journey observes locations.flocked.

This was written by Claude Code on behalf of max-sixty

…d titles

Title limit. `registry.kernel.title_limit()` reads the kernel registry's
`maxLength` on the `thread_title` event's `title`, and `thread.fit_title` is the
one fit: it collapses whitespace and cuts at a word, ending in an ellipsis. The
clerk and the page server's generated titles (`thread_titles.write_title`) both
use it, and the CLI's `--title` help and `events.md` take the number from it.
Behavior change: a generated title over 80 characters, or broken over lines, was
refused at admission and left its thread untitled; it is now fitted and written.
The six registry copies of the title schema stay inline. No kind's record refers
to another's by `$ref`, and the protocol baseline compares a reference by its
text, so the refactor would read as a protocol break.

Band words. `hooks/claude-code.ts` can't import `activity-words.js`, whose
imports reach the page's framework and Lit by server-absolute paths that no
module loader resolves outside the page. The band keeps its words, unchanged on
screen, and its comment no longer claims they are an All pages row's.

Path locks. `locations.path_lock(*paths)` holds one lock per `path_lock_key`
under `/tmp/leaf-path-locks-<uid>`, taken in sorted order. `package_write_lock`
and file-binding saves both use it. Behavior change: a save to a bound file used
to lock under `state_home()/files`, keyed by the path as stored. It now locks in
the machine-local directory, keyed by the resolved path, case-folded on a
case-insensitive volume, so two Leafs with different state homes serialize
their saves of one file. The package locks' directory was
`leaf-package-locks-<uid>`; the eval sandbox now allows the new name.

Initialized pages. `event_log.initialized(page_dir)` says whether the page's
log is a file and holds the rule in its docstring. The CLI's page argument,
`page init`, reconnect advice, `owned_pages`, the package gate, command timing
and the dev commands call it (`arrangement_eval` drops its guard, since
`read_events` already reads a missing log as empty). The package gate no longer
also requires `layer.json`, since init writes the layer record before the log.
Behavior change: a directory holding an `events.jsonl` but no `layer.json` now
counts as a page there, so its page-owned paths are protected.

Log parser. `event_log._stored_events` is the one parse of the log (torn lines,
seq by line number), and `_parse_events` drops the private session context from
it for application readings. `interaction_log.read_interactions` reads the log
through `read_stored_events` instead of splitting it itself. Each semantic row's
`event` now carries its `seq`, and the row's separate `event_seq` is gone;
`response_times` sorts by `event.seq`.

Nudge words. The Claude Code module test and the claude-code journey read
`harness.NUDGE_WORDS`, and the journey reads the wake summary as
`reply_phases.LEAF_WAKE`, so the module test holds the TypeScript copy to the
Python constant. A hooks module can import neither a Python constant nor JSON,
so the copy stays.

Claims directory. `state.claims_home()` is the resolved `claims/` that
`service.claim_path`, `session_claims`, `standing_claims` and the watch read.
Behavior change: a watch with no session used the unresolved directory, so on a
state home under a symlink, such as one in `/tmp` on macOS, its comparison with
change notifications, which name resolved paths, never matched.

Lock loop. `state.flocked_descriptor(path, flags)` is the one loop that locks,
checks that the path still names the file, retries, and unlocks before closing.
`flocked` wraps its descriptor in a file object, and `leases.page_locked` uses it
on the page directory. Behavior change: what a block writes through `flocked`'s
file is flushed before the lock is released, where it used to be flushed after,
and a descriptor that lost its path is unlocked before it is closed.

Timestamps. `state.aware_instant` is the parse of Leaf's date-time format,
moved beside `now_iso` from `registry.schema`, which imports the schema engine
that harness hooks avoid. `interaction_log.interaction_time` and the Codex
transcript check now use it. Behavior change: `page interactions --since` and
`--until` refuse a time without the `T` separator, as the format does.

Themes validate the catalogue with `registry.schema.json_validator`, imported
only when a catalogue exists. `state.write_json` stays, since the
`distribution` dev command uses it.

Tests. `test_thread_titles` adds a generated title that is fitted rather than
refused; it failed before this change. `test_clerk`'s title test drives a long
title through the clerk's answer instead of calling the private helper.
`test_file_bindings` finds the save's lock under `PATH_LOCKS`.
`test_interaction_log` matches the new message for a time without an offset.
`test_interact_claude_code_module` builds the nudge from `NUDGE_WORDS`. The
package-lock journey observes `locations.flocked`, where the lock is now taken.
#5272 made `registry.schema` cheap to import, loading jsonschema only to
validate, and moved `themes` onto `json_validator` itself. Both conflicts take
main's side. `aware_instant` stays in `registry.schema`, its home on main: this
branch had moved it to `state.py` only because importing `registry.schema` used
to load the schema engine. `interaction_log.interaction_time` and the Codex
transcript check now import it from there, and `sample_content`,
`served_state.queues` and `user_views` keep main's imports.
@max-sixty
max-sixty merged commit f322b31 into main Nov 4, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-a1b4e55a1debae46d branch November 4, 2026 07:00
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.

2 participants