computer

package
v0.65.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 31 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. What bounds the program is the directories the person allowed, enforced here on their machine, and their yes.

Index

Constants

View Source
const (
	BackgroundStopReasonStopped  = "stopped"
	BackgroundStopReasonLifetime = "lifetime"
	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), out of lifetime, or with this program as it shut down.

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 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 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 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 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 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"`
}

BackgroundReadArguments ask for one background command with its output: the last tailBytes of each stream, or all that is kept when that is zero.

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 out of
	// lifetime. 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"`
}

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 Match

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

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

	// 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 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"`
}

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"`
}

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