agentcrumbs

Timing and assertions

time(), timeEnd(), snapshot(), and assert()

crumb.time(label) / crumb.timeEnd(label, data?)

Measure the duration of an operation.

crumb.time("db-query"); // @crumbs
const rows = await db.query("SELECT * FROM users");
crumb.timeEnd("db-query", { rowCount: rows.length }); // @crumbs
// Emits: { msg: "db-query", type: "time", data: { rowCount: 42, duration: 12.5 } }

Parameters

time(label)

ParameterTypeDescription
labelstringTimer label (must match between time and timeEnd)

timeEnd(label, data?)

ParameterTypeDescription
labelstringTimer label (must match time)
dataunknownOptional data to include with the timing crumb

crumb.snapshot(label, obj)

Capture a point-in-time snapshot of an object using structuredClone. The snapshot is independent of future mutations to the original object.

crumb.snapshot("state-before", complexObject); // @crumbs
mutate(complexObject);
crumb.snapshot("state-after", complexObject); // @crumbs

Parameters

ParameterTypeDescription
labelstringLabel for the snapshot
objunknownObject to snapshot (cloned via structuredClone)

crumb.assert(condition, msg)

Debug-only assertion. Emits a crumb when the condition is falsy. Never throws. This is for debug tracing, not validation.

crumb.assert(user != null, "user should exist after auth"); // @crumbs
crumb.assert(items.length > 0, "cart should not be empty"); // @crumbs

Parameters

ParameterTypeDescription
conditionunknownCondition to check
msgstringMessage emitted when condition is falsy

On this page