ops

package
v0.9.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ops tracks long-running MCP tool invocations so a local portal can list and cancel them. It is intentionally process-local: each LabLinkServer process keeps its own registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redact

func Redact(args map[string]string) map[string]string

Redact returns a shallow copy of args with values replaced by "***" for keys whose name suggests they hold a secret. Always safe with nil input.

Types

type Event

type Event struct {
	Kind string     `json:"kind"` // "started" | "progress" | "finished"
	Op   *Operation `json:"op"`
}

Event is a change notification published over the bus.

type Handle

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

Handle is returned by Begin and used by the caller to mark completion.

func (*Handle) Done

func (h *Handle) Done(err error)

Done records terminal status. err==nil → succeeded; err set and the op was portal-cancelled → cancelled; otherwise → failed. The wrapped context is also cancelled to release any descendant work.

func (*Handle) ID

func (h *Handle) ID() string

ID returns the operation id.

func (*Handle) Progress added in v0.4.1

func (h *Handle) Progress(bytesDone, bytesTotal int64)

Progress publishes a liveness/progress update for the operation. It is a no-op on a nil or noop handle, and on a finished operation. bytesTotal may be 0 when the total size is unknown. Intended for long-running streaming tools (push_file, pull_file, …) so MCP clients that honor "tool is alive" signals don't kill the call mid-transfer.

type Operation

type Operation struct {
	ID         string            `json:"id"`
	Tool       string            `json:"tool"`
	Node       string            `json:"node,omitempty"`
	Summary    string            `json:"summary,omitempty"`
	Args       map[string]string `json:"args,omitempty"`
	StartedAt  time.Time         `json:"started_at"`
	FinishedAt *time.Time        `json:"finished_at,omitempty"`
	Status     Status            `json:"status"`
	Error      string            `json:"error,omitempty"`

	// Progress is an optional periodic liveness signal published by
	// long-running streaming tools (push_file, pull_file, …). BytesTotal
	// may be 0 when the total is not yet known. ProgressAt is the most
	// recent update time. Updated via Handle.Progress.
	BytesDone  int64      `json:"bytes_done,omitempty"`
	BytesTotal int64      `json:"bytes_total,omitempty"`
	ProgressAt *time.Time `json:"progress_at,omitempty"`
	// contains filtered or unexported fields
}

Operation is a single in-flight or recently-completed tool invocation.

type Registry

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

Registry tracks operations and fans out change events to subscribers.

func NewRegistry

func NewRegistry(maxHistory int) *Registry

NewRegistry constructs a Registry. maxHistory is the number of completed operations retained for display; 0 means unlimited.

func (*Registry) Begin

func (r *Registry) Begin(parent context.Context, tool, node, summary string, args map[string]string) (context.Context, *Handle)

Begin records a new operation and returns a wrapped context whose cancellation can be triggered either by the caller or by the portal (Cancel by ID). Done must be called on the returned Handle when the work completes.

func (*Registry) Cancel

func (r *Registry) Cancel(id string) bool

Cancel marks the operation as cancelled-by-portal and triggers its context cancel. Returns false if the id is unknown or already finished.

func (*Registry) List

func (r *Registry) List() []*Operation

List returns a snapshot of all operations (running first, most-recent finished after).

func (*Registry) Subscribe

func (r *Registry) Subscribe() (<-chan Event, func())

Subscribe returns a channel of events. Caller must call the returned cancel when done. Buffered to avoid blocking publishers on slow consumers; events are dropped when the buffer is full.

type Status

type Status string

Status of an Operation.

const (
	StatusRunning   Status = "running"
	StatusSucceeded Status = "succeeded"
	StatusFailed    Status = "failed"
	StatusCancelled Status = "cancelled"
)

Jump to

Keyboard shortcuts

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