api

package
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 86 Imported by: 0 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

The CI-aware PR loop's API surface (internal/ciloop, docs/ci-loop.md): arming a watch when the commit button opens a PR, the manual "watch this PR" endpoint for a PR the agent opened itself, and the card view.

mcp_clients.go backs the Settings "Connect your AI tools" card: one place that tells a new user which MCP clients can be wired to this Lectern with a single click, runs that click for the ones that genuinely support it, and remembers which clients have actually spoken to `lectern mcp` at least once.

Claude Code and Codex ship their own `mcp add`/`mcp get` subcommands, so for those two lectern can run the client's own registration command on the machine Lectern itself runs on (as the Lectern service user) — a true one click. Every other client (Claude Desktop, Cursor, VS Code, claude.ai, ChatGPT) gets the most automatic path it genuinely supports: a prefilled config snippet, a real deep link, or — where the client needs a public HTTPS endpoint Lectern does not expose — an honest explanation instead of a fake button.

pairing.go backs Settings → Devices ("Pair a phone") and the public /pair exchange it feeds: minting a short-lived, single-use code as an already-signed-in owner, and trading that code for a long-lived device credential from an unauthenticated browser. See internal/pairing for the design rationale and docs/remote-access.md for the operator-facing story (running Lectern behind a public tunnel with pairing on).

mintPairingCode and the device-list/revoke/settings handlers below all require CanDecide, exactly like decideApproval — minting a credential that can decide approvals is at least as sensitive as deciding one. exchangePairingCode is the one deliberate exception: see its own doc comment and the exemption in withAuth.

relay.go backs Settings → Devices → Encrypted relay (docs/relay.md): the relay connection's status, pairing a phone over the relay, revoking relay devices, and the signed app-shell manifest a paired phone's service worker checks before it accepts a new shell. Everything but the manifest is owner-only, like ordinary pairing: minting a credential that can decide approvals is at least as sensitive as deciding one.

Replay evals (docs/replay-evals.md): building eval cases out of a project's own merged-PR history, so "which agent/model is best for MY repository" is ground-truthed against what actually landed. This file is the target-facing orchestration — everything that needs a real gh/git call — around the pure logic in internal/replay.

Package api is lectern's HTTP surface: the REST control plane, the agent-facing hook endpoints, the SSE streams and the embedded PWA.

Session checks: the project's verify_cmd (or auto-detected .verify.yaml) run against a session's worktree, triggered on an agent Stop and shown on the card. See internal/checks and docs/agent-events.md section 4.

Review and merge: live diffs, commit/push/PR and inline review comments, shared between tasks (finished attempts) and sessions (long-running interactive worktrees). See docs/agent-events.md section 4.

Named session_review.go (not review.go) because review.go already exists — the terminal workspace's "changes" file browser, an unrelated feature.

Triggers let a project pick up work on its own — a labelled GitHub issue, an @mention, a Slack message/slash command, or a labelled Linear issue — instead of a human always pressing dispatch. See internal/triggers for the polling/socket engines and docs/triggers.md for setup and the security model. This file is the HTTP surface plus the one adapter (CreateTriggerTask) that turns a matched event into a real task through the same path a human's "New task" + dispatch always used.

Index

Constants

View Source
const (
	AgentTaskCap = 10
	NoteCap      = 20
)

AgentTaskCap and NoteCap bound what one attempt can file, so a looping agent cannot flood the board or the memory store.

View Source
const ShellManifestLabel = "lectern-shell-manifest-v1\x00"

ShellManifestLabel domain-separates the shell signature from every other use of an Ed25519 key. frontend/src/relay/shell.ts uses the same string.

Variables

View Source
var ClaudeModels = []string{"fable", "opus", "sonnet", "haiku"}

ClaudeModels are the shorthands Claude Code accepts. Every other agent names its models differently and the set moves, so there is nothing honest to hardcode for them — what you have actually used is the better suggestion.

Functions

This section is empty.

Types

type Server

type Server struct {
	// PhoneURL is the tailnet HTTPS origin (real certificate) once that
	// listener is up — the address to hand a phone. Empty otherwise.
	PhoneURL string

	DB       *store.DB
	Bus      *bus.Bus
	Broker   *broker.Broker
	Notifier *sinks.Notifier
	Reg      *executor.Registry
	Sched    *scheduler.Scheduler
	Sessions *sessions.Manager
	Events   *agentevents.Ingester
	Checks   *checks.Runner
	// CILoop watches the pull requests Lectern opens (internal/ciloop,
	// docs/ci-loop.md). Nil is safe: nothing is armed.
	CILoop *ciloop.Watcher
	// Triggers polls GitHub/Linear and holds Slack's Socket Mode connections
	// open (internal/triggers). Nil is safe everywhere it is read — a build
	// or test harness that never sets it simply has no trigger sources.
	Triggers *triggers.Manager
	// Awareness is cross-agent awareness's tracker (internal/awareness,
	// docs/agent-events.md "Cross-agent awareness"): peer lookups, briefing
	// text, edit warnings. Nil is safe everywhere it is read (every awareness
	// call site checks it first) so a build that predates this field, or a
	// test harness that never sets it, degrades to "no awareness" rather
	// than a panic.
	Awareness *awareness.Tracker
	// Claims is the Claim board's tracker (internal/claims, docs/claims.md):
	// create/release/extend, overlap queries, and the briefing/warning text.
	// Nil is safe everywhere it is read, same convention as Awareness.
	Claims    *claims.Tracker
	Memory    memory.Provider
	Terminals *terminal.Manager
	Push      *push.Sender
	Cfg       *config.Config
	Auth      *auth.Resolver
	Log       *slog.Logger
	// Pairing is device pairing's store (internal/pairing, pairing.go in
	// this package) — nil is safe everywhere it is read (pairingEnabled
	// treats a nil Pairing as "off"), so a build or test harness that never
	// wires one simply never offers /pair.
	Pairing *pairing.Store
	// Limits is the usage-limit tracker (internal/limits, docs/rate-limits.md):
	// the one-tap choices on a card or push go through it. Nil disables the
	// endpoints.
	Limits *limits.Tracker
	// Relay is the end-to-end encrypted relay connection (internal/relay/
	// host, relay.go in this package); nil unless LECTERN_RELAY_URL is set.
	// RelayStore holds the relay keys and devices and is set either way.
	Relay      *relayhost.Host
	RelayStore *relayhost.Store
	// Activity records recent real terminal input per session, for the
	// alert-suppression rule in docs/agent-events.md section 3. Nil is safe
	// (terminalActivity then just has nowhere to record — no suppression,
	// not a crash); app.New always sets it.
	Activity *alerts.Activity

	// SummaryGen, when set, replaces the real headless cheap-model call PR
	// description generation makes (see review.go runSummary). Tests set this
	// to a stub so a review test never spends a real model token or needs a
	// real agent binary.
	SummaryGen func(ctx context.Context, ex executor.Executor, agent, model, prompt string) (string, error)

	// MCPClientRunner, when set, replaces the real exec.CommandContext call
	// mcp_clients.go makes to run a client's own `mcp add`/`mcp get`
	// subcommand. Tests always set this — the suite must never run a real
	// claude/codex binary and mutate the operator's own agent config. nil
	// means "really exec it" (see mcpRunner).
	MCPClientRunner mcpClientRunnerFunc
	// LecternPath, when set, overrides the resolved lectern binary path
	// mcp_clients.go reports and uses to build install commands. Tests set
	// this to a fixed value instead of the test binary's own os.Executable().
	LecternPath string
	// contains filtered or unexported fields
}

Server wires every dependency the handlers need.

func (*Server) CreateTriggerTask added in v2.4.0

func (s *Server) CreateTriggerTask(project *store.Project, spec triggers.NewTaskSpec) (*store.Task, error)

CreateTriggerTask is internal/triggers.Manager.CreateTask's implementation: the one path a matched event reaches the board through, identical to a human's "New task" + dispatch except for two things that are the whole safety story in requirement 4 — the permission mode is always the project's own default (never anything a trigger source's config could elevate), and the task is queued and dispatched immediately, since a trigger with nobody watching the board is the point.

func (*Server) Creds

func (s *Server) Creds() *creds.Provisioner

Creds exposes the provisioner the scheduler owns, so the deep probe and a dispatch can never drift apart.

func (*Server) DrainStreams

func (s *Server) DrainStreams()

DrainStreams ends open-ended live updates before HTTP graceful shutdown waits for requests. Ordinary requests retain their own lifetime and drain normally.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler builds the full router, including auth and the embedded web app.

func (*Server) RunAutonomyTick added in v2.4.0

func (s *Server) RunAutonomyTick(ctx context.Context)

func (*Server) RunDueRoutines

func (s *Server) RunDueRoutines(ctx context.Context)

RunDueRoutines fires every scheduled routine whose time has come. The scheduler calls this on its tick.

A routine that cannot be scheduled any more (its schedule was edited to something unreadable) is disabled rather than retried forever, and says so in the log — a job silently firing every two seconds is a much worse failure than one that stops.

func (*Server) RunEvalsTick added in v2.4.0

func (s *Server) RunEvalsTick(ctx context.Context)

RunEvalsTick is the scheduler.Scheduler.Evals callback (see app.go): once per scheduler tick, it materialises newly-queued runs into their result cells, dispatches the next queued cells up to the run's concurrency limit, and grades cells whose dispatched task has finished. It reuses the ordinary task/attempt machinery end to end — an eval cell IS a task, so nothing here touches tmux, drivers or worktrees directly.

func (*Server) ScheduleAutonomyTick added in v2.4.0

func (s *Server) ScheduleAutonomyTick(ctx context.Context)

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown releases everything the server owns.

Source Files

Jump to

Keyboard shortcuts

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