Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v0.7.215 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConflictInterval is how often the daemon re-evaluates whether each
	// project's branch still merges cleanly. Far slower than PollInterval
	// because the answer only changes when a commit lands on either side, and
	// the check costs a merge in the object database rather than a stat.
	ConflictInterval = 60 * time.Second

	// FetchInterval is how often the merge target's remote-tracking ref is
	// refreshed. The check is worthless against a ref nobody has updated in a
	// week, and expensive if refreshed every time: this is the compromise.
	FetchInterval = 3 * time.Minute

	// MaxConflictPaths caps the paths reported for one branch. A merge that
	// conflicts in hundreds of files is one fact — "this branch has diverged
	// badly" — and listing all of them buries it.
	MaxConflictPaths = 20
)
View Source
const (
	// PollInterval is how often the daemon refreshes project state from disk.
	PollInterval = 5 * time.Second
	// RecentEvents is the maximum number of events kept per project.
	RecentEvents = 300
	// RunningTimeout is how long after the last non-terminal event a sidecar is
	// considered to still be running.
	RunningTimeout = 5 * time.Minute
)
View Source
const (
	// MaxCommandBytes is the default per-command output buffer cap in bytes.
	// Override at runtime with CHUNK_OUTPUT_BUFFER_SIZE so the cap can be tuned
	// via a sandbox-provisioner deploy without rebuilding images.
	MaxCommandBytes = 10 << 20 // 10 MB

	// MaxCommands caps retained commands per project. Only finished commands are
	// evicted, so a project running more than this many at once keeps them all.
	MaxCommands = 20
)
View Source
const DefaultAsyncMaxLines = 500

DefaultAsyncMaxLines is how large a change may be, in lines, and still be validated in the background.

The number is a judgement, not a measurement. What it is really choosing is how much of the inner loop runs without waiting: nearly every edit an agent makes in one turn lands under it, and the changes that do not are the ones where a developer is most likely to want the answer before doing anything else. Projects that disagree can say so — see config.AsyncValidateMaxLines.

View Source
const DefaultAttempts = 3

DefaultAttempts is how many rounds a factory session checks at most when the request does not say.

View Source
const MaxSessionsPerProject = 10

MaxSessionsPerProject caps retained sessions per project. Only finished ones are evicted, so a live session is never lost.

View Source
const MaxTasksPerProject = 20

MaxTasksPerProject caps retained validation tasks per project. Only finished tasks are evicted, so a project cannot lose a run that is still going. It is also what bounds delivered results, which collect keeps rather than deletes.

View Source
const PRPollInterval = 60 * time.Second

PRPollInterval is the minimum time between PR fetches for a given branch. GitHub's API is rate-limited, so polling too frequently is wasteful. A branch change resets the clock so the new branch's PR is fetched promptly.

Variables

This section is empty.

Functions

func RunDaemon

func RunDaemon(ctx context.Context, client *circleci.Client, authMessage string, runner ValidateRunner, ghClient *github.Client, opts ...Option) error

RunDaemon is the chunk daemon entry point, called by the hidden _daemon subcommand.

client and authMessage support the output-buffering feature; runner is called in-process to handle /validate requests. Both client and runner may be nil (the daemon still records commands without a client, and /validate returns an error without a runner). ghClient may be nil; PR monitoring is skipped when no GitHub credentials are available.

Types

type Option

type Option func(*daemonOptions)

Option customizes RunDaemon.

func WithReview

func WithReview(cfg ReviewConfig) Option

WithReview configures the daemon's review capability.

type ReviewConfig

type ReviewConfig struct {
	Credential claudecode.Credential
	// BaseURL is forwarded to claude when it is not Anthropic's own.
	BaseURL string
	// AuthError explains a missing Credential, reported in the snapshot so an
	// absent capability is explained rather than silent.
	AuthError string

	// The fields below are test seams. Left nil, the daemon talks to the
	// sandbox through the pool entry's own client.
	Submit SubmitFunc
	Stream StreamFunc
	// RunFactory runs a factory session; factory.Run when nil.
	RunFactory func(ctx context.Context, opts factory.RunOptions) (factory.Report, error)
}

ReviewConfig is everything the daemon needs to run factory sessions. The credential is resolved once by the caller at daemon start; it is only ever placed in the environment of a Claude command, and never logged or put in a snapshot.

type StreamFunc

type StreamFunc func(ctx context.Context, entry *sidecar.PoolEntry, commandID string, onOutput circleci.OutputFn) (int, error)

StreamFunc reads a submitted command's output to its end and returns its exit code.

type SubmitFunc

type SubmitFunc func(ctx context.Context, entry *sidecar.PoolEntry, script string, env map[string]string) (string, error)

SubmitFunc submits a script on a pool member and returns its command ID.

type ValidateRunner

type ValidateRunner func(ctx context.Context, projectRoot, workDir string, args []string, env []string, stdout, stderr io.Writer) int

ValidateRunner runs a validate command in-process. projectRoot is the repo the daemon uses for task tracking and state keying; workDir is the caller's working directory, passed to the subprocess as --project so it can load .chunk/config.json from the right location (workDir equals projectRoot unless the .chunk directory sits below the git root, in which case workDir is the subdirectory and projectRoot is the git top-level). When workDir is empty the runner falls back to projectRoot. args is os.Args[1:] from the caller; env is the caller's os.Environ(). stdout and stderr capture command output. Returns the exit code.

Jump to

Keyboard shortcuts

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