procresolve

package
v0.0.83 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 9 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 LiveLsof

func LiveLsof(pid int) []string

LiveLsof returns open-file paths for pid via `lsof -p <pid> -Fn`. On failure returns nil (soft miss for that candidate).

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 ListLiveProcs

func ListLiveProcs() []Proc

ListLiveProcs returns a best-effort process snapshot via `ps`. On failure (ps missing or error), returns nil.

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 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