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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ All notable changes to this project are documented here. The format follows
read side's identity index.

### Changed
- Agent reads: an `ARA217`/`ARA218` warning about one optional-layer file
(`staging/observations.yaml`, `trace/taste_log.yaml`, `trace/sessions/*`,
`logic/experiments.md`, `logic/solution/heuristics.md`, or the PAPER
`knowledge_paths` registry) no longer refuses `ls`, `show` and `find`
(0.1.34, plan 23, #128). The read prints its result with `complete: false`
and `incomplete: [{path, codes, reason}]`, brief text adds an
`incomplete: <path> (<codes>)` line, and the read exits 0 like any read
with warnings (`status` still exits 1 when incomplete). `status` keeps
its counts and withholds only the next ID of an affected prefix
(`next_id.incomplete_layer`). Node-scoped `ARA217`, `ARA222` and `ARA226`
still refuse with `incomplete_artifact`.
- Agent reads: bounded `find` (0.1.32, plan 22 part D). Brief `find` keeps
the first 3 matched lines of each hit and ends the hit with
`+K more matching lines`; `--lines-per-hit N` changes the cap and `0`
Expand Down Expand Up @@ -260,6 +271,12 @@ All notable changes to this project are documented here. The format follows
`invalid_document` errors name these roots. Old rubric history stays readable.

### Fixed
- Core reads: experiment and heuristic headings accept the separators claims
accept (`## E01 — Title`, `## H03 – Title`, `## E02 - Title`) and a bracketed
status before the separator (`## E02 [in progress]: Title`), which becomes
the entry's `status` unless a `**Status**` field is present (0.1.34, #128).
One shared parser serves the reader, merge identity and CLI heading lookup.
The `malformed entry heading` warning now gives its line and heading.
- Core validation: the dependency-cycle check (`ARA110`, 0.1.33) orients
`also_depends_on` edges from dependency to dependent, the same direction as
`children:` nesting. A cross-branch diamond, such as a node depending on a
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]

[workspace.package]
version = "0.1.33"
version = "0.1.34"
edition = "2024"
license = "MPL-2.0"
repository = "https://github.com/ARA-Labs/ara-cli"
Expand Down
38 changes: 29 additions & 9 deletions crates/ara-cli/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,10 @@ pub fn list(root: &Path, args: &ListArgs) -> Result<Value, AgentError> {
|| args.status.is_some()
|| args.provenance.is_some();
if args.output.brief() && document.is_none() && !filtered && !args.unfinished {
return Ok(
return Ok(validity::with_coverage(
json!({"format":"ara.ls/v1","documents":artifact.document_summaries(),"file_access":ara_core::FILE_ACCESS_ROOTS,"diagnostics":diagnostics(&artifact.report)}),
);
&artifact.report,
));
}
let matches_filters = |entry: &Entry<'_>| {
document.as_ref().is_none_or(|(path, _)| {
Expand Down Expand Up @@ -610,7 +611,10 @@ pub fn list(root: &Path, args: &ListArgs) -> Result<Value, AgentError> {
{
rows = display::heading_rows(&path, text);
}
Ok(json!({"format":"ara.ls/v1","entries":rows,"diagnostics":diagnostics(&artifact.report)}))
Ok(validity::with_coverage(
json!({"format":"ara.ls/v1","entries":rows,"diagnostics":diagnostics(&artifact.report)}),
&artifact.report,
))
}
pub fn show(root: &Path, args: &ShowArgs) -> Result<Value, AgentError> {
if args.identity {
Expand Down Expand Up @@ -946,8 +950,10 @@ fn show_rows(artifact: &Artifact, args: &ShowArgs, brief: bool) -> Result<Value,
}
rows.push(value);
}
let mut value =
json!({"format":"ara.show/v1","entries":rows,"diagnostics":diagnostics(&artifact.report)});
let mut value = validity::with_coverage(
json!({"format":"ara.show/v1","entries":rows,"diagnostics":diagnostics(&artifact.report)}),
&artifact.report,
);
if !failed.is_empty() {
value["errors"] = json!(failed);
}
Expand Down Expand Up @@ -990,6 +996,12 @@ pub fn status(root: &Path, brief: bool) -> Result<Value, AgentError> {
}
let complete =
loaded.report.is_ok() && loaded.manifest.is_some() && representable(&loaded.report);
// Optional-layer warnings keep `complete` false but leave counts and the
// unaffected next IDs available.
let counted = loaded.report.is_ok()
&& loaded.manifest.is_some()
&& validity::nodes_representable(&loaded.report);
let unknown_next = validity::incomplete_prefixes(&loaded.report);
let mut counts = BTreeMap::<String, usize>::new();
let mut native_ids = BTreeMap::<char, Vec<String>>::from([
('N', Vec::new()),
Expand Down Expand Up @@ -1021,7 +1033,7 @@ pub fn status(root: &Path, brief: bool) -> Result<Value, AgentError> {
}
latest = manifest.sessions.iter().map(|s| s.id.as_str()).max();
}
let historical = complete
let historical = counted
&& (loaded.sources.contains_key("trace/logic_mutations.yaml")
|| loaded.sources.contains_key("trace/merge_log.yaml"));
let working = if historical {
Expand All @@ -1033,9 +1045,16 @@ pub fn status(root: &Path, brief: bool) -> Result<Value, AgentError> {
};
let mut next_ids = BTreeMap::new();
let mut next_id_errors = BTreeMap::new();
if complete {
if counted {
for (prefix, ids) in native_ids {
let next = if let Some(working) = &working {
let next = if let Some(file) = unknown_next.get(&prefix) {
Err(ara_core::write::WriteError::semantic(
"next_id.incomplete_layer",
format!(
"`{file}` is not fully represented; run `ara check` and fix it before allocating the next {prefix} ID"
),
))
} else if let Some(working) = &working {
working.allocate_id(prefix, &ids, None)
} else {
ara_core::write::source::allocate_id(prefix, &ids, None)
Expand All @@ -1056,7 +1075,8 @@ pub fn status(root: &Path, brief: bool) -> Result<Value, AgentError> {
.iter()
.try_fold(0u64, |total, file| total.checked_add(file.bytes))
.ok_or_else(|| AgentError::io("Artifact byte size exceeds u64"))?;
let mut value = json!({"format":"ara.status/v1","artifact_location":root.canonicalize().map_err(|error|AgentError::io(error.to_string()))?,"file_count":files.len(),"total_bytes":total_bytes,"files":files,"complete":complete,"counts":if complete {json!(counts)}else{Value::Null},"next_ids":if complete{json!(next_ids)}else{Value::Null},"next_id_errors":next_id_errors,"latest_session":latest,"diagnostics":{"errors":loaded.report.errors().len(),"warnings":loaded.report.warnings().len(),"report":loaded.report}});
let mut value = json!({"format":"ara.status/v1","artifact_location":root.canonicalize().map_err(|error|AgentError::io(error.to_string()))?,"file_count":files.len(),"total_bytes":total_bytes,"files":files,"complete":complete,"counts":if counted {json!(counts)}else{Value::Null},"next_ids":if counted{json!(next_ids)}else{Value::Null},"next_id_errors":next_id_errors,"latest_session":latest,"diagnostics":{"errors":loaded.report.errors().len(),"warnings":loaded.report.warnings().len(),"report":loaded.report}});
value = validity::with_coverage(value, &loaded.report);
if brief {
let codes = |diagnostics: &[ara_core::Diagnostic]| {
diagnostics
Expand Down
5 changes: 4 additions & 1 deletion crates/ara-cli/src/agent/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ pub(super) fn show_document(
full: bool,
) -> Result<Value, AgentError> {
let row = document_row(artifact, document, headings, source, full)?;
Ok(json!({"format":"ara.show/v1","entries":[row],"diagnostics":diagnostics(&artifact.report)}))
Ok(super::validity::with_coverage(
json!({"format":"ara.show/v1","entries":[row],"diagnostics":diagnostics(&artifact.report)}),
&artifact.report,
))
}

/// Exact tiers, then an archived identity redirect, then tolerant tiers.
Expand Down
6 changes: 4 additions & 2 deletions crates/ara-cli/src/agent/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ pub fn find(root: &Path, args: &FindArgs) -> Result<Value, AgentError> {
.iter()
.map(|hit| results.row(hit, args.cap()))
.collect::<Result<Vec<_>, _>>()?;
let mut value =
json!({"format":"ara.find/v1","results":rows,"diagnostics":artifact.diagnostics()});
let mut value = super::validity::with_coverage(
json!({"format":"ara.find/v1","results":rows,"diagnostics":artifact.diagnostics()}),
&artifact.report,
);
if let Some(budget) = budget {
fit(&mut value, budget, args.output.brief(), |cap| {
results.row(&hits[0], Some(cap))
Expand Down
7 changes: 4 additions & 3 deletions crates/ara-cli/src/agent/headings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ fn native_shorthand(actual: &str, wanted: &str) -> bool {
&& wanted[1..].bytes().all(|byte| byte.is_ascii_digit())
&& heading_id(actual) == Some(wanted)
}
/// A claim heading's ID (any native separator), else the text before `:`.
/// A native entry heading's ID (any separator or bracketed status), else the
/// text before `:`.
pub(super) fn heading_id(heading: &str) -> Option<&str> {
ara_core::claim_heading(heading)
.map(|(id, _)| id)
ara_core::native_entry_heading(heading)
.map(|entry| entry.id)
.or_else(|| heading.split_once(':').map(|(id, _)| id.trim()))
}
/// A whole-document or selected-range row; the digest covers exactly the
Expand Down
123 changes: 120 additions & 3 deletions crates/ara-cli/src/agent/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
//! not any dangling ID names it. A dropped claim looks exactly like a dangling `ARA107`
//! reference, so that parse loss refuses as it did before. The report keeps
//! each diagnostic's original severity. Writes never use this tolerance.
//!
//! An `ARA217`/`ARA218` warning about one optional-layer file (observations,
//! taste log, sessions, experiments, heuristics, the knowledge registry) does
//! not refuse: the read goes ahead and [`with_coverage`] names the file under
//! `incomplete`. Node-scoped `ARA217`, `ARA222` and `ARA226` still refuse.
use crate::output::AgentError;
use ara_core::{ClaimId, Manifest, ParseReport, RuleCode};
use ara_core::{ClaimId, Diagnostic, Manifest, ParseReport, RuleCode};
use serde_json::{Value, json};
use std::collections::{BTreeMap, BTreeSet};

Expand Down Expand Up @@ -48,6 +53,85 @@ const UNREPRESENTED: [RuleCode; 4] = [
RuleCode::MalformedNodeAnnotation,
];

/// Optional-layer files whose `ARA217`/`ARA218` warnings read through.
const OPTIONAL_LAYER_FILES: [&str; 5] = [
"staging/observations.yaml",
"trace/taste_log.yaml",
"logic/experiments.md",
"logic/solution/heuristics.md",
// An invalid registry leaves the registered documents unloaded.
"PAPER.md.knowledge_paths",
];

/// Session records and their index, one optional layer.
const SESSIONS: &str = "trace/sessions/";

/// A diagnostic path without its `:line` suffix.
fn diagnostic_file(path: &str) -> &str {
match path.rsplit_once(':') {
Some((file, line)) if !line.is_empty() && line.bytes().all(|b| b.is_ascii_digit()) => file,
_ => path,
}
}

/// The optional-layer file a warning leaves incomplete, if it reads through.
fn optional_layer(diagnostic: &Diagnostic) -> Option<&str> {
if !matches!(
diagnostic.code,
RuleCode::MalformedAgentLayer | RuleCode::DuplicateAgentId
) {
return None;
}
let file = diagnostic_file(&diagnostic.path);
(OPTIONAL_LAYER_FILES.contains(&file) || file.starts_with(SESSIONS)).then_some(file)
}

/// `{path, codes, reason}` for each optional-layer file a read could not
/// fully represent, in first-diagnostic order. `reason` joins the first line
/// of each distinct message.
pub fn incomplete(report: &ParseReport) -> Vec<Value> {
let mut files: Vec<(&str, Vec<RuleCode>, Vec<&str>)> = Vec::new();
for diagnostic in report.warnings() {
let Some(file) = optional_layer(diagnostic) else {
continue;
};
let index = match files.iter().position(|(path, ..)| *path == file) {
Some(index) => index,
None => {
files.push((file, Vec::new(), Vec::new()));
files.len() - 1
}
};
let (_, codes, reasons) = &mut files[index];
if !codes.contains(&diagnostic.code) {
codes.push(diagnostic.code);
}
let reason = diagnostic.message.lines().next().unwrap_or_default();
if !reasons.contains(&reason) {
reasons.push(reason);
}
}
files
.into_iter()
.map(
|(path, codes, reasons)| json!({"path":path,"codes":codes,"reason":reasons.join("; ")}),
)
.collect()
}

/// A structural read result with `complete: false` and `incomplete` added
/// when an optional layer was not fully represented; unchanged otherwise.
pub fn with_coverage(mut value: Value, report: &ParseReport) -> Value {
let incomplete = incomplete(report);
if !incomplete.is_empty()
&& let Value::Object(object) = &mut value
{
object.insert("complete".into(), json!(false));
object.insert("incomplete".into(), json!(incomplete));
}
value
}

/// Whether every optional layer and node annotation was represented: none of
/// the [`UNREPRESENTED`] warnings is present. `status` uses this as part of
/// `complete`; structural reads refuse with `incomplete_artifact` without it.
Expand All @@ -58,6 +142,33 @@ pub fn representable(report: &ParseReport) -> bool {
.any(|diagnostic| UNREPRESENTED.contains(&diagnostic.code))
}

/// [`representable`], ignoring optional-layer warnings: every node and node
/// annotation was represented, so counts stay meaningful.
pub fn nodes_representable(report: &ParseReport) -> bool {
!report.warnings().iter().any(|diagnostic| {
UNREPRESENTED.contains(&diagnostic.code) && optional_layer(diagnostic).is_none()
})
}

/// Native ID prefixes whose next ID is unknown because their optional-layer
/// file is incomplete: a dropped entry may already hold the next number.
pub fn incomplete_prefixes(report: &ParseReport) -> BTreeMap<char, &str> {
let mut prefixes = BTreeMap::new();
for diagnostic in report.warnings() {
let prefix = match optional_layer(diagnostic) {
Some("staging/observations.yaml") => 'O',
Some("trace/taste_log.yaml") => 'T',
Some("logic/experiments.md") => 'E',
Some("logic/solution/heuristics.md") => 'H',
_ => continue,
};
prefixes
.entry(prefix)
.or_insert_with(|| diagnostic_file(&diagnostic.path));
}
prefixes
}

/// Distinct error codes in report order, filtered by `keep`.
fn error_codes(report: &ParseReport, keep: impl Fn(RuleCode) -> bool) -> Vec<RuleCode> {
let mut codes = Vec::new();
Expand Down Expand Up @@ -193,7 +304,8 @@ fn dangling_claim_headings(dangling: &BTreeSet<String>, claims: &str) -> Vec<Str

/// The structural-read refusal for a load, if any: `invalid_artifact` for a
/// blocking error, or for a read-through error while a typed document lost
/// entries, and `incomplete_artifact` for an unrepresented layer.
/// entries, and `incomplete_artifact` for an unrepresented node annotation.
/// Optional-layer warnings never refuse ([`with_coverage`]).
pub fn read_refusal(
report: &ParseReport,
sources: &BTreeMap<String, String>,
Expand All @@ -215,7 +327,12 @@ pub fn read_refusal(
}
let unrepresented: Vec<RuleCode> = UNREPRESENTED
.into_iter()
.filter(|code| report.warnings().iter().any(|d| d.code == *code))
.filter(|code| {
report
.warnings()
.iter()
.any(|d| d.code == *code && optional_layer(d).is_none())
})
.collect();
(!unrepresented.is_empty()).then(|| refusal("incomplete_artifact", report, unrepresented))
}
Expand Down
27 changes: 27 additions & 0 deletions crates/ara-cli/src/brief/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ pub(crate) fn print_diagnostics(value: &Value) {
{
eprintln!("{summary}");
}
for line in incomplete(value) {
eprintln!("{line}");
}
}

/// One `incomplete: path (codes)` line per optional-layer file a read could
/// not fully represent.
fn incomplete(value: &Value) -> Vec<String> {
let Some(files) = value["incomplete"].as_array() else {
return Vec::new();
};
files
.iter()
.map(|file| {
let codes: Vec<&str> = file["codes"]
.as_array()
.into_iter()
.flatten()
.filter_map(Value::as_str)
.collect();
format!(
"incomplete: {} ({})",
file["path"].as_str().unwrap_or_default(),
codes.join(", ")
)
})
.collect()
}

pub(crate) fn render(value: &Value, out: &mut impl Write) -> std::io::Result<()> {
Expand Down
Loading