dev

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dev contains the process-spawning, health-checking, and file-watching helpers used by `txco dev`. Lives outside chassis/cli proper so the dev subcommand's machinery doesn't bleed into the simpler subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitHealthy

func WaitHealthy(ctx context.Context, url string, timeout, interval time.Duration) error

WaitHealthy polls url with HTTP GET until it returns a 2xx response, or until timeout elapses, or until ctx is canceled. interval governs the gap between attempts.

Returns nil when the URL returns 2xx; an error otherwise. Uses a short per-request timeout so a slow-starting service doesn't block the polling loop on a single attempt.

func WatchColocatedComputes

func WatchColocatedComputes(ctx context.Context, dir string, debounce time.Duration, onChange func()) error

WatchColocatedComputes watches the OPS/ tree for colocated compute source changes (.js/.ts) and fires onChange (debounced). Only compute source — not .txcl/.json, which the OPS draft watcher handles — so a compute edit triggers a rebuild+activate without double-firing on resonator/mock edits.

func WatchOps

func WatchOps(ctx context.Context, dir string, debounce time.Duration, onChange func()) error

WatchOps watches dir recursively for changes to *.txcl and *.json files. Calls onChange with a 500ms-debounced cadence — bursty editor saves coalesce into a single re-apply rather than firing N times.

Blocks until ctx is canceled. Returns the watcher's exit error (or nil on clean shutdown).

Types

type Process

type Process struct {
	Name string
	Cmd  *exec.Cmd
	// contains filtered or unexported fields
}

Process is a managed child started by `txco dev`. It captures the child's stdout/stderr to a tagged writer (so output is interleaved readably) and runs it in its own process group so a single SIGTERM from the parent kills any grand-children too.

func Spawn

func Spawn(ctx context.Context, cfg SpawnConfig) (*Process, error)

Spawn starts a child process running `sh -c <cmd>` with the given working dir, in its own process group. The child's combined output is line-prefixed with cfg.Name and written to cfg.Out.

Returns a Process whose Wait() blocks until the child exits, and whose Stop(grace) sends SIGTERM to the whole group, then SIGKILL after grace.

func (*Process) Done

func (p *Process) Done() <-chan struct{}

Done returns a channel closed when the child exits.

func (*Process) Err

func (p *Process) Err() error

Err returns the child's exit error (if any). Only meaningful after Done has fired.

func (*Process) Signal added in v0.2.4

func (p *Process) Signal(sig syscall.Signal) error

Signal sends sig to the child's process group (negative pid), mirroring Stop's group-targeting so a forwarded signal reaches the real process even when a shell leader sits in front of it. Used to forward operator signals (e.g. SIGUSR1/SIGUSR2 drain) from the dev supervisor to a specific child. Returns the underlying kill error (ESRCH if the group is already gone).

func (*Process) Stop

func (p *Process) Stop(grace time.Duration)

Stop sends SIGTERM to the process group, then SIGKILL after grace if the child hasn't exited. Safe to call multiple times.

Always signals the *group* (negative pid), even when the immediate child has already been reaped. The leader (sh) can die first while grandchildren (e.g. pnpm → vite) keep running in the same pgid — this happens when exec.CommandContext's ctx is cancelled, since os/exec SIGKILLs only the leader. Targeting -pid kills the whole subtree.

type SpawnConfig

type SpawnConfig struct {
	Name string    // tag prefixed to output lines (e.g., "[classify]")
	Dir  string    // working dir; "" = current
	Cmd  string    // shell command, e.g. "npm run dev"
	Out  io.Writer // where to write tagged stdout/stderr
	Env  []string  // extra env vars (appended to os.Environ())
}

SpawnConfig drives Spawn.

Jump to

Keyboard shortcuts

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