From 2b114c3fc210108ced40b1e3cc28a2db3e7614a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:46:00 +0000 Subject: [PATCH 1/6] docs(campaigns): restore the 2026-05-26 Scripts heading The A2ML-to-deed migration (#298) inserted the "historical" note for file-ffi-pr-v2.sh in place of the `=== Scripts` heading: the section lost its heading, the note began with the sentence fragment "form was broken under jq operator precedence)", and `|=== Scripts` is not an AsciiDoc heading. Restore `=== Scripts` and append the note to the end of the file-ffi-pr-v2.sh table cell, where the fragment shows it was meant to go. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- docs/campaigns/2026-05-26/README.adoc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/campaigns/2026-05-26/README.adoc b/docs/campaigns/2026-05-26/README.adoc index f829cce..11f0743 100644 --- a/docs/campaigns/2026-05-26/README.adoc +++ b/docs/campaigns/2026-05-26/README.adoc @@ -8,11 +8,7 @@ They’re filed alongside the human + machine campaign reports so the campaign is reproducible. See link:../2026-05-26.md[`+../2026-05-26.md+`] for the report. -form was broken under jq operator precedence). *Historical since -2026-11-14:* it now exits at once, because it writes a retired `+.a2ml+` -registry; a registry is now `+audits/assail-classifications_praxis.deed+` -(see `+.claude/CLAUDE.md+`, User-Classification Registry). -|=== Scripts +=== Scripts [width="100%",cols="50%,50%",options="header",] |=== @@ -38,7 +34,10 @@ into autofix / issue / proof-draft / skip buckets. Writes `+legitimate-ffi+`). Builds the `+audits/assail-classifications.a2ml+` + audit doc, commits with the GPG override flags, pushes, opens a PR. *v2* uses `+--argjson+` + `+any()+` for the prefix filter (the v1 chained-OR -form was broken under jq operator precedence). +form was broken under jq operator precedence). *Historical since +2026-11-14:* it now exits at once, because it writes a retired `+.a2ml+` +registry; a registry is now `+audits/assail-classifications_praxis.deed+` +(see `+.claude/CLAUDE.md+`, User-Classification Registry). |=== === Known gotchas From 30649f17e7cf240bace6d9029e803d25a0a74ed8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:50:16 +0000 Subject: [PATCH 2/6] fix(manifest): propagate load errors instead of exporting defaults `panic-attack manifest` read the manifest with `Manifest::load(&target).unwrap_or_default()`. Since #298 made 0-AI-MANIFEST.deed the default manifest, a malformed or misheaded deed was silently replaced by the empty built-in manifest: the command exited 0, and with `-o` it overwrote the output with empty Nickel. Add `Manifest::load_if_exists`, which returns the defaults only when the file is missing and propagates every other error, and use it in the manifest command. `panic-attack diagnostics` without `--manifest` reused the startup manifest, which also falls back to the defaults on a load error and then reported "no manifest file; built-in defaults"; it now re-reads the default path the same way and fails on a malformed file. Tests: a2ml::tests::load_if_exists_defaults_only_when_the_file_is_missing, and tests/manifest_cli.rs (manifest_export_fails_on_a_malformed_default_deed and diagnostics_fails_on_a_malformed_default_deed fail without this fix). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- src/a2ml/mod.rs | 24 +++++++++++++ src/main.rs | 13 +++++-- tests/manifest_cli.rs | 83 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 tests/manifest_cli.rs diff --git a/src/a2ml/mod.rs b/src/a2ml/mod.rs index 9ce554c..b22bb16 100644 --- a/src/a2ml/mod.rs +++ b/src/a2ml/mod.rs @@ -184,6 +184,17 @@ impl Manifest { Self::load(&Self::default_path()) } + /// Load `path` if it exists, else the built-in defaults. A file that + /// exists but does not load (a malformed or misheaded deed, an unreadable + /// file) is an error, never the defaults. + pub fn load_if_exists(path: &Path) -> Result { + if path.exists() { + Self::load(path) + } else { + Ok(Self::default()) + } + } + /// Load a manifest. A `.deed` file is read with the deed grammar /// (`crate::deed`) and must be a `repo-deed`; anything else is read as /// legacy A2ML. @@ -1526,6 +1537,19 @@ mod tests { ); } + #[test] + fn load_if_exists_defaults_only_when_the_file_is_missing() { + let dir = TempDir::new().expect("tempdir"); + let path = dir.path().join("0-AI-MANIFEST.deed"); + let missing = Manifest::load_if_exists(&path).expect("missing file is the defaults"); + assert!(missing.path().is_none()); + fs::write(&path, "(manifest (project \"x\"))\n").expect("write"); + assert!( + Manifest::load_if_exists(&path).is_err(), + "a malformed manifest that exists must be an error, not the defaults" + ); + } + #[test] fn legacy_a2ml_manifest_still_reads_report_settings() { let dir = TempDir::new().expect("tempdir"); diff --git a/src/main.rs b/src/main.rs index 01d2ff0..257196d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2246,7 +2246,11 @@ fn run_main() -> Result<()> { Commands::Manifest { path, output } => { let target = path.unwrap_or_else(Manifest::default_path); - let manifest = Manifest::load(&target).unwrap_or_default(); + // A missing manifest exports the built-in defaults; one that exists + // but does not load is an error, so `-o` never overwrites with empty + // Nickel. + let manifest = Manifest::load_if_exists(&target) + .with_context(|| format!("reading manifest {}", target.display()))?; let nickel = manifest.to_nickel(); if let Some(output_path) = output { fs::write(&output_path, nickel)?; @@ -2399,11 +2403,16 @@ fn run_main() -> Result<()> { Commands::Diagnostics { manifest: manifest_path, } => { + // Re-read rather than reuse the startup manifest: startup falls back + // to the defaults on a load error, and diagnostics must not report a + // malformed manifest as "no manifest file". let diag_manifest = if let Some(path) = manifest_path { Manifest::load(&path) .with_context(|| format!("reading manifest {}", path.display()))? } else { - manifest.clone() + let path = Manifest::default_path(); + Manifest::load_if_exists(&path) + .with_context(|| format!("reading manifest {}", path.display()))? }; diagnostics::run_self_diagnostics(&diag_manifest)?; return Ok(()); diff --git a/tests/manifest_cli.rs b/tests/manifest_cli.rs new file mode 100644 index 0000000..f83db60 --- /dev/null +++ b/tests/manifest_cli.rs @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell + +//! CLI contract for `panic-attack manifest` and `panic-attack diagnostics`: +//! a manifest that exists but does not load is an error, never the built-in +//! defaults. + +use std::fs; +use std::path::Path; +use std::process::{Command, Output}; +use tempfile::TempDir; + +const POINTER_MANIFEST: &str = r#";; SPDX-License-Identifier: MPL-2.0 +(repo-deed + :schema-version "1.0.0" + (front-doors :machine "example_chora.deed" :human "README.adoc")) +"#; + +fn run(dir: &Path, args: &[&str]) -> Output { + Command::new(env!("CARGO_BIN_EXE_panic-attack")) + .current_dir(dir) + .args(args) + .output() + .expect("binary should run") +} + +#[test] +fn manifest_export_fails_on_a_malformed_default_deed() { + let dir = TempDir::new().unwrap(); + fs::write( + dir.path().join("0-AI-MANIFEST.deed"), + "(manifest (project \"x\"))\n", + ) + .unwrap(); + let out = dir.path().join("out.ncl"); + fs::write(&out, "previous export\n").unwrap(); + let o = run(dir.path(), &["manifest", "-o", out.to_str().unwrap()]); + assert!(!o.status.success(), "{o:?}"); + assert!( + String::from_utf8_lossy(&o.stderr).contains("0-AI-MANIFEST.deed"), + "{o:?}" + ); + assert_eq!( + fs::read_to_string(&out).unwrap(), + "previous export\n", + "a failed export must not overwrite the output" + ); +} + +#[test] +fn manifest_export_without_a_manifest_uses_the_defaults() { + let dir = TempDir::new().unwrap(); + let o = run(dir.path(), &["manifest"]); + assert!(o.status.success(), "{o:?}"); +} + +#[test] +fn manifest_export_reads_a_valid_pointer_deed() { + let dir = TempDir::new().unwrap(); + fs::write(dir.path().join("0-AI-MANIFEST.deed"), POINTER_MANIFEST).unwrap(); + let o = run(dir.path(), &["manifest"]); + assert!(o.status.success(), "{o:?}"); + assert!( + String::from_utf8_lossy(&o.stdout).contains("example_chora.deed"), + "{o:?}" + ); +} + +#[test] +fn diagnostics_fails_on_a_malformed_default_deed() { + let dir = TempDir::new().unwrap(); + fs::write( + dir.path().join("0-AI-MANIFEST.deed"), + "(manifest (project \"x\"))\n", + ) + .unwrap(); + let o = run(dir.path(), &["diagnostics"]); + assert!(!o.status.success(), "{o:?}"); + assert!( + String::from_utf8_lossy(&o.stderr).contains("reading manifest 0-AI-MANIFEST.deed"), + "{o:?}" + ); +} From fc5c15b1cc738498a4eaa1da34064817b118ca88 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:51:28 +0000 Subject: [PATCH 3/6] fix(manifest): hold 0-AI-MANIFEST.deed to the pointer-only profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deed manifest loader checked only the document head, so a 0-AI-MANIFEST.deed that was a valid repo-deed but had no (front-doors :machine … :human …) clause was accepted as the authoritative manifest, and no legacy manifest was considered, although agents then have no front door to follow (A7 ruling Q15). When the file is named 0-AI-MANIFEST.deed, require exactly one (front-doors …) clause giving :machine and :human once each as non-empty strings. Extra front doors (such as :agent) and other clauses are still accepted: estate manifests, including the standards repository's own, are not yet reduced to pointer-only form, and the deed linter is the gate for that. A repo deed under another name (a `--path` export of _chora.deed) is not held to the profile. Test: a2ml::tests::pointer_manifest_requires_its_front_doors (fails without this fix). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- src/a2ml/mod.rs | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/src/a2ml/mod.rs b/src/a2ml/mod.rs index b22bb16..cc0423b 100644 --- a/src/a2ml/mod.rs +++ b/src/a2ml/mod.rs @@ -232,6 +232,10 @@ impl Manifest { deed.head )); } + if path.file_name().and_then(|n| n.to_str()) == Some(MANIFEST_CANDIDATES[0]) { + check_pointer_profile(&deed.items) + .map_err(|e| anyhow!("{}: not a pointer-only manifest: {}", path.display(), e))?; + } Ok(Self { root_name: deed.head.clone(), entries: deed.items.iter().map(deed_item_to_sexpr).collect(), @@ -810,6 +814,57 @@ impl<'a> Parser<'a> { } } +/// The pointer-only profile of `0-AI-MANIFEST.deed` (A7 ruling Q15): exactly +/// one `(front-doors …)` clause, giving `:machine` and `:human` once each as +/// non-empty strings. Other members are not refused here: estate manifests +/// are still being reduced to pointer-only form, and the deed linter is the +/// gate for that. +fn check_pointer_profile(items: &[crate::deed::Item]) -> Result<()> { + use crate::deed::{Item, Value}; + let mut doors = items.iter().filter_map(|item| match item { + Item::Clause { name, items, line } if name == "front-doors" => Some((items, *line)), + _ => None, + }); + let (doors_items, doors_line) = doors + .next() + .ok_or_else(|| anyhow!("missing the (front-doors :machine … :human …) clause"))?; + if let Some((_, line)) = doors.next() { + return Err(anyhow!("line {line}: (front-doors) given more than once")); + } + for key in ["machine", "human"] { + let mut values = doors_items.iter().filter_map(|item| match item { + Item::Field { + key: k, + value, + line, + .. + } if k == key => Some((value, *line)), + _ => None, + }); + match (values.next(), values.next()) { + (None, _) => { + return Err(anyhow!( + "line {doors_line}: (front-doors) is missing :{key}" + )) + } + (Some(_), Some((_, line))) => { + return Err(anyhow!("line {line}: :{key} given more than once")) + } + (Some((Value::Str(s), _)), None) if !s.trim().is_empty() => {} + (Some((Value::Str(_), line)), None) => { + return Err(anyhow!("line {line}: :{key} is empty")) + } + (Some((value, line)), None) => { + return Err(anyhow!( + "line {line}: :{key} must be a string, found {}", + value.kind() + )) + } + } + } + Ok(()) +} + /// A deed member as a manifest entry: a field `:key value` becomes /// `(key value)` (a list value contributes its elements), a clause /// `(name …)` becomes `(name …)` with its members converted in turn. @@ -1537,6 +1592,55 @@ mod tests { ); } + #[test] + fn pointer_manifest_requires_its_front_doors() { + let dir = TempDir::new().expect("tempdir"); + let path = dir.path().join("0-AI-MANIFEST.deed"); + let front_doors = "(front-doors :machine \"example_chora.deed\" :human \"README.adoc\")"; + let refused = [ + ( + "no front-doors clause", + DEED_MANIFEST.replace(front_doors, ""), + ), + ( + "no :machine", + DEED_MANIFEST.replace(front_doors, "(front-doors :human \"README.adoc\")"), + ), + ( + "no :human", + DEED_MANIFEST.replace(front_doors, "(front-doors :machine \"x_chora.deed\")"), + ), + ( + "symbol :machine", + DEED_MANIFEST.replace("\"example_chora.deed\"", "example"), + ), + ( + "empty :human", + DEED_MANIFEST.replace("\"README.adoc\"", "\"\""), + ), + ( + "two front-doors clauses", + DEED_MANIFEST.replace(front_doors, &format!("{front_doors}\n {front_doors}")), + ), + ]; + for (why, text) in refused { + fs::write(&path, text).expect("write"); + assert!(Manifest::load(&path).is_err(), "{why} must be refused"); + } + // A pointer manifest with an extra front door is still accepted. + fs::write( + &path, + DEED_MANIFEST.replace(":human", ":agent \".claude/CLAUDE.md\" :human"), + ) + .expect("write"); + Manifest::load(&path).expect("extra front door is accepted"); + // The profile is the manifest's: a repo deed under another name is not + // held to it. + let other = dir.path().join("example_chora.deed"); + fs::write(&other, DEED_MANIFEST.replace(front_doors, "")).expect("write"); + Manifest::load(&other).expect("a chora deed needs no front-doors clause"); + } + #[test] fn load_if_exists_defaults_only_when_the_file_is_missing() { let dir = TempDir::new().expect("tempdir"); From a31b70b7ad2bcd8942384ff0f377ba20b9d62fc7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:53:34 +0000 Subject: [PATCH 4/6] fix(manifest): keep deed types in the Nickel export MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deed manifest was converted into the untyped A2ML S-expression tree before rendering, which lost what each value was: - a list field contributed its elements to the field, so `:x ()` became `null` and a one-element list became a scalar; - a clause with one child clause, such as `(bot-directives (bot …))`, became the array `["bot", …]` instead of a record; - `#t`/`#f` became the strings "#t"/"#f"; - an integer became a string ("3"). Keep the parsed deed members on the Manifest and render them directly: a field is `key = value`, a clause is always a record, a name given more than once is an array of its values, a list is always an array, booleans are `true`/`false`, and integers are number literals (leading zeros dropped, since a deed integer is never octal). Strings, symbols and ids are strings, as before. The legacy A2ML path is unchanged. Tests (each fails without this fix): a2ml::tests:: deed_lists_stay_arrays_in_nickel, deed_booleans_render_as_nickel_booleans, deed_single_child_clause_stays_a_record, deed_integers_render_as_nickel_numbers. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- src/a2ml/mod.rs | 167 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 135 insertions(+), 32 deletions(-) diff --git a/src/a2ml/mod.rs b/src/a2ml/mod.rs index cc0423b..cd91f92 100644 --- a/src/a2ml/mod.rs +++ b/src/a2ml/mod.rs @@ -150,7 +150,11 @@ pub const MANIFEST_CANDIDATES: &[&str] = &["0-AI-MANIFEST.deed", "0-AI-MANIFEST. #[derive(Clone, Debug)] pub struct Manifest { root_name: String, + /// The legacy A2ML tree; empty for a deed. entries: Vec, + /// The deed's members, kept typed so `to_nickel` renders lists, booleans, + /// integers and clauses as what they are; empty for legacy A2ML. + deed_items: Vec, /// The file the manifest was read from; `None` for the built-in defaults. path: Option, /// True when read from a `0-AI-MANIFEST.deed`. @@ -162,6 +166,7 @@ impl Default for Manifest { Self { root_name: "manifest".to_string(), entries: Vec::new(), + deed_items: Vec::new(), path: None, from_deed: false, } @@ -220,8 +225,8 @@ impl Manifest { self.from_deed } - /// Parse a deed manifest. The head becomes the root name and each field - /// or clause one entry, so `to_nickel` renders the deed as it stands. + /// Parse a deed manifest. The head becomes the root name and the members + /// are kept as parsed, so `to_nickel` renders the deed as it stands. fn parse_deed(raw: &str, path: &Path) -> Result { let deed = crate::deed::parse(raw, Some(path)) .map_err(|e| anyhow!("{}: {}", path.display(), e))?; @@ -238,7 +243,8 @@ impl Manifest { } Ok(Self { root_name: deed.head.clone(), - entries: deed.items.iter().map(deed_item_to_sexpr).collect(), + entries: Vec::new(), + deed_items: deed.items, path: None, from_deed: true, }) @@ -392,8 +398,11 @@ impl Manifest { } pub fn to_nickel(&self) -> String { - let entries = gather_entries(&self.entries); - let body = record_to_nickel(&entries); + let body = if self.from_deed { + deed_items_to_nickel(&self.deed_items) + } else { + record_to_nickel(&gather_entries(&self.entries)) + }; format!("let {} = {};\n{}", self.root_name, body, self.root_name) } @@ -865,39 +874,73 @@ fn check_pointer_profile(items: &[crate::deed::Item]) -> Result<()> { Ok(()) } -/// A deed member as a manifest entry: a field `:key value` becomes -/// `(key value)` (a list value contributes its elements), a clause -/// `(name …)` becomes `(name …)` with its members converted in turn. -fn deed_item_to_sexpr(item: &crate::deed::Item) -> Sexpr { - match item { - crate::deed::Item::Field { key, value, .. } => { - let mut list = vec![Sexpr::Atom(key.clone())]; - match value { - crate::deed::Value::List(values) => { - list.extend(values.iter().map(deed_value_to_sexpr)); - } - other => list.push(deed_value_to_sexpr(other)), - } - Sexpr::List(list) - } - crate::deed::Item::Clause { name, items, .. } => { - let mut list = vec![Sexpr::Atom(name.clone())]; - list.extend(items.iter().map(deed_item_to_sexpr)); - Sexpr::List(list) +/// Deed members as a Nickel record: a field `:key value` becomes +/// `key = value` and a clause `(name …)` becomes `name = { … }`, however +/// many members it has. A name given more than once (repeated clauses, such +/// as several `(bot …)`) becomes an array of its values, in order. +fn deed_items_to_nickel(items: &[crate::deed::Item]) -> String { + use crate::deed::Item; + let mut grouped: Vec<(&str, Vec)> = Vec::new(); + for item in items { + let (key, rendered) = match item { + Item::Field { key, value, .. } => (key.as_str(), deed_value_to_nickel(value)), + Item::Clause { name, items, .. } => (name.as_str(), deed_items_to_nickel(items)), + }; + match grouped.iter_mut().find(|(existing, _)| *existing == key) { + Some((_, values)) => values.push(rendered), + None => grouped.push((key, vec![rendered])), } } + nickel_record( + grouped + .into_iter() + .map(|(key, mut values)| { + let value = if values.len() == 1 { + values.remove(0) + } else { + format!("[{}]", values.join(", ")) + }; + format!("{} = {}", key_to_nickel(key), value) + }) + .collect(), + ) } -fn deed_value_to_sexpr(value: &crate::deed::Value) -> Sexpr { +/// A deed value as Nickel, keeping its type: a list is always an array (an +/// empty one included), `#t`/`#f` are booleans, an integer is a number, and +/// strings, symbols and ids are strings. +fn deed_value_to_nickel(value: &crate::deed::Value) -> String { use crate::deed::Value; match value { - Value::Str(s) | Value::Uuid(s) => Sexpr::String(s.clone()), - Value::Uuid8(s) => Sexpr::String(format!("#u8:{s}")), - Value::Uuid5(s) => Sexpr::String(format!("#u5:{s}")), - Value::Symbol(s) | Value::Integer(s) => Sexpr::Atom(s.clone()), - Value::Boolean(b) => Sexpr::Atom(if *b { "#t" } else { "#f" }.to_string()), - Value::Quoted(inner) => deed_value_to_sexpr(inner), - Value::List(values) => Sexpr::List(values.iter().map(deed_value_to_sexpr).collect()), + Value::Str(s) | Value::Uuid(s) | Value::Symbol(s) => nickel_escape_string(s), + Value::Uuid8(s) => nickel_escape_string(&format!("#u8:{s}")), + Value::Uuid5(s) => nickel_escape_string(&format!("#u5:{s}")), + Value::Integer(s) => nickel_integer(s), + Value::Boolean(b) => b.to_string(), + Value::Quoted(inner) => deed_value_to_nickel(inner), + Value::List(values) => format!( + "[{}]", + values + .iter() + .map(deed_value_to_nickel) + .collect::>() + .join(", ") + ), + } +} + +/// A deed integer (`-?[0-9]+`, kept as written) as a Nickel number literal: +/// leading zeros are dropped, since a deed integer is never octal. +fn nickel_integer(written: &str) -> String { + let (sign, digits) = match written.strip_prefix('-') { + Some(rest) => ("-", rest), + None => ("", written), + }; + let digits = digits.trim_start_matches('0'); + if digits.is_empty() { + "0".to_string() + } else { + format!("{sign}{digits}") } } @@ -936,6 +979,14 @@ fn record_to_nickel(entries: &[(String, Vec>)]) -> String { format!("{} = {}", key_to_nickel(key), value) }) .collect(); + nickel_record(lines) +} + +/// Field lines (`key = value`) as a Nickel record body. +fn nickel_record(lines: Vec) -> String { + if lines.is_empty() { + return "{}".to_string(); + } format!("{{\n {}\n}}", lines.join(";\n ")) } @@ -1592,6 +1643,58 @@ mod tests { ); } + /// `DEED_MANIFEST` with `clause` added before its front doors, loaded + /// and exported to Nickel. + fn deed_nickel_with(clause: &str) -> String { + let dir = TempDir::new().expect("tempdir"); + let path = dir.path().join("example_chora.deed"); + let text = DEED_MANIFEST.replace("(front-doors", &format!("{clause}\n (front-doors")); + fs::write(&path, text).expect("write"); + Manifest::load(&path).expect("deed should load").to_nickel() + } + + #[test] + fn deed_lists_stay_arrays_in_nickel() { + let nickel = deed_nickel_with("(clade :none () :one (\"panic-attacker\") :secondary (rm))"); + assert!(nickel.contains("none = []"), "{nickel}"); + assert!(nickel.contains("one = [\"panic-attacker\"]"), "{nickel}"); + assert!(nickel.contains("secondary = [\"rm\"]"), "{nickel}"); + } + + #[test] + fn deed_booleans_render_as_nickel_booleans() { + let nickel = deed_nickel_with("(permissions :source #t :tests #f)"); + assert!(nickel.contains("source = true"), "{nickel}"); + assert!(nickel.contains("tests = false"), "{nickel}"); + assert!(!nickel.contains("#t") && !nickel.contains("#f"), "{nickel}"); + } + + #[test] + fn deed_single_child_clause_stays_a_record() { + let one = deed_nickel_with("(bot-directives (bot :name panicbot :mode full))"); + assert!( + one.contains("\"bot-directives\" = {\n bot = {\n name = \"panicbot\""), + "{one}" + ); + assert!(!one.contains("[\"bot\""), "{one}"); + // Repeated clauses are an array of records. + let two = deed_nickel_with("(bot-directives (bot :name panicbot) (bot :name rhodibot))"); + assert!( + two.contains("bot = [{\n name = \"panicbot\"\n}, {\n name = \"rhodibot\"\n}]"), + "{two}" + ); + } + + #[test] + fn deed_integers_render_as_nickel_numbers() { + let nickel = deed_nickel_with("(limits :retries 3 :offset -2 :padded 007 :zero -0)"); + assert!(nickel.contains("retries = 3"), "{nickel}"); + assert!(nickel.contains("offset = -2"), "{nickel}"); + assert!(nickel.contains("padded = 7"), "{nickel}"); + assert!(nickel.contains("zero = 0"), "{nickel}"); + assert!(!nickel.contains("\"3\""), "{nickel}"); + } + #[test] fn pointer_manifest_requires_its_front_doors() { let dir = TempDir::new().expect("tempdir"); From c46be8b03931886f22722d4051664fb4cd279e47 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:54:51 +0000 Subject: [PATCH 5/6] fix(manifest): emit Nickel that the Nickel parser accepts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not one of the #298 review findings, but it makes the type fixes moot: the manifest export separated record fields with `;` and ended with `let x = { … };\nx`, which is Nix-like syntax. `nickel export` (1.18.0) rejects it with "unexpected token" on the second field, so no Nickel consumer could read the export at all. Separate fields with `,` and bind with `let x = { … } in\nx`. Both the deed and the legacy renderers share the record writer, so both are fixed. Checked by hand with `nickel export` on this repository's 0-AI-MANIFEST.deed, on panic-attack_chora.deed and on a legacy-format manifest. Test: a2ml::tests::manifest_nickel_uses_nickel_record_and_let_syntax (fails without this fix; it also runs `nickel export` on the output when the Nickel CLI is installed). The assault-report Nickel writer (src/report/output.rs) has the same `;` form and is not changed here. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- src/a2ml/mod.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/a2ml/mod.rs b/src/a2ml/mod.rs index cd91f92..04c8eb6 100644 --- a/src/a2ml/mod.rs +++ b/src/a2ml/mod.rs @@ -403,7 +403,7 @@ impl Manifest { } else { record_to_nickel(&gather_entries(&self.entries)) }; - format!("let {} = {};\n{}", self.root_name, body, self.root_name) + format!("let {} = {} in\n{}", self.root_name, body, self.root_name) } /// The legacy `(reports …)` section; never read from a deed. @@ -987,7 +987,7 @@ fn nickel_record(lines: Vec) -> String { if lines.is_empty() { return "{}".to_string(); } - format!("{{\n {}\n}}", lines.join(";\n ")) + format!("{{\n {}\n}}", lines.join(",\n ")) } fn values_to_nickel(values: &[Sexpr]) -> String { @@ -1605,6 +1605,43 @@ mod tests { ); } + #[test] + fn manifest_nickel_uses_nickel_record_and_let_syntax() { + // Nickel separates record fields with `,` and binds with `let … in`; + // `;` separators and a trailing `let x = …;` form do not parse. + let dir = TempDir::new().expect("tempdir"); + let deed = dir.path().join("0-AI-MANIFEST.deed"); + fs::write(&deed, DEED_MANIFEST).expect("write"); + // Any name other than `.deed` is read as legacy text. + let legacy = dir.path().join("legacy-manifest.txt"); + fs::write(&legacy, LEGACY_MANIFEST).expect("write"); + for path in [&deed, &legacy] { + let nickel = Manifest::load(path).expect("load").to_nickel(); + assert!(!nickel.contains(';'), "{nickel}"); + assert!(nickel.contains(",\n"), "{nickel}"); + let root = if path == &deed { + "repo-deed" + } else { + "manifest" + }; + assert!(nickel.ends_with(&format!(" in\n{root}")), "{nickel}"); + // Where the Nickel CLI is installed, it must accept the output. + let file = dir.path().join("out.ncl"); + fs::write(&file, &nickel).expect("write"); + if let Ok(out) = std::process::Command::new("nickel") + .arg("export") + .arg(&file) + .output() + { + assert!( + out.status.success(), + "{nickel}\n{}", + String::from_utf8_lossy(&out.stderr) + ); + } + } + } + #[test] fn deed_manifest_carries_no_report_settings() { // Pointer-only: even a (reports …) clause is not read from a deed. From a3217f1fc2b581ed69f477505888e30037358d2e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:56:18 +0000 Subject: [PATCH 6/6] fix(diagnostics): tell a missing repo deed and listing errors from no directives `panicbot_directives` returned `Ok(None)` in three cases that are not the same: - the directory holds no `*_chora.deed` (for example, the manifest's :machine target was deleted); - `fs::read_dir` failed, or a directory entry could not be read (entries were dropped with `filter_map(.ok())`); - a repo deed parsed and declares no panicbot directives. Only the last one shows that no directives are declared, yet all three were reported as "[OK] no panicbot directives declared (panicbot runs the full suite)". Return a `PanicbotDirectives` value (NoRepoDeed / NotDeclared / Declared), and propagate listing and entry errors as `Err`, which the existing warning arm reports. A missing repo deed is now a warning, the same level as a repo deed that does not parse; it does not fail diagnostics, because diagnostics also runs in repositories that do not carry a chora deed yet. Tests: diagnostics::tests:: panicbot_directives_tells_a_missing_repo_deed_from_no_directives and panicbot_directives_propagates_a_listing_error (on the old code both a deed-less directory and a missing directory returned Ok(None)). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZoBy5xGnGDLk7wQ8jC --- src/diagnostics.rs | 98 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 13 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 48338b1..3a0e5e3 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -209,7 +209,8 @@ fn check_watcher(label: &'static str, env_key: &str) -> Diagnostic { /// 3. WeakPointCategory and Severity serialise in PascalCase (no serde rename_all) /// /// Failed JSON checks, including serialisation errors, yield an error diagnostic; -/// a repo deed that does not parse yields a warning. +/// a repo deed that does not parse, a directory with no repo deed, or one +/// that cannot be listed yields a warning. fn check_panicbot_readiness() -> Diagnostic { let directives = panicbot_directives(Path::new(".")); @@ -261,18 +262,24 @@ fn check_panicbot_readiness() -> Diagnostic { ); } match directives { - Ok(Some(deed)) => Diagnostic::ok( + Ok(PanicbotDirectives::Declared(deed)) => Diagnostic::ok( "panicbot integration", format!( "directives declared in {} (bot-directives), JSON contract verified", deed.display() ), ), - Ok(None) => Diagnostic::ok( + Ok(PanicbotDirectives::NotDeclared) => Diagnostic::ok( "panicbot integration", "no panicbot directives declared (panicbot runs the full suite), JSON contract verified" .to_string(), ), + Ok(PanicbotDirectives::NoRepoDeed) => Diagnostic::warning( + "panicbot integration", + "JSON contract OK but no _chora.deed found here, so whether panicbot \ + directives are declared is unknown" + .to_string(), + ), Err(err) => Diagnostic::warning( "panicbot integration", format!("JSON contract OK but the repo deed could not be read: {err}"), @@ -280,15 +287,31 @@ fn check_panicbot_readiness() -> Diagnostic { } } -/// The repo deed in `root` that declares `(bot-directives (bot :name -/// panicbot …))`, if any. `Err` when a `*_chora.deed` there does not parse. -fn panicbot_directives(root: &Path) -> Result> { +/// What the repo deeds in a directory say about panicbot directives. +#[derive(Debug, PartialEq, Eq)] +enum PanicbotDirectives { + /// No `*_chora.deed` is there, so nothing can be said either way. + NoRepoDeed, + /// The repo deed parses and declares no panicbot directives. + NotDeclared, + /// This repo deed declares `(bot-directives (bot :name panicbot …))`. + Declared(std::path::PathBuf), +} + +/// What the repo deeds in `root` say about panicbot directives. `Err` when +/// the directory or one of its entries cannot be read, or when a +/// `*_chora.deed` there does not parse: none of those shows that no +/// directives are declared. +fn panicbot_directives(root: &Path) -> Result { use panic_attack::deed::{Item, Value}; - let Ok(entries) = fs::read_dir(root) else { - return Ok(None); - }; - let mut deeds: Vec<_> = entries - .filter_map(|e| e.ok().map(|e| e.path())) + let listing = || format!("listing {}", root.display()); + let paths = fs::read_dir(root) + .with_context(listing)? + .map(|entry| entry.map(|e| e.path())) + .collect::>>() + .with_context(listing)?; + let mut deeds: Vec<_> = paths + .into_iter() .filter(|p| { p.file_name() .and_then(|n| n.to_str()) @@ -296,6 +319,7 @@ fn panicbot_directives(root: &Path) -> Result> { }) .collect(); deeds.sort(); + let any_deed = !deeds.is_empty(); let names_panicbot = |items: &[Item]| { items.iter().any(|item| { matches!(item, Item::Field { key, value: Value::Symbol(name), .. } @@ -317,10 +341,14 @@ fn panicbot_directives(root: &Path) -> Result> { _ => false, }); if declared { - return Ok(Some(path)); + return Ok(PanicbotDirectives::Declared(path)); } } - Ok(None) + Ok(if any_deed { + PanicbotDirectives::NotDeclared + } else { + PanicbotDirectives::NoRepoDeed + }) } /// Check attestation readiness: whether signing is available and if a @@ -356,3 +384,47 @@ enum Severity { Warn, Error, } + +#[cfg(test)] +mod tests { + use super::*; + use tempfile::TempDir; + + fn repo_deed(body: &str) -> String { + format!( + ";; SPDX-License-Identifier: MPL-2.0\n(repo-deed\n :schema-version \"1.0.0\"{body})\n" + ) + } + + #[test] + fn panicbot_directives_tells_a_missing_repo_deed_from_no_directives() { + let dir = TempDir::new().expect("tempdir"); + assert_eq!( + panicbot_directives(dir.path()).expect("empty directory lists"), + PanicbotDirectives::NoRepoDeed + ); + let deed = dir.path().join("example_chora.deed"); + fs::write(&deed, repo_deed("")).expect("write"); + assert_eq!( + panicbot_directives(dir.path()).expect("deed parses"), + PanicbotDirectives::NotDeclared + ); + fs::write( + &deed, + repo_deed("\n (bot-directives (bot :name panicbot))"), + ) + .expect("write"); + assert_eq!( + panicbot_directives(dir.path()).expect("deed parses"), + PanicbotDirectives::Declared(deed) + ); + } + + #[test] + fn panicbot_directives_propagates_a_listing_error() { + let dir = TempDir::new().expect("tempdir"); + let missing = dir.path().join("no-such-directory"); + let err = panicbot_directives(&missing).expect_err("listing must fail"); + assert!(err.to_string().contains("listing"), "{err:#}"); + } +}