groktty

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCodexCommandArgv

func BuildCodexCommandArgv(env *exec.Env, settingsPath, agentPath, model, resumeSession string) ([]string, error)

BuildCodexCommandArgv returns argv for the interactive Codex TUI inside the PTY.

func BuildCommandArgv

func BuildCommandArgv(env *exec.Env, settingsPath, agentPath, model, resumeSession string) ([]string, error)

BuildCommandArgv returns argv for the interactive grok TUI inside the PTY.

func BuildGrokCommandArgv

func BuildGrokCommandArgv(env *exec.Env, settingsPath, agentPath, model, resumeSession string) ([]string, error)

BuildGrokCommandArgv returns argv for the interactive grok TUI inside the PTY.

func CodexHome

func CodexHome() string

func DiscoverActiveCodexTranscript

func DiscoverActiveCodexTranscript(ctx context.Context, codexHome, workspace string, runStart time.Time) (sessionID, path string, err error)

func DiscoverCodexTranscript

func DiscoverCodexTranscript(ctx context.Context, codexHome, sessionID string) (string, error)

func DiscoverSession

func DiscoverSession(ctx context.Context, grokHome, workspace, prompt string, runStart time.Time) (sessionID string, updatesPath string, err error)

DiscoverSession locates the grok on-disk session matching workspace cwd and prompt. When AGENT_RUN_GROK_TTY_GROK_SESSION_ID is set, discovery is skipped.

func EncodedCwd

func EncodedCwd(workspace string) (string, error)

EncodedCwd returns url.PathEscape(absWorkspace) matching grok session layout.

func FindCodexResumeSessionID

func FindCodexResumeSessionID(text string) string

func GrokHome

func GrokHome() string

GrokHome returns the grok data directory ($GROK_HOME or $HOME/.grok).

func ParseShellWords

func ParseShellWords(line string) ([]string, error)

ParseShellWords splits a shell-style command line into argv words.

func RemoveRegistry

func RemoveRegistry(home, sessionID string)

RemoveRegistry deletes the registry file for a session.

func RemoveRegistryFor

func RemoveRegistryFor(home, dirName, sessionID string)

RemoveRegistryFor deletes the registry file for a provider-specific session.

func RenderTerminalText

func RenderTerminalText(scrollback []byte) []byte

RenderTerminalText renders PTY scrollback into a plain terminal screen snapshot.

func ReserveRegistrySessionID

func ReserveRegistrySessionID(home, dirName string) (string, func(), error)

ReserveRegistrySessionID returns the next session-N id for a registry dir. The returned release function must be called after the registry entry is written, so concurrent processes cannot choose the same id.

func Run

func Run(ctx context.Context, opts RunOptions) (captured string, grokSessionID string, err error)

Run starts an adhoc ptywrap server, runs interactive grok in a PTY, injects the prompt after the TUI banner, tails the matching grok session updates.jsonl when found, and blocks until the session exits.

func StripANSI

func StripANSI(data []byte) string

StripANSI removes ANSI escape sequences from terminal scrollback.

func TailCodexTranscriptFromOffset

func TailCodexTranscriptFromOffset(ctx context.Context, path string, startOffset int64, emit func(types.AgentEvent) error) error

func TailUpdates

func TailUpdates(ctx context.Context, updatesPath string, emit func(types.AgentEvent) error) error

TailUpdates polls updates.jsonl and emits AgentEvents for new lines until ctx is done.

func TailUpdatesFromOffset

func TailUpdatesFromOffset(ctx context.Context, updatesPath string, startOffset int64, emit func(types.AgentEvent) error) error

TailUpdatesFromOffset tails updates.jsonl starting at the given byte offset. Use updatesTailStartOffset at discovery time to skip bytes already on disk.

func WriteRegistry

func WriteRegistry(home string, entry RegistryEntry) error

WriteRegistry creates the registry file for a live grok-tty session.

func WriteRegistryFor

func WriteRegistryFor(home, dirName string, entry RegistryEntry) error

WriteRegistryFor creates a live TTY registry file in a provider-specific registry dir.

Types

type ACPConverter

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

ACPConverter converts ACP session updates to AgentEvents with chunk coalescing.

func NewACPConverter

func NewACPConverter() *ACPConverter

NewACPConverter creates a converter for one grok session tail.

func (*ACPConverter) Flush

func (c *ACPConverter) Flush() []types.AgentEvent

Flush emits any buffered chunk coalescence at end of tail.

func (*ACPConverter) ProcessLine

func (c *ACPConverter) ProcessLine(line string) []types.AgentEvent

ProcessLine parses one updates.jsonl line and returns AgentEvents to emit.

type RegistryEntry

type RegistryEntry struct {
	SessionID  string `json:"session_id"`
	ListenAddr string `json:"listen_addr"`
	PID        int    `json:"pid"`
	CreatedAt  string `json:"created_at"`
}

RegistryEntry maps a grok-tty session id to the adhoc ptywrap listen address.

func ReadRegistry

func ReadRegistry(home, sessionID string) (*RegistryEntry, error)

ReadRegistry loads a grok-tty session registry entry.

func ReadRegistryFor

func ReadRegistryFor(home, dirName, sessionID, label string) (*RegistryEntry, error)

ReadRegistryFor loads a provider-specific TTY session registry entry.

func ReadSupportedRegistry

func ReadSupportedRegistry(home, sessionID string) (*RegistryEntry, string, error)

ReadSupportedRegistry searches known TTY registry dirs deterministically and returns the first reachable live entry.

type RunOptions

type RunOptions struct {
	Home                 string
	Workspace            string
	Prompt               string
	Model                string
	ResumeSessionID      string
	SettingsPath         string
	AgentPath            string
	RunnerID             string
	StderrPrefix         string
	RegistryDir          string
	BannerProvider       string
	BannerMarkers        []string
	DisableTail          bool
	KeepTerminalAlive    bool
	KeepTerminalBlocking bool // block after prompt inject to keep ptywrap server alive
	BuildArgv            func(env *agentexec.Env, settingsPath, agentPath, model, resumeSession string) ([]string, error)
	Stderr               io.Writer
	Emit                 func(types.AgentEvent) error
	OnTerminalSessionID  func(string)
}

RunOptions configures a grok-tty headless invocation.

Jump to

Keyboard shortcuts

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