procresolve

package
v0.0.125 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatLiveError

func FormatLiveError(pid int, err error) string

FormatLiveError is a small helper for CLI messages (kept for symmetry).

func FormatTree

func FormatTree(nodes []ProcNode, opts TreeFormatOptions) string

FormatTree rebuilds a parent→child forest from node PPIDs and prints each node as connectors + "PID Cmd". Pure: does not call Resolve or Lsof.

Connector rules (matches locked P2 templates for sole-child chains):

  • Non-last siblings use branch (├── / +--) and pipe continuation (│ / |).
  • Last siblings that still have children also use branch + pipe (so a single intermediate child is drawn with ├──/│, not └──/spaces).
  • Last siblings that are leaves use last (└── / `--) and blank continuation.

func IsGrokRunner added in v0.0.94

func IsGrokRunner(cmd string) bool

IsGrokRunner reports whether cmd is a grok session runner (basename grok, excluding pure `grok update` utilities).

func LiveLsof

func LiveLsof(pid int) []string

LiveLsof returns open-file paths for pid via shared go-pkgs/proc OpenFiles. On failure returns nil (soft miss for that candidate).

func ParseSessionFromPath added in v0.0.94

func ParseSessionFromPath(path string) (kind, sessionID string, ok bool)

ParseSessionFromPath extracts a hard session hit from an open-file path. Returns kind ("grok"|"codex"), sessionID (lowercased), ok.

Types

type Options

type Options struct {
	GrokHome  string
	CodexHome string
	MaxDepth  int
	ListProcs func() []Proc
	Lsof      func(pid int) []string

	// EnrichInfo, when true and Kind is grok with a SessionID, calls
	// LookupGrokInfo to fill GrokTitle / GrokModel. Opt-in; default false.
	EnrichInfo bool
	// LookupGrokInfo is optional. Production CLI may default to
	// agent/grok/sessions.Info; tests inject a pure stub.
	LookupGrokInfo func(home, sessionID string) (title, model string, err error)
}

Options configures ResolveFromPID. ListProcs and Lsof are injectable for tests; production may wire live process listing and lsof.

type Proc

type Proc struct {
	PID  int
	PPID int
	Cmd  string
}

Proc is one process row in a snapshot.

func FindAncestorGrok added in v0.0.125

func FindAncestorGrok(startPID int, opts Options) (Proc, bool)

FindAncestorGrok walks startPID then each PPID via opts.ListProcs and returns the nearest grok session runner (IsGrokRunner). Missing start PID, a missing parent, or pid 0 yields ok=false and a zero Proc.

func ListLiveProcs

func ListLiveProcs() []Proc

ListLiveProcs returns a best-effort process snapshot via shared go-pkgs/proc. On failure (ps missing or error), returns nil/empty.

type ProcNode

type ProcNode struct {
	PID  int
	PPID int
	Role string // input | agent-run | agent-run-serve | grok | codex | other
	Cmd  string
}

ProcNode is a classified process in the descendant tree of the input pid.

type Result

type Result struct {
	InputPID   int
	Kind       string // grok | codex | none
	SessionID  string
	Source     string // open-files | open-files+tree
	Confidence string // hard | "" when none
	RunnerPID  int
	RunnerCmd  string
	Tree       []ProcNode
	Warnings   []string
	// GrokTitle / GrokModel are filled only when EnrichInfo is true and
	// LookupGrokInfo succeeds for a grok hard hit.
	GrokTitle string
	GrokModel string
}

Result is the outcome of ResolveFromPID.

func ResolveFromAncestors added in v0.0.125

func ResolveFromAncestors(startPID int, opts Options) (*Result, error)

ResolveFromAncestors finds the nearest grok ancestor of startPID and delegates to ResolveFromPID so the session id comes from Lsof paths. A missing start PID is an error. No grok ancestor is a soft miss (Kind=none); descendant groks are not considered.

func ResolveFromPID

func ResolveFromPID(pid int, opts Options) (*Result, error)

ResolveFromPID builds the descendant tree of pid, classifies nodes, and resolves a hard session id from open files on grok/codex runner candidates. Session ids come from open-file paths only (not cmdline flags).

type TreeFormatOptions

type TreeFormatOptions struct {
	// ASCII, when true, uses +-- / `-- / | instead of box-drawing.
	ASCII bool
}

TreeFormatOptions controls FormatTree connector style.

Jump to

Keyboard shortcuts

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