// Mutable run state shared across the state handlers. Created once per run by the loop;
// handlers read ports/limits/clock and mutate counters, the message accumulator, and the
// terminal-outcome carriers (patchDiff, report, failure). Keeping this in one place lets
// each handler file stay small and free of cross-handler imports.
import { Emitter } from "./emitter.js";
export function newCounters() {
    return {
        iterations: 0,
        modelCalls: 0,
        toolCalls: 0,
        commandExecutions: 0,
        failureAttempts: 0,
        browserNavigations: 0,
    };
}
// UTF-8 byte length of the serialised message array — the zero-dependency context-size
// proxy (ADR-0004 D3). Tokens require a model-specific tokeniser; bytes do not.
const encoder = new TextEncoder();
export function contextBytes(messages) {
    return encoder.encode(JSON.stringify(messages)).length;
}
