Documentation
¶
Index ¶
- Constants
- func BuildForkFollowUpCommand(agentRunBinary, cwd, grokSessionID string) string
- func BuildSessionsRestoreScript(doc *SaveDocument) string
- func BuildSessionsRestoreScriptWithTell(doc *SaveDocument, appTell string) string
- func ClearRestoreAppDiskForTest()
- func DefaultDecisionsPath() string
- func DefaultSessionsAutoPath() string
- func DefaultSessionsSavePath() string
- func Handle(args []string) error
- func InstallPhasedFixtureCollectorForTest(t testing.TB, opts PhasedFixtureOpts)
- func ProcessCwd() (string, error)
- func RenderSessionStatus(w io.Writer, snap *Snapshot, s *SnapshotSession, opt RenderOptions) error
- func RenderSnapshot(w io.Writer, snap *Snapshot, opt RenderOptions) error
- func RunFocusForTest(args []string, stdout, stderr io.Writer, fake *FocusFake) int
- func RunForTest(args []string, stdout, stderr io.Writer, workingDir string) int
- func RunForTestEnv(args []string, stdout, stderr io.Writer, env TestRun) int
- func SetCurrentSpaceIndexForTest(fn CurrentSpaceIndexFunc)
- func SetGOOSForTest(goos string)
- func SetInstallHTTPForTest(latestURL string, client *http.Client) (restore func())
- func SetMultiAppPreflightForTest(fn MultiAppPreflightFn)
- func SetRestoreAppDiskForTest(homeExists, systemExists bool)
- func SetSessionsRunRestoreASForTest(fn func(script string) (string, error))
- func SetSnapshotCollectorForTest(c *SnapshotCollector)
- func SetSpaceBackendForTest(b SpaceBackend)
- func SetSpaceIndexForWindowForTest(fn SpaceIndexResolver)
- func SetSpaceSwitchSettleForTest(d time.Duration)
- func WriteDecisionsDocument(path string, doc *DecisionsDocument) error
- func WriteError(stderr io.Writer, msg string)
- func WriteNotice(stderr io.Writer, msg string)
- func WriteSaveDocument(path string, doc *SaveDocument) error
- func WriteWarning(stderr io.Writer, msg string)
- type AgentResolveFixture
- type AgentTreeNode
- type CaptureOpts
- type CommandDecision
- type CurrentSpaceIndexFunc
- type DecisionsDocument
- type FocusCandidate
- type FocusFake
- type ForegroundCommand
- type ForkPlan
- type FormatFlags
- type MultiAppPreflight
- type MultiAppPreflightFn
- type OutputFormat
- type PhasedFixtureOpts
- type RenderOptions
- type RestoreAppTarget
- type SaveDocument
- type SaveFilter
- type SaveSummary
- type SaveTab
- type SaveWindow
- type SavedCommand
- type SessionAgent
- type SessionListRow
- type Snapshot
- func CaptureSnapshot() (*Snapshot, []string, error)
- func CaptureSnapshotAcrossApps(opts CaptureOpts) (*Snapshot, []string, error)
- func CaptureSnapshotAcrossAppsStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
- func CaptureSnapshotAcrossAppsStrict(opts CaptureOpts) (*Snapshot, []string, error)
- func CaptureSnapshotForSave(opts CaptureOpts) (*Snapshot, []string, error)
- func CaptureSnapshotForSaveStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
- func CaptureSnapshotStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
- func CaptureSnapshotWith(opts CaptureOpts) (*Snapshot, []string, error)
- type SnapshotCollector
- func (c *SnapshotCollector) Capture() (*Snapshot, []string, error)
- func (c *SnapshotCollector) CaptureWith(opts CaptureOpts) (*Snapshot, []string, error)
- func (c *SnapshotCollector) ListTabsAndSessions(windowIndex int) (tabs []SnapshotTab, warnings []string, err error)
- func (c *SnapshotCollector) ListWindows() (windows []SnapshotWindow, warnings []string, err error)
- type SnapshotProc
- type SnapshotSession
- type SnapshotSummary
- type SnapshotTab
- type SnapshotWindow
- type SpaceBackend
- type SpaceIndexResolver
- type TestRun
Constants ¶
const ( CanonicalITermAppSystem = "/Applications/iTerm.app" CanonicalITermAppHome = "~/Applications/iTerm.app" )
Canonical iTerm2 install paths recorded in SaveWindow.app (D9). Home form is always ~/… never expanded /Users/….
Variables ¶
This section is empty.
Functions ¶
func BuildForkFollowUpCommand ¶ added in v0.0.174
BuildForkFollowUpCommand builds the agent-run line for ForceNew FollowUpCommands. Binary defaults to "agent-run". Does not include --new-terminal (parent opens the window).
func BuildSessionsRestoreScript ¶ added in v0.0.127
func BuildSessionsRestoreScript(doc *SaveDocument) string
BuildSessionsRestoreScript returns AppleScript that creates one new iTerm2 window per saved window and one tab per saved tab, then sends:
cd <cwd> <resume_cmd>
as two separate write text lines (empty cwd skips the cd line).
Uses bare tell application "iTerm2". Prefer BuildSessionsRestoreScriptWithTell when a path target is known.
Window title setting is best-effort: each set name is wrapped in try/on error so a refused title does not abort remaining windows. Failures are returned as one line per title on stdout (empty stdout means all titles OK).
func BuildSessionsRestoreScriptWithTell ¶ added in v0.0.142
func BuildSessionsRestoreScriptWithTell(doc *SaveDocument, appTell string) string
BuildSessionsRestoreScriptWithTell is BuildSessionsRestoreScript with an optional path-tell target. appTell is an absolute .app path (or expanded home path); empty or "iTerm2" uses bare tell application "iTerm2".
func ClearRestoreAppDiskForTest ¶ added in v0.0.142
func ClearRestoreAppDiskForTest()
ClearRestoreAppDiskForTest restores live disk checks and releases the exclusive inject hold from SetRestoreAppDiskForTest.
func DefaultDecisionsPath ¶ added in v0.0.173
func DefaultDecisionsPath() string
DefaultDecisionsPath returns ~/.config/iterm2/restore-decisions.json.
func DefaultSessionsAutoPath ¶ added in v0.0.143
func DefaultSessionsAutoPath() string
DefaultSessionsAutoPath is ~/.config/iterm2/sessions-auto.json. Distinct from DefaultSessionsSavePath (manual sessions-save.json).
func DefaultSessionsSavePath ¶ added in v0.0.127
func DefaultSessionsSavePath() string
DefaultSessionsSavePath is ~/.config/iterm2/sessions-save.json.
func InstallPhasedFixtureCollectorForTest ¶ added in v0.0.127
func InstallPhasedFixtureCollectorForTest(t testing.TB, opts PhasedFixtureOpts)
InstallPhasedFixtureCollectorForTest installs an injectable SnapshotCollector.
func ProcessCwd ¶ added in v0.0.174
ProcessCwd returns the process working directory, normalized for --only-cwd.
func RenderSessionStatus ¶ added in v0.0.127
func RenderSessionStatus(w io.Writer, snap *Snapshot, s *SnapshotSession, opt RenderOptions) error
RenderSessionStatus writes a single-session status report.
func RenderSnapshot ¶ added in v0.0.127
func RenderSnapshot(w io.Writer, snap *Snapshot, opt RenderOptions) error
RenderSnapshot writes the snapshot in the requested format to w.
func RunFocusForTest ¶ added in v0.0.133
RunFocusForTest runs the iterm2 focus route against an injected boundary. args are the full arguments after "kool iterm2", mirroring the public handler rather than requiring callers to strip the focus subcommand.
func RunForTest ¶
RunForTest runs the handler in-process for doctest handler phase. workingDir is unused; callers pass absolute paths in args.
func RunForTestEnv ¶ added in v0.0.150
RunForTestEnv is RunForTest with explicit hooks (no process Setenv/Chdir).
func SetCurrentSpaceIndexForTest ¶ added in v0.0.157
func SetCurrentSpaceIndexForTest(fn CurrentSpaceIndexFunc)
SetCurrentSpaceIndexForTest installs a current-Desktop resolver. Pass nil to restore the live ListUserSpaces path. Tests should t.Cleanup restore.
func SetGOOSForTest ¶
func SetGOOSForTest(goos string)
SetGOOSForTest overrides platform detection for handler tests.
func SetInstallHTTPForTest ¶ added in v0.0.144
SetInstallHTTPForTest injects latest URL + HTTP client for install resolve/download. Returns restore; callers should defer restore (also safe under a process mutex).
func SetMultiAppPreflightForTest ¶ added in v0.0.140
func SetMultiAppPreflightForTest(fn MultiAppPreflightFn)
SetMultiAppPreflightForTest installs a preflight resolver for tests. Pass nil to restore live discovery. Prefer t.Cleanup.
func SetRestoreAppDiskForTest ¶ added in v0.0.142
func SetRestoreAppDiskForTest(homeExists, systemExists bool)
SetRestoreAppDiskForTest injects which canonical installs exist for restore target resolution (prefer-home / --same-app). Takes an exclusive hold until ClearRestoreAppDiskForTest so parallel leaves cannot clobber each other. Prefer t.Cleanup(ClearRestoreAppDiskForTest).
func SetSessionsRunRestoreASForTest ¶ added in v0.0.132
SetSessionsRunRestoreASForTest installs the restore AppleScript runner for L2/unit tests. Pass nil to restore the production default. Prefer t.Cleanup to restore.
func SetSnapshotCollectorForTest ¶ added in v0.0.127
func SetSnapshotCollectorForTest(c *SnapshotCollector)
SetSnapshotCollectorForTest overrides the collector used by CaptureSnapshot.
func SetSpaceBackendForTest ¶ added in v0.0.132
func SetSpaceBackendForTest(b SpaceBackend)
SetSpaceBackendForTest installs a Space Backend for restore placement. Pass nil to restore live path. Tests should t.Cleanup restore.
func SetSpaceIndexForWindowForTest ¶ added in v0.0.132
func SetSpaceIndexForWindowForTest(fn SpaceIndexResolver)
SetSpaceIndexForWindowForTest installs a Space index resolver. Pass nil to restore. Tests should t.Cleanup restore.
func SetSpaceSwitchSettleForTest ¶ added in v0.0.157
SetSpaceSwitchSettleForTest overrides the delay between Switch retries. Pass a negative duration to restore the default. Tests should t.Cleanup restore.
func WriteDecisionsDocument ¶ added in v0.0.173
func WriteDecisionsDocument(path string, doc *DecisionsDocument) error
WriteDecisionsDocument writes the store atomically with 0600 — argv can contain credentials, so the file must never be world-readable.
func WriteError ¶ added in v0.0.127
WriteError prints a red Error line when appropriate.
func WriteNotice ¶ added in v0.0.173
WriteNotice prints a gray informational notice line to stderr.
func WriteSaveDocument ¶ added in v0.0.127
func WriteSaveDocument(path string, doc *SaveDocument) error
WriteSaveDocument writes the checkpoint atomically (temp + rename).
func WriteWarning ¶ added in v0.0.127
WriteWarning prints a yellow warning line to stderr when color is appropriate.
Types ¶
type AgentResolveFixture ¶ added in v0.0.127
type AgentResolveFixture struct {
Kind string // grok | codex | none
SessionID string
Title string // optional GrokTitle
Tree []AgentTreeNode
}
AgentResolveFixture is an injectable procresolve result keyed by tty (tests).
type AgentTreeNode ¶ added in v0.0.127
type AgentTreeNode struct {
PID int `json:"pid"`
PPID int `json:"ppid"`
Role string `json:"role,omitempty"` // input | agent-run | … | grok | codex | other
Cmd string `json:"cmd"`
}
AgentTreeNode is one process in the agent process tree (JSON + FormatTree).
type CaptureOpts ¶ added in v0.0.127
type CaptureOpts struct {
// NoEnrich skips procresolve agent attach (CLI --no-enrich).
NoEnrich bool
// SpaceAllow, when non-empty, enables space-first filtering in the lib.
SpaceAllow []int
// SpaceSkipped, when non-nil, receives skipped window-header count.
SpaceSkipped *int
}
CaptureOpts controls optional phases of snapshot capture.
type CommandDecision ¶ added in v0.0.173
type CommandDecision struct {
Key string `json:"key"`
Cwd string `json:"cwd"`
Argv []string `json:"argv"`
Decision string `json:"decision"` // allow | deny
DecidedAt string `json:"decided_at"`
}
CommandDecision is one remembered allow/deny for an exact command (cwd + argv).
type CurrentSpaceIndexFunc ¶ added in v0.0.157
CurrentSpaceIndexFunc returns the frontmost 0-based user Desktop index (same dense numbering as save / SpaceIndexForWindow).
type DecisionsDocument ¶ added in v0.0.173
type DecisionsDocument struct {
Version int `json:"version"`
Decisions []CommandDecision `json:"decisions"`
}
DecisionsDocument is the persisted restore-decision store. It lives outside checkpoints because checkpoints are overwritten on every save.
func ReadDecisionsDocument ¶ added in v0.0.173
func ReadDecisionsDocument(path string) (*DecisionsDocument, []string)
ReadDecisionsDocument loads the store. Missing or corrupt files yield an empty store plus warnings; restore never blocks on the store being absent.
type FocusCandidate ¶ added in v0.0.133
type FocusCandidate struct {
WindowID string
WindowTitle string
TabIndex int
SessionID string
Path string
KoolTargetDir string
}
FocusCandidate identifies one candidate session. Its order is presented to users as the stable zero-based --index order.
type FocusFake ¶ added in v0.0.133
type FocusFake struct {
Candidates []FocusCandidate
Focused []string
DiscoverCalls int
}
FocusFake is the deterministic injected iTerm boundary used by L2 callers.
func (*FocusFake) Discover ¶ added in v0.0.133
func (f *FocusFake) Discover(_ string) ([]FocusCandidate, error)
func (*FocusFake) Focus ¶ added in v0.0.133
func (f *FocusFake) Focus(candidate FocusCandidate) error
type ForegroundCommand ¶ added in v0.0.173
type ForegroundCommand struct {
PID int `json:"pid"`
Cwd string `json:"cwd,omitempty"`
Argv []string `json:"argv,omitempty"`
Observed string `json:"observed,omitempty"`
Reason string `json:"reason,omitempty"`
Complex bool `json:"complex,omitempty"`
}
ForegroundCommand is command evidence, not an instruction to replay. Observed is display-only ps text. Only Argv contains exact argument boundaries. Complex or Reason nonempty requires review; unavailable argv/cwd must never be guessed.
type ForkPlan ¶ added in v0.0.174
type ForkPlan struct {
SourceItermID string
Cwd string
GrokSessionID string
FollowUp string
AgentRunBinary string
}
ForkPlan is the resolved action for session fork (dry-run and live).
func BuildForkPlan ¶ added in v0.0.174
func BuildForkPlan(s *SnapshotSession, agentRunBinary string) (*ForkPlan, error)
BuildForkPlan validates a snapshot session for fork and builds the plan. Returns an error message suitable for WriteError (without "Error: " prefix).
type FormatFlags ¶ added in v0.0.127
FormatFlags are mutually exclusive explicit format options.
type MultiAppPreflight ¶ added in v0.0.140
type MultiAppPreflight struct {
// AsApp is the canonical app that bare `tell application "iTerm2"` targets.
AsApp string
// RunningApps is the set of canonical installs with a live process
// (home and/or system). Order is not significant.
RunningApps []string
}
MultiAppPreflight is the resolved bare-AS app and running install list (save-only).
type MultiAppPreflightFn ¶ added in v0.0.140
type MultiAppPreflightFn func() (MultiAppPreflight, error)
MultiAppPreflightFn resolves preflight for multi-app save.
type OutputFormat ¶ added in v0.0.127
type OutputFormat string
OutputFormat is how a snapshot is rendered.
const ( FormatCLI OutputFormat = "cli" FormatJSON OutputFormat = "json" FormatMarkdown OutputFormat = "markdown" FormatHTML OutputFormat = "html" )
func ResolveFormat ¶ added in v0.0.127
func ResolveFormat(flags FormatFlags, outputPath string) (OutputFormat, error)
ResolveFormat picks the output format from explicit flags and optional -o path. Explicit format flags win over file suffix. Multiple format flags → error. Unknown suffix with no flag → FormatCLI (plain text when writing to a file).
type PhasedFixtureOpts ¶ added in v0.0.127
type PhasedFixtureOpts struct {
Windows []SnapshotWindow
ITermRunning bool
OnListWindows func()
OnListTabs func(windowIndex int)
IdleTTYs []string
BusyTTYs []string
BusyLeafByTTY map[string]string
CwdByTTY map[string]string
Now time.Time
Hostname string
AgentResolveByTTY map[string]AgentResolveFixture
}
PhasedFixtureOpts configures InstallPhasedFixtureCollectorForTest.
type RenderOptions ¶ added in v0.0.127
type RenderOptions struct {
Format OutputFormat
NoColor bool
// NoTree omits FormatTree process-tree lines while keeping agent session id.
NoTree bool
// ForceColor forces ANSI even when stdout is not a TTY (tests).
ForceColor bool
// ColorWriter is checked for TTY (defaults to os.Stdout).
ColorWriter *os.File
}
RenderOptions control snapshot rendering.
type RestoreAppTarget ¶ added in v0.0.142
type RestoreAppTarget struct {
// Canonical is ~/Applications/iTerm.app or /Applications/iTerm.app, or empty when Bare.
Canonical string
// Bare means fall back to tell application "iTerm2" (no path).
Bare bool
// Warning is optional user message without the "warning:" prefix.
Warning string
}
RestoreAppTarget is a resolved create/tell target for restore.
func (RestoreAppTarget) Display ¶ added in v0.0.142
func (t RestoreAppTarget) Display() string
Display returns the plan-text form: canonical path or bare "iTerm2".
func (RestoreAppTarget) TellPath ¶ added in v0.0.142
func (t RestoreAppTarget) TellPath() string
TellPath returns the absolute .app path for AppleScript path-tell, or "" for bare.
type SaveDocument ¶ added in v0.0.127
type SaveDocument struct {
Version int `json:"version"`
SavedAt string `json:"saved_at"`
RestoredAt *string `json:"restored_at"` // null until restore succeeds
Host string `json:"host"`
Source string `json:"source"`
Filter *SaveFilter `json:"filter,omitempty"` // present when save used --spaces
Summary SaveSummary `json:"summary"`
Windows []SaveWindow `json:"windows"`
}
SaveDocument is the checkpoint written by sessions save / read by restore.
func BuildSaveDocument ¶ added in v0.0.127
BuildSaveDocument filters a live snapshot to critical grok/codex/mark tabs. Skips panes with empty cwd (warning). Prefers agent over mark on the same pane.
func ReadSaveDocument ¶ added in v0.0.127
func ReadSaveDocument(path string) (*SaveDocument, error)
ReadSaveDocument loads and validates a checkpoint file.
func (*SaveDocument) IsConsumed ¶ added in v0.0.127
func (d *SaveDocument) IsConsumed() bool
IsConsumed returns true when restored_at is set to a non-empty string.
type SaveFilter ¶ added in v0.0.140
type SaveFilter struct {
// Spaces is the sorted, deduped 0-based allowlist from --spaces.
Spaces []int `json:"spaces,omitempty"`
}
SaveFilter records save-time constraints applied when building the checkpoint. Restore ignores this object for placement; it is audit/metadata only.
type SaveSummary ¶ added in v0.0.127
type SaveSummary struct {
Windows int `json:"windows"`
Tabs int `json:"tabs"`
Sessions int `json:"sessions"`
ByKind map[string]int `json:"by_kind"`
}
SaveSummary counts critical tabs in the checkpoint.
type SaveTab ¶ added in v0.0.127
type SaveTab struct {
SourceTabIndex int `json:"source_tab_index,omitempty"`
SourcePaneIndex int `json:"source_pane_index,omitempty"`
Name string `json:"name,omitempty"`
Cwd string `json:"cwd"`
Kind string `json:"kind"` // grok | codex | mark | command
Command *SavedCommand `json:"command,omitempty"`
SessionID string `json:"session_id,omitempty"`
Message string `json:"message,omitempty"` // mark only
Title string `json:"title,omitempty"`
ResumeCmd string `json:"resume_cmd"`
ItermSessionID string `json:"iterm_session_id,omitempty"`
SourceCmdLine string `json:"source_command_line,omitempty"`
// ResolvedAllow / ResolvedDeny are in-memory restore-time decisions (from
// the decision store or the confirmation prompt). Never serialized.
ResolvedAllow bool `json:"-"`
ResolvedDeny bool `json:"-"`
}
SaveTab is one critical pane to restore as a tab (cd + resume_cmd).
type SaveWindow ¶ added in v0.0.127
type SaveWindow struct {
SourceIndex int `json:"source_index"`
Name string `json:"name,omitempty"`
App string `json:"app,omitempty"` // canonical install; restore prefer-home or --same-app
Space int `json:"space"` // 0-based Desktop; always emitted when not ignore
ItermWindowID int64 `json:"iterm_window_id,omitempty"` // info only at save; restore never uses it
Tabs []SaveTab `json:"tabs"`
// contains filtered or unexported fields
}
SaveWindow is one original iTerm window that had critical tabs.
func (SaveWindow) MarshalJSON ¶ added in v0.0.132
func (w SaveWindow) MarshalJSON() ([]byte, error)
MarshalJSON always emits "space" (including 0) unless noSpaceRecord. App is omitempty (canonical strings only when known).
type SavedCommand ¶ added in v0.0.173
type SavedCommand struct {
Argv []string `json:"argv,omitempty"`
Source string `json:"source"`
Category string `json:"category,omitempty"`
RestorePolicy string `json:"restore_policy"`
Reason string `json:"reason,omitempty"`
}
SavedCommand describes evidence, not arbitrary shell text to execute. ResumeCmd is display-only for command entries; restore regenerates it from verified argv.
type SessionAgent ¶ added in v0.0.127
type SessionAgent struct {
Kind string `json:"kind"`
SessionID string `json:"session_id"`
Title string `json:"title,omitempty"`
Tree []AgentTreeNode `json:"tree,omitempty"`
}
SessionAgent is the procresolve result attached to a busy SnapshotSession.
type SessionListRow ¶ added in v0.0.174
type SessionListRow struct {
ItermID string `json:"iterm_id"`
Status string `json:"status"` // idle | busy | unknown
Name string `json:"name,omitempty"`
Cwd string `json:"cwd,omitempty"`
Kind string `json:"kind,omitempty"` // grok | codex | …
AgentSession string `json:"agent_session,omitempty"`
Title string `json:"title,omitempty"`
WindowIndex int `json:"window_index,omitempty"`
TabIndex int `json:"tab_index,omitempty"`
PaneIndex int `json:"pane_index,omitempty"`
}
SessionListRow is one flat row for session list output.
func FilterSessionList ¶ added in v0.0.174
func FilterSessionList(rows []SessionListRow, grokOnly, onlyCwd bool, onlyCwdPath string) []SessionListRow
FilterSessionList applies --grok and/or --only-cwd filters. onlyCwdPath should be the caller's realpath cwd when onlyCwd is true; empty onlyCwdPath with onlyCwd true yields no matches (safe).
func FlattenSessions ¶ added in v0.0.174
func FlattenSessions(snap *Snapshot) []SessionListRow
FlattenSessions builds list rows from a full snapshot (window order preserved).
type Snapshot ¶ added in v0.0.127
type Snapshot struct {
CapturedAt string `json:"captured_at"`
Host string `json:"host"`
Source string `json:"source"`
Summary SnapshotSummary `json:"summary"`
Windows []SnapshotWindow `json:"windows"`
}
Snapshot is a full inventory of iTerm2 windows, tabs, and sessions (panes).
func CaptureSnapshot ¶ added in v0.0.127
CaptureSnapshot builds a full live snapshot of iTerm2 sessions (multi-app).
func CaptureSnapshotAcrossApps ¶ added in v0.0.156
func CaptureSnapshotAcrossApps(opts CaptureOpts) (*Snapshot, []string, error)
CaptureSnapshotAcrossApps captures all running iTerm application surfaces. Fixture collectors already carry all windows in one snapshot and use one pass.
func CaptureSnapshotAcrossAppsStream ¶ added in v0.0.156
func CaptureSnapshotAcrossAppsStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
CaptureSnapshotAcrossAppsStream is CaptureSnapshotAcrossApps with an optional callback after each deep-captured window is ready.
func CaptureSnapshotAcrossAppsStrict ¶ added in v0.0.156
func CaptureSnapshotAcrossAppsStrict(opts CaptureOpts) (*Snapshot, []string, error)
CaptureSnapshotAcrossAppsStrict captures every running iTerm surface and fails if any surface cannot be inspected.
func CaptureSnapshotForSave ¶ added in v0.0.140
func CaptureSnapshotForSave(opts CaptureOpts) (*Snapshot, []string, error)
CaptureSnapshotForSave captures all multi-app sources when live (not fixture). opts.SpaceAllow enables space-first deep-capture filtering for save.
func CaptureSnapshotForSaveStream ¶ added in v0.0.140
func CaptureSnapshotForSaveStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
CaptureSnapshotForSaveStream preserves the save-specific streaming API.
func CaptureSnapshotStream ¶ added in v0.0.155
func CaptureSnapshotStream(opts CaptureOpts, onWindowReady func(win SnapshotWindow) error) (*Snapshot, []string, error)
CaptureSnapshotStream is the shared streaming multi-app capture entrypoint (sessions snapshot, status, save, auto-backup). Same as AcrossAppsStream.
func CaptureSnapshotWith ¶ added in v0.0.127
func CaptureSnapshotWith(opts CaptureOpts) (*Snapshot, []string, error)
CaptureSnapshotWith builds a snapshot with capture options (multi-app stream).
type SnapshotCollector ¶ added in v0.0.127
type SnapshotCollector struct {
// OnListWindows is an optional test hook invoked at the start of ListWindows.
OnListWindows func()
// OnListTabs is an optional test hook invoked at the start of ListTabsAndSessions.
OnListTabs func(windowIndex int)
// ResolveFromPID optionally overrides live procresolve (production default).
ResolveFromPID func(pid int) (*procresolve.Result, error)
// AppTell is the AppleScript application target (forwarded to lib).
AppTell string
// AppTag is stamped on windows when App is empty (forwarded to lib).
AppTag string
// RunAppleScript / ListProcs / ListTTYProcs / ListCwds / ITermRunning are
// injectable for live_scan and tests; synced onto lib before capture.
RunAppleScript func(script string) (string, error)
ListProcs func(ttyShort string) ([]snapshot.ProcRow, error)
ListTTYProcs func(ttyShorts []string) ([]liveTTYProc, error)
ListCwds func(pids []int) (map[int]string, error)
ITermRunning func() bool
Now func() time.Time
Hostname func() (string, error)
// contains filtered or unexported fields
}
SnapshotCollector is a thin adapter over snapshot.Collector plus agent-pro itermsnapshot attach. Hierarchy + process enrich + SpaceAllow live in the lib; Agent attach and kool Snapshot (with Agent) are composed here.
func ActiveSnapshotCollectorForTest ¶ added in v0.0.127
func ActiveSnapshotCollectorForTest() *SnapshotCollector
ActiveSnapshotCollectorForTest returns the collector CaptureSnapshot will use.
func (*SnapshotCollector) Capture ¶ added in v0.0.127
func (c *SnapshotCollector) Capture() (*Snapshot, []string, error)
Capture runs phased hierarchy collection + process enrichment + agent attach.
func (*SnapshotCollector) CaptureWith ¶ added in v0.0.127
func (c *SnapshotCollector) CaptureWith(opts CaptureOpts) (*Snapshot, []string, error)
CaptureWith runs Capture with options (e.g. skip agent enrich, SpaceAllow).
func (*SnapshotCollector) ListTabsAndSessions ¶ added in v0.0.127
func (c *SnapshotCollector) ListTabsAndSessions(windowIndex int) (tabs []SnapshotTab, warnings []string, err error)
ListTabsAndSessions returns tabs and sessions for one window (by 1-based index).
func (*SnapshotCollector) ListWindows ¶ added in v0.0.127
func (c *SnapshotCollector) ListWindows() (windows []SnapshotWindow, warnings []string, err error)
ListWindows returns window index + name headers (tabs may be empty).
type SnapshotProc ¶ added in v0.0.127
type SnapshotProc struct {
PID int `json:"pid"`
PPID int `json:"ppid"`
Stat string `json:"stat"`
Etime string `json:"etime"`
DurationSeconds int64 `json:"duration_seconds"`
Duration string `json:"duration"`
StartTime *string `json:"start_time"`
StartTimeUnix *int64 `json:"start_time_unix"`
RSSKB int64 `json:"rss_kb"`
Command string `json:"command"`
}
SnapshotProc is one process observed on a session tty.
type SnapshotSession ¶ added in v0.0.127
type SnapshotSession struct {
Index int `json:"index"`
ID string `json:"id"`
Name string `json:"name"`
TTY string `json:"tty"`
Profile string `json:"profile"`
ItermIsProcessing bool `json:"iterm_is_processing"`
Idle *bool `json:"idle"` // nil = unknown
Cwd *string `json:"cwd"`
ShellPID *int `json:"shell_pid"`
PID *int `json:"pid"`
PPID *int `json:"ppid"`
Stat *string `json:"stat"`
Command *string `json:"command"`
CommandLine *string `json:"command_line"`
StartTime *string `json:"start_time"`
StartTimeUnix *int64 `json:"start_time_unix"`
DurationSeconds *int64 `json:"duration_seconds"`
Duration *string `json:"duration"`
Etime *string `json:"etime"`
RSSKB *int64 `json:"rss_kb"`
Processes []SnapshotProc `json:"processes"`
// Agent is set when procresolve finds a grok/codex session on a busy pane.
Agent *SessionAgent `json:"agent,omitempty"`
// Foreground contains live launcher evidence, separate from the chosen leaf.
Foreground *ForegroundCommand `json:"foreground,omitempty"`
// Layout hints (not required for id resolution).
WindowIndex int `json:"window_index,omitempty"`
TabIndex int `json:"tab_index,omitempty"`
}
SnapshotSession is one pane/session. Id is the iTerm2 session unique ID (UUID).
func FindSessionsByRef ¶ added in v0.0.127
func FindSessionsByRef(snap *Snapshot, ref string) []*SnapshotSession
FindSessionsByRef returns sessions matching a user-supplied id token.
type SnapshotSummary ¶ added in v0.0.127
type SnapshotSummary struct {
Windows int `json:"windows"`
Tabs int `json:"tabs"`
Sessions int `json:"sessions"`
Idle int `json:"idle"`
Busy int `json:"busy"`
Unknown int `json:"unknown"`
}
SnapshotSummary counts windows/tabs/sessions and idle/busy.
type SnapshotTab ¶ added in v0.0.127
type SnapshotTab struct {
Index int `json:"index"`
Name string `json:"name"`
Sessions []SnapshotSession `json:"sessions"`
}
SnapshotTab is one tab; sessions are panes within the tab.
type SnapshotWindow ¶ added in v0.0.127
type SnapshotWindow struct {
Index int `json:"index"`
Name string `json:"name"`
// WindowID is the iTerm/AppleScript window id (CG window number when available).
// Used to resolve macOS Space on sessions save; zero means unknown.
WindowID uint64 `json:"window_id,omitempty"`
// FixedSpace, when non-nil, is the resolved 0-based Space for tests/fixtures.
// Prefer this over SpaceIndexForWindow so parallel tests need no global hook.
FixedSpace *int `json:"-"`
// App is the canonical iTerm install that owns this window (fixture tag or
// multi-app save source). Only "~/Applications/iTerm.app" or
// "/Applications/iTerm.app". Not emitted on sessions snapshot JSON.
App string `json:"-"`
Tabs []SnapshotTab `json:"tabs"`
}
SnapshotWindow is one iTerm2 window.
type SpaceBackend ¶ added in v0.0.132
SpaceBackend is Create / Switch / Highest for restore placement. Matches space.Backend (Create/Switch/List/Highest); tests typically inject space.MockBackend.
type SpaceIndexResolver ¶ added in v0.0.132
SpaceIndexResolver maps an iTerm/CG window id to a 0-based Desktop index.
type TestRun ¶ added in v0.0.150
type TestRun struct {
TabSetDir string
GOOS string
Installed func() bool
Osascript func(script string) error
// Contents overrides lib.Contents (tests).
Contents func(sessionID string, cfg *lib.ContentsConfig) (lib.ContentsResult, error)
// SendText overrides lib.SendText (tests).
SendText func(sessionID, text string, opts lib.SendTextOptions, cfg *lib.SendTextConfig) error
// ListSessions overrides lib.ListSessions for send resolve (tests).
ListSessions func() ([]lib.SessionRef, error)
// CurrentStatus overrides resolve probes for window/tab status (tests).
CurrentStatus *lib.CurrentStatusConfig
}
TestRun injects handler-test overrides. Do not mutate process env or cwd.
Source Files
¶
- applescript.go
- contents.go
- focus.go
- install.go
- iterm2.go
- session_fork.go
- session_list.go
- sessions.go
- sessions_auto_backup.go
- sessions_checkpoint.go
- sessions_command.go
- sessions_command_capture.go
- sessions_command_capture_other.go
- sessions_decisions.go
- sessions_decisions_cli.go
- sessions_live_scan.go
- sessions_multi_app.go
- sessions_restore.go
- sessions_space.go
- snapshot_agent.go
- snapshot_collect.go
- snapshot_format.go
- snapshot_helpers.go
- snapshot_model.go
- snapshot_proc_compat.go
- snapshot_render.go
- tabset.go
- window_tab_status.go