Skip to main content

Module process_registration

Module process_registration 

Source
Expand description

Helper for registering an agent process in zag’s ProcessStore and producing the env vars (ZAG_PROCESS_ID, ZAG_SESSION_ID, etc.) that zag ps kill self / zig self terminate use to resolve the running agent from inside the agent’s own subshell.

Two callers need this exact sequence:

  • zag-cli/src/commands/agent_action.rs — the zag agent CLI path.
  • zag-agent::AgentBuilder — used by library consumers (e.g. zig run interactive steps in the zig workflow tool) that drive an agent programmatically without going through the zag CLI.

Before this module existed, only agent_action.rs did the registration (and via unsafe std::env::set_var, polluting the parent process’s env). Library callers got no registration and no env vars, so zig self terminate failed with Cannot resolve "self": ZAG_PROCESS_ID is not set from inside any zig-run interactive step.

This module is now the single source of truth. Callers either:

  • Call register directly and wire the returned ProcessRegistration to their Agent / AgentBuilder via set_env_vars + set_on_spawn_hook (or [AgentBuilder::env] / [AgentBuilder::on_spawn] / the convenience [AgentBuilder::register_process]), then call ProcessRegistration::update_status when the agent exits.
  • Or pass a RegisterOptionsOwned to [AgentBuilder::register_process] and let the builder handle registration + finalisation automatically.

Structs§

ProcessRegistration
A live process registration. Holds the generated proc_id and the env vars to inject into the agent subprocess. Callers wire env_vars() and on_spawn_hook() to the agent and call update_status() once the agent exits.
RegisterOptions
Borrowed options for register. Field semantics mirror ProcessEntry one-for-one.
RegisterOptionsOwned
Owned variant of RegisterOptions for storage on a builder before the terminal method runs.

Functions§

register
Register a new process entry in zag’s ProcessStore and return a ProcessRegistration holding the proc_id and the env vars to inject into the agent subprocess.