coreapi

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 23 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

Package coreapi answers the HTTP routes of the core slice that drive the tab state keeper: the agents' hook reports, a launch typed by the page, the recovery of a tab whose state is unknown, killing and resuming a conversation's agent, and the device visibility the web push sender reads. Status codes and bodies are the previous runtime's.

Index

Constants

View Source
const Slice = "core"

Slice is the switch these routes answer under.

Variables

View Source
var ErrResumeLine = errors.New("resume line not built")

ErrResumeLine: the resume line could not be built (a stored id that is no session id, a launcher not written yet); trying again does not help, unlike a tmux call that failed.

Functions

This section is empty.

Types

type Access

type Access struct {
	// contains filtered or unexported fields
}

Access is the runtime's network access rule: which remote addresses may call it. Spec words: "all" (also "*", "0.0.0.0"), "localhost", "tailscale", "lan", or a CIDR / address, comma-separated; the deployment derives the spec from its setting (an explicit host, else the configured network access, "all" by default).

func AccessFor

func AccessFor(networkAccess string) Access

AccessFor reads the setting of the network access option: localhost, tailscale (with localhost) or all.

func ParseAccess

func ParseAccess(spec string) Access

ParseAccess reads a spec; parts it cannot read are left out.

func (Access) Allowed

func (a Access) Allowed(remote string) bool

Allowed tells whether a remote address (host, or host:port) may call.

type Agent

type Agent struct {
	// ReadSessionID is the tab's stored session (claude.Tabs or codex.Tabs).
	ReadSessionID func(t agents.TabAgent) string
	// Running tells whether the agent runs under a pane's shell.
	Running func(panePID int) bool
	// ResumeCommand is the line that resumes a session (claude/codex LaunchConfig).
	ResumeCommand func(sessionID, workspaceID string, launch *agents.Launch) (string, error)
}

Agent is one agent CLI as resuming a conversation needs it.

type CodexSessionSink

type CodexSessionSink interface {
	CodexSession(tmuxSession string, info agents.SessionInfo, clear bool)
}

CodexSessionSink hears the session a Codex SessionStart hook names (clear: it was a /clear), for the session watchers of the timeline; the deployment forwards it to the runtime that still holds the timeline.

type Config

type Config struct {
	Keeper Keeper
	// PermissionRequest holds Claude's PermissionRequest hook for the conversation of a tmux session until the person
	// decided, and answers with what the hook prints; false, or nil, leaves it to Claude's own dialog.
	PermissionRequest func(ctx context.Context, session string, request map[string]any) (any, bool)
	// TokenOK checks the runtime's cli-token in the hook's headers.
	TokenOK func(*http.Request) bool
	// APIRefusal is the dispatcher's answer to a caller with neither a page session nor the cli-token (refused false
	// lets the request in); the hook route is open and checks the token itself.
	APIRefusal func(*http.Request) (status int, body any, h http.Header, refused bool)
	// Access is the network access rule, asked per hook (the setting may change).
	Access func() Access
	// RemoteAddr is the caller's address (r.RemoteAddr by default).
	RemoteAddr    func(*http.Request) string
	CodexSessions CodexSessionSink
	Tabs          TabLookup
	Panes         Panes
	// Agents by provider id.
	Agents map[string]Agent
	// RecoverSession finds and stores the session of a tab that lost its id (from its transcript or history).
	RecoverSession func(session string, providerID string) (string, bool)
	// LaunchOf is the model and effort the tab's conversation was started with, nil for the CLI's default.
	LaunchOf func(session string) *agents.Launch
	// KillTree stops a pane's process tree, keeping the shell, and returns how many processes it stopped.
	KillTree   func(panePID int) int
	Visibility Visibility
	// SessionProcessPath is the route of killing and resuming a conversation's agent (under the deployment's platform
	// prefix); empty leaves it out.
	SessionProcessPath string
	// MirrorVisibility also tells the previous runtime, which still sends some pushes of its own.
	MirrorVisibility func(deviceID string, visible bool)
	Timings          Timings
	Log              func(level, msg string, kv ...any)
	// Spool is the file Claude's status hook leaves its events in before it calls (hookspool); nil applies every event
	// as it comes. Its Apply is ApplyClaudeHook.
	Spool *hookspool.Queue
}

Config is what the routes use.

func (*Config) ApplyClaudeHook

func (c *Config) ApplyClaudeHook(f map[string]any)

ApplyClaudeHook is one event of Claude's status hook, as the request or the spool carried it.

func (*Config) Kill

func (c *Config) Kill(t status.Tab) int

Kill stops the agent of a tab and everything it started, keeping the pane's shell, then marks the agent gone (its launch, if any, ends). It returns how many processes it stopped; 0 without the tmux session or its pane.

func (*Config) Resume

func (c *Config) Resume(found FoundTab) (string, error)

Resume types the resume line of the tab's session into its pane: "resumed", "running" (the agent already runs), "no-session" (nothing to resume) or "busy-shell" (something else holds the terminal).

func (*Config) Routes

func (c *Config) Routes() []gate.JSONRoute

Routes are the core slice's routes for the gate.

type FoundTab

type FoundTab struct {
	WorkspaceID string
	Directories []string
	Tab         status.Tab
	Cwd         string
}

FoundTab is a layout tab with what resuming it needs.

type Keeper

type Keeper interface {
	HandleProviderEvent(providerID, session string, ev agents.Event, firedAt *float64) bool
	ApplyHookMeta(providerID, session string, meta status.HookMeta) (tabID, cliState string, ok bool)
	MarkAgentLaunch(tabID string, reset bool)
	MarkAgentGone(tabID string, endLaunch bool)
	RecoverUnknown(tabID string) (bool, string)
	Poll()
	AgentSources() []status.AgentSource
	SynthesizeEvent(session, event string)
}

Keeper is the part of the state keeper (*status.Manager) the routes drive.

type Panes

type Panes interface {
	HasSession(name string) bool
	PanePID(name string) int
	CreateSession(name string, cols, rows int, cwd string) error
	CheckTerminalProcess(name string) (safe bool, process string)
	SendKeys(name, line string) error
}

Panes is what the routes ask tmux; *tmux.Tmux has it.

type TabLookup

type TabLookup interface {
	FindTab(tabID string) (FoundTab, bool)
}

TabLookup finds a tab by id in the layouts on disk.

type Timings

type Timings struct {
	// ShellReady: a fresh tmux session's shell needs a moment before it takes keys.
	ShellReady time.Duration
	// ShellSettle and ShellPoll: how long and how often a terminal that looks busy is looked at again before a resume
	// gives up on it.
	ShellSettle, ShellPoll time.Duration
	// BackstopPoll and BackstopWait: how often and how long the agent is looked for after the resume line; BackstopGrace
	// is how long it may then run without a SessionStart hook before one is synthesized.
	BackstopPoll, BackstopWait, BackstopGrace time.Duration
}

Timings of a resume; zero values take the previous runtime's.

type Visibility

type Visibility interface {
	MarkVisible(deviceID string)
	MarkHidden(deviceID string)
}

Visibility is where the page's device visibility goes (the push sender's store).

Directories

Path Synopsis
Package layoutapi answers the core slice's routes over layouts, workspaces, the CLIs' tab commands and the right pane's bridges, the way the previous runtime's API answered them: its route table and precedence, its sign-in check, its body parsing (1 MB, "Invalid JSON", 413), its JSON with ETag and 304, and each handler's statuses and texts.
Package layoutapi answers the core slice's routes over layouts, workspaces, the CLIs' tab commands and the right pane's bridges, the way the previous runtime's API answered them: its route table and precedence, its sign-in check, its body parsing (1 MB, "Invalid JSON", 413), its JSON with ETag and 304, and each handler's statuses and texts.

Jump to

Keyboard shortcuts

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