{"modulePath":"github.com/sneat-dev/wb","version":"v0.218.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubapp\n\nPackage githubapp defines the Workbench GitHub App control-plane API.\n\n## Constants\n\n```go\nconst (\n\t// ControlPlaneOrigin is the dedicated machine API origin.\n\tControlPlaneOrigin = \"https://wb-github-app.sneat.dev\"\n\t// ControlPlaneHost is the host-only form used by the Cloud Run adapter.\n\tControlPlaneHost = \"wb-github-app.sneat.dev\"\n\t// UIOrigin is the browser origin permitted to call the control-plane API.\n\tUIOrigin = \"https://sneat.work\"\n\t// APIPrefix is mounted by the host application.\n\tAPIPrefix = \"/v0/workbench\"\n)\n```\n\n```go\nconst (\n\tProjectionCollection  = \"workbench_projections\"\n\tSeriesCollection      = \"workbench_series\"\n\tLeaderboardCollection = \"workbench_leaderboards\"\n\tMergeCollection       = \"workbench_latest_merges\"\n)\n```\n\n```go\nconst DefaultMachineStaleAfter = 24 * time.Hour\n```\nDefaultMachineStaleAfter matches WB's ordinary remote-machine freshness window. Hosted views keep stale rows visible; this threshold only labels their last published observation.\n\n## Variables\n\n```go\nvar (\n\tErrPublisherIdentity = errors.New(\"machine publisher identity is unavailable\")\n\tErrPublisherMismatch = errors.New(\"published login or machine does not match the authenticated publisher\")\n)\n```\n\n```go\nvar (\n\tErrNoProjector       = errors.New(\"workbench projection engine is not configured\")\n\tErrInvalidProjection = errors.New(\"invalid workbench projection snapshot\")\n)\n```\n\n```go\nvar (\n\tErrPrivateData = errors.New(\"private Workbench data requires membership\")\n\tErrNoReadModel = errors.New(\"workbench read model is not configured\")\n\tErrNoWebhook   = errors.New(\"workbench webhook processor is not configured\")\n)\n```\n\n```go\nvar ErrProjectionNotFound = errors.New(\"workbench projection not found\")\n```\n\n## Functions\n\n```go\nfunc NewHandler(options HandlerOptions) http.Handler\n```\nNewHandler returns the Workbench GitHub App API under APIPrefix. It permits the Sneat Workbench browser origin only; GitHub webhooks have no CORS need.\n\n```go\nfunc ProjectionKey(scope Scope, id string) string\n```\nProjectionKey is the stable document key: scope plus a SHA-256 digest of the canonical subject ID. The digest prevents slashes in github.com/org/repo IDs from changing collection hierarchy while preserving the original ID in the document body for audit and display.\n\n```go\nfunc ValidateProjectionDocument(document ProjectionDocument) error\n```\n\n```go\nfunc ValidatePublicEligibility(evidence PublicEligibility) error\n```\nValidatePublicEligibility rejects incomplete or non-canonical durable evidence. It intentionally verifies the identity and URL shape only; the authoritative reader verifies the README contents before it records this evidence with a projection.\n\n## Types\n\n```go\ntype Access[T any] struct {\n\tVisibility Visibility\n\tValue      T\n}\n```\nAccess wraps a read-model result with its disclosure class.\n\n```go\ntype AuthoritativeProjectionReader interface {\n\tRefreshAuthoritativeProjection(context.Context, WebhookDelivery) (ProjectionSnapshot, error)\n}\n```\nAuthoritativeProjectionReader combines the freshness barrier and projection read for readers that can carry one request-scoped GitHub snapshot across the provider boundary. This avoids issuing the same REST reads twice.\n\n```go\ntype AuthoritativeReader interface {\n\tRefresh(context.Context, WebhookDelivery) error\n}\n```\nAuthoritativeReader refreshes the GitHub App's authoritative view before an action is queued. A cache hit alone must never satisfy this call.\n\n```go\ntype Dashboard struct {\n\tGeneratedAt time.Time `json:\"generated_at\"`\n\tSummary     Summary   `json:\"summary\"`\n\tLinks       []Link    `json:\"links,omitempty\"`\n\t// Fleet is the published machine and worktree projection. A self-hosted\n\t// hub serves it from its own store; a control-plane deployment without a\n\t// fleet projection omits it.\n\tFleet *FleetSnapshot `json:\"fleet,omitempty\"`\n}\n```\nDashboard is the top-level dashboard response.\n\n```go\ntype DeliveryStore interface {\n\tHasDelivery(context.Context, string) (bool, error)\n\tCommitDeliveryAndWakeup(context.Context, string, Wakeup) (bool, error)\n}\n```\nDeliveryStore must be backed by durable storage. HasDelivery is a cheap preflight that avoids repeating an authoritative GitHub read for a redelivery. CommitDeliveryAndWakeup atomically records the delivery ID and persists a wakeup coalesced by its scope key. It returns false when a concurrent request committed the same delivery first.\n\n```go\ntype DocumentProjectionDeliveryStore struct {\n\tBackend DocumentStore\n\tNow     func() time.Time\n\tLease   time.Duration\n}\n```\nDocumentProjectionDeliveryStore provides the atomic claim and coalesced wakeup used by ProjectionEngine. An expired claim is recoverable.\n\n```go\nfunc (store DocumentProjectionDeliveryStore) ClaimDelivery(ctx context.Context, id string) (bool, error)\n```\n\n```go\nfunc (store DocumentProjectionDeliveryStore) CommitDeliveryAndWakeup(ctx context.Context, id string, wakeup Wakeup) (bool, error)\n```\n\n```go\nfunc (store DocumentProjectionDeliveryStore) HasDelivery(ctx context.Context, id string) (bool, error)\n```\n\n```go\nfunc (store DocumentProjectionDeliveryStore) ReleaseDelivery(ctx context.Context, id string) error\n```\n\n```go\ntype DocumentProjectionStore struct{ Backend DocumentStore }\n```\nDocumentProjectionStore maps the documented Workbench collections to the host's document store. The adapter contains no cloud.google.com imports, keeping the provider portable and letting the host supply its configured engine.\n\n```go\nfunc (store DocumentProjectionStore) GetLeaderboard(ctx context.Context, metric string) (LeaderboardDocument, error)\n```\n\n```go\nfunc (store DocumentProjectionStore) GetProjection(ctx context.Context, scope Scope, id string) (ProjectionDocument, error)\n```\n\n```go\nfunc (store DocumentProjectionStore) ListProjections(ctx context.Context, scope Scope) ([]ProjectionDocument, error)\n```\n\n```go\nfunc (store DocumentProjectionStore) ListPublicLatestMerges(ctx context.Context, limit int) (PublicLatestMerges, error)\n```\n\n```go\nfunc (store DocumentProjectionStore) ListSeries(ctx context.Context, scope Scope, id, metric string) (SeriesDocument, error)\n```\n\n```go\ntype DocumentProjectionWriter struct{ Backend DocumentStore }\n```\nDocumentProjectionWriter applies complete batches by stable document key. Set is intentionally idempotent, so a retry after a crash cannot duplicate projections or public merges.\n\n```go\nfunc (writer DocumentProjectionWriter) WriteLatestMerges(ctx context.Context, deliveryID string, batch RepositoryLatestMerges) error\n```\n\n```go\nfunc (writer DocumentProjectionWriter) WriteOrganizations(ctx context.Context, deliveryID string, records []ProjectionDocument) error\n```\n\n```go\nfunc (writer DocumentProjectionWriter) WriteRepositories(ctx context.Context, deliveryID string, records []ProjectionDocument) error\n```\n\n```go\ntype DocumentStore interface {\n\tGet(context.Context, string, string, any) (bool, error)\n\tQuery(context.Context, string, map[string]any, int, any) error\n\tSet(context.Context, string, string, any) error\n\tUpdateAtomic(context.Context, func(DocumentTransaction) error) error\n}\n```\nDocumentStore is the deliberately small seam over a hierarchical document database. A collection is addressed by its slash-joined path (\"installations/42/chunks\"), a document by its id within it. Values are decoded into out by the store. Query takes equality filters only (a nil or empty map is an unfiltered scan) and a limit, where 0 means unbounded; out is a pointer to a slice of the document type. UpdateAtomic must provide serializable transaction semantics and may invoke its callback more than once when the storage engine retries a conflict.\n\ndalgostore.New implements it on DALgo, so the hosted instance runs on dalgo2firestore and a self-hoster picks any DALgo engine. See spec/decisions/0002-bench-open-source-and-self-hosting.md.\n\n```go\ntype DocumentTransaction interface {\n\tGet(context.Context, string, string, any) (bool, error)\n\tSet(context.Context, string, string, any) error\n\t// Delete removes one document inside the same atomic update. Provider-owned\n\t// stores need it to consume a pending installation state once it has been\n\t// transitioned or completed, and to drop acknowledged pending event\n\t// references, so that a replay cannot observe state that was already spent.\n\tDelete(context.Context, string, string) error\n}\n```\n\n```go\ntype Event struct {\n\tID         uint64          `json:\"id\"`\n\tType       EventType       `json:\"type\"`\n\tVisibility Visibility      `json:\"visibility\"`\n\tAt         time.Time       `json:\"at\"`\n\tRepository string          `json:\"repository,omitempty\"`\n\tTask       string          `json:\"task,omitempty\"`\n\tOperation  string          `json:\"operation,omitempty\"`\n\tSession    string          `json:\"session,omitempty\"`\n\tSeverity   string          `json:\"severity,omitempty\"`\n\tPayload    json.RawMessage `json:\"payload\"`\n}\n```\nEvent is an SSE record. ID is a durable monotonic cursor, not a timestamp. Payload is only serialized after the viewer passes its visibility check.\n\n```go\ntype EventFilter struct {\n\tAfter      uint64\n\tSince      time.Time\n\tRepository string\n\tTask       string\n\tOperation  string\n\tSession    string\n\tSeverity   string\n}\n```\nEventFilter selects one resumable daemon/direct-WB event sequence. Work Logs remain immutable per-task evidence; this filter is transient monitoring only.\n\n```go\ntype EventSource interface {\n\tReplay(context.Context, EventFilter) ([]Event, error)\n\tSubscribe(context.Context, EventFilter) (\u003c-chan Event, error)\n}\n```\nEventSource durably replays events strictly after a cursor, then exposes a live subscription. Implementations must retain enough history for reconnects and issue globally monotonic IDs across daemon generations.\n\n```go\ntype EventType string\n```\nEventType classifies a live Workbench daemon update. WebSocket is reserved for later bidirectional controls such as cancel and reprioritize.\n\n```go\nconst (\n\tEventQueue            EventType = \"queue\"\n\tEventJobPhase         EventType = \"job.phase\"\n\tEventJobProgress      EventType = \"job.progress\"\n\tEventCI               EventType = \"ci\"\n\tEventCleanup          EventType = \"cleanup\"\n\tEventSync             EventType = \"sync\"\n\tEventDaemonGeneration EventType = \"daemon.generation\"\n)\n```\n\n```go\ntype FleetMachine struct {\n\tName        string          `json:\"name\"`\n\tPublishedAt string          `json:\"published_at,omitempty\"`\n\tLastSeenAt  string          `json:\"last_seen_at,omitempty\"`\n\tStale       bool            `json:\"stale,omitempty\"`\n\tState       string          `json:\"state,omitempty\"`\n\tWorktrees   []FleetWorktree `json:\"worktrees\"`\n}\n```\nFleetMachine is one machine and the worktrees it published.\n\n```go\ntype FleetPullRequest struct {\n\tNumber int    `json:\"number\"`\n\tURL    string `json:\"url\"`\n\tState  string `json:\"state\"`\n}\n```\nFleetPullRequest is the browser's review link for one worktree. The browser requires a positive number, an http(s) URL and one of the four states, so a partial link is omitted entirely instead of invalidating the fleet payload.\n\n```go\ntype FleetSnapshot struct {\n\tMachines []FleetMachine `json:\"machines\"`\n}\n```\nFleetSnapshot is the optional fleet projection inside a dashboard or stat response.\n\n```go\ntype FleetWorktree struct {\n\tTask            string            `json:\"task\"`\n\tRepository      string            `json:\"repository\"`\n\tBranch          string            `json:\"branch\"`\n\tOwnerState      string            `json:\"owner_state,omitempty\"`\n\tStream          string            `json:\"stream,omitempty\"`\n\tStatus          string            `json:\"status,omitempty\"`\n\tLastActivityAt  string            `json:\"last_activity_at,omitempty\"`\n\tPullRequest     *FleetPullRequest `json:\"pull_request,omitempty\"`\n\tNeedsAttention  bool              `json:\"needs_attention,omitempty\"`\n\tAttentionReason string            `json:\"attention_reason,omitempty\"`\n}\n```\nFleetWorktree is one published worktree as the browser table renders it.\n\n```go\ntype GitHubRESTProjectionReader struct {\n\tHTTP    HTTPDoer\n\tTokens  GitHubTokenSource\n\tAPIBase string\n\tNow     func() time.Time\n}\n```\nGitHubRESTProjectionReader builds one delivery snapshot from GitHub's REST API. APIBase is injectable for a host proxy and tests; the default is the public GitHub API.\n\n```go\nfunc (reader GitHubRESTProjectionReader) Refresh(ctx context.Context, delivery WebhookDelivery) error\n```\n\n```go\nfunc (reader GitHubRESTProjectionReader) RefreshAuthoritativeProjection(ctx context.Context, delivery WebhookDelivery) (ProjectionSnapshot, error)\n```\n\n```go\nfunc (reader GitHubRESTProjectionReader) RefreshProjection(ctx context.Context, delivery WebhookDelivery) (ProjectionSnapshot, error)\n```\n\n```go\ntype GitHubTokenSource interface {\n\tToken(context.Context, WebhookDelivery) (string, error)\n}\n```\n\n```go\ntype HTTPDoer interface {\n\tDo(*http.Request) (*http.Response, error)\n}\n```\nHTTPDoer and GitHubTokenSource keep credentials and transport in the host. The reader never imports a GitHub SDK or accepts identity from a webhook payload beyond its repository/install identity.\n\n```go\ntype HandlerOptions struct {\n\tService           Service\n\tViewerResolver    ViewerResolver\n\tPublisherResolver MachinePublisherResolver\n\tMachineSnapshots  *MachineSnapshotService\n\tAllowedOrigin     string\n}\n```\nHandlerOptions supplies the narrow host bindings for the public API.\n\n```go\ntype InstallationTokenSource struct {\n\tAppID         int64\n\tPrivateKeyPEM []byte\n\tTransport     http.RoundTripper\n\tAPIBase       string\n\tNow           func() time.Time\n}\n```\nInstallationTokenSource exchanges a delivery's exact GitHub App installation identity for a short-lived installation access token. Hosts supply every credential, the HTTP transport, and the clock.\n\n```go\nfunc (source InstallationTokenSource) Token(ctx context.Context, delivery WebhookDelivery) (string, error)\n```\nToken creates a short-lived RS256 GitHub App JWT and exchanges it for the installation token identified by delivery.Payload. Errors never include the private key, JWT, installation token, or response body.\n\n```go\ntype LatestMerge struct {\n\tRepository     string    `json:\"repository\" firestore:\"repository\"`\n\tPullRequest    int       `json:\"pull_request\" firestore:\"pull_request\"`\n\tMergedAt       time.Time `json:\"merged_at\" firestore:\"merged_at\"`\n\tPullRequestURL string    `json:\"pull_request_url,omitempty\" firestore:\"pull_request_url,omitempty\"`\n\tIssueURL       string    `json:\"issue_url,omitempty\" firestore:\"issue_url,omitempty\"`\n\tMergeCommitSHA string    `json:\"merge_commit_sha,omitempty\" firestore:\"merge_commit_sha,omitempty\"`\n\tMergeCommitURL string    `json:\"merge_commit_url,omitempty\" firestore:\"merge_commit_url,omitempty\"`\n\tReleaseURL     string    `json:\"release_url,omitempty\" firestore:\"release_url,omitempty\"`\n\tReceiptURL     string    `json:\"receipt_url,omitempty\" firestore:\"receipt_url,omitempty\"`\n}\n```\nLatestMerge gives the dashboard every navigable artifact around a merge.\n\n```go\ntype Leaderboard struct {\n\tMetric  string             `json:\"metric\"`\n\tEntries []LeaderboardEntry `json:\"entries\"`\n}\n```\nLeaderboard groups ranked values for a requested metric.\n\n```go\ntype LeaderboardDocument struct {\n\tMetric     string             `json:\"metric\" firestore:\"metric\"`\n\tEntries    []LeaderboardEntry `json:\"entries\" firestore:\"entries\"`\n\tPublicOnly bool               `json:\"public_only\" firestore:\"public_only\"`\n}\n```\n\n```go\ntype LeaderboardEntry struct {\n\tRank        int    `json:\"rank\" firestore:\"rank\"`\n\tSubjectID   string `json:\"subject_id\" firestore:\"subject_id\"`\n\tDisplayName string `json:\"display_name\" firestore:\"display_name\"`\n\tValue       int64  `json:\"value\" firestore:\"value\"`\n}\n```\nLeaderboardEntry is intentionally small so public leaderboards do not leak private repository names or private activity counts.\n\n```go\ntype Link struct {\n\tKind string `json:\"kind\"`\n\tHref string `json:\"href\"`\n}\n```\nLink is a canonical GitHub, release, or Workbench receipt reference.\n\n```go\ntype MachineAccessResolver interface {\n\tCanViewMachine(context.Context, Viewer, string, string) (bool, error)\n}\n```\nMachineAccessResolver proves that one viewer may inspect one exact published machine. Authentication alone is never treated as machine ownership.\n\n```go\ntype MachinePublisher struct {\n\tLogin   string\n\tMachine string\n}\n```\nMachinePublisher is the exact identity bound to a daemon credential by the host. Neither value comes from request headers or the submitted payload.\n\n```go\ntype MachinePublisherResolver interface {\n\tPublisher(*http.Request) (MachinePublisher, error)\n}\n```\nMachinePublisherResolver binds host authentication to one exact WB machine.\n\n```go\ntype MachineSnapshotService struct {\n\tStore machinesnapshot.SnapshotStore\n\tNow   func() time.Time\n}\n```\nMachineSnapshotService applies publisher identity, validation, server time, and privacy-safe persistence around a durable store.\n\n```go\nfunc (service MachineSnapshotService) List(ctx context.Context, publisher MachinePublisher) (machinesnapshot.ListResponse, error)\n```\nList returns every durable machine for the authenticated login. Publisher credentials never grant cross-login reads.\n\n```go\nfunc (service MachineSnapshotService) Publish(ctx context.Context, publisher MachinePublisher, snapshot machinesnapshot.Snapshot) (machinesnapshot.Receipt, error)\n```\nPublish validates and atomically stores the latest snapshot for one exact authenticated login/machine key.\n\n```go\ntype MembershipResolver interface {\n\tMember(context.Context, Viewer, Scope, string) (bool, error)\n}\n```\nMembershipResolver proves GitHub installation membership for one canonical subject. A Firebase-authenticated host maps Viewer.UserID to GitHub identity; the provider never trusts browser headers or public GitHub visibility.\n\n```go\ntype ProjectionDeliveryStore interface {\n\tDeliveryStore\n\tClaimDelivery(context.Context, string) (bool, error)\n\tReleaseDelivery(context.Context, string) error\n}\n```\nProjectionDeliveryStore extends DeliveryStore with an atomic in-flight claim. ClaimDelivery returns false for a committed or currently claimed delivery. ReleaseDelivery makes refresh/write failures retryable; the implementation must retain its append-only audit record.\n\n```go\ntype ProjectionDocument struct {\n\tScope             Scope              `json:\"scope\" firestore:\"scope\"`\n\tID                string             `json:\"id\" firestore:\"id\"`\n\tDisplayName       string             `json:\"display_name\" firestore:\"display_name\"`\n\tSummary           Summary            `json:\"summary\" firestore:\"summary\"`\n\tUpdatedAt         time.Time          `json:\"updated_at\" firestore:\"updated_at\"`\n\tPublicOptIn       bool               `json:\"public_opt_in\" firestore:\"public_opt_in\"`\n\tPublicEligibility *PublicEligibility `json:\"public_eligibility,omitempty\" firestore:\"public_eligibility,omitempty\"`\n}\n```\nProjectionDocument is the durable, privacy-classified summary written by a Workbench-owned projector. Public responses require PublicOptIn; private responses require the host membership resolver below.\n\n```go\ntype ProjectionEngine struct {\n\tDeliveries          ProjectionDeliveryStore\n\tReader              ProjectionReader\n\tWriter              ProjectionWriter\n\tAuthoritativeReader AuthoritativeReader\n\tWebhookSecret       []byte\n}\n```\nProjectionEngine coordinates authoritative refresh, durable projection writes, and delivery receipt publication. It deliberately does not import GitHub, Firebase, or Firestore clients.\n\n```go\nfunc (engine ProjectionEngine) Process(ctx context.Context, delivery WebhookDelivery, signature string) (queued bool, processErr error)\n```\nProcess verifies and applies one delivery. AuthoritativeReader is retained as a required companion to ProjectionReader so hosts cannot accidentally wire a projection reader that omits the existing refresh barrier.\n\n```go\ntype ProjectionReader interface {\n\tRefreshProjection(context.Context, WebhookDelivery) (ProjectionSnapshot, error)\n}\n```\nProjectionReader refreshes and returns the authoritative records for a delivery. Implementations may coalesce equivalent repository refreshes, but must not satisfy a delivery from cache alone.\n\n```go\ntype ProjectionSnapshot struct {\n\tRepositories  []ProjectionDocument\n\tOrganizations []ProjectionDocument\n\tLatestMerges  *RepositoryLatestMerges\n}\n```\nProjectionSnapshot is the authoritative result of refreshing one GitHub App delivery. The reader owns GitHub access; the provider owns validation and the stable projection write order.\n\n```go\ntype ProjectionStore interface {\n\tListProjections(context.Context, Scope) ([]ProjectionDocument, error)\n\tGetProjection(context.Context, Scope, string) (ProjectionDocument, error)\n\tListSeries(context.Context, Scope, string, string) (SeriesDocument, error)\n\tGetLeaderboard(context.Context, string) (LeaderboardDocument, error)\n\tListPublicLatestMerges(context.Context, int) (PublicLatestMerges, error)\n}\n```\nProjectionStore is the narrow durable persistence adapter supplied by the host. Implementations map these operations to Firestore or another durable store; aggregation and disclosure stay in this package.\n\n```go\ntype ProjectionWriter interface {\n\tWriteRepositories(context.Context, string, []ProjectionDocument) error\n\tWriteOrganizations(context.Context, string, []ProjectionDocument) error\n\tWriteLatestMerges(context.Context, string, RepositoryLatestMerges) error\n}\n```\nProjectionWriter durably applies a complete authoritative snapshot. Every method is keyed by deliveryID and must be idempotent: a crash after a write and before DeliveryStore commits is safe to retry. Implementations should replace projections by ProjectionKey and replace the public merge view as a single logical operation.\n\n```go\ntype PublicEligibility struct {\n\tRepository string    `json:\"repository\" firestore:\"repository\"`\n\tREADMEURL  string    `json:\"readme_url\" firestore:\"readme_url\"`\n\tVerifiedAt time.Time `json:\"verified_at\" firestore:\"verified_at\"`\n}\n```\nPublicEligibility is the auditable root-README opt-in record required before a repository can appear in unauthenticated results. It is not inferred from GitHub repository visibility alone.\n\n```go\nfunc VerifyPublicEligibility(repository, readmeURL, markdown string, verifiedAt time.Time) (PublicEligibility, error)\n```\nVerifyPublicEligibility returns auditable evidence only when the root README has an explicit Workbench opt-in. The caller supplies the canonical GitHub README URL it read and the verification time from its authoritative refresh.\n\n```go\ntype PublicLatestMerges struct {\n\tEntries []LatestMerge `json:\"entries\" firestore:\"entries\"`\n}\n```\n\n```go\ntype ReadModel interface {\n\tDashboard(context.Context, Viewer) (Access[Dashboard], error)\n\tStats(context.Context, Viewer, Scope, string) (Access[Stat], error)\n\tSeries(context.Context, Viewer, Scope, string, string) (Access[Series], error)\n\tLeaderboard(context.Context, Viewer, string) (Access[Leaderboard], error)\n\tLatestMerges(context.Context, Viewer, int) (Access[[]LatestMerge], error)\n}\n```\nReadModel owns persistence and GitHub data projection. It must return only subjects whose public opt-in is recorded, unless the supplied viewer is an authenticated member of the private subject.\n\n```go\ntype RemoteStateReadModel struct {\n\tStore      SnapshotReader\n\tAccess     MachineAccessResolver\n\tNow        func() time.Time\n\tStaleAfter time.Duration\n}\n```\nRemoteStateReadModel serves the dashboard read routes from the WB machine snapshots a self-hosted hub already stores, so an operator sees their own machine, repositories and worktrees with no configuration and no hosted control plane. It is the read-model sibling of RemoteStateWorktreeReadModel, and shares its per-machine access rule.\n\nOnly what the snapshots genuinely carry is reported. Pull requests, issues, releases, token and cost trends and cross-repository merges are GitHub-derived projections a self-hosted hub does not compute, so those counters stay zero and the corresponding collections stay empty rather than being invented.\n\n```go\nfunc (model RemoteStateReadModel) Dashboard(ctx context.Context, viewer Viewer) (Access[Dashboard], error)\n```\nDashboard reports every machine this viewer may inspect.\n\n```go\nfunc (model RemoteStateReadModel) LatestMerges(_ context.Context, _ Viewer, _ int) (Access[[]LatestMerge], error)\n```\n\n```go\nfunc (model RemoteStateReadModel) Leaderboard(_ context.Context, _ Viewer, metric string) (Access[Leaderboard], error)\n```\n\n```go\nfunc (model RemoteStateReadModel) Series(_ context.Context, _ Viewer, scope Scope, id, metric string) (Access[Series], error)\n```\nSeries, Leaderboard and LatestMerges are part of the read-model contract but have no local source, so they answer with an empty, well-formed shape instead of failing the page.\n\n```go\nfunc (model RemoteStateReadModel) Stats(ctx context.Context, viewer Viewer, scope Scope, id string) (Access[Stat], error)\n```\nStats reports one repository, organization, or the whole local fleet. The repository id uses the browser's canonical \"\\\u003chost\u003e/\\\u003corg\u003e/\\\u003crepo\u003e\" form, which is also how a machine snapshot names its repositories.\n\n```go\ntype RemoteStateWorktreeReadModel struct {\n\tStore      SnapshotReader\n\tAccess     MachineAccessResolver\n\tNow        func() time.Time\n\tStaleAfter time.Duration\n}\n```\nRemoteStateWorktreeReadModel projects existing WB machine snapshots through a per-machine authorization boundary.\n\n```go\nfunc (model RemoteStateWorktreeReadModel) Worktrees(ctx context.Context, viewer Viewer, filter WorktreeFilter) (Access[WorktreeTable], error)\n```\n\n```go\ntype RepositoryLatestMerges struct {\n\tRepository  string\n\tPublicOptIn bool\n\tEntries     []LatestMerge\n}\n```\nRepositoryLatestMerges is one repository's complete contribution to the anonymous latest-merge view. PublicOptIn false removes any earlier public contribution for the repository without publishing private merge details.\n\n```go\ntype Scope string\n```\nScope identifies the GitHub subject represented by a statistic.\n\n```go\nconst (\n\tScopeRepository   Scope = \"repository\"\n\tScopeOrganization Scope = \"organization\"\n\tScopeUser         Scope = \"user\"\n)\n```\n\n```go\ntype Series struct {\n\tScope  Scope         `json:\"scope\"`\n\tID     string        `json:\"id\"`\n\tMetric string        `json:\"metric\"`\n\tPoints []SeriesPoint `json:\"points\"`\n}\n```\nSeries is a named time-series for graph and table consumers.\n\n```go\ntype SeriesDocument struct {\n\tScope  Scope         `json:\"scope\" firestore:\"scope\"`\n\tID     string        `json:\"id\" firestore:\"id\"`\n\tMetric string        `json:\"metric\" firestore:\"metric\"`\n\tPoints []SeriesPoint `json:\"points\" firestore:\"points\"`\n}\n```\n\n```go\ntype SeriesPoint struct {\n\tAt    time.Time `json:\"at\" firestore:\"at\"`\n\tValue int64     `json:\"value\" firestore:\"value\"`\n}\n```\nSeriesPoint can render either a graph point or a table row.\n\n```go\ntype Service struct {\n\t// Projector is the only supported webhook processor.\n\tProjector *ProjectionEngine\n\tReadModel ReadModel\n\tWorktrees WorktreeReadModel\n\tEvents    EventSource\n}\n```\nService applies disclosure policy around a Workbench read model and processes signed GitHub App webhook deliveries.\n\n```go\nfunc (service Service) Dashboard(ctx context.Context, viewer Viewer) (Dashboard, error)\n```\n\n```go\nfunc (service Service) EventStream(ctx context.Context, viewer Viewer, filter EventFilter) ([]Event, \u003c-chan Event, error)\n```\nEventStream replays visible durable events after cursor and returns the filtered live channel. It validates monotonic order so a bad source cannot cause a browser to skip or regress a reconnect cursor.\n\n```go\nfunc (service Service) LatestMerges(ctx context.Context, viewer Viewer, limit int) ([]LatestMerge, error)\n```\n\n```go\nfunc (service Service) Leaderboard(ctx context.Context, viewer Viewer, metric string) (Leaderboard, error)\n```\n\n```go\nfunc (service Service) ProcessWebhook(ctx context.Context, delivery WebhookDelivery, signature string) (bool, error)\n```\nProcessWebhook delegates webhook processing to the claim-safe projection engine. Hosts without a configured projector fail closed; the legacy fields are retained only so migrating compositions remain source-compatible.\n\n```go\nfunc (service Service) Series(ctx context.Context, viewer Viewer, scope Scope, id, metric string) (Series, error)\n```\n\n```go\nfunc (service Service) Stats(ctx context.Context, viewer Viewer, scope Scope, id string) (Stat, error)\n```\n\n```go\nfunc (service Service) WorktreeTable(ctx context.Context, viewer Viewer, filter WorktreeFilter) (WorktreeTable, error)\n```\nWorktreeTable returns one privacy-safe row per published worktree on the machines the host authorizes for this viewer.\n\n```go\ntype SnapshotReader interface {\n\tListLatest(context.Context) ([]machinesnapshot.StoredSnapshot, error)\n}\n```\nSnapshotReader lists the latest published snapshot per machine. The read models only read, so they depend on this rather than on the store that also writes; the host adapts its own store to it. hub imports this package, so the adapter lives with the caller instead of dragging hub's record type in here.\n\n```go\ntype Stat struct {\n\tScope       Scope          `json:\"scope\"`\n\tID          string         `json:\"id\"`\n\tDisplayName string         `json:\"display_name\"`\n\tSummary     Summary        `json:\"summary\"`\n\tUpdatedAt   time.Time      `json:\"updated_at\"`\n\tLinks       []Link         `json:\"links,omitempty\"`\n\tFleet       *FleetSnapshot `json:\"fleet,omitempty\"`\n}\n```\nStat is one scoped repository, organization, or user result.\n\n```go\ntype StoreReadModel struct {\n\tStore      ProjectionStore\n\tMembership MembershipResolver\n}\n```\n\n```go\nfunc (model StoreReadModel) Dashboard(ctx context.Context, viewer Viewer) (Access[Dashboard], error)\n```\n\n```go\nfunc (model StoreReadModel) LatestMerges(ctx context.Context, viewer Viewer, limit int) (Access[[]LatestMerge], error)\n```\n\n```go\nfunc (model StoreReadModel) Leaderboard(ctx context.Context, viewer Viewer, metric string) (Access[Leaderboard], error)\n```\n\n```go\nfunc (model StoreReadModel) Series(ctx context.Context, viewer Viewer, scope Scope, id, metric string) (Access[Series], error)\n```\n\n```go\nfunc (model StoreReadModel) Stats(ctx context.Context, viewer Viewer, scope Scope, id string) (Access[Stat], error)\n```\n\n```go\ntype Summary struct {\n\tRepositories int `json:\"repositories\" firestore:\"repositories\"`\n\tOpenPulls    int `json:\"open_pulls\" firestore:\"open_pulls\"`\n\tMergedPulls  int `json:\"merged_pulls\" firestore:\"merged_pulls\"`\n\tOpenIssues   int `json:\"open_issues\" firestore:\"open_issues\"`\n\tReleases     int `json:\"releases\" firestore:\"releases\"`\n}\n```\nSummary is the compact dashboard card set.\n\n```go\ntype Viewer struct {\n\tAuthenticated bool\n\tMember        bool\n\tUserID        string\n}\n```\nViewer is resolved by the host before a private record is rendered.\n\n```go\ntype ViewerResolver interface {\n\tViewer(*http.Request) (Viewer, error)\n}\n```\nViewerResolver binds the host authentication and membership system to the Workbench domain. The WB domain never accepts identity headers directly.\n\n```go\ntype Visibility string\n```\nVisibility describes whether a response contains an explicitly opted-in public subject or a member-only private subject.\n\n```go\nconst (\n\tVisibilityPublic  Visibility = \"public\"\n\tVisibilityPrivate Visibility = \"private\"\n)\n```\n\n```go\ntype Wakeup struct {\n\tKey        string `json:\"key\" firestore:\"key\"`\n\tRepository string `json:\"repository\" firestore:\"repository\"`\n\tEvent      string `json:\"event\" firestore:\"event\"`\n}\n```\nWakeup is a durable, coalescible unit of refresh work.\n\n```go\ntype WebhookDelivery struct {\n\tID         string\n\tEvent      string\n\tRepository string\n\tPayload    []byte\n}\n```\nWebhookDelivery is the verified, minimally parsed GitHub webhook envelope.\n\n```go\ntype WorktreeFilter struct {\n\tMachine        string\n\tRepository     string\n\tStatus         string\n\tStream         string\n\tTask           string\n\tNeedsAttention *bool\n}\n```\nWorktreeFilter selects rows in the consolidated development-machine table. Empty strings match every value. NeedsAttention is a pointer so false can be selected explicitly rather than being confused with an omitted filter.\n\n```go\ntype WorktreeReadModel interface {\n\tWorktrees(context.Context, Viewer, WorktreeFilter) (Access[WorktreeTable], error)\n}\n```\nWorktreeReadModel supplies the private cross-machine dashboard table.\n\n```go\ntype WorktreeRow struct {\n\tRepository      string     `json:\"repository\"`\n\tTask            string     `json:\"task\"`\n\tStream          string     `json:\"stream,omitempty\"`\n\tBranch          string     `json:\"branch\"`\n\tStatus          string     `json:\"status\"`\n\tLifecycle       string     `json:\"lifecycle\"`\n\tOwnerStatus     string     `json:\"owner_status\"`\n\tOwner           string     `json:\"owner,omitempty\"`\n\tPullRequest     int        `json:\"pull_request,omitempty\"`\n\tPullRequestURL  string     `json:\"pull_request_url,omitempty\"`\n\tMachine         string     `json:\"machine\"`\n\tMachineSeenAt   time.Time  `json:\"machine_seen_at\"`\n\tMachineStale    bool       `json:\"machine_stale\"`\n\tLastActivityAt  *time.Time `json:\"last_activity_at,omitempty\"`\n\tPublishedAt     time.Time  `json:\"published_at\"`\n\tNeedsAttention  bool       `json:\"needs_attention\"`\n\tAttentionReason string     `json:\"attention_reason,omitempty\"`\n}\n```\nWorktreeRow is the privacy-safe hosted projection of a published worktree. It intentionally has no local path, projects root, commit subject, or prompt.\n\n```go\ntype WorktreeTable struct {\n\tGeneratedAt time.Time     `json:\"generated_at\"`\n\tRows        []WorktreeRow `json:\"rows\"`\n}\n```\nWorktreeTable is one generated, filterable view across authorized machines.\n\n","path":"github.com/sneat-dev/wb/api/githubapp","name":"githubapp","synopsis":"Package githubapp defines the Workbench GitHub App control-plane API.","isRedistributable":true}
