copilot

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package copilot runs the GitHub Copilot CLI (`copilot`) as a provider.

Like claudecode it drives an agent harness rather than calling a model: the CLI works in the project directory with tools of its own — a shell, file edits, search — and cloop reads its answer off stdout. It runs in prompt mode (the prompt arrives on stdin, so no argument-length limit applies and the task never appears in a process listing), once per call, under the sign-in the CLI already has: `copilot login`, a token in COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN — in that order — or the GitHub CLI's, and with COPILOT_PROVIDER_BASE_URL set, a model provider of the operator's own (BYOK).

The flags were taken from Copilot CLI 1.0.103's own help and each behaviour this package depends on was checked against that binary: see copilot_cli_test.go, which runs the real CLI against a stub model server when one is installed.

Index

Constants

View Source
const (
	// ProviderName is the name config.yaml, --provider and the dashboard use.
	ProviderName = "copilot"
	// Binary is the program this provider execs. The dashboard's placement
	// check and a device's harness inventory name it the same way.
	Binary = "copilot"
)
View Source
const (
	EnvGitHubToken     = "COPILOT_GITHUB_TOKEN"
	EnvProviderBaseURL = "COPILOT_PROVIDER_BASE_URL"
)

The variables the CLI authenticates with. COPILOT_GITHUB_TOKEN outranks GH_TOKEN and GITHUB_TOKEN, which is what makes it the one to grant a sandbox: a repository grant may put a GitHub token without the Copilot permission in those two, and this one is still the one the CLI uses.

Variables

View Source
var ErrAuthFailure = errors.New("copilot CLI is not signed in or its credential was refused")

ErrAuthFailure marks a CLI run that found no credential, or whose credential was refused — the GitHub account has no Copilot access, or a custom provider rejected its key. Nothing cloop can retry fixes it.

Functions

func FindBinary

func FindBinary() string

FindBinary locates the copilot binary: PATH first, then where its installers put it — GitHub's install script at ~/.local/bin for a user and /usr/local/bin for root, `npm install -g` under a redirected prefix, and Homebrew on Apple silicon — which may not be on the PATH of a dashboard started by a service manager.

Types

type BackgroundPolicy

type BackgroundPolicy = agentproc.BackgroundPolicy

BackgroundPolicy governs the work the CLI leaves running after it exits; see agentproc. The zero value detects it, waits for it and terminates whatever outlives the wait.

type Provider

type Provider struct {
	// Background governs the handling of work the CLI leaves running after it
	// exits. The CLI's shell tool has an async mode, so an agent can leave a
	// build or a training run behind exactly as a claude agent can.
	Background BackgroundPolicy
}

Provider runs the Copilot CLI once per Complete.

func New

func New() *Provider

New builds a provider with the default background policy.

func NewWithBackground

func NewWithBackground(policy BackgroundPolicy) *Provider

NewWithBackground builds a provider with an explicit policy for work the CLI leaves running. Zero-valued fields resolve to agentproc's defaults.

func (*Provider) Complete

func (p *Provider) Complete(ctx context.Context, prompt string, opts provider.Options) (*provider.Result, error)

Complete runs the CLI once.

Unlike claudecode there is no retry on an authentication failure. The CLI refreshes its own credential and retries rate limits and server errors itself before it gives up, so a failure that reaches here is one a second attempt would meet again.

func (*Provider) DefaultModel

func (p *Provider) DefaultModel() string

DefaultModel is empty: with no model set cloop passes no --model, and the CLI's own choice applies — COPILOT_MODEL, the model saved in its settings, or its default.

func (*Provider) Name

func (p *Provider) Name() string

Jump to

Keyboard shortcuts

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