From 37afd6d9ce3c6d23756dd9d437f49807c083fd6b Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Fri, 13 Nov 2026 20:30:56 +0100 Subject: [PATCH 1/8] A chat moved to another model sends its reasoning back no more The answers a model wrote keep the reasoning its provider returned, signed, and iq sends it back as it came. Another provider cannot check that signature and refuses the whole request: a chat moved from one model to another failed on its first call. The reasoning is taken off the conversation's answers before the first turn on the new model, their text whole. Should a provider still refuse a signature it cannot check, the call goes again once without those of the earlier turns, and they are sent no more; those of the turn under way stay, as a model may need them while it calls its tools. --- AGENTS.md | 2 +- crates/agent/src/crew.rs | 47 ++++++++++++++++-- crates/agent/src/keep.rs | 17 +++++++ crates/agent/tests/crew.rs | 97 +++++++++++++++++++++++++++++++++++++- 4 files changed, 158 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0921a1d..d855d4e 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, 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 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 it leads to is, 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, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most), 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 compacting it with its own summary once its request is done, when its skills say, 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 cost shown as any call's, unless the person names it first, an agent answered from its next turn by the model the person gives it, 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 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 it leads to is, 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, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most), 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 compacting it with its own summary once its request is done, when its skills say, 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 cost shown as any call's, unless the person names it first, 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, taken off then, their text whole, and a call refused for a signature its provider cannot check sent again once without those of the earlier turns), 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 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. 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/agent/src/crew.rs b/crates/agent/src/crew.rs index 3b22c33..b2bf9e7 100644 --- a/crates/agent/src/crew.rs +++ b/crates/agent/src/crew.rs @@ -22,7 +22,7 @@ use tokio::task::JoinHandle; use crate::event::{Event, PERSON}; use crate::extension::Extension; -use crate::keep::{Aside, Keeper, ModelChoice, Saved, Shown}; +use crate::keep::{Aside, Keeper, ModelChoice, Saved, Shown, forget_reasoning}; use crate::place::{Placed, Placer}; use crate::review; use crate::rules::{self, RulesFile}; @@ -705,6 +705,10 @@ struct Member { chosen: bool, /// Each choice of its model, the latest last. models_chosen: Vec, + /// Whether the reasoning its answers carry is taken off before its + /// next turn: its model changed, and only the provider that signed it + /// can check it. + forget_reasoning: bool, } /// An agent of the crew, as listed. @@ -985,6 +989,7 @@ where renaming: None, chosen: false, models_chosen: saved.models_chosen, + forget_reasoning: false, }, ); drop(board); @@ -1518,6 +1523,7 @@ where how: how.to_owned(), at: now(), }], + forget_reasoning: false, }, ); drop(board); @@ -1745,6 +1751,7 @@ where .ok_or_else(|| format!("no agent is named {agent:?}"))?; let mut place = None; if let Some(member) = board.members.get_mut(&name) { + member.forget_reasoning |= member.model != *model; member.model = model.clone(); member.models_chosen.push(ModelChoice { model: model.to_string(), @@ -2443,8 +2450,11 @@ where /// leaves the agent as it was before it. async fn turn(self, name: String, prompt: String, number: u64) { let (taken, posted_before) = { - let board = lock(&self.inner.board); - let taken = board.members.get(&name).map(|member| { + let mut board = lock(&self.inner.board); + let taken = board.members.get_mut(&name).map(|member| { + if std::mem::take(&mut member.forget_reasoning) { + forget_reasoning(&mut member.messages); + } ( member.messages.clone(), member.model.clone(), @@ -2964,6 +2974,10 @@ where // What the last call that answered read: all but the answer it // gave, which is read from the next. let mut counted = messages.len().saturating_sub(1); + // The turns before this one, whose reasoning may be another + // model's. + let earlier = messages.len(); + let mut forgotten = false; messages.push(Message::user(prompt)); if let Some(member) = lock(&self.inner.board).members.get_mut(name) { member.reason = None; @@ -3009,6 +3023,22 @@ where self.measure(name, model).await; let response = match self.ask_model(name, &request).await { Ok(response) => response, + // A signature its provider cannot check, written as another + // model answered: the call goes again once without them. + Err(failed) + if !forgotten + && signature_refused(&failed) + && forget_reasoning(&mut messages[..earlier]) => + { + forgotten = true; + self.report(Event::Notice { + agent: name.to_owned(), + text: "its provider refused the reasoning its earlier answers carry, \ + signed for another model: it is called again without it" + .into(), + }); + continue; + } Err(failed) => { let said = self.failed(name, model, failed, &messages[counted..]); return (messages, Err(said)); @@ -4810,6 +4840,17 @@ fn context_said(context: TokenCount, rises: Option) -> String { format!("(iq: your conversation is {context} tokens now, read again on each call{past}.)") } +/// Whether `failed` is a provider refusing a signature of reasoning it +/// cannot check, rather than one it misses. +fn signature_refused(failed: &Failure) -> bool { + failed.refusal.as_ref().is_some_and(|refusal| { + let said = refusal.message.to_lowercase(); + (400..500).contains(&refusal.status) + && said.contains("signature") + && !said.contains("missing") + }) +} + /// A conversation compacted: its standing instructions, its task and the /// summary its agent wrote of the rest, then its last answer. fn compacted( diff --git a/crates/agent/src/keep.rs b/crates/agent/src/keep.rs index d8d9d85..bbcbb44 100644 --- a/crates/agent/src/keep.rs +++ b/crates/agent/src/keep.rs @@ -157,6 +157,23 @@ pub struct ModelChoice { pub at: u64, } +/// Takes off what the answers of `messages` carry of their model's +/// reasoning, as its provider signed it: their text stays. Returns whether +/// any carried it. +pub(crate) fn forget_reasoning(messages: &mut [Message]) -> bool { + let mut forgot = false; + for message in messages { + if let Message::Assistant { + reasoning_signature, + .. + } = message + { + forgot |= reasoning_signature.take().is_some(); + } + } + forgot +} + /// Keeps the chats between sessions. pub trait Keeper: Send + Sync { /// Keeps `chat` as it stands now, in place of what was kept of it. diff --git a/crates/agent/tests/crew.rs b/crates/agent/tests/crew.rs index 4e60cbe..7d78154 100644 --- a/crates/agent/tests/crew.rs +++ b/crates/agent/tests/crew.rs @@ -23,6 +23,9 @@ struct Scripted { /// How many of each agent's calls are answered before its provider /// refuses the others. refused: Mutex>, + /// Whether the provider refuses a call that sends a reasoning back, as + /// one refuses another's signature. + refuses_signed: Mutex, } /// What the scripted provider fails with. @@ -32,6 +35,8 @@ enum Failed { Busy, /// Refused, whatever is tried again. Refused, + /// Refused for a signature of reasoning it cannot check. + Signed, } impl std::fmt::Display for Failed { @@ -39,12 +44,16 @@ impl std::fmt::Display for Failed { match self { Failed::Busy => f.write_str("HTTP 429: TPM quota exhausted, please try again later"), Failed::Refused => f.write_str("HTTP 400: Request contains an invalid argument."), + Failed::Signed => f.write_str(SIGNED), } } } impl std::error::Error for Failed {} +/// What a provider says of a signature of reasoning it cannot check. +const SIGNED: &str = "messages.3.content.0: Invalid `signature` in `thinking` block"; + impl Scripted { fn new(scripts: &[(&str, Vec)]) -> Arc { Arc::new(Self { @@ -57,6 +66,7 @@ impl Scripted { requests: Mutex::default(), busy: Mutex::default(), refused: Mutex::default(), + refuses_signed: Mutex::default(), }) } @@ -174,6 +184,9 @@ impl ChatModel for Model { } *left -= 1; } + if *self.refuses_signed.lock().unwrap() && signed(request) { + return Err(Failed::Signed); + } let next = self .scripts .lock() @@ -188,7 +201,7 @@ impl ChatModel for Model { Failed::Busy => Some(Busy { after: Some(Duration::from_millis(1)), }), - Failed::Refused => None, + Failed::Refused | Failed::Signed => None, } } @@ -199,10 +212,35 @@ impl ChatModel for Model { status: 400, message: "Request contains an invalid argument.".into(), }), + Failed::Signed => Some(iq_core::Refusal { + status: 400, + message: SIGNED.into(), + }), } } } +/// Whether `request` sends a reasoning back with one of its answers. +fn signed(request: &ChatRequest) -> bool { + request.messages.iter().any(|message| { + matches!( + message, + Message::Assistant { + reasoning_signature: Some(_), + .. + } + ) + }) +} + +/// `text`, said with a reasoning its provider signed. +fn reasoned(text: &str) -> ChatResponse { + ChatResponse { + reasoning_signature: Some(serde_json::json!("c2lnbmVk")), + ..say(text) + } +} + fn say(text: &str) -> ChatResponse { ChatResponse { content: Some(text.to_owned()), @@ -1588,6 +1626,63 @@ async fn a_model_the_person_does_not_allow_is_refused_with_those_they_do() { assert!(f.crew.set_model("lead", &model("lab/quill")).is_ok()); } +#[tokio::test] +async fn a_chat_moved_to_another_model_sends_its_reasoning_back_no_more() { + let f = fixture( + &[( + "lead", + vec![reasoned("First."), reasoned("Second."), say("Third.")], + )], + Settings::default(), + ); + f.crew.start("lead", &model("lab/sol"), "go".into(), PERSON); + f.settled().await; + // On the same model, its reasoning goes back with its answer. + f.crew.tell("lead", "and then?".into()).unwrap(); + f.settled().await; + assert!(signed(f.model.requests_of("lead").last().unwrap())); + // On another, its answers go back without it, their text whole. + f.crew.set_model("lead", &model("lab/haiku")).unwrap(); + f.crew.tell("lead", "and after?".into()).unwrap(); + f.settled().await; + let last = f.model.requests_of("lead").pop().unwrap(); + assert_eq!(last.model.as_str(), "lab/haiku"); + assert!(!signed(&last)); + assert!(format!("{:?}", last.messages).contains("Second.")); +} + +#[tokio::test] +async fn a_reasoning_another_provider_cannot_check_is_left_out_and_the_call_made_again() { + let f = fixture( + &[("lead", vec![reasoned("First."), say("Second.")])], + Settings::default(), + ); + f.crew.start("lead", &model("lab/sol"), "go".into(), PERSON); + f.settled().await; + *f.model.refuses_signed.lock().unwrap() = true; + f.crew.tell("lead", "and then?".into()).unwrap(); + f.settled().await; + let events = f.events(); + assert!( + events.contains(&Event::Done { + agent: "lead".into(), + outcome: Ok("Second.".into()) + }), + "{events:#?}" + ); + assert!(events.iter().any(|event| matches!( + event, + Event::Notice { text, .. } if text.starts_with("its provider refused the reasoning") + ))); + // Once left out, it is sent no more. + let requests = f.model.requests_of("lead"); + assert_eq!(requests.len(), 3); + assert!(signed(&requests[1]) && !signed(&requests[2])); + f.crew.tell("lead", "and after?".into()).unwrap(); + f.settled().await; + assert_eq!(f.model.requests_of("lead").len(), 4); +} + #[tokio::test] async fn an_agent_names_a_model_whole_as_the_provider_lists_it() { let f = fixture( From 7528cc724b017c874986fef437413f7be866226d Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Fri, 13 Nov 2026 20:33:10 +0100 Subject: [PATCH 2/8] A chat that comes back follows the settings' lead, unless its model was chosen A chat the person started came back on the model it ran on, whatever the settings name now: after changing the lead in the settings, every chat that came back still ran on the old one, and only new chats took the new lead. A chat whose model nobody chose, started on the settings' model, now comes back on the settings' lead, said as iq starts ("fix answers on , the settings' lead, from its next turn (it was on )"), the move kept with its choices and its answers' reasoning taken off. One the person gave a model (`/model`, `--model`, `/new` or its first message) stays on it, as do the agents a lead started. --- AGENTS.md | 2 +- crates/agent/src/keep.rs | 34 +++++++++++++++++++++++ crates/agent/src/lib.rs | 2 +- crates/ui/src/board.rs | 2 +- src/chats.rs | 58 ++++++++++++++++++++++++++++++++++++++++ src/main.rs | 9 ++++++- 6 files changed, 103 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d855d4e..e7865a5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -68,7 +68,7 @@ Separation of concerns is **enforced by the crate dependency graph**, not by con | `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 in a few lines under the number the steps' page gives it (summed up by a cheap model when the settings name one, what follows waiting a little for it, else its first lines, each cut), 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 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 oldest question waiting of any chat, apart from the agents, said from another chat when it is, 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, 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 | +| `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, a chat of the person's whose model nobody chose (`SETTINGS_MODEL`) moved to the settings' lead when they changed it, said as iq starts and kept with its choices, one given a model with `/model`, `--model`, `/new` or its first message staying on it, 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/agent/src/keep.rs b/crates/agent/src/keep.rs index bbcbb44..0986fa1 100644 --- a/crates/agent/src/keep.rs +++ b/crates/agent/src/keep.rs @@ -7,6 +7,12 @@ use std::path::PathBuf; use iq_core::{Effort, Message, Usd}; use serde::{Deserialize, Serialize}; +use crate::PERSON; + +/// How a chat came to run on the model the settings name for the person's +/// chats: chosen by none, it follows them as they change. +pub const SETTINGS_MODEL: &str = "the settings' model"; + /// An agent and its conversation, as kept. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Saved { @@ -59,6 +65,34 @@ pub struct Saved { pub messages: Vec, } +impl Saved { + /// Whether the chat runs on the model the settings name, as the person + /// started it: they chose none for it, and it follows the settings as + /// they change. + #[must_use] + pub fn follows_settings(&self) -> bool { + self.by == PERSON + && self + .models_chosen + .last() + .is_none_or(|choice| choice.how == SETTINGS_MODEL) + } + + /// Moves the chat to `model`, which `by` chose as `how` says at `at`, + /// from its next turn: its answers keep their text, not the reasoning + /// their provider signed, which another provider cannot check. + pub fn move_to(&mut self, model: &str, by: &str, how: &str, at: u64) { + forget_reasoning(&mut self.messages); + model.clone_into(&mut self.model); + self.models_chosen.push(ModelChoice { + model: model.to_owned(), + by: by.to_owned(), + how: how.to_owned(), + at, + }); + } +} + /// One thing the person was shown of an agent beside its conversation, /// with when and in which of its turns, so that its chat can be read /// back as it happened. diff --git a/crates/agent/src/lib.rs b/crates/agent/src/lib.rs index 89ea235..7ff8530 100644 --- a/crates/agent/src/lib.rs +++ b/crates/agent/src/lib.rs @@ -36,7 +36,7 @@ pub use crew::{ }; pub use event::{Event, PERSON}; pub use extension::{Called, Extension}; -pub use keep::{Aside, Keeper, ModelChoice, Saved, Shown}; +pub use keep::{Aside, Keeper, ModelChoice, SETTINGS_MODEL, Saved, Shown}; pub use once::{Asked, ask_once}; pub use place::{Placed, Placer}; pub use rules::{RulesFile, with_imports}; diff --git a/crates/ui/src/board.rs b/crates/ui/src/board.rs index f8ebd5b..46ae752 100644 --- a/crates/ui/src/board.rs +++ b/crates/ui/src/board.rs @@ -136,7 +136,7 @@ const OFFERED: usize = 8; const NAMED_IN_MESSAGE: &str = "named in the message"; /// The same, when it is the settings' lead. -const SETTINGS_MODEL: &str = "the settings' model"; +const SETTINGS_MODEL: &str = iq_agent::SETTINGS_MODEL; /// How many of the person's chats the switcher shows at once. pub const SWITCH_ROWS: usize = 5; diff --git a/src/chats.rs b/src/chats.rs index 7d82dd1..3bf7050 100644 --- a/src/chats.rs +++ b/src/chats.rs @@ -197,6 +197,21 @@ impl Keeper for Chats { } } +/// Moves `chat` to `lead`, the settings' lead, at `at`, when it follows +/// the settings and runs on another: the person changed their lead since. +/// Returns what the person is told of it. +pub(crate) fn on_the_lead(chat: &mut Saved, lead: &str, at: u64) -> Option { + if !chat.follows_settings() || chat.model == lead { + return None; + } + let was = chat.model.clone(); + chat.move_to(lead, iq_agent::PERSON, iq_agent::SETTINGS_MODEL, at); + Some(format!( + "{} answers on {lead}, the settings' lead, from its next turn (it was on {was})", + chat.name + )) +} + /// Where the agents retired are kept, under a project's chats. const RETIRED: &str = "retired"; @@ -256,6 +271,49 @@ mod tests { } } + #[test] + fn a_chat_on_the_settings_model_follows_them_and_one_chosen_stays() { + let mut chat = saved("fix"); + chat.models_chosen[0].how = iq_agent::SETTINGS_MODEL.to_owned(); + chat.messages.push(Message::Assistant { + content: Some("Fixed.".into()), + tool_calls: Vec::new(), + reasoning_signature: Some(serde_json::json!("c2lnbmVk")), + }); + assert_eq!( + on_the_lead(&mut chat, "lab/haiku", 9).as_deref(), + Some( + "fix answers on lab/haiku, the settings' lead, from its next turn (it was on lab/model)" + ) + ); + assert_eq!(chat.model, "lab/haiku"); + let last = chat.models_chosen.last().unwrap(); + assert_eq!((last.how.as_str(), last.at), (iq_agent::SETTINGS_MODEL, 9)); + // Its answers go on without the reasoning another model signed. + assert!(chat.messages.iter().all(|message| !matches!( + message, + Message::Assistant { + reasoning_signature: Some(_), + .. + } + ))); + // On the lead, and once it was moved, it stays. + assert_eq!(on_the_lead(&mut chat, "lab/haiku", 10), None); + assert_eq!(chat.models_chosen.len(), 2); + // A model the person chose for it stays, as does an agent's. + let mut chosen = saved("chosen"); + chosen.models_chosen[0].how = "/model".to_owned(); + assert_eq!(on_the_lead(&mut chosen, "lab/haiku", 9), None); + let mut started = saved("lead/tests"); + started.by = "lead".to_owned(); + started.models_chosen.clear(); + assert_eq!(on_the_lead(&mut started, "lab/haiku", 9), None); + // One kept before choices were, the settings'. + let mut older = saved("older"); + older.models_chosen.clear(); + assert!(on_the_lead(&mut older, "lab/haiku", 9).is_some()); + } + #[test] fn a_chat_is_kept_whole_listed_and_forgotten_once_old() { let dir = tempfile::tempdir().unwrap(); diff --git a/src/main.rs b/src/main.rs index 3fe39a4..efb7795 100644 --- a/src/main.rs +++ b/src/main.rs @@ -403,6 +403,13 @@ fn resume_chats( if let Some(by) = names.get(&found.chat.by) { found.chat.by.clone_from(by); } + if let Ok(lead) = settings.lead() { + said.extend(chats::on_the_lead( + &mut found.chat, + lead.as_str(), + iq_ui::now(), + )); + } if !allowed.is_empty() && !allowed.iter().any(|a| a.as_str() == found.chat.model) { said.push(format!( "{} runs on {}, which allowed_models leaves out: /model gives it another", @@ -918,7 +925,7 @@ async fn work( if cli.model.is_some() { "--model" } else { - "the settings' model" + iq_agent::SETTINGS_MODEL }, ); let mut tally = terminal::Tally::default(); From f5bc3fcba70d534798220e67410d2dbcb47d63dc Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Fri, 13 Nov 2026 20:40:39 +0100 Subject: [PATCH 3/8] A compacted chat comes back as it was shown, each turn under its model A chat that was compacted came back, when iq started again, as a list of headers and of what was set aside (stops, errors, questions), with no answer between them: its thread was rebuilt from its messages, which the compaction had replaced by its summary. And every past turn was headed by the model the chat runs on now, even those another model answered. A compaction now keeps the messages it replaces with the chat, whole and in order, leaving out what the compaction before wrote (its summary, and its last answer said again), and the thread is rebuilt from the whole: what was replaced, then what the conversation holds since. What is set aside is placed among those messages, so that it stands where it came. Each turn sets aside the model it answers on when it is not the one before, and a chat that comes back heads each of its turns with it. --- AGENTS.md | 2 +- crates/agent/src/crew.rs | 68 +++++++++++++++++++++-- crates/agent/src/keep.rs | 56 ++++++++++++++++++- crates/agent/tests/crew.rs | 103 +++++++++++++++++++++++++++++++++-- crates/tui/src/history.rs | 87 ++++++++++++++++++++++++++++- crates/tui/src/pages/team.rs | 11 ++++ crates/ui/src/crew.rs | 4 ++ crates/ui/src/steps.rs | 6 +- src/chats.rs | 2 + src/main.rs | 4 +- 10 files changed, 328 insertions(+), 15 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e7865a5..ea2ff3d 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, 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 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 it leads to is, 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, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most), 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 compacting it with its own summary once its request is done, when its skills say, 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 cost shown as any call's, unless the person names it first, 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, taken off then, their text whole, and a call refused for a signature its provider cannot check sent again once without those of the earlier turns), 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 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 it leads to is, 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, an agent waiting there for the agents it started waiting until one of them writes, whatever time it gave, ten minutes at most), 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 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 cost shown as any call's, unless the person names it first, 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, taken off then, their text whole, and a call refused for a signature its provider cannot check sent again once without those of the earlier turns), 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 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. 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/agent/src/crew.rs b/crates/agent/src/crew.rs index b2bf9e7..1b6e40b 100644 --- a/crates/agent/src/crew.rs +++ b/crates/agent/src/crew.rs @@ -22,7 +22,7 @@ use tokio::task::JoinHandle; use crate::event::{Event, PERSON}; use crate::extension::Extension; -use crate::keep::{Aside, Keeper, ModelChoice, Saved, Shown, forget_reasoning}; +use crate::keep::{Aside, Keeper, ModelChoice, Saved, Shown, forget_reasoning, placed}; use crate::place::{Placed, Placer}; use crate::review; use crate::rules::{self, RulesFile}; @@ -479,6 +479,10 @@ struct AsideLog { turn: u64, /// How many messages its conversation holds, as far as told. messages: usize, + /// How many messages its compactions replaced, and how many its last + /// wrote: where its conversation stands in what it was. + away: usize, + head: usize, /// What was set aside, in order. kept: Vec