From a32c8c404b53570ce8897b5f80fb0854b3fe54db Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 20:59:35 +0100 Subject: [PATCH 1/3] A chat compacted before #17 comes back with its last answer at its end For a chat compacted before compactions kept what they replaced, what was set aside before the compaction stood past the messages kept, and the thread placed it, with all that was set aside after it, below the last answer: old steps and errors piled up under it. What stands past the messages kept and came before something set aside among them now comes first; what truly came last stays at the end; and what stands among the messages is placed by where it stands. --- AGENTS.md | 2 +- crates/ui/src/crew.rs | 68 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e9deed8..ef41476 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ Separation of concerns is **enforced by the crate dependency graph**, not by con | `iq-core` | Domain types and traits, zero I/O, zero network | | `iq-llm` | Model providers, one `impl ChatModel` per protocol: Requesty's router, and any OpenAI compatible endpoint, every call saying it comes from iq (`User-Agent: iq/`), with the models it lists and their prices, dearer past a size of conversation where its tiers say, and whether an error says the provider is out of capacity for now (a quota for the minute, an overload, a connection never made) with how long it asked to be left, from its headers or its words; what it said as it refused a call, in its own words (`Refusal`); the signature a model gives its reasoning kept with its answer and sent back as it came; Claude's requests marked for the cache by iq itself, and those of any model whose name holds a word the settings' `cache_marks` give, the others left to the router | | `iq-gate` | The one gate every action goes through (reading or writing a file, a folder listed, `~/` read as the home, running a command line, reaching the network, a page or a search given as a command with the internet is, calling a tool of a server the person declared, one its server says only reads judged as reaching the internet and any other the person's alone to give), judged by what it reaches and by rules on commands, written to the audit log before it is taken, a refusal written with its reason as an approval is; what waits for a login at a terminal or in a browser, which nobody can give an agent's command, refused by the rules; files read and written under a permit, where they were judged; the person's skills, a folder of secrets often, opened to an agent when the crew says so (`judge_with`): a Markdown file of the folders the settings give (`GateBuilder::skills`) read, each change of one asked of the person alone, never a reviewer, whose policy is one of them, nothing else opening with them (a file whose name says it holds secrets, a link leading out of them, the rest of `~/.iq`); the agents' folder of scratch, outside the workspace, where commands write and files are read and written without asking, a chat's given to its commands as `IQ_SCRATCH`, its oldest files taken once it grows past its size; the model each agent is started on or given written to the audit log with who chose it and how; the sandbox commands run in (Landlock and seccomp on Linux, with a network of the sandbox's own where only localhost answers; Seatbelt on macOS), their secrets kept out and their output cleared of the workspace's, git's hooks put back after them, each stopped past the time the settings give it or once it wrote nothing for as long as they say (one waiting for an answer nobody can give it), and stopped with its group when its agent is stopped; the commands the rules say need the machine itself, or an agent asks it for, run there once approved, with the person's environment but iq's own variables, their output cleared and hooks put back the same; every command, in the sandbox or on the machine, leading a session of its own with no terminal, so that what would ask at one (ssh, sudo, a pinentry) fails at once instead of writing over iq's screen and waiting there, and git and ssh told never to ask (`GIT_TERMINAL_PROMPT=0`, ssh in batch mode unless the person named their own, in their environment or git's settings); a gate for another folder as the crew's own (its rules, its audit log, and what the person opened shared), as a worktree of the project is, the repository's own folder writable from it and the hooks it keeps put back; the variables a program of the person's gives a place, which every command run there gets, in the sandbox or on the machine, none of those the sandbox and the shell rest on nor a secret, each given written to the audit log with what that program said it ran | -| `iq-agent` | The crew: iq's agents (a model of the provider in a loop with its tools, each acting through the gate, each file one writes or edits said with how its lines changed, a unified diff with three lines around each change, what both ends share at their start and their end set aside first, a line past 400 characters cut (`diff.rs`, `Event::Changed`), before the step that wrote it, never for a file of secrets, as the agent named it or as the file the gate judged it written to is (`~/` read as the gate's home, a link followed), whose lines the person allowed written but not shown), the board they write to each other and to the person on (a message waking its reader a few times in a while, one posted while its reader worked waking it as its turn ends, a peer's under the same limit, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most, or, with `until_done`, until none of them works or one asks it something, then given all they wrote at once, once the board stayed quiet a moment), the patterns the person may start a team in (solo, a lead and the agents it starts, a writer and its reviewer, a debate), each hand-over decided by iq from how a turn ended, never by a model, the teams an agent starts with the roles, models and efforts it gives them, as the person's skills tell it (each model named whole as the provider lists it, and one the person's settings allow when they list some, any other refused with those there are, so that the agent chooses again; each choice of a model, the person's or an agent's, written to the audit log and kept with its chat, with who made it and how) (the first member working at once and answering whoever started the team, the others waiting until a teammate writes and answering the first), each agent another starts named after its chat and its part (`/review`, `/2`), so that it never takes a chat's name, and retired once done with its task (its answer reached who started it, alone or, in a team, once the team's first answered; none of them working, written to by the person, with a command running, a wake waiting, a message unread or an agent of its own on the board): off the board, its name free again for the next, its chat file kept apart (`Keeper::retire`) as long as its chat, what writes to it told it finished with its last answer (`Event::Retired`), the rules agents follow (the person's own files, iq's `~/.iq/AGENTS.md`, else `~/.claude/CLAUDE.md`, unless the settings list others, then the project's `AGENTS.md`, `CLAUDE.md` and those of its `.claude/rules` for the whole project, a file imported twice given once, the project's read where the agent works) given only to the agents the person starts, the rules of `.claude/rules` whose head names `paths` given to any agent as it first reads or writes one of those files, the leads told which there are, as are the extensions for leads, those agents giving the ones they start what their part needs, and every agent another started told to pass on in turn what those it starts need of its task, each agent told its chat's folder of scratch, outside the workspace, where it keeps what outlives one command, and the models the person allows when they list some, each agent told its conversation's size each time it grows by a step the settings set, and where its model's price rises when the provider's list says, and, past the size it should stay under (`compact_at`, else where its model's price rises), told at once and again as each turn begins past it to finish its request, then compact before it answers, `look_back` finding again what its compactions replaced (`look_back.rs`: its messages numbered, by the words they hold or on from a number, each cut past 4,000 characters and 24,000 in all), and compacting it with its own summary once its request is done, when its skills say (what it replaced kept with the chat, whole and in order, but for what the compaction before wrote, `Saved::compacted_away`, so that the chat comes back as it was shown, `Saved::history`, what was set aside placed among those messages, and the model each turn answers on set aside as it begins when it changed, `Shown::Model`, the turn's head naming it as the chat comes back), its old tool results set apart once its calls read past what the settings say (all but the latest six, the long ones), each replaced by a line saying what it was, `reread` reading it again whole, then again each time what its calls read grew as much, so that the provider's cache breaks seldom, the person told each time, each chat's turn (from the person's request to a chat none of whose agents works) counted as it spends, its agents', the reviewer's for them and the summaries' of their messages (`Event::Turn`, each `Event::Spent` naming the chat it served), the person asked once for all the chat's agents, before their next call, whether it goes on once it spent what the settings let a turn spend, with what each spent, then as much again each time, a turn stopped failing every agent of the chat at its next call until the person writes again, each agent thinking as hard as it was started with (the lead choosing its agents') or changed to by the person, the reviewer that answers for the person when the autopilot is on, thinking as hard as the settings say, given its selected local skill again for each decision, told the agent's task as its chat started, what the person asked of it since (kept with the chat), what started its turn under way when a teammate did, its last actions with how they ended, so that a policy may rest on what was just done, and what the agent wrote just before the action, a few hundred characters given as its own claim, never the person's word (nothing else of its conversation: no file, output or page it read), told where the action runs and, for a `make` target, what its recipe and those it depends on do, read from the Makefile that makes it where the agent works (in the folder a `cd` or make's `-C` names, a recipe handing its work to a folder's Makefile followed there) (what stays within the sandbox, what only reaches the internet and what runs on the machine itself unless the settings keep those for the person, the machine's being the reviewer's once a skill says what runs there; publishing, what changes what others share, files outside the workspace and secrets never), an agent's next action asked of the person after as many refusals in a row as the settings say, the person told once, when a chat writes in a folder another chat of the session wrote in within half an hour (a file written or edited, a command run), naming the other, each agent the person starts given a place of its own when they want one (a folder apart from their checkout, as a worktree is, made by what the binary gives the crew for it), the agents it starts working there with it, and one that could not be given its place not started, the person told why, each chat given to a keeper as it joins (with what the person was shown of each agent beside its conversation, each where it came among its messages: iq's notices, its questions with their answers, what the gate asked and the autopilot answered, its errors, and the calls it made with what they cost), as the person writes to it (when they last did kept with it), as its turn goes, after each round of its tools, so that iq ended or crashed in the middle of a turn finds it where it stopped (a turn the person stops kept as it was before it), and at every turn's end, and put back on the board from what was kept, resting, its instructions written again, in its place when it still has one, an agent the person renames going on under its new name, during a turn too (shown and written to under it at once, taken as its turn ends), the agents of its chat named after it with it (what was written to it, the agents it started and its teams following it, what is written to its old name reaching it, kept under the new one), each chat the person did not name named after what its work is about by the cheap model the settings give (its subject, never a verb of asking nor a politeness), its cost shown as any call's, unless the person names it first, the person's skills opened to the agents of one chat until the turn they serve ends (the one under way, else the next), shut once none of its agents works, as a later turn begins or as the person says, said in the chat each time (`Event::Skills`), the agents told with their next call that they are open and where, and that they shut, each file written or edited asked of the person with what it becomes, as a unified diff, when the agent may read it (`Event::Asked::preview`), an agent answered from its next turn by the model the person gives it (the reasoning its answers carry, which only the provider that signed it checks against all that came before it, taken off then, their text whole, as it is whenever iq changes what came before: old results set apart, from the first one changed, other tools offered, a chat resumed under other instructions; a call still refused for a signature sent again without the reasoning of the earlier turns, then without any), a call to a provider out of capacity sent again as many times as the settings say, after as long as it asks and a wait doubling at each try, each wait said, then the turn ended saying the conversation is kept to go on later or on another model, a call to a model the settings give backups (`[backups]`) going to the next of them, with a notice and without the reasoning, when it gets no answer within `backup_after` or its provider is out of capacity (at once, without the tries), never when it is refused, the backup answering for the rest of the turn and billed as the model that answered, the last one waited for as before, a call the provider refused reported with its status, the provider's own words, the model, about how many tokens it held and what the agent had spent until then (`Event::Failed`, which the binary writes to iq's log), the agent that started the failed one told those facts as iq's, never left to an agent to tell, and the tools another part of iq offers some agents as an extension, read again at each call so that one an agent asked for is offered from its next step, whose calls act through the crew and ask the person through it, an extension answering a call of a tool it has not described whole yet, and showing a model an image after its step's results (an image a file holds, read with `read_file`, a folder listed the latest first; one an MCP tool answers with; one the person attached, with a chat's task or a message); `ask_person`, a question with two to four choices for the person, its answer kept with what they asked of the agent, an agent another started asking that agent first (a message it must answer, with iq's account of the asker's role and what it spent, which it answers or puts to the person, who is then told who raised it, through whom, and what they spent), so that the person is never asked the same thing by several agents at once, every agent told to stop and ask rather than go on alone past its part, its brief or its budget, or with what it found of uncertain worth; `run` that failed in the sandbox for want of the person's ssh keys, as its output shows, told that a git command reaching a remote over ssh runs on the machine; `run` left in the background, read as it runs, stopped, its end waking its agent, its latest lines said at most twice a second as they change (`Event::JobOutput`) and the end of its output said with its end; `wake_me`, a wake after a time the agent chooses, three waiting at once and twelve within an hour, so that an agent waking itself again and again is held; whom a chat waits for said (`Event::Waiting`). Generic over `ChatModel` | +| `iq-agent` | The crew: iq's agents (a model of the provider in a loop with its tools, each acting through the gate, each file one writes or edits said with how its lines changed, a unified diff with three lines around each change, what both ends share at their start and their end set aside first, a line past 400 characters cut (`diff.rs`, `Event::Changed`), before the step that wrote it, never for a file of secrets, as the agent named it or as the file the gate judged it written to is (`~/` read as the gate's home, a link followed), whose lines the person allowed written but not shown), the board they write to each other and to the person on (a message waking its reader a few times in a while, one posted while its reader worked waking it as its turn ends, a peer's under the same limit, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most, or, with `until_done`, until none of them works or one asks it something, then given all they wrote at once, once the board stayed quiet a moment), the patterns the person may start a team in (solo, a lead and the agents it starts, a writer and its reviewer, a debate), each hand-over decided by iq from how a turn ended, never by a model, the teams an agent starts with the roles, models and efforts it gives them, as the person's skills tell it (each model named whole as the provider lists it, and one the person's settings allow when they list some, any other refused with those there are, so that the agent chooses again; each choice of a model, the person's or an agent's, written to the audit log and kept with its chat, with who made it and how) (the first member working at once and answering whoever started the team, the others waiting until a teammate writes and answering the first), each agent another starts named after its chat and its part (`/review`, `/2`), so that it never takes a chat's name, and retired once done with its task (its answer reached who started it, alone or, in a team, once the team's first answered; none of them working, written to by the person, with a command running, a wake waiting, a message unread or an agent of its own on the board): off the board, its name free again for the next, its chat file kept apart (`Keeper::retire`) as long as its chat, what writes to it told it finished with its last answer (`Event::Retired`), the rules agents follow (the person's own files, iq's `~/.iq/AGENTS.md`, else `~/.claude/CLAUDE.md`, unless the settings list others, then the project's `AGENTS.md`, `CLAUDE.md` and those of its `.claude/rules` for the whole project, a file imported twice given once, the project's read where the agent works) given only to the agents the person starts, the rules of `.claude/rules` whose head names `paths` given to any agent as it first reads or writes one of those files, the leads told which there are, as are the extensions for leads, those agents giving the ones they start what their part needs, and every agent another started told to pass on in turn what those it starts need of its task, each agent told its chat's folder of scratch, outside the workspace, where it keeps what outlives one command, and the models the person allows when they list some, each agent told its conversation's size each time it grows by a step the settings set, and where its model's price rises when the provider's list says, and, past the size it should stay under (`compact_at`, else where its model's price rises), told at once and again as each turn begins past it to finish its request, then compact before it answers, `look_back` finding again what its compactions replaced (`look_back.rs`: its messages numbered, by the words they hold or on from a number, each cut past 4,000 characters and 24,000 in all), and compacting it with its own summary once its request is done, when its skills say (what it replaced kept with the chat, whole and in order, but for what the compaction before wrote, `Saved::compacted_away`, so that the chat comes back as it was shown, `Saved::history`, what was set aside placed among those messages (for a chat compacted before compactions kept what they replaced, what stands past its messages and came before something among them first, what truly came last at the end), and the model each turn answers on set aside as it begins when it changed, `Shown::Model`, the turn's head naming it as the chat comes back), its old tool results set apart once its calls read past what the settings say (all but the latest six, the long ones), each replaced by a line saying what it was, `reread` reading it again whole, then again each time what its calls read grew as much, so that the provider's cache breaks seldom, the person told each time, each chat's turn (from the person's request to a chat none of whose agents works) counted as it spends, its agents', the reviewer's for them and the summaries' of their messages (`Event::Turn`, each `Event::Spent` naming the chat it served), the person asked once for all the chat's agents, before their next call, whether it goes on once it spent what the settings let a turn spend, with what each spent, then as much again each time, a turn stopped failing every agent of the chat at its next call until the person writes again, each agent thinking as hard as it was started with (the lead choosing its agents') or changed to by the person, the reviewer that answers for the person when the autopilot is on, thinking as hard as the settings say, given its selected local skill again for each decision, told the agent's task as its chat started, what the person asked of it since (kept with the chat), what started its turn under way when a teammate did, its last actions with how they ended, so that a policy may rest on what was just done, and what the agent wrote just before the action, a few hundred characters given as its own claim, never the person's word (nothing else of its conversation: no file, output or page it read), told where the action runs and, for a `make` target, what its recipe and those it depends on do, read from the Makefile that makes it where the agent works (in the folder a `cd` or make's `-C` names, a recipe handing its work to a folder's Makefile followed there) (what stays within the sandbox, what only reaches the internet and what runs on the machine itself unless the settings keep those for the person, the machine's being the reviewer's once a skill says what runs there; publishing, what changes what others share, files outside the workspace and secrets never), an agent's next action asked of the person after as many refusals in a row as the settings say, the person told once, when a chat writes in a folder another chat of the session wrote in within half an hour (a file written or edited, a command run), naming the other, each agent the person starts given a place of its own when they want one (a folder apart from their checkout, as a worktree is, made by what the binary gives the crew for it), the agents it starts working there with it, and one that could not be given its place not started, the person told why, each chat given to a keeper as it joins (with what the person was shown of each agent beside its conversation, each where it came among its messages: iq's notices, its questions with their answers, what the gate asked and the autopilot answered, its errors, and the calls it made with what they cost), as the person writes to it (when they last did kept with it), as its turn goes, after each round of its tools, so that iq ended or crashed in the middle of a turn finds it where it stopped (a turn the person stops kept as it was before it), and at every turn's end, and put back on the board from what was kept, resting, its instructions written again, in its place when it still has one, an agent the person renames going on under its new name, during a turn too (shown and written to under it at once, taken as its turn ends), the agents of its chat named after it with it (what was written to it, the agents it started and its teams following it, what is written to its old name reaching it, kept under the new one), each chat the person did not name named after what its work is about by the cheap model the settings give (its subject, never a verb of asking nor a politeness), its cost shown as any call's, unless the person names it first, the person's skills opened to the agents of one chat until the turn they serve ends (the one under way, else the next), shut once none of its agents works, as a later turn begins or as the person says, said in the chat each time (`Event::Skills`), the agents told with their next call that they are open and where, and that they shut, each file written or edited asked of the person with what it becomes, as a unified diff, when the agent may read it (`Event::Asked::preview`), an agent answered from its next turn by the model the person gives it (the reasoning its answers carry, which only the provider that signed it checks against all that came before it, taken off then, their text whole, as it is whenever iq changes what came before: old results set apart, from the first one changed, other tools offered, a chat resumed under other instructions; a call still refused for a signature sent again without the reasoning of the earlier turns, then without any), a call to a provider out of capacity sent again as many times as the settings say, after as long as it asks and a wait doubling at each try, each wait said, then the turn ended saying the conversation is kept to go on later or on another model, a call to a model the settings give backups (`[backups]`) going to the next of them, with a notice and without the reasoning, when it gets no answer within `backup_after` or its provider is out of capacity (at once, without the tries), never when it is refused, the backup answering for the rest of the turn and billed as the model that answered, the last one waited for as before, a call the provider refused reported with its status, the provider's own words, the model, about how many tokens it held and what the agent had spent until then (`Event::Failed`, which the binary writes to iq's log), the agent that started the failed one told those facts as iq's, never left to an agent to tell, and the tools another part of iq offers some agents as an extension, read again at each call so that one an agent asked for is offered from its next step, whose calls act through the crew and ask the person through it, an extension answering a call of a tool it has not described whole yet, and showing a model an image after its step's results (an image a file holds, read with `read_file`, a folder listed the latest first; one an MCP tool answers with; one the person attached, with a chat's task or a message); `ask_person`, a question with two to four choices for the person, its answer kept with what they asked of the agent, an agent another started asking that agent first (a message it must answer, with iq's account of the asker's role and what it spent, which it answers or puts to the person, who is then told who raised it, through whom, and what they spent), so that the person is never asked the same thing by several agents at once, every agent told to stop and ask rather than go on alone past its part, its brief or its budget, or with what it found of uncertain worth; `run` that failed in the sandbox for want of the person's ssh keys, as its output shows, told that a git command reaching a remote over ssh runs on the machine; `run` left in the background, read as it runs, stopped, its end waking its agent, its latest lines said at most twice a second as they change (`Event::JobOutput`) and the end of its output said with its end; `wake_me`, a wake after a time the agent chooses, three waiting at once and twelve within an hour, so that an agent waking itself again and again is held; whom a chat waits for said (`Event::Waiting`). Generic over `ChatModel` | | `iq-observe` | What iq's work goes to: the journal's tasks, the categories of work the person names in their settings with rules if they wish, the rules placing a task first, then a cheap model in the background, shown the categories and the tasks placed before so that it keeps to them, its placements kept beside the journal, a day's placing capped; nothing leaves the machine. Generic over `ChatModel` | | `iq-memory` | What the agents the person starts know beyond their task: the project's notes, each a Markdown file with its name and what it holds, kept by the address of the project's repository so that the same project on another machine finds them, the notes kept of the project under `~/.claude` read beside them and never changed; and the person's skills, Markdown files in the folders the settings list (a folder with its `SKILL.md`, or a file), each listed by name and read whole with a tool before the work it is for, those the settings' `lead_skills` name given whole in the instructions of the leads of the person's chats (`Skills::with_lead`), never to the agents a chat starts. A secret is never kept nor given. The selected skill for permission reviews is read again at each decision and kept outside the workspace so commands cannot rewrite their own policy, never shown to the agents, a missing, unreadable or unsafe skill leaving the decision to the person. Extensions of the crew: the notes for leads, the skills for every agent (one another started may start agents in turn, and chooses them as the skills say), and review policy | | `iq-sync` | iq's folder of data kept in the git repository the settings' `[sync]` names, a private one of any name: what changed here sent, what changed elsewhere taken, a new machine taking everything before it sends anything, this machine's lines winning where both changed; the settings, rules and skills of iq's own folder mirrored in it, and the files of the home they keep, put back on a new machine, what holds secrets never kept (in a folder of credentials of the home, such as `~/.claude`, only its Markdown files), a file of the home never removed; what a sync would send listed before it goes, for the person to say whether it does, the person's own files by name and the rest counted by folder, and shown line by line as the diff git makes of it, each file named as the repository names it, never by where it lives; a new machine taking what is there first and sending nothing until asked; what the folder's `.gitignore` leaves out, the worktrees the agents work in and the store of the assay iq once had among it, taken out of the repository. Git does it all, with the credentials the machine has | diff --git a/crates/ui/src/crew.rs b/crates/ui/src/crew.rs index 6d53179..e347487 100644 --- a/crates/ui/src/crew.rs +++ b/crates/ui/src/crew.rs @@ -442,17 +442,34 @@ fn entries(message: &Message, returned: &std::collections::HashMap<&str, &str>) #[must_use] pub fn past_with(messages: &[Message], aside: &[iq_agent::Aside]) -> Vec { let returned = returned(messages); - let mut thread = Vec::new(); - let mut aside = aside.iter().peekable(); - for at in 0..=messages.len() { - while let Some(shown) = aside.next_if(|shown| shown.after <= at) { + let len = messages.len(); + // What stands past the messages kept was set aside before a + // compaction that kept nothing of what it replaced, when something set + // aside after it stands among them: it comes first. What truly came + // last stays at the end, below the last answer. + let within = aside.iter().rposition(|shown| shown.after <= len); + let (mut first, mut placed, mut last) = (Vec::new(), Vec::new(), Vec::new()); + for (at, shown) in aside.iter().enumerate() { + if shown.after <= len { + placed.push(shown); + } else if within.is_some_and(|within| at < within) { + first.push(shown); + } else { + last.push(shown); + } + } + placed.sort_by_key(|shown| shown.after); + let mut thread: Vec = first.iter().map(|shown| set_aside(&shown.shown)).collect(); + let mut placed = placed.into_iter().peekable(); + for at in 0..=len { + while let Some(shown) = placed.next_if(|shown| shown.after <= at) { thread.push(set_aside(&shown.shown)); } if let Some(message) = messages.get(at) { thread.extend(entries(message, &returned)); } } - thread.extend(aside.map(|shown| set_aside(&shown.shown))); + thread.extend(last.iter().map(|shown| set_aside(&shown.shown))); thread } @@ -1337,6 +1354,47 @@ mod tests { ); } + #[test] + fn what_a_compaction_left_standing_past_the_messages_comes_first_not_below_the_answer() { + // Compacted before compactions kept what they replaced: its + // conversation is its summary, then its last turn. + let kept = [ + Message::system("You are lead"), + Message::user("the summary"), + Message::user("and now?"), + Message::Assistant { + content: Some("Done.".into()), + tool_calls: Vec::new(), + reasoning_signature: None, + }, + ]; + let notice = |after: usize, text: &str| iq_agent::Aside { + at: 1, + turn: 1, + after, + shown: iq_agent::Shown::Notice { text: text.into() }, + }; + let thread = past_with( + &kept, + &[ + notice(40, "an old step"), + notice(3, "on the last turn"), + notice(9, "truly the last"), + ], + ); + assert_eq!( + thread, + [ + Entry::Notice("an old step".into()), + Entry::Prompt("the summary".into()), + Entry::Prompt("and now?".into()), + Entry::Notice("on the last turn".into()), + Entry::Text("Done.".into()), + Entry::Notice("truly the last".into()), + ] + ); + } + #[test] fn a_kept_conversation_becomes_a_thread_without_iq_s_own_words() { let kept = [ From 8bd6cc19571a5327e1f768e728d31adb90fbce9d Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 21:02:37 +0100 Subject: [PATCH 2/3] A row of the conversation iq draws is erased again only once it changed The end of every row of the conversation iq draws was erased after each draw, unchanged rows included, at least once a second for the status line's clock. Kitty, seeing the selected rows written again, dropped a selection the terminal itself made; other terminals may do the same. The end of a row is now erased only when the row changed (its text, its width or its mark's colour), what was erased being forgotten when the screen is wiped or refitted, or the row given to the live part. --- AGENTS.md | 2 +- crates/tui/src/lib.rs | 100 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ef41476..b0d5371 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -67,7 +67,7 @@ Separation of concerns is **enforced by the crate dependency graph**, not by con | `iq-assay` | The assay, in iq with the `assay` feature alone, run by `iq assay` (what its folder holds, `freeze`, `run`, `grade`), the binary giving it the provider, the sandbox's helper, and an audit log and a ledger of billed calls of its own: frozen exercises given to candidate models (one in iq's loop, or a team in one of the crew's patterns), each run in a folder of its own by a crew of its own, through a gate of its own where nobody answers for the person, its agents started on the candidate's models alone, stopped past the minutes and the dollars its exercise allows; what it changed compared file by file, then its hidden checks run in the sandbox by the command the exercise names; graded blind, each a letter, by one grader, always the same so that grades compare, the exercise's reference among them, another grader's grades kept apart; an exercise frozen only once its check fails on its start and passes on its reference, changed later a new version whose results start anew; what a run or a grading should cost said before the person is asked, from past runs or the provider's prices; the results summed by candidate, by exercise and by kind of task, with the cheapest that does as well as the reference; its own folder (`IQ_ASSAY_HOME`, else `iq-assay` in the system's folder of data) and its own settings there, never iq's, a key it does not read said and left aside. Generic over `ChatModel` | | `iq-plugin` | What iq and its plugins say to each other, one line of JSON each way over the plugin's standard input and output: iq's hello with its protocol and folder, where each chat works, the person's commands, its goodbye; the plugin's hello with its protocol and commands, what it shows on the status line and on the chats' page, the variables it gives a place's commands with the line that sets them in a terminal, what it says, and what it runs on the machine. The messages and how they are written, no I/O | | `iq-ui` | iq's state in the terminal: where the person writes (to an agent, or to a new chat with its model, its pattern, its role and its name, made from the first words of its first request until a model names it after its work, unless the person gives one, `/name` renaming the chat written to and saying where they write that it did or why not, `/new` and `/model` taking only a model of the provider's, read as a model named in a message is, and one the settings allow when they list some, the model a new chat starts on said as it is made, a model never taken by Enter from what `/new` or `/model` list while the person did not move to one, `/model` changing the one the chat written to answers on; the switcher of the person's chats, the one used last first, five shown at once and the others scrolled to, opened on the one used before; Ctrl-N a new chat; the agents they started written to by name), the chats of earlier sessions as they come back (iq opening on the one the person wrote to last, each with its thread as kept, recalled once as the person comes back to it), what they write and the messages sent before, the `/` commands and what completes them, the page open over the conversation and how far down it is read (the chats, an agent's thread, the costs, the observations, the keys, what a sync would send, answered from there, every step the agents took, what they wrote to each other and the jobs that ended (each job's command whole and the end of its output), the map of the turn of the chat written to (`map.rs`: its agents as a tree under the chat's own, each followed by its jobs, those finished a moment ago shown, the rest folded into a count the person unfolds; chosen with the arrows, an agent read, written to or stopped, a job's command read whole or the job stopped), each whole or folded as the person chooses), the agents' steps (the tools they call, what the person and the autopilot allow or refuse them, each said in a few words, the questions the person answered them, iq's notices) folded between two of their lines of text, live and in a chat that comes back, whose thread's steps are made into numbered folds as it does, a fold closed as the agent goes on, the observations (iq's tasks over a day, a week, a month, a year or all of it, in the person's time zone, summed by category, model, project or agent), the chats (the person's chats alone, the one used last first, this session's and earlier ones', what each was first asked and when it last worked, how many of its agents are at work, picked there to write to, each chat's whole thread, where it works when it has a place of its own, what it spent, the context its calls read, the questions waiting for the person; what the agents a chat started do read on the steps' page and the map), the costs of every call to a model, by model, over time and by kind of task, what each model read from the provider's cache this session as the person's categories place iq's tasks, over the last hours or days or since midnight in the person's time zone, and what was billed today beside what the session spent, the models the person names in a message ("with opus"), read by matching words among the provider's, a maker's name that models of several lines share (`claude`) naming none, told the agent after the message as a fact, never as an order in the person's name, the theme, the shortcuts as the settings bind them, what a command line does in a few words read from it (the programs it runs and the files it names, never a script's body), how many of a job's latest lines show, and what the person's plugins show (their commands, completed and listed with iq's, which come first, what each shows on the status line and under a chat on the chats' page, the line that sets a place's variables in a terminal), all of it gone with a plugin that stopped; every key the person presses is taken there. A new task starts on the lead's model, or on the one the person named or chose, `/effort` sets how hard the agent written to thinks, and `/mcp` asks how each MCP server is; the images the person attaches to what they write (a file dropped, its path pasted, or `/image`), sent with it; a question with choices of the chat written to, answered with a digit, the arrows or the person's own words, another chat's never taking what is written. Draws nothing | -| `iq-tui` | Draws `iq-ui`'s state in the terminal, as terminal agents do: the conversation of the chat written to written once into the terminal's own scrollback as it happens, no control character of it written but the escapes iq makes itself (each agent's text a line at a time, as the Markdown it is, a table held until its last row and drawn at the width it is written at, its columns aligned on their widest cell, the widest made narrower and their cells folded within them when the terminal is narrow, a faint rule between its rows once one folds, a block of code written as it is, at the line's start and never folded by iq, its marks above and below it rather than before each line, so that a selection copies it as written, a link written as its text alone, a hyperlink, in the terminals that take them, its address after it elsewhere, a Mermaid diagram held until its fence closes, then drawn as an image in Kitty by what the program gives it, half as large again as its pixels, one at least three times wider than tall across the whole width, the image alone, or folded as one line (`▸ diagram · flowchart, 6 nodes`) when the settings say, waiting as the last thing written for the down arrow to unfold it in place, written folded for good once anything follows, its source written where it is not drawn, what its window writes after it held until it is, shown alone on its page in Kitty as the part its zoom and how far it was moved say, under the agent's name in its chat's window, its model for the chat's own and its part and model for one it started, with how hard it thinks, its tools, its questions answered, its messages, what agents write to each other (their tasks too) kept out of the conversation, which keeps the person's question and its answer: the turn's strip shows the latest ten, a line each (summed up in fifteen words at most by a cheap model when the settings name one, else its first line), the earlier counted, and a turn of several agents of the person's chat ends with a line that sums it up (the agents by model, the messages, the calls, the cost, the key to every step), the steps' page keeping all of it whole, the map of a turn (the turn's line: its number, how long it runs, what it spent against what it may, its cost split by model; a row for each agent with its state as a glyph that holds without colour, its model, what it spent in the turn and in how many calls, how full its conversation is against where its model's price rises, what it does in a few words or how it ended; a row for each job with its latest lines; a foot for those finished and what the autopilot and the summaries spent; a message's spark running along the rows from its writer to its reader, which glows, and between two agents neither of which started the other an arc a moment with its first words; columns dropped on a narrow screen, never a row folded), on its page or, as the settings say, as a strip in place of the panes (the turn's line, the agents at work, and those of the turn resting or finished counted), a file an agent changed written as it is changed, under the steps it closes (`✎`, its name and how many lines came and went, then its lines changed and three around each, numbered as in the file, those added green after `+`, those removed red after `-`, the first twelve, the rest unfolded in place with a click in the conversation iq draws and copied as the diff; the one step that wrote it, alone in its fold, not written beside it), a job in one line as it starts and one as it ends (what it does in a few words, the cheap model's when there is one, else read from its line, how it ended, how long it ran, the number its page unfolds it under), never its command, and while it runs its latest lines in a window under its line in the live part, cut to the screen, the oldest scrolling away, a long command among the steps said the same way, a model the person gives an agent, the end of its turns, one empty line at most between its name, its text, its steps and the end of a turn, none after its name, and the last exchanges of a chat of an earlier session as the person comes back to it), so that the person scrolls, selects and copies it as any output; or, when the settings say `conversation = "drawn"`, drawn by iq itself on the terminal's other screen from the blocks each chat's window keeps, laid out again at every draw (`drawn.rs`), the mouse taken, scrolled with the wheel, the touchpad and Page Up and Down, the end followed while the person is at it and the view kept still while they read further up, what is folded (a fold of steps, a job that ended, a message between agents, a diagram folded) unfolded in place, alone, with a click, and folded again the same, nothing moving but what follows it, or marked with Shift-↑ then the arrows and unfolded with Enter (each block standing for a steps' page entry keeping its number, `Block::Entry`, the page's own body drawn under it), what is marked tinted to the screen's edge rather than written a bar, and no row filled with spaces past its text but erased to its end once drawn, so that a selection in the terminal takes neither, a diagram enlarged with a click or Enter, across the width, centred, twice its pixels at most, the conversation's room its alone and the wheel scrolling it, until another click puts it back, words found in it with `/find` (each block holding them marked in turn with n and N, the newest first, the words shown reversed), and what is marked copied with c as it was written (a fold's steps, a message, a job whole, a block of code without its marks, a paragraph of an agent's text), to the terminal's clipboard, the letters (c, n, N) keys only while the person reads from the keyboard (Shift-↑, `/find`): after a click, a letter is what they start writing, never a key, a link opened by iq itself, whatever the terminal takes, as the terminal would (its address, which rides on its spans' background, taken off them and kept for the columns each shows at, handed to the system's opener, `open` on macOS, `xdg-open` elsewhere, apart from iq and not waited for), with a click, or with Enter on what is marked when it neither folds nor enlarges (the one link it holds, or those it holds listed over the conversation's last rows to choose one with the arrows and Enter, its number or a click, a number being the list's only while it shows, so that what the person starts writing after a click opens nothing), its address said in the status line while the mouse is over it or the mark on what holds it, the answers read one after another (each turn's head, an agent's name or what the person wrote, a block of its own, `Block::Head`: an agent's answer taller than the room ends with `↑ top of this answer`, which a click, or Enter once the arrows mark it, takes back to its first line; Home and End go to the top and the end of the answer at the view's top, what the person wrote read with the answer after it, Shift and the arrows to the turn before or after; the arrows, nothing marked, start from what shows), the click that gives the terminal the focus, within half a second of the terminal saying it got it, giving it and nothing more, so that coming back to iq's window opens on the prompt rather than on reading, and going to another chat or a new one leaving the reading of the last, the panes at the top and the live part below it, the shell's screen given back as iq ends, without the conversation; each chat a window of its own, kept as its agents work whether it shows or not, the screen and the scrollback cleared and its window written again as the person goes to it; while several agents of the chat written to work side by side, a pane each at the top of the screen, four at most, two to a row, the conversation scrolling below them and written again whole once they go, an agent another started writing in its pane, not in the window, unless the person wrote to it; below it a live part drawn again as things move (the agents of the chat written to at work, one alone with its latest steps since its last line of text, as many as the settings say, the earlier counted, while a turn of the chat is under way, a line naming the agents it started that the turn concerns (at work, at work since it began, or just started and waiting for a message), at work first, then resting, with its model and who started it, those that finished in it only counted at its end (`4 finished`), gone once nothing of the chat works, those of other chats in the switcher alone, the person's own chat called the chat where they write ("Write to the chat…") and in its turn's costs, an agent it started by its name, the oldest question waiting of any chat, apart from the agents, said from another chat when it is, with what a file written becomes when it was given (its lines added in the colour of what is well, removed in that of what is not, forty at most, under the keys that answer, which a short screen keeps), the person's skills while they are open said first in the status line in the colour of danger (`⚠ SKILLS OPEN`, the chat named when it is not the one written to, and the key or `/skills` that shuts them), the system's notifications the person turns on when they want them (`notify.rs`: `notify-send` on Linux, `osascript` on macOS, on a thread of their own, with iq in front too), sent as a question waits ("Waiting for you") and as a turn of theirs ends ("Turn done", which turns them off), never a word of the work, a screen being shared at times, said in the status line while on, the switcher of the person's chats while it is open, in a box of its own, the completions, where the person writes, the whole path of the folder of its own the agent they write to works in, for them to paste in another terminal, or the command that goes there and sets the variables a plugin gave it, the status line with what the plugins show, then the person, the chat written to and the agents it started, no other chat, along which a message's spark runs from its writer to its reader); the pages on the terminal's other screen, with charts drawn in characters (curves in Braille dots, bars in half blocks, gauges by eighths); colours in 24 bits where the terminal takes them, else the nearest of its 256, the terminal's background never painted; and runs the loop, which draws only when something changes or moves | +| `iq-tui` | Draws `iq-ui`'s state in the terminal, as terminal agents do: the conversation of the chat written to written once into the terminal's own scrollback as it happens, no control character of it written but the escapes iq makes itself (each agent's text a line at a time, as the Markdown it is, a table held until its last row and drawn at the width it is written at, its columns aligned on their widest cell, the widest made narrower and their cells folded within them when the terminal is narrow, a faint rule between its rows once one folds, a block of code written as it is, at the line's start and never folded by iq, its marks above and below it rather than before each line, so that a selection copies it as written, a link written as its text alone, a hyperlink, in the terminals that take them, its address after it elsewhere, a Mermaid diagram held until its fence closes, then drawn as an image in Kitty by what the program gives it, half as large again as its pixels, one at least three times wider than tall across the whole width, the image alone, or folded as one line (`▸ diagram · flowchart, 6 nodes`) when the settings say, waiting as the last thing written for the down arrow to unfold it in place, written folded for good once anything follows, its source written where it is not drawn, what its window writes after it held until it is, shown alone on its page in Kitty as the part its zoom and how far it was moved say, under the agent's name in its chat's window, its model for the chat's own and its part and model for one it started, with how hard it thinks, its tools, its questions answered, its messages, what agents write to each other (their tasks too) kept out of the conversation, which keeps the person's question and its answer: the turn's strip shows the latest ten, a line each (summed up in fifteen words at most by a cheap model when the settings name one, else its first line), the earlier counted, and a turn of several agents of the person's chat ends with a line that sums it up (the agents by model, the messages, the calls, the cost, the key to every step), the steps' page keeping all of it whole, the map of a turn (the turn's line: its number, how long it runs, what it spent against what it may, its cost split by model; a row for each agent with its state as a glyph that holds without colour, its model, what it spent in the turn and in how many calls, how full its conversation is against where its model's price rises, what it does in a few words or how it ended; a row for each job with its latest lines; a foot for those finished and what the autopilot and the summaries spent; a message's spark running along the rows from its writer to its reader, which glows, and between two agents neither of which started the other an arc a moment with its first words; columns dropped on a narrow screen, never a row folded), on its page or, as the settings say, as a strip in place of the panes (the turn's line, the agents at work, and those of the turn resting or finished counted), a file an agent changed written as it is changed, under the steps it closes (`✎`, its name and how many lines came and went, then its lines changed and three around each, numbered as in the file, those added green after `+`, those removed red after `-`, the first twelve, the rest unfolded in place with a click in the conversation iq draws and copied as the diff; the one step that wrote it, alone in its fold, not written beside it), a job in one line as it starts and one as it ends (what it does in a few words, the cheap model's when there is one, else read from its line, how it ended, how long it ran, the number its page unfolds it under), never its command, and while it runs its latest lines in a window under its line in the live part, cut to the screen, the oldest scrolling away, a long command among the steps said the same way, a model the person gives an agent, the end of its turns, one empty line at most between its name, its text, its steps and the end of a turn, none after its name, and the last exchanges of a chat of an earlier session as the person comes back to it), so that the person scrolls, selects and copies it as any output; or, when the settings say `conversation = "drawn"`, drawn by iq itself on the terminal's other screen from the blocks each chat's window keeps, laid out again at every draw (`drawn.rs`), the mouse taken, scrolled with the wheel, the touchpad and Page Up and Down, the end followed while the person is at it and the view kept still while they read further up, what is folded (a fold of steps, a job that ended, a message between agents, a diagram folded) unfolded in place, alone, with a click, and folded again the same, nothing moving but what follows it, or marked with Shift-↑ then the arrows and unfolded with Enter (each block standing for a steps' page entry keeping its number, `Block::Entry`, the page's own body drawn under it), what is marked tinted to the screen's edge rather than written a bar, and no row filled with spaces past its text but erased to its end once drawn, and again only once it changed (`to_erase`), so that a selection in the terminal takes neither, and one the terminal made holds as the screen is drawn again, a diagram enlarged with a click or Enter, across the width, centred, twice its pixels at most, the conversation's room its alone and the wheel scrolling it, until another click puts it back, words found in it with `/find` (each block holding them marked in turn with n and N, the newest first, the words shown reversed), and what is marked copied with c as it was written (a fold's steps, a message, a job whole, a block of code without its marks, a paragraph of an agent's text), to the terminal's clipboard, the letters (c, n, N) keys only while the person reads from the keyboard (Shift-↑, `/find`): after a click, a letter is what they start writing, never a key, a link opened by iq itself, whatever the terminal takes, as the terminal would (its address, which rides on its spans' background, taken off them and kept for the columns each shows at, handed to the system's opener, `open` on macOS, `xdg-open` elsewhere, apart from iq and not waited for), with a click, or with Enter on what is marked when it neither folds nor enlarges (the one link it holds, or those it holds listed over the conversation's last rows to choose one with the arrows and Enter, its number or a click, a number being the list's only while it shows, so that what the person starts writing after a click opens nothing), its address said in the status line while the mouse is over it or the mark on what holds it, the answers read one after another (each turn's head, an agent's name or what the person wrote, a block of its own, `Block::Head`: an agent's answer taller than the room ends with `↑ top of this answer`, which a click, or Enter once the arrows mark it, takes back to its first line; Home and End go to the top and the end of the answer at the view's top, what the person wrote read with the answer after it, Shift and the arrows to the turn before or after; the arrows, nothing marked, start from what shows), the click that gives the terminal the focus, within half a second of the terminal saying it got it, giving it and nothing more, so that coming back to iq's window opens on the prompt rather than on reading, and going to another chat or a new one leaving the reading of the last, the panes at the top and the live part below it, the shell's screen given back as iq ends, without the conversation; each chat a window of its own, kept as its agents work whether it shows or not, the screen and the scrollback cleared and its window written again as the person goes to it; while several agents of the chat written to work side by side, a pane each at the top of the screen, four at most, two to a row, the conversation scrolling below them and written again whole once they go, an agent another started writing in its pane, not in the window, unless the person wrote to it; below it a live part drawn again as things move (the agents of the chat written to at work, one alone with its latest steps since its last line of text, as many as the settings say, the earlier counted, while a turn of the chat is under way, a line naming the agents it started that the turn concerns (at work, at work since it began, or just started and waiting for a message), at work first, then resting, with its model and who started it, those that finished in it only counted at its end (`4 finished`), gone once nothing of the chat works, those of other chats in the switcher alone, the person's own chat called the chat where they write ("Write to the chat…") and in its turn's costs, an agent it started by its name, the oldest question waiting of any chat, apart from the agents, said from another chat when it is, with what a file written becomes when it was given (its lines added in the colour of what is well, removed in that of what is not, forty at most, under the keys that answer, which a short screen keeps), the person's skills while they are open said first in the status line in the colour of danger (`⚠ SKILLS OPEN`, the chat named when it is not the one written to, and the key or `/skills` that shuts them), the system's notifications the person turns on when they want them (`notify.rs`: `notify-send` on Linux, `osascript` on macOS, on a thread of their own, with iq in front too), sent as a question waits ("Waiting for you") and as a turn of theirs ends ("Turn done", which turns them off), never a word of the work, a screen being shared at times, said in the status line while on, the switcher of the person's chats while it is open, in a box of its own, the completions, where the person writes, the whole path of the folder of its own the agent they write to works in, for them to paste in another terminal, or the command that goes there and sets the variables a plugin gave it, the status line with what the plugins show, then the person, the chat written to and the agents it started, no other chat, along which a message's spark runs from its writer to its reader); the pages on the terminal's other screen, with charts drawn in characters (curves in Braille dots, bars in half blocks, gauges by eighths); colours in 24 bits where the terminal takes them, else the nearest of its 256, the terminal's background never painted; and runs the loop, which draws only when something changes or moves | | `iq` | CLI entry point: iq in the terminal, `iq do` for a task handed over at once, `iq sync`, each chat the person starts in a worktree of its own when the settings or `--worktree` say (under iq's folder of data, on a branch `iq/` from what is checked out or from what the settings name, given the files of the checkout they name that git does not keep (a local `.env`) where it has their folder, never over one, then set up with the commands they list, run there on the machine, the person told where it is, what it starts from and how to take its work, their checkout left as it is; as iq starts, the worktrees untouched for as long as the settings say removed when nothing in them is uncommitted, their branch with them once merged, the person told), the person's settings, the machine's sync (what changed asked of the person before it is sent, as iq opens, while it runs and as it ends, unless the settings send it on their own and say what went; what other machines sent taken as iq opens and now and then), what iq keeps of its sessions (calls billed, each task's files, commands and costs, the files read in the place the agent works in, why a turn ended without an answer), the person's plugins, the programs `iq-` on the `PATH` their settings list, started as iq opens or `iq do` starts and ended with it, each told where the chats work and handed the commands the person gives it, what they say taken to the board (printed, for `iq do`) and the variables they give to the gate, one that stops said with its last errors and iq going on without it; the Mermaid diagrams drawn as the settings' `mermaid` says, off unless set (mmdr when installed, with its dark theme, a transparent background and text twice its size, written beside the source as `look.json`, or the person's command, `{look}` naming that look), each in a folder of its own in iq's cache with its source alone (and its look), the program run there in the sandbox, judged by the gate and written to the audit log, the image kept so that the same diagram is drawn once; the MCP servers the settings declare (`[mcp.]`, an address or a command), started as iq opens or `iq do` starts, ended with it, what each does said; the images the person attaches, read as their own action (a file of secrets refused, one outside the workspace written to the audit log as theirs), sent only when they are images of a size a model takes; the web's tools, the search as `[web]` chooses it; the chats kept in iq's own folder, one file each under `chats//`, written whole at every turn's end, put back on the board as iq opens, the person's first and the agents each started under it, every chat the person leads put back on the settings' lead and effort (a model or an effort chosen for it with `/new`, `/model`, `--model`, its first message or `/effort` lasting until iq starts again), said as iq starts, the move kept with its choices (`SETTINGS_MODEL`), the agents a lead started keeping what it chose for them, one whose starter did not come back let go, each with its thread and when it was last at work, those untouched for as long as the settings say forgotten first, their worktree with them; each chat's folder of scratch in iq's cache, never synced, given to the gate, following its chat as it is renamed and gone once it is forgotten; the provider's models handed to the crew, which starts agents only on them; what agents write to each other summed up for the person by the model the settings name, its cost counted as any call's; the models the settings use that those they allow leave out said as iq starts; and, run with one of its flags, the sandbox's helper | A new crate is added when its first real code lands, not before, and this graph is updated in the same commit. diff --git a/crates/tui/src/lib.rs b/crates/tui/src/lib.rs index 89e0bf0..83d4d36 100644 --- a/crates/tui/src/lib.rs +++ b/crates/tui/src/lib.rs @@ -36,6 +36,7 @@ mod tty; mod wrap; use std::collections::HashSet; +use std::hash::{Hash, Hasher}; use std::io::{self, Write}; use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender, TryRecvError}; @@ -138,6 +139,7 @@ pub fn run( relayout: false, kitty: graphics::detect(|name| std::env::var(name).ok()), sent: HashSet::new(), + erased: Vec::new(), }; let depth = Depth::detect(); let p = Palette::new(board.look().theme(), depth); @@ -193,6 +195,10 @@ struct Screen { kitty: Option, /// The images it was sent since the screen was last wiped. sent: HashSet, + /// What each row of the screen showed when its end was last erased, in + /// the conversation iq draws: a row erased again although unchanged is + /// written again, and a terminal drops a selection made on it. + erased: Vec>, } impl Screen { @@ -200,6 +206,7 @@ impl Screen { /// terminal is made anew rather than resized: resized narrower, /// ratatui clears the whole screen and moves what it draws to its top. fn refit(&mut self, area: Rect) -> io::Result<()> { + self.erased.clear(); for y in area.top()..area.bottom() { queue!(self.out, MoveTo(0, y), Clear(ClearType::CurrentLine))?; } @@ -226,6 +233,7 @@ impl Screen { )?; self.inline = Inline::new(cols, rows); self.sent.clear(); + self.erased.clear(); Ok(()) } @@ -256,6 +264,42 @@ fn cell() -> (u16, u16) { }) } +/// The rows of the conversation iq draws whose end is erased, from `head` +/// on, each with where its text ends and its background: those whose +/// width, background or text (`ends`) changed since `erased` says they +/// were erased last, on a screen `rows` tall and `cols` wide. What it +/// says of the rows that are not the conversation's any more is +/// forgotten. +fn to_erase( + erased: &mut Vec>, + rows: u16, + head: u16, + ends: &[(u16, Option, u64)], + cols: u16, +) -> Vec<(u16, u16, Option)> { + erased.resize(usize::from(rows), None); + let conversation = usize::from(head)..usize::from(head).saturating_add(ends.len()); + for (at, kept) in erased.iter_mut().enumerate() { + if !conversation.contains(&at) { + *kept = None; + } + } + let mut erase = Vec::new(); + for (row, &(width, ground, shows)) in (head..).zip(ends) { + let Some(kept) = erased.get_mut(usize::from(row)) else { + continue; + }; + if *kept == Some(shows) { + continue; + } + *kept = Some(shows); + if width < cols { + erase.push((row, width, ground)); + } + } + erase +} + /// The escape that sets the background to `color`, or to the terminal's /// own. fn background(color: Option) -> String { @@ -643,11 +687,18 @@ impl Iq { p: &self.p, now, }; - let ends: Vec<(u16, Option)> = (0..usize::from(room)) + let ends: Vec<(u16, Option, u64)> = (0..usize::from(room)) .map(|row| { - let width = shown.lines.get(row).map_or(0, Line::width); + let line = shown.lines.get(row); + let width = line.map_or(0, Line::width); let ground = shown.grounds.get(row).copied().flatten(); - (u16::try_from(width).unwrap_or(u16::MAX), ground) + let mut shows = std::collections::hash_map::DefaultHasher::new(); + (line, ground).hash(&mut shows); + ( + u16::try_from(width).unwrap_or(u16::MAX), + ground, + shows.finish(), + ) }) .collect(); let motion = &mut self.motion; @@ -659,12 +710,11 @@ impl Iq { })?; // Past its text, each row of the conversation is left empty rather // than filled with spaces, in the mark's colour on what it marks: - // a selection in the terminal takes neither. - for (row, (width, ground)) in (head..).zip(ends) { - if width < cols { - queue!(screen.out, MoveTo(width, row))?; - write!(screen.out, "{}\x1b[K", background(ground))?; - } + // a selection in the terminal takes neither. Only a row that + // changed is erased again, as its text was written again. + for (row, width, ground) in to_erase(&mut screen.erased, rows, head, &ends, cols) { + queue!(screen.out, MoveTo(width, row))?; + write!(screen.out, "{}\x1b[K", background(ground))?; } write!(screen.out, "\x1b[0m")?; if let Some((x, y)) = caret { @@ -849,3 +899,35 @@ impl Iq { screen.out.flush() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_row_of_the_conversation_is_erased_again_only_once_it_changed() { + let mut erased = Vec::new(); + let marked = Some(Color::Rgb(1, 2, 3)); + let ends = [(10, None, 1), (80, None, 2), (4, marked, 3)]; + // Drawn first: every row shorter than the screen. + assert_eq!( + to_erase(&mut erased, 6, 1, &ends, 80), + [(1, 10, None), (3, 4, marked)] + ); + // Drawn again unchanged, as the clock ticks: none, so that a + // selection the terminal made on them holds. + assert!(to_erase(&mut erased, 6, 1, &ends, 80).is_empty()); + // A row changed, its text or its mark: that one. + let changed = [(10, None, 1), (80, None, 2), (4, None, 4)]; + assert_eq!(to_erase(&mut erased, 6, 1, &changed, 80), [(3, 4, None)]); + // The conversation lower by a row: what it shows there now is + // erased, and a row given back and taken again is erased too. + assert_eq!( + to_erase(&mut erased, 6, 2, &changed, 80), + [(2, 10, None), (4, 4, None)] + ); + // Forgotten, as the screen is wiped: all of it again. + erased.clear(); + assert_eq!(to_erase(&mut erased, 6, 2, &changed, 80).len(), 2); + } +} From d801168aeee0fb62855359450d8caf8c545eb2c1 Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 21:10:02 +0100 Subject: [PATCH 3/3] One conversation, the one iq draws, and iq selecting in it itself Selecting in the conversation iq draws needed Shift, the mouse being iq's, and stopped at the screen's edges; the scrollback selected well but lost the clicks on folds, links and diagrams. iq now always draws the conversation; `conversation` is read no more, said so as iq starts, so that older settings still load, and the scrollback writer is left for a cleanup of its own. A press let go where it was is a click, as before. A drag selects, shown reversed, with no Shift; held at the conversation's top or bottom edge, it scrolls a row every 60 ms, the mouse still; the selection is kept by block and row so that it holds as the conversation scrolls. As the mouse comes up, what it holds goes to the terminal's clipboard through OSC 52, without the images, the rows' padding nor the conversation's own indent. Shift and a drag stay the terminal's own selection, where a terminal does not let OSC 52 write its clipboard. --- AGENTS.md | 2 +- crates/tui/src/drawn.rs | 285 +++++++++++++++++++++++++++++++++++++ crates/tui/src/graphics.rs | 5 + crates/tui/src/lib.rs | 26 +++- crates/ui/src/board.rs | 92 ++++++++++++ src/settings.rs | 22 ++- 6 files changed, 423 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b0d5371..12d9332 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -67,7 +67,7 @@ Separation of concerns is **enforced by the crate dependency graph**, not by con | `iq-assay` | The assay, in iq with the `assay` feature alone, run by `iq assay` (what its folder holds, `freeze`, `run`, `grade`), the binary giving it the provider, the sandbox's helper, and an audit log and a ledger of billed calls of its own: frozen exercises given to candidate models (one in iq's loop, or a team in one of the crew's patterns), each run in a folder of its own by a crew of its own, through a gate of its own where nobody answers for the person, its agents started on the candidate's models alone, stopped past the minutes and the dollars its exercise allows; what it changed compared file by file, then its hidden checks run in the sandbox by the command the exercise names; graded blind, each a letter, by one grader, always the same so that grades compare, the exercise's reference among them, another grader's grades kept apart; an exercise frozen only once its check fails on its start and passes on its reference, changed later a new version whose results start anew; what a run or a grading should cost said before the person is asked, from past runs or the provider's prices; the results summed by candidate, by exercise and by kind of task, with the cheapest that does as well as the reference; its own folder (`IQ_ASSAY_HOME`, else `iq-assay` in the system's folder of data) and its own settings there, never iq's, a key it does not read said and left aside. Generic over `ChatModel` | | `iq-plugin` | What iq and its plugins say to each other, one line of JSON each way over the plugin's standard input and output: iq's hello with its protocol and folder, where each chat works, the person's commands, its goodbye; the plugin's hello with its protocol and commands, what it shows on the status line and on the chats' page, the variables it gives a place's commands with the line that sets them in a terminal, what it says, and what it runs on the machine. The messages and how they are written, no I/O | | `iq-ui` | iq's state in the terminal: where the person writes (to an agent, or to a new chat with its model, its pattern, its role and its name, made from the first words of its first request until a model names it after its work, unless the person gives one, `/name` renaming the chat written to and saying where they write that it did or why not, `/new` and `/model` taking only a model of the provider's, read as a model named in a message is, and one the settings allow when they list some, the model a new chat starts on said as it is made, a model never taken by Enter from what `/new` or `/model` list while the person did not move to one, `/model` changing the one the chat written to answers on; the switcher of the person's chats, the one used last first, five shown at once and the others scrolled to, opened on the one used before; Ctrl-N a new chat; the agents they started written to by name), the chats of earlier sessions as they come back (iq opening on the one the person wrote to last, each with its thread as kept, recalled once as the person comes back to it), what they write and the messages sent before, the `/` commands and what completes them, the page open over the conversation and how far down it is read (the chats, an agent's thread, the costs, the observations, the keys, what a sync would send, answered from there, every step the agents took, what they wrote to each other and the jobs that ended (each job's command whole and the end of its output), the map of the turn of the chat written to (`map.rs`: its agents as a tree under the chat's own, each followed by its jobs, those finished a moment ago shown, the rest folded into a count the person unfolds; chosen with the arrows, an agent read, written to or stopped, a job's command read whole or the job stopped), each whole or folded as the person chooses), the agents' steps (the tools they call, what the person and the autopilot allow or refuse them, each said in a few words, the questions the person answered them, iq's notices) folded between two of their lines of text, live and in a chat that comes back, whose thread's steps are made into numbered folds as it does, a fold closed as the agent goes on, the observations (iq's tasks over a day, a week, a month, a year or all of it, in the person's time zone, summed by category, model, project or agent), the chats (the person's chats alone, the one used last first, this session's and earlier ones', what each was first asked and when it last worked, how many of its agents are at work, picked there to write to, each chat's whole thread, where it works when it has a place of its own, what it spent, the context its calls read, the questions waiting for the person; what the agents a chat started do read on the steps' page and the map), the costs of every call to a model, by model, over time and by kind of task, what each model read from the provider's cache this session as the person's categories place iq's tasks, over the last hours or days or since midnight in the person's time zone, and what was billed today beside what the session spent, the models the person names in a message ("with opus"), read by matching words among the provider's, a maker's name that models of several lines share (`claude`) naming none, told the agent after the message as a fact, never as an order in the person's name, the theme, the shortcuts as the settings bind them, what a command line does in a few words read from it (the programs it runs and the files it names, never a script's body), how many of a job's latest lines show, and what the person's plugins show (their commands, completed and listed with iq's, which come first, what each shows on the status line and under a chat on the chats' page, the line that sets a place's variables in a terminal), all of it gone with a plugin that stopped; every key the person presses is taken there. A new task starts on the lead's model, or on the one the person named or chose, `/effort` sets how hard the agent written to thinks, and `/mcp` asks how each MCP server is; the images the person attaches to what they write (a file dropped, its path pasted, or `/image`), sent with it; a question with choices of the chat written to, answered with a digit, the arrows or the person's own words, another chat's never taking what is written. Draws nothing | -| `iq-tui` | Draws `iq-ui`'s state in the terminal, as terminal agents do: the conversation of the chat written to written once into the terminal's own scrollback as it happens, no control character of it written but the escapes iq makes itself (each agent's text a line at a time, as the Markdown it is, a table held until its last row and drawn at the width it is written at, its columns aligned on their widest cell, the widest made narrower and their cells folded within them when the terminal is narrow, a faint rule between its rows once one folds, a block of code written as it is, at the line's start and never folded by iq, its marks above and below it rather than before each line, so that a selection copies it as written, a link written as its text alone, a hyperlink, in the terminals that take them, its address after it elsewhere, a Mermaid diagram held until its fence closes, then drawn as an image in Kitty by what the program gives it, half as large again as its pixels, one at least three times wider than tall across the whole width, the image alone, or folded as one line (`▸ diagram · flowchart, 6 nodes`) when the settings say, waiting as the last thing written for the down arrow to unfold it in place, written folded for good once anything follows, its source written where it is not drawn, what its window writes after it held until it is, shown alone on its page in Kitty as the part its zoom and how far it was moved say, under the agent's name in its chat's window, its model for the chat's own and its part and model for one it started, with how hard it thinks, its tools, its questions answered, its messages, what agents write to each other (their tasks too) kept out of the conversation, which keeps the person's question and its answer: the turn's strip shows the latest ten, a line each (summed up in fifteen words at most by a cheap model when the settings name one, else its first line), the earlier counted, and a turn of several agents of the person's chat ends with a line that sums it up (the agents by model, the messages, the calls, the cost, the key to every step), the steps' page keeping all of it whole, the map of a turn (the turn's line: its number, how long it runs, what it spent against what it may, its cost split by model; a row for each agent with its state as a glyph that holds without colour, its model, what it spent in the turn and in how many calls, how full its conversation is against where its model's price rises, what it does in a few words or how it ended; a row for each job with its latest lines; a foot for those finished and what the autopilot and the summaries spent; a message's spark running along the rows from its writer to its reader, which glows, and between two agents neither of which started the other an arc a moment with its first words; columns dropped on a narrow screen, never a row folded), on its page or, as the settings say, as a strip in place of the panes (the turn's line, the agents at work, and those of the turn resting or finished counted), a file an agent changed written as it is changed, under the steps it closes (`✎`, its name and how many lines came and went, then its lines changed and three around each, numbered as in the file, those added green after `+`, those removed red after `-`, the first twelve, the rest unfolded in place with a click in the conversation iq draws and copied as the diff; the one step that wrote it, alone in its fold, not written beside it), a job in one line as it starts and one as it ends (what it does in a few words, the cheap model's when there is one, else read from its line, how it ended, how long it ran, the number its page unfolds it under), never its command, and while it runs its latest lines in a window under its line in the live part, cut to the screen, the oldest scrolling away, a long command among the steps said the same way, a model the person gives an agent, the end of its turns, one empty line at most between its name, its text, its steps and the end of a turn, none after its name, and the last exchanges of a chat of an earlier session as the person comes back to it), so that the person scrolls, selects and copies it as any output; or, when the settings say `conversation = "drawn"`, drawn by iq itself on the terminal's other screen from the blocks each chat's window keeps, laid out again at every draw (`drawn.rs`), the mouse taken, scrolled with the wheel, the touchpad and Page Up and Down, the end followed while the person is at it and the view kept still while they read further up, what is folded (a fold of steps, a job that ended, a message between agents, a diagram folded) unfolded in place, alone, with a click, and folded again the same, nothing moving but what follows it, or marked with Shift-↑ then the arrows and unfolded with Enter (each block standing for a steps' page entry keeping its number, `Block::Entry`, the page's own body drawn under it), what is marked tinted to the screen's edge rather than written a bar, and no row filled with spaces past its text but erased to its end once drawn, and again only once it changed (`to_erase`), so that a selection in the terminal takes neither, and one the terminal made holds as the screen is drawn again, a diagram enlarged with a click or Enter, across the width, centred, twice its pixels at most, the conversation's room its alone and the wheel scrolling it, until another click puts it back, words found in it with `/find` (each block holding them marked in turn with n and N, the newest first, the words shown reversed), and what is marked copied with c as it was written (a fold's steps, a message, a job whole, a block of code without its marks, a paragraph of an agent's text), to the terminal's clipboard, the letters (c, n, N) keys only while the person reads from the keyboard (Shift-↑, `/find`): after a click, a letter is what they start writing, never a key, a link opened by iq itself, whatever the terminal takes, as the terminal would (its address, which rides on its spans' background, taken off them and kept for the columns each shows at, handed to the system's opener, `open` on macOS, `xdg-open` elsewhere, apart from iq and not waited for), with a click, or with Enter on what is marked when it neither folds nor enlarges (the one link it holds, or those it holds listed over the conversation's last rows to choose one with the arrows and Enter, its number or a click, a number being the list's only while it shows, so that what the person starts writing after a click opens nothing), its address said in the status line while the mouse is over it or the mark on what holds it, the answers read one after another (each turn's head, an agent's name or what the person wrote, a block of its own, `Block::Head`: an agent's answer taller than the room ends with `↑ top of this answer`, which a click, or Enter once the arrows mark it, takes back to its first line; Home and End go to the top and the end of the answer at the view's top, what the person wrote read with the answer after it, Shift and the arrows to the turn before or after; the arrows, nothing marked, start from what shows), the click that gives the terminal the focus, within half a second of the terminal saying it got it, giving it and nothing more, so that coming back to iq's window opens on the prompt rather than on reading, and going to another chat or a new one leaving the reading of the last, the panes at the top and the live part below it, the shell's screen given back as iq ends, without the conversation; each chat a window of its own, kept as its agents work whether it shows or not, the screen and the scrollback cleared and its window written again as the person goes to it; while several agents of the chat written to work side by side, a pane each at the top of the screen, four at most, two to a row, the conversation scrolling below them and written again whole once they go, an agent another started writing in its pane, not in the window, unless the person wrote to it; below it a live part drawn again as things move (the agents of the chat written to at work, one alone with its latest steps since its last line of text, as many as the settings say, the earlier counted, while a turn of the chat is under way, a line naming the agents it started that the turn concerns (at work, at work since it began, or just started and waiting for a message), at work first, then resting, with its model and who started it, those that finished in it only counted at its end (`4 finished`), gone once nothing of the chat works, those of other chats in the switcher alone, the person's own chat called the chat where they write ("Write to the chat…") and in its turn's costs, an agent it started by its name, the oldest question waiting of any chat, apart from the agents, said from another chat when it is, with what a file written becomes when it was given (its lines added in the colour of what is well, removed in that of what is not, forty at most, under the keys that answer, which a short screen keeps), the person's skills while they are open said first in the status line in the colour of danger (`⚠ SKILLS OPEN`, the chat named when it is not the one written to, and the key or `/skills` that shuts them), the system's notifications the person turns on when they want them (`notify.rs`: `notify-send` on Linux, `osascript` on macOS, on a thread of their own, with iq in front too), sent as a question waits ("Waiting for you") and as a turn of theirs ends ("Turn done", which turns them off), never a word of the work, a screen being shared at times, said in the status line while on, the switcher of the person's chats while it is open, in a box of its own, the completions, where the person writes, the whole path of the folder of its own the agent they write to works in, for them to paste in another terminal, or the command that goes there and sets the variables a plugin gave it, the status line with what the plugins show, then the person, the chat written to and the agents it started, no other chat, along which a message's spark runs from its writer to its reader); the pages on the terminal's other screen, with charts drawn in characters (curves in Braille dots, bars in half blocks, gauges by eighths); colours in 24 bits where the terminal takes them, else the nearest of its 256, the terminal's background never painted; and runs the loop, which draws only when something changes or moves | +| `iq-tui` | Draws `iq-ui`'s state in the terminal, as terminal agents do: the conversation of the chat written to written once into the terminal's own scrollback as it happens, no control character of it written but the escapes iq makes itself (each agent's text a line at a time, as the Markdown it is, a table held until its last row and drawn at the width it is written at, its columns aligned on their widest cell, the widest made narrower and their cells folded within them when the terminal is narrow, a faint rule between its rows once one folds, a block of code written as it is, at the line's start and never folded by iq, its marks above and below it rather than before each line, so that a selection copies it as written, a link written as its text alone, a hyperlink, in the terminals that take them, its address after it elsewhere, a Mermaid diagram held until its fence closes, then drawn as an image in Kitty by what the program gives it, half as large again as its pixels, one at least three times wider than tall across the whole width, the image alone, or folded as one line (`▸ diagram · flowchart, 6 nodes`) when the settings say, waiting as the last thing written for the down arrow to unfold it in place, written folded for good once anything follows, its source written where it is not drawn, what its window writes after it held until it is, shown alone on its page in Kitty as the part its zoom and how far it was moved say, under the agent's name in its chat's window, its model for the chat's own and its part and model for one it started, with how hard it thinks, its tools, its questions answered, its messages, what agents write to each other (their tasks too) kept out of the conversation, which keeps the person's question and its answer: the turn's strip shows the latest ten, a line each (summed up in fifteen words at most by a cheap model when the settings name one, else its first line), the earlier counted, and a turn of several agents of the person's chat ends with a line that sums it up (the agents by model, the messages, the calls, the cost, the key to every step), the steps' page keeping all of it whole, the map of a turn (the turn's line: its number, how long it runs, what it spent against what it may, its cost split by model; a row for each agent with its state as a glyph that holds without colour, its model, what it spent in the turn and in how many calls, how full its conversation is against where its model's price rises, what it does in a few words or how it ended; a row for each job with its latest lines; a foot for those finished and what the autopilot and the summaries spent; a message's spark running along the rows from its writer to its reader, which glows, and between two agents neither of which started the other an arc a moment with its first words; columns dropped on a narrow screen, never a row folded), on its page or, as the settings say, as a strip in place of the panes (the turn's line, the agents at work, and those of the turn resting or finished counted), a file an agent changed written as it is changed, under the steps it closes (`✎`, its name and how many lines came and went, then its lines changed and three around each, numbered as in the file, those added green after `+`, those removed red after `-`, the first twelve, the rest unfolded in place with a click in the conversation iq draws and copied as the diff; the one step that wrote it, alone in its fold, not written beside it), a job in one line as it starts and one as it ends (what it does in a few words, the cheap model's when there is one, else read from its line, how it ended, how long it ran, the number its page unfolds it under), never its command, and while it runs its latest lines in a window under its line in the live part, cut to the screen, the oldest scrolling away, a long command among the steps said the same way, a model the person gives an agent, the end of its turns, one empty line at most between its name, its text, its steps and the end of a turn, none after its name, and the last exchanges of a chat of an earlier session as the person comes back to it), so that the person scrolls, selects and copies it as any output (kept for a cleanup of its own: iq draws the conversation, `conversation` read no more); drawn by iq itself on the terminal's other screen from the blocks each chat's window keeps, laid out again at every draw (`drawn.rs`), the mouse taken (a press let go where it was a click, a drag a selection iq makes itself, shown reversed, the conversation scrolling a row every 60 ms while it is held at its top or bottom edge, kept by block and row as it scrolls, copied as the mouse comes up through the terminal's clipboard, OSC 52, without images, padding nor the conversation's indent; Shift and a drag the terminal's own), scrolled with the wheel, the touchpad and Page Up and Down, the end followed while the person is at it and the view kept still while they read further up, what is folded (a fold of steps, a job that ended, a message between agents, a diagram folded) unfolded in place, alone, with a click, and folded again the same, nothing moving but what follows it, or marked with Shift-↑ then the arrows and unfolded with Enter (each block standing for a steps' page entry keeping its number, `Block::Entry`, the page's own body drawn under it), what is marked tinted to the screen's edge rather than written a bar, and no row filled with spaces past its text but erased to its end once drawn, and again only once it changed (`to_erase`), so that a selection in the terminal takes neither, and one the terminal made holds as the screen is drawn again, a diagram enlarged with a click or Enter, across the width, centred, twice its pixels at most, the conversation's room its alone and the wheel scrolling it, until another click puts it back, words found in it with `/find` (each block holding them marked in turn with n and N, the newest first, the words shown reversed), and what is marked copied with c as it was written (a fold's steps, a message, a job whole, a block of code without its marks, a paragraph of an agent's text), to the terminal's clipboard, the letters (c, n, N) keys only while the person reads from the keyboard (Shift-↑, `/find`): after a click, a letter is what they start writing, never a key, a link opened by iq itself, whatever the terminal takes, as the terminal would (its address, which rides on its spans' background, taken off them and kept for the columns each shows at, handed to the system's opener, `open` on macOS, `xdg-open` elsewhere, apart from iq and not waited for), with a click, or with Enter on what is marked when it neither folds nor enlarges (the one link it holds, or those it holds listed over the conversation's last rows to choose one with the arrows and Enter, its number or a click, a number being the list's only while it shows, so that what the person starts writing after a click opens nothing), its address said in the status line while the mouse is over it or the mark on what holds it, the answers read one after another (each turn's head, an agent's name or what the person wrote, a block of its own, `Block::Head`: an agent's answer taller than the room ends with `↑ top of this answer`, which a click, or Enter once the arrows mark it, takes back to its first line; Home and End go to the top and the end of the answer at the view's top, what the person wrote read with the answer after it, Shift and the arrows to the turn before or after; the arrows, nothing marked, start from what shows), the click that gives the terminal the focus, within half a second of the terminal saying it got it, giving it and nothing more, so that coming back to iq's window opens on the prompt rather than on reading, and going to another chat or a new one leaving the reading of the last, the panes at the top and the live part below it, the shell's screen given back as iq ends, without the conversation; each chat a window of its own, kept as its agents work whether it shows or not, the screen and the scrollback cleared and its window written again as the person goes to it; while several agents of the chat written to work side by side, a pane each at the top of the screen, four at most, two to a row, the conversation scrolling below them and written again whole once they go, an agent another started writing in its pane, not in the window, unless the person wrote to it; below it a live part drawn again as things move (the agents of the chat written to at work, one alone with its latest steps since its last line of text, as many as the settings say, the earlier counted, while a turn of the chat is under way, a line naming the agents it started that the turn concerns (at work, at work since it began, or just started and waiting for a message), at work first, then resting, with its model and who started it, those that finished in it only counted at its end (`4 finished`), gone once nothing of the chat works, those of other chats in the switcher alone, the person's own chat called the chat where they write ("Write to the chat…") and in its turn's costs, an agent it started by its name, the oldest question waiting of any chat, apart from the agents, said from another chat when it is, with what a file written becomes when it was given (its lines added in the colour of what is well, removed in that of what is not, forty at most, under the keys that answer, which a short screen keeps), the person's skills while they are open said first in the status line in the colour of danger (`⚠ SKILLS OPEN`, the chat named when it is not the one written to, and the key or `/skills` that shuts them), the system's notifications the person turns on when they want them (`notify.rs`: `notify-send` on Linux, `osascript` on macOS, on a thread of their own, with iq in front too), sent as a question waits ("Waiting for you") and as a turn of theirs ends ("Turn done", which turns them off), never a word of the work, a screen being shared at times, said in the status line while on, the switcher of the person's chats while it is open, in a box of its own, the completions, where the person writes, the whole path of the folder of its own the agent they write to works in, for them to paste in another terminal, or the command that goes there and sets the variables a plugin gave it, the status line with what the plugins show, then the person, the chat written to and the agents it started, no other chat, along which a message's spark runs from its writer to its reader); the pages on the terminal's other screen, with charts drawn in characters (curves in Braille dots, bars in half blocks, gauges by eighths); colours in 24 bits where the terminal takes them, else the nearest of its 256, the terminal's background never painted; and runs the loop, which draws only when something changes or moves | | `iq` | CLI entry point: iq in the terminal, `iq do` for a task handed over at once, `iq sync`, each chat the person starts in a worktree of its own when the settings or `--worktree` say (under iq's folder of data, on a branch `iq/` from what is checked out or from what the settings name, given the files of the checkout they name that git does not keep (a local `.env`) where it has their folder, never over one, then set up with the commands they list, run there on the machine, the person told where it is, what it starts from and how to take its work, their checkout left as it is; as iq starts, the worktrees untouched for as long as the settings say removed when nothing in them is uncommitted, their branch with them once merged, the person told), the person's settings, the machine's sync (what changed asked of the person before it is sent, as iq opens, while it runs and as it ends, unless the settings send it on their own and say what went; what other machines sent taken as iq opens and now and then), what iq keeps of its sessions (calls billed, each task's files, commands and costs, the files read in the place the agent works in, why a turn ended without an answer), the person's plugins, the programs `iq-` on the `PATH` their settings list, started as iq opens or `iq do` starts and ended with it, each told where the chats work and handed the commands the person gives it, what they say taken to the board (printed, for `iq do`) and the variables they give to the gate, one that stops said with its last errors and iq going on without it; the Mermaid diagrams drawn as the settings' `mermaid` says, off unless set (mmdr when installed, with its dark theme, a transparent background and text twice its size, written beside the source as `look.json`, or the person's command, `{look}` naming that look), each in a folder of its own in iq's cache with its source alone (and its look), the program run there in the sandbox, judged by the gate and written to the audit log, the image kept so that the same diagram is drawn once; the MCP servers the settings declare (`[mcp.]`, an address or a command), started as iq opens or `iq do` starts, ended with it, what each does said; the images the person attaches, read as their own action (a file of secrets refused, one outside the workspace written to the audit log as theirs), sent only when they are images of a size a model takes; the web's tools, the search as `[web]` chooses it; the chats kept in iq's own folder, one file each under `chats//`, written whole at every turn's end, put back on the board as iq opens, the person's first and the agents each started under it, every chat the person leads put back on the settings' lead and effort (a model or an effort chosen for it with `/new`, `/model`, `--model`, its first message or `/effort` lasting until iq starts again), said as iq starts, the move kept with its choices (`SETTINGS_MODEL`), the agents a lead started keeping what it chose for them, one whose starter did not come back let go, each with its thread and when it was last at work, those untouched for as long as the settings say forgotten first, their worktree with them; each chat's folder of scratch in iq's cache, never synced, given to the gate, following its chat as it is renamed and gone once it is forgotten; the provider's models handed to the crew, which starts agents only on them; what agents write to each other summed up for the person by the model the settings name, its cost counted as any call's; the models the settings use that those they allow leave out said as iq starts; and, run with one of its flags, the sandbox's helper | A new crate is added when its first real code lands, not before, and this graph is updated in the same commit. diff --git a/crates/tui/src/drawn.rs b/crates/tui/src/drawn.rs index 59be14c..db8e10e 100644 --- a/crates/tui/src/drawn.rs +++ b/crates/tui/src/drawn.rs @@ -70,8 +70,18 @@ pub(crate) struct View { pointer: Option<(u16, u16)>, /// The links of what is marked, listed for the person to choose one. listing: Option, + /// The conversation's height, as last drawn. + height: usize, + /// What the person selects with the mouse: where it began and where it + /// reaches, each the number of a block, a row in it and a column, so + /// that it holds as the conversation scrolls. + selection: Option<(Point, Point)>, } +/// A cell of the conversation, where it is whatever shows: the number of +/// the block, the row in it and the column. +type Point = (usize, usize, u16); + /// What a row of the conversation shows, or the mark is on: a block, by /// its number, or the mark after an agent's answer taller than the room, /// which goes back to its top, by the number of the block it follows. @@ -603,7 +613,50 @@ impl View { } None => {} }, + Reading::Select(column, row) => { + self.selection = self + .place_at(&laid, height, *row) + .filter(|_| self.zoom.is_none()) + .map(|(number, inner)| { + ((number, inner, *column), (number, inner, *column)) + }); + } + Reading::Stretch(column, row) => { + if self.selection.is_none() { + continue; + } + // Held at an edge, the conversation scrolls a row. + let (top, bottom) = (self.from, self.from + height as u16 - 1); + let row = if *row <= top { + self.scroll(&laid, height, -1); + top + } else if *row >= bottom { + self.scroll(&laid, height, 1); + bottom + } else { + *row + }; + if let (Some((start, _)), Some((number, inner))) = + (self.selection, self.place_at(&laid, height, row)) + { + self.selection = Some((start, (number, inner, *column))); + } + } + Reading::Selected => { + if let Some((a, b)) = self.selection + && a != b + { + let text = selected(&laid, ordered(&laid, a, b)); + let lines = text.lines().count().max(1); + said = Some(format!( + "copied {lines} line{}", + if lines == 1 { "" } else { "s" } + )); + copied = Some(text); + } + } Reading::Click(column, row) => { + self.selection = None; let shown = usize::from(row.saturating_sub(self.from)); let clicked = (*row >= self.from) .then(|| self.rows.get(shown).copied().flatten()) @@ -684,6 +737,7 @@ impl View { Reading::Leave => { self.mark = None; self.found = None; + self.selection = None; } } } @@ -735,9 +789,30 @@ impl View { } } self.from = area.from; + self.height = height; for line in &mut shown.lines { trimmed(line); } + // What is selected, reversed, as a terminal shows its own. + if let Some((a, b)) = self + .selection + .filter(|(a, b)| a != b && self.zoom.is_none()) + { + let (start, end) = ordered(&laid, a, b); + let (first, last) = ((laid.at(start.0), start.1), (laid.at(end.0), end.1)); + for (row, line) in (self.from..).zip(shown.lines.iter_mut()) { + let Some((number, inner)) = self.place_at(&laid, height, row) else { + continue; + }; + let here = (laid.at(number), inner); + if here < first || here > last { + continue; + } + let from = if here == first { start.2 } else { 0 }; + let to = if here == last { end.2 } else { u16::MAX }; + reversed(line, usize::from(from), usize::from(to)); + } + } let ground = p.color(p.ground.mix(p.accent, MARKED)); shown.grounds = self .rows @@ -782,6 +857,35 @@ impl View { shown } + /// Whether the screen's `row` is the conversation's top or bottom edge, + /// or past it: a selection held there scrolls it. + pub(crate) fn at_edge(&self, row: u16) -> bool { + self.height > 0 + && (row <= self.from || usize::from(row) + 1 >= usize::from(self.from) + self.height) + } + + /// The block, by its number, and the row in it that the screen's `row` + /// shows, the view as it now stands; none past the conversation. + fn place_at(&self, laid: &Laid<'_>, height: usize, row: u16) -> Option<(usize, usize)> { + let mut down = usize::from(row.checked_sub(self.from)?); + if down >= height { + return None; + } + let (mut at, mut inner) = self.top_now(laid, height); + loop { + let rows = laid.rows(at); + if inner + down < rows { + return Some((laid.number(at), inner + down)); + } + down -= rows.saturating_sub(inner); + inner = 0; + at += 1; + if at >= laid.len() { + return None; + } + } + } + /// The mouse is now over the cell at `column` and `row` of the screen. /// Returns whether it points at another link than it did. pub(crate) fn point(&mut self, column: u16, row: u16) -> bool { @@ -1111,6 +1215,110 @@ impl View { } } +/// `a` and `b`, the first in the conversation first. +fn ordered(laid: &Laid<'_>, a: Point, b: Point) -> (Point, Point) { + let key = |point: Point| (laid.at(point.0), point.1, point.2); + if key(a) <= key(b) { (a, b) } else { (b, a) } +} + +/// What the selection from `start` to `end` holds, as text: without the +/// images, the rows' padding nor the conversation's own indent. +fn selected(laid: &Laid<'_>, (start, end): (Point, Point)) -> String { + let (first, last) = (laid.at(start.0), laid.at(end.0)); + // Each row whole, with the columns the selection takes of it. + let mut rows: Vec<(String, usize, usize)> = Vec::new(); + for at in first..=last.min(laid.len().saturating_sub(1)) { + let lines = laid.lines(at, &mut Vec::new()); + let from = if at == first { start.1 } else { 0 }; + let to = if at == last { end.1 } else { usize::MAX }; + for (inner, line) in lines.iter().enumerate() { + if inner < from || inner > to { + continue; + } + let text: String = line + .spans + .iter() + .map(|span| span.content.as_ref()) + .collect::() + .chars() + .filter(|c| !crate::graphics::image_cell(*c)) + .collect(); + let left = if at == first && inner == start.1 { + start.2 + } else { + 0 + }; + let right = if at == last && inner == end.1 { + end.2 + } else { + u16::MAX + }; + rows.push((text, usize::from(left), usize::from(right))); + } + } + // The conversation's own indent, as its rows whole say it. + let indent = rows + .iter() + .filter(|(text, ..)| !text.trim().is_empty()) + .map(|(text, ..)| text.len() - text.trim_start_matches(' ').len()) + .min() + .unwrap_or(0); + rows.iter() + .map(|(text, left, right)| { + columns(text, (*left).max(indent), *right) + .trim_end() + .to_owned() + }) + .collect::>() + .join("\n") +} + +/// The characters of `text` from column `from` to column `to`, both in. +fn columns(text: &str, from: usize, to: usize) -> String { + let mut column = 0; + let mut kept = String::new(); + for c in text.chars() { + if column >= from && column <= to { + kept.push(c); + } + column += unicode_width::UnicodeWidthChar::width(c).unwrap_or(0); + } + kept +} + +/// `line` reversed from column `from` to column `to`, both in, as a +/// terminal shows what it selects. +fn reversed(line: &mut Line<'static>, from: usize, to: usize) { + let mut column = 0; + let mut spans = Vec::new(); + for span in line.spans.drain(..) { + let mut parts: [String; 3] = Default::default(); + for c in span.content.chars() { + let part = if column < from { + 0 + } else if column <= to { + 1 + } else { + 2 + }; + parts[part].push(c); + column += unicode_width::UnicodeWidthChar::width(c).unwrap_or(0); + } + for (part, text) in parts.into_iter().enumerate() { + if text.is_empty() { + continue; + } + let style = if part == 1 { + span.style.add_modifier(Modifier::REVERSED) + } else { + span.style + }; + spans.push(Span::styled(text, style)); + } + } + line.spans = spans; +} + /// The links `line` shows, by their columns, their addresses taken off /// their spans' background, which the terminal would paint. fn unlinked(line: &mut Line<'static>) -> Vec { @@ -1284,6 +1492,83 @@ mod tests { assert_eq!(end[end.len() - 2], " line 21"); } + #[test] + fn a_drag_selects_shown_reversed_and_copies_the_text_alone() { + let (p, mut board, mut history) = joined(); + said(&mut board, &mut history, &p, "one\n\ntwo \n\nthree\n"); + let _ = history.take(60, Some("lead")); + let mut view = View::default(); + let first = rows(&view.shown(&history, &board, &p, Some("lead"), area(10), &[])); + let row = |text: &str| 2 + first.iter().position(|r| r == text).unwrap() as u16; + let (one, three) = (row(" one"), row(" three")); + // From the o of one to the e of three. + let shown = view.shown( + &history, + &board, + &p, + Some("lead"), + area(10), + &[ + Reading::Select(2, one), + Reading::Stretch(6, three), + Reading::Selected, + ], + ); + // Without the conversation's indent nor any padding. + assert_eq!(shown.copied.as_deref(), Some("one\n\ntwo\n\nthree")); + assert_eq!(shown.said.as_deref(), Some("copied 5 lines")); + let at = usize::from(one - 2); + let reversed: String = shown.lines[at] + .spans + .iter() + .filter(|span| span.style.add_modifier.contains(Modifier::REVERSED)) + .map(|span| span.content.as_ref()) + .collect(); + assert_eq!(reversed, "one"); + // A click puts it away. + let shown = view.shown( + &history, + &board, + &p, + Some("lead"), + area(10), + &[Reading::Click(0, 0)], + ); + assert!( + shown + .lines + .iter() + .flat_map(|line| &line.spans) + .all(|span| !span.style.add_modifier.contains(Modifier::REVERSED)) + ); + } + + #[test] + fn a_selection_held_at_the_edge_scrolls_the_conversation_and_holds() { + let (p, mut board, mut history) = joined(); + let lines: String = (1..=20).map(|n| format!("line {n}\n\n")).collect(); + said(&mut board, &mut history, &p, &lines); + let _ = history.take(60, Some("lead")); + let mut view = View::default(); + let mut shown = |readings: &[Reading]| { + view.shown(&history, &board, &p, Some("lead"), area(5), readings) + }; + let up = rows(&shown(&[Reading::Page(-2)])); + let middle = 2 + up.iter().position(|r| r.starts_with(" line")).unwrap() as u16 + 2; + let line_at = |shown: &[String], row: u16| shown[usize::from(row - 2)].clone(); + let from = line_at(&up, middle); + // Held at the top edge, a row at a time. + // Begun past the end of a row, which it holds whole. + let _ = shown(&[Reading::Select(59, middle), Reading::Stretch(2, 2)]); + let held = shown(&[Reading::Stretch(2, 2), Reading::Stretch(2, 2)]); + let top = rows(&held)[0].clone(); + assert_ne!(top, up[0], "it scrolled"); + let copied = shown(&[Reading::Selected]).copied.unwrap(); + // From the top shown now to where it began, as long as it holds. + assert!(copied.ends_with(from.trim()), "{copied:?}"); + assert!(copied.lines().count() > 3, "{copied:?}"); + } + #[test] fn answers_are_read_one_after_another_and_a_long_one_goes_back_to_its_top() { let (p, mut board, mut history) = joined(); diff --git a/crates/tui/src/graphics.rs b/crates/tui/src/graphics.rs index e840ca1..e87a801 100644 --- a/crates/tui/src/graphics.rs +++ b/crates/tui/src/graphics.rs @@ -30,6 +30,11 @@ pub(crate) fn detect(var: impl Fn(&str) -> Option) -> Option { /// The character Kitty shows an image under. const PLACEHOLDER: char = '\u{10EEEE}'; +/// Whether `c` is part of the cells an image shows under, not text. +pub(crate) fn image_cell(c: char) -> bool { + c == PLACEHOLDER || DIACRITICS.contains(&c) +} + /// The marks after a placeholder that say its row and column in the image: /// the first marks the first, and so on. Kitty's own list, /// `rowcolumn-diacritics.txt`. diff --git a/crates/tui/src/lib.rs b/crates/tui/src/lib.rs index 83d4d36..2d57e00 100644 --- a/crates/tui/src/lib.rs +++ b/crates/tui/src/lib.rs @@ -82,6 +82,10 @@ const CLOCK: Duration = Duration::from_secs(1); /// click that brought the person back to iq's window. const FOCUSING: Duration = Duration::from_millis(500); +/// How often the conversation scrolls a row while a selection is held at +/// its top or bottom edge, the mouse still. +const EDGE_SCROLL: Duration = Duration::from_millis(60); + /// Runs iq in the terminal until the person quits or iq is asked to stop: /// `board` as the settings made it, what `feed` brings, what the person /// asks of the crew sent on `requests`, the diagrams agents write drawn by @@ -739,7 +743,19 @@ impl Iq { /// what shows: the mouse moving changes it only as it comes over a /// link or leaves one. fn keys(&mut self, wait: Duration) -> io::Result { + // A selection held at the conversation's edge scrolls it on its own. + let edge = self.board.selecting().is_some_and(|(_, row)| { + self.screen + .drawn + .as_ref() + .is_some_and(|view| view.at_edge(row)) + }); + let wait = if edge { wait.min(EDGE_SCROLL) } else { wait }; match self.screen.tty.wait(wait) { + Wait::Nothing if edge => { + self.board.select_on(); + return Ok(true); + } Wait::Nothing => return Ok(false), Wait::Gone => { // Its window closed: nobody is there to answer, and the @@ -791,9 +807,17 @@ impl Iq { .take() .is_some_and(|at| at.elapsed() < FOCUSING); if !focusing { - self.board.click(mouse.column, mouse.row); + self.board.mouse_down(mouse.column, mouse.row); } } + // A drag selects in the conversation iq draws; a press + // let go where it was is a click. + MouseEventKind::Drag(MouseButton::Left) => { + self.board.mouse_drag(mouse.column, mouse.row); + } + MouseEventKind::Up(MouseButton::Left) => { + self.board.mouse_up(mouse.column, mouse.row); + } _ => {} }, Event::Resize(cols, rows) => { diff --git a/crates/ui/src/board.rs b/crates/ui/src/board.rs index 62ba96c..d48461e 100644 --- a/crates/ui/src/board.rs +++ b/crates/ui/src/board.rs @@ -138,6 +138,9 @@ const NAMED_IN_MESSAGE: &str = "named in the message"; /// The same, when it is the settings' lead. const SETTINGS_MODEL: &str = iq_agent::SETTINGS_MODEL; +/// A cell of the screen: its column and its row. +type Cell = (u16, u16); + /// What the person is notified of as a turn of theirs ends. const DONE_ALERT: &str = "Turn done"; @@ -243,6 +246,9 @@ pub struct Board { /// Whether the person asked to be notified once a turn of theirs ends /// or a question waits. notify: bool, + /// Where the mouse was pressed in the conversation iq draws, while it + /// is, and where it was moved to last once it moved: a selection. + pressed: Option<(Cell, Option)>, /// The notifications waiting for the terminal to send them. alerts: Vec<&'static str>, } @@ -300,6 +306,14 @@ pub enum Reading { Answer(isize), /// The person reads no more: the mark goes, and what was found. Leave, + /// A selection begins at the cell at this column and row: the mouse + /// was pressed there, then moved. + Select(u16, u16), + /// The selection reaches the cell at this column and row, the + /// conversation scrolled a row when it is at its top or bottom edge. + Stretch(u16, u16), + /// The selection is done, the mouse let go: what it holds is copied. + Selected, } /// The image a paste is, when it is the path of one alone: a file dropped @@ -371,6 +385,57 @@ impl Board { clicked: false, notify: false, alerts: Vec::new(), + pressed: None, + } + } + + /// The mouse was pressed on the cell at `column` and `row`: a click + /// once it comes up where it was, a selection once it moves. + pub fn mouse_down(&mut self, column: u16, row: u16) { + self.pressed = Some(((column, row), None)); + } + + /// The mouse, pressed, moved to the cell at `column` and `row`: in the + /// conversation iq draws, a selection from where it was pressed. + pub fn mouse_drag(&mut self, column: u16, row: u16) { + let Some((start, moved)) = self.pressed else { + return; + }; + if !self.drawn() || moved.is_none() && (column, row) == start { + return; + } + if moved.is_none() { + self.readings.push(Reading::Select(start.0, start.1)); + } + self.pressed = Some((start, Some((column, row)))); + self.readings.push(Reading::Stretch(column, row)); + } + + /// The mouse came up on the cell at `column` and `row`: the selection + /// made is copied, or, where it did not move, a click. + pub fn mouse_up(&mut self, column: u16, row: u16) { + match self.pressed.take() { + Some((_, Some(_))) => { + self.readings.push(Reading::Stretch(column, row)); + self.readings.push(Reading::Selected); + } + Some((start, None)) => self.click(start.0, start.1), + None => {} + } + } + + /// Where the mouse is held while it selects, for the conversation to + /// scroll on its own as it stays at its edge. + #[must_use] + pub fn selecting(&self) -> Option<(u16, u16)> { + self.pressed.and_then(|(_, moved)| moved) + } + + /// The mouse stays where it is while it selects: the conversation + /// scrolls on at its edge. + pub fn select_on(&mut self) { + if let Some((column, row)) = self.selecting() { + self.readings.push(Reading::Stretch(column, row)); } } @@ -2141,6 +2206,33 @@ mod tests { assert!(board.take_readings().is_empty()); } + #[test] + fn a_press_let_go_where_it_was_clicks_and_one_dragged_selects() { + let look = Look::default().with_conversation(crate::look::Conversation::Drawn); + let mut board = Board::new(Keymap::default(), look); + board.mouse_down(4, 9); + board.mouse_drag(4, 9); + board.mouse_up(4, 9); + assert_eq!(board.take_readings(), [Reading::Click(4, 9)]); + board.mouse_down(4, 9); + board.mouse_drag(7, 10); + assert_eq!(board.selecting(), Some((7, 10))); + // Held still at an edge, the same cell again. + board.select_on(); + board.mouse_up(8, 10); + assert_eq!( + board.take_readings(), + [ + Reading::Select(4, 9), + Reading::Stretch(7, 10), + Reading::Stretch(7, 10), + Reading::Stretch(8, 10), + Reading::Selected + ] + ); + assert_eq!(board.selecting(), None); + } + #[test] fn notifications_come_once_asked_and_say_nothing_of_the_work() { let mut board = Board::default(); diff --git a/src/settings.rs b/src/settings.rs index d4b6a8f..a29f3ad 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -34,7 +34,7 @@ //! job_lines = 3 # a background job's latest lines shown under its line while it runs, cut to the screen's width; 0 none //! turn_view = "panes" # a turn of several agents shown as panes side by side at the top, or "strip": a few lines of its map below the conversation; Ctrl-G opens the whole map either way //! diagrams_folded = false # a diagram shown as one line, unfolded in place with the down arrow while it is the last thing written -//! conversation = "scrollback" # the conversation written into the terminal's scrollback, or "drawn": drawn by iq on the terminal's other screen, the mouse taken, a click unfolding what is folded in place and enlarging a diagram, Shift and drag selecting; it stays out of the scrollback once iq ends +//! conversation = "drawn" # read no more, so that older settings load: iq draws the conversation on the terminal's other screen, the mouse taken, a click unfolding what is folded in place and enlarging a diagram, a drag selecting and copying through the terminal's clipboard (OSC 52), Shift and drag the terminal's own selection; it stays out of the scrollback once iq ends //! rules = ["~/.iq/AGENTS.md"] # your rules for every project, given to the agents you start; unless set, this one, else ~/.claude/CLAUDE.md //! autopilot_skill = "local-review" # a skill of yours the reviewer follows, kept outside the workspace, read again at each decision, never shown to the agents //! skills = ["~/.iq/skills"] # folders of your skills (a folder with its SKILL.md, or a .md file); this one unless set; the project's .claude/skills are read after them, yours winning a name both hold @@ -116,7 +116,14 @@ const CHAT_KEEP_DAYS: u64 = 30; /// What the settings once held and iq reads no more, since it works with /// the provider's models alone and lets the lead decide. -const RETIRED: [&str; 5] = ["budget", "steward", "[limits]", "[assay]", "[route]"]; +const RETIRED: [&str; 6] = [ + "budget", + "steward", + "[limits]", + "[assay]", + "[route]", + "conversation", +]; #[derive(Debug, Default, Deserialize)] #[serde(deny_unknown_fields)] @@ -421,6 +428,7 @@ impl Settings { self.limits.is_some(), self.assay.is_some(), self.route.is_some(), + self.conversation.is_some(), ] .into_iter() .zip(RETIRED) @@ -603,10 +611,10 @@ impl Settings { None => iq_ui::look::TurnShown::Panes, }) .with_diagrams_folded(self.diagrams_folded.unwrap_or(false)) - .with_conversation(match self.conversation.as_deref() { - Some(conversation) => conversation.parse().map_err(anyhow::Error::msg)?, - None => iq_ui::look::Conversation::Scrollback, - })) + // One way only: iq draws the conversation and selects in it + // itself. The setting is still read, so that older settings + // load. + .with_conversation(iq_ui::look::Conversation::Drawn)) } /// The model that sums up what agents write to each other, when set. @@ -966,7 +974,7 @@ mod tests { assert!(wrong.look().is_err()); // Older settings still open, what iq reads no more said. let older: Settings = toml::from_str( - "budget = 2.0\nsteward = true\n[limits]\nrequesty_month = 20.0\n[assay]\ngrader = \"x/y\"\n[route]\noff = true", + "budget = 2.0\nsteward = true\nconversation = \"scrollback\"\n[limits]\nrequesty_month = 20.0\n[assay]\ngrader = \"x/y\"\n[route]\noff = true", ) .unwrap(); assert_eq!(older.retired(), RETIRED);