From 1778bf163d854927d16c9a0c7d0d0c52b2cc5232 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 18 Oct 2026 21:37:15 -0700 Subject: [PATCH 1/4] docs: plan optional-layer read-through and shared entry headings (#128) Adds plan 23 and reproduction tests in agent_layer_tolerance.rs (three fail on 0.1.33 as reported). --- crates/ara-cli/tests/agent_layer_tolerance.rs | 124 +++++++++++++++ .../23-optional-layer-tolerance.md | 149 ++++++++++++++++++ plans/agent-cli-interface/README.md | 1 + 3 files changed, 274 insertions(+) create mode 100644 crates/ara-cli/tests/agent_layer_tolerance.rs create mode 100644 plans/agent-cli-interface/23-optional-layer-tolerance.md diff --git a/crates/ara-cli/tests/agent_layer_tolerance.rs b/crates/ara-cli/tests/agent_layer_tolerance.rs new file mode 100644 index 0000000..fc579ba --- /dev/null +++ b/crates/ara-cli/tests/agent_layer_tolerance.rs @@ -0,0 +1,124 @@ +//! Reproductions for #128: real ARAs refused over optional agent layers. +//! +//! Typed entries in `logic/experiments.md` and `logic/solution/heuristics.md` +//! should accept the dash separators claims already accept, and a malformed or +//! duplicated optional-layer record should not hide the rest of the artifact +//! from structural reads. +use assert_cmd::Command; +use serde_json::Value; +use std::path::Path; +use tempfile::TempDir; + +const TREE: &str = "tree:\n - id: N01\n type: question\n title: Q\n"; + +fn ara() -> Command { + let mut command = Command::cargo_bin("ara").unwrap(); + command.env_remove("ARA_DIR"); + command +} +fn artifact(files: &[(&str, &str)]) -> TempDir { + let dir = TempDir::new().unwrap(); + for (rel, body) in files { + let path = dir.path().join(rel); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(path, body).unwrap(); + } + dir +} +fn run(root: &Path, args: &[&str]) -> Value { + let output = ara() + .arg("-C") + .arg(root) + .args(args) + .arg("--json") + .assert() + .success() + .get_output() + .clone(); + serde_json::from_slice(&output.stdout).unwrap() +} +fn warning_codes(result: &Value) -> Vec { + result["diagnostics"]["warnings"] + .as_array() + .unwrap() + .iter() + .map(|d| d["code"].as_str().unwrap().to_owned()) + .collect() +} +fn entry<'a>(result: &'a Value, id: &str) -> &'a Value { + result["entries"] + .as_array() + .unwrap() + .iter() + .find(|row| row["id"] == id) + .unwrap_or_else(|| panic!("no entry {id} in {result}")) +} + +#[test] +fn dash_separated_typed_entry_headings_parse() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "logic/experiments.md", + "# Experiments\n\n\ + ## E01 \u{2014} Baseline vs. seed (upper bound)\n- **Setup**: x\n\n\ + ## E02 - Hyphen separated\n- **Setup**: y\n", + ), + ( + "logic/solution/heuristics.md", + "# Heuristics\n\n## H03 \u{2013} Track the sanity metric\n- **Rationale**: z\n", + ), + ]); + let listed = run(dir.path(), &["ls"]); + assert_eq!(warning_codes(&listed), Vec::::new(), "{listed}"); + for (id, title) in [ + ("E01", "Baseline vs. seed (upper bound)"), + ("E02", "Hyphen separated"), + ("H03", "Track the sanity metric"), + ] { + assert_eq!(entry(&listed, id)["title"], title, "{id}"); + } +} + +#[test] +fn hyphenated_title_word_is_not_a_separator() { + // `E01-ablation: Title` is not an entry ID; the dash split must need + // whitespace on both sides, exactly as for claims. + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "logic/experiments.md", + "# Experiments\n\n## E01: Two-stage - warmup\n- **Setup**: x\n", + ), + ]); + let listed = run(dir.path(), &["ls"]); + assert_eq!(entry(&listed, "E01")["title"], "Two-stage - warmup"); +} + +#[test] +fn duplicate_observation_id_does_not_hide_the_tree() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "staging/observations.yaml", + "observations:\n - id: O01\n content: a\n - id: O01\n content: b\n", + ), + ]); + let shown = run(dir.path(), &["show", "N01"]); + assert_eq!(entry(&shown, "N01")["title"], "Q"); + assert!(warning_codes(&shown).contains(&"ARA218".to_owned()), "{shown}"); +} + +#[test] +fn malformed_session_file_does_not_hide_the_tree() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "trace/sessions/2026-10-16_001.yaml", + "session:\n id: s1\n id: s1\n", + ), + ]); + let listed = run(dir.path(), &["ls"]); + assert_eq!(entry(&listed, "N01")["title"], "Q"); + assert!(warning_codes(&listed).contains(&"ARA217".to_owned()), "{listed}"); +} diff --git a/plans/agent-cli-interface/23-optional-layer-tolerance.md b/plans/agent-cli-interface/23-optional-layer-tolerance.md new file mode 100644 index 0000000..a4fac47 --- /dev/null +++ b/plans/agent-cli-interface/23-optional-layer-tolerance.md @@ -0,0 +1,149 @@ +# PR 23: read real ARAs despite optional-layer warnings (#128) +**Date:** 2026-10-18 + +Status: **draft, awaiting review**; D1 and D2 decided 2026-10-18 (both option a). Issue: [#128](https://github.com/ARA-Labs/ara-cli/issues/128). +Branch: `fix/128-readable-real-aras`, targeting `feat/agent-cli-interface`. +Parent: [agent CLI interface](../agent-cli-interface.md). Shared checks: [PR index](README.md). + +## TL;DR + +Two changes. (1) Typed entries in `logic/experiments.md` and +`logic/solution/heuristics.md` accept the same `ID: Title`, `ID — Title`, +`ID – Title` and `ID - Title` headings that claims already accept, through one +shared parser that the reader, merge identity and CLI heading lookup all use. +(2) An `ARA217`/`ARA218` warning about one optional-layer file stops refusing +every structural read. Reads go ahead and say which files were not fully +represented. Writes keep their existing validation. + +## Problem + +`ara` 0.1.33 refuses `ls`, `show` and `find` on every real research ARA over 40 +nodes in the #128 audit, and on `ara-paperbench/nanogpt-speedrun`. Plain file +reads work. Two causes concern only optional agent layers: + +- **Entry headings.** `markdown_entries` (`crates/ara-core/src/agent_layers.rs`) + splits on the first `:` only. `## E01 — Baseline` and `## H03 – Track …` drop + the entry and warn `ARA217 malformed entry heading` (with no line number). + `claims::claim_heading` already accepts spaced dashes, but only for `C` IDs. +- **All-or-nothing refusal.** `validity::read_refusal` turns any `ARA217`, + `ARA218`, `ARA222` or `ARA226` warning into `incomplete_artifact` for all + structural reads. One duplicate observation ID or one session file with a + duplicate YAML key hides a valid 500-node tree, its claims and experiments. + +The agent-CLI evaluation E2 pads benchmarks with these ARAs, so today the CLI +condition measures refusals, not efficiency. + +Out of scope: `ARA100`, `ARA105`, `ARA112` in the audit. They are real record +errors and keep refusing with `invalid_artifact`. + +### Reproduction + +`crates/ara-cli/tests/agent_layer_tolerance.rs` (new). On 0.1.33: + +| Test | Result | +|---|---| +| `dash_separated_typed_entry_headings_parse` | fails: `incomplete_artifact`, `ARA217`×3 | +| `duplicate_observation_id_does_not_hide_the_tree` | fails: `incomplete_artifact`, `ARA218` | +| `malformed_session_file_does_not_hide_the_tree` | fails: `incomplete_artifact`, `ARA217` | +| `hyphenated_title_word_is_not_a_separator` | passes (guard for the fix) | + +## What else reads these headings + +| Site | Today | Change | +|---|---|---| +| `agent_layers::markdown_entries` (reader) | `:` only | shared parser | +| `merge::identity::heading_entry`, `merge::markdown::identified_title` | dash only for `C` | shared parser for any native prefix | +| `ara-cli` `agent::headings::heading_id` | dash only for `C` | shared parser | +| `write::logic::heading_id` (writes, ID allocation) | splits on `:`/whitespace | none: already returns `E01` for `E01 — X` and `E02 [x]: X` | + +If the reader accepted dashes but merge did not, merge would treat `E01 — X` as +a different entry from the reader's `E01`. All three sites change together. + +## Proposed approach + +### Part 1: shared entry-heading parser + +1. In `ara-core`, generalize `claims::claim_heading` into + `entry_heading(heading, prefix) -> Option<(&str, &str)>` with the same rules: + canonical `{prefix}##` ID, then `:` or a dash (`-`, `–`, `—`) with whitespace + on both sides, then a nonempty title. Keep `claim_heading(h)` as + `entry_heading(h, 'C')` so existing callers are unchanged. +2. `markdown_entries` uses `entry_heading(section.heading, prefix)`. +3. Merge (`heading_entry`, `identified_title`) and the CLI `heading_id` try + `entry_heading` with the prefix the ID starts with (`N C H E O T`). +4. The `malformed entry heading` warning gains the line and heading text + (`logic/experiments.md:12: malformed entry heading `E02 …``), as + `unparsed_claim_headings` already reports for claims. +5. **D1 (decided: accept).** `## E02 [in progress]: Reception` parses as ID + `E02`, title `Reception`. The bracket text is the entry's `status` when it + has no `**Status**` field; a `**Status**` field wins. The heading source is + kept verbatim. Only `entry_heading` callers that read typed entries use the + bracket; claims do not gain bracket syntax. + +### Part 2: optional-layer warnings read through + +6. Split `UNREPRESENTED` by what the warning covers, using its `path`: + - **Optional layer file** (read through): `ARA217`/`ARA218` whose path is + `staging/observations.yaml`, `trace/taste_log.yaml`, `trace/sessions/*`, + `logic/experiments.md`, `logic/solution/heuristics.md`, or + `PAPER.md.knowledge_paths`. + - **Node-scoped** (still refuse): `ARA222`, `ARA226`, and `ARA217` on a + `nodes[…]` path. These change what a tree node says, which is outside + #128. +7. `read_refusal` refuses `incomplete_artifact` only for node-scoped warnings. + Optional-layer warnings no longer refuse. +8. **D2 (decided: explicit marker).** When an optional layer is not fully + represented, `ls`/`show`/`find` results add `"complete": false` and + `"incomplete": [{"path", "codes", "reason"}]`; both are absent otherwise. + Brief text adds one line, `incomplete: staging/observations.yaml (ARA218)`. + `status.complete` keeps its all-or-nothing meaning. +9. `status`: `counts` and `next_ids` are no longer nulled for an optional-layer + warning alone. The next ID for an affected prefix (`E` after a dropped + experiment heading) is null with a `next_id_errors` entry, because the + dropped entry may already hold the next number. +10. `show O01` with two `O01` records (`ARA218`, "all entries retained"): + returns both records. A test pins this. +11. Writes are unchanged. They validate in `ara-core` (`write/source.rs`) and + reject only diagnostics the write introduces; they never called + `read_refusal`. + +## Decisions (2026-10-18) + +**D1. `## E02 [planned]: Title`.** +- (a) **Chosen:** accept it. The ID is `E02`, the title `Title`. The bracket + text becomes the entry's `status` when there is no `**Status**` field, and the + source heading stays verbatim. Writes already accept it. +- (b) Keep refusing, with a clearer message (`status brackets are not + supported; use a **Status** field`). + +**D2. What a structural read returns for partial coverage.** +- (a) **Chosen:** add `"complete": false` and + `"incomplete": [{"path", "codes", "reason"}]` to `ls`/`show`/`find` results + only when something is unrepresented. Brief text adds one line + (`incomplete: staging/observations.yaml (ARA218)`). `status.complete` keeps + its all-or-nothing meaning. +- (b) Rely on the existing `diagnostics.warnings` and add nothing. Smaller, but + an agent must know which codes mean lost data. + +## Implementation steps + +1. Part 1 steps 1–4 with core unit tests for `entry_heading` (all separators, + `E01-x` not split, empty title, wrong prefix) and merge identity tests for a + dash-separated `E`/`H` heading. +2. D1 as decided, with a test. +3. Part 2 steps 6–10. Update `agent_tolerant_reads.rs`: its `ARA217` + observations-shape case becomes a read-through case, and a node-scoped + `ARA226` case keeps refusing. +4. Remove the `#128` reproduction header once all four tests pass. +5. Docs: `docs/agent-cli.md` (refusal table and the `ARA217`… paragraph), + ARA format notes for accepted heading forms. +6. Bump to 0.1.34, `CHANGELOG.md` entries under Fixed/Changed. +7. Rerun the #128 audit ARAs and `nanogpt-speedrun` with `ara ls`; record which + remain refused and why (expected: only the ARA100/105/112 ones). + +## Verification and acceptance + +- `cargo test --workspace` and `cargo clippy --workspace -- -D warnings` pass. +- The four reproduction tests pass. +- A merge test shows a dash-headed `E01` matches the reader's `E01`. +- Step 7: no audited ARA is refused for `ARA217`/`ARA218` alone. diff --git a/plans/agent-cli-interface/README.md b/plans/agent-cli-interface/README.md index 97d5c54..77a2d25 100644 --- a/plans/agent-cli-interface/README.md +++ b/plans/agent-cli-interface/README.md @@ -22,6 +22,7 @@ is separate from historical reproduction, human protocol approval, and experimen | [20](../../docs/agent-cli-interface/20-command-simplification.md) | Approved 2026-10-06; implemented in 0.1.27 as one coordinated command, live-skill, and runner cutover; the completed design replaces the plan | | [21](../../docs/agent-cli-interface/21-reader-round-trips.md) | Approved 2026-10-08; reader-only access guide, Files grounding rule and fewer-requests guidance shipped in 0.1.28 as skill-only changes; conditional `find --show` not implemented; the completed design replaces the plan | | [22](../../docs/agent-cli-interface/22-reader-turn-overhead.md) | Approved 2026-10-14; stray-`---` recovery (0.1.29), one-step reader startup (0.1.30, skill only), partial multi-address `show` with addressed `find` hits and bare entry IDs (0.1.31), and bounded `find` (0.1.32) shipped; paired pilots measured CLI ÷ Files cost 0.94 and time 1.07 at equal accuracy; the completed design replaces the plan | +| [23](23-optional-layer-tolerance.md) | Drafted 2026-10-18 for [#128](https://github.com/ARA-Labs/ara-cli/issues/128): shared dash/bracket entry headings and optional-layer read-through; D1/D2 decided; awaiting plan approval | Plan 18's CLI and skill changes are implemented; its external changes and pilot follow-ups remain separate, so it stays a plan. Plan 18 supersedes the parent plan's default-JSON agent workflow with brief text while retaining programmatic JSON access, and [the command reference](../../docs/agent-cli.md) documents the shipped behavior. Plan 19's CLI sub-PRs are implemented; its repeated skill audit and upstream event-target review remain pending. Mechanical recording does not delegate research judgment to the CLI. From 036aebf56ade559fb8832553e74e8b979cd09d3f Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 18 Oct 2026 22:18:49 -0700 Subject: [PATCH 2/4] fix: read real ARAs despite optional-layer warnings (0.1.34) (#128) Typed experiment and heuristic headings share the claims heading parser (spaced dashes, bracketed status). ARA217/ARA218 warnings about one optional-layer file no longer refuse ls/show/find; results carry complete: false and an incomplete list and exit 1. status keeps counts and withholds only the affected prefix's next ID. Co-Authored-By: Claude --- CHANGELOG.md | 16 ++ Cargo.lock | 8 +- Cargo.toml | 2 +- crates/ara-cli/src/agent.rs | 38 +++- crates/ara-cli/src/agent/documents.rs | 5 +- crates/ara-cli/src/agent/find.rs | 6 +- crates/ara-cli/src/agent/headings.rs | 7 +- crates/ara-cli/src/agent/validity.rs | 123 +++++++++- crates/ara-cli/src/brief/mod.rs | 27 +++ crates/ara-cli/src/output.rs | 1 + crates/ara-cli/tests/agent_layer_tolerance.rs | 210 +++++++++++++++-- crates/ara-cli/tests/agent_tolerant_reads.rs | 18 +- crates/ara-core/src/agent_layers.rs | 155 ++++++++----- crates/ara-core/src/claims.rs | 21 +- crates/ara-core/src/entry_heading.rs | 213 ++++++++++++++++++ crates/ara-core/src/lib.rs | 2 + crates/ara-core/src/merge/identity.rs | 30 ++- crates/ara-core/src/merge/markdown.rs | 26 ++- .../ara-core/tests/merge_markdown_layers.rs | 57 +++++ .../23-optional-layer-tolerance.md | 94 ++++++++ docs/agent-cli-interface/README.md | 1 + docs/agent-cli.md | 58 ++++- docs/stage-1-core-parse-validate.md | 26 ++- .../23-optional-layer-tolerance.md | 149 ------------ plans/agent-cli-interface/README.md | 2 +- skills/compiler-cli/references/cli-access.md | 2 +- skills/research-foresight-cli/SKILL.md | 6 +- .../references/cli-access.md | 2 +- .../references/cli-access.md | 2 +- 29 files changed, 998 insertions(+), 309 deletions(-) create mode 100644 crates/ara-core/src/entry_heading.rs create mode 100644 docs/agent-cli-interface/23-optional-layer-tolerance.md delete mode 100644 plans/agent-cli-interface/23-optional-layer-tolerance.md diff --git a/CHANGELOG.md b/CHANGELOG.md index de5772e..ebbc623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,16 @@ 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: ()` line, and the command exits 1. `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` @@ -260,6 +270,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 diff --git a/Cargo.lock b/Cargo.lock index fc5fb97..61ee662 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,7 +112,7 @@ checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3" [[package]] name = "ara-cli" -version = "0.1.33" +version = "0.1.34" dependencies = [ "ara-core", "arc-swap", @@ -138,7 +138,7 @@ dependencies = [ [[package]] name = "ara-core" -version = "0.1.33" +version = "0.1.34" dependencies = [ "base64", "dagre-dgl-rs", @@ -154,7 +154,7 @@ dependencies = [ [[package]] name = "ara-viewer" -version = "0.1.33" +version = "0.1.34" dependencies = [ "ara-core", "console_error_panic_hook", @@ -172,7 +172,7 @@ dependencies = [ [[package]] name = "ara-wasm" -version = "0.1.33" +version = "0.1.34" [[package]] name = "arc-swap" diff --git a/Cargo.toml b/Cargo.toml index 47967e6..cd13332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/ara-cli/src/agent.rs b/crates/ara-cli/src/agent.rs index 10847e2..5787c0d 100644 --- a/crates/ara-cli/src/agent.rs +++ b/crates/ara-cli/src/agent.rs @@ -560,9 +560,10 @@ pub fn list(root: &Path, args: &ListArgs) -> Result { || 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, _)| { @@ -610,7 +611,10 @@ pub fn list(root: &Path, args: &ListArgs) -> Result { { 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 { if args.identity { @@ -946,8 +950,10 @@ fn show_rows(artifact: &Artifact, args: &ShowArgs, brief: bool) -> Result Result { } 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::::new(); let mut native_ids = BTreeMap::>::from([ ('N', Vec::new()), @@ -1021,7 +1033,7 @@ pub fn status(root: &Path, brief: bool) -> Result { } 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 { @@ -1033,9 +1045,16 @@ pub fn status(root: &Path, brief: bool) -> Result { }; 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) @@ -1056,7 +1075,8 @@ pub fn status(root: &Path, brief: bool) -> Result { .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 diff --git a/crates/ara-cli/src/agent/documents.rs b/crates/ara-cli/src/agent/documents.rs index 0656b32..4361630 100644 --- a/crates/ara-cli/src/agent/documents.rs +++ b/crates/ara-cli/src/agent/documents.rs @@ -347,7 +347,10 @@ pub(super) fn show_document( full: bool, ) -> Result { 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. diff --git a/crates/ara-cli/src/agent/find.rs b/crates/ara-cli/src/agent/find.rs index fcf69f0..367f597 100644 --- a/crates/ara-cli/src/agent/find.rs +++ b/crates/ara-cli/src/agent/find.rs @@ -95,8 +95,10 @@ pub fn find(root: &Path, args: &FindArgs) -> Result { .iter() .map(|hit| results.row(hit, args.cap())) .collect::, _>>()?; - 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)) diff --git a/crates/ara-cli/src/agent/headings.rs b/crates/ara-cli/src/agent/headings.rs index a76a49a..5a133a4 100644 --- a/crates/ara-cli/src/agent/headings.rs +++ b/crates/ara-cli/src/agent/headings.rs @@ -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 diff --git a/crates/ara-cli/src/agent/validity.rs b/crates/ara-cli/src/agent/validity.rs index 8186a24..a3b291b 100644 --- a/crates/ara-cli/src/agent/validity.rs +++ b/crates/ara-cli/src/agent/validity.rs @@ -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}; @@ -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 { + let mut files: Vec<(&str, Vec, 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. @@ -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 { + 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 { let mut codes = Vec::new(); @@ -193,7 +304,8 @@ fn dangling_claim_headings(dangling: &BTreeSet, claims: &str) -> Vec, @@ -215,7 +327,12 @@ pub fn read_refusal( } let unrepresented: Vec = 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)) } diff --git a/crates/ara-cli/src/brief/mod.rs b/crates/ara-cli/src/brief/mod.rs index 23c70b9..bc3446c 100644 --- a/crates/ara-cli/src/brief/mod.rs +++ b/crates/ara-cli/src/brief/mod.rs @@ -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 { + 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<()> { diff --git a/crates/ara-cli/src/output.rs b/crates/ara-cli/src/output.rs index 5def208..0fe3f0b 100644 --- a/crates/ara-cli/src/output.rs +++ b/crates/ara-cli/src/output.rs @@ -126,6 +126,7 @@ pub fn project(value: &mut Value, fields: Option<&str>) -> Result<(), AgentError | "target" | "unresolved_count" | "complete" + | "incomplete" | "diagnostics" | "advisories" | "duplicate_candidates" diff --git a/crates/ara-cli/tests/agent_layer_tolerance.rs b/crates/ara-cli/tests/agent_layer_tolerance.rs index fc579ba..87eb0e8 100644 --- a/crates/ara-cli/tests/agent_layer_tolerance.rs +++ b/crates/ara-cli/tests/agent_layer_tolerance.rs @@ -1,15 +1,15 @@ -//! Reproductions for #128: real ARAs refused over optional agent layers. -//! -//! Typed entries in `logic/experiments.md` and `logic/solution/heuristics.md` -//! should accept the dash separators claims already accept, and a malformed or -//! duplicated optional-layer record should not hide the rest of the artifact -//! from structural reads. +//! Optional-layer tolerance (#128): typed entry headings accept dash +//! separators and a bracketed status, and an `ARA217`/`ARA218` warning about +//! one optional-layer file no longer hides the rest of the artifact. Such a +//! read prints its result, names the file under `incomplete`, and exits 1. use assert_cmd::Command; -use serde_json::Value; +use serde_json::{Value, json}; use std::path::Path; use tempfile::TempDir; const TREE: &str = "tree:\n - id: N01\n type: question\n title: Q\n"; +const DUPLICATE_OBSERVATIONS: &str = + "observations:\n - id: O01\n content: a\n - id: O01\n content: b\n"; fn ara() -> Command { let mut command = Command::cargo_bin("ara").unwrap(); @@ -25,18 +25,28 @@ fn artifact(files: &[(&str, &str)]) -> TempDir { } dir } -fn run(root: &Path, args: &[&str]) -> Value { +/// A JSON read's stdout, asserting its exit code. +fn read(root: &Path, args: &[&str], code: i32) -> Value { let output = ara() .arg("-C") .arg(root) .args(args) .arg("--json") .assert() - .success() + .code(code) .get_output() .clone(); serde_json::from_slice(&output.stdout).unwrap() } +fn run(root: &Path, args: &[&str]) -> Value { + read(root, args, 0) +} +/// A read that went through with an incomplete optional layer. +fn partial(root: &Path, args: &[&str]) -> Value { + let value = read(root, args, 1); + assert_eq!(value["complete"], false, "{value}"); + value +} fn warning_codes(result: &Value) -> Vec { result["diagnostics"]["warnings"] .as_array() @@ -53,6 +63,14 @@ fn entry<'a>(result: &'a Value, id: &str) -> &'a Value { .find(|row| row["id"] == id) .unwrap_or_else(|| panic!("no entry {id} in {result}")) } +fn incomplete_paths(result: &Value) -> Vec<&str> { + result["incomplete"] + .as_array() + .unwrap() + .iter() + .map(|file| file["path"].as_str().unwrap()) + .collect() +} #[test] fn dash_separated_typed_entry_headings_parse() { @@ -71,6 +89,7 @@ fn dash_separated_typed_entry_headings_parse() { ]); let listed = run(dir.path(), &["ls"]); assert_eq!(warning_codes(&listed), Vec::::new(), "{listed}"); + assert!(listed.get("complete").is_none() && listed.get("incomplete").is_none()); for (id, title) in [ ("E01", "Baseline vs. seed (upper bound)"), ("E02", "Hyphen separated"), @@ -78,12 +97,18 @@ fn dash_separated_typed_entry_headings_parse() { ] { assert_eq!(entry(&listed, id)["title"], title, "{id}"); } + // Bare-ID lookup resolves through the shared heading parser too. + let shown = run(dir.path(), &["show", "H03"]); + assert!( + entry(&shown, "H03")["body"] + .as_str() + .unwrap() + .starts_with("## H03 \u{2013} Track") + ); } #[test] fn hyphenated_title_word_is_not_a_separator() { - // `E01-ablation: Title` is not an entry ID; the dash split must need - // whitespace on both sides, exactly as for claims. let dir = artifact(&[ ("trace/exploration_tree.yaml", TREE), ( @@ -96,17 +121,80 @@ fn hyphenated_title_word_is_not_a_separator() { } #[test] -fn duplicate_observation_id_does_not_hide_the_tree() { +fn bracketed_status_is_kept_unless_a_status_field_exists() { let dir = artifact(&[ ("trace/exploration_tree.yaml", TREE), ( - "staging/observations.yaml", - "observations:\n - id: O01\n content: a\n - id: O01\n content: b\n", + "logic/experiments.md", + "# Experiments\n\n\ + ## E02 [in progress]: Reception analysis\n- **Setup**: y\n\n\ + ## E03 [planned] \u{2014} Overridden\n- **Status**: done\n", + ), + ]); + let shown = run(dir.path(), &["show", "E02", "E03"]); + let e02 = entry(&shown, "E02"); + assert_eq!(e02["title"], "Reception analysis"); + assert_eq!(e02["status"], "in progress"); + assert!( + e02["body"] + .as_str() + .unwrap() + .starts_with("## E02 [in progress]: Reception analysis") + ); + let e03 = entry(&shown, "E03"); + assert_eq!(e03["title"], "Overridden"); + assert_eq!(e03["status"], "done"); +} + +#[test] +fn malformed_entry_heading_reads_through_with_its_line() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "logic/experiments.md", + "# Experiments\n\n## E01: Kept\n- **Setup**: x\n\n## E2x: Dropped\n", ), ]); - let shown = run(dir.path(), &["show", "N01"]); + let listed = partial(dir.path(), &["ls"]); + assert_eq!(entry(&listed, "E01")["title"], "Kept"); + assert_eq!(entry(&listed, "N01")["title"], "Q"); + assert_eq!( + listed["incomplete"], + json!([{ + "path": "logic/experiments.md", + "codes": ["ARA217"], + "reason": "malformed entry heading `E2x: Dropped`", + }]) + ); + let warning = &listed["diagnostics"]["warnings"][0]; + assert_eq!(warning["path"], "logic/experiments.md:6"); +} + +#[test] +fn duplicate_observation_id_does_not_hide_the_tree() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ("staging/observations.yaml", DUPLICATE_OBSERVATIONS), + ]); + let shown = partial(dir.path(), &["show", "N01"]); assert_eq!(entry(&shown, "N01")["title"], "Q"); - assert!(warning_codes(&shown).contains(&"ARA218".to_owned()), "{shown}"); + assert!( + warning_codes(&shown).contains(&"ARA218".to_owned()), + "{shown}" + ); + assert_eq!(incomplete_paths(&shown), ["staging/observations.yaml"]); + // Both records stay readable. + let listed = partial(dir.path(), &["ls", "--type", "observation"]); + let contents: Vec<&str> = listed["entries"] + .as_array() + .unwrap() + .iter() + .filter(|row| row["id"] == "O01") + .map(|row| row["content"].as_str().unwrap()) + .collect(); + assert_eq!(contents, ["a", "b"]); + let found = partial(dir.path(), &["find", "Q"]); + assert_eq!(incomplete_paths(&found), ["staging/observations.yaml"]); } #[test] @@ -118,7 +206,93 @@ fn malformed_session_file_does_not_hide_the_tree() { "session:\n id: s1\n id: s1\n", ), ]); - let listed = run(dir.path(), &["ls"]); + let listed = partial(dir.path(), &["ls"]); assert_eq!(entry(&listed, "N01")["title"], "Q"); - assert!(warning_codes(&listed).contains(&"ARA217".to_owned()), "{listed}"); + assert!( + warning_codes(&listed).contains(&"ARA217".to_owned()), + "{listed}" + ); + assert_eq!( + incomplete_paths(&listed), + ["trace/sessions/2026-10-16_001.yaml"] + ); +} + +#[test] +fn non_text_promoted_to_does_not_hide_the_tree() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "staging/observations.yaml", + "observations:\n - id: O01\n content: a\n promoted_to: 3\n", + ), + ]); + let listed = partial(dir.path(), &["ls"]); + assert_eq!(entry(&listed, "O01")["content"], "a"); + assert_eq!(incomplete_paths(&listed), ["staging/observations.yaml"]); +} + +#[test] +fn brief_reads_name_the_incomplete_file() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ("staging/observations.yaml", DUPLICATE_OBSERVATIONS), + ]); + let output = ara() + .arg("-C") + .arg(dir.path()) + .arg("ls") + .assert() + .code(1) + .get_output() + .clone(); + assert!( + String::from_utf8_lossy(&output.stdout).contains("trace/exploration_tree.yaml\tquestion=1") + ); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + stderr.contains("incomplete: staging/observations.yaml (ARA218)"), + "{stderr}" + ); +} + +#[test] +fn status_keeps_counts_and_withholds_only_the_affected_next_id() { + let dir = artifact(&[ + ("trace/exploration_tree.yaml", TREE), + ( + "logic/experiments.md", + "# Experiments\n\n## E01: Kept\n- **Setup**: x\n\n## E2x: Dropped\n", + ), + ]); + let status = read(dir.path(), &["status"], 1); + assert_eq!(status["complete"], false); + assert_eq!(status["counts"]["experiment_plan"], 1); + assert_eq!(status["next_ids"]["N"], "N02"); + assert_eq!(status["next_ids"]["E"], Value::Null); + assert_eq!( + status["next_id_errors"]["E"]["code"], + "next_id.incomplete_layer" + ); + assert_eq!(incomplete_paths(&status), ["logic/experiments.md"]); +} + +#[test] +fn node_annotation_warnings_still_refuse() { + let dir = artifact(&[( + "trace/exploration_tree.yaml", + "tree:\n - id: N01\n type: question\n title: Q\n same_as: 7\n", + )]); + let output = ara() + .arg("-C") + .arg(dir.path()) + .args(["ls", "--json"]) + .assert() + .code(1) + .get_output() + .clone(); + assert!(output.stdout.is_empty()); + let refused: Value = serde_json::from_slice(&output.stderr).unwrap(); + assert_eq!(refused["error"]["code"], "incomplete_artifact"); + assert_eq!(refused["error"]["details"]["blocking"], json!(["ARA222"])); } diff --git a/crates/ara-cli/tests/agent_tolerant_reads.rs b/crates/ara-cli/tests/agent_tolerant_reads.rs index 5554095..d72117c 100644 --- a/crates/ara-cli/tests/agent_tolerant_reads.rs +++ b/crates/ara-cli/tests/agent_tolerant_reads.rs @@ -208,13 +208,23 @@ fn retained_refusals_name_their_blocking_codes() { "ARA100", vec![("trace/exploration_tree.yaml", "tree: not-a-list\n")], ), + // Node-scoped warnings still refuse; optional-layer files read + // through (agent_layer_tolerance.rs). + ( + "incomplete_artifact", + "ARA222", + vec![( + "trace/exploration_tree.yaml", + "tree:\n - id: N01\n type: question\n same_as: 7\n", + )], + ), ( "incomplete_artifact", "ARA217", - vec![ - ("trace/exploration_tree.yaml", q), - ("staging/observations.yaml", "observations: wrong-shape\n"), - ], + vec![( + "trace/exploration_tree.yaml", + "tree:\n - id: N01\n type: pivot\n from: a\n prior_direction: b\n", + )], ), ]; for (error, code, files) in cases { diff --git a/crates/ara-core/src/agent_layers.rs b/crates/ara-core/src/agent_layers.rs index 95bdbf6..de395d0 100644 --- a/crates/ara-core/src/agent_layers.rs +++ b/crates/ara-core/src/agent_layers.rs @@ -233,31 +233,45 @@ pub(crate) fn parse_taste(source: &str, file: &str, report: &mut ParseReport) -> .collect() } +/// One typed Markdown entry: heading parts, exact source and fields. +struct TypedEntry { + id: String, + title: String, + /// Bracketed heading status (`## E02 [planned]: Title`). + status: Option, + body: String, + fields: Vec, +} +impl TypedEntry { + /// The `Status` field, else the bracketed heading status. + fn status(&self) -> Option { + field(&self.fields, &["Status"]).or_else(|| self.status.clone()) + } +} + fn markdown_entries( source: &str, prefix: char, file: &str, report: &mut ParseReport, -) -> Vec<(String, String, String, Vec)> { +) -> Vec { let mut seen = BTreeSet::new(); crate::markdown::document_sections(file, source) .into_iter() .filter_map(|section| { - let Some((id, title)) = section.heading.split_once(':') else { - if looks_like_entry(section.heading, prefix) { - malformed(report, file, "malformed entry heading"); + let Some(heading) = crate::entry_heading::typed_entry_heading(section.heading, prefix) + else { + if looks_like_entry(section.heading.trim_start(), prefix) { + let line = source[..section.range.start].matches('\n').count() + 1; + malformed( + report, + &format!("{file}:{line}"), + format!("malformed entry heading `{}`", section.heading.trim()), + ); } return None; }; - let id = id.trim(); - let title = title.trim(); - if !is_canonical_id(id, prefix) || title.is_empty() { - if looks_like_entry(id, prefix) { - malformed(report, file, "malformed entry heading"); - } - return None; - } - duplicate(id, &mut seen, file, report); + duplicate(heading.id, &mut seen, file, report); let fields = crate::markdown::fields(source, section.body_range) .into_iter() .map(|f| SourceField { @@ -265,12 +279,13 @@ fn markdown_entries( value: crate::markdown::decode_field(&f).into_owned(), }) .collect(); - Some(( - id.to_string(), - title.to_string(), - source[section.range].to_string(), + Some(TypedEntry { + id: heading.id.to_string(), + title: heading.title.to_string(), + status: heading.status.map(str::to_string), + body: source[section.range].to_string(), fields, - )) + }) }) .collect() } @@ -295,19 +310,29 @@ pub(crate) fn parse_heuristics( ) -> Vec { markdown_entries(source, 'H', file, report) .into_iter() - .map(|(id, title, body, fields)| Heuristic { - id: HeuristicId::new(id), - title, - source_file: file.to_string(), - body, - rationale: field(&fields, &["Rationale"]), - sources: field(&fields, &["Sources"]), - status: field(&fields, &["Status"]), - provenance: field(&fields, &["Provenance"]), - sensitivity: field(&fields, &["Sensitivity"]), - code_ref: field(&fields, &["Code ref"]), - last_revised: field(&fields, &["Last revised"]), - source_fields: fields, + .map(|entry| { + let status = entry.status(); + let TypedEntry { + id, + title, + body, + fields, + .. + } = entry; + Heuristic { + id: HeuristicId::new(id), + title, + source_file: file.to_string(), + body, + rationale: field(&fields, &["Rationale"]), + sources: field(&fields, &["Sources"]), + status, + provenance: field(&fields, &["Provenance"]), + sensitivity: field(&fields, &["Sensitivity"]), + code_ref: field(&fields, &["Code ref"]), + last_revised: field(&fields, &["Last revised"]), + source_fields: fields, + } }) .collect() } @@ -318,35 +343,45 @@ pub(crate) fn parse_experiments( ) -> Vec { markdown_entries(source, 'E', file, report) .into_iter() - .map(|(id, title, body, fields)| ExperimentPlan { - id: ExperimentId::new(id), - title, - source_file: file.to_string(), - body, - status: field(&fields, &["Status"]), - evidence_output: field(&fields, &["Evidence output"]), - question: field(&fields, &["Question"]), - setup: field(&fields, &["Setup"]), - prediction: field( - &fields, - &[ - "Prediction", - "Predictions", - "Prediction (directional)", - "Predictions (directional)", - ], - ), - falsification: field( - &fields, - &[ - "Falsification", - "Falsification criteria", - "Falsification condition", - ], - ), - provenance: field(&fields, &["Provenance"]), - last_revised: field(&fields, &["Last revised"]), - source_fields: fields, + .map(|entry| { + let status = entry.status(); + let TypedEntry { + id, + title, + body, + fields, + .. + } = entry; + ExperimentPlan { + id: ExperimentId::new(id), + title, + source_file: file.to_string(), + body, + status, + evidence_output: field(&fields, &["Evidence output"]), + question: field(&fields, &["Question"]), + setup: field(&fields, &["Setup"]), + prediction: field( + &fields, + &[ + "Prediction", + "Predictions", + "Prediction (directional)", + "Predictions (directional)", + ], + ), + falsification: field( + &fields, + &[ + "Falsification", + "Falsification criteria", + "Falsification condition", + ], + ), + provenance: field(&fields, &["Provenance"]), + last_revised: field(&fields, &["Last revised"]), + source_fields: fields, + } }) .collect() } diff --git a/crates/ara-core/src/claims.rs b/crates/ara-core/src/claims.rs index f7a0281..dcf1b30 100644 --- a/crates/ara-core/src/claims.rs +++ b/crates/ara-core/src/claims.rs @@ -90,30 +90,11 @@ pub(crate) fn parse_claims(md: &str) -> ParsedClaims { } } -/// Separators accepted between a claim ID and its title, besides `:`. Each -/// needs whitespace on both sides, so a hyphen inside an ID or a hyphenated -/// word never splits a heading. -const DASH_SEPARATORS: [char; 3] = ['-', '\u{2013}', '\u{2014}']; - /// The `(id, title)` of a level-two claim heading's text: a canonical `C##` /// ID, then `:` or a spaced dash separator, then a nonempty title. Both are /// trimmed slices of `heading`; the source spelling is never rewritten. pub fn claim_heading(heading: &str) -> Option<(&str, &str)> { - if let Some((id, title)) = heading.split_once(':') - && is_canonical_id(id.trim(), 'C') - { - let title = title.trim(); - return (!title.is_empty()).then(|| (id.trim(), title)); - } - let heading = heading.trim_start(); - let id_end = heading.find(char::is_whitespace)?; - let (id, rest) = heading.split_at(id_end); - let rest = rest.trim_start(); - let separator = rest.chars().next()?; - let title = rest[separator.len_utf8()..].strip_prefix(char::is_whitespace)?; - let title = title.trim(); - (is_canonical_id(id, 'C') && DASH_SEPARATORS.contains(&separator) && !title.is_empty()) - .then_some((id, title)) + crate::entry_heading::entry_heading(heading, 'C') } /// Level-two headings of `logic/claims.md` that start like a claim ID diff --git a/crates/ara-core/src/entry_heading.rs b/crates/ara-core/src/entry_heading.rs new file mode 100644 index 0000000..aea2f53 --- /dev/null +++ b/crates/ara-core/src/entry_heading.rs @@ -0,0 +1,213 @@ +//! Typed entry headings shared by the readers, merge identity and CLI lookup. +//! +//! A level-two heading names an entry with a canonical `{prefix}##` ID, a +//! separator and a nonempty title. The separator is `:` or a spaced ASCII +//! hyphen, en dash or em dash (`## E01 — Title`). Typed entries other than +//! claims may also put a bracketed status between the ID and the separator +//! (`## E02 [in progress]: Title`). Every returned part is a trimmed slice of +//! the heading; the source spelling is never rewritten. + +use crate::manifest::is_canonical_id; + +/// Separators accepted between an entry ID and its title, besides `:`. Each +/// needs whitespace on both sides, so a hyphen inside an ID or a hyphenated +/// word never splits a heading. +const DASH_SEPARATORS: [char; 3] = ['-', '\u{2013}', '\u{2014}']; + +/// Prefixes of native entry IDs whose headings may carry a bracketed status. +const BRACKET_PREFIXES: [char; 5] = ['N', 'H', 'E', 'O', 'T']; + +/// The parts of a typed entry heading. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct EntryHeading<'a> { + pub id: &'a str, + pub title: &'a str, + /// Bracketed status text between the ID and the separator, if any. + pub status: Option<&'a str>, +} + +/// The `(id, title)` of `ID: Title` or `ID Title` for `prefix`. +pub fn entry_heading(heading: &str, prefix: char) -> Option<(&str, &str)> { + if let Some((id, title)) = heading.split_once(':') + && is_canonical_id(id.trim(), prefix) + { + let title = title.trim(); + return (!title.is_empty()).then(|| (id.trim(), title)); + } + let heading = heading.trim_start(); + let id_end = heading.find(char::is_whitespace)?; + let (id, rest) = heading.split_at(id_end); + let title = dash_title(rest)?; + is_canonical_id(id, prefix).then_some((id, title)) +} + +/// [`entry_heading`], or `ID [status] Title`. +pub fn typed_entry_heading(heading: &str, prefix: char) -> Option> { + if let Some((id, title)) = entry_heading(heading, prefix) { + return Some(EntryHeading { + id, + title, + status: None, + }); + } + let heading = heading.trim_start(); + let open = heading.find('[')?; + let id = heading[..open].trim_end(); + if !is_canonical_id(id, prefix) { + return None; + } + let (status, rest) = heading[open + 1..].split_once(']')?; + let status = status.trim(); + if status.is_empty() { + return None; + } + let title = match rest.trim_start().strip_prefix(':') { + Some(title) => title.trim(), + None => dash_title(rest)?, + }; + (!title.is_empty()).then_some(EntryHeading { + id, + title, + status: Some(status), + }) +} + +/// A heading for whichever native prefix its ID starts with. Claims (`C`) +/// accept no bracketed status. +pub fn native_entry_heading(heading: &str) -> Option> { + let prefix = heading.trim_start().chars().next()?; + if prefix == 'C' { + return entry_heading(heading, 'C').map(|(id, title)| EntryHeading { + id, + title, + status: None, + }); + } + BRACKET_PREFIXES + .contains(&prefix) + .then(|| typed_entry_heading(heading, prefix)) + .flatten() +} + +/// The title after a spaced dash: `rest` is whitespace, a dash separator, +/// whitespace, then a nonempty title. +fn dash_title(rest: &str) -> Option<&str> { + let rest = rest.strip_prefix(char::is_whitespace)?.trim_start(); + let separator = rest.chars().next()?; + if !DASH_SEPARATORS.contains(&separator) { + return None; + } + let title = rest[separator.len_utf8()..] + .strip_prefix(char::is_whitespace)? + .trim(); + (!title.is_empty()).then_some(title) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn every_separator_parses_for_any_prefix() { + for (heading, prefix, id, title) in [ + ("E01: Colon", 'E', "E01", "Colon"), + ("E01 : Spaced colon", 'E', "E01", "Spaced colon"), + ("E01 - Hyphen", 'E', "E01", "Hyphen"), + ("H03 \u{2013} En dash", 'H', "H03", "En dash"), + ( + "E01 \u{2014} Baseline vs. seed (upper bound)", + 'E', + "E01", + "Baseline vs. seed (upper bound)", + ), + ("E01: Two-stage - warmup", 'E', "E01", "Two-stage - warmup"), + ("C01 \u{2014} Claim", 'C', "C01", "Claim"), + ] { + assert_eq!( + entry_heading(heading, prefix), + Some((id, title)), + "{heading:?}" + ); + } + } + + #[test] + fn unspaced_dashes_wrong_prefixes_and_empty_titles_do_not_parse() { + for heading in [ + "E01-Title", + "E01 -Title", + "E01- Title", + "E01\u{2014}Title", + "E01 - ", + "E01:", + "E01 -- Title", + "e01 - Title", + "H01 - Title", + "E01-ablation: Title", + "Experiments overview", + ] { + assert_eq!(entry_heading(heading, 'E'), None, "{heading:?}"); + assert_eq!(typed_entry_heading(heading, 'E'), None, "{heading:?}"); + } + } + + #[test] + fn bracketed_status_precedes_the_separator() { + for (heading, title, status) in [ + ( + "E02 [in progress]: Reception analysis", + "Reception analysis", + "in progress", + ), + ("E02 [planned] \u{2014} Dash", "Dash", "planned"), + ("E02[done]: Unspaced", "Unspaced", "done"), + ] { + assert_eq!( + typed_entry_heading(heading, 'E'), + Some(EntryHeading { + id: "E02", + title, + status: Some(status) + }), + "{heading:?}" + ); + } + for heading in [ + "E02 []: Empty", + "E02 [x]", + "E02 [x]:", + "E02 [x] Title", + "E02 [x: Title", + ] { + assert_eq!(typed_entry_heading(heading, 'E'), None, "{heading:?}"); + } + // A bracket in the title is title text, not a status. + assert_eq!( + typed_entry_heading("E01: Title [draft]", 'E'), + Some(EntryHeading { + id: "E01", + title: "Title [draft]", + status: None + }) + ); + } + + #[test] + fn native_headings_pick_their_prefix_and_claims_take_no_status() { + assert_eq!( + native_entry_heading("H03 \u{2013} Track").map(|h| h.id), + Some("H03") + ); + assert_eq!( + native_entry_heading("E02 [x]: T").map(|h| h.id), + Some("E02") + ); + assert_eq!( + native_entry_heading("C01 - Claim").map(|h| h.id), + Some("C01") + ); + assert_eq!(native_entry_heading("C01 [x]: Claim"), None); + assert_eq!(native_entry_heading("RW01: Related"), None); + assert_eq!(native_entry_heading("Overview"), None); + } +} diff --git a/crates/ara-core/src/lib.rs b/crates/ara-core/src/lib.rs index 00c713e..c095892 100644 --- a/crates/ara-core/src/lib.rs +++ b/crates/ara-core/src/lib.rs @@ -9,6 +9,7 @@ //! See . mod claims; +mod entry_heading; pub mod figure; mod flat_yaml; pub mod layout; @@ -42,6 +43,7 @@ mod sections; pub mod write; pub use claims::{claim_heading, fenced_claim_headings, unparsed_claim_headings}; +pub use entry_heading::{EntryHeading, entry_heading, native_entry_heading, typed_entry_heading}; pub use layout::{LayoutOptions, LayoutResult, NodePosition, Point, Rect}; pub use manifest::{ Binding, BindingRole, BuiltOn, Claim, ClaimId, Concept, Exhibit, ExhibitKind, ExperimentId, diff --git a/crates/ara-core/src/merge/identity.rs b/crates/ara-core/src/merge/identity.rs index 699268a..58de907 100644 --- a/crates/ara-core/src/merge/identity.rs +++ b/crates/ara-core/src/merge/identity.rs @@ -1671,12 +1671,12 @@ pub(crate) fn reference_namespaces( } Ok(()) } -/// The entry ID prefix a heading literal names: a claim heading's ID under -/// any native separator (`:` or a spaced dash), else the text before `:`. -/// The result is always a prefix slice of `heading`. +/// The entry ID prefix a heading literal names: a native entry heading's ID +/// under any separator (`:`, a spaced dash, or a bracketed status first), +/// else the text before `:`. The result is always a prefix slice of `heading`. pub(crate) fn heading_entry(heading: &str) -> &str { - crate::claims::claim_heading(heading) - .map(|(id, _)| id) + crate::entry_heading::native_entry_heading(heading) + .map(|entry| entry.id) .filter(|id| heading.starts_with(id)) .unwrap_or_else(|| heading.split_once(':').map_or(heading, |(id, _)| id)) } @@ -1845,3 +1845,23 @@ mod native_record_decode_tests { } } } + +#[cfg(test)] +mod tests { + use super::heading_entry; + + #[test] + fn heading_entries_follow_the_shared_entry_heading_parser() { + for (heading, entry) in [ + ("C01 \u{2014} Claim", "C01"), + ("E01 \u{2014} Baseline vs. seed", "E01"), + ("H03 \u{2013} Track", "H03"), + ("E02 [in progress]: Reception", "E02"), + ("E01: Colon", "E01"), + ("Overview: notes", "Overview"), + ("Plain heading", "Plain heading"), + ] { + assert_eq!(heading_entry(heading), entry, "{heading:?}"); + } + } +} diff --git a/crates/ara-core/src/merge/markdown.rs b/crates/ara-core/src/merge/markdown.rs index c7e2495..8235efb 100644 --- a/crates/ara-core/src/merge/markdown.rs +++ b/crates/ara-core/src/merge/markdown.rs @@ -201,17 +201,18 @@ pub(crate) fn selector_key(selector: &EntrySelector) -> Option { } } } -/// The title of an identified heading, split as the claims parser splits a -/// claim heading (`:` or a spaced dash), else after the first `:`. +/// The title of an identified heading, split as the readers split a native +/// entry heading (`:`, a spaced dash, or a bracketed status first), else after +/// the first `:`. fn identified_title(heading: &str) -> &str { - crate::claims::claim_heading(heading).map_or_else( + crate::entry_heading::native_entry_heading(heading).map_or_else( || { heading .split_once(':') .map_or(heading, |(_, title)| title) .trim() }, - |(_, title)| title, + |entry| entry.title, ) } fn rw_id(heading: &str) -> Option<&str> { @@ -1902,3 +1903,20 @@ mod selector_tests { ); } } + +#[cfg(test)] +mod tests { + use super::identified_title; + + #[test] + fn identified_titles_follow_the_shared_entry_heading_parser() { + for (heading, title) in [ + ("C01 \u{2014} Speedup: fast", "Speedup: fast"), + ("E01 \u{2014} Baseline", "Baseline"), + ("E02 [planned]: Reception", "Reception"), + ("Overview: notes", "notes"), + ] { + assert_eq!(identified_title(heading), title, "{heading:?}"); + } + } +} diff --git a/crates/ara-core/tests/merge_markdown_layers.rs b/crates/ara-core/tests/merge_markdown_layers.rs index 5d862a3..04cf934 100644 --- a/crates/ara-core/tests/merge_markdown_layers.rs +++ b/crates/ara-core/tests/merge_markdown_layers.rs @@ -1083,3 +1083,60 @@ fn dash_claim_titles_with_colons_keep_concurrent_edits_visible() { assert!(merged.report.conflicts.is_empty()); assert_eq!(merged.working.text(CLAIMS).unwrap(), theirs); } + +/// The merge of base/ours/theirs typed-entry documents, plus its conflicts. +fn merged_entries(path: &str, base: &str, ours: &str, theirs: &str) -> (String, usize) { + let merged = plan( + &snapshot(&[(path, base)]), + &snapshot(&[(path, ours)]), + &snapshot(&[(path, theirs)]), + ); + ( + merged.working.text(path).unwrap().to_owned(), + merged.report.conflicts.len(), + ) +} + +#[test] +fn dash_and_bracket_typed_headings_merge_like_colon_headings() { + // #128: merge identifies typed entries as the reader does. Concurrent + // additions of the same numeric ID renumber the incoming entry, and a + // title edit merges with a field edit, whatever the heading separator. + for (path, prefix, open, separator) in [ + ("logic/experiments.md", "E", "", " \u{2014} "), + ("logic/experiments.md", "E", " [planned]", ": "), + ("logic/solution/heuristics.md", "H", "", " \u{2013} "), + ] { + let doc = |separator: &str, entries: &[(&str, &str)]| { + let mut text = String::from("# Entries\n\n"); + for (id, title) in entries { + text.push_str(&format!( + "## {prefix}{id}{separator}{title}\n- **Rationale**: {title}\n\n" + )); + } + text + }; + let heading = format!("{open}{separator}"); + let base = [("01", "Base")]; + let ours = [("01", "Base renamed"), ("02", "Ours")]; + let theirs = [("01", "Base"), ("02", "Theirs")]; + let colon = merged_entries( + path, + &doc(": ", &base), + &doc(": ", &ours), + &doc(": ", &theirs), + ); + let other = merged_entries( + path, + &doc(&heading, &base), + &doc(&heading, &ours), + &doc(&heading, &theirs), + ); + assert_eq!( + other.0.replace(&heading, ": "), + colon.0, + "{prefix}{heading:?}" + ); + assert_eq!(other.1, colon.1, "{prefix}{heading:?}"); + } +} diff --git a/docs/agent-cli-interface/23-optional-layer-tolerance.md b/docs/agent-cli-interface/23-optional-layer-tolerance.md new file mode 100644 index 0000000..eee60d2 --- /dev/null +++ b/docs/agent-cli-interface/23-optional-layer-tolerance.md @@ -0,0 +1,94 @@ +# 23: read real ARAs despite optional-layer warnings + +Shipped in workspace 0.1.34 for [#128](https://github.com/ARA-Labs/ara-cli/issues/128). +Command behavior is documented in [agent-cli.md](../agent-cli.md#incomplete-optional-layers); +heading rules in [stage-1](../stage-1-core-parse-validate.md#entry-headings). + +## Problem + +`ara` 0.1.33 refused `ls`, `show` and `find` on every research ARA over 40 +nodes in the #128 audit, and on `ara-paperbench/nanogpt-speedrun`, although +plain file reads worked. The agent-CLI scaling evaluation (E2) pads benchmarks +with these ARAs, so its CLI condition measured refusals. Two causes concerned +only optional agent layers: + +- `markdown_entries` split experiment and heuristic headings on the first `:` + only. `## E01 — Baseline` dropped the entry and warned `ARA217`, while claims + already accepted spaced dashes. +- `validity::read_refusal` turned any `ARA217`/`ARA218` warning into an + `incomplete_artifact` refusal of every structural read. One duplicate + observation ID hid a 900-entry tree. + +`ARA100`, `ARA105` and `ARA112` in the same audit are real record errors and +keep refusing. + +## Design + +### One entry-heading parser + +`ara_core::entry_heading(heading, prefix)` accepts a canonical `{prefix}##` +ID, then `:` or a dash (`-`, U+2013, U+2014) with whitespace on both sides, +then a nonempty title. `claim_heading` is its `C` case. +`typed_entry_heading` also accepts a bracketed status before the separator +(`## E02 [in progress]: Title`); the reader stores it as the entry's `status` +unless a `**Status**` field exists. Claims take no bracket. +`native_entry_heading` picks the prefix from the heading's first character. + +The reader (`markdown_entries`), merge identity (`heading_entry`, +`identified_title`) and the CLI heading lookup (`agent::headings::heading_id`) +all use it, so no layer sees an ID the others do not. Writes needed no change: +`write::logic::heading_id` splits on `:` or whitespace and already returned +`E01` for both new forms, and merge's entry inventory comes from the same +reader. A heading that starts like an entry ID but does not parse still drops +the entry; its `ARA217` now carries `path:line` and the heading text. + +### Optional layers read through + +`validity::optional_layer` classifies an `ARA217`/`ARA218` warning by its path +(without `:line`): `staging/observations.yaml`, `trace/taste_log.yaml`, +`trace/sessions/*`, `logic/experiments.md`, `logic/solution/heuristics.md` and +`PAPER.md.knowledge_paths`. These no longer refuse. Node-scoped warnings +(`ARA222`, `ARA226`, `ARA217` on `nodes[…]`) still refuse, because they change +what a tree node says. + +`validity::with_coverage` adds `complete: false` and +`incomplete: [{path, codes, reason}]` to `ls`, `show`, `find` and `status` +results when any optional-layer file is affected, and nothing otherwise. Brief +text prints `incomplete: ()` after the diagnostics summary. + +The command exits 1. The existing contract says incomplete source +representation is never reported as success, and `complete: false` already +mapped to exit 1. Partial multi-address `show` made the same trade-off +([plan 22](22-reader-turn-overhead.md)): output on stdout, a countable +non-zero exit. The shared skill access guide and the reader skill now say that +an exit-1 read with `incomplete` carries valid results. + +`status` keeps `complete` all-or-nothing, but `counts` and `next_ids` stay +available unless an error or node-scoped warning exists. The next ID of an +affected prefix (`O`, `T`, `E`, `H`) is null with `next_id.incomplete_layer`, +because a dropped entry may already hold that number. Writes validate in +`ara-core` and never used `read_refusal`, so they are unchanged. + +## Verification + +- `crates/ara-cli/tests/agent_layer_tolerance.rs`: the three #128 + reproductions (failing on 0.1.33), bracket status, line-numbered warnings, + duplicate records, non-text `promoted_to`, brief output, `status`, and a + node-scoped refusal. +- `agent_tolerant_reads.rs`: the old observations-shape refusal case became + node-scoped `ARA222` and pivot `ARA217` refusal cases. +- `entry_heading` unit tests; merge helper unit tests; a merge test showing + dash and bracket headings merge exactly like colon headings. That merge test + also passes on 0.1.33, because merge identity already came from the reader + and write heading lookups; it guards the shared behavior. +- Local real-ARA rerun, 0.1.33 → 0.1.34 (`ara ls --json`): + +| ARA | 0.1.33 | 0.1.34 | +|---|---|---| +| `ara-paperbench/.../nanogpt-speedrun` | `incomplete_artifact` ARA217 | readable, exit 0 | +| `Lara/ara` | `incomplete_artifact` ARA217, ARA218 | readable; `staging/observations.yaml` incomplete | +| `DissClaimer/ara`, `MSI/ara` | `invalid_artifact` ARA100 | unchanged (out of scope) | +| `mandate/ara`, `mandate-eval/ara` | `invalid_artifact` ARA105 | unchanged (out of scope) | +| `rsi-bench`, `rsi-chip-bench`, `sierra` | readable | readable | + +The four other ARAs from the #128 audit were not available locally. diff --git a/docs/agent-cli-interface/README.md b/docs/agent-cli-interface/README.md index 189ce2e..8fc9786 100644 --- a/docs/agent-cli-interface/README.md +++ b/docs/agent-cli-interface/README.md @@ -23,6 +23,7 @@ verification report for the current evidence. - [20-command-simplification](./20-command-simplification.md) - [21-reader-round-trips](./21-reader-round-trips.md) - [22-reader-turn-overhead](./22-reader-turn-overhead.md) +- [23-optional-layer-tolerance](./23-optional-layer-tolerance.md) Plan 15 is deferred. Conditional 16/17 are closed for this delivery because their experiment evidence gates have not fired; no implementation is claimed. diff --git a/docs/agent-cli.md b/docs/agent-cli.md index 500e597..9fabd0f 100644 --- a/docs/agent-cli.md +++ b/docs/agent-cli.md @@ -40,7 +40,7 @@ ara -C ./ara find 'failure boundary' --limit 10 --full --json | Command | Behavior | Brief default text | |---|---|---| -| `status` | Layer counts, diagnostics and advisory next IDs | Counts and next IDs only when complete; error and warning counts with rule codes | +| `status` | Layer counts, diagnostics and advisory next IDs | Counts and next IDs unless an error or node-scoped warning exists; error and warning counts with rule codes | | `ls` | Source-order entries; intersecting type, subtree, date, status and provenance filters | No arguments: one line per knowledge document with entry counts by kind (or heading count) and line count, then the direct-file roots. `ls `: that document's entries, or its heading addresses when it has none. Filters: matching entries | | `show` | Entry projection, relations via `--with`, full body or bounded native document; `--lines A:B` windows and `--max-bytes` budgets | One labeled block per selection: native source with its `source_digest`, or a projection without a digest; 16 KiB budget, paged at whole lines | | `show --with path` | Root-to-node nesting, with cross-edges kept distinct | Root-to-node IDs, indented by depth | @@ -55,8 +55,9 @@ and applicable ID, line or details. Exit 0 means completion, exit 1 means a semantic rejection or unresolved merge, and exit 2 means setup, argument, I/O or lock failure. `--fields` projects supported fields while retaining transaction/result identity. A multi-address `show` in which some -addresses fail is the one partial result: it prints on stdout and exits 1 -([partial reads](#partial-multi-address-reads)). JSON excerpts are bounded to 160 Unicode +addresses fail is a partial result: it prints on stdout and exits 1 +([partial reads](#partial-multi-address-reads)). A read over an incomplete +optional layer does the same ([below](#incomplete-optional-layers)). JSON excerpts are bounded to 160 Unicode characters; `--full` retains source content. Incomplete source representation must not be reported as success. @@ -575,15 +576,46 @@ fence, and conservatively a claim title such as `## C02: Extends C01` all count). Dangling dependency IDs come from the parsed claims; an `ARA107` or `ARA109` whose claim ID cannot be identified also refuses. A dropped claim produces the same `ARA107` as a dangling reference, so this parse loss still refuses with `invalid_artifact` and `details.unrepresented` (`path:line: -reason`). `ARA217`, `ARA218`, `ARA222` and `ARA226` warnings still refuse with -`incomplete_artifact`, and I/O issues still fail as I/O errors. A refusal +reason`). Node-scoped warnings (`ARA222`, `ARA226`, and `ARA217` on a +`nodes[…]` path) still refuse with `incomplete_artifact`, and I/O issues still +fail as I/O errors. A refusal (`invalid_artifact` or `incomplete_artifact`) has `details.blocking` (the refusing rule codes) and `details.hint` (run `ara check`; source reads still work). Relationship reads never invent a missing target: `show --with claims,depends_on` omits it and `show --with refs`/`show` on the missing ID return `unknown_id`. `status` is unchanged: `complete` is false, and counts and next IDs are null, whenever any error exists. `check` and `validate` still fail on -these errors. Write commands do not use this tolerance; `apply` refuses +these errors. + +### Incomplete optional layers + +An `ARA217` or `ARA218` warning about one optional-layer file does not refuse +structural reads (#128). The files are `staging/observations.yaml`, +`trace/taste_log.yaml`, `trace/sessions/*` (records and index), +`logic/experiments.md`, `logic/solution/heuristics.md`, and the PAPER +`knowledge_paths` registry (`PAPER.md.knowledge_paths`; an invalid registry +leaves the registered documents unloaded). A malformed session file, a +non-text observation field, a duplicate observation ID or a dropped +experiment heading therefore no longer hides the tree, claims and the +other layers. `ls`, `show` and `find` print their result and add: + +```json +"complete": false, +"incomplete": [{"path": "staging/observations.yaml", "codes": ["ARA218"], + "reason": "duplicate layer id `O01`; all entries retained"}] +``` + +`reason` joins the first line of each distinct message for that file. Both +fields are absent when every layer was represented. Brief text adds one +`incomplete: ()` line on stderr after the diagnostics summary. +The command exits 1, because incomplete source representation is not reported +as success. Duplicate records stay readable: `ls --type observation` lists +both `O01` rows. `status` keeps `complete: false` with the same `incomplete` +list, but its `counts` and `next_ids` stay available; only the next ID of an +affected prefix (`O`, `T`, `E`, `H`) is null, with a `next_id_errors` entry +coded `next_id.incomplete_layer`, because a dropped entry may already hold +that number. Writes are unaffected: they validate in `ara-core` and reject only +diagnostics the write itself introduces. Write commands do not use this tolerance; `apply` refuses any validation error. Explicit `--source` reads keep `artifact_validation: "not_run"`, which does not mean the artifact is valid. @@ -608,10 +640,16 @@ that removes the fence is accepted, but claim retention counts the recovered claims: a repair that drops one fails with `write.claim_retention` like any other edit that retires a canonical claim. -Claim headings accept `:` and a spaced `-`, U+2013 or U+2014 separator -(`## C04 — Title`). `show C04`, `--heading C04`, `show --with refs` and merge titles -resolve them, source bytes keep the original spelling, and `ara check` does -not report them (`ARA004` covers only unspaced dashes). +Claim, experiment and heuristic headings accept `:` and a spaced `-`, U+2013 +or U+2014 separator (`## C04 — Title`, `## E01 — Title`, `## H03 – Title`). +Experiment and heuristic headings may also put a bracketed status before the +separator (`## E02 [in progress]: Title`); it becomes the entry's `status` +unless a `**Status**` field is present. `show C04`, `--heading C04`, `show +--with refs` and merge titles resolve them through one shared parser +(`ara_core::entry_heading`), source bytes keep the original spelling, and +`ara check` does not report them (`ARA004` covers only unspaced claim +dashes). Any other heading that starts like an entry ID (`## E2x: Title`) +drops the entry and warns `ARA217` at `path:line` with the heading text. ## Authoring commands and source inputs diff --git a/docs/stage-1-core-parse-validate.md b/docs/stage-1-core-parse-validate.md index 576847c..b69ea1b 100644 --- a/docs/stage-1-core-parse-validate.md +++ b/docs/stage-1-core-parse-validate.md @@ -188,13 +188,19 @@ file-watching (Stage 4); `E##` evidence resolution (`T-EVIDENCE`); the real- corpus schema widening and `ara-2.0` support (`T-REAL-CORPUS`); adopting an upstream schema (`T-ARA-SCHEMA`). -## Claim headings - -A level-two heading is a claim when it is a canonical `C##` ID, then `:` or -a dash separator (`-`, U+2013 or U+2014) with whitespace on both sides, then a -nonempty title (`ara_core::claim_heading`). `C01-Title`, `C01 -Title` and -hyphens inside IDs or prose never split a heading. Source bytes, including the -claim's `body`, keep the original spelling; duplicate IDs stay errors whatever -the separator. These spellings are native, so `ara check` does not report -them; `ARA004` repairs only unspaced or half-spaced dashes, whose claims are -dropped. Merge reads claim titles with the same split. +## Entry headings + +A level-two heading is a claim, experiment or heuristic entry when it is a +canonical `C##`, `E##` or `H##` ID, then `:` or a dash separator (`-`, U+2013 +or U+2014) with whitespace on both sides, then a nonempty title +(`ara_core::entry_heading`; `claim_heading` is its `C` case). `C01-Title`, +`C01 -Title` and hyphens inside IDs or prose never split a heading. +Experiment and heuristic headings may also carry a bracketed status between +the ID and the separator (`## E02 [planned]: Title`, +`ara_core::typed_entry_heading`); a `**Status**` field takes precedence over +it. Claims accept no bracket. Source bytes, including the entry's `body`, keep +the original spelling; duplicate IDs stay diagnostics whatever the separator. +These spellings are native, so `ara check` does not report them; `ARA004` +repairs only unspaced or half-spaced claim dashes, whose claims are dropped. +Merge identity (`heading_entry`, `identified_title`) and the CLI heading lookup +use the same parser (`ara_core::native_entry_heading`). diff --git a/plans/agent-cli-interface/23-optional-layer-tolerance.md b/plans/agent-cli-interface/23-optional-layer-tolerance.md deleted file mode 100644 index a4fac47..0000000 --- a/plans/agent-cli-interface/23-optional-layer-tolerance.md +++ /dev/null @@ -1,149 +0,0 @@ -# PR 23: read real ARAs despite optional-layer warnings (#128) -**Date:** 2026-10-18 - -Status: **draft, awaiting review**; D1 and D2 decided 2026-10-18 (both option a). Issue: [#128](https://github.com/ARA-Labs/ara-cli/issues/128). -Branch: `fix/128-readable-real-aras`, targeting `feat/agent-cli-interface`. -Parent: [agent CLI interface](../agent-cli-interface.md). Shared checks: [PR index](README.md). - -## TL;DR - -Two changes. (1) Typed entries in `logic/experiments.md` and -`logic/solution/heuristics.md` accept the same `ID: Title`, `ID — Title`, -`ID – Title` and `ID - Title` headings that claims already accept, through one -shared parser that the reader, merge identity and CLI heading lookup all use. -(2) An `ARA217`/`ARA218` warning about one optional-layer file stops refusing -every structural read. Reads go ahead and say which files were not fully -represented. Writes keep their existing validation. - -## Problem - -`ara` 0.1.33 refuses `ls`, `show` and `find` on every real research ARA over 40 -nodes in the #128 audit, and on `ara-paperbench/nanogpt-speedrun`. Plain file -reads work. Two causes concern only optional agent layers: - -- **Entry headings.** `markdown_entries` (`crates/ara-core/src/agent_layers.rs`) - splits on the first `:` only. `## E01 — Baseline` and `## H03 – Track …` drop - the entry and warn `ARA217 malformed entry heading` (with no line number). - `claims::claim_heading` already accepts spaced dashes, but only for `C` IDs. -- **All-or-nothing refusal.** `validity::read_refusal` turns any `ARA217`, - `ARA218`, `ARA222` or `ARA226` warning into `incomplete_artifact` for all - structural reads. One duplicate observation ID or one session file with a - duplicate YAML key hides a valid 500-node tree, its claims and experiments. - -The agent-CLI evaluation E2 pads benchmarks with these ARAs, so today the CLI -condition measures refusals, not efficiency. - -Out of scope: `ARA100`, `ARA105`, `ARA112` in the audit. They are real record -errors and keep refusing with `invalid_artifact`. - -### Reproduction - -`crates/ara-cli/tests/agent_layer_tolerance.rs` (new). On 0.1.33: - -| Test | Result | -|---|---| -| `dash_separated_typed_entry_headings_parse` | fails: `incomplete_artifact`, `ARA217`×3 | -| `duplicate_observation_id_does_not_hide_the_tree` | fails: `incomplete_artifact`, `ARA218` | -| `malformed_session_file_does_not_hide_the_tree` | fails: `incomplete_artifact`, `ARA217` | -| `hyphenated_title_word_is_not_a_separator` | passes (guard for the fix) | - -## What else reads these headings - -| Site | Today | Change | -|---|---|---| -| `agent_layers::markdown_entries` (reader) | `:` only | shared parser | -| `merge::identity::heading_entry`, `merge::markdown::identified_title` | dash only for `C` | shared parser for any native prefix | -| `ara-cli` `agent::headings::heading_id` | dash only for `C` | shared parser | -| `write::logic::heading_id` (writes, ID allocation) | splits on `:`/whitespace | none: already returns `E01` for `E01 — X` and `E02 [x]: X` | - -If the reader accepted dashes but merge did not, merge would treat `E01 — X` as -a different entry from the reader's `E01`. All three sites change together. - -## Proposed approach - -### Part 1: shared entry-heading parser - -1. In `ara-core`, generalize `claims::claim_heading` into - `entry_heading(heading, prefix) -> Option<(&str, &str)>` with the same rules: - canonical `{prefix}##` ID, then `:` or a dash (`-`, `–`, `—`) with whitespace - on both sides, then a nonempty title. Keep `claim_heading(h)` as - `entry_heading(h, 'C')` so existing callers are unchanged. -2. `markdown_entries` uses `entry_heading(section.heading, prefix)`. -3. Merge (`heading_entry`, `identified_title`) and the CLI `heading_id` try - `entry_heading` with the prefix the ID starts with (`N C H E O T`). -4. The `malformed entry heading` warning gains the line and heading text - (`logic/experiments.md:12: malformed entry heading `E02 …``), as - `unparsed_claim_headings` already reports for claims. -5. **D1 (decided: accept).** `## E02 [in progress]: Reception` parses as ID - `E02`, title `Reception`. The bracket text is the entry's `status` when it - has no `**Status**` field; a `**Status**` field wins. The heading source is - kept verbatim. Only `entry_heading` callers that read typed entries use the - bracket; claims do not gain bracket syntax. - -### Part 2: optional-layer warnings read through - -6. Split `UNREPRESENTED` by what the warning covers, using its `path`: - - **Optional layer file** (read through): `ARA217`/`ARA218` whose path is - `staging/observations.yaml`, `trace/taste_log.yaml`, `trace/sessions/*`, - `logic/experiments.md`, `logic/solution/heuristics.md`, or - `PAPER.md.knowledge_paths`. - - **Node-scoped** (still refuse): `ARA222`, `ARA226`, and `ARA217` on a - `nodes[…]` path. These change what a tree node says, which is outside - #128. -7. `read_refusal` refuses `incomplete_artifact` only for node-scoped warnings. - Optional-layer warnings no longer refuse. -8. **D2 (decided: explicit marker).** When an optional layer is not fully - represented, `ls`/`show`/`find` results add `"complete": false` and - `"incomplete": [{"path", "codes", "reason"}]`; both are absent otherwise. - Brief text adds one line, `incomplete: staging/observations.yaml (ARA218)`. - `status.complete` keeps its all-or-nothing meaning. -9. `status`: `counts` and `next_ids` are no longer nulled for an optional-layer - warning alone. The next ID for an affected prefix (`E` after a dropped - experiment heading) is null with a `next_id_errors` entry, because the - dropped entry may already hold the next number. -10. `show O01` with two `O01` records (`ARA218`, "all entries retained"): - returns both records. A test pins this. -11. Writes are unchanged. They validate in `ara-core` (`write/source.rs`) and - reject only diagnostics the write introduces; they never called - `read_refusal`. - -## Decisions (2026-10-18) - -**D1. `## E02 [planned]: Title`.** -- (a) **Chosen:** accept it. The ID is `E02`, the title `Title`. The bracket - text becomes the entry's `status` when there is no `**Status**` field, and the - source heading stays verbatim. Writes already accept it. -- (b) Keep refusing, with a clearer message (`status brackets are not - supported; use a **Status** field`). - -**D2. What a structural read returns for partial coverage.** -- (a) **Chosen:** add `"complete": false` and - `"incomplete": [{"path", "codes", "reason"}]` to `ls`/`show`/`find` results - only when something is unrepresented. Brief text adds one line - (`incomplete: staging/observations.yaml (ARA218)`). `status.complete` keeps - its all-or-nothing meaning. -- (b) Rely on the existing `diagnostics.warnings` and add nothing. Smaller, but - an agent must know which codes mean lost data. - -## Implementation steps - -1. Part 1 steps 1–4 with core unit tests for `entry_heading` (all separators, - `E01-x` not split, empty title, wrong prefix) and merge identity tests for a - dash-separated `E`/`H` heading. -2. D1 as decided, with a test. -3. Part 2 steps 6–10. Update `agent_tolerant_reads.rs`: its `ARA217` - observations-shape case becomes a read-through case, and a node-scoped - `ARA226` case keeps refusing. -4. Remove the `#128` reproduction header once all four tests pass. -5. Docs: `docs/agent-cli.md` (refusal table and the `ARA217`… paragraph), - ARA format notes for accepted heading forms. -6. Bump to 0.1.34, `CHANGELOG.md` entries under Fixed/Changed. -7. Rerun the #128 audit ARAs and `nanogpt-speedrun` with `ara ls`; record which - remain refused and why (expected: only the ARA100/105/112 ones). - -## Verification and acceptance - -- `cargo test --workspace` and `cargo clippy --workspace -- -D warnings` pass. -- The four reproduction tests pass. -- A merge test shows a dash-headed `E01` matches the reader's `E01`. -- Step 7: no audited ARA is refused for `ARA217`/`ARA218` alone. diff --git a/plans/agent-cli-interface/README.md b/plans/agent-cli-interface/README.md index 77a2d25..b8c7d08 100644 --- a/plans/agent-cli-interface/README.md +++ b/plans/agent-cli-interface/README.md @@ -22,7 +22,7 @@ is separate from historical reproduction, human protocol approval, and experimen | [20](../../docs/agent-cli-interface/20-command-simplification.md) | Approved 2026-10-06; implemented in 0.1.27 as one coordinated command, live-skill, and runner cutover; the completed design replaces the plan | | [21](../../docs/agent-cli-interface/21-reader-round-trips.md) | Approved 2026-10-08; reader-only access guide, Files grounding rule and fewer-requests guidance shipped in 0.1.28 as skill-only changes; conditional `find --show` not implemented; the completed design replaces the plan | | [22](../../docs/agent-cli-interface/22-reader-turn-overhead.md) | Approved 2026-10-14; stray-`---` recovery (0.1.29), one-step reader startup (0.1.30, skill only), partial multi-address `show` with addressed `find` hits and bare entry IDs (0.1.31), and bounded `find` (0.1.32) shipped; paired pilots measured CLI ÷ Files cost 0.94 and time 1.07 at equal accuracy; the completed design replaces the plan | -| [23](23-optional-layer-tolerance.md) | Drafted 2026-10-18 for [#128](https://github.com/ARA-Labs/ara-cli/issues/128): shared dash/bracket entry headings and optional-layer read-through; D1/D2 decided; awaiting plan approval | +| [23](../../docs/agent-cli-interface/23-optional-layer-tolerance.md) | Approved 2026-10-18 for [#128](https://github.com/ARA-Labs/ara-cli/issues/128); shared dash/bracket entry headings and optional-layer read-through shipped in 0.1.34; the completed design replaces the plan | Plan 18's CLI and skill changes are implemented; its external changes and pilot follow-ups remain separate, so it stays a plan. Plan 18 supersedes the parent plan's default-JSON agent workflow with brief text while retaining programmatic JSON access, and [the command reference](../../docs/agent-cli.md) documents the shipped behavior. Plan 19's CLI sub-PRs are implemented; its repeated skill audit and upstream event-target review remain pending. Mechanical recording does not delegate research judgment to the CLI. diff --git a/skills/compiler-cli/references/cli-access.md b/skills/compiler-cli/references/cli-access.md index 80e9227..60fc6ff 100644 --- a/skills/compiler-cli/references/cli-access.md +++ b/skills/compiler-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls diff --git a/skills/research-foresight-cli/SKILL.md b/skills/research-foresight-cli/SKILL.md index 40dd285..669611d 100644 --- a/skills/research-foresight-cli/SKILL.md +++ b/skills/research-foresight-cli/SKILL.md @@ -52,8 +52,10 @@ ara -C show '
' --max-bytes 32768 Use only addresses that `ls`, `find` or an error printed. `find` prints line numbers of the whole source document, so read around a hit with the `--document` window; `show
--lines` counts inside that address. A truncated block ends with `next:`; rerun with that `--lines`. On -`unknown_id` or `ambiguous_heading`, pick from the printed `candidates:`. Report any other `ara` -error as it is; never fall back to file tools on knowledge paths. +`unknown_id` or `ambiguous_heading`, pick from the printed `candidates:`. A line +`incomplete: ()` means that one file was not fully read; the rest of the output is +valid even though the command exits 1. Report any other `ara` error as it is; never fall back to +file tools on knowledge paths. ## Inputs diff --git a/skills/research-foresight-cli/references/cli-access.md b/skills/research-foresight-cli/references/cli-access.md index 80e9227..60fc6ff 100644 --- a/skills/research-foresight-cli/references/cli-access.md +++ b/skills/research-foresight-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls diff --git a/skills/research-manager-cli/references/cli-access.md b/skills/research-manager-cli/references/cli-access.md index 80e9227..60fc6ff 100644 --- a/skills/research-manager-cli/references/cli-access.md +++ b/skills/research-manager-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls From f01d95217449bb727ea2fe67ea391cafedfcbe36 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 18 Oct 2026 23:06:35 -0700 Subject: [PATCH 3/4] fix(cli): treat incomplete optional layers as a read warning (#128) ls, show and find over an incomplete optional layer now exit 0 and keep complete: false, the incomplete list and the brief line. Exit 1 on a read means the request failed; here the request succeeds and the gap is an artifact defect. status still exits 1 when incomplete. Co-Authored-By: Claude --- CHANGELOG.md | 3 ++- crates/ara-cli/src/main.rs | 4 +++- crates/ara-cli/tests/agent_layer_tolerance.rs | 7 ++++--- .../23-optional-layer-tolerance.md | 19 +++++++++++++------ docs/agent-cli.md | 12 +++++++----- skills/compiler-cli/references/cli-access.md | 2 +- skills/research-foresight-cli/SKILL.md | 2 +- .../references/cli-access.md | 2 +- .../references/cli-access.md | 2 +- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebbc623..5e31791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,7 +120,8 @@ All notable changes to this project are documented here. The format follows `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: ()` line, and the command exits 1. `status` keeps + `incomplete: ()` 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`. diff --git a/crates/ara-cli/src/main.rs b/crates/ara-cli/src/main.rs index 8bd7dbb..1b3fba3 100644 --- a/crates/ara-cli/src/main.rs +++ b/crates/ara-cli/src/main.rs @@ -93,8 +93,10 @@ fn agent_command( context::discover(directory) } .and_then(|root| command(&root)); + // A structural read over an incomplete optional layer is a warning: its + // `complete: false` and `incomplete` report the gap without failing. let incomplete = result.as_ref().is_ok_and(|value| { - value.get("complete") == Some(&serde_json::Value::Bool(false)) + format == "ara.status/v1" && value.get("complete") == Some(&serde_json::Value::Bool(false)) || format == "ara.show/v1" && value .get("errors") diff --git a/crates/ara-cli/tests/agent_layer_tolerance.rs b/crates/ara-cli/tests/agent_layer_tolerance.rs index 87eb0e8..8a342e7 100644 --- a/crates/ara-cli/tests/agent_layer_tolerance.rs +++ b/crates/ara-cli/tests/agent_layer_tolerance.rs @@ -1,7 +1,8 @@ //! Optional-layer tolerance (#128): typed entry headings accept dash //! separators and a bracketed status, and an `ARA217`/`ARA218` warning about //! one optional-layer file no longer hides the rest of the artifact. Such a -//! read prints its result, names the file under `incomplete`, and exits 1. +//! read prints its result, names the file under `incomplete`, and exits 0; +//! only `status` exits 1 when incomplete. use assert_cmd::Command; use serde_json::{Value, json}; use std::path::Path; @@ -43,7 +44,7 @@ fn run(root: &Path, args: &[&str]) -> Value { } /// A read that went through with an incomplete optional layer. fn partial(root: &Path, args: &[&str]) -> Value { - let value = read(root, args, 1); + let value = read(root, args, 0); assert_eq!(value["complete"], false, "{value}"); value } @@ -243,7 +244,7 @@ fn brief_reads_name_the_incomplete_file() { .arg(dir.path()) .arg("ls") .assert() - .code(1) + .success() .get_output() .clone(); assert!( diff --git a/docs/agent-cli-interface/23-optional-layer-tolerance.md b/docs/agent-cli-interface/23-optional-layer-tolerance.md index eee60d2..450f3f2 100644 --- a/docs/agent-cli-interface/23-optional-layer-tolerance.md +++ b/docs/agent-cli-interface/23-optional-layer-tolerance.md @@ -56,12 +56,19 @@ what a tree node says. results when any optional-layer file is affected, and nothing otherwise. Brief text prints `incomplete: ()` after the diagnostics summary. -The command exits 1. The existing contract says incomplete source -representation is never reported as success, and `complete: false` already -mapped to exit 1. Partial multi-address `show` made the same trade-off -([plan 22](22-reader-turn-overhead.md)): output on stdout, a countable -non-zero exit. The shared skill access guide and the reader skill now say that -an exit-1 read with `incomplete` carries valid results. +`ls`, `show` and `find` exit 0. An implementation first exited 1, reusing +the `status` rule that `complete: false` exits 1; that rule existed because +only `status` emitted `complete`. Exit 1 on a read means the request failed: +partial multi-address `show` exits 1 because an address the caller asked for +did not resolve, and the reader harness counts those exits as agent failures. +Here the request succeeds (`show N01` returns N01 in full), the gap is often +in a file the caller never asked about, and `ARA218` loses nothing at all, so +exit 1 would report artifact defects as agent errors. Reads already return +other warnings with exit 0; the `incomplete` report keeps the gap explicit, so +it is not reported as plain success. `status` still exits 1 when +`complete` is false, because reporting completeness is its job. The shared +skill access guide and the reader skill say that `incomplete` names files +that were not fully read while the rest of the output is valid. `status` keeps `complete` all-or-nothing, but `counts` and `next_ids` stay available unless an error or node-scoped warning exists. The next ID of an diff --git a/docs/agent-cli.md b/docs/agent-cli.md index 9fabd0f..1e90d8a 100644 --- a/docs/agent-cli.md +++ b/docs/agent-cli.md @@ -57,9 +57,11 @@ or lock failure. `--fields` projects supported fields while retaining transaction/result identity. A multi-address `show` in which some addresses fail is a partial result: it prints on stdout and exits 1 ([partial reads](#partial-multi-address-reads)). A read over an incomplete -optional layer does the same ([below](#incomplete-optional-layers)). JSON excerpts are bounded to 160 Unicode +optional layer is not a failure: it exits 0 and reports the gap in +`incomplete` ([below](#incomplete-optional-layers)). JSON excerpts are bounded to 160 Unicode characters; `--full` retains source content. Incomplete source representation -must not be reported as success. +must not be reported as success: a refusal or an explicit `incomplete` report +says so. ### Observation inactivity in `ls --unfinished` @@ -608,10 +610,10 @@ other layers. `ls`, `show` and `find` print their result and add: `reason` joins the first line of each distinct message for that file. Both fields are absent when every layer was represented. Brief text adds one `incomplete: ()` line on stderr after the diagnostics summary. -The command exits 1, because incomplete source representation is not reported -as success. Duplicate records stay readable: `ls --type observation` lists +The read exits 0, like a read with any other warning: the request succeeded, +and `incomplete` reports the gap without counting as a failed request. Duplicate records stay readable: `ls --type observation` lists both `O01` rows. `status` keeps `complete: false` with the same `incomplete` -list, but its `counts` and `next_ids` stay available; only the next ID of an +list and still exits 1 when incomplete, but its `counts` and `next_ids` stay available; only the next ID of an affected prefix (`O`, `T`, `E`, `H`) is null, with a `next_id_errors` entry coded `next_id.incomplete_layer`, because a dropped entry may already hold that number. Writes are unaffected: they validate in `ara-core` and reject only diff --git a/skills/compiler-cli/references/cli-access.md b/skills/compiler-cli/references/cli-access.md index 60fc6ff..6727fd9 100644 --- a/skills/compiler-cli/references/cli-access.md +++ b/skills/compiler-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read whose results carry `incomplete` (`complete: false`; brief text: `incomplete: ()`) succeeded: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls diff --git a/skills/research-foresight-cli/SKILL.md b/skills/research-foresight-cli/SKILL.md index 669611d..b184995 100644 --- a/skills/research-foresight-cli/SKILL.md +++ b/skills/research-foresight-cli/SKILL.md @@ -54,7 +54,7 @@ source document, so read around a hit with the `--document` window; `show ()` means that one file was not fully read; the rest of the output is -valid even though the command exits 1. Report any other `ara` error as it is; never fall back to +valid. Report any other `ara` error as it is; never fall back to file tools on knowledge paths. ## Inputs diff --git a/skills/research-foresight-cli/references/cli-access.md b/skills/research-foresight-cli/references/cli-access.md index 60fc6ff..6727fd9 100644 --- a/skills/research-foresight-cli/references/cli-access.md +++ b/skills/research-foresight-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read whose results carry `incomplete` (`complete: false`; brief text: `incomplete: ()`) succeeded: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls diff --git a/skills/research-manager-cli/references/cli-access.md b/skills/research-manager-cli/references/cli-access.md index 60fc6ff..6727fd9 100644 --- a/skills/research-manager-cli/references/cli-access.md +++ b/skills/research-manager-cli/references/cli-access.md @@ -6,7 +6,7 @@ This is an access contract, not a new research method. All variants retain their Use `ara -C ` (or the same explicit artifact via `ARA_DIR`). Every read/write of `PAPER.md`, `logic/`, `trace/`, `staging/` and registered additional knowledge documents goes through `ara`, including initialization, session indexes, reasoning and taste. Do not use Read/Grep/Glob/Edit/Write, Python or shell filesystem operations on those knowledge bodies. Reading the skill's supplied instruction/reference/template pages remains direct. Source inputs and actual `rubric/`, `src/`, `data/`, `evidence/` bodies are not `ara` documents: read, search and write them directly with file tools where the baseline permits them (`ara show --document` rejects `rubric/`, `src/` and `evidence/` paths with `invalid_document` and lists those roots in `error.details.file_access`); the reader still cannot execute source code or leave its single ARA. Never use a source/evidence exemption to open a knowledge path. -Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read that prints its results with `incomplete` (`complete: false`; brief text: `incomplete: ()`) also exits 1: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. +Exit 1 means rejected/unknown/invalid operation; exit 2 means setup/IO failure. Report the exact failure and apply the source skill's original stopping/repair rule. A read whose results carry `incomplete` (`complete: false`; brief text: `incomplete: ()`) succeeded: use the printed results, and treat only the named optional-layer files as not fully represented. Never fall back to direct knowledge-file access or retry automatically with a changed scientific payload. ## Shell calls From dffb0e0ea3902af07e162e25db651fc322ad4048 Mon Sep 17 00:00:00 2001 From: Yifeng He Date: Sun, 18 Oct 2026 23:10:04 -0700 Subject: [PATCH 4/4] docs: record the full #128 real-ARA rerun Co-Authored-By: Claude --- .../23-optional-layer-tolerance.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/agent-cli-interface/23-optional-layer-tolerance.md b/docs/agent-cli-interface/23-optional-layer-tolerance.md index 450f3f2..243a729 100644 --- a/docs/agent-cli-interface/23-optional-layer-tolerance.md +++ b/docs/agent-cli-interface/23-optional-layer-tolerance.md @@ -88,14 +88,18 @@ because a dropped entry may already hold that number. Writes validate in dash and bracket headings merge exactly like colon headings. That merge test also passes on 0.1.33, because merge identity already came from the reader and write heading lookups; it guards the shared behavior. -- Local real-ARA rerun, 0.1.33 → 0.1.34 (`ara ls --json`): +- Local real-ARA rerun, 0.1.33 → 0.1.34 (`ara ls --json`), 13 research ARAs + plus `nanogpt-speedrun`: | ARA | 0.1.33 | 0.1.34 | |---|---|---| -| `ara-paperbench/.../nanogpt-speedrun` | `incomplete_artifact` ARA217 | readable, exit 0 | -| `Lara/ara` | `incomplete_artifact` ARA217, ARA218 | readable; `staging/observations.yaml` incomplete | -| `DissClaimer/ara`, `MSI/ara` | `invalid_artifact` ARA100 | unchanged (out of scope) | -| `mandate/ara`, `mandate-eval/ara` | `invalid_artifact` ARA105 | unchanged (out of scope) | +| `ara-paperbench/.../nanogpt-speedrun` | `incomplete_artifact` ARA217 | readable | +| `808-Heartbreak`, `music/808`, `SOULFuzz` | `incomplete_artifact` ARA217 | readable | +| `FuzzCC` | `incomplete_artifact` ARA217 | readable; one session file incomplete | +| `Lara` | `incomplete_artifact` ARA217, ARA218 | readable; `staging/observations.yaml` incomplete | +| `DissClaimer`, `MSI` | `invalid_artifact` ARA100 | unchanged (out of scope) | +| `mandate`, `mandate-eval` | `invalid_artifact` ARA105 | unchanged (out of scope) | +| `AgentFuzzBench` | `invalid_artifact` ARA112 | unchanged (out of scope) | | `rsi-bench`, `rsi-chip-bench`, `sierra` | readable | readable | -The four other ARAs from the #128 audit were not available locally. +The remaining refusals are exactly the record errors #128 leaves out of scope.