claudecore

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PromptInjectCheckInterval = 500 * time.Millisecond
	PromptInjectTimeout       = 30 * time.Second
)

Variables

This section is empty.

Functions

func DefaultLauncher

func DefaultLauncher() terminal.Launcher

func MustJSON

func MustJSON(v any) json.RawMessage

func ShellQuote

func ShellQuote(s string) string

ShellQuote single-quotes a string for safe interpolation into a shell command.

func TranscriptPath

func TranscriptPath(home, dir, sessionID string) string

func ValidTmuxKey

func ValidTmuxKey(key string) bool

ValidTmuxKey returns true if key is a safe single-character string for tmux send-keys.

func WaitForPaneReady

func WaitForPaneReady(ctx context.Context, term terminal.Session) bool

WaitForPaneReady blocks until Claude's input box is taking input. It auto-dismisses the trust-safety dialog if present. Returns false on context cancel, capture error, send error, or the PromptInjectTimeout deadline — callers must treat any false return as "do not paste, the pane is not in a known-ready state".

Types

type PaneState

type PaneState string
const (
	PaneStateUnknown    PaneState = "unknown"
	PaneStateActive     PaneState = "active"
	PaneStatePermission PaneState = "permission"
	PaneStateIdle       PaneState = "idle"
)

func ClassifyPane

func ClassifyPane(text string) PaneState

ClassifyPane returns the most-specific pane state. After a turn is submitted the pane shows both an echo line that starts with `❯` (the prior user prompt) AND a spinner line below it; the input box `❯` reappears at the bottom. An activity line therefore must beat any `❯` line, otherwise we'd report idle while a turn is still running.

func ScanTerminal

func ScanTerminal(ctx context.Context, term terminal.Session) (PaneState, error)

type PermissionOption

type PermissionOption struct {
	ID    string
	Label string
}

type Session

type Session struct {
	SessionID string
	RunID     string
	Dir       string
	TmuxName  string

	Term       terminal.Session
	Transcript *TranscriptReader

	Events    chan events.Event
	Done      chan struct{}
	Ctx       context.Context
	CancelFn  context.CancelFunc
	StartedAt time.Time

	Mu                  sync.Mutex
	Prompted            bool
	Active              bool
	Finished            bool
	PendingTerminalPerm *TerminalPermission
}

func NewSession

func NewSession(ctx context.Context, opts SessionOptions) *Session

func (*Session) Emit

func (s *Session) Emit(ev events.Event)

func (*Session) MarkActive

func (s *Session) MarkActive()

func (*Session) MarkFinished

func (s *Session) MarkFinished() bool

func (*Session) ScanTerminalTick

func (s *Session) ScanTerminalTick()

func (*Session) ScanTranscriptTick

func (s *Session) ScanTranscriptTick()

func (*Session) SendCancelKeys

func (s *Session) SendCancelKeys(ctx context.Context) error

type SessionOptions

type SessionOptions struct {
	SessionID  string
	RunID      string
	Dir        string
	TmuxName   string
	Term       terminal.Session
	Transcript *TranscriptReader
	EventsBuf  int
}

type TerminalPermission

type TerminalPermission struct {
	RequestID string
	Prompt    string
	Options   []PermissionOption
	CreatedAt time.Time
}

func ParseTerminalPermission

func ParseTerminalPermission(text string) *TerminalPermission

ParseTerminalPermission extracts a TerminalPermission from pane text, or nil if the text doesn't represent a Claude permission dialog.

type TranscriptReader

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

TranscriptReader incrementally reads new records from a JSONL transcript. Successive Tick calls return only records appended since the last call.

func NewTranscriptReader

func NewTranscriptReader(path string) *TranscriptReader

func (*TranscriptReader) Tick

Tick reads records appended since the previous call. It returns the records, the file's mtime (zero if missing), and any read error. A missing file is not an error — callers tick early and often, and the transcript only appears once Claude writes its first record.

Offset only advances past newline-terminated lines so a half-written final record is left for the next tick to consume in full.

type TranscriptRecord

type TranscriptRecord struct {
	Type       string `json:"type"`
	AITitle    string `json:"aiTitle,omitempty"`
	Timestamp  string `json:"timestamp,omitempty"`
	StopReason string `json:"stop_reason,omitempty"`
}

TranscriptRecord is the minimal subset of JSONL fields used for status detection. Records are heterogeneous; unknown fields are ignored.

Directories

Path Synopsis
Package terminal provides an abstraction for interactive terminal sessions.
Package terminal provides an abstraction for interactive terminal sessions.

Jump to

Keyboard shortcuts

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