computer

package
v0.249.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 38 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 computer is the person's own computer as their agent reaches it: the program `teanode computer` runs there, answering the agent's requests over a websocket to the server, as the person, anywhere on the machine, and running what the server sends.

Nothing here decides whether a command looks dangerous. A rule that matched a command line against a list of dangerous-looking shapes lived in this package and was removed: it could not name everything dangerous, a wrapper script walked past it, and a control that catches some of the bad cases reads as one that catches them all. The program is not confined to a list of directories: it reaches everything the person can, and only its file tool leaves out the files `teanode passwords` keeps. What stands between a request and the machine is their yes.

Index

Constants

View Source
const (
	BackgroundStopReasonStopped  = "stopped"
	BackgroundStopReasonShutdown = "shutdown"
)

Why a background command was ended by somebody other than itself: stopped when asked (by the person, or by the agent, which then needs no word of it), or with this program as it shut down.

View Source
const (
	HerdrSessionStateIdle    = "idle"
	HerdrSessionStateWorking = "working"
	HerdrSessionStateAsking  = "asking"
	HerdrSessionStateUnknown = "unknown"
)

The states of a herdr session, as this program decides them.

View Source
const (
	HerdrEventKindAsking   = "asking"
	HerdrEventKindAnswered = "answered"
	HerdrEventKindSettled  = "settled"
)

The events the program says unasked.

View Source
const (
	HerdrQuestionKindQuestion     = "question"
	HerdrQuestionKindToolApproval = "toolApproval"
	HerdrQuestionKindPlanApproval = "planApproval"
)

The kinds of question.

View Source
const (
	HerdrOptionKindChoice   = "choice"
	HerdrOptionKindFreeText = "freeText"
	HerdrOptionKindChat     = "chat"
)

The kinds of option: one to choose, one that takes typed text, and Claude Code's way out of the form into a conversation about it.

View Source
const (
	CodingAgentKindClaude = "claude"
	CodingAgentKindCodex  = "codex"
)

The coding agents, as herdr names them.

View Source
const (
	HerdrSubagentStateRunning = "running"
	HerdrSubagentStateDone    = "done"
	HerdrSubagentStateStopped = "stopped"
)

The states of a session's agent.

View Source
const (
	HerdrTurnRolePerson = "person"
	HerdrTurnRoleAgent  = "agent"
	HerdrTurnRoleTool   = "tool"
)

The roles of a turn.

View Source
const (
	FormatFiles   = "files"
	FormatJournal = "journal"

	// FormatRecords is a folder of JSON lines somebody's script wrote,
	// which is how a source this program has no reader for -- a Drive, a
	// wiki, a mailbox behind a command line tool -- is indexed without
	// another reader being written and released.
	FormatRecords = "records"

	// FormatProbe asks only whether the root can be scanned here: the
	// answer is an empty page, or why not. Sent before a source is made,
	// so that a missing folder is said at once rather than found in the
	// source's error a minute later.
	FormatProbe = "probe"
)

The formats this program understands, which are the formats the server may ask for.

View Source
const (
	EcosystemGo     = "go"
	EcosystemNpm    = "npm"
	EcosystemPython = "python"
	EcosystemCargo  = "cargo"
	EcosystemCMake  = "cmake"
)

The ecosystems a dependency can come from, which is which kind of build file named it.

View Source
const AttachedSession = "attached"

AttachedSession is the identifier the attached terminal's session has. One per connection, so it needs no other name.

View Source
const (

	// DefaultMaxAttachmentBytes is the largest file a record's
	// attachment may be for this program to hash it and hand it over.
	//
	// The server says what the limit is, per source, and this is what a
	// request that does not say falls back to -- an older server, or the
	// probe. It is a fallback and not a floor: a server asking for less
	// gets less, and a server asking for more gets more.
	DefaultMaxAttachmentBytes = 25 << 20
)

The bounds of one scan.

View Source
const EcosystemJhbuild = "jhbuild"

EcosystemJhbuild is a component that is a module of a jhbuild moduleset.

View Source
const FeatureAuthorizationForward = "authorizationForward"

FeatureAuthorizationForward is this program listening for an authorization on its loopback interface when asked.

View Source
const FeatureBackground = "background"

FeatureBackground is background commands: a command started to run on, one left running when its wait runs out, and the actions that read, list and stop them.

View Source
const FeatureHerdr = "herdr"

FeatureHerdr is the person's herdr sessions on this computer: the herdr_* actions, and the herdr messages the program sends unasked.

View Source
const FeatureHerdrFiles = "herdr_files"

FeatureHerdrFiles is files sent with a herdr_send: written on this computer, and their paths typed before the text. A program that predates it would type the text alone.

View Source
const FeatureHerdrOpenBeside = "herdr_open_beside"

FeatureHerdrOpenBeside is a herdr_open given a pane: the new tab opens in that pane's workspace, in its directory, with its agent. A program that predates it would open a workspace of its own.

View Source
const FeatureHerdrSubagents = "herdr_subagents"

FeatureHerdrSubagents is the agents a session started, as a tree: the herdr_subagents action. A program that predates it would not know the action.

View Source
const FormatTyped = "typed"

FormatTyped is a source read by running its type.

View Source
const KindAttachment = "attachment"

KindAttachment is what an entry for a file a record came with is called. Its bytes are fetched afterwards with the blob action, which is why it is a kind of its own rather than a file. Its text is what the record said it says, or what a reader on this machine made of it, and is empty for a picture, which is a later night's work.

View Source
const PersonAuthor = "@you"

PersonAuthor is the author a record gives the person whose computer it is, when the source knows a post is theirs but not their name: the server files it under their username.

View Source
const Protocol = 2

Protocol is the version of the exchange this program speaks; the server refuses another. Protocol 2 added `scan`, which is the one action a server may ask for with nobody watching. A server that needs it and meets a program speaking 1 says so rather than failing obscurely.

Variables

View Source
var ErrKnownMissing = errors.New("the known hashes of this pass are not held here; send them again")

ErrKnownMissing is the answer to a page that names a pass whose known hashes this program does not hold: the server sends them with the next request.

View Source
var ErrTerminalEnded = errors.New("the shell ended")

ErrTerminalEnded is how Serve ends when the shell the person attached has: not a failure, the way they detach.

Functions

func DoRequest added in v0.54.0

func DoRequest(ctx context.Context, request *sources.PreparedRequest) (int, []byte, error)

DoRequest makes a type's web request, from wherever it runs.

func LooksLikeSymbol

func LooksLikeSymbol(word string) bool

LooksLikeSymbol says whether a word from a question is an identifier rather than an ordinary word: CamelCase, snake_case, a dotted path, or something with a digit in the middle. Asked of every word of a search, which is why it is cheap and strict.

func NewLocalExecutor added in v0.54.0

func NewLocalExecutor(directory string) sources.Executor

NewLocalExecutor runs a type's commands on this computer from a directory, for trying a type out by hand.

func RunFilesystem

func RunFilesystem(options *Options, arguments *FilesystemArguments) (any, error)

RunFilesystem does one thing with the files and reports it.

func RunHerdr added in v0.120.0

func RunHerdr(ctx context.Context, herdr *Herdr, action string, arguments *HerdrArguments) (any, error)

RunHerdr does one herdr action.

func Serve

func Serve(ctx context.Context, connection Connection, options *Options) error

Serve says hello, then answers requests until the connection ends or the context is done. It returns what ended it; a RefusedError means the server said no.

Types

type AuthorizationForwardArguments added in v0.73.0

type AuthorizationForwardArguments struct {
	// ForwardURL is the dashboard's address that finishes a connection.
	ForwardURL string `json:"forwardUrl"`

	// LifetimeSeconds is how long to wait for the redirect before the
	// listener closes.
	LifetimeSeconds int `json:"lifetimeSeconds,omitempty"`
}

AuthorizationForwardArguments are where to send the browser on to.

type AuthorizationForwardResult added in v0.73.0

type AuthorizationForwardResult struct {
	RedirectURL string `json:"redirectUrl"`
}

AuthorizationForwardResult is the address to give the service.

func RunAuthorizationForward added in v0.73.0

func RunAuthorizationForward(arguments *AuthorizationForwardArguments) (*AuthorizationForwardResult, error)

RunAuthorizationForward opens one listener and answers with its address. It outlives the request, and the connection too: a network that drops while the person is in the middle of signing in should not lose the redirect.

type BackgroundAcknowledgeArguments added in v0.57.0

type BackgroundAcknowledgeArguments struct {
	IDs []string `json:"ids"`
}

BackgroundAcknowledgeArguments say the server has heard these ended.

type BackgroundCommands added in v0.57.0

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

BackgroundCommands are the ones this program holds.

func NewBackgroundCommands added in v0.57.0

func NewBackgroundCommands() *BackgroundCommands

NewBackgroundCommands is an empty registry, for a program that keeps one across its connections.

func (*BackgroundCommands) Close added in v0.57.0

func (self *BackgroundCommands) Close()

Close kills every one still running, for the program ending.

type BackgroundReadArguments added in v0.57.0

type BackgroundReadArguments struct {
	ID          string `json:"id"`
	TailBytes   int    `json:"tailBytes,omitempty"`
	Stream      string `json:"stream,omitempty"`
	Offset      int64  `json:"offset,omitempty"`
	LengthBytes int    `json:"lengthBytes,omitempty"`
}

BackgroundReadArguments ask for one background command with its output: the last tailBytes of each stream, or what text gives when that is zero. With Stream (stdout or stderr), the bytes of that stream from Offset instead, LengthBytes of them or readBytesDefault when that is zero; the whole output is there to be read this way.

type BackgroundStatus added in v0.57.0

type BackgroundStatus struct {
	ID        string          `json:"id"`
	Command   string          `json:"command"`
	Directory string          `json:"directory"`
	Origin    json.RawMessage `json:"origin,omitempty"`
	StartedAt time.Time       `json:"startedAt"`
	EndedAt   *time.Time      `json:"endedAt,omitempty"`
	IsRunning bool            `json:"isRunning"`
	ExitCode  int             `json:"exitCode"`

	// StopReason says it did not end on its own: stopped, or ended with the
	// program. Empty when it ended by itself or is still running.
	StopReason string `json:"stopReason,omitempty"`

	// IsAcknowledged says the server has heard that it ended.
	IsAcknowledged bool `json:"isAcknowledged"`

	// Output, when it was asked for: what is kept of each stream, and how
	// much each has written in all.
	Stdout            string `json:"stdout,omitempty"`
	Stderr            string `json:"stderr,omitempty"`
	IsStdoutTruncated bool   `json:"isStdoutTruncated,omitempty"`
	IsStderrTruncated bool   `json:"isStderrTruncated,omitempty"`
	StdoutByteCount   int64  `json:"stdoutByteCount"`
	StderrByteCount   int64  `json:"stderrByteCount"`

	// When one stream was read by offset (BackgroundReadArguments.Stream):
	// which, where this read began, and where the next begins. Stdout or
	// Stderr then holds just that part; IsStdoutTruncated and
	// IsStderrTruncated say whether more follows it.
	Stream           string `json:"stream,omitempty"`
	StreamOffset     int64  `json:"streamOffset,omitempty"`
	StreamNextOffset int64  `json:"streamNextOffset,omitempty"`
}

BackgroundStatus is one background command as the server is told about it.

type BackgroundStopArguments added in v0.57.0

type BackgroundStopArguments struct {
	ID             string `json:"id"`
	IsAcknowledged bool   `json:"isAcknowledged,omitempty"`
}

BackgroundStopArguments stop one. IsAcknowledged says whoever stopped it needs no notice that it ended: the agent stopping its own command knows.

type BlobArguments

type BlobArguments struct {
	// Path is where the file is on this machine, as the scan reported
	// it in the entry's metadata.
	Path string `json:"path"`

	// Hash is what the scan said the file's bytes come to. The answer is
	// refused when it no longer does.
	Hash string `json:"hash"`

	// MaxBytes is the same bound the scan ran under, said again so that
	// this request cannot be used to get round it. Zero is
	// DefaultMaxAttachmentBytes.
	MaxBytes int64 `json:"maxBytes,omitempty"`
}

BlobArguments is a file the server wants the bytes of.

type BlobResult

type BlobResult struct {
	Path        string `json:"path"`
	Name        string `json:"name"`
	Bytes       int64  `json:"bytes"`
	Hash        string `json:"hash"`
	ContentType string `json:"contentType,omitempty"`
	Base64      string `json:"base64"`
}

BlobResult is the file, bytes and all.

func RunBlob

func RunBlob(options *Options, arguments *BlobArguments) (*BlobResult, error)

RunBlob answers with one file's bytes.

type Connection

type Connection interface {
	ReadJSON(value any) error
	WriteJSON(value any) error
}

Connection is what Serve needs of the websocket: JSON in, JSON out.

type Entry

type Entry struct {
	Name     string    `json:"name"`
	Path     string    `json:"path,omitempty"`
	Kind     string    `json:"kind"` // file, directory, link, other
	Size     int64     `json:"size"`
	Modified time.Time `json:"modified"`
}

Entry is one file or directory as listed.

type FilesystemArguments

type FilesystemArguments struct {
	Action  string `json:"action"`
	Path    string `json:"path"`
	Content string `json:"content,omitempty"`

	// Base64 is the content of a file being put here, encoded, for the
	// bytes that are not text. The server sends it; nothing types it.
	Base64 string `json:"base64,omitempty"`

	Destination string `json:"destination,omitempty"`
	Pattern     string `json:"pattern,omitempty"`
	Find        string `json:"find,omitempty"`
	Replace     string `json:"replace,omitempty"`
	All         bool   `json:"all,omitempty"`
	Offset      int    `json:"offset,omitempty"`
	Limit       int    `json:"limit,omitempty"`
	Recursive   bool   `json:"recursive,omitempty"`
}

FilesystemArguments are one thing to do with the files.

type HTTPArguments added in v0.50.0

type HTTPArguments struct {
	Method string              `json:"method"`
	URL    string              `json:"url"`
	Header map[string][]string `json:"header,omitempty"`
	// Body is the request's body; encoded as base64 on the wire.
	Body []byte `json:"body,omitempty"`
	// TimeoutSeconds bounds the whole request, redirects included.
	TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
	// MaximumBytes bounds how much of the answer is read.
	MaximumBytes int64 `json:"maximumBytes,omitempty"`
}

HTTPArguments are one request to make through this computer.

type HTTPResult added in v0.50.0

type HTTPResult struct {
	Status int                 `json:"status"`
	Header map[string][]string `json:"header"`
	Body   []byte              `json:"body"`
	// Truncated says the body was longer than MaximumBytes and was cut.
	Truncated bool `json:"truncated,omitempty"`
	// URL is where the answer finally came from.
	URL string `json:"url"`
}

HTTPResult is the answer, after any redirects.

func RunHTTP added in v0.50.0

func RunHTTP(ctx context.Context, arguments *HTTPArguments) (*HTTPResult, error)

RunHTTP makes one request through this computer.

type Herdr added in v0.120.0

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

Herdr is this program's view of the person's herdr, held across its connections to the server.

func NewHerdr added in v0.120.0

func NewHerdr(home string) *Herdr

NewHerdr is the view of the herdr running for the person whose home directory this is. Start watches it.

func (*Herdr) Close added in v0.120.0

func (self *Herdr) Close()

Close stops watching.

func (*Herdr) Start added in v0.120.0

func (self *Herdr) Start(ctx context.Context)

Start looks at every pane from now until Close.

type HerdrAnswerResult added in v0.120.0

type HerdrAnswerResult struct {
	HerdrSession     *HerdrSession `json:"herdrSession"`
	IsAnswerAccepted bool          `json:"isAnswerAccepted"`
	// AnsweredWith is what was chosen, in words.
	AnsweredWith string `json:"answeredWith"`
}

HerdrAnswerResult says whether the question went once the answer was pressed.

type HerdrArguments added in v0.120.0

type HerdrArguments struct {
	PaneID    string `json:"paneId,omitempty"`
	TurnCount int    `json:"turnCount,omitempty"`
	LineCount int    `json:"lineCount,omitempty"`
	// Offset is how many of the newest turns (read) or agents (subagents)
	// to skip, so that the older ones can be read.
	Offset int `json:"offset,omitempty"`
	// ShouldIncludeToolDetail asks a read for each tool turn's whole input
	// and what the tool answered.
	ShouldIncludeToolDetail bool `json:"shouldIncludeToolDetail,omitempty"`
	// ShouldKeepColor asks for the screen with its colors, as the codes
	// that select them and nothing else a terminal would act on.
	ShouldKeepColor     bool   `json:"shouldKeepColor,omitempty"`
	Text                string `json:"text,omitempty"`
	WaitSeconds         int    `json:"waitSeconds,omitempty"`
	QuestionFingerprint string `json:"questionFingerprint,omitempty"`
	OptionNumbers       []int  `json:"optionNumbers,omitempty"`
	// OptionLabels, when given, are the labels of the options chosen, as
	// the person was shown them: an answer whose labels differ is
	// refused, so what they confirmed is what is pressed.
	OptionLabels []string `json:"optionLabels,omitempty"`
	FreeText     string   `json:"freeText,omitempty"`
	// Origin is the server's own note of who watches, handed back when
	// the session finishes.
	Origin json.RawMessage `json:"origin,omitempty"`
	// HerdrEventIDs are the events the server acknowledges.
	HerdrEventIDs []string `json:"herdrEventIds,omitempty"`
	// IsRemoval takes the hooks out rather than putting them in.
	IsRemoval bool `json:"isRemoval,omitempty"`
	// Directory, CodingAgentKind and AgentName open a session: where, which
	// coding agent ("claude" or "codex"), and what to call it; the
	// directory's name when none is given.
	Directory       string `json:"directory,omitempty"`
	CodingAgentKind string `json:"codingAgentKind,omitempty"`
	AgentName       string `json:"agentName,omitempty"`
	// ShouldSkipPermissions starts it without asking before it acts: Claude
	// Code with --dangerously-skip-permissions, Codex with --yolo.
	ShouldSkipPermissions bool `json:"shouldSkipPermissions,omitempty"`
	// HerdrFiles are sent with the text: each is written on this computer
	// and its path typed before the text, for the coding agent to open.
	HerdrFiles []*HerdrFile `json:"herdrFiles,omitempty"`
}

HerdrArguments are what every herdr action may be given.

type HerdrCloseResult added in v0.120.0

type HerdrCloseResult struct {
	HerdrSession *HerdrSession `json:"herdrSession"`
	IsClosed     bool          `json:"isClosed"`
}

HerdrCloseResult says a session's pane was closed.

type HerdrEvent added in v0.120.0

type HerdrEvent struct {
	HerdrEventID   string          `json:"herdrEventId"`
	HerdrEventKind string          `json:"herdrEventKind"`
	HerdrSession   *HerdrSession   `json:"herdrSession"`
	Origin         json.RawMessage `json:"origin,omitempty"`
	EventAt        time.Time       `json:"eventAt"`
	// AnswerText is what a question that went was answered with, when that
	// is known: the answer given through TeaNode, or the one Claude Code
	// wrote into its history when the person answered at the keyboard.
	AnswerText string `json:"answerText,omitempty"`
	// contains filtered or unexported fields
}

HerdrEvent is something the program says unasked: a question came, a question went, a watched session finished.

type HerdrFile added in v0.164.0

type HerdrFile struct {
	FileName    string `json:"fileName"`
	FileContent []byte `json:"fileContent"`
}

HerdrFile is one file a send carries.

type HerdrQuestion added in v0.120.0

type HerdrQuestion struct {
	// QuestionFingerprint names this question as it stands: an answer
	// carrying another is refused, so a late answer from far away never
	// presses keys into whatever came after it.
	QuestionFingerprint string                `json:"questionFingerprint"`
	HerdrQuestionKind   string                `json:"herdrQuestionKind"`
	QuestionText        string                `json:"questionText"`
	IsMultipleChoice    bool                  `json:"isMultipleChoice"`
	Options             []HerdrQuestionOption `json:"options"`
	// IsFromTranscript says the question was read from the history file,
	// not from a form on the screen, and is answered by typing.
	IsFromTranscript bool `json:"isFromTranscript,omitempty"`
	// IsNumberless says the form's options have no numbers on screen: they
	// are numbered here, top down, and chosen with the arrows from the one
	// CursorOptionNumber names, which is the option the cursor is on in
	// any form.
	IsNumberless       bool `json:"isNumberless,omitempty"`
	CursorOptionNumber int  `json:"cursorOptionNumber,omitempty"`
}

HerdrQuestion is a question a coding agent waits on.

type HerdrQuestionOption added in v0.120.0

type HerdrQuestionOption struct {
	OptionNumber      int    `json:"optionNumber"`
	OptionLabel       string `json:"optionLabel"`
	OptionDescription string `json:"optionDescription,omitempty"`
	HerdrOptionKind   string `json:"herdrOptionKind"`
}

HerdrQuestionOption is one option of a question, numbered as the form numbers it.

type HerdrReadResult added in v0.120.0

type HerdrReadResult struct {
	HerdrSession *HerdrSession `json:"herdrSession"`
	Turns        []*HerdrTurn  `json:"turns"`
	// IsTruncated says there are older turns than these; NextOffset is the
	// offset that reads them.
	IsTruncated bool `json:"isTruncated"`
	NextOffset  int  `json:"nextOffset,omitempty"`
}

HerdrReadResult is the last turns of a session.

type HerdrScreenResult added in v0.120.0

type HerdrScreenResult struct {
	HerdrSession *HerdrSession `json:"herdrSession"`
	ScreenText   string        `json:"screenText"`
}

HerdrScreenResult is a session's screen.

type HerdrSendResult added in v0.120.0

type HerdrSendResult struct {
	HerdrSession *HerdrSession `json:"herdrSession"`
	IsSent       bool          `json:"isSent"`
	// FilePaths are where the files sent with it were written.
	FilePaths []string `json:"filePaths,omitempty"`
}

HerdrSendResult says the text was typed.

type HerdrSession added in v0.120.0

type HerdrSession struct {
	PaneID string `json:"paneId"`
	// PaneName is the pane as the person finds it in herdr: its
	// workspace's label, its tab's when the workspace has several, and the
	// agent's name, or which agent it is, when a tab holds more than one.
	// The id says nothing to a person; this is what is shown, and either
	// names a pane to every action.
	PaneName string `json:"paneName"`
	// The workspace and tab the pane is in, as herdr numbers and labels
	// them; empty when herdr's lists could not be read.
	WorkspaceID     string `json:"workspaceId"`
	WorkspaceLabel  string `json:"workspaceLabel"`
	WorkspaceNumber int    `json:"workspaceNumber"`
	TabID           string `json:"tabId"`
	TabLabel        string `json:"tabLabel"`
	TabNumber       int    `json:"tabNumber"`
	// IsTabFocused says herdr shows this session's tab on the computer's
	// screen now: its tab is the active one of the focused workspace.
	IsTabFocused      bool   `json:"isTabFocused"`
	CodingAgentKind   string `json:"codingAgentKind"`
	CodingSessionID   string `json:"codingSessionId"`
	HerdrSessionState string `json:"herdrSessionState"`
	// HerdrAgentStatus is what herdr itself said, for when the two
	// disagree.
	HerdrAgentStatus string `json:"herdrAgentStatus"`
	PaneTitle        string `json:"paneTitle"`
	WorkingDirectory string `json:"workingDirectory"`
	TranscriptPath   string `json:"transcriptPath,omitempty"`
	// IsWatched says somebody asked to be told when it next finishes.
	IsWatched bool           `json:"isWatched,omitempty"`
	Question  *HerdrQuestion `json:"question,omitempty"`
	// contains filtered or unexported fields
}

HerdrSession is one coding session in one of herdr's panes.

type HerdrSetupResult added in v0.120.0

type HerdrSetupResult struct {
	IsInstalled    bool     `json:"isInstalled"`
	SettingsPath   string   `json:"settingsPath"`
	ScriptPath     string   `json:"scriptPath"`
	BackupPath     string   `json:"backupPath,omitempty"`
	HookEventNames []string `json:"hookEventNames"`
}

HerdrSetupResult says what setup did.

type HerdrSubagent added in v0.186.0

type HerdrSubagent struct {
	SubagentID string `json:"subagentId"`
	// ParentSubagentID is the agent that started this one; empty when the
	// session itself did.
	ParentSubagentID string `json:"parentSubagentId,omitempty"`
	// SubagentType is the kind of agent, such as general-purpose or Explore.
	SubagentType string `json:"subagentType"`
	SubagentName string `json:"subagentName,omitempty"`
	// TaskText is the one-line task its parent gave it.
	TaskText      string `json:"taskText"`
	ModelName     string `json:"modelName"`
	SubagentState string `json:"subagentState"`
	// SpawnDepth is 1 for an agent the session started, 2 for one that
	// agent started, and so on.
	SpawnDepth int        `json:"spawnDepth"`
	StartedAt  *time.Time `json:"startedAt,omitempty"`
	// EndedAt is when its history was last written; nil while it runs.
	EndedAt *time.Time `json:"endedAt,omitempty"`
	// ToolNames are the tools it called, the most used first; a tool of a
	// connected server is named by the server.
	ToolNames     []string `json:"toolNames"`
	ToolCallCount int      `json:"toolCallCount"`
}

HerdrSubagent is one agent a session started, or one an agent started.

type HerdrSubagentsResult added in v0.186.0

type HerdrSubagentsResult struct {
	HerdrSession     *HerdrSession `json:"herdrSession"`
	SessionModelName string        `json:"sessionModelName"`
	// RequestStartedAt is when the person last spoke to the session.
	RequestStartedAt *time.Time       `json:"requestStartedAt,omitempty"`
	Subagents        []*HerdrSubagent `json:"subagents"`
	// IsTruncated says there are older agents than this page holds;
	// LeftCount is how many, and NextOffset is the offset that reads them.
	IsTruncated bool `json:"isTruncated"`
	LeftCount   int  `json:"leftCount"`
	NextOffset  int  `json:"nextOffset,omitempty"`
}

HerdrSubagentsResult is the agents of a session's current request.

type HerdrTurn added in v0.120.0

type HerdrTurn struct {
	HerdrTurnRole string     `json:"herdrTurnRole"`
	TurnText      string     `json:"turnText"`
	TurnAt        *time.Time `json:"turnAt,omitempty"`
	// ToolInputText and ToolResultText are a tool turn's whole input and
	// what the tool answered; only when a read asks for them.
	ToolInputText  string `json:"toolInputText,omitempty"`
	ToolResultText string `json:"toolResultText,omitempty"`
	// HasToolDetail says a tool turn has an input or a result to show,
	// whether or not the read asked for them.
	HasToolDetail bool `json:"hasToolDetail,omitempty"`
	// contains filtered or unexported fields
}

HerdrTurn is one thing said or done in a coding session: the person's words, the agent's, or a tool the agent called, in a line.

type HerdrWaitResult added in v0.120.0

type HerdrWaitResult struct {
	HerdrSession *HerdrSession `json:"herdrSession"`
	IsTimedOut   bool          `json:"isTimedOut"`
}

HerdrWaitResult is a session once it stopped working, or when the wait ran out.

type Match

type Match struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Text string `json:"text"`

	// LineBytes is how long the line was, when Text is only the start of
	// it; zero when Text is the whole line.
	LineBytes int `json:"lineBytes,omitempty"`
}

Match is one line of a file that matched.

type Options

type Options struct {
	// Terminal, when set, attaches the terminal this program runs in.
	Terminal *TerminalOptions

	// Background holds the commands running on after their call, across
	// connections; a program that reconnects passes the same one each
	// time. When nil, the program does not offer background commands.
	Background *BackgroundCommands

	// Herdr watches the person's herdr sessions across connections, as
	// Background holds commands. When nil, the program does not offer
	// them.
	Herdr *Herdr

	// Token is the person's, from `teanode auth login`.
	Token string
	// Name is what the computer is called to the agent; the host name by
	// default. System is the operating system, for the agent to know what
	// commands it may use.
	Name   string
	System string
	// Description is what the computer is and what it is for, in the
	// person's words, so the agent can tell it from their others: which
	// one is for work, which one reaches which network.
	Description string
	// Home is where a command runs unless a directory is given, and what
	// ~ and a relative path are from; the person's home directory by
	// default.
	Home string

	// Notice is where the program says what it was asked and how long it
	// took. Optional; nothing is said when it is not set.
	//
	// The server can only report that this end did not answer within ten
	// minutes. Which request, and whether it ran at all or never arrived,
	// is known here and nowhere else -- and a source that timed out every
	// pass for an evening could not be told apart from one that was never
	// asked, because the program that was or was not asked said nothing.
	Notice func(text string)
}

Options say what the program offers.

type RefusedError

type RefusedError struct {
	Reason string
}

RefusedError is the server turning the program away in words: a token it does not take, a protocol it does not speak. Not worth reconnecting for.

func (*RefusedError) Error

func (self *RefusedError) Error() string

type RepositoryActivity added in v0.79.0

type RepositoryActivity struct {
	CommitCountLast90Days  int `json:"commitCountLast90Days"`
	CommitCountLast365Days int `json:"commitCountLast365Days"`
	AuthorCountLast365Days int `json:"authorCountLast365Days"`
}

RepositoryActivity is how many commits a checkout had lately and by how many people, by the author's date.

type RepositoryComponent added in v0.79.0

type RepositoryComponent struct {
	// Path is the component's directory, relative to the checkout; empty
	// for a module a moduleset builds from the checkout as a whole.
	Path string `json:"path,omitempty"`

	// Name is what its build file calls it, or its directory's name when
	// the build file does not say.
	Name string `json:"name"`

	Ecosystem string `json:"ecosystem"`
	File      string `json:"file"`

	// Dependencies are what it needs: other components of the checkout by
	// their names, and packages as its build file names them.
	Dependencies []string `json:"dependencies,omitempty"`
}

RepositoryComponent is one part of a checkout that builds on its own: a subdirectory with a build file of its own, or one of several modules a moduleset builds from this same repository.

type RepositoryDependency added in v0.79.0

type RepositoryDependency struct {
	Name string `json:"name"`

	// Ecosystem is which kind of build file named it: go, npm, python,
	// cargo or cmake.
	Ecosystem string `json:"ecosystem"`

	// File is the build file it was read from, relative to the checkout.
	File string `json:"file"`
}

RepositoryDependency is one thing a build file says the checkout needs: a Go module, an npm package, a Python or Rust package, a CMake package.

type RepositoryModule added in v0.79.0

type RepositoryModule struct {
	Name string `json:"name"`

	// Repository is the last segment of the module's repository path,
	// without `.git`, which is what a checkout of it is usually called.
	// The module's own name when the moduleset does not say.
	Repository string `json:"repository,omitempty"`

	Dependencies []string `json:"dependencies,omitempty"`
	File         string   `json:"file"`
	// contains filtered or unexported fields
}

RepositoryModule is one module of a jhbuild moduleset: a name the moduleset builds, the repository it builds it from, and the other modules it needs first.

type RepositoryProfile

type RepositoryProfile struct {
	Head          string         `json:"head,omitempty"`
	DefaultBranch string         `json:"defaultBranch,omitempty"`
	NewestTag     string         `json:"newestTag,omitempty"`
	Remotes       []string       `json:"remotes,omitempty"`
	Languages     map[string]int `json:"languages,omitempty"`
	Readme        string         `json:"readme,omitempty"`
	First         *time.Time     `json:"first,omitempty"`
	Last          *time.Time     `json:"last,omitempty"`
	Commits       int            `json:"commits,omitempty"`
	Contributors  int            `json:"contributors,omitempty"`
	Dirty         bool           `json:"dirty,omitempty"`

	// Description is what the README says the thing is: its first real
	// paragraph, with the markdown taken off. The whole README is also
	// indexed as a file, so this is for the page's opening and nothing
	// else. Readme is kept for callers that want the raw text.
	Description string `json:"description,omitempty"`

	// Directories is the top of the tree: the first level of it, which is
	// what "what modules does it have" means for most checkouts.
	Directories []string `json:"directories,omitempty"`

	// Module is what the checkout calls itself in its own manifest --
	// go.mod, package.json, pyproject.toml, Cargo.toml -- where it has
	// one.
	Module string `json:"module,omitempty"`

	// Authors is everyone who has committed, with how much and when.
	// Filtering this down to people the person actually worked with is
	// the server's job; the whole list is the evidence for it.
	Authors []ScanAuthor `json:"authors,omitempty"`

	// Dependencies are what the checkout's build files say it needs, and
	// Modules what a jhbuild moduleset in it says other repositories are
	// and need. Read by a program, not guessed by a model, so that the
	// links between checkouts are exact. Both are left out by a program
	// that predates them, and a server reads their absence as nothing
	// known.
	Dependencies []RepositoryDependency `json:"dependencies,omitempty"`
	Modules      []RepositoryModule     `json:"modules,omitempty"`

	// Components are the parts of the checkout that build on their own,
	// each with what it needs. Left out, like the two above, by a program
	// that predates them.
	Components []RepositoryComponent `json:"components,omitempty"`

	// Activity is how busy the checkout has been lately, counted from the
	// same history as Commits. Nil from a program that predates it.
	Activity *RepositoryActivity `json:"activity,omitempty"`

	// IsBuildRead says this program read the build files and the history
	// for Dependencies, Modules, Components and Activity, so that their
	// being empty means the checkout has none. A program that predates
	// them sends none of the five, and the server then leaves what an
	// earlier pass wrote from them alone rather than take it for "no
	// dependencies, no components, no activity".
	IsBuildRead bool `json:"isBuildRead,omitempty"`
}

RepositoryProfile is what git says about a checkout: the first facts of a project's page, computed here in one pass and costing no model at all.

type ScanArguments

type ScanArguments struct {
	// Root is the directory to read.
	Root string `json:"root"`

	// Format is how to read it: files (the default), journal, records,
	// typed.
	Format string `json:"format,omitempty"`

	// SourceType is the source type's file, for the typed format, with
	// Settings the source's values for it and Secrets the ones it
	// declares. SourceKey names the directory under the person's cache
	// the type keeps its state in; Root is not used for a typed source,
	// so a request cannot point its writing anywhere else.
	SourceType string            `json:"sourceType,omitempty"`
	Settings   map[string]any    `json:"settings,omitempty"`
	Secrets    map[string]string `json:"secrets,omitempty"`
	SourceKey  string            `json:"sourceKey,omitempty"`

	Include []string `json:"include,omitempty"`
	Exclude []string `json:"exclude,omitempty"`

	// Known is what the server already holds: external identifier to
	// hash. Anything whose hash matches is reported and its text left
	// out, which is what makes a second pass cheap.
	//
	// Never omitted when empty: a source with nothing indexed yet sends an
	// empty map on its first page, and omitted it arrived as no map at all,
	// which the daemon answers with ErrKnownMissing -- so a new source's
	// first pass failed every time, and the retry with the map failed the
	// same way.
	Known map[string]string `json:"known"`

	// KnownID names the pass Known belongs to. Sent with Known, the map
	// is kept here under that name; sent without it, the map kept under
	// that name is used, and an unknown name is refused with
	// ErrKnownMissing so the server sends the map again. A source of
	// four hundred thousand documents has a map of fifty megabytes, and
	// carrying it on every page of two hundred and fifty entries was
	// most of what a page cost.
	KnownID string `json:"knownId,omitempty"`

	// After is where the last pass stopped, so this one goes on from
	// there: a path, a commit, a channel and a timestamp.
	After string `json:"after,omitempty"`

	// Most is how many entries to answer with.
	Most int `json:"most,omitempty"`

	// MaxAttachmentBytes is the largest file a record's attachment may
	// be. The server resolves it from the source and the configuration
	// and says it here, so that an operator can raise it without every
	// person on the deployment updating this program. Zero -- an older
	// server, which says nothing -- is DefaultMaxAttachmentBytes, never
	// no limit at all.
	MaxAttachmentBytes int64 `json:"maxAttachmentBytes,omitempty"`

	// OwnAddresses are the addresses that are the person: their account's
	// own, and every one on the card they marked as themselves. A
	// checkout whose history holds none of them is one they cloned, and
	// its files stay here.
	//
	// Said by the server on every request rather than known here,
	// for the same reason as the bound above: who somebody is lives on
	// the card they keep, it changes there, and a copy kept on this
	// machine would go stale without anybody being able to see that it
	// had. Empty -- an older server, or a person with no card yet --
	// leaves every checkout read, because silence must not empty a
	// source.
	OwnAddresses []string `json:"ownAddresses,omitempty"`

	// ReadEveryCheckout reads the files of every checkout in the tree,
	// including the ones nobody here ever committed to. It is the
	// source's own setting, for somebody who does want a dependency's
	// source read.
	ReadEveryCheckout bool `json:"readEveryCheckout,omitempty"`

	// OwnCommitsAtLeast is how many commits of the person's own a
	// checkout's history must hold before its files are read, whatever
	// the length of that history. Zero -- an older server, or a source
	// that says nothing -- is the bar ownCommitsNeeded works out, which
	// climbs with the log.
	//
	// Said by the server, for the same reason as the bound above: what
	// counts as somebody's own work is an argument to have on the
	// source, not one settled by which release of this program they
	// happen to be running.
	OwnCommitsAtLeast int `json:"ownCommitsAtLeast,omitempty"`

	// CommitsPerPass is how many commits one pass over this tree
	// offers, over all the checkouts in it. Zero -- an older server,
	// which says nothing -- is scanCommitsPerPass.
	//
	// Said by the server, for the same reason as the attachment bound
	// above: a tree of a hundred checkouts and a third of a million
	// commits is paced by what the person set on the source, not by a
	// release everybody has to install.
	CommitsPerPass int `json:"commitsPerPass,omitempty"`
}

ScanArguments is what the server asks for.

type ScanAuthor

type ScanAuthor struct {
	Name    string     `json:"name"`
	Address string     `json:"address"`
	Commits int        `json:"commits"`
	First   *time.Time `json:"first,omitempty"`
	Last    *time.Time `json:"last,omitempty"`
}

ScanAuthor is one person in a repository's history.

type ScanEntry

type ScanEntry struct {
	// ExternalID is what the server files it under: a path relative to
	// the root, a commit hash, a channel and a range.
	ExternalID string `json:"id"`

	Kind       string     `json:"kind"`
	Title      string     `json:"title,omitempty"`
	URL        string     `json:"url,omitempty"`
	Size       int64      `json:"size,omitempty"`
	Hash       string     `json:"hash,omitempty"`
	ModifiedAt *time.Time `json:"modifiedAt,omitempty"`
	HappenedAt *time.Time `json:"happenedAt,omitempty"`

	// Text is what was read, and is left out when the server said it
	// already holds this hash.
	Text string `json:"text,omitempty"`

	// Unchanged says the server's copy is still current.
	Unchanged bool `json:"unchanged,omitempty"`

	// Refused says why nothing was sent: a secret, a file too large, a
	// kind nothing here can read.
	Refused string `json:"refused,omitempty"`

	// Metadata is what the kind carries beside its text: an author, a
	// repository, the people in a thread.
	Metadata map[string]any `json:"metadata,omitempty"`

	// Private marks a thread or a channel only the person can see.
	Private bool `json:"private,omitempty"`

	// Symbols are the definitions a code file declares.
	Symbols []ScanSymbol `json:"symbols,omitempty"`

	// Repository is filled on the entry for a repository's root: what
	// `git` says about it, which becomes the first facts of its page.
	Repository *RepositoryProfile `json:"repository,omitempty"`
}

ScanEntry is one thing found.

type ScanResult

type ScanResult struct {
	Entries []ScanEntry `json:"entries"`

	// Next is where the following page starts; empty when there is no
	// more.
	Next string `json:"next,omitempty"`

	// Refused is how many entries carried something that must not leave
	// this machine.
	Refused int `json:"refused,omitempty"`

	// Extractors says which outside readers were found, so the source's
	// page can say what it cannot read here.
	Extractors []string `json:"extractors,omitempty"`

	// CheckoutsKeptToProfile is how many checkouts in this tree were kept
	// to what git says about them, their files left unread, and
	// FilesKeptToProfile how many files that was. Counted over the whole
	// tree when the pass built its manifest, and said the same on every
	// page of that pass.
	//
	// Reported rather than silent: this is the program declining to read
	// something the person asked it to read, and a person who disagrees
	// has to be able to see it first.
	CheckoutsKeptToProfile int `json:"checkoutsKeptToProfile,omitempty"`
	FilesKeptToProfile     int `json:"filesKeptToProfile,omitempty"`

	// Unfinished says a typed source's reading ran out of time part way:
	// what it read is here, and the pass this page belongs to must not
	// delete what it did not see, since the reading goes on next pass.
	IsUnfinished bool `json:"unfinished,omitempty"`
}

ScanResult is one page of a scan.

func RunScan

func RunScan(ctx context.Context, options *Options, arguments *ScanArguments) (*ScanResult, error)

RunScan reads a tree and answers with a page of what it found.

type ScanSymbol

type ScanSymbol struct {
	Symbol string `json:"symbol"`
	Kind   string `json:"kind,omitempty"`
	Line   int    `json:"line,omitempty"`
}

ScanSymbol is one definition.

type SessionCloseArguments

type SessionCloseArguments struct {
	Session string `json:"session"`
}

SessionCloseArguments end one. It is asked to stop, and killed if it does not; a session left open by a turn that ended is not the person's problem to notice.

type SessionReadArguments

type SessionReadArguments struct {
	Session string `json:"session"`
}

SessionReadArguments ask for the screen as it stands.

type SessionResizeArguments

type SessionResizeArguments struct {
	Session string `json:"session"`
	Columns int    `json:"columns"`
	Rows    int    `json:"rows"`
}

SessionResizeArguments change a terminal's size.

type SessionResult

type SessionResult struct {
	Session string `json:"session"`
	OK      bool   `json:"ok"`
}

SessionResult is the answer to writing, signalling or closing.

type SessionScreen

type SessionScreen struct {
	Session string `json:"session"`
	Columns int    `json:"columns"`
	Rows    int    `json:"rows"`

	// Text is the screen, one line per row, trailing blank rows dropped.
	Text string `json:"text"`

	// CursorX and CursorY are where the cursor is, from the top left.
	CursorX int `json:"cursorX"`
	CursorY int `json:"cursorY"`

	// Changed says the screen has changed since it was last read, which is
	// what a wait for it to settle looks at.
	Changed bool `json:"changed"`

	// Ended says the program finished, with Code. The screen is still what
	// it left.
	Ended bool `json:"ended"`
	Code  int  `json:"code"`
}

SessionScreen is what a terminal shows at this moment.

type SessionSignalArguments

type SessionSignalArguments struct {
	Session string `json:"session"`
	Signal  string `json:"signal"`
}

SessionSignalArguments send a signal: "int", "term", "kill", or "hup".

type SessionStartArguments

type SessionStartArguments struct {
	// Session is the identifier the server chose. It names this session in
	// everything after, in both directions.
	Session string `json:"session"`

	// Kind is "stdio" for a program spoken to over its standard streams,
	// or "pty" for one run in a terminal and read as a screen.
	Kind string `json:"kind"`

	// Command and Arguments are what to run; Directory where; Environment
	// what to add to this program's own.
	Command     string            `json:"command"`
	Arguments   []string          `json:"arguments,omitempty"`
	Directory   string            `json:"directory,omitempty"`
	Environment map[string]string `json:"environment,omitempty"`

	// Columns and Rows size a terminal; a stdio session ignores them.
	Columns int `json:"columns,omitempty"`
	Rows    int `json:"rows,omitempty"`
}

SessionStartArguments start one.

type SessionStartResult

type SessionStartResult struct {
	Session string `json:"session"`
	PID     int    `json:"pid"`
}

SessionStartResult says it started, and what it is.

type SessionWriteArguments

type SessionWriteArguments struct {
	Session string `json:"session"`
	Data    string `json:"data"`
}

SessionWriteArguments write to one's input. Data is base64, because what goes to a program's standard input is bytes and not necessarily text.

type ShellArguments

type ShellArguments struct {
	Command     string            `json:"command"`
	Directory   string            `json:"directory,omitempty"`
	Timeout     int               `json:"timeout,omitempty"`
	Environment map[string]string `json:"environment,omitempty"`

	// IsBackground starts it and answers at once, leaving it running.
	// ShouldKeepOnTimeout leaves it running when the call's wait runs
	// out, rather than killing it. Both hand it to the background
	// commands, which a server that predates them never asks for.
	IsBackground        bool `json:"isBackground,omitempty"`
	ShouldKeepOnTimeout bool `json:"shouldKeepOnTimeout,omitempty"`

	// Origin is the server's own note of who started it, handed back
	// untouched when it ends so the server knows whom to tell.
	Origin json.RawMessage `json:"origin,omitempty"`
}

ShellArguments are a command to run.

type ShellResult

type ShellResult struct {
	Stdout          string  `json:"stdout"`
	Stderr          string  `json:"stderr"`
	ExitCode        int     `json:"exitCode"`
	StdoutTruncated bool    `json:"stdoutTruncated,omitempty"`
	StderrTruncated bool    `json:"stderrTruncated,omitempty"`
	TimedOut        bool    `json:"timedOut,omitempty"`
	Seconds         float64 `json:"seconds"`

	// BackgroundID names the command when it is still running in the
	// background: started there, or moved there when the wait ran out.
	// The output is then what it had written so far.
	BackgroundID string `json:"backgroundId,omitempty"`

	// OutputID names the command when it ended and wrote more than an
	// answer carries: all of its output stays readable by this id, with an
	// offset, as a background command's is.
	OutputID string `json:"outputId,omitempty"`
}

ShellResult is what a command did.

func RunShell

func RunShell(ctx context.Context, options *Options, background *BackgroundCommands, arguments *ShellArguments) (*ShellResult, error)

RunShell runs a command through the person's shell, in a directory of theirs, and reports what it printed: when it ends, or when the timeout comes -- killing it then, or leaving it in the background when the call asked for that and there is somewhere to leave it.

type TerminalOptions

type TerminalOptions struct {
	// Input is what the person types; Output is their screen.
	Input  io.Reader
	Output io.Writer
	// Shell is what to run in it; their $SHELL by default.
	Shell string
	// Size is the terminal's size now, asked for as the person resizes it.
	Size func() (columns, rows int)
}

TerminalOptions attach the terminal this program is running in: the person's own shell in a pty, which they type into and read as usual, and which their agent can read and type into as well. The pty is a session like any other; what is different is that somebody is sitting in it.

Jump to

Keyboard shortcuts

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