Importing agent logs
detect and import read the tool call logs that agent frameworks write, as well as the native trace format. A log records the tool, the arguments and the result of each call, and no log records whether a call moved the work forward, so westering derives that progress flag from the recorded results under a rule you can name.
The repository carries three synthetic logs under examples/logs, each written for this repository and each showing a stall.
| Log | Shape | Stall |
|---|---|---|
openai_chat.json | One OpenAI Chat Completions request with its messages and declared tools | The same search repeated with the same empty result, a loop |
codex_session.jsonl | OpenAI Responses items wrapped under payload, as a Codex session file holds them | The same patch reapplied and the same failing test rerun, a two call cycle |
claude_code_session.jsonl | Anthropic messages wrapped under message, as a Claude Code transcript holds them | Grep searches under new patterns that all find nothing while Glob and Read go unused, a fixation |
Detect a stall in a log
Name the format, or let auto decide from the file.
$ ./target/debug/westering detect --trace examples/logs/claude_code_session.jsonl --format auto
{
"detections": [
{
"detail": "tool Grep made 4 of 4 calls with no progress while Glob, Read went unused",
"evidence_span": {
"end_step": 6,
"start_step": 3
},
"pattern": [
"Grep"
],
"shape": "tool_fixation",
"trace_id": "claude_code_session"
}
],
"trace_id": "claude_code_session"
}
The trace id is the file name without its last extension. The steps count the tool calls from zero in the order the log records them.
With no --format, detect reads the native trace format, exactly as it did before logs were supported.
$ ./target/debug/westering detect --trace examples/logs/claude_code_session.jsonl; echo "exit $?"
error: trace file is not valid JSON, examples/logs/claude_code_session.jsonl
exit 2
See the trace a log imports to
import prints the native trace a file reads as, the document detect reads, so an imported log can be inspected, kept, and run again. Its format defaults to auto. The first events of the Codex style log show how each call reads.
$ ./target/debug/westering import --trace examples/logs/codex_session.jsonl | head -n 14
{
"events": [
{
"call": "shell(command=[\"cargo\", \"test\", \"parser\"])",
"progress": true,
"step": 0,
"tool": "shell"
},
{
"call": "apply_patch(\"*** Begin Patch\\n*** Update File: src/parser.rs\\n@@ fn read...[138 chars 69fb0db10061b1d6])",
"progress": true,
"step": 1,
"tool": "apply_patch"
},
The call text is the tool name followed by its arguments in parentheses. Named arguments stand as name=value in sorted name order with each value as JSON text, and arguments that are not a JSON object stand as one value. A name of ASCII letters, digits, underscores, hyphens and full stops stands bare, and any other name stands as its JSON text, so {"a=1, b": 2} reads t("a=1, b"=2) and never as the two arguments t(a=1, b=2). A value whose JSON text runs past 80 characters shows its first 60 characters, three dots, and in brackets its length and its 64 bit FNV-1a digest, so two different long values read differently unless their digests collide. A float that is not finite shows as NaN, Infinity or -Infinity.
Each call id is read once. A record that names a call id seen earlier in the file, the shape of a streamed message written once per content block, adds no second call, so a log that gives one id to two different calls reads as one call. A call whose id is empty has no id, so it adds its own call and matches no result.
The goal of the imported trace is the first user message that carries words of its own, and its available tools are the tools the log declares, or every tool it calls when it declares none. Detect reads the output of import back to the same detections it gives on the log.
Formats
--format | Reads |
|---|---|
trace | The native trace format, the detect default |
openai | Chat Completions tool_calls and tool messages, and Responses function_call, custom_tool_call and their output items, in one JSON document or in JSON Lines |
anthropic | tool_use blocks in assistant messages and tool_result blocks in user messages, with is_error read as a failed call, in one JSON document or in JSON Lines |
auto | A native trace when the file is one object holding trace_id and events, then anthropic when the anthropic reader finds a tool call in it, then openai when the openai reader finds one, the import default |
A JSON Lines record wrapped under message, as Claude Code transcripts write it, or under payload with the type response_item, as Codex session files write it, is unwrapped first.
Progress rules
--progress names how a logged call counts as progress, and it applies only to an imported format.
--progress | A call makes progress when |
|---|---|
tool-result, the default | its result differs from every earlier result of the same tool |
call-result | no earlier call with the same call text returned the same result |
Under both rules a call whose result is marked as an error makes no progress, and so does a call with no result in the log. The rules can disagree. Under call-result every Grep in the Claude Code style log is a new call, so none of them repeats and no stall is found.
$ ./target/debug/westering detect --trace examples/logs/claude_code_session.jsonl --format auto --progress call-result
{
"detections": [],
"trace_id": "claude_code_session"
}
A progress rule beside the trace format is refused.
$ ./target/debug/westering detect --trace examples/looping_trace.json --progress call-result; echo "exit $?"
error: progress applies only to an imported format, not to the trace format
exit 2
Refusals
Each refusal prints one line on standard error and nothing on standard output. A log file that cannot be read, is not UTF-8, is neither one JSON document nor JSON Lines, or carries a later line that does not parse is refused at exit status 2, and so is a log with no tool call in the named format. A log nested past the reader ceiling is refused at exit status 1, as a trace file is.
$ ./target/debug/westering detect --trace examples/logs/claude_code_session.jsonl --format openai; echo "exit $?"
error: log holds no tool calls in the openai format, examples/logs/claude_code_session.jsonl
exit 2
Under auto a file that is none of the three is refused.
$ printf '{"note": "no calls here"}' > target/neither.json && ./target/debug/westering import --trace target/neither.json; echo "exit $?"
error: log file is in no format auto reads, target/neither.json
exit 2
Your own logs
Codex and Claude Code each keep one JSON Lines file per session in their own data directory, and an application built on the OpenAI or Anthropic APIs can write its request messages to a file. Point detect at such a file with --format auto. Keep real logs out of this repository, as the contributing guide asks. The MCP server reads the same formats through its detect tool.