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 ¶
const Slice = "core"
Slice is the switch these routes answer under.
Variables ¶
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 ¶
AccessFor reads the setting of the network access option: localhost, tailscale (with localhost) or all.
func ParseAccess ¶
ParseAccess reads a spec; parts it cannot read are left out.
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 ¶
ApplyClaudeHook is one event of Claude's status hook, as the request or the spool carried it.
func (*Config) Kill ¶
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.
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 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 ¶
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. |