sessionlink

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 6 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 sessionlink joins a session Caprock started to the record the agent's own files keep of it.

Claude Code and Gemini CLI take an id on the command line, so the session Caprock starts and the session their transcript or telemetry describes are one id from the first byte. Codex and OpenCode cannot be told one. Codex names its thread itself; OpenCode creates its session when the first message is sent. Their importers find those sessions under the agent's own id, and without a link a session started from the dashboard would appear twice — once as a terminal with no cost, once as a cost with no terminal.

A link is made one of two ways, and the difference is the whole point of keeping them apart:

  • Claim is exact. OpenCode's TUI runs a server on a port Caprock chose, and that server announces `session.created` for the session the TUI made. Nothing else can be on that port.
  • Match is a heuristic, for Codex, which writes no id anywhere Caprock can see before the rollout appears. A rollout is matched to a spawn when it was written by the Codex TUI (not the desktop app, not a subagent, not an import), in the same directory, by a thread that started within the window after the spawn. Codex stamps a thread with the moment the TUI started, not the moment its file was first written (measured on 14 CLI rollouts: up to 4m40s apart), so the window can be tight even though the file appears whenever the user first types.

Once made, a link is stored on the session (sessions.native_id) and the importers write the thread's events under Caprock's id.

Index

Constants

View Source
const Grace = time.Minute

Grace is how long an expectation outlives the process that set it. A session that is typed into and closed within one import tick still has its rollout read after it has gone.

View Source
const Skew = 5 * time.Second

Skew is how far before the spawn a thread's start may be stamped. Clocks agree on one machine; this absorbs rounding, not drift.

View Source
const Window = 2 * time.Minute

Window is how long after a spawn a Codex thread may say it started and still be taken as the one Caprock launched. The TUI stamps its thread within seconds of starting; two minutes covers a loaded machine without reaching a thread the user opened later by hand.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	NativeID string
	Cwd      string
	Started  time.Time
	// Eligible says the session is one a person started in the agent's own
	// TUI — not a subagent, a thread imported from another agent, or one the
	// desktop app owns. Only an eligible candidate is ever matched.
	Eligible bool
}

Candidate is a session an importer found under the agent's own id.

type Linker

type Linker struct {
	Store *store.Store
	Log   *slog.Logger
	// Now is overridable in tests.
	Now func() time.Time
	// contains filtered or unexported fields
}

Linker holds the spawns still waiting for their agent's id.

func New

func New(st *store.Store, log *slog.Logger) *Linker

New builds a linker over the store.

func (*Linker) Claim

func (l *Linker) Claim(ctx context.Context, agent, sessionID, nativeID string) bool

Claim links sessionID to the agent's own id, exactly. It is for a source that names the session it made — OpenCode's own server on a port Caprock chose. Reports whether the link was made.

func (*Linker) Ended

func (l *Linker) Ended(sessionID string)

Ended tells the linker a spawned process has exited. Its expectation is kept for Grace, then dropped.

func (*Linker) Expect

func (l *Linker) Expect(agent, sessionID, cwd string, at time.Time, match bool)

Expect records a spawn whose agent will name the session later. match says whether Match may take it; OpenCode's spawns are claimed exactly instead.

func (*Linker) Resolve

func (l *Linker) Resolve(ctx context.Context, agent string, c Candidate) string

Resolve answers the id an importer should store a session's events under: the Caprock session linked to it, or the agent's own id when there is none. A candidate that matches a waiting Codex spawn is linked here.

func (*Linker) Waiting

func (l *Linker) Waiting(agent string) bool

Waiting reports whether any spawn of this agent is still unlinked — an importer uses it to hold back a file it could otherwise only file under the wrong id.

Jump to

Keyboard shortcuts

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