Skip to main content

History core

Parse, index and hydrate turn logs without importing the agent runtime.

source

hydrate_turns

def hydrate_turns(
    cfg, turns
):

Restore whole results and prompts from confined details files. A missing or unreadable file leaves clipped text.


source

request_title

def request_title(
    prompt, n:int=80
):

A session’s title from its first request: the first sentence of request_body, in at most n characters.


source

request_body

def request_body(
    prompt
):

request_text without the harness’s blocks, or a <user-request> tag a prompt cut short kept.


source

request_text

def request_text(
    prompt
):

The person’s request, without the notebook or screen context composed around it.


source

labeled_rows

def labeled_rows(
    rows, legacy_n:int=0, legacy_last:NoneType=None, key:function=<lambda>
):

Yield (session_id, item) for each item of rows whose row is key(item), with legacy ids inferred and rows with invalid timestamps skipped.


source

history_rows

def history_rows(
    path, offset:int=0
):

Yield (start, end, row) for each complete object row from offset.

A history index skips rows whose timestamps are not numeric.

rows = [
    (0, 10, {'session': 'bad', 'at': 'later', 'prompt': 'skip me'}),
    (10, 20, {'session': 'kept', 'at': 2, 'prompt': 'Keep this turn'}),
]
indexed = _index_rows(rows)
assert list(indexed) == ['kept']
indexed['kept']