teamapi

package
v0.210.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package teamapi is the Caprock Teams channel contract: the messages a laptop that joined a Caprock Teams server exchanges with that server.

It is public and dependency-free on purpose. The laptop side lives in this repository (internal/team); the server is a separate, closed product that imports this package at a pinned version and tests against it, so the one definition of what may leave a laptop is the one in this file. Nothing in Caprock imports the server.

What may go up is fixed by construction: UsageReport has no field for a prompt, a reply, tool input or output, a command, a file or a commit message, and fields_test.go fails when any field is added until the allowlist there — and the security documentation it points to — name it.

Contract: .ai/03-contracts.md § Teams channel. Decision: ADR-120.

Index

Constants

View Source
const (
	PathHello  = "/team/v1/hello"
	PathEnrol  = "/team/v1/enrol"
	PathReport = "/team/v1/report"
	PathLeave  = "/team/v1/leave"
	PathRules  = "/team/v1/rules" // minor 1: team rules come down
)

Paths, under the server's base URL.

View Source
const (
	FeatureUsage     = "usage"     // POST /team/v1/report
	FeatureLeave     = "leave"     // POST /team/v1/leave deletes this machine's rows
	FeatureRules     = "rules"     // GET /team/v1/rules (contract 1.1)
	FeatureMemories  = "memories"  // approved team memories come down (not in 1.0)
	FeatureProposals = "proposals" // a memory may be proposed on a click (not in 1.0)
)

Features a server may announce in Hello. A laptop shows and uses only what the server it joined announces.

View Source
const (
	CodeBadToken         = "bad_token"
	CodeRevoked          = "revoked"
	CodeUnsupportedMajor = "unsupported_major"
	CodeBadRequest       = "bad_request"
)

Error codes.

View Source
const (
	MaxRules         = 200
	MaxRuleTitle     = 120
	MaxRuleText      = 4000
	MaxRuleRepoCount = 50
)

Limits a laptop enforces on what comes down, whatever the server sends.

View Source
const Major = 1

Major is the contract's major version. It is in every path; a server keeps answering an older major while any enrolled machine still reports it.

View Source
const MaxBuckets = 500

MaxBuckets is the most buckets one report may carry; a laptop pages above it.

View Source
const Minor = 1

Minor grows with each optional field added under the same major. Both sides ignore fields they do not know, so a minor never breaks either side.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	SessionID string `json:"session_id"` // the agent's own session id
	Agent     string `json:"agent"`      // "claude", "codex", "opencode", …
	Model     string `json:"model"`
	Hour      int64  `json:"hour"` // unix seconds at the start of the UTC hour

	Turns            int64   `json:"turns"`
	TokensIn         int64   `json:"tokens_in"`
	TokensOut        int64   `json:"tokens_out"`
	CacheRead        int64   `json:"cache_read"`
	CacheWrite       int64   `json:"cache_write"`
	CostUSD          float64 `json:"cost_usd"`           // at list price, from the laptop's pricing table
	UnpricedTurns    int64   `json:"unpriced_turns"`     // turns with tokens and no price: a shortfall, not zero
	RereadUSD        float64 `json:"reread_usd"`         // cache-read tokens at this model's cache-read rate
	RereadUnpriced   int64   `json:"reread_unpriced"`    // cache-read tokens of a model with no price row
	SessionStart     int64   `json:"session_start"`      // unix ms
	SessionLastEvent int64   `json:"session_last_event"` // unix ms

	// Where the work happened. Each may be hidden (hashed) or left out by the
	// user on the laptop; a hashed value is "h:" + hex SHA-256 prefix, salted
	// with the machine id so it cannot be looked up across machines.
	Repo   string `json:"repo,omitempty"`   // repository web URL, credentials stripped
	Branch string `json:"branch,omitempty"` // git branch at the session's start
	Dir    string `json:"dir,omitempty"`    // the folder's base name, never its full path
	Email  string `json:"email,omitempty"`  // git user.email of the repository, unless left out

	// Commits the session's author made in this hour (SHAs only, by commit
	// time, from `git log --author=<email>` in the repository), and the loops
	// that started in this hour. Either may be empty; a server must accept that.
	Commits []string `json:"commits,omitempty"`
	Loops   []Loop   `json:"loops,omitempty"`
}

Bucket is one session's usage of one model within one clock hour (UTC). Counters and named identifiers only — never content.

type EnrolRequest

type EnrolRequest struct {
	Token     string `json:"token"`      // the team token the admin handed out
	MachineID string `json:"machine_id"` // random, made on the laptop for this team only
	Status    Status `json:"status"`
}

EnrolRequest is POST /team/v1/enrol. The team token is used once, here, and traded for a per-machine secret, so one machine can be revoked without re-enrolling the team.

type EnrolResponse

type EnrolResponse struct {
	MachineSecret string `json:"machine_secret"` // Bearer for every later call
	Team          string `json:"team"`
}

EnrolResponse answers EnrolRequest.

type Error

type Error struct {
	Code    string `json:"code"` // bad_token, revoked, unsupported_major, bad_request, …
	Message string `json:"message"`
}

Error is the body of every non-2xx answer.

type Hello

type Hello struct {
	Product  string   `json:"product"`  // "caprock-teams"
	Version  string   `json:"version"`  // the server's build version
	Team     string   `json:"team"`     // the team's display name
	Majors   []int    `json:"majors"`   // contract majors served, e.g. [1]
	Minor    int      `json:"minor"`    // highest minor of the newest major
	Features []string `json:"features"` // Feature* values
}

Hello is GET /team/v1/hello, unauthenticated: who the server is and what it speaks. It carries nothing about any machine or person.

type LeaveRequest

type LeaveRequest struct {
	Reason string `json:"reason,omitempty"` // "user" — the person unenrolled
}

LeaveRequest is POST /team/v1/leave, Authorization: Bearer <machine secret>. The server deletes every row of this machine and forgets its secret.

type Loop

type Loop struct {
	Tool  string `json:"tool"`
	Calls int64  `json:"calls"`
	// CostUSD is what those calls paid to re-read the conversation, at
	// cache-read rates — the figure the live loop alert shows. It is not "what
	// the loop cost", which cannot be separated from the work beside it.
	// Zero when it could not be priced.
	CostUSD float64 `json:"cost_usd"`
}

Loop is a loop: which tool repeated and how often (K or more calls of one signature, each within the detector's window of the one before). Never the command or its input.

type ReportResponse

type ReportResponse struct {
	Accepted int `json:"accepted"` // buckets stored
}

ReportResponse answers UsageReport.

type Rule

type Rule struct {
	ID        string   `json:"id"`
	Title     string   `json:"title"`
	Text      string   `json:"text"`
	Repos     []string `json:"repos,omitempty"` // repository web URLs; empty: every repository
	Author    string   `json:"author,omitempty"`
	Revision  int      `json:"revision"`   // grows with each edit of this rule
	UpdatedAt int64    `json:"updated_at"` // unix ms
}

Rule is one team rule: text an agent is given at session start, in the repositories its scope names (all of the team's when Repos is empty).

type RulesResponse

type RulesResponse struct {
	Version string `json:"version"` // changes whenever any rule changes
	Rules   []Rule `json:"rules"`
}

RulesResponse is GET /team/v1/rules, Authorization: Bearer <machine secret> (contract 1.1). The server answers 304 when If-None-Match carries the current Version. Rules come down; nothing about them goes up.

type Status

type Status struct {
	CaprockVersion string   `json:"caprock_version"`
	Major          int      `json:"major"`
	Minor          int      `json:"minor"`
	OS             string   `json:"os"`                 // runtime.GOOS
	Hidden         []string `json:"hidden,omitempty"`   // which Hide* options are on: "email", "branch", "dir"
	Excluded       int      `json:"excluded,omitempty"` // how many repositories the user excluded (not which)
}

Status is sent with enrolment and every report: enough for the server to show "this machine has not reported since …" rather than read a gap as no spend. It names no person and no content.

type UsageReport

type UsageReport struct {
	Major   int      `json:"major"`
	Minor   int      `json:"minor"`
	Status  Status   `json:"status"`
	Buckets []Bucket `json:"buckets"`
}

UsageReport is POST /team/v1/report, Authorization: Bearer <machine secret>. A server upserts each bucket by (machine, session, hour, model), so a resent or corrected bucket replaces the earlier one and is counted once.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL