forge_workspace/target.rs
1//! Identifiers + the `SessionTarget` enum used to address sessions.
2
3// `SessionSlot` lives in forge-primitives so the same routing key
4// flows through the view → workspace → agent layers without each crate
5// growing its own near-identical newtype. Re-exported here so call
6// sites continue to import via `forge_workspace::SessionSlot`.
7pub use forge_primitives::SessionSlot;
8
9// `ProjectKey` lives in forge-primitives for the same reason
10// `SessionSlot` does: it addresses a project across the workspace and
11// a view, both of which key their own maps on it. Re-exported here so
12// call sites continue to import via `forge_workspace::ProjectKey`.
13pub use forge_primitives::ProjectKey;
14
15/// What [`crate::Workspace::get_agent_handle`] should hand back.
16#[derive(Clone, Debug)]
17pub enum SessionTarget {
18 /// The lead of the fallback project: the alphabetically-first
19 /// project overall.
20 Default,
21 /// Open the lead of the project whose `name` matches the given
22 /// string in `forge.toml`. Errors with `ProjectNotFound` if no
23 /// such name exists.
24 Named(String),
25 /// A specific session slot, resumed under the id the store holds
26 /// for it. Used by the click-to-resume flow in the Projects pane
27 /// and by `Workspace::spawn_session`.
28 Session(SessionSlot),
29 /// Spawn a FRESH session in `slot`'s project, bypassing the
30 /// lead-resume path. Used by the workers MCP so a worker is always
31 /// a brand-new session, not a resume of the project's existing
32 /// lead. The caller has already recorded the id it minted for the
33 /// slot, so the child adopts exactly that one.
34 ///
35 /// `cwd` is the tree the fresh session runs in when the spawn
36 /// pointed it somewhere other than the project's own path (a
37 /// worker's own `cwd`); `None` is the project path, exactly as
38 /// before.
39 FreshInProject { slot: SessionSlot, cwd: Option<std::path::PathBuf> },
40}