Vapora/crates/vapora-worktree/src/detect.rs
Jesús Pérez 75e5ebd9a2
Some checks failed
Documentation Lint & Validation / Markdown Linting (push) Has been cancelled
Documentation Lint & Validation / Validate mdBook Configuration (push) Has been cancelled
Documentation Lint & Validation / Content & Structure Validation (push) Has been cancelled
mdBook Build & Deploy / Build mdBook (push) Has been cancelled
Nickel Type Check / Nickel Type Checking (push) Has been cancelled
Rust CI / Security Audit (push) Has been cancelled
Rust CI / Check + Test + Lint (nightly) (push) Has been cancelled
Rust CI / Check + Test + Lint (stable) (push) Has been cancelled
Documentation Lint & Validation / Lint & Validation Summary (push) Has been cancelled
mdBook Build & Deploy / Documentation Quality Check (push) Has been cancelled
mdBook Build & Deploy / Deploy to GitHub Pages (push) Has been cancelled
mdBook Build & Deploy / Notification (push) Has been cancelled
chore: ontology sync + 4 NCL ADRs + landing page update
on+re:
  - core.ncl: 5 new Practice nodes (notification-channels,
    vapora-capabilities, agent-hot-reload-stable-identity,
    merkle-audit-trail, notification-channels) + 5 new edges;
    knowledge-graph-execution-history updated with HNSW+BM25+RRF
  - state.ncl: production-readiness blocker/catalyst updated (hot-reload
    complete, BudgetManager/LLMRouter still require restart);
    ontoref-integration catalyst updated (vapora-ontology/reflection
    crates, api-catalog.json, nickel contracts)

  ADRs (NCL):
  - adr-013: KG hybrid search — HNSW+BM25+RRF, rejected in-process scan
  - adr-014: capability packages — AgentDefinition→vapora-shared,
    DashMap shard-before-await constraint
  - adr-015: Merkle audit trail — SHA-256 hash chain, rejected HMAC
  - adr-016: agent hot-reload — stable_id=role, learning_profiles survive
    drain, BudgetManager excluded from reload scope

  landing page:
  - 2 new feature boxes: VCS-Agnostic Worktree (jj/git), Ontology Protocol
  - KG box: 20→28 tests, HNSW+BM25+RRF description
  - Agents box: 71→82 tests, hot-reload + stable_id
  - tech stack: Rust 21→23 crates, added jj, Radicle, ontoref badges
  - status badge: 620→691 tests
2026-04-07 21:06:48 +01:00

62 lines
1.7 KiB
Rust

use std::path::Path;
/// Which VCS is active in a directory, detected by filesystem inspection.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VcsDetection {
/// Both `.jj/` and `.git/` present — jj colocated mode (preferred for
/// Radicle interop).
JjColocated,
/// Only `.jj/` present.
Jj,
/// Only `.git/` present.
Git,
/// Neither found.
None,
}
/// Detect VCS by inspecting `path` for `.jj/` and `.git/` directories.
pub fn detect_vcs(path: &Path) -> VcsDetection {
let has_jj = path.join(".jj").is_dir();
let has_git = path.join(".git").is_dir();
match (has_jj, has_git) {
(true, true) => VcsDetection::JjColocated,
(true, false) => VcsDetection::Jj,
(false, true) => VcsDetection::Git,
(false, false) => VcsDetection::None,
}
}
#[cfg(test)]
mod tests {
use tempfile::TempDir;
use super::*;
#[test]
fn detect_none() {
let dir = TempDir::new().unwrap();
assert_eq!(detect_vcs(dir.path()), VcsDetection::None);
}
#[test]
fn detect_git_only() {
let dir = TempDir::new().unwrap();
std::fs::create_dir(dir.path().join(".git")).unwrap();
assert_eq!(detect_vcs(dir.path()), VcsDetection::Git);
}
#[test]
fn detect_jj_only() {
let dir = TempDir::new().unwrap();
std::fs::create_dir(dir.path().join(".jj")).unwrap();
assert_eq!(detect_vcs(dir.path()), VcsDetection::Jj);
}
#[test]
fn detect_colocated() {
let dir = TempDir::new().unwrap();
std::fs::create_dir(dir.path().join(".jj")).unwrap();
std::fs::create_dir(dir.path().join(".git")).unwrap();
assert_eq!(detect_vcs(dir.path()), VcsDetection::JjColocated);
}
}