sessionlink

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sessionlink ties sessions that handle the same matter together, so each knows the others exist, what they are doing right now, and can read their latest turns — instead of a person forwarding between them.

A link comes from one of four places:

  • an explicit pair in session.Meta.Links, written to both sides (Link): by an agent through wick_session_link, or by wick itself;
  • a Team pairing, session.Meta.LinkedFromSession (read as a link, never rewritten here: Team routing owns that field);
  • a thread an agent opened and announced with LinkThread: the session born in that thread later is linked to the one that opened it the first time either side is looked at;
  • nothing else. Tickets link through Link when a session joins one.

Everything here reads and writes session files directly; callers that cache sessions refresh them afterwards.

Index

Constants

View Source
const (
	StateRunning = "running"
	StateIdle    = "idle"
	// StatePending: a thread was opened and announced, nobody replied in
	// it yet, so no session exists there.
	StatePending = "pending"
)

Peer states.

Variables

View Source
var ErrSelf = errors.New("a session cannot be linked to itself")

ErrSelf refuses linking a session to itself.

Functions

func IsLinked

func IsLinked(layout config.Layout, id, peer string) bool

IsLinked reports whether peer is among id's linked sessions.

func Link(layout config.Layout, a, b, why string) error

Link ties a and b together, on both sides. Linking an existing pair again only refreshes its reason.

func LinkThread

func LinkThread(layout config.Layout, origin, channel, chatID, threadID, why string) error

LinkThread announces that origin opened a thread (channel "slack", chatID a channel id, threadID the new message's ts). The session a reply there starts is linked to origin the first time either is looked at.

func Note

func Note(layout config.Layout, id string, now time.Time) string

Note is the one-line [linked] block a turn of id opens with: only the linked sessions working right now, since those are the ones whose work this turn could repeat or collide with. "" when none is.

func Prompt

func Prompt(layout config.Layout, id string) string

Prompt is the "Linked sessions" section of id's system prompt: who is linked when the process starts. "" for a session with no links, so a session that never has any pays nothing.

func Unlink(layout config.Layout, a, b string) error

Unlink removes the pair from both sides. A side that is gone is skipped.

Types

type Peer

type Peer struct {
	Session    string    `json:"session,omitempty"`
	Title      string    `json:"title"`
	AgentID    string    `json:"agent_id,omitempty"`
	Why        string    `json:"why"`
	State      string    `json:"state"`
	LastActive time.Time `json:"last_active,omitempty"`
	// Thread is "<channel>:<chat>/<thread>" for a pending thread.
	Thread string `json:"thread,omitempty"`
}

Peer is one linked session as an agent or the UI sees it.

func Peers

func Peers(layout config.Layout, id string) ([]Peer, error)

Peers lists id's linked sessions, newest activity first, then the threads it opened that nobody answered yet.

type Turn

type Turn struct {
	Role string    `json:"role"`
	Text string    `json:"text"`
	At   time.Time `json:"at"`
}

Turn is one conversation turn as Read returns it.

func Read

func Read(layout config.Layout, peer string, n, maxChars int) ([]Turn, error)

Read returns peer's last n user/assistant turns, oldest first, each cut to maxChars. Callers check IsLinked (or ownership) first.

Jump to

Keyboard shortcuts

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