Craft Anything: understand how any software works, and craft your own.
Rust
Keep a prompt's pictures when Up brings it back (#570)
BFlate1d1974468e2
diff --git a/apps/craft-anything-cli/src/rebuild_cmd.rs b/apps/craft-anything-cli/src/rebuild_cmd.rsindex 8375176b..66924ce3 100644--- a/apps/craft-anything-cli/src/rebuild_cmd.rs+++ b/apps/craft-anything-cli/src/rebuild_cmd.rs@@ -160,9 +160,9 @@ fn run(cli: &Cli, a: &RebuildArgs) -> Result<bool, ToolError> {}}RunEvent::Agent(_) => {}- RunEvent::Note(text) => {+ RunEvent::Note { shown, .. } => {end_line(&mut line_open);- println!(" + {text}");+ println!(" + {shown}");}RunEvent::Ask(r) => {end_line(&mut line_open);diff --git a/crates/ai/src/rebuild/activity.rs b/crates/ai/src/rebuild/activity.rsindex 6ab3ebd3..ad206652 100644--- a/crates/ai/src/rebuild/activity.rs+++ b/crates/ai/src/rebuild/activity.rs@@ -251,7 +251,7 @@ impl Activity {}}},- RunEvent::Note(shown) => new.push((LineKind::Note, format!("You added: {shown}"))),+ RunEvent::Note { shown, .. } => new.push((LineKind::Note, format!("You added: {shown}"))),RunEvent::Ask(r) => new.push((LineKind::Note, format!("Waiting for your answer: {}", r.title))),RunEvent::Checked(c) => {let result = if c.passed { LineKind::Done } else { LineKind::Failed };diff --git a/crates/ai/src/rebuild/feed.rs b/crates/ai/src/rebuild/feed.rsindex 73ee002f..925d66bd 100644--- a/crates/ai/src/rebuild/feed.rs+++ b/crates/ai/src/rebuild/feed.rs@@ -60,9 +60,9 @@ pub fn apply(feed: &mut Vec<FeedItem>, e: &RunEvent) {feed.push(FeedItem::Error { message: message.clone(), remediation: remediation.clone(), log: log.clone() });}RunEvent::Agent(_) => end_stream(feed),- RunEvent::Note(shown) => {+ RunEvent::Note { shown, pictures } => {end_stream(feed);- feed.push(FeedItem::User(shown.clone()));+ feed.push(FeedItem::User(UserItem::new(shown.clone(), pictures.clone())));}RunEvent::Ask(r) => feed.push(FeedItem::Ask { request: r.clone(), answer: None }),RunEvent::Checked(c) => feed.push(FeedItem::Check(c.clone())),@@ -186,7 +186,7 @@ mod tests {]})};let call = |status: &str| RunEvent::Agent(AgentEvent::ToolStarted { call_id: "t".into(), tool: "TodoWrite".into(), input: todo(status) });- let mut feed = vec![FeedItem::User("A snake game".into())];+ let mut feed = vec![FeedItem::User(UserItem::Text("A snake game".into()))];apply(&mut feed, &call("in_progress"));apply(&mut feed, &RunEvent::Agent(AgentEvent::TextDelta { text: "Working.".into() }));apply(&mut feed, &call("completed"));@@ -207,11 +207,11 @@ mod tests {let d = tempfile::tempdir().unwrap();let ws = Workspace::create(d.path(), "x", "Clone it", TargetRef::None).unwrap();let mut log = FeedLog::open(&ws);- log.push(FeedItem::User("Make it blue".into()));+ log.push(FeedItem::User(UserItem::Text("Make it blue".into())));log.record(&RunEvent::Agent(AgentEvent::TextDelta { text: "Done.".into() }));log.record(&RunEvent::Finished { ok: true, message: "Ready.".into(), paused: false });assert!(matches!(load(&ws).as_slice(), [FeedItem::User(a), FeedItem::User(b), FeedItem::Agent { text, streaming: false }]- if a == "Clone it" && b == "Make it blue" && text == "Done."));+ if a.text() == "Clone it" && b.text() == "Make it blue" && text == "Done."));// An answer written to the file by someone else while it runs survives the run's saves.let inbox = Inbox::new(ws.inbox_dir());let id = inbox.post(craft_anything_engine::inbox::RequestKind::Question, "Blue?", "", vec![], true, None).unwrap();diff --git a/crates/ai/src/rebuild/mod.rs b/crates/ai/src/rebuild/mod.rsindex 40d290ce..b1b6ef91 100644--- a/crates/ai/src/rebuild/mod.rs+++ b/crates/ai/src/rebuild/mod.rs@@ -75,8 +75,9 @@ pub enum RunEvent {Step { step: Step, text: String },/// Something from the coding agent (text, tool calls, errors).Agent(AgentEvent),- /// A note the person added while it worked, now read by the agent (as the feed shows it).- Note(String),+ /// A note the person added while it worked, now read by the agent (as the feed shows it),+ /// with the pictures attached to it (their copies in the project).+ Note { shown: String, pictures: Vec<PathBuf> },/// A question or approval waiting for the person.Ask(Request),/// A check finished.@@ -124,6 +125,9 @@ pub struct RunOptions {/// How the person's message is shown in the project's feed (it can differ from `message`,/// which carries attachment paths). `None` adds nothing to the feed.pub shown: Option<String>,+ /// The pictures attached to `shown` (their copies in the project), so the feed keeps them+ /// with the message for Up to bring back.+ pub shown_pictures: Vec<PathBuf>,/// Pick up a build whose last run stopped part-way (paused, the app closed, the computer/// stopped): Study isn't repeated when it was done, and an agent with a saved session is/// told to carry on rather than given the brief again. A run with no message on a project@@ -148,6 +152,7 @@ impl Default for RunOptions {backend: None,message: None,shown: None,+ shown_pictures: Vec::new(),continuing: false,max_rounds: 6,good_enough: 90.0,@@ -168,6 +173,8 @@ pub struct Note {pub text: String,/// How it appears in the project's feed.pub shown: String,+ /// The pictures attached to it (their copies in the project), for the feed's history.+ pub pictures: Vec<PathBuf>,}/// A running (or finished) rebuild.@@ -225,7 +232,7 @@ impl RebuildRun {// The project's conversation: the run keeps it in the folder as it goes.let feed = Arc::new(Mutex::new(feed::FeedLog::open(&ws)));if let Some(shown) = opts.shown.clone() {- feed.lock().unwrap_or_else(PoisonError::into_inner).push(feed::FeedItem::User(shown));+ feed.lock().unwrap_or_else(PoisonError::into_inner).push(feed::FeedItem::User(feed::UserItem::new(shown, opts.shown_pictures.clone())));}let ctx = Worker {wake: opts.wake.clone(),@@ -279,15 +286,16 @@ impl RebuildRun {}/// Add something while it works; the agent reads it at its next step, and only then does it- /// join the feed (as `shown`). Returns its id, to take it back with `unsend` until then.- pub fn add_note(&self, text: String, shown: String) -> u64 {+ /// join the feed (as `shown`, with `pictures`). Returns its id, to take it back with `unsend`+ /// until then.+ pub fn add_note(&self, text: String, shown: String, pictures: Vec<PathBuf>) -> u64 {static NEXT: AtomicU64 = AtomicU64::new(1);let id = NEXT.fetch_add(1, Ordering::Relaxed);// Also left for an agent that takes notes at its next step; without it, after the turn.if let Err(e) = notes::hand_over(¬es::notes_dir(self.inbox.dir()), id, &text) {log::warn!("A note waits for the builder's turn to end: {}", e.message);}- self.notes.lock().unwrap_or_else(PoisonError::into_inner).push(Note { id, text, shown });+ self.notes.lock().unwrap_or_else(PoisonError::into_inner).push(Note { id, text, shown, pictures });id}@@ -501,7 +509,7 @@ impl Worker {notes::forget(&dir, n.id);}for n in ¬es {- self.emit(RunEvent::Note(n.shown.clone()));+ self.emit(RunEvent::Note { shown: n.shown.clone(), pictures: n.pictures.clone() });}// A cancelled step can't be reported, but the notes go in either way.let _ = self.step(ws, Step::Build, Status::Building, "Reading what you added…");@@ -962,7 +970,7 @@ impl Worker {};for n in read {notes::forget(&dir, n.id);- self.emit(RunEvent::Note(n.shown));+ self.emit(RunEvent::Note { shown: n.shown, pictures: n.pictures });}}diff --git a/crates/ai/src/rebuild/stand_in.rs b/crates/ai/src/rebuild/stand_in.rsindex acdd5e1c..d2bc935e 100644--- a/crates/ai/src/rebuild/stand_in.rs+++ b/crates/ai/src/rebuild/stand_in.rs@@ -44,7 +44,7 @@ impl StandIns {let running = Arc::new(AtomicBool::new(true));let feed = Arc::new(Mutex::new(feed::FeedLog::open(&ws)));if let Some(shown) = opts.shown {- feed.lock().unwrap_or_else(PoisonError::into_inner).push(feed::FeedItem::User(shown));+ feed.lock().unwrap_or_else(PoisonError::into_inner).push(feed::FeedItem::User(feed::UserItem::new(shown, opts.shown_pictures)));}all.lock().unwrap_or_else(PoisonError::into_inner).push(Handle {root: ws.root.clone(),diff --git a/crates/ai/src/rebuild/tests.rs b/crates/ai/src/rebuild/tests.rsindex fccf31c5..73aefe31 100644--- a/crates/ai/src/rebuild/tests.rs+++ b/crates/ai/src/rebuild/tests.rs@@ -296,14 +296,14 @@ fn notes_added_while_it_works_reach_the_agent_at_its_next_step() {self_check: None,};assert!(w.added(&mut ws).is_none(), "nothing added, nothing to say");- let note = |id, text: &str| Note { id, text: format!("{text} (pictures: a.png)"), shown: text.into() };+ let note = |id, text: &str| Note { id, text: format!("{text} (pictures: a.png)"), shown: text.into(), pictures: Vec::new() };notes.lock().unwrap().extend([note(1, "Make it faster"), note(2, "A blue sky")]);let p = w.added(&mut ws).unwrap();assert!(p.contains("- Make it faster (pictures: a.png)\n- A blue sky"), "{p}");assert!(notes.lock().unwrap().is_empty(), "each note goes in once");// The notes join the feed as they're read, before the step that reads them.let events: Vec<RunEvent> = rx.try_iter().collect();- let shown: Vec<_> = events.iter().filter_map(|e| if let RunEvent::Note(s) = e { Some(s.as_str()) } else { None }).collect();+ let shown: Vec<_> = events.iter().filter_map(|e| if let RunEvent::Note { shown, .. } = e { Some(shown.as_str()) } else { None }).collect();assert_eq!(shown, ["Make it faster", "A blue sky"]);assert!(matches!(events.last(), Some(RunEvent::Step { text, .. }) if text == "Reading what you added…"));}@@ -1664,8 +1664,8 @@ fn a_note_the_builder_took_at_a_step_joins_the_feed_and_isnt_sent_again() {inbox: Inbox::new(ws.inbox_dir()),editor: None,notes: Arc::new(Mutex::new(vec![- Note { id: 1, text: "make the header blue".into(), shown: "make the header blue".into() },- Note { id: 2, text: "add a footer".into(), shown: "add a footer".into() },+ Note { id: 1, text: "make the header blue".into(), shown: "make the header blue".into(), pictures: Vec::new() },+ Note { id: 2, text: "add a footer".into(), shown: "add a footer".into(), pictures: Vec::new() },])),feed: Arc::new(Mutex::new(feed::FeedLog::open(&ws))),assets: false,@@ -1681,7 +1681,7 @@ fn a_note_the_builder_took_at_a_step_joins_the_feed_and_isnt_sent_again() {assert_eq!(notes::claim(&dir), ["make the header blue"]);std::fs::rename(dir.join("2.wait"), dir.join("2.json")).unwrap();w.relay_read_notes(&ws);- let shown: Vec<String> = rx.try_iter().filter_map(|e| if let RunEvent::Note(s) = e { Some(s) } else { None }).collect();+ let shown: Vec<String> = rx.try_iter().filter_map(|e| if let RunEvent::Note { shown, .. } = e { Some(shown) } else { None }).collect();assert_eq!(shown, ["make the header blue"], "it joins the feed as soon as the builder took it");assert!(!notes::was_read(&dir, 1), "its files are gone");// After the turn, only the note nobody took is sent, and no hook can hand it over again.diff --git a/crates/ai/src/rebuild/tools.rs b/crates/ai/src/rebuild/tools.rsindex 04ce87d4..b25bab2d 100644--- a/crates/ai/src/rebuild/tools.rs+++ b/crates/ai/src/rebuild/tools.rs@@ -399,7 +399,7 @@ fn rebuild_note(ctx: &mut Ctx<'_>, params: Value) -> Result<ToolOutput, ToolErrorefresh(ctx, &mut set);match set.get(&ws.root).filter(|r| r.is_running()) {Some(run) => {- let id = run.add_note(p.text.clone(), p.text);+ let id = run.add_note(p.text.clone(), p.text, Vec::new());Ok(ToolOutput::Value(json!({"id": id, "queued": run.queued()})))}None => Err(ToolError::new(ErrorCode::BadInput, "No build is running for this project in this session.")diff --git a/crates/engine/src/feed.rs b/crates/engine/src/feed.rsindex e61b2556..e3c71906 100644--- a/crates/engine/src/feed.rs+++ b/crates/engine/src/feed.rs@@ -8,13 +8,53 @@ use craft_anything_evidence::{ErrorCode, ToolError};use serde::{Deserialize, Serialize};use serde_json::Value;use std::collections::HashSet;-use std::path::Path;+use std::path::{Path, PathBuf};/// Where the conversation is kept in the project folder.pub const FEED_FILE: &str = "feed.json";-/// The format written today (2 added `Paused`); files without a version are the earlier bare list.-pub const FEED_VERSION: u32 = 2;+/// The format written today (3 saved a prompt's pictures with it); files without a version are+/// the earlier bare list.+pub const FEED_VERSION: u32 = 3;++/// What the person sent: as the feed shows it, and the pictures attached to it (their copies in+/// the project's `attachments/`).+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]+#[serde(untagged)]+pub enum UserItem {+ /// No pictures: saved as a plain string, as every earlier feed was.+ Text(String),+ WithPictures {+ text: String,+ pictures: Vec<PathBuf>,+ },+}++impl UserItem {+ pub fn new(text: String, pictures: Vec<PathBuf>) -> Self {+ if pictures.is_empty() { UserItem::Text(text) } else { UserItem::WithPictures { text, pictures } }+ }++ pub fn text(&self) -> &str {+ match self {+ UserItem::Text(text) | UserItem::WithPictures { text, .. } => text,+ }+ }++ /// The copies in the project's `attachments/`, in the order they were attached.+ pub fn pictures(&self) -> &[PathBuf] {+ match self {+ UserItem::Text(_) => &[],+ UserItem::WithPictures { pictures, .. } => pictures,+ }+ }+}++impl From<String> for UserItem {+ fn from(text: String) -> Self {+ UserItem::Text(text)+ }+}/// One step of the builder's own checklist (from its TodoWrite list).#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]@@ -37,7 +77,7 @@ pub enum PlanStatus {pub enum FeedItem {/// The builder's checklist, kept up to date in place (shown pinned above the prompt box).Plan(Vec<PlanStep>),- User(String),+ User(UserItem),Step {step: Step,text: String,@@ -113,7 +153,7 @@ pub fn load(ws: &Workspace) -> Vec<FeedItem> {/// and anything still waiting for an answer.pub fn history(ws: &Workspace) -> Vec<FeedItem> {let m = &ws.manifest;- let mut feed = vec![FeedItem::User(m.request.clone())];+ let mut feed = vec![FeedItem::User(UserItem::new(m.request.clone(), Vec::new()))];feed.extend(m.checks.iter().cloned().map(FeedItem::Check));if !m.last_reply.is_empty() {feed.push(FeedItem::Agent { text: m.last_reply.clone(), streaming: false });@@ -180,22 +220,37 @@ mod tests {ws.save().unwrap();Inbox::new(ws.inbox_dir()).post(RequestKind::Question, "Blue or red?", "", vec![], true, None).unwrap();let f = history(&ws);- assert!(matches!(&f[0], FeedItem::User(r) if r == "Clone it"));+ assert!(matches!(&f[0], FeedItem::User(r) if r.text() == "Clone it"));assert!(matches!(f.last(), Some(FeedItem::Ask { answer: None, .. })), "pending questions come back");assert_eq!(f.len(), 4);}+ #[test]+ fn a_prompt_keeps_its_pictures_with_it() {+ let d = tempfile::tempdir().unwrap();+ let ws = Workspace::create(d.path(), "x", "Clone it", TargetRef::None).unwrap();+ let pictures = vec![ws.root.join("attachments/picture-1.png"), ws.root.join("attachments/picture-2.webp")];+ save(&ws.root, &[FeedItem::User(UserItem::new("Make it blue".into(), pictures.clone()))]).unwrap();+ let loaded = load(&ws);+ assert!(matches!(&loaded[0], FeedItem::User(u) if u.text() == "Make it blue" && u.pictures() == pictures.as_slice()));+ // A prompt with no pictures is still saved as the plain string older feeds hold.+ save(&ws.root, &[FeedItem::User(UserItem::new("Add tags".into(), Vec::new()))]).unwrap();+ let raw: Value = serde_json::from_slice(&std::fs::read(ws.root.join(FEED_FILE)).unwrap()).unwrap();+ assert_eq!(raw["items"][0]["User"], "Add tags");+ assert!(raw["items"][0]["User"].is_string());+ }+#[test]fn older_files_load_answers_are_kept_and_newer_files_are_left_alone() {let d = tempfile::tempdir().unwrap();let ws = Workspace::create(d.path(), "x", "Clone it", TargetRef::None).unwrap();- save(&ws.root, &[FeedItem::User("Clone it".into()), FeedItem::Agent { text: "Done.".into(), streaming: true }]).unwrap();+ save(&ws.root, &[FeedItem::User(UserItem::Text("Clone it".into())), FeedItem::Agent { text: "Done.".into(), streaming: true }]).unwrap();assert!(matches!(load(&ws).as_slice(), [FeedItem::User(_), FeedItem::Agent { streaming: false, .. }]), "nothing streams after a restart");let raw: Value = serde_json::from_slice(&std::fs::read(ws.root.join(FEED_FILE)).unwrap()).unwrap();assert_eq!(raw["version"], FEED_VERSION);// A feed saved before versioning (the bare list) still loads.std::fs::write(ws.root.join(FEED_FILE), br#"[{"User":"Old request"}]"#).unwrap();- assert!(matches!(load(&ws).as_slice(), [FeedItem::User(r)] if r == "Old request"));+ assert!(matches!(load(&ws).as_slice(), [FeedItem::User(r)] if r.text() == "Old request"));// Answers given with no run going are saved too.let inbox = Inbox::new(ws.inbox_dir());let id = inbox.post(RequestKind::Question, "Blue or red?", "", vec![], true, None).unwrap();@@ -205,7 +260,7 @@ mod tests {assert!(std::fs::read_to_string(ws.root.join(FEED_FILE)).unwrap().contains("\"Blue\""));// #176: one the saved conversation never had (posted from outside a run, answered before// anything saved it) is kept with its answer, once, and still after the inbox forgets it.- save(&ws.root, &[FeedItem::User("Clone it".into())]).unwrap();+ save(&ws.root, &[FeedItem::User(UserItem::Text("Clone it".into()))]).unwrap();let id = inbox.post(RequestKind::Question, "Which scope?", "", vec![], true, None).unwrap();let question = inbox.pending().into_iter().find(|r| r.id == id).unwrap();inbox.answer(&id, &crate::inbox::Answer { choice: Some("Minimal".into()), ..Default::default() }).unwrap();@@ -219,7 +274,7 @@ mod tests {// One from a newer Craft Anything is shown as far as we can, never written over.let newer = br#"{"version":99,"items":[{"User":"From the future"}],"extra":1}"#;std::fs::write(ws.root.join(FEED_FILE), newer).unwrap();- assert!(save(&ws.root, &[FeedItem::User("x".into())]).is_err());+ assert!(save(&ws.root, &[FeedItem::User(UserItem::Text("x".into()))]).is_err());assert_eq!(std::fs::read(ws.root.join(FEED_FILE)).unwrap(), newer);}}diff --git a/crates/engine/src/tools/project_tools.rs b/crates/engine/src/tools/project_tools.rsindex 05e7c3bd..53c48463 100644--- a/crates/engine/src/tools/project_tools.rs+++ b/crates/engine/src/tools/project_tools.rs@@ -580,7 +580,7 @@ mod tests {assert_eq!((ws.manifest.status, ws.manifest.note.as_str()), (Status::Ready, CALLED_DONE));let items = feed::load(&ws);assert!(- matches!(items.as_slice(), [feed::FeedItem::User(a), feed::FeedItem::Step { step: Step::Done, text }] if a == "A website" && text == CALLED_DONE),+ matches!(items.as_slice(), [feed::FeedItem::User(a), feed::FeedItem::Step { step: Step::Done, text }] if a.text() == "A website" && text == CALLED_DONE),"{items:?}");let err = e.call("project_build_finish", json!({"project": d.path().join("nope")}), CallOptions::new(Caller::Cli)).unwrap_err();diff --git a/crates/ui-egui/examples/snapshot.rs b/crates/ui-egui/examples/snapshot.rsindex dd3886dd..b1f412ce 100644--- a/crates/ui-egui/examples/snapshot.rs+++ b/crates/ui-egui/examples/snapshot.rs@@ -193,8 +193,8 @@ fn main() {let root = ws.root.clone();let _ = a.runs.start(&a.hub, ws, RunOptions::default());if let Some(run) = a.runs.get(&root) {- run.add_note("Make the header blue".into(), "Make the header blue".into());- run.add_note("And add a contact form".into(), "And add a contact form".into());+ run.add_note("Make the header blue".into(), "Make the header blue".into(), Vec::new());+ run.add_note("And add a contact form".into(), "And add a contact form".into(), Vec::new());}}a@@ -391,7 +391,7 @@ fn main() {render(&out, "project-game", w, h, scale, move || {let mut a = demo::app(demo::engine(Mode::Beginner, true));a.state.feed = vec![- craft_anything_ui_egui::state::FeedItem::User("A snake game".into()),+ craft_anything_ui_egui::state::FeedItem::User(craft_anything_ui_egui::state::UserItem::Text("A snake game".into())),craft_anything_ui_egui::state::FeedItem::Agent {text: "Your snake game is ready: arrow keys to steer, eat the dots to grow, and the speed goes up as you score.".into(),streaming: false,@@ -422,11 +422,9 @@ fn main() {render(&out, "project-long-prompt", w, h, scale, || {let mut a = demo::app(demo::engine(Mode::Beginner, true));demo::fill_project(&mut a);- a.state.feed.push(craft_anything_ui_egui::state::FeedItem::User(format!(- "{}https://example.com/{}",- "Make it exactly like the original, with the same menus, weapons and maps. ".repeat(6),- "a".repeat(160)- )));+ let text =+ format!("{}https://example.com/{}", "Make it exactly like the original, with the same menus, weapons and maps. ".repeat(6), "a".repeat(160));+ a.state.feed.push(craft_anything_ui_egui::state::FeedItem::User(craft_anything_ui_egui::state::UserItem::Text(text)));a});}diff --git a/crates/ui-egui/src/chat.rs b/crates/ui-egui/src/chat.rsindex 367f853e..23e43aa9 100644--- a/crates/ui-egui/src/chat.rs+++ b/crates/ui-egui/src/chat.rs@@ -320,7 +320,13 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, dense: bool) {let answering = app.answering();let hint = if dense { tr("Ask the agent…") } else { tr("Ask anything, e.g. \"What does this program do?\"") };ui.allocate_ui(Vec2::new(width, 0.0), |ui| {- let history = || app.state.chat.iter().filter_map(|i| if let ChatItem::User(text) = i { Some(text.clone()) } else { None }).collect();+ let history = || {+ app.state+ .chat+ .iter()+ .filter_map(|i| if let ChatItem::User(text) = i { Some(crate::prompt_box::Prompt { text: text.clone(), pictures: Vec::new() }) } else { None })+ .collect()+ };let out = crate::prompt_box::show(ui,&mut app.state.input,diff --git a/crates/ui-egui/src/demo.rs b/crates/ui-egui/src/demo.rsindex 2a1e0f25..2ff5220d 100644--- a/crates/ui-egui/src/demo.rs+++ b/crates/ui-egui/src/demo.rs@@ -264,7 +264,7 @@ pub fn fill_projects(app: &mut CraftApp) {/// A project mid-build: steps, the agent's words, collapsed tool work, a question and a check.pub fn fill_project(app: &mut CraftApp) {- use crate::state::FeedItem;+ use crate::state::{FeedItem, UserItem};use craft_anything_ai::rebuild::Step;use craft_anything_engine::inbox::{Request, RequestKind};let mut ws = workspace("example-com", "example.com", "Recreate this website", TargetRef::Website { url: "https://example.com".into() }, Status::Ready, 2);@@ -290,7 +290,7 @@ pub fn fill_project(app: &mut CraftApp) {enabled: true,}];app.state.feed = vec![- FeedItem::User("Recreate this website".into()),+ FeedItem::User(UserItem::Text("Recreate this website".into())),FeedItem::Step { step: Step::Study, text: "Opening https://example.com in a private browser…".into() },FeedItem::Step { step: Step::Study, text: "Photographing the page and reading its layout…".into() },FeedItem::Step { step: Step::Build, text: "Building the first version…".into() },diff --git a/crates/ui-egui/src/just_ask.rs b/crates/ui-egui/src/just_ask.rsindex 263ba78a..54e7306d 100644--- a/crates/ui-egui/src/just_ask.rs+++ b/crates/ui-egui/src/just_ask.rs@@ -57,20 +57,21 @@ pub fn question_in(text: &str, just_ask: bool) -> Result<Option<String>, String>}}-/// Everything sent in a project, oldest first: its messages as they were typed, and its questions-/// where they were asked, as `/btw` so they stay questions when sent again.-pub fn prompts(feed: &[FeedItem], asked: &[Asked]) -> Vec<String> {+/// Everything sent in a project, oldest first: its messages as they were typed (with their+/// pictures), and its questions where they were asked, as `/btw` so they stay questions when sent+/// again.+pub fn prompts(feed: &[FeedItem], asked: &[Asked]) -> Vec<prompt_box::Prompt> {let mut out = Vec::new();let mut asked = asked.iter().peekable();for (i, item) in feed.iter().enumerate() {while let Some(a) = asked.next_if(|a| a.after <= i) {- out.push(format!("/btw {}", a.question));+ out.push(prompt_box::Prompt { text: format!("/btw {}", a.question), pictures: Vec::new() });}- if let FeedItem::User(shown) = item {- out.push(prompt_box::as_typed(shown).to_string());+ if let FeedItem::User(u) = item {+ out.push(prompt_box::Prompt { text: prompt_box::as_typed(u.text()).to_string(), pictures: u.pictures().to_vec() });}}- out.extend(asked.map(|a| format!("/btw {}", a.question)));+ out.extend(asked.map(|a| prompt_box::Prompt { text: format!("/btw {}", a.question), pictures: Vec::new() }));out}@@ -182,14 +183,34 @@ pub fn card(ui: &mut Ui, a: &mut Asked, glossary: bool) {#[cfg(test)]mod tests {use super::*;+ use crate::state::FeedItem;+ use crate::state::UserItem;#[test]fn prompts_keep_questions_where_they_were_asked() {let asked = |q: &str, after| Asked { question: q.into(), answer: None, after, collapsed: false, reveal: false };- let user = |t: &str| FeedItem::User(t.into());+ let user = |t: &str| FeedItem::User(UserItem::Text(t.into()));let feed = [user("A notes app"), FeedItem::Paused, user("Make it blue\n(1 picture attached)")];let list = [asked("why Rust", 1), asked("where are the files", 3)];- assert_eq!(prompts(&feed, &list), ["A notes app", "/btw why Rust", "Make it blue", "/btw where are the files"]);+ assert_eq!(+ prompts(&feed, &list).iter().map(|p| p.text.as_str()).collect::<Vec<_>>(),+ ["A notes app", "/btw why Rust", "Make it blue", "/btw where are the files"]+ );+ }++ #[test]+ fn a_prompt_brought_back_with_up_keeps_its_pictures() {+ let asked = |q: &str, after| Asked { question: q.into(), answer: None, after, collapsed: false, reveal: false };+ // The feed stores the shown text with its "(n pictures attached)" line, and the+ // pictures travel with the same UserItem.+ let pics = [std::path::PathBuf::from("attachments/picture-1.png")];+ let feed = [FeedItem::User(UserItem::new("Make it blue\n(1 picture attached)".to_string(), pics.to_vec()))];+ let list = [asked("where are the files", 1)];+ let out = prompts(&feed, &list);+ assert_eq!(out[0].text, "Make it blue");+ assert_eq!(out[0].pictures, pics);+ assert_eq!(out[1].text, "/btw where are the files");+ assert!(out[1].pictures.is_empty());}#[test]diff --git a/crates/ui-egui/src/project.rs b/crates/ui-egui/src/project.rsindex 248e988c..b6bfe2dd 100644--- a/crates/ui-egui/src/project.rs+++ b/crates/ui-egui/src/project.rs@@ -5,7 +5,7 @@use crate::i18n::{tr, trf};use crate::make::{self, resolve_target};-use crate::state::{FeedItem, MakeDraft, Modal, PlanStatus, PlanStep, Screen};+use crate::state::{FeedItem, MakeDraft, Modal, PlanStatus, PlanStep, Screen, UserItem};use crate::theme::{self, Tokens};use crate::{CraftApp, Done, chat, icons, prompt_box, widgets};use craft_anything_ai::AgentEvent;@@ -112,11 +112,11 @@ impl CraftApp {if self.state.make.request.trim() == request {self.state.make = MakeDraft::default();}- self.state.feed = vec![FeedItem::User(request)];- self.start_run(ws, Some(backend), None, None);+ self.state.feed = vec![FeedItem::User(UserItem::Text(request))];+ self.start_run(ws, Some(backend), None, None, Vec::new());}- fn run_options(&self, backend: Option<String>, message: Option<String>, shown: Option<String>) -> RunOptions {+ fn run_options(&self, backend: Option<String>, message: Option<String>, shown: Option<String>, pictures: Vec<PathBuf>) -> RunOptions {let build = &self.settings.build;// Each event repaints the window, so a build needs no timer to show its progress.let wake = self.jobs.repaint_ctx().cloned().map_or_else(Default::default, |ctx| rebuild::Wake::new(move || ctx.request_repaint()));@@ -125,6 +125,7 @@ impl CraftApp {backend,message,shown,+ shown_pictures: pictures,beginner: self.beginner(),kinds: self.kinds.clone(),max_rounds: build.max_rounds,@@ -139,9 +140,10 @@ impl CraftApp {self.runs.start(&self.hub, ws, opts)}- /// `shown`: the person's message as the feed shows it (already in the app's feed).- fn start_run(&mut self, ws: Workspace, backend: Option<String>, message: Option<String>, shown: Option<String>) {- let opts = self.run_options(backend, message, shown);+ /// `shown`: the person's message as the feed shows it (already in the app's feed), and the+ /// pictures attached to it (their copies in the project).+ fn start_run(&mut self, ws: Workspace, backend: Option<String>, message: Option<String>, shown: Option<String>, pictures: Vec<PathBuf>) {+ let opts = self.run_options(backend, message, shown, pictures);self.start_run_with(ws, opts);}@@ -190,10 +192,10 @@ impl CraftApp {return;}if let Some(t) = &text {- self.state.feed.push(FeedItem::User(t.clone()));+ self.state.feed.push(FeedItem::User(UserItem::Text(t.clone())));}let shown = text.clone();- self.resume(text, shown);+ self.resume(text, shown, Vec::new());}/// Carry on where the open project's last run stopped (paused, or the app or the computer@@ -205,7 +207,7 @@ impl CraftApp {let Some(ws) = self.workspace.clone() else { return };let Some(backend) = self.builder_backend(ws.manifest.builder.as_deref()) else { return self.need_builder(false) };let ws = Workspace::open(&ws.root).unwrap_or(ws);- let opts = RunOptions { continuing: true, ..self.run_options(Some(backend), None, None) };+ let opts = RunOptions { continuing: true, ..self.run_options(Some(backend), None, None, Vec::new()) };self.start_run_with(ws, opts);}@@ -294,6 +296,7 @@ impl CraftApp {let left = self.runs.get(&root).map(RebuildRun::take_notes).unwrap_or_default();let join = |part: fn(&Note) -> &str| left.iter().map(part).collect::<Vec<_>>().join("\n\n");let (message, shown) = (join(|n| &n.text), join(|n| &n.shown));+ let pictures: Vec<PathBuf> = left.iter().flat_map(|n| n.pictures.clone()).collect();if open.as_ref() == Some(&root) {if let Some(ws) = self.workspace.as_mut() {let _ = ws.reload();@@ -302,14 +305,14 @@ impl CraftApp {if matches!(self.state.feed.last(), Some(FeedItem::Paused)) {self.state.feed.pop();}- self.state.feed.push(FeedItem::User(shown.clone()));- self.resume(Some(message), Some(shown));+ self.state.feed.push(FeedItem::User(UserItem::new(shown.clone(), pictures.clone())));+ self.resume(Some(message), Some(shown), pictures);}} else if !left.is_empty() {// Another project's notes start its next run in the background.let Ok(ws) = Workspace::open(&root) else { continue };let Some(backend) = self.builder_backend(ws.manifest.builder.as_deref()) else { continue };- let opts = self.run_options(Some(backend), Some(message), Some(shown));+ let opts = self.run_options(Some(backend), Some(message), Some(shown), pictures);if let Err(e) = self.launch(ws, opts) {self.toast(e.message, true);}@@ -1113,7 +1116,7 @@ fn draw_items(for (i, item) in items.iter().enumerate() {questions_up_to(app, ui, i);ui.push_id(i, |ui| match item {- FeedItem::User(text) => chat::user_bubble(ui, text, false),+ FeedItem::User(text) => chat::user_bubble(ui, text.text(), false),FeedItem::Step { text, .. } => chat::activity_row(ui, RichText::new(text).color(t.text_dim).size(theme::SMALL)),FeedItem::Paused => chat::activity_row(ui, RichText::new(tr("Paused.")).color(t.text_dim).size(theme::SMALL)),FeedItem::Agent { text, streaming } => {@@ -1558,6 +1561,10 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, t: &Tokens) {if let Some(i) = out.remove {app.state.project_attachments.remove(i);}+ // A past prompt brought back with Up (or the draft with Down) holds its own pictures.+ if let Some(pictures) = out.restore {+ app.state.project_attachments = pictures;+ }if out.attach {app.pick(crate::Pick::Attach);}@@ -1676,12 +1683,12 @@ impl CraftApp {match self.open_run() {Some(run) if run.is_running() => {// It joins the feed when the builder reads it; until then it can be taken back.- let id = run.add_note(message, shown);+ let id = run.add_note(message, shown, files.clone());self.drafts.insert(id, Draft { root: ws.root.clone(), text, attachments });}_ => {- self.state.feed.push(FeedItem::User(shown.clone()));- self.resume(Some(message), Some(shown));+ self.state.feed.push(FeedItem::User(UserItem::new(shown.clone(), files.clone())));+ self.resume(Some(message), Some(shown), files);}}}@@ -1697,12 +1704,12 @@ impl CraftApp {}/// Start another run on the open project: with a message (already shown in the app's feed;- /// `shown` puts it in the saved one), or none to try again.- fn resume(&mut self, message: Option<String>, shown: Option<String>) {+ /// `shown` puts it in the saved one, with `pictures`), or none to try again.+ fn resume(&mut self, message: Option<String>, shown: Option<String>, pictures: Vec<PathBuf>) {let Some(ws) = self.workspace.clone() else { return };let ws = Workspace::open(&ws.root).unwrap_or(ws);let Some(backend) = self.builder_backend(ws.manifest.builder.as_deref()) else { return self.need_builder(false) };- self.start_run(ws, Some(backend), message, shown);+ self.start_run(ws, Some(backend), message, shown, pictures);}}diff --git a/crates/ui-egui/src/prompt_box.rs b/crates/ui-egui/src/prompt_box.rsindex 2c3065be..4ef93cbc 100644--- a/crates/ui-egui/src/prompt_box.rs+++ b/crates/ui-egui/src/prompt_box.rs@@ -11,6 +11,13 @@ use crate::{icons, widgets};use egui::{Margin, RichText, Ui};use std::path::PathBuf;+/// An earlier prompt: what was typed, and the pictures attached to it.+#[derive(Debug, Clone, Default, PartialEq)]+pub struct Prompt {+ pub text: String,+ pub pictures: Vec<PathBuf>,+}+/// How one prompt box looks and behaves.pub struct PromptBox<'a> {/// The accessible name, and the id of the text field.@@ -29,38 +36,50 @@ pub struct PromptBox<'a> {/// A sent message is still waiting and can be taken back: Up at the start of the box asks for it.pub recall: bool,/// Earlier prompts, oldest first, for Up and Down; read only when a key asks for them.- pub history: Option<&'a dyn Fn() -> Vec<String>>,+ pub history: Option<&'a dyn Fn() -> Vec<Prompt>>,pub font_size: f32,}-/// Going through earlier prompts: how far back, and what the box holds for it to still count.+/// Going through earlier prompts: how far back (0 is what was being typed), and what the box+/// holds for it to still count.#[derive(Debug, Clone, Default, PartialEq)]struct Browsing {back: usize,shown: String,/// What was being typed, for Down past the newest.draft: String,+ /// The pictures attached to what was being typed.+ draft_pictures: Vec<PathBuf>,+ /// The pictures of the prompt showing.+ shown_pictures: Vec<PathBuf>,}/// The prompt before the one showing; none when there's no earlier one.-fn older(history: &[String], now: Option<&Browsing>, text: &str) -> Option<Browsing> {+fn older(history: &[Prompt], now: Option<&Browsing>, text: &str, pictures: &[PathBuf]) -> Option<Browsing> {let back = now.map_or(1, |b| b.back + 1);- let shown = history.get(history.len().checked_sub(back)?)?.clone();- Some(Browsing { back, shown, draft: now.map_or_else(|| text.to_string(), |b| b.draft.clone()) })+ let p = history.get(history.len().checked_sub(back)?)?;+ Some(Browsing {+ back,+ shown: p.text.clone(),+ draft: now.map_or_else(|| text.to_string(), |b| b.draft.clone()),+ draft_pictures: now.map_or_else(|| pictures.to_vec(), |b| b.draft_pictures.clone()),+ shown_pictures: p.pictures.clone(),+ })}/// The prompt after the one showing, or what was being typed once past the newest.-fn newer(history: &[String], now: &Browsing) -> Result<Browsing, String> {+fn newer(history: &[Prompt], now: &Browsing) -> Browsing {let back = now.back.saturating_sub(1);match history.len().checked_sub(back).and_then(|i| history.get(i)) {- Some(shown) if back > 0 => Ok(Browsing { back, shown: shown.clone(), draft: now.draft.clone() }),- _ => Err(now.draft.clone()),+ Some(p) if back > 0 => Browsing { back, shown: p.text.clone(), shown_pictures: p.pictures.clone(), ..now.clone() },+ _ => Browsing { back: 0, shown: now.draft.clone(), shown_pictures: now.draft_pictures.clone(), ..now.clone() },}}/// Up at the start or Down at the end went through earlier prompts: consumed before the field/// sees them. Up leaves the cursor at the start and Down at the end, so pressing it again goes on.-fn browse(ui: &mut Ui, id: egui::Id, text: &mut String, history: &dyn Fn() -> Vec<String>) {+/// Returns the pictures the box should hold now, when it moved to another prompt.+fn browse(ui: &mut Ui, id: egui::Id, text: &mut String, attachments: &[PathBuf], history: &dyn Fn() -> Vec<Prompt>) -> Option<Vec<PathBuf>> {let key = id.with("history");// Editing what came back, or sending it, ends going through them.let now = ui.data_mut(|d| d.get_temp::<Browsing>(key)).filter(|b| b.shown == *text);@@ -72,26 +91,23 @@ fn browse(ui: &mut Ui, id: egui::Id, text: &mut String, history: &dyn Fn() -> Velet plain = egui::Modifiers::NONE;let up = at_start(ui.ctx(), id, text) && ui.input_mut(|i| i.consume_key(plain, egui::Key::ArrowUp));let next = if up {- older(&list(), now.as_ref(), text).map(Ok)+ older(&list(), now.as_ref(), text, attachments)} else {now.as_ref().filter(|_| at_end(ui.ctx(), id, text) && ui.input_mut(|i| i.consume_key(plain, egui::Key::ArrowDown))).map(|b| newer(&list(), b))};- match next {- Some(Ok(b)) => {- text.clone_from(&b.shown);- ui.data_mut(|d| d.insert_temp(key, b));- }- Some(Err(draft)) => {- *text = draft;- ui.data_mut(|d| d.remove_temp::<Browsing>(key));- }- None => return,+ let b = next?;+ text.clone_from(&b.shown);+ if b.back == 0 {+ ui.data_mut(|d| d.remove_temp::<Browsing>(key));+ } else {+ ui.data_mut(|d| d.insert_temp(key, b.clone()));}if up {cursor_to(ui.ctx(), id, 0);} else {cursor_to_end(ui.ctx(), id, text);}+ Some(b.shown_pictures)}/// What the person did with it this frame.@@ -105,6 +121,9 @@ pub struct PromptOut {pub recall: bool,/// The attachment to remove.pub remove: Option<usize>,+ /// Up or Down moved to another prompt: the pictures the box should hold now (the draft's own+ /// when it came back to what was being typed). `None` leaves them as they are.+ pub restore: Option<Vec<PathBuf>>,}pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBox) -> PromptOut {@@ -157,7 +176,7 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBoout.recall = true;ui.data_mut(|d| d.insert_temp(to_end, true));} else if let Some(history) = b.history.filter(|_| focused && !b.recall) {- browse(ui, id, text, history);+ out.restore = browse(ui, id, text, attachments, history);}// What Tab would complete to, when the box starts with a partial command name. egui// decides keyboard navigation at the start of the pass, so the field keeps Tab only@@ -314,15 +333,34 @@ mod tests {#[test]fn up_goes_back_through_prompts_and_down_returns_to_what_was_being_typed() {- let list = ["one".to_string(), "two".to_string()];- let first = older(&list, None, "half a thou").unwrap();+ let list = [Prompt { text: "one".into(), ..Default::default() }, Prompt { text: "two".into(), ..Default::default() }];+ let first = older(&list, None, "half a thou", &[]).unwrap();assert_eq!((first.shown.as_str(), first.draft.as_str()), ("two", "half a thou"));- let second = older(&list, Some(&first), &first.shown).unwrap();+ let second = older(&list, Some(&first), &first.shown, &[]).unwrap();assert_eq!((second.shown.as_str(), second.draft.as_str()), ("one", "half a thou"));- assert_eq!(older(&list, Some(&second), &second.shown), None, "the oldest stays");- assert_eq!(newer(&list, &second).unwrap().shown, "two");- assert_eq!(newer(&list, &first), Err("half a thou".to_string()));- assert_eq!(older(&[], None, ""), None);+ assert_eq!(older(&list, Some(&second), &second.shown, &[]), None, "the oldest stays");+ assert_eq!(newer(&list, &second).shown, "two");+ let draft = newer(&list, &first);+ assert_eq!((draft.back, draft.shown.as_str()), (0, "half a thou"), "past the newest is the draft");+ assert_eq!(older(&[], None, "", &[]), None);+ }++ #[test]+ fn each_prompt_brings_back_its_own_pictures_and_the_draft_its_own() {+ let one = Prompt { text: "one".into(), pictures: vec![PathBuf::from("a.png")] };+ let two = Prompt { text: "two".into(), pictures: vec![PathBuf::from("b.png"), PathBuf::from("c.png")] };+ let list = [one.clone(), two.clone()];+ let draft_pictures = vec![PathBuf::from("draft.png")];+ let first = older(&list, None, "half a thou", &draft_pictures).unwrap();+ assert_eq!(first.shown_pictures, two.pictures, "the newest prompt's pictures");+ assert_eq!(first.draft_pictures, draft_pictures, "the draft's are kept for Down");+ let second = older(&list, Some(&first), &first.shown, &draft_pictures).unwrap();+ assert_eq!(second.shown_pictures, one.pictures, "the earlier prompt's own pictures");+ let back = newer(&list, &second);+ assert_eq!((back.shown.as_str(), back.shown_pictures.clone()), ("two", two.pictures.clone()));+ let draft = newer(&list, &back);+ assert_eq!((draft.back, draft.shown.as_str()), (0, "half a thou"));+ assert_eq!(draft.shown_pictures, draft_pictures, "the draft's own pictures come back");}#[test]diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex b555ee00..83a61c7a 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -96,7 +96,7 @@ impl Default for MakeDraft {}}-pub use craft_anything_ai::rebuild::feed::{FeedItem, PlanStatus, PlanStep};+pub use craft_anything_ai::rebuild::feed::{FeedItem, PlanStatus, PlanStep, UserItem};/// The first-run steps. Never more than four.#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rsindex 29b1428e..e0636e36 100644--- a/crates/ui-egui/tests/smoke.rs+++ b/crates/ui-egui/tests/smoke.rs@@ -225,7 +225,7 @@ fn deep_mode_without_ghidra_asks_to_get_it_before_using_it() {#[test]fn a_long_prompt_wraps_inside_the_window_in_the_project_and_the_chat() {- use craft_anything_ui_egui::state::{ChatItem, FeedItem};+ use craft_anything_ui_egui::state::{ChatItem, FeedItem, UserItem};// Long sentences and one very long unbroken address.let long = format!("{}https://example.com/{}", "Make it exactly like the original, with the same menus, weapons and maps. ".repeat(8), "a".repeat(300));for in_chat in [false, true] {@@ -238,8 +238,8 @@ fn a_long_prompt_wraps_inside_the_window_in_the_project_and_the_chat() {a.state.chat.push(ChatItem::User("Make it blue".into()));} else {demo::fill_project(&mut a);- a.state.feed.push(FeedItem::User(text));- a.state.feed.push(FeedItem::User("Make it blue".into()));+ a.state.feed.push(FeedItem::User(UserItem::Text(text)));+ a.state.feed.push(FeedItem::User(UserItem::Text("Make it blue".into())));}a});@@ -305,7 +305,7 @@ fn an_engine_download_shows_in_the_title_bar_on_every_screen() {#[test]fn a_projects_conversation_and_place_come_back_after_a_restart() {use craft_anything_engine::workspace::{TargetRef, Workspace};- use craft_anything_ui_egui::state::FeedItem;+ use craft_anything_ui_egui::state::{FeedItem, UserItem};struct Mem(std::collections::HashMap<String, String>);impl eframe::Storage for Mem {fn get_string(&self, key: &str) -> Option<String> {@@ -325,7 +325,7 @@ fn a_projects_conversation_and_place_come_back_after_a_restart() {// One session: a conversation on the project, then the app closes.let mut first = demo::app(demo::engine(Mode::Beginner, true));first.open_workspace(ws);- first.state.feed.push(FeedItem::User("Make it faster".into()));+ first.state.feed.push(FeedItem::User(UserItem::Text("Make it faster".into())));first.state.feed.push(FeedItem::Agent { text: "Done: the snake moves faster now.".into(), streaming: true });// A run keeps the feed in the project folder (here, as one would have).let root = first.workspace.as_ref().unwrap().root.clone();@@ -339,7 +339,7 @@ fn a_projects_conversation_and_place_come_back_after_a_restart() {assert_eq!(next.state.screen, Screen::Project);assert_eq!(next.workspace.as_ref().map(|w| w.manifest.name.as_str()), Some("Snake"));let feed = &next.state.feed;- assert!(feed.iter().any(|f| matches!(f, FeedItem::User(t) if t == "Make it faster")), "{feed:?}");+ assert!(feed.iter().any(|f| matches!(f, FeedItem::User(t) if t.text() == "Make it faster")), "{feed:?}");assert!(feed.iter().any(|f| matches!(f, FeedItem::Agent { text, streaming: false } if text.starts_with("Done:"))),"nothing is still streaming after a restart: {feed:?}"@@ -426,7 +426,11 @@ fn the_prompt_box_sends_on_enter_with_its_pictures() {assert!(root.join("attachments/picture-1.png").is_file(), "the picture is copied into the project");assert!(h.state().state.project_input.is_empty() && h.state().state.project_attachments.is_empty());assert!(- h.state().state.feed.iter().any(|f| matches!(f, FeedItem::User(t) if t.starts_with("Make it faster\nand louder") && t.contains("1 picture attached"))),+ h.state()+ .state+ .feed+ .iter()+ .any(|f| matches!(f, FeedItem::User(t) if t.text().starts_with("Make it faster\nand louder") && t.text().contains("1 picture attached"))),"{:?}",h.state().state.feed);@@ -1227,7 +1231,7 @@ fn a_note_waiting_for_the_builder_can_be_taken_back_into_the_prompt_box() {h.state_mut().send_message();}h.run_steps(3);- let in_feed = |app: &CraftApp, text: &str| app.state.feed.iter().any(|f| matches!(f, FeedItem::User(t) if t == text));+ let in_feed = |app: &CraftApp, text: &str| app.state.feed.iter().any(|f| matches!(f, FeedItem::User(t) if t.text() == text));assert!(!in_feed(h.state(), "Make them blue"));h.get_by_label("Make them blue");h.get_by_label("And sortable");@@ -1238,7 +1242,7 @@ fn a_note_waiting_for_the_builder_can_be_taken_back_into_the_prompt_box() {assert_eq!(h.state().state.project_input, "Make them blue\ndraft");assert!(h.query_by_label("Make them blue").is_none());// The builder reads the other: it joins the conversation and can't be taken back.- assert!(runs.send(&a.root, RunEvent::Note("And sortable".into())));+ assert!(runs.send(&a.root, RunEvent::Note { shown: "And sortable".into(), pictures: Vec::new() }));h.run_steps(2);assert!(in_feed(h.state(), "And sortable"));h.state_mut().pause();@@ -1289,7 +1293,7 @@ fn up_in_the_prompt_box_takes_back_the_last_waiting_note() {fn up_and_down_in_the_prompt_box_go_through_earlier_prompts() {use craft_anything_ai::rebuild::StandIns;use craft_anything_engine::workspace::{TargetRef, Workspace};- use craft_anything_ui_egui::state::FeedItem;+ use craft_anything_ui_egui::state::{FeedItem, UserItem};let d = tempfile::tempdir().unwrap();let a = Workspace::create(d.path(), "Alpha", "A notes app", TargetRef::None).unwrap();let (dir, runs) = (d.path().to_path_buf(), StandIns::new());@@ -1297,7 +1301,7 @@ fn up_and_down_in_the_prompt_box_go_through_earlier_prompts() {h.run_steps(2);h.state_mut().open_workspace(a);h.run_steps(2);- let user = |t: &str| FeedItem::User(t.into());+ let user = |t: &str| FeedItem::User(UserItem::Text(t.into()));h.state_mut().state.feed = vec![user("A notes app"), user("Make it blue\n(1 picture attached)"), user("Make it blue"), user("First line\nSecond line")];h.state_mut().state.project_input = String::new();h.get_by_label("Ask for a change").focus();diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex b11e051b..9ba8f746 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -406,7 +406,8 @@ Owner: maintainers · Status: in progress### R2.9 Everyday use: typing, projects, settingsOwner: maintainers · Status: in progressGaps found while using the app for real projects.-- [ ] A prompt brought back with Up keeps its pictures (only the text comes back now) — in PR #216+- [x] A prompt brought back with Up keeps its pictures (their paths are absolute, so they don't+ come back after the project is moved)- [ ] Change a project's builder from its page (a tool, so the CLI and MCP can too) — in PR #245- [ ] When the builder decides a question, show the question and its choice as an answered cardin the feed (the run sees only the tool call today; the builder's words say what it chose)diff --git a/docs/file-formats.md b/docs/file-formats.mdindex 179bf657..4af988d6 100644--- a/docs/file-formats.md+++ b/docs/file-formats.md@@ -17,7 +17,11 @@ version up to the current one, then turn the document into Rust types. The step| `<project>/questions.json` | `engine::questions` (`AskedQuestion`, written by `rebuild_question_ask`) | `QUESTIONS_VERSION` = 1 (`{version, items}`) | read as before | read as far as its fields are known || `<project>/pinned/<n>/pin.json` | `engine::pins` (`Pin`) | `PIN_VERSION` = 2 (`version`; missing = 1; 2 records the selected program for a copied direct launch) | brought forward | read as far as its fields are known || `<folder>/standin.json` | `engine::tools::standin_tools` (`analysis::standin::StandIn`; written only by `web_standin_build`) | `STANDIN_VERSION` = 1 (`version`, required) | brought forward | refused, with "update Craft Anything", and never written over |-| `<project>/feed.json` | `ai::rebuild::feed` (written by the run) | `FEED_VERSION` = 2 (`{version, items}`; a bare list = 0) | read as before, saved as current | never written over; the conversation is rebuilt from the project for display |+| `<project>/feed.json` | `ai::rebuild::feed` (written by the run) | `FEED_VERSION` = 3 (`{version, items}`; a bare list = 0) | read as before, saved as current | never written over; the conversation is rebuilt from the project for display |++A saved `User` message with pictures is `{text, pictures: [paths]}`, where the pictures are the+copies in the project's `attachments/`; one without pictures stays the plain string earlier+versions wrote.Other JSON in a project (`assets.json`, `inbox/`, `checks/`, evidence records) has no version yet;add one the first time its shape changes.