module

Arcana::Mail::Sessions

Session records and runners, as the dot-ai spec has them (Mail: Runners, Session records; Draft 0.5 for registered runners), kept the same way whichever program writes them, so each reads the others'. Where Arcana is the carrier, its hooks keep a record of each session (Hook), and delivery tells the newest open session of each project it put mail into through that session's runner (tell_project). Arcana never pushes into a session itself: its own tell says when a session will hear at the end of its turn, and otherwise that it can't push (own_tell). Pushing belongs to the runners.

Constants

KEEP = 7.days

A record ended (or whose harness went) this long ago may be removed.

NAME_RE = /\A[a-z0-9-]+\z/

What a runner's or a carrier's name may be: never a path or a command line.

TELL_TIMEOUT = 10.seconds

How long a runner's tell may take before it's given up on.

Class methods

by

The runner of a session the hooks record: the program that started it, by DOT_AI_BY; else Arcana, the hooks' carrier. There's no default runner.

Source
clean

Removes records ended, or whose harness went, a week ago.

Source
dir

Where every runner keeps its sessions' records: the person's own.

Source
harness_pid(agent : String) : String | Nil

The harness's process, for Claude Code or Codex: the nearest process above this one, within three, that is the harness's (a hook runs under a shell it starts). For Codex, only under codex --no-daemon, whose TUI runs its app server itself; a hook its daemon runs (codex app-server, which outlives its sessions) gets none.

Source
key(id : String) : String

A session's id as its record's name.

Source
newest_first(root : String) : Array(Tuple(String, Hash(String, String)))

The records of the project at root's sessions, newest first.

Source
open?(fields : Hash(String, String)) : Bool

Whether a record's session is still open: not ended, and its harness's process, where it names one, still there.

Source
own_tell(id : String) : Int32

Arcana's own tell, for a session whose runner is Arcana: 3 when there's no record or its session isn't open (marking it ended), 0 when it's busy (its Stop tells it), and 4 otherwise, since Arcana never pushes.

Source
path(id : String) : String
Source
read(path : String) : Hash(String, String)

The record at path as fields; empty when there's none.

Source
record(id : String, root : String, agent : String, state : String, start : Bool) : Nil

Writes the session's record in state state. Its runner and harness's process are found at its start and kept after.

Source
runner_path(name : String) : String | Nil

The program of the runner name, as it registered it; nil where it hasn't, or where its registration or its program fails the checks: the folder and the file the person's, the line an absolute path to an executable that's the person's (or root's), checked at what a link leads to, and none of them writable by anyone else.

Source
runners_dir

Where runners register: runners/NAME, a line holding the runner's program's absolute path.

Source
set_state(path : String, state : String) : Nil

Changes the state of a record that exists.

Source
state_base
Source
tell_project(root : String, io : IO) : Nil

Tells the project at root, whose inbox mail has just reached: its newest open session, through its runner, so two sessions don't both answer the mail. Status 0: told, or will be at the end of its turn; 3: not open, so the next newest; 4: can't push, so the session hears at its next start or Stop, from the hooks. Arcana's own sessions it answers for itself (own_tell); others', through the program their runner registered (runner_path). A record naming a runner that hasn't registered, or whose registration fails the checks, is left alone, as if it answered 4: its session has hooks, so it hears at its Stop, and telling an older one as well would have two answer. A runner that fails is named in a not told: line to io: the mail was delivered all the same.

Source
write(path : String, fields : Hash(String, String)) : Nil

Writes a record, under a hidden name renamed into place, in the records folder, made private to the person if need be.

Source