context

package
v1.135.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package context implements the `bitbottle context` command — a single one-call orientation primitive that returns the current host, project, slug, branch, default branch, ahead/behind counts vs the default branch, authenticated user, and backend type. This collapses what previously required three independent calls (auth status / repo view / git status) into a single structured response, principally for AI-agent integrations that pay a per-round-trip latency cost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCmdContext

func NewCmdContext(f *factory.Factory) *cobra.Command

NewCmdContext builds the cobra command. The command has no subcommands and takes no positional arguments — the entire shape is resolved from config, git state, and one backend round-trip (current user + branch list when inside a repo).

Types

type Context added in v1.79.0

type Context struct {
	Host          string      `json:"host"`
	Project       string      `json:"project"`
	Slug          string      `json:"slug"`
	Branch        string      `json:"branch"`
	DefaultBranch string      `json:"default_branch"`
	Ahead         *int        `json:"ahead,omitempty"`
	Behind        *int        `json:"behind,omitempty"`
	User          ContextUser `json:"user"`
	Backend       string      `json:"backend"`
}

Context is the orientation snapshot returned by `bitbottle context` and the MCP `get_context` tool. It collapses auth status, repo info, and git state into one structured response so callers can orient in a single round-trip.

Ahead and Behind use *int with omitempty so that "unknown" is encoded as absent JSON keys, never as 0/0 — which would falsely signal "in sync". Both pointers are populated as a pair: either both non-nil, or both nil.

This type lives in the cmd layer, not the backend domain, because it carries json tags purely for CLI --json / MCP output. No backend adapter returns or accepts it; it is assembled in Build().

func Build

func Build(f *factory.Factory, hostname string) (Context, error)

Build assembles a Context from config, git state, and the backend (current user + branch list when inside a repo). Exposed so the MCP `get_context` handler returns the exact same shape as the CLI.

Outside a git repository, BaseRepo() returns a non-nil error. That branch yields an empty Project / Slug / Branch / DefaultBranch / Ahead / Behind while still resolving Host, User, and Backend.

type ContextUser added in v1.79.0

type ContextUser struct {
	Slug        string `json:"slug"`
	DisplayName string `json:"display_name"`
}

ContextUser is the user shape embedded in Context. It mirrors backend.User but carries json tags so the output contract is stable regardless of future backend.User reshaping.

Jump to

Keyboard shortcuts

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