Hook entry points and streaming¶
octomate_cli.emit ¶
Forward a native session's hook payload from stdin to Octomate's hook router.
Both agents' installers write command hooks that run this script — Codex because it
has no http hook handler at all, Claude so the settings file stays free of hosts and
credentials: with no --url pinned, the router's address is resolved when the hook
fires, from OCTOMATE_CLI_URL or the client config file, and switching servers is an
environment switch, not a re-install. The transport is HTTP either way: this only
carries stdin to the router at <base>{--path}.
Run by absolute path, never as python -m octomate..., and imports nothing from
octomate. Both matter: octomate/__init__.py builds Octomate, which pulls in
pydantic-ai and costs ~1.9s to import — per hook, on a handler the session blocks on,
several times a turn. Codex session names are read through its SDK without loading
turn history; the observer never resumes or runs the session.
Keep server-package imports out of this script. The environment variable names,
the hook path, and the client-config resolution below are duplicated
from octomate_cli/config.py and octomate_cli/tentacles/codex/hooks.py for the same
reason — this module cannot import them without paying for a package. Change them
together; the tests hold the copies to the canonical ones.
config_files ¶
Project scope first, then user scope — hooks run with cwd at the directory the
session lives in, so ./.octomate/cli.toml is that project's own override.
Source code in cli/octomate_cli/emit.py
file_config ¶
One file's table, {} when absent. A file that does not parse is reported and
treated as absent: this runs on the blocking path of someone's session, where a
traceback helps nobody.
Source code in cli/octomate_cli/emit.py
resolved ¶
The client's precedence: the environment, then the config files in scope order.
Source code in cli/octomate_cli/emit.py
main ¶
Source code in cli/octomate_cli/emit.py
octomate_cli.launch ¶
Spawn the transcript tail for a native session — the launcher hook.
The forwarding hooks carry the ledger to Octomate over HTTP, but they can start
nothing on this machine; the transcript stream needs a local process, and this
command hook is what starts it. It fires on every prompt, spawns octomate <agent>
tail detached, and returns at once so the turn never waits — the tail itself refuses
to run twice per session, so the repeated fire is the liveness check, not a leak.
On a Codex SubagentStop, the event's agent_transcript_path rides along as
--agent-path: the running tail cannot see which sibling rollout is a child of its
session, so the hook that knows hands it the path (the tail spools it and exits when
one already holds the session).
The stream address is pinned only when the install pinned --url; otherwise it is
derived when the hook fires, from OCTOMATE_CLI_URL or the client config file — the
same resolution the forwarding hooks follow. With none of them, nothing spawns and
nothing is said: the emit hook on the same event already complained on stderr.
Run by absolute path, never as python -m octomate..., and imports nothing from
octomate: octomate/__init__.py builds Octomate, which costs ~1.9s to import, and
this command is on the blocking path of every prompt. Shared hook schemas live in
the lightweight protocol package. The environment variable name and the client-config
resolution are duplicated from
octomate_cli/config.py for the same reason — change them together.
Prints nothing on success: a UserPromptSubmit hook's stdout is injected into the
turn's context, so silence is the only correct answer.
USAGE
module-attribute
¶
USAGE = "usage: launch.py [--url <stream-url>] [--path <hook-path>] [--agent <claude|codex>] --octomate <bin>"
config_files ¶
Project scope first, then user scope — mirroring emit.py's resolution.
configured_base ¶
The server base from the environment, then the config files in scope order. A file that does not parse counts as absent — the emit hook on the same event reports it.
Source code in cli/octomate_cli/launch.py
stream_url ¶
The pinned stream URL, or one derived from the resolved base — the same
http(s) → ws(s) + /stream derivation the installer's stream_url_for does,
duplicated here because this script cannot import the package.
Source code in cli/octomate_cli/launch.py
main ¶
Source code in cli/octomate_cli/launch.py
octomate_cli.streaming.files ¶
octomate claude tail / octomate codex tail — the client half of the transcript
stream.
Runs on the machine a native session lives on: watches its transcript (and the subagent files beside it), frames complete lines, and ships them raw to Octomate's stream endpoint. No parsing happens here — the server's tailer assembles the turns — so a transcript format change never needs this client updated.
The agents differ only in where a subagent's file lives. Claude keeps them under
<session-id>/subagents/, discoverable by glob and keyed by agent id. Codex writes a
child rollout as a sibling file only its content identifies, so the launcher hook
spools the exact path each SubagentStop names into a per-session file here, and the
tail ships every spooled file keyed by its basename — the server classifies each from
its own opening session_meta line, keeping even that parsing server-side.
Spawned per session by the launcher hook (launch.py), detached so the turn never
waits on it; one instance per config scope, agent and session, enforced with a file
lock the OS releases with the process. The server owns every cursor: each connect
re-asks where to resume, so this process holds no durable state and a crash anywhere
costs a re-stream, never a loss. It ends when the server says finalize (the turn
stopped or the session ended; the next prompt's launcher spawns a fresh tail), when
the session goes quiet past the idle window (drain and eof — the same bet the server
tailer's idle reclaim makes), or when the server refuses it outright (close code 1008).
FileCursor
dataclass
¶
One file's read state. Complete lines only leave through read_lines; a
trailing fragment stays unread and is re-read whole next time, so a line split
across two reads is never half-shipped.
Source code in cli/octomate_cli/streaming/files.py
read_lines ¶
New complete lines as (start, end, raw) — offsets in this file's own byte
space, end past the newline each line was framed on.
Source code in cli/octomate_cli/streaming/files.py
SessionTail
dataclass
¶
One session's cursors: the transcript's own, and one per subagent file, each seeded from the offset the server's welcome named for it.
Subagent files come from the agent's own layout. With no spool (Claude), they
appear under <session-id>/subagents/ and key by agent id. With one (Codex),
they are the sibling rollouts the spool names, keyed by basename — a label in
this machine's namespace the server classifies by content.
Source code in cli/octomate_cli/streaming/files.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
files
class-attribute
instance-attribute
¶
last_active
class-attribute
instance-attribute
¶
receipts
class-attribute
instance-attribute
¶
receipts: Queue[
StreamSnapshotStored | ConnectionClosed | ValueError
] = field(default_factory=asyncio.Queue)
discover ¶
The file keys present right now: the session itself, plus every subagent file — new children join the pump the moment they exist (or are spooled).
Source code in cli/octomate_cli/streaming/files.py
cursor ¶
Source code in cli/octomate_cli/streaming/files.py
pump
async
¶
Ship every complete new line of every file; True if anything went out.
Source code in cli/octomate_cli/streaming/files.py
snapshot ¶
Read an already streamed range without resending the stored prefix.
Source code in cli/octomate_cli/streaming/files.py
upload_snapshot
async
¶
Upload only new transcript bytes and require their acknowledgment.
Source code in cli/octomate_cli/streaming/files.py
tail_path ¶
Lock/spool basename scoped by config location, never its URL or contents.
Source code in cli/octomate_cli/streaming/files.py
stream_session
async
¶
stream_session(
url: str,
session_id: str,
transcript_path: Path,
cwd: str,
token: str,
spool: Path | None = None,
) -> bool
One connection's life. True when the session is done (the server said finalize, or it went idle and drained out); False to reconnect and resume.
Source code in cli/octomate_cli/streaming/files.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
run_tail
async
¶
run_tail(
url: str,
session_id: str,
transcript_path: Path,
cwd: str,
token: str,
spool: Path | None = None,
) -> None
The reconnect loop around stream_session: resume after drops, back off while
the server is unreachable, and stop retrying once the session itself has gone
quiet — a fresh session's launcher starts a fresh tail.
Source code in cli/octomate_cli/streaming/files.py
main ¶
main(
*,
agent: Literal["claude", "codex"],
session_id: str,
transcript_path: Path,
url: str,
cwd: str,
agent_path: Path | None = None,
) -> None
Source code in cli/octomate_cli/streaming/files.py
octomate_cli.streaming.deepseek ¶
octomate deepseek tail — the client half of the dsh event stream.
Runs on the machine a native dsh session lives on, but unlike the Claude and
Codex tails it opens no file: dsh's session log is zstd-framed and only
advances at checkpoints, while the harness's own /api gateway serves it
decoded and unpacked (session/follow and session/page) — cold sessions included, other dsh
processes under the same $DSH_HOME included. So this client reads the local
gateway and ships each history entry as one framed line to Octomate's stream
endpoint, the event's dense seq standing where a file tail's byte offsets
stand (start = seq, end = seq + 1). The server assembles the turns; the
server never speaks to this machine's dsh.
One safety rule is the only interpretation this client performs beyond
framing: for a session whose last turn is still open, the gateway's reader
synthesizes turn/end {reason: interrupted} closers in memory — and if the
session's own process later completes the turn, the log's real events land on
those same seqs with different content. Shipping the synthesis would advance
the cursor past seqs whose truth is not yet written. So a fetch whose final
event is an interrupted turn/end withholds everything from that turn's
turn/start on; the next poll re-reads, and the turn ships once anything
follows it — a successor event is the proof the closers are the log's own.
Spawned per session by the launcher hook (launch.py), detached; one
instance per config scope, agent and session via the same flock the file tails use.
The server owns the cursor: each connect re-asks where to resume (the committed
floor), so this process holds no durable state. It ends on the server's finalize (a
Stop settled), on the idle window, or on a policy refusal (close 1008, such
as a stale protocol).
DshCompatibilityError ¶
DshHistoryClient ¶
One authenticated cookie session for native history reads.
Source code in cli/octomate_cli/streaming/deepseek.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
opener
instance-attribute
¶
opener: OpenerDirector = urllib.request.build_opener(
urllib.request.HTTPCookieProcessor(self.cookies)
)
rpc ¶
Source code in cli/octomate_cli/streaming/deepseek.py
snapshot ¶
Source code in cli/octomate_cli/streaming/deepseek.py
event_of ¶
seq_of ¶
new_entries ¶
The session's history entries at or past cursor, in seq order — pages
walked back from the tail until the window reaches the cursor.
Source code in cli/octomate_cli/streaming/deepseek.py
reason_kind ¶
Source code in cli/octomate_cli/streaming/deepseek.py
shippable ¶
The prefix safe to ship: everything, unless the fetch ends on an
interrupted turn/end — possibly the reader's in-memory synthesis for a
turn another process is still writing — in which case the whole trailing
turn (its turn/start on) is withheld for a later poll to prove out.
Source code in cli/octomate_cli/streaming/deepseek.py
session_origin ¶
Source code in cli/octomate_cli/streaming/deepseek.py
stream_session
async
¶
stream_session(
url: str,
session_id: str,
transcript_path: Path,
cwd: str,
token: str,
dsh_url: str,
) -> bool
One connection's life. True when the session is done (the server said finalize, or it went idle); False to reconnect and resume.
Source code in cli/octomate_cli/streaming/deepseek.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
run_tail
async
¶
run_tail(
url: str,
session_id: str,
transcript_path: Path,
cwd: str,
token: str,
dsh_url: str,
) -> None
The reconnect loop around stream_session, mirroring the file tails':
resume after drops, back off while the server is unreachable, stop once
the session goes quiet — the next prompt's launcher starts a fresh tail.