Merge main; align lint and skill practices with essential memory/history and the four graded examples
This commit is contained in:
@@ -85,6 +85,13 @@ const (
|
||||
// shared list metadata (colour, star, title) changes, carrying the updated
|
||||
// registry row in ChatSession, so each device's list updates live.
|
||||
ChatSessionChanged = "chat_session_changed"
|
||||
// ChatActivityChanged is pushed to every open connection (not only the
|
||||
// session's room subscribers) when a chat's live activity changes: its turn
|
||||
// starts or ends, or its count of running background tasks changes. The
|
||||
// body is ChatActivity. It is sent on those transitions only, never per
|
||||
// output chunk; a client applies a push only when its Seq is newer than the
|
||||
// activity it already holds for that session.
|
||||
ChatActivityChanged = "chat_activity"
|
||||
// ChatSubscribe attaches a connection to one session's shared live stream so
|
||||
// it receives every frame any client's turn produces (its own and the other
|
||||
// devices'), not only the frames of a turn it prompted itself. Any number of
|
||||
@@ -320,6 +327,26 @@ type ChatSession struct {
|
||||
// the operator started a fresh session. Clients replace the row with that
|
||||
// id by this one; it is never part of a listed row.
|
||||
PreviousID string `json:"previous_id,omitempty"`
|
||||
// Activity is the server's live view of the session. A server that tracks
|
||||
// it sets it on every chat_sessions row (its presence, even as an empty
|
||||
// object, tells a client the server also pushes chat_activity). Older
|
||||
// servers omit it.
|
||||
Activity *ChatActivity `json:"activity,omitempty"`
|
||||
}
|
||||
|
||||
// ChatActivity is one session's live activity as the server observes it: a
|
||||
// turn in flight, and how many background tasks (shells, background commands,
|
||||
// subagents) the harness reports still running. It rides on chat_sessions rows
|
||||
// and is pushed as chat_activity. Seq orders one session's snapshots across
|
||||
// the list reply and the pushes (a later snapshot has a larger Seq, also
|
||||
// across a server restart); a client keeps the snapshot with the largest Seq.
|
||||
// Background tasks are counted only while the server observes the session's
|
||||
// stream, so an unobserved session reports none rather than a stale count.
|
||||
type ChatActivity struct {
|
||||
SessionID string `json:"session_id,omitempty"`
|
||||
TurnRunning bool `json:"turn_running,omitempty"`
|
||||
BackgroundTasks int `json:"background_tasks,omitempty"`
|
||||
Seq int64 `json:"seq,omitempty"`
|
||||
}
|
||||
|
||||
// Chat export formats accepted by chat_export.
|
||||
|
||||
@@ -199,6 +199,8 @@ type Message struct {
|
||||
// requests themselves ride on ChatQuery (the session id), matching
|
||||
// chat_messages/chat_interrupt.
|
||||
ChatClose *ChatCloseResult `json:"chat_close,omitempty"`
|
||||
// ChatActivity is the chat_activity push: one session's live activity.
|
||||
ChatActivity *ChatActivity `json:"chat_activity,omitempty"`
|
||||
// ChatAnswer is the chat_answer body; the form update arrives through the
|
||||
// normal chat_event stream.
|
||||
ChatAnswer *ChatAnswerRequest `json:"chat_answer,omitempty"`
|
||||
|
||||
+75
-10
@@ -1,6 +1,9 @@
|
||||
package protocol
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RunPipeline = "run_pipeline"
|
||||
@@ -197,6 +200,14 @@ type RunSummary struct {
|
||||
// session directories and an estimate of its database rows. It is cached
|
||||
// server-side; 0 means not measured yet (a background backfill fills it).
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
// Usage is the totalled reported usage of the run's model stages. The run
|
||||
// list sums it with one SQL aggregate per batch over the stored per-stage
|
||||
// usage rows; the run detail sums the same rows in one pass over its loaded
|
||||
// steps (TotalUsage). It is absent for a run with no model usage recorded
|
||||
// (including historical runs and servers predating the list aggregate), so
|
||||
// a client shows nothing rather than zero. A total is partial when
|
||||
// TokensKnownStages < Stages.
|
||||
Usage *RunUsage `json:"usage,omitempty"`
|
||||
}
|
||||
|
||||
// RunGraphVisit contains only routing and lifecycle facts, never private step
|
||||
@@ -317,6 +328,14 @@ type StageUsage struct {
|
||||
SplitKnown bool `json:"split_known,omitempty"`
|
||||
CostUSD float64 `json:"cost_usd,omitempty"`
|
||||
CostKnown bool `json:"cost_known"`
|
||||
// TokensReasoning, CacheRead and CacheWrite are the remaining components of
|
||||
// a split report (TokensTotal = in + out + reasoning + cache read + cache
|
||||
// write). They are recorded only when CacheKnown; a row stored before they
|
||||
// were kept has CacheKnown=false, so its absent counts are unknown, not zero.
|
||||
TokensReasoning int64 `json:"tokens_reasoning,omitempty"`
|
||||
CacheRead int64 `json:"cache_read,omitempty"`
|
||||
CacheWrite int64 `json:"cache_write,omitempty"`
|
||||
CacheKnown bool `json:"cache_known,omitempty"`
|
||||
}
|
||||
|
||||
// RunUsage is the totalled reported usage of a run's model stages. It is summed
|
||||
@@ -336,6 +355,41 @@ type RunUsage struct {
|
||||
SplitUnknownStages int `json:"split_unknown_stages,omitempty"`
|
||||
CostKnownStages int `json:"cost_known_stages"`
|
||||
CostUnknownStages int `json:"cost_unknown_stages,omitempty"`
|
||||
// TokensReasoning, CacheRead and CacheWrite sum the stages that recorded the
|
||||
// component split (CacheKnownStages). CacheKnown is true only when every
|
||||
// token-reporting stage did, so fresh (total minus cache read) versus cached
|
||||
// is never presented from a partial split.
|
||||
TokensReasoning int64 `json:"tokens_reasoning,omitempty"`
|
||||
CacheRead int64 `json:"cache_read,omitempty"`
|
||||
CacheWrite int64 `json:"cache_write,omitempty"`
|
||||
CacheKnown bool `json:"cache_known,omitempty"`
|
||||
CacheKnownStages int `json:"cache_known_stages,omitempty"`
|
||||
}
|
||||
|
||||
// RunWarnings derives the run-level warnings from its steps: every visit whose
|
||||
// retained file-change capture was partial or unavailable is named, because
|
||||
// such evidence is not a complete workspace diff and must never be read as "no
|
||||
// edits". Steps with no capture (historical, human or server-skip visits) are
|
||||
// not flagged here; their File changes section already says "not recorded".
|
||||
func RunWarnings(steps []RunStep) []string {
|
||||
var visits []string
|
||||
for _, step := range steps {
|
||||
if step.FileChanges == nil || step.FileChanges.Status == "complete" {
|
||||
continue
|
||||
}
|
||||
visits = append(visits, fmt.Sprintf("%s #%d (%s)", step.Stage, step.Sequence, step.FileChanges.Status))
|
||||
}
|
||||
if len(visits) == 0 {
|
||||
return nil
|
||||
}
|
||||
const shown = 8
|
||||
list := visits
|
||||
extra := ""
|
||||
if len(list) > shown {
|
||||
extra = fmt.Sprintf(" and %d more", len(list)-shown)
|
||||
list = list[:shown]
|
||||
}
|
||||
return []string{fmt.Sprintf("File-change capture was incomplete for %d visit(s): %s%s. Recorded file changes are not a complete workspace diff, and no stage is auto-skipped after such a visit.", len(visits), strings.Join(list, ", "), extra)}
|
||||
}
|
||||
|
||||
// TotalUsage sums the per-stage usage of a run's steps into one run total. It is
|
||||
@@ -360,6 +414,12 @@ func TotalUsage(steps []RunStep) *RunUsage {
|
||||
splitComplete = false
|
||||
total.SplitUnknownStages++
|
||||
}
|
||||
if usage.CacheKnown {
|
||||
total.CacheKnownStages++
|
||||
total.TokensReasoning += usage.TokensReasoning
|
||||
total.CacheRead += usage.CacheRead
|
||||
total.CacheWrite += usage.CacheWrite
|
||||
}
|
||||
}
|
||||
if usage.CostKnown {
|
||||
total.CostKnownStages++
|
||||
@@ -372,6 +432,7 @@ func TotalUsage(steps []RunStep) *RunUsage {
|
||||
return nil
|
||||
}
|
||||
total.SplitKnown = total.TokensKnownStages > 0 && splitComplete
|
||||
total.CacheKnown = total.TokensKnownStages > 0 && total.CacheKnownStages == total.TokensKnownStages
|
||||
return total
|
||||
}
|
||||
|
||||
@@ -400,11 +461,15 @@ type StageFileChanges struct {
|
||||
}
|
||||
|
||||
type FileChange struct {
|
||||
Path string `json:"path"`
|
||||
Kind string `json:"kind"` // added, modified, deleted
|
||||
Patch string `json:"patch,omitempty"`
|
||||
Binary bool `json:"binary,omitempty"`
|
||||
Truncated bool `json:"truncated,omitempty"`
|
||||
Path string `json:"path"`
|
||||
Kind string `json:"kind"` // added, modified, deleted
|
||||
Patch string `json:"patch,omitempty"`
|
||||
Binary bool `json:"binary,omitempty"`
|
||||
Truncated bool `json:"truncated,omitempty"`
|
||||
// NoPatch marks a change listed without any patch: the content exceeded the
|
||||
// capture budget (compared by hash) or the change was seen only in Git
|
||||
// status. Truncated is also set so older readers show "patch omitted".
|
||||
NoPatch bool `json:"no_patch,omitempty"`
|
||||
BeforeMode string `json:"before_mode,omitempty"`
|
||||
AfterMode string `json:"after_mode,omitempty"`
|
||||
}
|
||||
@@ -433,10 +498,10 @@ type RunDetail struct {
|
||||
Input map[string]any `json:"input"`
|
||||
Output map[string]any `json:"output"`
|
||||
Steps []RunStep `json:"steps"`
|
||||
// Usage is the totalled reported usage of the run's model stages, summed in
|
||||
// one pass over Steps. It is absent for a run with no model usage recorded
|
||||
// (including historical runs).
|
||||
Usage *RunUsage `json:"usage,omitempty"`
|
||||
// Warnings are run-level, read-time notes an operator should see before
|
||||
// trusting the evidence, e.g. that a visit's file-change capture was partial.
|
||||
// Derived from Steps by RunWarnings; absent when there is nothing to flag.
|
||||
Warnings []string `json:"warnings,omitempty"`
|
||||
// TitleSource is "model" when Title came from the shared summariser or
|
||||
// "fallback" when it was derived from the prompt; TitleModel names the model
|
||||
// that produced a model title. They are retained so a diagnosis can tell the
|
||||
|
||||
@@ -37,6 +37,12 @@ type UsageTotals struct {
|
||||
SplitUnknownStages int `json:"split_unknown_stages,omitempty"`
|
||||
CostKnownStages int `json:"cost_known_stages"`
|
||||
CostUnknownStages int `json:"cost_unknown_stages,omitempty"`
|
||||
// The cache/reasoning components, as in RunUsage.
|
||||
TokensReasoning int64 `json:"tokens_reasoning,omitempty"`
|
||||
CacheRead int64 `json:"cache_read,omitempty"`
|
||||
CacheWrite int64 `json:"cache_write,omitempty"`
|
||||
CacheKnown bool `json:"cache_known,omitempty"`
|
||||
CacheKnownStages int `json:"cache_known_stages,omitempty"`
|
||||
}
|
||||
|
||||
type UsageStats struct {
|
||||
|
||||
Reference in New Issue
Block a user