Skip to main content

Module extract

Module extract 

Source
Expand description

Facts a session leaves behind, kept without anyone asking. When a runner ends a session, the hook reads its transcript and keeps up to MAX_PER_SESSION sentences that state something durable: a rule (“always”, “never”, “must”), a cause (“root cause”, “because”, “turns out”), or a fix. Each is written at once as a note whose source.basis is agent, carrying via:session-end, the session, and the open sitting’s issue. The read side goes by that stored basis: recall, search and the island label it an unverified agent note, and no prompt hook hands it on as a fact or a rule. With no sitting, packset has no place for a note, and the write is skipped. No model runs: the extraction is a bounded, deterministic read. A sentence already kept (by its normalized form) is not written again.

The read runs at session end. LJOS_EXTRACT=off turns it off. A mined sentence is still nobody’s claim: the note stays on the tracker, and no prompt hook injects it.

Constants§

MAX_PER_SESSION
The most facts one session writes.
MAX_TRANSCRIPT_BYTES
The longest transcript read, in bytes, from its end.

Functions§

asked_by
asked_for over the variable’s value, so a test names it.
asked_for
Whether session-end extraction runs. It does, unless LJOS_EXTRACT=off.
at_session_end
Hand the session finish to a detached process and return. The hook does not read the transcript and does not call the pack. The child fires the session’s memories, writes the notes, and drains a queued tracker push. Returns 0: the count is not known until the child ends.
facts
Up to MAX_PER_SESSION facts from a transcript, newest last, with no two of the same normalized form and none in kept.
is_fact
Whether a sentence states something durable enough to keep.
kept
The normalized forms already kept on this machine.
normal
A sentence’s form for deduplication: lowercase words only.
prose
The prose of a transcript: JSONL with one message a line (Claude Code, Codex and most runners), or plain text.
read_tail
The last cap bytes of path, or the whole file when it is shorter. The head of a long transcript is not read. None when the file cannot be opened.
run_finish_job
The detached session finish. path is the job schedule_finish wrote.
schedule_finish
Write the hook payload and start ljos hook --finish-session in its own session. A failure to start is one line. The hook does not do the work itself.