Documentation
¶
Overview ¶
Package devtools is the DevTools record of the preview slots: what a slot's page did on the network and in its console, and the conditions it runs under (throttling, blocked addresses, cache). The proxy and the page's bridge write, the panel, the CLI and the MCP server read. Rings, not logs: the newest requests and console entries per slot.
Index ¶
- Constants
- Variables
- func BlockedBy(url string, patterns []string) string
- func IsOffline(t Throttle) bool
- func IsThrottled(t Throttle) bool
- func JSNumber(text string) float64
- func ParseBlocked(v any) ([]string, bool)
- func ParseServerLogQuery(q Query) (bool, int, string)
- func ToTargetText(text, slot string, target *Target) string
- type API
- func (a *API) ChangeSettings(asked string, body any) Outcome
- func (a *API) ClearLogs(asked string) Outcome
- func (a *API) Console(asked string, q ConsoleQuery) Outcome
- func (a *API) Network(asked string, q NetworkQuery) Outcome
- func (a *API) ServerLogOf(asked string, all bool, lines int) Outcome
- func (a *API) SettingsOf(asked string) Outcome
- func (a *API) Slots() SlotsView
- type BlockedChanges
- type ClearedView
- type ConsoleEntry
- type ConsoleQuery
- type ConsoleView
- type Listener
- type LogLine
- type LogSource
- type MCP
- type NetworkEntry
- type NetworkQuery
- type NetworkView
- type Outcome
- type Pacer
- type Patch
- type Query
- type Report
- type ServerLog
- type ServerLogView
- type ServerLogs
- type Settings
- type SettingsChangeView
- type SettingsView
- type SlotSummary
- type SlotsView
- type Snapshot
- type Store
- func (s *Store) Clear(slot string)
- func (s *Store) Finish(slot string, id int64, patch func(*NetworkEntry))
- func (s *Store) List() []SlotSummary
- func (s *Store) NewPacer(slot string, down bool, w io.Writer, done <-chan struct{}, onSlice func(int)) *Pacer
- func (s *Store) Read(slot string, since int64) Snapshot
- func (s *Store) RecordConsole(slot string, e ConsoleEntry)
- func (s *Store) RecordRequest(slot string, e NetworkEntry) int64
- func (s *Store) Resolve(asked string) string
- func (s *Store) SetSettings(slot string, p Patch) Settings
- func (s *Store) Settings(slot string) Settings
- func (s *Store) TakeQuota(slot string, wanted int, now int64) int
- func (s *Store) TargetOf(slot string) *Target
- func (s *Store) Touch(slot string, target Target)
- type Target
- type Throttle
Constants ¶
const ( DefaultLimit = 100 MaxLimit = 500 MaxServerLines = 1000 )
const ( MaxReportEvents = 100 MaxReportBytes = 256 * 1024 MaxEventsPerWindow = 500 )
const ( NetworkLimit = 1000 ConsoleLimit = 500 MaxBlocked = 50 MaxPattern = 300 )
const NeighbourPrefix = "/__tk/p/"
NeighbourPrefix is the path of the main slot under which neighbour ports (MFE remotes) are served.
Variables ¶
var Presets = map[string]Throttle{
"none": {"none", 0, 0, 0},
"fast-4g": {"fast-4g", 165, 9000, 1500},
"slow-4g": {"slow-4g", 563, 1600, 750},
"3g": {"3g", 2000, 400, 400},
"offline": {"offline", 0, 0, 0},
}
Presets are Chrome DevTools' own, so a number seen here means the same as there.
Functions ¶
func BlockedBy ¶
BlockedBy is the first pattern found anywhere in the full URL, case-insensitively; "" when none.
func IsThrottled ¶
func ParseBlocked ¶
ParseBlocked keeps the strings, trimmed, non-empty and not too long, once each, at most MaxBlocked; false for a value that is not a list.
func ToTargetText ¶
ToTargetText turns every slot address in a text (a URL, a message, a stack trace) into the target's: "<slot>/__tk/p/5173/x" is the neighbour's "http://localhost:5173/x". A page's report speaks of the slot; people and agents know the target.
Types ¶
type API ¶
type API struct {
Store *Store
// CLI is the command people and agents type ("acme"), named in the messages.
CLI string
// ServerLog reads the dev server's terminal of a slot.
ServerLog func(slot string, all bool, lines int) (ServerLog, error)
}
API is the agents' view of a store.
func (*API) ChangeSettings ¶
ChangeSettings applies what the panel sends (throttle, blocked, disableCache) plus blockedAdd and blockedRemove, which edit the current list in one step instead of replacing it.
func (*API) SettingsOf ¶
type BlockedChanges ¶
type ClearedView ¶
type ConsoleEntry ¶
type ConsoleQuery ¶
func ParseConsoleQuery ¶
func ParseConsoleQuery(q Query) (ConsoleQuery, string)
type ConsoleView ¶
type Listener ¶
Listener is whoever listens on a port; PID 0 for another user's process, which ss does not name.
type LogLine ¶
func ProblemLines ¶
ProblemLines is the last limit problems, each with its stack or code frame, and the successes between them, consecutive ones as one.
type LogSource ¶
func (LogSource) MarshalJSON ¶
type MCP ¶
type MCP struct {
API *API
// contains filtered or unexported fields
}
MCP is the preview DevTools' tools of the agents' MCP server (internal/mcpserver).
func (*MCP) Instructions ¶ added in v0.15.40
type NetworkEntry ¶
type NetworkEntry struct {
At int64 `json:"at"`
Source string `json:"source"`
Method string `json:"method"`
URL string `json:"url"`
Host string `json:"host"`
Type string `json:"type"`
Status *int64 `json:"status"`
Mime *string `json:"mime"`
Size *int64 `json:"size"`
DurationMs *int64 `json:"durationMs"`
ThirdParty bool `json:"thirdParty"`
Blocked bool `json:"blocked"`
Throttled bool `json:"throttled"`
Error *string `json:"error"`
ID int64 `json:"id"`
}
NetworkEntry is one request; Id grows by one per slot and is the cursor of `since`.
type NetworkQuery ¶
type NetworkQuery struct {
Since int64
Errors bool
ThirdParty bool
URL string
Types []string
Limit int
}
func ParseNetworkQuery ¶
func ParseNetworkQuery(q Query) (NetworkQuery, string)
ParseNetworkQuery is the HTTP form: since, errors=1, thirdParty=1, url, type (comma-separated), limit.
type NetworkView ¶
type Pacer ¶
type Pacer struct {
OnSlice func(int)
// contains filtered or unexported fields
}
Pacer passes a body on at the slot's rate, in slices of a quarter second at most. OnSlice sees every slice that left.
type Patch ¶
Patch is a validated partial change of a slot's settings; nil fields stay.
func ParseSettingsPatch ¶
ParseSettingsPatch validates a partial change; the error names the field in words.
type Report ¶
type Report struct {
Network []NetworkEntry
Console []ConsoleEntry
}
Report is a report's valid events.
type ServerLogView ¶
type ServerLogs ¶
type ServerLogs struct {
Store *Store
Tmux *tmux.Tmux
Listener func(port int) (*Listener, error)
// Panes and Capture default to the tmux servers': every pane by session, and a pane's text with its history.
Panes func() (map[string]tmux.PaneInfo, bool)
Capture func(session string, lines int) (string, bool)
// Outside names where a dev server should run for its output to be found (the platform's terminals).
Outside string
ProcRoot string
// contains filtered or unexported fields
}
ServerLogs reads and briefly remembers the dev server output of the slots' ports.
type Settings ¶
type Settings struct {
Throttle Throttle `json:"throttle"`
Blocked []string `json:"blocked"`
DisableCache bool `json:"disableCache"`
}
func DefaultSettings ¶
func DefaultSettings() Settings
type SettingsChangeView ¶
type SettingsChangeView struct {
Slot string `json:"slot"`
Target *Target `json:"target"`
Settings Settings `json:"settings"`
Changes BlockedChanges `json:"changes"`
}
type SettingsView ¶
type SlotSummary ¶
type SlotsView ¶
type SlotsView struct {
Slots []SlotSummary `json:"slots"`
}
type Snapshot ¶
type Snapshot struct {
Slot string `json:"slot"`
Target *Target `json:"target"`
Settings Settings `json:"settings"`
Network []NetworkEntry `json:"network"`
Console []ConsoleEntry `json:"console"`
Cursor int64 `json:"cursor"`
}
type Store ¶
type Store struct {
Now func() time.Time
// OnFailed, when set, is told every request that failed (blocked, an error, 4xx or 5xx) and OnError every console
// error, as they are recorded (the machine's journal). They are called under the store's lock: they must
// not block or call back into the store.
OnFailed func(slot string, e NetworkEntry)
OnError func(slot string, e ConsoleEntry)
// contains filtered or unexported fields
}
Store holds every slot's record of this process.
func (*Store) Finish ¶
func (s *Store) Finish(slot string, id int64, patch func(*NetworkEntry))
Finish fills in the answer of a pending request. It moves to the end of the ring with a fresh id, so `since` readers see it again once it is finished.
func (*Store) NewPacer ¶
func (s *Store) NewPacer(slot string, down bool, w io.Writer, done <-chan struct{}, onSlice func(int)) *Pacer
NewPacer writes to w at the slot's rate in that direction until done closes.
func (*Store) RecordConsole ¶
func (s *Store) RecordConsole(slot string, e ConsoleEntry)
RecordConsole adds a console entry; one identical to the last folds into it, as in Chrome.
func (*Store) RecordRequest ¶
func (s *Store) RecordRequest(slot string, e NetworkEntry) int64
RecordRequest adds an entry and returns its id.
func (*Store) Resolve ¶
Resolve is the slot the caller named, or the one the person used last: agents rarely know the slot's name.
func (*Store) SetSettings ¶
SetSettings applies a validated patch.
func (*Store) TakeQuota ¶
TakeQuota is how many of wanted events the slot may still record in this window: a page logging in a loop fills the rings with its last words, not the runtime's memory.
type Target ¶
Target is what a slot shows: a local port or an external origin.
func (Target) MarshalJSON ¶
func (Target) TargetOrigin ¶
TargetOrigin is where the slot's page really lives.