Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ Atomic's CRDT semantic layer (Trunk → Branch → Leaf) tracks changes at the t

Every repository has a **vault** — a versioned knowledge store that persists what your team and your agents learn across sessions. Goals, decisions, architecture context, and working memory all live in `.vault/` as structured markdown with cryptographic provenance.

Vault **writes** — `atomic vault goal start/stop/resume`, `atomic vault materialize`, `atomic vault sync`, `atomic intent new/update/delete/link/attest`, and `atomic memory new/write/attest` — create the vault on first use if it does not exist yet. Reads never mutate the checkout: on a repository without a vault they return empty/not-found, so read-only checkouts keep working. `atomic vault init` is only needed when you want the defaults created and recorded up front, for example after `atomic init --no-vault`.

```bash
# Initialize the vault in your repo
atomic vault init
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/intent/attest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Command for IntentAttest {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let inputs = bridge::read_intent(&repo, &self.id)?;

Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/intent/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Command for IntentDelete {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

if !self.force {
// Check that the intent exists before prompting.
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/intent/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Command for IntentLink {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

repo.vault_intent_link(&self.id, &self.goal)
.map_err(CliError::Repository)?;
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/intent/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Command for IntentNew {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let (created, kind) =
create_intent(&repo, &self.title, &self.kind, self.review.as_deref())?;
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/intent/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Command for IntentUpdate {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let content = self.resolve_body()?;
if self.status.is_none()
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/intent/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl Command for IntentValidate {
})?
} else {
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;
let inputs = bridge::read_intent(&repo, &self.id_or_path)?;
match bridge::load_attestation(&repo, &self.id_or_path, &inputs)? {
bridge::Attestation::Fresh(node) => *node,
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/intent/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl Command for IntentVerify {
impl IntentVerify {
async fn execute(&self) -> CliResult<()> {
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let inputs = bridge::read_intent(&repo, &self.id)?;
let node = match bridge::load_attestation(&repo, &self.id, &inputs)? {
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/memory/attest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Command for MemoryAttest {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let inputs = bridge::read_memory(&repo, &self.id)?;

Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/memory/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ impl Command for MemoryList {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let verifier = resolve_verifier(&self.identity)?;

Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/memory/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Command for MemoryNew {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let id = self.id.clone().unwrap_or_else(generate_ulid_lowercased);
let vault_path = bridge::normalize_memory_path(&id);
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/memory/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl Command for MemoryShow {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let inputs = bridge::read_memory(&repo, &self.id)?;
let attestation = bridge::load_attestation(&repo, &self.id, &inputs)?;
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/memory/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl Command for MemoryValidate {
})?
} else {
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;
let inputs = bridge::read_memory(&repo, &self.id_or_path)?;
match bridge::load_attestation(&repo, &self.id_or_path, &inputs)? {
bridge::Attestation::Fresh(node) => *node,
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/memory/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl Command for MemoryVerify {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let inputs = bridge::read_memory(&repo, &self.id)?;
let node = match bridge::load_attestation(&repo, &self.id, &inputs)? {
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/memory/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Command for MemoryWrite {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

// Freeform body from stdin — no lift/gate; this is the raw path.
use std::io::Read;
Expand Down
32 changes: 32 additions & 0 deletions atomic-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,38 @@ pub(crate) fn open_readonly_repository(
Repository::open_readonly_wait(path, std::time::Duration::from_secs(10))
}

/// Open the repository at `root` for a command that writes to the vault,
/// creating the vault when it does not exist yet.
///
/// Vault *writes* — `goal start/stop/resume`, `materialize`, `sync`,
/// `intent new/update/delete/link/attest`, `memory new/write/attest` — open
/// through this helper so a repository created without a vault
/// (`atomic init --no-vault`, or one that never ran `atomic vault init`)
/// works on first use instead of failing with "Vault not initialized".
///
/// Read-only commands deliberately do NOT use this helper: they open with
/// [`open_readonly_repository`], so a read never mutates a checkout — an
/// uninitialized vault reads as empty/not-found, and the first write
/// initializes it.
///
/// The initialization is [`Repository::ensure_vault`], the same idempotent
/// path `atomic vault init` uses. It runs at most once: an existing vault is
/// never re-initialized.
pub fn open_repository_with_vault(root: &Path) -> CliResult<Repository> {
let repo = Repository::open(root).map_err(CliError::from)?;
ensure_vault_exists(&repo)?;
Ok(repo)
}

/// One-time implicit vault initialization, announced on stderr so `--json`
/// output stays parseable.
fn ensure_vault_exists(repo: &Repository) -> CliResult<()> {
if repo.ensure_vault().map_err(CliError::from)? {
eprintln!("Initialized vault at {}", repo.vault_dir().display());
}
Ok(())
}

/// Open a repository or return a user-friendly error.
///
/// This is a convenience wrapper around [`open_repository`] that provides
Expand Down
12 changes: 7 additions & 5 deletions atomic-cli/src/commands/vault/goal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Command for GoalStart {
return Ok(());
}
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let result = repo
.vault_goal_start(GoalStartOptions {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl Command for GoalStop {
return Ok(());
}
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

// Find the goal to stop
let goal_name = match &self.goal {
Expand Down Expand Up @@ -291,7 +291,7 @@ impl Command for GoalResume {
return Ok(());
}
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let info = repo
.vault_goal_resume(&self.goal)
Expand Down Expand Up @@ -387,7 +387,8 @@ impl Command for GoalList {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let filter = if self.status == "all" {
Some("all")
Expand Down Expand Up @@ -434,7 +435,8 @@ impl Command for GoalShow {
return Ok(());
}
let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let entry = repo
.vault_goal_show(&self.goal)
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/vault/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ impl Command for List {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let type_filter = self.r#type.as_deref().and_then(VaultEntryType::parse);
let prefix = self.prefix.as_deref().unwrap_or("");
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/vault/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Command for Materialize {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

if let Some(ref path) = self.path {
repo.vault_materialize(path).map_err(CliError::Repository)?;
Expand Down
3 changes: 2 additions & 1 deletion atomic-cli/src/commands/vault/summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl Command for Summaries {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo =
crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?;

let prefix = match &self.goal {
Some(name) => format!("goals/{}/", name),
Expand Down
2 changes: 1 addition & 1 deletion atomic-cli/src/commands/vault/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Command for Sync {
}

let root = find_repository_root()?;
let repo = Repository::open(&root).map_err(CliError::Repository)?;
let repo = crate::commands::open_repository_with_vault(&root)?;

let updated = repo
.vault_record_working_copy()
Expand Down
1 change: 1 addition & 0 deletions atomic-cli/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ mod session_integration_test;
mod shim_census_cb13a_test;
mod status_git_cb11a_test;
mod unrecord_integration_test;
mod vault_auto_init_test;
mod vault_context_integration_test;
mod view_confirmation_integration_test;
mod working_copy_preservation_test;
Expand Down
Loading
Loading