Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRecordingLLM ¶
NewRecordingLLM wraps inner so each LLM call is appended to rec. model labels the records (cogito builds requests without a model; the underlying client fills it in), and agentID tags the source ("" for the main session).
func Preflight ¶ added in v0.7.0
Preflight reports whether a trace directory can actually be written, without keeping the file open.
It exists because a failed recorder used to be a warning the default log level discarded, so a user who asked for a trace got none and no explanation. Checking here lets app.Run refuse the run before anything is spawned, which is the only place that can produce a clean exit in TUI mode: chat.NewSession runs inside a tea.Cmd there, so its error arrives as an in-TUI banner after the UI is already up.
The probe duplicates what NewRecorder does rather than calling it, because a caller that is only asking the question must not be left holding an open file handle. It uses the same flags (never O_TRUNC), so an existing transcript is appended to rather than destroyed.
func WriteUsage ¶ added in v0.7.0
WriteUsage writes v to <dir>/usage.json, replacing any previous report.
A separate file rather than a final trace.ndjson record: Record's schema mirrors voro/claudemaster's trace.Call so the transcript stays directly consumable by that pipeline, and a summary record with no request would break it. A standalone JSON object is also simpler for a benchmark harness to read than the last line of an NDJSON stream.
Replacing rather than appending is what makes a second call safe: the session Close that calls this is not guaranteed to run once, and two objects in one file would be unparseable for the harness this exists to serve.
v is `any` rather than a concrete usage type because chat imports trace; naming chat's type here would be an import cycle.
Types ¶
type Record ¶
type Record struct {
Timestamp time.Time `json:"timestamp"`
Provider string `json:"provider"` // always "openai"
Model string `json:"model"`
AgentID string `json:"agent_id,omitempty"` // "" = main session
Method string `json:"method"` // chat_completion | ask | stream
Request *openai.ChatCompletionRequest `json:"request"`
Response *openai.ChatCompletionResponse `json:"response,omitempty"` // omitted on error
Error string `json:"error,omitempty"`
}
Record is one captured LLM call, serialized as a single NDJSON line. The first five fields mirror voro/claudemaster's trace.Call so the transcript is directly consumable by its export pipeline; Request/Response are go-openai types and therefore already in the OpenAI-chat shape that pipeline targets.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder appends LLM call records to <dir>/trace.ndjson. It is safe for concurrent use: each Record call is serialized under a mutex so lines never interleave. One unbuffered write syscall per record means a process crash leaves a valid prefix of complete lines.
func NewRecorder ¶
NewRecorder creates dir if needed and opens the transcript for appending.