From 193df0f0a2ae843cbdbab8ae929543b6bb6f704f Mon Sep 17 00:00:00 2001 From: aien Date: Thu, 8 Oct 2026 20:14:56 -0500 Subject: [PATCH 1/4] requirements: read or flag the elided second bound (at least 20 lines and no more than 40) The second bound's noun is carried over from the first count when that is unambiguous; otherwise it is reported uncertain instead of dropped. Closes #344. Co-Authored-By: Claude Opus 5.5 --- .../aien-runtime/src/requirements_extract.rs | 46 +++++ .../tests/requirements_elided_bound_test.rs | 180 ++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 crates/aien-runtime/tests/requirements_elided_bound_test.rs diff --git a/crates/aien-runtime/src/requirements_extract.rs b/crates/aien-runtime/src/requirements_extract.rs index f0e60a78..7bbbfb78 100644 --- a/crates/aien-runtime/src/requirements_extract.rs +++ b/crates/aien-runtime/src/requirements_extract.rs @@ -1,3 +1,4 @@ +//! | ` N and|or|but M` (second noun left out, e.g. `at least 20 lines and no more than 40`) | the second bound is read with the earlier noun (`MaxLines(40)`); with no clear earlier noun, or a direction the noun does not support (`at least 3 paragraphs and no more than 5`), it is UNCERTAIN, never dropped (#344) | //! Reading the requirements out of a goal (see `requirements` for the model). //! //! `analyze` is rule based and deterministic. It returns the requirements it @@ -1463,6 +1464,51 @@ pub fn analyze(goal: &str) -> Extraction { let Num::Val(v) = parse_num(&numtok.word) else { continue; }; + // "at least 20 lines and no more than 40": the second noun is elided + // (#344). Read it with the earlier noun, or report it UNCERTAIN; never drop it. + let next_is_noun = toks + .get(i + 1) + .is_some_and(|t| NOUNS.contains(&t.word.as_str())); + if !next_is_noun && qualifier_ok(&toks, i) && !negated_before(&toks, s) { + let sent = sentence_of(&toks, s); + let joined = + s > sent.start && matches!(toks[s - 1].word.as_str(), "and" | "or" | "but"); + let earlier = (sent.start..s).any(|k| handled.contains(&k)); + // the noun of the count that ends right before the joiner + let antecedent = if joined { + (sent.start..s - 1).rev().find_map(|p| { + let (l, _, _) = match_cue(&toks, p, false)?; + let Num::Val(_) = parse_num(&toks.get(p + l)?.word) else { + return None; + }; + let mut j = p + l + 1; + if toks.get(j).is_some_and(|t| { + matches!(t.word.as_str(), "non-empty" | "nonempty" | "non-blank") + }) { + j += 1; + } + let noun = toks.get(j)?.word.as_str(); + // the noun sits right before the joiner (an optional "long" between) + let gap_ok = j + 1 == s - 1 || (j + 2 == s - 1 && toks[j + 1].word == "long"); + (NOUNS.contains(&noun) && handled.contains(&p) && gap_ok).then_some(noun) + }) + } else { + None + }; + let v = v as i64 + adj; + match antecedent.and_then(|noun| count_req(dir, noun, v.max(1) as usize)) { + Some(r) if v >= 1 => { + add(&mut counts, r); + handled.extend(s..=i); + } + _ if earlier => { + bad(&mut unsure, s, true); + handled.extend(s..=i); + } + _ => {} + } + continue; + } let mut j = i + 1; // "non-empty lines": line counts are over non-empty lines already (sc#331). if toks diff --git a/crates/aien-runtime/tests/requirements_elided_bound_test.rs b/crates/aien-runtime/tests/requirements_elided_bound_test.rs new file mode 100644 index 00000000..de742a1a --- /dev/null +++ b/crates/aien-runtime/tests/requirements_elided_bound_test.rs @@ -0,0 +1,180 @@ +//! #344: a second bound whose noun is left out ("at least 20 lines and no more +//! than 40") is read with the earlier noun, or reported UNCERTAIN. It is never +//! dropped silently. +use aien_runtime::control::ControlResponse; +use aien_runtime::requirements::{analyze, refusal_reason, Requirement}; +use aien_runtime::spine::{ + check_file_proposal, propose_task_checked, ComposeBridge, ComposeProposer, Generation, + COMPOSE_MAX_ATTEMPTS, +}; +use std::sync::Arc; +use std::time::Duration; + +use Requirement::*; + +fn read(goal: &str) -> Vec { + let ex = analyze(goal); + assert!(ex.uncertain.is_empty(), "{goal:?}: {:?}", ex.uncertain); + ex.requirements +} + +#[test] +fn elided_max_after_min_is_read_with_the_earlier_noun() { + let want = [MinLines(20), MaxLines(40)]; + for g in [ + "Write at least 20 lines and no more than 40.", + "Write at least 20 lines and no more than 40", + "Write at least 20 lines, and no more than 40.", + "Write at least 20 lines but at most 40.", + "Write no fewer than 20 lines and up to 40.", + "Create docs/a.md with at least 20 lines and at most 40 in total.", + ] { + let r = read(g); + for w in &want { + assert!(r.contains(w), "{g:?} -> {r:?}"); + } + } + let r = read("Write at least 100 words but at most 200."); + assert!( + r.contains(&MinWords(100)) && r.contains(&MaxWords(200)), + "{r:?}" + ); + // strict cue keeps its adjustment: fewer than 40 is at most 39 + let r = read("Write at least 20 lines and fewer than 40."); + assert!(r.contains(&MaxLines(39)), "{r:?}"); +} + +#[test] +fn unsupported_noun_or_direction_is_uncertain_not_silent() { + // paragraphs have no upper bound in the model + let ex = analyze("Write at least 3 paragraphs and no more than 5."); + assert!(!ex.uncertain.is_empty(), "{ex:?}"); + // items: no upper bound either + let ex = analyze("List at least 3 items and no more than 5."); + assert!(!ex.uncertain.is_empty(), "{ex:?}"); + // a cue with no earlier noun to carry over, after a read count + let ex = analyze("Write at least 20 lines and then keep it under, no more than 40."); + assert!(!ex.uncertain.is_empty(), "{ex:?}"); +} + +#[test] +fn ordinary_numbers_stay_silent() { + for g in [ + "Write at least 20 lines and fix 2 typos.", + "Fix 2 typos in README.md", + "Update section 3 of docs/a.md", + "Write at least 20 lines and update section 3.", + ] { + let r = analyze(g); + assert!(r.uncertain.is_empty(), "{g:?}: {:?}", r.uncertain); + assert!( + !r.requirements.iter().any(|x| matches!(x, MaxLines(_))), + "{g:?}: {:?}", + r.requirements + ); + } + assert!(analyze("Fix 2 typos").requirements.is_empty()); + assert!(analyze("Update section 3").requirements.is_empty()); +} + +fn gen(text: &str) -> Result { + Ok(Generation { + text: text.to_string(), + tokens: 5, + finish_reason: Some("eos".into()), + ..Default::default() + }) +} + +fn reply(lines: usize) -> String { + let mut s = String::from("filename: docs/NOTES.md\n"); + for i in 0..lines { + s.push_str(&format!("line number {i}\n")); + } + s +} + +const GOAL: &str = "Create the file docs/NOTES.md with at least 20 lines and no more than 40."; + +#[test] +fn bytes_over_the_second_bound_are_refused_and_within_bounds_pass() { + let reqs = analyze(GOAL).requirements; + let over = check_file_proposal(&reply(45)).unwrap().content; + let why = refusal_reason(&reqs, &over).expect("45 lines must be refused"); + assert!(why.contains("40"), "{why}"); + for ok in [20usize, 30, 40] { + let c = check_file_proposal(&reply(ok)).unwrap().content; + assert!(refusal_reason(&reqs, &c).is_none(), "{ok} lines"); + } +} + +fn bridge(tmp: &std::path::Path, lines: usize) -> ComposeBridge { + let text = reply(lines); + let proposer: ComposeProposer = Arc::new(move |_: &str, _: Duration| gen(&text)); + ComposeBridge::new(tmp.join("compose"), proposer, "test:elided") +} + +fn report(resp: ControlResponse) -> Option { + if !aien_omega_compose::LINKED { + assert!(matches!(resp, ControlResponse::Error(_))); + return None; + } + let ControlResponse::ComposeTaskResult(r) = resp else { + panic!("{resp:?}") + }; + Some(*r) +} + +#[test] +fn linked_compose_does_not_commit_45_lines_but_commits_30() { + let tmp = tempfile::tempdir().unwrap(); + let ws = tmp.path().join("ws"); + std::fs::create_dir_all(&ws).unwrap(); + let r = report(bridge(tmp.path(), 45).run_task(GOAL, ws.to_str().unwrap())); + if let Some(r) = r { + assert!(!r.committed, "{r:?}"); + assert!(r.proposal.is_none()); + assert_eq!(r.proposal_attempts.len(), COMPOSE_MAX_ATTEMPTS as usize); + assert_eq!(std::fs::read_dir(&ws).unwrap().count(), 0); + } + let tmp = tempfile::tempdir().unwrap(); + let ws = tmp.path().join("ws"); + std::fs::create_dir_all(&ws).unwrap(); + if let Some(r) = report(bridge(tmp.path(), 30).run_task(GOAL, ws.to_str().unwrap())) { + assert!(r.committed, "{r:?}"); + let p = check_file_proposal(r.proposal.as_deref().unwrap()).unwrap(); + assert_eq!(p.content, check_file_proposal(&reply(30)).unwrap().content); + } +} + +/// The real compose verification boundary (`propose_task_checked`), which does +/// not need the linked omega build: the 45 line reply is refused on every +/// attempt and nothing is approved; the 30 line reply is approved byte for byte. +#[test] +fn compose_boundary_refuses_45_lines_and_approves_30() { + let ex = analyze(GOAL); + assert!(ex.uncertain.is_empty()); + let run = |lines: usize| { + let text = reply(lines); + let proposer = move |_: &str, _: Duration| gen(&text); + propose_task_checked( + &proposer, + "base", + None, + &ex.requirements, + Duration::from_secs(5), + Duration::from_millis(1), + COMPOSE_MAX_ATTEMPTS, + ) + }; + let (out, attempts) = run(45); + let why = out.unwrap_err(); + assert!(why.contains("40"), "{why}"); + assert_eq!(attempts.len(), COMPOSE_MAX_ATTEMPTS as usize); + assert!(attempts + .iter() + .all(|a| a.outcome == "refused" && a.aegis.is_none())); + let (out, attempts) = run(30); + assert_eq!(out.unwrap(), reply(30)); + assert_eq!(attempts.len(), 1); +} From d2adbfbc6a2bf84e88b379c36e987d9ee4911ebe Mon Sep 17 00:00:00 2001 From: aien Date: Thu, 8 Oct 2026 20:24:46 -0500 Subject: [PATCH 2/4] requirements: a bound cue with a bare number and nothing to bind to is uncertain Co-Authored-By: Claude Opus 5.5 --- .../aien-runtime/src/requirements_extract.rs | 6 ++-- .../tests/requirements_elided_bound_test.rs | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/aien-runtime/src/requirements_extract.rs b/crates/aien-runtime/src/requirements_extract.rs index 7bbbfb78..52621c88 100644 --- a/crates/aien-runtime/src/requirements_extract.rs +++ b/crates/aien-runtime/src/requirements_extract.rs @@ -1,4 +1,4 @@ -//! | ` N and|or|but M` (second noun left out, e.g. `at least 20 lines and no more than 40`) | the second bound is read with the earlier noun (`MaxLines(40)`); with no clear earlier noun, or a direction the noun does not support (`at least 3 paragraphs and no more than 5`), it is UNCERTAIN, never dropped (#344) | +//! | ` N and|or|but M` (second noun left out, e.g. `at least 20 lines and no more than 40`) | the second bound is read with the earlier noun (`MaxLines(40)`); with no clear earlier noun (or no earlier count at all), or a direction the noun does not support (`at least 3 paragraphs and no more than 5`), it is UNCERTAIN, never dropped (#344) | //! Reading the requirements out of a goal (see `requirements` for the model). //! //! `analyze` is rule based and deterministic. It returns the requirements it @@ -1473,7 +1473,6 @@ pub fn analyze(goal: &str) -> Extraction { let sent = sentence_of(&toks, s); let joined = s > sent.start && matches!(toks[s - 1].word.as_str(), "and" | "or" | "but"); - let earlier = (sent.start..s).any(|k| handled.contains(&k)); // the noun of the count that ends right before the joiner let antecedent = if joined { (sent.start..s - 1).rev().find_map(|p| { @@ -1501,11 +1500,10 @@ pub fn analyze(goal: &str) -> Extraction { add(&mut counts, r); handled.extend(s..=i); } - _ if earlier => { + _ => { bad(&mut unsure, s, true); handled.extend(s..=i); } - _ => {} } continue; } diff --git a/crates/aien-runtime/tests/requirements_elided_bound_test.rs b/crates/aien-runtime/tests/requirements_elided_bound_test.rs index de742a1a..cd338238 100644 --- a/crates/aien-runtime/tests/requirements_elided_bound_test.rs +++ b/crates/aien-runtime/tests/requirements_elided_bound_test.rs @@ -52,7 +52,7 @@ fn unsupported_noun_or_direction_is_uncertain_not_silent() { // items: no upper bound either let ex = analyze("List at least 3 items and no more than 5."); assert!(!ex.uncertain.is_empty(), "{ex:?}"); - // a cue with no earlier noun to carry over, after a read count + // a cue with no earlier noun to carry over let ex = analyze("Write at least 20 lines and then keep it under, no more than 40."); assert!(!ex.uncertain.is_empty(), "{ex:?}"); } @@ -178,3 +178,32 @@ fn compose_boundary_refuses_45_lines_and_approves_30() { assert_eq!(out.unwrap(), reply(30)); assert_eq!(attempts.len(), 1); } + +#[test] +fn bound_cue_with_bare_number_and_no_antecedent_is_uncertain() { + for g in [ + "Keep it to no more than 40", + "Keep it to no more than 40.", + "Write at least 20", + "Write at least 20.", + "Use up to 12.", + "Make it fewer than 40.", + "Make it more than 10.", + "Write a maximum of 30.", + "Write a minimum of 30.", + "Write no fewer than 5.", + ] { + let ex = analyze(g); + assert!(!ex.uncertain.is_empty(), "{g:?} silent: {ex:?}"); + } + for g in [ + "Fix 2 typos", + "Update section 3", + "Use Python 3", + "Use Python 3.", + ] { + let ex = analyze(g); + assert!(ex.uncertain.is_empty(), "{g:?}: {:?}", ex.uncertain); + assert!(ex.requirements.is_empty(), "{g:?}: {:?}", ex.requirements); + } +} From 2865673d8f0288049f88999f686c613287a628a3 Mon Sep 17 00:00:00 2001 From: aien Date: Thu, 8 Oct 2026 20:32:43 -0500 Subject: [PATCH 3/4] requirements: every bound cue with a number is read or uncertain Co-Authored-By: Claude Opus 5.5 --- .../aien-runtime/src/requirements_extract.rs | 8 ++++- .../tests/requirements_elided_bound_test.rs | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/aien-runtime/src/requirements_extract.rs b/crates/aien-runtime/src/requirements_extract.rs index 52621c88..9e951021 100644 --- a/crates/aien-runtime/src/requirements_extract.rs +++ b/crates/aien-runtime/src/requirements_extract.rs @@ -2425,7 +2425,13 @@ pub fn analyze(goal: &str) -> Extraction { let under_read = toks[s].norm == "under" && handled.contains(&i) && ((s >= 1 && organise(s - 1)) || (s >= 2 && organise(s - 2))); - if looks_numeric && (noun_near || num_at == Some(Num::Bad)) && !under_read { + // a bound cue and a number nothing above read: read or UNCERTAIN, never + // ignored ("at most 40 please", "fix at least 2 typos") (#344) + let unread_bound = + !vague && matches!(num_at, Some(Num::Val(_))) && !handled.contains(&i); + if ((looks_numeric && (noun_near || num_at == Some(Num::Bad))) || unread_bound) + && !under_read + { bad(&mut unsure, s, true); continue; } diff --git a/crates/aien-runtime/tests/requirements_elided_bound_test.rs b/crates/aien-runtime/tests/requirements_elided_bound_test.rs index cd338238..be49a6bc 100644 --- a/crates/aien-runtime/tests/requirements_elided_bound_test.rs +++ b/crates/aien-runtime/tests/requirements_elided_bound_test.rs @@ -207,3 +207,32 @@ fn bound_cue_with_bare_number_and_no_antecedent_is_uncertain() { assert!(ex.requirements.is_empty(), "{g:?}: {:?}", ex.requirements); } } + +#[test] +fn every_bound_cue_with_a_number_is_read_or_uncertain() { + for g in [ + "Keep it at most 40 please", + "Keep it to no more than 40, thanks.", + "Include at least 2 of them", + "Fix at least 2 typos in README.md", + "Write at least 20 lines and fix at least 2 typos.", + "Use not more than 3 colours.", + "Use not less than 3 colours.", + ] { + let ex = analyze(g); + assert!(!ex.uncertain.is_empty(), "{g:?} silent: {ex:?}"); + } + // still read, not uncertain + assert_eq!(read("Write at most 40 lines please."), [MaxLines(40)]); + for g in [ + "Fix 2 typos in README.md", + "Update section 3", + "Use Python 3", + ] { + let ex = analyze(g); + assert!( + ex.uncertain.is_empty() && ex.requirements.is_empty(), + "{g:?}" + ); + } +} From b1f0c995842928af15d6223bb1daeff33f34b62d Mon Sep 17 00:00:00 2001 From: aien Date: Fri, 9 Oct 2026 09:50:37 -0500 Subject: [PATCH 4/4] crumb: recompile after rebase onto main 797039a Co-Authored-By: Claude Opus 5.5 --- .crumb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.crumb b/.crumb index 51fded1c..d34ff840 100644 --- a/.crumb +++ b/.crumb @@ -65,7 +65,7 @@ "children": [ { "digest": "bf0b33103faf720887cc37d410f924747078edab52d2170d7c9d8c965a8b3618", - "last_commit": "3bd36c2", + "last_commit": "797039a", "name": "scripts", "purpose": "" }, @@ -77,14 +77,14 @@ } ], "children_root": "sha256:20c95358a2e6cde016bc1a6b9d07b1ed5500de7131c7eb30982592664870658c", - "compiled_at": "2026-10-09T14:36:46Z", + "compiled_at": "2026-10-09T14:50:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:335f6b5a5407bf79938e039ef8ca28f9480f49594593e688d0d93385cbdb36d9", + "digest": "sha256:9cfbde28d83d8770600ce621d93cd695720f9fe9088c4eaf3a011a9c196d12a4", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 1847, - "generated_at_commit": "8f08f119552ca8aa127e3a7024840155559ad208", - "source_tree": "sha256:c5564ec1371a82e51e07316070f50157ffb177c90b18eb49a1db734c1c5786f3" + "files": 1848, + "generated_at_commit": "2865673d8f0288049f88999f686c613287a628a3", + "source_tree": "sha256:b278a7013dfae86f02b66d6b877096408d7388f7aa06830f4da9a010e6924733" } }, "history": [],