package wire import "time" // Connections (Equipo Connections spec §§2, 7, slice 1). A connection is // one signed-in account on one runner, owned by one person. The instance // holds this record and never a secret: no key, token, credential or path // field exists on any connection type (TestConnectionTypesCarryNoSecrets). // Connection states. const ( ConnConnecting = "connecting" ConnHealthy = "healthy" ConnLimited = "limited" ConnSignInAgain = "sign_in_again" ConnError = "error" ConnSignedOut = "signed_out" // ConnForgotten is only ever an event's: the person removed a record // the runner no longer holds, and clients drop it. ConnForgotten = "forgotten" ) // Providers and kinds a slice 1 connection may have. const ( ProviderClaude = "claude" ProviderCodex = "codex" KindSubscription = "subscription" ) // Prompt kinds on a connecting card: a device code to enter at URL, or // Claude's sign-in link whose code comes back sealed (PromptAuthorize). const ( PromptDeviceCode = "device_code" // PromptAuthorize is Claude's sign-in with no terminal (Paul, // 2026-11-10): the runner runs the unmodified `claude setup-token` // itself and shows the authorize URL the CLI prints; the person signs // in at Anthropic, which shows a one-time code; the page seals the // code to the runner (EndpointClaudeCode, Attempt the prompt's), and // the runner types it into the waiting CLI. The token the CLI prints // is kept as a pasted one is. A Claude Connect with Kind subscription // starts it; the record is kind subscription // while it connects and kind token once healthy. With no URL and // Attempt 0 the runner is starting the CLI; with no URL and an // Attempt, that attempt's code was sent and the runner is finishing. PromptAuthorize = "authorize_link" ) // MaxCodeAttempts bounds the codes one sign-in attempt takes: a wrong // code asks for another (the same link while the CLI waits, a new link // when it had to start again), up to this many. const MaxCodeAttempts = 5 // ConnectReasons end a connection attempt in error. Never provider text. var ConnectReasons = map[string]bool{ "": true, "timed_out": true, "cancelled": true, "provider_refused": true, "runner_offline": true, "identity_mismatch": true, "already_connected": true, // An API-key connection: the provider refused the key, or listed no // model Equipo can price (ProtocolMetered). "key_refused": true, "no_priced_model": true, // A Mac worker keeps only Claude token connections (slice F, // ProtocolMacEngineering): any other kind is refused with this. ReasonMacClaudeOnly: true, } // ConnectionCommands are the instance's commands about a runner's // connections. A worker takes them, and says anything of its // connections, only at ProtocolMacEngineering. var ConnectionCommands = map[string]bool{FrameConnect: true, FrameCancelConnect: true, FrameDisconnect: true, FrameSecret: true, FrameCheck: true, FramePreference: true, FrameModel: true, FrameModels: true, FrameBudget: true, FrameResumeSpend: true} // ReasonMacClaudeOnly ends an attempt a Mac worker does not take: only // Claude, by a pasted token or its own sign-in, runs on a Mac. const ReasonMacClaudeOnly = "mac_claude_only" // EventConnection fires on every state or headroom change of one of the // person's connections; Data is the Connection. const EventConnection = "connection" // Window is one provider rate-limit window as the provider reported it: // Codex gives a primary and a secondary window, Claude one per kind. type Window struct { Name string `json:"name"` UsedPercent float64 `json:"used_percent"` Minutes int64 `json:"minutes"` ResetsAt *time.Time `json:"resets_at"` } // Headroom is what the provider reported and nothing else. Utilization is // 0 to 1 (null when unreported); ResetsAt is when a limited connection // may answer again (null when the provider did not say). CheckedAt is // when the runner took the reading (ProtocolReadings; absent from an // older runner). Fetched distinguishes a Claude OAuth read from a turn. type Headroom struct { Utilization *float64 `json:"utilization"` ResetsAt *time.Time `json:"resets_at"` Windows []Window `json:"windows"` CheckedAt *time.Time `json:"checked_at,omitempty"` // ProtocolUsageRefresh. Unavailable leaves any last reading intact. Fetched bool `json:"fetched,omitempty"` Unavailable bool `json:"unavailable,omitempty"` } // ConnectPrompt is what a connecting card shows: Kind is a Prompt* // constant; URL is the provider's own page and Code the provider's // display code (device code only). Neither is a secret. For // PromptAuthorize, Attempt is the code attempt the page seals for (from // 1) and WrongCode says the last code did not work. type ConnectPrompt struct { Kind string `json:"kind"` URL string `json:"url"` Code string `json:"code"` Attempt int64 `json:"attempt,omitempty"` WrongCode bool `json:"wrong_code,omitempty"` // Models are the models the provider listed for a pasted API key, // that Equipo can price (PromptModel): the person picks one. Models []string `json:"models,omitempty"` // Choices are every model the key listed, each saying whether it can // be allowed (priced and tiered), for the models card // (PromptModels, ProtocolModels): the person ticks the allowed set. Choices []ModelChoice `json:"choices,omitempty"` } // Connection is GET /api/v1/connections/{id}: one of the person's own // connections. LocalID is the runner's name for it (its account home), // empty while an attempt is connecting. type Connection struct { ID string `json:"id"` Revision int64 `json:"revision"` RunnerID string `json:"runner_id"` LocalID string `json:"local_id"` Provider string `json:"provider"` Kind string `json:"kind"` Label string `json:"label"` State string `json:"state"` Reason string `json:"reason"` Plan string `json:"plan"` Headroom *Headroom `json:"headroom"` Prompt *ConnectPrompt `json:"prompt"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` // ExpiresAt is when the connection's own credential expires (a pasted // setup token), null when it renews itself. ExpiresEstimated: the // date is an estimate (neither the token nor the CLI says it). ExpiresAt *time.Time `json:"expires_at"` ExpiresEstimated bool `json:"expires_estimated"` // An API-key connection (KindAPIKey, ProtocolMetered): its harness, // its provider's origin, how it is billed, its one model, when the // person confirmed the provider-side limit and, for a subscription // that can bill overflow, that pay-as-you-go is off; its soft budget // and spend as the runner holds them, and BudgetPending while a // budget change waits for the runner to apply it. Harness string `json:"harness,omitempty"` Upstream string `json:"upstream,omitempty"` Billing string `json:"billing,omitempty"` Model string `json:"model,omitempty"` LimitConfirmedAt *time.Time `json:"limit_confirmed_at,omitempty"` PaygOffConfirmedAt *time.Time `json:"payg_off_confirmed_at,omitempty"` Budget *Budget `json:"budget,omitempty"` Spend *Spend `json:"spend,omitempty"` BudgetPending bool `json:"budget_pending,omitempty"` // Models is the allowed set of a metered connection (ProtocolModels, // §16.1): every model its key listed, whether the person allows it, // whether the runner applied that, and its state there. // ModelsRevision is the set's revision; ModelsPending while the // runner has not applied it. ModelsTooOld: the runner is below // ProtocolModels, so the set cannot change. Models []ConnectionModel `json:"models,omitempty"` ModelsRevision int64 `json:"models_revision,omitempty"` ModelsPending bool `json:"models_pending,omitempty"` ModelsTooOld bool `json:"models_too_old,omitempty"` } // ConnectionList is GET /api/v1/connections: the person's own, every runner. type ConnectionList struct { Items []Connection `json:"items"` } // Connect is POST /api/v1/connections. RunnerID empty means the person's // primary runner. SameMachine is refused when true: the sign-in finished // at the runner's machine is gone (2026-11-10); the field stays so the // documents keep their shape. type Connect struct { Provider string `json:"provider"` Kind string `json:"kind"` RunnerID string `json:"runner_id"` SameMachine bool `json:"same_machine"` // An API-key connection (KindAPIKey) needs LimitConfirmed when it is // metered, and may carry PaygOffConfirmed only for a subscription // that can bill overflow (APIKeyProvider.CheckConfirmations). Budget // is a metered connection's day and month figures, both required. LimitConfirmed bool `json:"limit_confirmed,omitempty"` PaygOffConfirmed bool `json:"payg_off_confirmed,omitempty"` Budget *Budget `json:"budget,omitempty"` } // Frames for connections. const ( // FrameConnect (instance to runner, durable) starts an attempt. FrameConnect = "connect" // FrameCancelConnect (instance to runner, durable) ends one. FrameCancelConnect = "cancel_connect" // FrameConnection (runner to instance, durable) reports an attempt's // progress or a connection's change of state. FrameConnection = "connection" // FrameDisconnect (instance to runner, durable) signs a connection out. FrameDisconnect = "disconnect" // FramePreference (instance to runner, durable) carries the person's // preference, so the runner's choice has it offline. FramePreference = "preference" ) // Preferences is GET and PUT /api/v1/connections/preference: the provider the // person prefers to answer, "" for Automatic. A preference orders the // choice among connections that can answer now; it never overrides // health, and a coordinator session moves to it only at the start of a // turn (spec §3, "The preference"). Slice 1 keeps one per person, by // provider; per-role rows come with routing (slice 3). Revision is the // one the change was made against on PUT. type Preferences struct { Provider string `json:"provider"` Revision int64 `json:"revision"` // Until ends the preference by itself (protocol 14); absent: no end. // Once it passes the preference is Automatic again. Until *time.Time `json:"until,omitempty"` } // PreferenceProviders are the values Preferences.Provider may take. var PreferenceProviders = map[string]bool{"": true, "claude": true, "codex": true} // EventPreference fires when the person's preference changes; Data is // the Preferences. const EventPreference = "preference" // PreferenceCommand is the person's preference for the runner. A command // with a revision below the one the runner holds changes nothing. type PreferenceCommand struct { Person string `json:"person"` Provider string `json:"provider"` Revision int64 `json:"revision"` // Until (protocol 14): the preference ends by itself then. Encode // refuses a preference with an end below 14. Until *time.Time `json:"until,omitempty"` } // DisconnectCommand signs one of the person's connections out: the // harness's own logout, the home deleted, the binding gone. The runner // answers with a connection report in state signed_out. type DisconnectCommand struct { Connection string `json:"connection"` Person string `json:"person"` LocalID string `json:"local_id"` // RunnerID (ProtocolMacEngineering) is the runner whose connection it // is: a runner signs out only its own (local ids repeat across // runners). Dropped below 37. RunnerID string `json:"runner_id,omitempty"` } // ConnectCommand asks the runner to connect a new account for Person. // SameMachine is always false from this instance and ignored by the // runner; it stays because every connect frame an older instance sends // carries it, and frames are parsed strictly. type ConnectCommand struct { Connection string `json:"connection"` Person string `json:"person"` Provider string `json:"provider"` Kind string `json:"kind"` SameMachine bool `json:"same_machine"` // Billing and Budget come with an API-key connection // (ProtocolMetered; Encode refuses the frame below it). Billing string `json:"billing,omitempty"` Budget *Budget `json:"budget,omitempty"` } // CancelConnectCommand ends an attempt the person cancelled. type CancelConnectCommand struct { Connection string `json:"connection"` Person string `json:"person"` } // ConnectionReport is the runner's word on one attempt (Connection is the // instance's id) or, with Connection empty, on a connection it holds // (LocalID). Reason is from ConnectReasons when State is error. type ConnectionReport struct { Connection string `json:"connection"` Person string `json:"person"` LocalID string `json:"local_id"` Provider string `json:"provider"` State string `json:"state"` Reason string `json:"reason"` Label string `json:"label"` Plan string `json:"plan"` Headroom *Headroom `json:"headroom"` Prompt *ConnectPrompt `json:"prompt"` } // HeldConnection is one connection in hello: what the runner holds for // which person, and how it stands. Replaces Account. type HeldConnection struct { LocalID string `json:"local_id"` Person string `json:"person"` Provider string `json:"provider"` Kind string `json:"kind"` Label string `json:"label"` State string `json:"state"` Plan string `json:"plan"` Headroom *Headroom `json:"headroom"` // ExpiresAt is when a pasted credential expires (absent otherwise); // ExpiresEstimated says the date is an estimate. ExpiresAt *time.Time `json:"expires_at,omitempty"` ExpiresEstimated bool `json:"expires_estimated,omitempty"` // An API-key connection's facts (ProtocolMetered): Encode drops the // connection itself below it. Harness string `json:"harness,omitempty"` Upstream string `json:"upstream,omitempty"` Billing string `json:"billing,omitempty"` Model string `json:"model,omitempty"` Budget *Budget `json:"budget,omitempty"` Spend *Spend `json:"spend,omitempty"` // The allowed set the runner applied, at ModelsRevision, with each // model's state, and every model the key listed when it was last read // (Choices; the page's list), each saying whether it can be allowed // (ProtocolModels; dropped below it). Models []ModelState `json:"models,omitempty"` ModelsRevision int64 `json:"models_revision,omitempty"` Choices []ModelChoice `json:"choices,omitempty"` } // Switched is the quiet line under a reply (or on a step) that moved to // another connection: from what, to what, and when the first one's limit // resets when the provider said (null otherwise). type Switched struct { From string `json:"from"` To string `json:"to"` Window string `json:"window"` ResetsAt *time.Time `json:"resets_at"` } // ReasonNoConnection holds a turn: nothing the person has connected can // answer now. The turn stays running (the message waits) and goes on its // own when a connection returns; the person may cancel it. const ReasonNoConnection = "no_connection" // KindToken is a Claude connection made from a pasted `claude setup-token` // OAuth token (Paul, 2026-11-09): sealed in the browser to the runner's // seal key, opened and kept only on the runner, passed to the CLI as // CLAUDE_CODE_OAUTH_TOKEN. PromptToken is its card: run the command, // approve, paste. const ( KindToken = "token" PromptToken = "token" // EndpointAnthropic is the endpoint a Claude token is bound to. EndpointAnthropic = "https://api.anthropic.com:443" // EndpointClaudeCode is what a sealed sign-in code is bound to: the // redirect of the authorize URL that made it (PromptAuthorize). A // box with it is a code, typed into the waiting CLI and never kept; // a box with EndpointAnthropic is a token. Neither is taken as the // other. EndpointClaudeCode = "https://platform.claude.com/oauth/code/callback" // SealedTTL is how long a sealed box may wait to be opened. SealedTTL = 10 * time.Minute // MaxSealedBytes caps a box (base64 included). MaxSealedBytes = 4096 // TokenLifetime estimates how long a setup token lasts from when it // is pasted: the CLI says a year when it makes one, but neither the // token nor the CLI reveals the date and the token may be older. So // the expiry is marked an estimate, and TokenRenewal, when the row // asks for a new one, is six weeks ahead. TokenLifetime = 365 * 24 * time.Hour TokenRenewal = 42 * 24 * time.Hour ) // Sealed is a secret sealed to one runner (spec §2.4): Box is // base64 (standard, padded) libsodium crypto_box_seal of a SealedPayload // to the runner's seal key; the other fields travel in the clear beside // it and the runner refuses the box when any differs from the payload // inside, when ExpiresAt has passed, when the attempt is not the one it // is running, or when it has seen (ConnectionID, Attempt) before. type Sealed struct { Box string `json:"box"` RunnerID string `json:"runner_id"` ConnectionID string `json:"connection_id"` Provider string `json:"provider"` Endpoint string `json:"endpoint"` Attempt int64 `json:"attempt"` ExpiresAt time.Time `json:"expires_at"` } // SealedPayload is what a Sealed box holds: the secret and the binding. type SealedPayload struct { Secret string `json:"secret"` RunnerID string `json:"runner_id"` ConnectionID string `json:"connection_id"` Provider string `json:"provider"` Endpoint string `json:"endpoint"` Attempt int64 `json:"attempt"` ExpiresAt time.Time `json:"expires_at"` } // FrameSecret (instance to runner, durable) carries a sealed secret for a // connection attempt the runner is running. The instance forgets the box // once the runner acks it. const FrameSecret = "secret" // SecretCommand is the sealed secret for one of the person's attempts. type SecretCommand struct { Connection string `json:"connection"` Person string `json:"person"` Sealed Sealed `json:"sealed"` } // FrameCheck (instance to runner, durable) is the person's Check again on // a connection: the runner runs its real check (for a token, one small // request), the only thing that clears a rejection besides an answered // run. The outcome comes back as the connection's state in hello. const FrameCheck = "check" // CheckCommand names the connection to check. type CheckCommand struct { Connection string `json:"connection"` Person string `json:"person"` LocalID string `json:"local_id"` }