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
18 changes: 9 additions & 9 deletions atomic-cli/src/commands/intent/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub struct IntentList {
pub identity: Option<String>,

/// Only list intents of this classification (one of feature, review, bug,
/// chore, remediation). Read from the manifest `IntentSummary.kind` — no
/// lift. Mutually exclusive with `--review`.
/// chore, remediation). Read from intent frontmatter or the legacy manifest
/// fallback. Mutually exclusive with `--review`.
#[arg(long, value_name = "KIND", conflicts_with = "review")]
pub kind: Option<String>,

Expand Down Expand Up @@ -238,7 +238,7 @@ pub(crate) struct Row {
/// name an intent without a second lookup. The table stays id-only.
pub(crate) title: String,
pub(crate) status: String,
/// Classification tag, read from the manifest `IntentSummary.kind` (no lift).
/// Classification from the stored frontmatter, falling back to the manifest.
pub(crate) kind: String,
pub(crate) attested: Attested,
pub(crate) verifies: Verifies,
Expand Down Expand Up @@ -351,9 +351,9 @@ fn compute_row(

/// Build the (optionally kind-filtered) rows for the listing.
///
/// Enumeration reuses [`Repository::vault_intent_list`]; the `kind` tag is read
/// straight from the manifest `IntentSummary.kind` (a manifest read, never a
/// lift). Factored out of [`Command::run`] so the kind tag + filter are
/// Enumeration reuses [`Repository::vault_intent_list`]; the `kind` tag prefers
/// stored frontmatter over the manifest fallback. Factored out of [`Command::run`]
/// so the kind tag + filter are
/// unit-testable without a global identity store. A row whose id is missing from
/// the manifest (should not happen — the same manifest backs both) degrades to
/// the default `feature`.
Expand All @@ -369,7 +369,7 @@ fn build_rows(
let kind = manifest
.intents
.get(&info.id)
.map(|s| s.kind.clone())
.map(|s| repo.vault_intent_effective_kind(&s.vault_path, &s.kind))
.unwrap_or_else(|| "feature".to_string());
if let Some(f) = filter {
if kind != f {
Expand Down Expand Up @@ -449,7 +449,7 @@ impl IntentList {
}

/// One row reconstructed from the wire's per-entry classification — the
/// routed twin of [`compute_row`]: the handler computed the manifest kind
/// routed twin of [`compute_row`]: the handler computed the effective kind
/// and the attestation/verifies state with the same domain logic, so the
/// row maps straight off the wire columns.
pub(crate) fn wire_row(entry: &atomic_client::proto::VaultEntry) -> Row {
Expand Down Expand Up @@ -511,7 +511,7 @@ impl Command for IntentList {

// Enumerate via the SAME source `atomic vault intent list` uses; already
// sorted by id. Attestation entries are never in `manifest.intents`. The
// kind tag is read from the manifest summary (no lift).
// kind tag uses stored frontmatter with a manifest fallback.
let mut rows = build_rows(&repo, verifier.as_ref(), filter.as_deref())?;
sort_rows(&mut rows, self.sort, self.reverse);

Expand Down
8 changes: 4 additions & 4 deletions atomic-cli/src/commands/intent/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ fn create_intent(

impl Command for IntentNew {
fn run(&self) -> CliResult<()> {
if crate::commands::rpc::intent_new(self)? {
return Ok(());
}

if self.template != "feature" {
return Err(CliError::InvalidArgument {
message: format!(
Expand All @@ -154,6 +150,10 @@ impl Command for IntentNew {
});
}

if crate::commands::rpc::intent_new(self)? {
return Ok(());
}

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

Expand Down
25 changes: 24 additions & 1 deletion atomic-cli/src/commands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,34 @@ pub fn intent_new(args: &super::intent::new::IntentNew) -> CliResult<bool> {
developer: None,
intent: None,
model: None,
intent_kind: Some(args.kind.clone()),
review_target: args.review.clone(),
view: None,
expected_snapshot: None,
};
let response = session.create_vault_entity(request)?;
let entry = response.entry.expect("created entry");
let expected_kind = if args.review.is_some() {
"review"
} else {
&args.kind
};
if expected_kind != "feature" && entry.manifest_kind.as_deref() != Some(expected_kind) {
return Err(CliError::Internal(anyhow::anyhow!(
"intent {} was created, but the service did not confirm kind '{}'; upgrade the service and inspect the intent",
entry.id, expected_kind
)));
}
println!("Created intent: {}", entry.id);
println!(" file: {}", entry.vault_path.clone().unwrap_or_default());
println!(" template: {}", args.template);
println!(" kind: {}", args.kind);
println!(
" kind: {}",
entry.manifest_kind.as_deref().unwrap_or(&args.kind)
);
if let Some(target) = &args.review {
println!(" reviews: {target}");
}
Ok(true)
}

Expand Down Expand Up @@ -1104,6 +1123,8 @@ pub fn memory_new(args: &super::memory::new::MemoryNew) -> CliResult<bool> {
developer: None,
intent: None,
model: None,
intent_kind: None,
review_target: None,
view: None,
expected_snapshot: None,
};
Expand Down Expand Up @@ -5983,6 +6004,8 @@ pub fn vault_goal_start(args: &super::vault::goal::GoalStart) -> CliResult<bool>
developer: args.developer.clone(),
intent: args.intent.clone(),
model: args.model.clone(),
intent_kind: None,
review_target: None,
view: None,
expected_snapshot: None,
};
Expand Down
94 changes: 94 additions & 0 deletions atomic-cli/tests/it/routing_parity_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,100 @@ fn intent_list_json_carries_attestation_columns_over_the_wire() {
assert!(table.contains(&id));
}

#[test]
fn intent_kind_is_preserved_and_stale_summaries_are_reconciled() {
let (repo, home) = fixture("intent-kind");
let (root, home_dir) = (repo.path(), home.path());
let create = |args: &[&str]| {
let output = run(root, home_dir, args);
output
.lines()
.find_map(|s| s.strip_prefix("Created intent: "))
.unwrap()
.to_owned()
};
let feature = create(&["intent", "new", "Feature"]);
let bug = create(&["intent", "new", "Bug", "--kind", "bug"]);
let review = create(&["intent", "new", "Review", "--review", &bug]);
let bug_show = run(root, home_dir, &["intent", "show", &bug]);
assert!(bug_show.contains("Kind: bug"), "{bug_show}");
let review_show = run(root, home_dir, &["intent", "show", &review]);
assert!(
review_show.contains("Kind: review") && review_show.contains(&bug),
"{review_show}"
);
for args in [
vec!["intent", "new", "bad", "--kind", "nonsense"],
vec!["intent", "new", "bad", "--template", "nonsense"],
] {
assert!(!atomic(root, home_dir, &args).status.success(), "{args:?}");
}
let rows = |args: &[&str]| -> Vec<serde_json::Value> {
serde_json::from_str(&run(root, home_dir, args)).unwrap()
};
let all = rows(&["intent", "list", "--json"]);
assert_eq!(all.len(), 3, "invalid requests must not create intents");
assert!(all
.iter()
.any(|row| row["id"] == feature && row["kind"] == "feature"));
assert!(all
.iter()
.any(|row| row["id"] == review && row["kind"] == "review"));
let bugs = rows(&["intent", "list", "--kind", "bug", "--json"]);
assert_eq!(bugs.len(), 1);
assert_eq!(bugs[0]["id"], bug);

// Simulate an already-stored corrected document with a stale manifest,
// without rewriting the document during listing or reconciliation.
{
let repository = atomic_repository::Repository::open_existing(root).unwrap();
let summary = repository.vault_manifest().unwrap().intents[&feature].clone();
let entry = repository
.vault_retrieve(&summary.vault_path)
.unwrap()
.unwrap();
let mut fm: serde_json::Value = serde_json::from_str(&entry.frontmatter_json).unwrap();
fm["kind"] = "bug".into();
repository
.vault_store(
&summary.vault_path,
atomic_core::pristine::VaultEntryType::Intent,
entry.content_bytes,
serde_json::to_string(&fm).unwrap(),
)
.unwrap();
repository.vault_materialize(&summary.vault_path).unwrap();
assert_eq!(
repository.vault_manifest().unwrap().intents[&feature].kind,
"feature"
);
}
let bugs = rows(&["intent", "list", "--kind", "bug", "--json"]);
assert_eq!(bugs.len(), 2);
assert!(bugs.iter().any(|row| row["id"] == feature));
let path = {
let repository = atomic_repository::Repository::open_existing(root).unwrap();
repository.vault_manifest().unwrap().intents[&feature]
.vault_path
.clone()
};
let before = std::fs::read(root.join(".vault").join(path)).unwrap();
run(root, home_dir, &["vault", "sync"]);
let repository = atomic_repository::Repository::open_existing(root).unwrap();
assert_eq!(
repository.vault_manifest().unwrap().intents[&feature].kind,
"bug"
);
assert_eq!(
before,
std::fs::read(
root.join(".vault")
.join(&repository.vault_manifest().unwrap().intents[&feature].vault_path)
)
.unwrap()
);
}

#[test]
fn intent_human_key_sort_is_natural_in_service_output() {
let repo = TempDir::new().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions atomic-repository/src/repository/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ impl Repository {
if let Some(status) = fm.get("status").and_then(|v| v.as_str()) {
summary.status = status.to_string();
}
if let Some(kind) = fm.get("kind").and_then(|v| v.as_str()) {
summary.kind = kind.to_string();
}
// Same story as status: the title lives in the frontmatter, and
// the summary is what `intent list` and the intents API render.
// Unmirrored, an intent that plainly has a title listed with none.
Expand Down
69 changes: 55 additions & 14 deletions atomic-repository/src/repository/vault_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,14 @@ impl Repository {
})
}

/// Rebuild missing `manifest.intents` summaries from stored intent entries.
/// Rebuild missing summaries and reconcile explicit intent classifications.
///
/// Intent entries can reach the vault without `vault_intent_create` ever
/// running: clone bootstrap and `vault sync` deflate inherited
/// `.vault/intents/**` files straight into redb, and
/// `update_manifest_for_store` deliberately leaves intent summaries to
/// "higher-level methods". This is that higher-level method for the
/// ingestion path. Existing summaries are never overwritten — the
/// authoring path stays the source of truth for intents it created.
/// ingestion path. Existing summaries retain their other fields.
///
/// Also adopts the authoring repo's intent prefix when the local one is
/// unset, and advances the per-author sequence allocator past inherited
Expand All @@ -369,18 +368,9 @@ impl Repository {
.get_vault_manifest()
.map_err(|e| RepositoryError::Database(e.to_string()))?;
let mut added = 0usize;
let mut changed = false;

for meta in &entries {
// Already indexed (the authoring path stores vault_path on every
// summary) — leave it alone.
if manifest
.intents
.values()
.any(|summary| summary.vault_path == meta.path)
{
continue;
}

let Some(entry) = txn
.get_vault_entry(&meta.path)
.map_err(|e| RepositoryError::Database(e.to_string()))?
Expand All @@ -394,6 +384,19 @@ impl Repository {
);
continue;
};
if let Some(summary) = manifest
.intents
.values_mut()
.find(|s| s.vault_path == meta.path)
{
if let Some(kind) = fm.get("kind").and_then(|v| v.as_str()) {
if summary.kind != kind {
summary.kind = kind.to_owned();
changed = true;
}
}
continue;
}
// `id` is the human key; an entry without one is not a canonical
// intent scaffold and has nothing to index.
let Some(human_key) = fm.get("id").and_then(|v| v.as_str()).map(str::to_owned) else {
Expand Down Expand Up @@ -456,7 +459,7 @@ impl Repository {
added += 1;
}

if added > 0 {
if added > 0 || changed {
manifest.updated_at = chrono::Utc::now().to_rfc3339();
txn.put_vault_manifest(&manifest)
.map_err(|e| RepositoryError::Database(e.to_string()))?;
Expand All @@ -466,6 +469,19 @@ impl Repository {
Ok(added)
}

/// Prefer an explicit stored classification over a stale manifest summary.
/// Legacy entries without a kind continue to use their manifest value.
pub fn vault_intent_effective_kind(&self, path: &str, fallback: &str) -> String {
self.vault_retrieve(path)
.ok()
.flatten()
.and_then(|entry| {
serde_json::from_str::<serde_json::Value>(&entry.frontmatter_json).ok()
})
.and_then(|fm| fm.get("kind").and_then(|v| v.as_str()).map(str::to_owned))
.unwrap_or_else(|| fallback.to_owned())
}

/// List vault intents.
///
/// Optionally filtered by status. Pass `Some("all")` or `None` for all intents.
Expand Down Expand Up @@ -1516,6 +1532,31 @@ mod tests {
assert_eq!(rev_fm["kind"], "review");
}

#[test]
fn sync_mirrors_edited_kind_and_preserves_legacy_fallback() {
let dir = tempdir().unwrap();
let repo = init_repo_with_vault(dir.path());
let created = repo
.vault_intent_create(create_opts_manual("Kind edit"))
.unwrap();
assert_eq!(
repo.vault_intent_effective_kind(&created.intent_file, "review"),
"review"
);
let path = repo.vault_dir().join(&created.intent_file);
let content = std::fs::read_to_string(&path).unwrap();
std::fs::write(&path, content.replacen("---\n", "---\nkind: bug\n", 1)).unwrap();
repo.vault_record_working_copy().unwrap();
assert_eq!(
repo.vault_manifest().unwrap().intents[&created.id].kind,
"bug"
);
assert_eq!(
repo.vault_intent_effective_kind(&created.intent_file, "feature"),
"bug"
);
}

/// Reproduces the clone-inheritance gap: an intent file that arrives as
/// bytes (clone materializes it; `vault sync` deflates it) must become
/// listable and resolvable — `vault_intent_create` never runs on the
Expand Down
3 changes: 3 additions & 0 deletions libatomic/proto/atomic/services/vault/vault_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ message CreateVaultEntityRequest {
optional string developer = 9;
optional string intent = 10;
optional string model = 11;
// Intent classification and optional reviewed target (add-only).
optional string intent_kind = 12;
optional string review_target = 13;
ViewRef view = 20;
ViewSnapshot expected_snapshot = 21;
}
Expand Down
Loading
Loading