← Commit history

Merge PR #539: step: know every AI Flow step before plan, and name the lane's library step (fix/step-names-before-plan -> main) merge

Colby Knox ·d952f33781 · ·parents 258b10a, 036ef08

Showing changes introduced by the merge (against its first parent).

3 files changed +124−3
crates/adom-aiflow/src/main.rs+14−3
@@ -4678,7 +4678,7 @@ fn main() {             // issue #169: the package version follows its content; KiCad's PCM updates only to a higher one             if v["pcmVersionWhy"].as_str().is_some_and(|w| w.starts_with("content changed")) { hints.push(format!("PCM package {} ({}): a KiCad that has an earlier version installed updates with kicad_pcm_install {{\"identifier\":\"{}\",\"update\":true}}, or Update in KiCad's Plugin and Content Manager after a restart", v["pcmVersion"].as_str().unwrap_or("?"), v["pcmVersionWhy"].as_str().unwrap_or(""), v["identifier"].as_str().unwrap_or(""))); }             ok(&format!("{}: README revision 1 with {} parts, KiCad PCM repository {} (package {}; {} symbols, {} footprints, {} models for {} distinct parts; symbol library version {}, KiCad load check: {})", page_said, v["parts"], v["repositoryUrl"].as_str().unwrap_or(""), v["pcmVersion"].as_str().unwrap_or("?"), c["symbols"], c["footprints"], c["models"], c["distinctParts"], v["libraryCheck"]["symVersion"], v["libraryCheck"]["kicadCli"].as_str().unwrap_or("?")),-               &[hints, if *no_push { vec![format!("Local build only: the README, PCM zip and repository files are in {}. The repository URL above works only after `project-page` runs without --no-push.", dir.join("project-page").display())] } else { vec![] }, vec![format!("Next: `step libraries`, then install the parts in KiCad: kicad_pcm_add_repository {{\"url\":\"{}\"}} and kicad_pcm_install {{\"repositoryUrl\":\"{}\",\"identifier\":\"{}\"}}, restart KiCad, then `pcm check`.", v["repositoryUrl"].as_str().unwrap_or(""), v["repositoryUrl"].as_str().unwrap_or(""), v["identifier"].as_str().unwrap_or(""))]].concat());+               &[hints, if *no_push { vec![format!("Local build only: the README, PCM zip and repository files are in {}. The repository URL above works only after `project-page` runs without --no-push.", dir.join("project-page").display())] } else { vec![] }, vec![format!("Next: `step {}`, then install the parts in KiCad: kicad_pcm_add_repository {{\"url\":\"{}\"}} and kicad_pcm_install {{\"repositoryUrl\":\"{}\",\"identifier\":\"{}\"}}, restart KiCad, then `pcm check`.", sequence::library_step(&r.data["sequence"].as_array().map(|a| a.iter().filter_map(|s| s.as_str().map(str::to_string)).collect::<Vec<_>>()).unwrap_or_default()), v["repositoryUrl"].as_str().unwrap_or(""), v["repositoryUrl"].as_str().unwrap_or(""), v["identifier"].as_str().unwrap_or(""))]].concat());         }         Cmd::Pcm { what: _ } => {             thread(&cli);@@ -7588,9 +7588,20 @@ fn main() {             thread(&cli);             let mut r = load_run(&cli);             for l in handson::ingest(&mut r.data, &dir.join("timeline")) { println!("{l}"); }-            let mut known: Vec<String> = r.data["flow"]["steps"].as_array().map(|a| a.iter().filter_map(|x| x["name"].as_str().map(str::to_string)).collect()).unwrap_or_else(|| ["intake", "placement", "routing", "pours", "current", "thermal", "capture", "finish"].iter().map(|s| s.to_string()).collect());-            for s in preboard::PREBOARD_STEPS.iter().chain(reviews::STEPS.iter()) { if !known.iter().any(|k| k == s) { known.push(s.to_string()); } }+            // every step AI Flow knows (the flow's steps and later steps, every lane's sequence, the steps+            // before the board, the reviews), not only the flow `plan` copies into the run: before `plan`,+            // documented steps such as silkscreen or library read as "your own step name"+            let flow_names: Value = serde_json::from_str(include_str!("../../../flows/board.json")).unwrap();+            let mut known: Vec<String> = r.data["flow"]["steps"].as_array().map(|a| a.iter().filter_map(|x| x["name"].as_str().map(str::to_string)).collect()).unwrap_or_default();+            for s in sequence::flow_step_names(&flow_names) { if !known.contains(&s) { known.push(s); } }             let known: Vec<&str> = known.iter().map(String::as_str).collect();+            // a step name this run's sequence does not have: the lane's own name for it, or that it is not required+            {+                let key = sequence::sequence_key(&dir, &r.data);+                let want = sequence::sequence_of(&flow_names, &key);+                let run_seq: Vec<String> = match r.data["sequence"].as_array() { Some(a) if !sequence::may_resequence(&r.data, &want) => a.iter().filter_map(|s| s.as_str().map(str::to_string)).collect(), _ => want };+                if let Some(n) = sequence::step_name_note(&flow_names, &run_seq, &key, name) { note(&n, &[]); }+            }             let mut clip_stopped = false;             let prev = r.data["currentStep"].as_str().map(str::to_string);             // an Altium run's edits live in the open documents until they are saved: a 2026-10-20 run saved
crates/adom-aiflow/src/sequence.rs+75
@@ -154,6 +154,45 @@ pub fn sequence_of(flow: &Value, lane: &str) -> Vec<String> {     flow["sequence"][lane].as_array().map(|a| a.iter().filter_map(|s| s.as_str().map(str::to_string)).collect()).unwrap_or_default() } +/// Every step name AI Flow itself knows: the flow's steps and later steps, every lane's sequence, the+/// steps before the board and the declared reviews. A name outside this list is the AI's own.+pub fn flow_step_names(flow: &Value) -> Vec<String> {+    let mut out: Vec<String> = Vec::new();+    let mut add = |s: &str| if !s.is_empty() && !out.iter().any(|k| k == s) { out.push(s.to_string()); };+    for key in ["steps", "later"] {+        for s in flow[key].as_array().into_iter().flatten() { if let Some(n) = s["name"].as_str() { add(n); } }+    }+    for (k, seq) in flow["sequence"].as_object().into_iter().flatten() {+        if k == "_" { continue; }+        for s in seq.as_array().into_iter().flatten() { if let Some(n) = s.as_str() { add(n); } }+    }+    for s in crate::preboard::PREBOARD_STEPS.iter().chain(crate::reviews::STEPS.iter()) { add(s); }+    out+}++/// The name this run's sequence gives a step another lane names differently (the parts library is+/// `libraries` on the KiCad lane and `library` on the others).+pub fn lane_name_for<'a>(seq: &'a [String], name: &str) -> Option<&'a str> {+    const SAME: [(&str, &str); 2] = [("library", "libraries"), ("libraries", "library")];+    SAME.iter().filter(|(a, _)| *a == name).find_map(|(_, b)| seq.iter().find(|s| s.as_str() == *b)).map(String::as_str)+}++/// The library step of this run's sequence, for the hints that send the AI there.+pub fn library_step(seq: &[String]) -> &'static str {+    if seq.iter().any(|s| s == "library") { "library" } else { "libraries" }+}++/// What `step <name>` notes about a name this run's sequence does not have: the lane's own name when+/// another lane names the step differently, or that the step is AI Flow's but not required here. None+/// for a step of the sequence and for a name AI Flow does not know (the AI's own step name).+pub fn step_name_note(flow: &Value, seq: &[String], lane: &str, name: &str) -> Option<String> {+    if seq.iter().any(|s| s == name) { return None; }+    if let Some(ours) = lane_name_for(seq, name) {+        return Some(format!("{name} is not a step of this run's sequence ({lane}): it calls that step {ours}. `step {ours}` charges the work to it and counts its proof; {name} is charged like any other name."));+    }+    flow_step_names(flow).iter().any(|s| s == name).then(|| format!("{name} is an AI Flow step this run's sequence ({lane}) does not require; it is charged like any other."))+}+ fn last_visit(data: &Value, step: &str) -> Option<String> {     data["steps"][step]["visits"].as_array().and_then(|a| a.iter().filter_map(|v| v["at"].as_str()).max().map(str::to_string)) }@@ -673,3 +712,39 @@ mod label_tests {         let _ = std::fs::remove_dir_all(root);     } }++#[cfg(test)]+mod step_name_tests {+    use super::*;++    fn flow() -> Value { serde_json::from_str(include_str!("../../../flows/board.json")).unwrap() }++    #[test]+    fn every_documented_step_is_known_without_plan() {+        let f = flow();+        let names = flow_step_names(&f);+        for s in ["silkscreen", "library", "libraries", "components", "models", "parts", "project-page", "outline", "fields", "nets", "3d", "export", "thermal-vias", "sourcing", "schematic", "simulation", "design", "test-plan", "mechanical-review", "moleculize"] {+            assert!(names.iter().any(|n| n == s), "{s} missing from {names:?}");+        }+        let seq = sequence_of(&f, "kicad");+        assert_eq!(step_name_note(&f, &seq, "kicad", "silkscreen"), None);+        assert_eq!(step_name_note(&f, &seq, "kicad", "my-bench-check"), None, "the AI's own name is the hint's business, not a note");+    }++    #[test]+    fn the_other_lanes_name_for_a_step_points_to_this_lanes() {+        let f = flow();+        let new = sequence_of(&f, "kicad-new");+        let old = sequence_of(&f, "kicad");+        assert_eq!(library_step(&new), "library");+        assert_eq!(library_step(&old), "libraries");+        assert_eq!(lane_name_for(&new, "libraries"), Some("library"));+        assert_eq!(lane_name_for(&old, "library"), Some("libraries"));+        assert_eq!(lane_name_for(&new, "library"), None);+        let n = step_name_note(&f, &new, "kicad-new", "libraries").unwrap();+        assert!(n.starts_with("libraries is not a step of this run's sequence (kicad-new): it calls that step library."), "{n}");+        // a step of the flow that this lane leaves out (the pattern lane has no routing)+        let pat = sequence_of(&f, "pattern");+        assert!(step_name_note(&f, &pat, "pattern", "routing").unwrap().starts_with("routing is an AI Flow step this run's sequence (pattern) does not require"));+    }+}
tests/step-names-workflow.pyadded+35
@@ -0,0 +1,35 @@+"""`step <name>` judges the name by the run's own sequence, before `plan` has run too.++A KiCad board from scratch (an intake run, sequence kicad-new) has `library` and `silkscreen` among+its steps: `step silkscreen` and `step library` are charged to those steps, `step libraries` (the plain+KiCad lane's name) notes that this lane calls it `library`, a step of the flow this lane leaves out is+noted as such, and only a name AI Flow does not know is "your own step name". No CAD, desktop or+dashboard.++  python3 tests/step-names-workflow.py <adom-aiflow binary>+"""+import json, os, pathlib, subprocess, sys, tempfile+binary = str(pathlib.Path(sys.argv[1]).resolve())++with tempfile.TemporaryDirectory(prefix='aiflow-step-names-') as td:+    run = pathlib.Path(td) / 'run'+    env = dict(os.environ, AIFLOW_DASHBOARD='off')+    def call(*args):+        r = subprocess.run([binary, '--run', str(run), '--ai-thread', 'step-names-test', *args], env=env, capture_output=True, text=True, timeout=120)+        assert r.returncode == 0, r.stdout + r.stderr+        return r.stdout + r.stderr+    call('intake', '--prompt-time', '2026-11-19T01:00:00Z', '--engine', 'test')+    seq = json.loads((run / 'run.json').read_text()).get('sequence')+    out = call('step', 'rules')+    seq = json.loads((run / 'run.json').read_text())['sequence']+    assert 'library' in seq and 'libraries' not in seq and 'silkscreen' in seq, seq+    for name in ['silkscreen', 'library', 'project-page']:+        out = call('step', name)+        assert f'Every command from here is charged to {name} until the next `step`.' in out and 'your own step name' not in out, (name, out)+    out = call('step', 'libraries')+    assert 'NOTE (a suggestion, not a stop): libraries is not a step of this run\'s sequence (kicad-new): it calls that step library.' in out and 'your own step name' not in out, out+    out = call('step', 'moleculize')+    assert 'moleculize is an AI Flow step this run\'s sequence (kicad-new) does not require' in out and 'your own step name' not in out, out+    out = call('step', 'bench-check')+    assert 'bench-check is your own step name (the known ones: ' in out and 'not a step of this run' not in out, out+print('PASS: before `plan`, `step` charges silkscreen, library and project-page as the run\'s own steps, notes that this lane calls libraries library, notes a flow step the lane does not require, and calls only an unknown name the AI\'s own')