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
impl ProjectBinding
Sourcepub fn resolve(path: Option<PathBuf>) -> Result<Self, BindingError>
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.
Sourcepub fn root(&self) -> Option<&Path>
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.
Sourcepub fn is_bound(&self) -> bool
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.
Sourcepub fn is_git(&self) -> bool
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.
Sourcepub fn should_index(&self) -> bool
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.
Sourcepub fn state(&self) -> &'static str
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.
Sourcepub fn label(&self) -> Option<String>
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.
Sourcepub fn agents_dir(&self) -> PathBuf
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.
Sourcepub fn to_json(&self) -> Value
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
impl Clone for ProjectBinding
Source§impl Debug for ProjectBinding
impl Debug for ProjectBinding
Source§impl Default for ProjectBinding
impl Default for ProjectBinding
Source§impl<'de> Deserialize<'de> for ProjectBinding
impl<'de> Deserialize<'de> for ProjectBinding
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
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.
impl Eq for ProjectBinding
Source§impl PartialEq for ProjectBinding
impl PartialEq for ProjectBinding
Source§impl Serialize for ProjectBinding
impl Serialize for ProjectBinding
Source§fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
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.
impl StructuralPartialEq for ProjectBinding
Auto Trait Implementations§
impl Freeze for ProjectBinding
impl RefUnwindSafe for ProjectBinding
impl Send for ProjectBinding
impl Sync for ProjectBinding
impl Unpin for ProjectBinding
impl UnsafeUnpin for ProjectBinding
impl UnwindSafe for ProjectBinding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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