ForwardLineReader

works.iterative.claude.core.log.ForwardLineReader

Reads the complete lines appended to a file after a byte offset.

The region is a file the CLI is still writing. Lines are delimited by 0x0A; because no byte of a multi-byte UTF-8 sequence is ever 0x0A, splitting on the raw byte never severs a character, so each line's byte slice decodes as UTF-8 independently. A single trailing \r is stripped so a CRLF-terminated line reads the same as an LF-terminated one — the same rules BackwardLineReader reads a tail by, so a transcript read once at the end and then followed says the same thing either way.

Torn-final-line rule: bytes after the last 0x0A are a line whose terminating newline has not been written yet. They are left unread and the returned cursor stops before them, so the next read starts at that line and sees it whole once the writer finishes it. An entry is therefore never shown half-written, and never shown twice.

The cursor is the whole of what a follower has to remember: it is a byte position into an append-only file, so feeding it back is what makes reading resumable without holding on to anything that was read.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

final case class Appended(lines: Vector[String], next: Long)

What a file has grown by.

What a file has grown by.

Value parameters

lines

the complete lines between the requested offset and the region end, in file order, each without its terminating newline or a trailing \r

next

the offset to read from next: just past the last complete line, or the requested offset when nothing complete was there. Always a line start.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def linesFrom(from: Long, regionEnd: Long, blockSize: Int, readBlock: (Long, Int) => Array[Byte]): Appended

Extracts the complete lines in [from, regionEnd).

Extracts the complete lines in [from, regionEnd).

Value parameters

blockSize

how many bytes to pull per read; must be positive

from

the byte offset to read from; always a line start, being either 0 or a cursor a previous call returned

readBlock

a pure view of the underlying append-only file returning the bytes in [offset, offset + length); the reader only ever asks for ranges within [from, regionEnd)

regionEnd

exclusive upper byte bound of the region to read — the file's size as the follower last saw it

Attributes