Expand description
forge-agent - drives one forge_sdk::Client and exposes a
channel-based Agent / AgentHandle surface to UI consumers.
Public API: Agent::spawn returns an AgentHandle holding
Sender<Command>, a take_events() for the bridge’s AgentEvent
stream, and direct-accessor passthroughs (config_dir,
settings_documents, oauth_*).
ForgeSdkBridge is a pub(crate) implementation detail - Agent’s
dispatcher task is the only caller.
§Module layout
agent-Agent::spawn+AgentHandle(the public API).client-AgentEventenum + supporting types.cloud- network-side state: oauth + cli usage fetchers.userdata- disk-side state: settings, sessions catalog, memory, plugins.commands/session_lifecycle- bridge helpers consumed by the worker and the workspace.forge_sdk_worker(crate-private) /replay/tooling/user_interaction- internal implementation modules consumed byagent’s dispatcher and translator paths.
Re-exports§
pub use agent::Agent;pub use agent::AgentError;pub use agent::AgentHandle;pub use client::AgentEvent;pub use client::SessionLaunchSettings;pub use forge_sdk_worker::set_test_sdk_binary;pub use userdata::catalog::scan::has_a_transcript_row;
Modules§
- agent
- Channel-based
Agenthandle - the public consumer surface. - client
- cloud
- Network-side state. OAuth flow, account info, usage polling - anything that talks to api.anthropic.com directly (NOT through the claude CLI subprocess).
- commands
- Mode-state helpers - supported-mode list filtering +
ModeStatebuilder. Used by the worker to assemble the Connected event payload at spawn time. - env
- Live environment - git context, cwd insights, OS-side observations the agent needs but the SDK doesn’t.
- forge_
sdk_ 🔒bridge ForgeSdkBridge- in-process driver around aforge_sdk::Client.- forge_
sdk_ 🔒worker - Session-launcher + reader-pump helpers for the bridge layer.
- http_
trust - Reqwest builder helper that extends the TLS trust store with
certs from
NODE_EXTRA_CA_CERTS(withSSL_CERT_FILEas fallback) to match nativeclaude’s TLS trust behaviour. - logging
- Tracing target constants used by the agent’s bridge code. Strings
stay consistent with the server’s
logging::targetsso the subscriber’s env-filter picks up agent-side logs. - replay 🔒
- Resume-history synthesizer: converts on-disk transcript JSONL into the
forge_primitives::Messageenvelopes the live wire stream produces, so consumers read replay and live messages identically. - session_
lifecycle - Model resolution + connect-event + initialize-result mapping.
Mirrors the relevant portions of upstream’s
agent-sdk/src/bridge/session_lifecycle.ts. - tooling
- Tool-call construction + tool-result extraction. 1:1 port of
upstream’s
agent-sdk/src/bridge/tooling.ts(714LoC). - translate
- Translation helpers used by callers that need to convert wire-shape data (forge-sdk message payloads, control responses) into typed Rust values. A view consumes these from its event-loop translator paths.
- user_
interaction AskUserQuestionsequential sequencing. Mirrors upstream’sagent-sdk/src/bridge/user_interaction.ts(323LoC) - focused on the multi-question loop + answer-payload assembly.- userdata
- User-data state on disk. Settings, sessions catalog, memory, plugins, slash commands, MCP config - anything the agent reads or writes outside live SDK sessions.
Enums§
- Permission
Mode - Which permission flow the
claudebinary should use for tool invocations. Mirrors the upstream CLI’s six-variant set.
Functions§
- session_
history - The messages a session’s transcript holds and the compactions it records. The same read the spawn performs, available for a session that is already running.
- session_
history_ main_ thread session_historyover the session’s own rows only: sub-agent sidecars are not opened or folded. The handoff brief takes this one, so it pays for neither the frames nor the parse. A page read does not: a dispatch row draws its sidecar frames (#1763).- transcript_
rows - The rows of a session’s transcript that sit strictly before
below, for a paging read that has walked below the window a conversation is kept in.