Skip to main content

ProjectBinding

Enum ProjectBinding 

Source
pub enum ProjectBinding {
    None,
    Directory(PathBuf),
    GitRepo(PathBuf),
}
Expand description

A workstream’s project binding — zero or one project, in one of three states.

Why: see the module docs — this is the single typed object that replaces task.run’s un-omittable path and session.create’s un-indexable label. What: None is projectless (chat/planning; no index, no diff target, no project-scoped memory palace). The two bound variants both carry a canonical root and both index; they differ ONLY in whether git affordances are available. Test: binding::tests::*.

Variants§

§

None

Projectless — no directory bound. Chat/planning only.

§

Directory(PathBuf)

Bound to a plain directory that is NOT a git worktree (#2728/#2747). Indexes; git affordances are hidden, never faked.

§

GitRepo(PathBuf)

Bound to a git worktree. Indexes; full git affordances.

Implementations§

Source§

impl ProjectBinding

Source

pub fn resolve(path: Option<PathBuf>) -> Result<Self, BindingError>

Classify an optional project path into one of the three binding states.

Why: the single entry point every API surface funnels through, so task.run and session.create can never again disagree about what a project is or how one is recognised. What: None ⇒ ProjectBinding::None (projectless — the supported, non-error case). Some(p) ⇒ an existing directory classified as GitRepo when is_git_worktree says so, else Directory — a BOUND, indexing state, not a fallback to projectless. A Some(p) naming a nonexistent path or a non-directory is a BindingError, never a silent downgrade to projectless: omitting a project is a deliberate choice, whereas naming one that cannot bind is a caller mistake, and collapsing the two would hide it. The root is canonicalised when the filesystem allows, so two spellings of one project (., /abs/path, a symlink) yield one binding. Test: binding::tests::resolve_none_is_projectless, binding::tests::resolve_plain_dir_binds_as_directory, binding::tests::resolve_git_repo_binds_as_git_repo, binding::tests::resolve_rejects_missing_path, binding::tests::resolve_rejects_file_path.

Source

pub fn root(&self) -> Option<&Path>

The bound project root, or None when projectless.

Why: every consumer that needs a real directory (fs tools, CLAUDE.md loading, indexing) asks here, and the Option makes “there may be no project” impossible to forget at the type level — which is exactly the bug the old required PathBuf encoded. What: Some(&Path) for both bound variants; None for projectless. Test: binding::tests::root_is_none_only_when_projectless.

Source

pub fn is_bound(&self) -> bool

Whether a project is bound at all (either bound state).

Why: the index/diff/palace decisions key off “is there a project”, NOT off “is it git” — conflating those two is precisely the proposal’s error. What: false only for ProjectBinding::None. Test: binding::tests::non_git_dir_is_bound_and_indexes.

Source

pub fn is_git(&self) -> bool

Whether git affordances (branch, PR, dirty-tree) are available.

Why: the ONLY question the git/non-git split is allowed to answer. It must never be used to decide whether to bind or index (AC-2.2/AC-2.3). What: true only for ProjectBinding::GitRepo. Test: binding::tests::non_git_dir_is_bound_and_indexes, binding::tests::resolve_git_repo_binds_as_git_repo.

Source

pub fn should_index(&self) -> bool

Whether this binding’s project should be indexed (AC-2.3).

Why: names the rule in one place so no call site re-derives it and accidentally reintroduces the git-only gate. What: identical to is_bound — both bound states index, git or not. Projectless does not. Test: binding::tests::non_git_dir_is_bound_and_indexes, binding::tests::projectless_does_not_index.

Source

pub fn state(&self) -> &'static str

The wire state discriminant for this binding.

Why: the SPA renders three distinct states (§4.2) and needs to tell them apart without inferring from the presence of a path. What: one of STATE_PROJECTLESS, STATE_DIRECTORY, STATE_GIT_REPO. Test: binding::tests::wire_shape_round_trips_each_state.

Source

pub fn label(&self) -> Option<String>

A human display label for the bound project, or None when projectless.

Why: preserves Session.project’s existing Option<String> wire field — which is now DERIVED from the binding rather than being an independent, unvalidated source of truth. That derivation is the whole reconciliation: the label still exists for humans, but it can no longer disagree with the path, because there is only one path and the label is computed from it. What: the root’s display string; None for projectless. Test: binding::tests::label_is_derived_from_root.

Source

pub fn agents_dir(&self) -> PathBuf

The agents directory this binding resolves <agent>.md from.

Why: a projectless daemon still runs a PM and still needs agent configs; with no project root there is no project-scoped .claude/agents to read, so it must fall back rather than fail. Falling back to the process CWD would silently bind to a directory the operator never chose — the exact implicit-binding bug this type exists to prevent — so it falls back to the USER-level location instead. What: bound ⇒ crate::agents::locate_agents_dir on the project root (the .claude/agents → .open-mpm/agents convention). Projectless ⇒ the same convention rooted at $HOME, i.e. ~/.claude/agents, matching Claude Code’s user-level agents location. With no resolvable home directory, degrades to a bare relative .claude/agents — which simply will not exist, surfacing as a normal “PM config error” rather than a panic. Test: binding::tests::agents_dir_uses_project_root_when_bound, binding::tests::projectless_agents_dir_is_user_level.

Source

pub fn to_json(&self) -> Value

The JSON wire representation: { "state": …, "root": … }.

Why: the SPA needs the state discriminant explicitly rather than inferring projectless from a null path (AC-2.1) — an absent root and a projectless state are the same fact today, but only the discriminant stays honest if a future state carries no path for a different reason. What: root is null for projectless, the display path otherwise. Test: binding::tests::wire_shape_round_trips_each_state.

Trait Implementations§

Source§

impl Clone for ProjectBinding

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProjectBinding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProjectBinding

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ProjectBinding

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Reconstruct a binding from its wire shape.

Why: Session derives Deserialize, so its binding field needs one. What: reconstructs from the EXPLICIT state discriminant and does NOT re-probe the filesystem — deserializing a value must not depend on whether a path still exists or is still a git repo on THIS machine, which would make a round-trip lossy (a GitRepo read back on a host without the repo would silently become a Directory). A bound state missing its root, or an unknown discriminant, is a hard error rather than a silent downgrade to projectless. Test: binding::tests::deserialize_round_trips_without_touching_disk, binding::tests::deserialize_rejects_bound_state_without_root.

Source§

impl Eq for ProjectBinding

Source§

impl PartialEq for ProjectBinding

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ProjectBinding

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialise via ProjectBinding::to_json so the wire shape is defined in exactly one place.

Why: Session derives Serialize; without this the enum would emit serde’s default externally-tagged shape and drift from to_json. What: delegates to ProjectBinding::to_json. Test: binding::tests::serialize_matches_to_json.

Source§

impl StructuralPartialEq for ProjectBinding

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more