Skip to main content

zeph_subagent/
lib.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Subagent management: spawning, grants, transcripts, and lifecycle hooks.
5//!
6//! `zeph-subagent` provides the full lifecycle of sub-agent tasks within the Zeph agent
7//! framework. It covers:
8//!
9//! - **Definitions** ([`SubAgentDef`]) — parse YAML/TOML frontmatter from `.md` files,
10//!   validate names and permissions, and load from priority-ordered directories.
11//! - **Manager** ([`SubAgentManager`]) — spawn, cancel, collect, and resume sub-agent tasks
12//!   against a configurable concurrency limit.
13//! - **Grants** ([`PermissionGrants`]) — zero-trust TTL-bounded permission tracking for
14//!   vault secrets and runtime tool grants.
15//! - **Hooks** ([`fire_hooks`]) — run shell commands at `PreToolUse`, `PostToolUse`,
16//!   `SubagentStart`, and `SubagentStop` lifecycle events.
17//! - **Filter** ([`FilteredToolExecutor`]) — enforce per-agent [`ToolPolicy`] and denylist
18//!   on every tool call before it reaches the real executor.
19//! - **Transcripts** ([`TranscriptWriter`], [`TranscriptReader`]) — persist conversation
20//!   history to JSONL files for session resume and auditing.
21//! - **Memory** ([`ensure_memory_dir`], [`load_memory_content`]) — resolve and inject
22//!   persistent `MEMORY.md` content into the sub-agent system prompt.
23//! - **Commands** ([`AgentCommand`], [`AgentsCommand`]) — typed parsers for `/agent` and
24//!   `/agents` slash commands.
25//!
26//! # Quick start
27//!
28//! ```rust,no_run
29//! use std::sync::Arc;
30//! use zeph_subagent::{SubAgentDef, SubAgentManager};
31//!
32//! // Parse a definition from markdown frontmatter.
33//! let content = "---\nname: helper\ndescription: A helpful sub-agent\n---\nYou are a helper.\n";
34//! let def = SubAgentDef::parse(content).expect("valid definition");
35//! assert_eq!(def.name, "helper");
36//!
37//! // Create a manager with a concurrency limit of 4.
38//! let _manager = SubAgentManager::new(4);
39//! ```
40
41mod agent_loop;
42pub mod command;
43pub mod def;
44pub mod error;
45pub mod filter;
46pub mod grants;
47pub mod hooks;
48pub mod manager;
49pub mod memory;
50pub mod resolve;
51pub mod state;
52pub mod transcript;
53
54pub use command::{AgentCommand, AgentsCommand};
55pub use def::{
56    MemoryScope, ModelSpec, PermissionMode, SkillFilter, SubAgentDef, SubAgentPermissions,
57    ToolPolicy, is_valid_agent_name,
58};
59pub use error::SubAgentError;
60pub use filter::{FilteredToolExecutor, PlanModeExecutor, filter_skills};
61pub use grants::{Grant, GrantKind, PermissionGrants, SecretRequest};
62pub use hooks::{
63    HookDef, HookError, HookMatcher, HookType, SubagentHooks, fire_hooks, matching_hooks,
64};
65pub use manager::{SpawnContext, SubAgentHandle, SubAgentManager, SubAgentStatus};
66pub use memory::{ensure_memory_dir, load_memory_content};
67pub use resolve::resolve_agent_paths;
68pub use state::SubAgentState;
69pub use transcript::{TranscriptMeta, TranscriptReader, TranscriptWriter, sweep_old_transcripts};