From f72ba97502fe69edcf8b9df13a90e18a97606aae Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 20:45:52 +0100 Subject: [PATCH 1/5] A message posted during an agent's last call wakes it once its turn ends A turn that ended woke its agent again only for the person's messages. An answer from an agent it started, posted while its last call ran, waited unread until something else woke it, and was lost if iq started again in between, as the board's messages are not kept. A turn that ends now wakes its agent for what was written to it since it last read the board, as a message would have woken it resting: the person's, iq's, or that of an agent it started or one retired since, at once; a peer's at work under the same limit as when it rests, so that two agents writing to each other at their turns' ends do not wake each other forever. --- AGENTS.md | 2 +- crates/agent/src/crew.rs | 38 ++++++++++++++++++++++++-------- crates/agent/tests/crew.rs | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0039bc7..7516cd8 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, 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, 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), 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-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/agent/src/crew.rs b/crates/agent/src/crew.rs index d4b4af6..01b8060 100644 --- a/crates/agent/src/crew.rs +++ b/crates/agent/src/crew.rs @@ -2654,8 +2654,8 @@ where } self.retire_done(&name); } - // What the person wrote after its last look at the board. - if self.person_waits(&name) + // What was written to it after its last look at the board. + if self.woken_by_unread(&name) && let Some(news) = self.unread(&name) { self.wake(&name, news); @@ -3108,14 +3108,34 @@ where } } - /// Whether the person wrote to `agent` since it last read the board. - fn person_waits(&self, agent: &str) -> bool { - let board = lock(&self.inner.board); - board.members.get(agent).is_some_and(|member| { - board.messages[member.read..] + /// Whether what was written to `agent` since it last read the board + /// wakes it as its turn ends: the person's message, iq's, or that of an + /// agent it started or one retired since, at once; a peer's at work + /// while the two do not wake each other too often. Posted during its + /// last call, it would wait unread until something else woke it, and + /// be lost with the board were iq started again. + fn woken_by_unread(&self, agent: &str) -> bool { + let (direct, peer) = { + let board = lock(&self.inner.board); + let Some(member) = board.members.get(agent) else { + return false; + }; + let unread: Vec<&Posted> = board.messages[member.read..] .iter() - .any(|m| m.from == PERSON && (m.to == agent || m.to == ALL)) - }) + .filter(|m| (m.to == agent || m.to == ALL) && m.from != agent) + .collect(); + // A writer gone from the board wakes nobody in turn. + let peer_of = |m: &Posted| { + board + .members + .get(&m.from) + .is_some_and(|writer| writer.by != agent) + }; + let direct = unread.iter().any(|m| !peer_of(m)); + let peer = unread.iter().find(|m| peer_of(m)).map(|m| m.from.clone()); + (direct, peer) + }; + direct || peer.is_some_and(|from| self.peer_may_wake(&from, agent)) } /// A turn of one of iq's agents: its model called with its tools until diff --git a/crates/agent/tests/crew.rs b/crates/agent/tests/crew.rs index eba602c..0d9dc45 100644 --- a/crates/agent/tests/crew.rs +++ b/crates/agent/tests/crew.rs @@ -2079,6 +2079,50 @@ async fn a_model_too_slow_hands_the_call_to_its_backup() { assert_eq!(g.model.models_of("lead"), ["lab/main"]); } +#[tokio::test] +async fn a_message_sent_during_an_agent_s_last_call_wakes_it_once_its_turn_ends() { + let f = fixture( + &[ + ( + "lead", + vec![ + calls( + "start_agent", + serde_json::json!({"role": "helper", "model": "lab/medium", "task": "help"}), + ), + say("Started."), + say("Got its answer."), + ], + ), + ("lead/helper", vec![say("Done helping.")]), + ], + Settings::default(), + ); + // The lead's calls take longer than its helper's: the helper answers + // during the lead's last call. + let slow = [ + ("lab/slow", Duration::from_millis(400)), + ("lab/medium", Duration::from_millis(100)), + ]; + f.model + .slow_models + .lock() + .unwrap() + .extend(slow.map(|(model, time)| (model.to_owned(), time))); + f.crew + .start("lead", &model("lab/slow"), "go".into(), PERSON); + f.settled().await; + let seen = f.model.seen_by("lead"); + assert!( + seen.contains("Message from lead/helper: Done helping."), + "{seen}" + ); + assert!(f.events().contains(&Event::Done { + agent: "lead".into(), + outcome: Ok("Got its answer.".into()) + })); +} + #[tokio::test] async fn an_agent_names_a_model_whole_as_the_provider_lists_it() { let f = fixture( From 99d8aff4b1cc36720cd199b0c0966dab7943b9cc Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 20:47:55 +0100 Subject: [PATCH 2/5] An agent waits for all the agents it started in one call An agent that starts several was woken, and read its whole conversation again, at every message they wrote: most of such an agent's calls were waits. `wait_for_messages` with `until_done: true` waits until none of the agents it started works, or one asks it something it has not read, ten minutes at most, then gives all they wrote at once, once the board stayed quiet 300 ms, as an agent rests just before its answer is posted. --- AGENTS.md | 2 +- crates/agent/src/crew.rs | 56 ++++++++++++++++++++++++++++++++++++++ crates/agent/src/tools.rs | 10 +++++-- crates/agent/tests/crew.rs | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 7516cd8..74658fb 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), 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, 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/agent/src/crew.rs b/crates/agent/src/crew.rs index 01b8060..19ab9f4 100644 --- a/crates/agent/src/crew.rs +++ b/crates/agent/src/crew.rs @@ -69,6 +69,11 @@ const PEER_SPAN: Duration = Duration::from_secs(10 * 60); /// started still work. const WAIT_LOOK: Duration = Duration::from_secs(1); +/// How long the board stays quiet before an agent waiting for all those it +/// started is given their answers: one rests just before its answer is +/// posted. +const WAIT_QUIET: Duration = Duration::from_millis(300); + /// How many crews this program made: each numbers its questions apart /// from the others', so that an answer reaches the crew that asked when /// one window shows several. @@ -2491,6 +2496,54 @@ where } } + /// Waits until none of the agents `agent` started works, or one asks + /// it something it has not read, ten minutes at most, then gives all + /// that was written to it at once: one call, where waking at each + /// message would read its whole conversation again each time. + async fn wait_all(&self, agent: &str) -> String { + let mut posted = self.inner.posted.subscribe(); + let on = self.at_work_by(agent); + if !on.is_empty() { + self.report(Event::Waiting { + agent: agent.to_owned(), + on, + }); + } + let most = tokio::time::Instant::now() + Duration::from_secs(tools::WAIT_MOST); + loop { + posted.borrow_and_update(); + let asked = lock(&self.inner.raised) + .get(agent) + .is_some_and(|raised| !raised.is_empty()) + && self.has_unread(agent); + let now = tokio::time::Instant::now(); + if asked || !self.started_at_work(agent) || now >= most { + break; + } + let _ = tokio::time::timeout_at(most.min(now + WAIT_LOOK), posted.changed()).await; + } + // The answers of those who just rested, posted a moment after. + while tokio::time::Instant::now() < most + && matches!( + tokio::time::timeout(WAIT_QUIET, posted.changed()).await, + Ok(Ok(())) + ) + {} + let working = self.at_work_by(agent); + match (self.unread(agent), working.is_empty()) { + (Some(news), _) => news, + (None, true) => { + "The agents you started are done, and wrote nothing more to you.".to_owned() + } + (None, false) => format!( + "No message came in {} seconds, and {} still work. End your turn: their answers \ + will wake you.", + tools::WAIT_MOST, + working.join(", ") + ), + } + } + /// Whether an agent `agent` started works. fn started_at_work(&self, agent: &str) -> bool { !self.at_work_by(agent).is_empty() @@ -3581,6 +3634,9 @@ where Ok("Sent.".into()) } "wait_for_messages" => { + if args.flag("until_done") { + return Ok(self.wait_all(agent).await); + } let seconds = args .number("seconds") .unwrap_or(tools::WAIT_SECONDS) diff --git a/crates/agent/src/tools.rs b/crates/agent/src/tools.rs index 893ab66..5be5510 100644 --- a/crates/agent/src/tools.rs +++ b/crates/agent/src/tools.rs @@ -249,14 +249,18 @@ pub fn board() -> Vec { name: "wait_for_messages".into(), description: "Gives the messages written to you since you last read them, waiting \ up to `seconds` (30 by default) for one when there is none, and while \ - agents you started work, until one of them writes. Ending your turn \ - is the cheaper wait: an agent you started wakes you with its answer, \ - and each call made to wait again reads your whole conversation." + agents you started work, until one of them writes. With `until_done`, \ + waits until none of the agents you started works, or one asks you \ + something, ten minutes at most, and gives all they wrote at once: the \ + wait for several agents. Ending your turn is the cheaper wait for one: \ + it wakes you with its answer, and each call made to wait again reads \ + your whole conversation." .into(), parameters: json!({ "type": "object", "properties": { "seconds": {"type": "integer"}, + "until_done": {"type": "boolean", "description": "Wait until none of the agents you started works."}, }, }), }, diff --git a/crates/agent/tests/crew.rs b/crates/agent/tests/crew.rs index 0d9dc45..3082c1f 100644 --- a/crates/agent/tests/crew.rs +++ b/crates/agent/tests/crew.rs @@ -2079,6 +2079,55 @@ async fn a_model_too_slow_hands_the_call_to_its_backup() { assert_eq!(g.model.models_of("lead"), ["lab/main"]); } +#[tokio::test] +async fn waiting_until_done_gives_every_agent_s_answer_in_one_call() { + let start = |role: &str, model: &str| { + calls( + "start_agent", + serde_json::json!({"role": role, "model": model, "task": "help"}), + ) + }; + let f = fixture( + &[ + ( + "lead", + vec![ + start("first", "lab/quick"), + start("second", "lab/slower"), + calls("wait_for_messages", serde_json::json!({"until_done": true})), + say("Both answered."), + ], + ), + ("lead/first", vec![say("First done.")]), + ("lead/second", vec![say("Second done.")]), + ], + Settings::default(), + ); + let slow = [ + ("lab/quick", Duration::from_millis(50)), + ("lab/slower", Duration::from_millis(400)), + ]; + f.model + .slow_models + .lock() + .unwrap() + .extend(slow.map(|(model, time)| (model.to_owned(), time))); + f.crew.start("lead", &model("lab/m"), "go".into(), PERSON); + f.settled().await; + // One wait, both answers in it. + let requests = f.model.requests_of("lead"); + assert_eq!(requests.len(), 4, "{:#?}", f.events()); + let after = format!("{:?}", requests[3].messages); + assert!( + after.contains("First done.") && after.contains("Second done."), + "{after}" + ); + assert!(f.events().contains(&Event::Done { + agent: "lead".into(), + outcome: Ok("Both answered.".into()) + })); +} + #[tokio::test] async fn a_message_sent_during_an_agent_s_last_call_wakes_it_once_its_turn_ends() { let f = fixture( From 6e8301d114edc46e91eb9cdf6268b4baefce4525 Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 20:54:41 +0100 Subject: [PATCH 3/5] The conversation keeps the question and the answer, the agents' messages the strip A turn with half a dozen agents wrote every task and message between them into the conversation, several lines each, burying what the person asked and what they were answered. What agents write to each other, their tasks too, now stays out of the conversation, kept per chat for its turn. The turn's strip (`turn_view = "strip"`) shows the latest ten, a line each, the earlier counted. A turn of the person's chat in which other agents worked ends with one line that sums it up: the agents by model, the messages, the calls, the cost, and the key to every step. The summarizer is asked for one line of fifteen words at most. The steps' page still has everything whole. Not done: the panes show no messages, and an agent's line saying it joined stays in the conversation. --- AGENTS.md | 2 +- crates/tui/src/history.rs | 402 ++++++++++++++++++++++++++------------ crates/tui/src/live.rs | 79 ++++++++ src/summaries.rs | 5 +- 4 files changed, 358 insertions(+), 130 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 74658fb..cf3a0b7 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 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 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 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, 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 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/history.rs b/crates/tui/src/history.rs index 5612011..48b6775 100644 --- a/crates/tui/src/history.rs +++ b/crates/tui/src/history.rs @@ -39,6 +39,41 @@ use crate::wrap::{cut, fit, wrap}; /// sums it up. const MESSAGE_LINES: usize = 4; +/// How many of the latest messages between a chat's agents its turn's +/// strip shows, one line each. +pub(crate) const CHATTER_SHOWN: usize = 10; + +/// What one agent wrote to another in a chat's turn, kept out of its +/// conversation: the turn's strip shows the latest, the steps' page all. +#[derive(Debug, Clone)] +pub(crate) struct Chatted { + /// Its writer. + pub(crate) from: String, + /// Its reader. + pub(crate) to: String, + /// What it wrote, whole. + text: String, + /// Its summary, when a model sums messages up and it is long. + summary: Option>, +} + +impl Chatted { + /// What it says in a line: its summary once made, else its first line. + pub(crate) fn said(&self) -> String { + self.summary + .as_ref() + .and_then(|summary| summary.text()) + .unwrap_or_else(|| { + self.text + .lines() + .find(|line| !line.trim().is_empty()) + .unwrap_or_default() + .trim() + .to_owned() + }) + } +} + /// The longest line of a message written, in characters: a paragraph /// written as one line is cut there. const LINE_CHARS: usize = 200; @@ -165,14 +200,6 @@ pub(crate) enum Block { label: Label, tail: Vec>, }, - /// A message between agents summed up, under `indent`, in `style`; its - /// first lines, `instead`, until it is, or when it cannot be. - Summed { - summary: Arc, - instead: Vec, - indent: String, - style: Style, - }, } /// Whose turn a head begins. @@ -227,15 +254,6 @@ impl Block { .to_owned() } Block::Change { diff, .. } => diff.clone(), - Block::Summed { - summary, instead, .. - } => summary.text().unwrap_or_else(|| { - instead - .iter() - .map(|para| spans(¶.body)) - .collect::>() - .join("\n") - }), Block::Entry { blocks, .. } => blocks .iter() .map(Block::written) @@ -279,7 +297,6 @@ impl Block { match self { Block::Diagram { diagram, .. } => diagram.drawing(), Block::Entry { blocks, .. } => blocks.iter().any(Block::drawing), - Block::Summed { summary, .. } => summary.making(), Block::Job { label, .. } => label.making(), Block::Para(_) | Block::Change { .. } @@ -353,25 +370,6 @@ impl Block { } lines } - Block::Summed { - summary, - instead, - indent, - style, - } => match summary.text() { - Some(said) => said - .lines() - .filter(|line| !line.trim().is_empty()) - .flat_map(|line| { - let at = [Span::raw(indent.clone())]; - wrap(&[Span::styled(line.to_owned(), *style)], width, &at, &at) - }) - .collect(), - None => instead - .iter() - .flat_map(|para| wrap(¶.body, width, ¶.first, ¶.rest)) - .collect(), - }, Block::Diagram { diagram, code, @@ -515,6 +513,9 @@ pub(crate) struct History { /// The agents another started that the person wrote to: what they /// write until their turn ends is theirs to read. woken: HashSet, + /// The latest messages between each chat's agents in its turn, and + /// how many there were in all, with the turn's number. + chatter: HashMap)>, /// The model the turns of a thread written again answered on, as it /// says: their heads name it rather than the chat's model now. recalled_on: Option, @@ -660,18 +661,8 @@ impl History { } let by = board.crew().agent(agent).map(|a| a.by.clone()); match by { - Some(by) if by != PERSON => { - self.header(agent, board, p); - let id = board - .steps() - .latest_said() - .filter(|said| said.task && said.to == *agent) - .map(|said| said.id); - let mut head = vec![Span::styled("↳ its task", p.fg(p.info))]; - head.extend(numbered(id, p)); - self.push(Para::indented(" ", head)); - self.message(&by, agent, prompt, id, p); - } + // A task between agents stays out of the conversation. + Some(by) if by != PERSON => self.chatted(&by, agent, prompt, board), _ => self.person(prompt, agent, board, p), } } @@ -758,25 +749,11 @@ impl History { let out = markdown.flush(p); self.write(from, out, board, p); } else { + // Between agents: out of the conversation, which keeps + // the person's question and its answer. self.finish(from, board, p); self.folds(from, board, p); - self.set_speaker(None); - let (writer, reader) = - (self.shown_name(board, from), self.shown_name(board, to)); - let id = board - .steps() - .latest_said() - .filter(|said| !said.task && said.from == *from && said.to == *to) - .map(|said| said.id); - let mut head = vec![ - Span::styled("✉ ", p.fg(p.info)), - Span::styled(writer, p.fg(agent_tint(board, from, p))), - Span::styled(" → ", p.fg(p.faint)), - Span::styled(reader, p.fg(agent_tint(board, to, p))), - ]; - head.extend(numbered(id, p)); - self.push(Para::indented(" ", head)); - self.message(from, to, text, id, p); + self.chatted(from, to, text, board); } } Event::Done { agent, outcome } => { @@ -787,6 +764,9 @@ impl History { let turn = self.turns.remove(agent); match outcome { Ok(_) => { + if let Some(digest) = self.turn_digest(agent, board, p) { + self.push(digest); + } let mut said = String::new(); if let Some(turn) = turn { said.push_str(&seconds(turn.since.elapsed().as_secs())); @@ -896,10 +876,14 @@ impl History { } // Its turn's end says it, with the facts; the agents line // counts those retired. - Event::Failed { .. } - | Event::Retired { .. } - | Event::Turn { .. } - | Event::Window { .. } => {} + // A chat's new turn begins with none of its messages. + Event::Turn { chat, number, .. } => { + let kept = self.chatter.entry(chat.clone()).or_default(); + if kept.0 != *number { + *kept = (*number, 0, VecDeque::new()); + } + } + Event::Failed { .. } | Event::Retired { .. } | Event::Window { .. } => {} Event::Placed { agent, said: Some(said), @@ -1260,35 +1244,117 @@ impl History { } } - /// What `from` wrote to `to`, numbered `id` on the steps' page, under - /// its head: whole when it is short; else summed up, when a model sums - /// messages up, what comes after it waiting a little for it; else its - /// first lines. - fn message(&mut self, from: &str, to: &str, text: &str, id: Option, p: &Palette) { - const INDENT: &str = " "; + /// Keeps what `from` wrote to `to`, both agents of the chat written in, + /// for its turn's strip, summed up when a model sums messages up and it + /// is long: the summary is the steps' page's too. + fn chatted(&mut self, from: &str, to: &str, text: &str, board: &Board) { + let Some(chat) = self.at.clone() else { + return; + }; let lines: Vec<&str> = text.lines().filter(|l| !l.trim().is_empty()).collect(); - let short = lines.len() <= MESSAGE_LINES - && lines.iter().all(|line| line.chars().count() <= LINE_CHARS); - let said = match (&self.summarizer.0, id) { - (Some(summarize), Some(id)) if !short => { - let summary = Summary::new(from, to, text, Arc::clone(summarize)); - self.summaries.insert(id, Arc::clone(&summary)); - vec![Block::Summed { - summary, - instead: first_lines(text, INDENT, p, MESSAGE_LINES), - indent: INDENT.to_owned(), - style: p.fg(p.dim), - }] + let short = lines.len() <= 1 && lines.iter().all(|line| line.chars().count() <= LINE_CHARS); + let summary = self + .summarizer + .0 + .as_ref() + .filter(|_| !short) + .map(|summarize| Summary::new(from, to, text, Arc::clone(summarize))); + if let (Some(summary), Some(said)) = (&summary, board.steps().latest_said()) + && said.from == from + && said.to == to + { + self.summaries.insert(said.id, Arc::clone(summary)); + } + let kept = self.chatter.entry(chat).or_default(); + kept.1 += 1; + kept.2.push_back(Chatted { + from: from.to_owned(), + to: to.to_owned(), + text: text.to_owned(), + summary, + }); + while kept.2.len() > CHATTER_SHOWN { + kept.2.pop_front(); + } + } + + /// The latest messages between `chat`'s agents in its turn, oldest + /// first, and how many came before them. + pub(crate) fn chatter(&self, chat: &str) -> (Vec<&Chatted>, usize) { + self.chatter + .get(chat) + .map_or((Vec::new(), 0), |(_, all, kept)| { + (kept.iter().collect(), all.saturating_sub(kept.len())) + }) + } + + /// The line that sums up the turn of the person's chat `agent` leads, + /// as it ends, when other agents worked in it: who, on which models, + /// what they wrote each other, the calls, the cost, and where every + /// step is. + fn turn_digest(&self, agent: &str, board: &Board, p: &Palette) -> Option { + if board + .crew() + .agent(agent) + .is_none_or(|view| view.by != PERSON) + { + return None; + } + let turn = board.crew().turn(agent)?; + let others: Vec<&iq_ui::crew::TurnSpending> = turn + .by + .iter() + .filter(|spent| spent.who != agent && spent.who.contains('/')) + .collect(); + let messages = self.chatter.get(agent).map_or(0, |(_, all, _)| *all); + if others.is_empty() && messages == 0 { + return None; + } + let mut models: Vec<(String, usize)> = Vec::new(); + for spent in &others { + let short = spent + .model + .rsplit('/') + .next() + .unwrap_or(&spent.model) + .to_owned(); + match models.iter_mut().find(|(model, _)| *model == short) { + Some((_, count)) => *count += 1, + None => models.push((short, 1)), + } + } + let plural = |count: usize, one: &str| { + if count == 1 { + format!("1 {one}") + } else { + format!("{count} {one}s") } - _ => first_lines(text, INDENT, p, MESSAGE_LINES) - .into_iter() - .map(Block::Para) - .collect(), }; - match id { - Some(id) => self.push_block(Block::Entry { id, blocks: said }), - None => said.into_iter().for_each(|block| self.push_block(block)), + let mut said = plural(others.len(), "agent"); + if !models.is_empty() { + let on: Vec = models + .iter() + .map(|(model, count)| format!("{count} on {model}")) + .collect(); + said.push_str(&format!(" ({})", on.join(", "))); + } + let calls: u64 = turn.by.iter().map(|spent| spent.calls).sum(); + said.push_str(&format!( + " · {} · {} · {}", + plural(messages, "message"), + plural(usize::try_from(calls).unwrap_or(usize::MAX), "call"), + turn.total + )); + if let Some(chord) = board.keys().chord(Action::Steps) { + said.push_str(&format!(" · {chord} every step")); } + Some(Para::indented( + " ", + vec![ + Span::styled("⋯ ", p.fg(p.faint)), + Span::styled(said, p.fg(p.faint)), + ], + )) } /// Whether `agent`'s text goes in its pane rather than its chat's @@ -2050,13 +2116,6 @@ fn change(path: &str, diff: &str, p: &Palette) -> Block { } } -/// The number a message has on the steps' page, as its head ends: the -/// way to it whole. -fn numbered(id: Option, p: &Palette) -> Vec> { - id.map(|id| vec![Span::styled(format!(" #{id}"), p.fg(p.faint))]) - .unwrap_or_default() -} - /// The agent `event` is of, when it is of one. fn agent_of(event: &Event) -> Option<&str> { match event { @@ -3346,7 +3405,7 @@ mod tests { } #[test] - fn messages_between_agents_are_written_short_and_to_the_person_whole() { + fn messages_between_agents_stay_out_of_the_conversation_and_to_the_person_are_whole() { let p = Palette::new(Theme::Ink, Depth::True); let mut board = Board::default(); let mut history = History::default(); @@ -3401,13 +3460,8 @@ mod tests { lines, [ // In the chat's window, its own agent goes by its model; - // a message by its number on the steps' page too. + // what it wrote its helper is the turn's strip's. "◦ helper joins, on m, started by m", - " ✉ m → helper #1", - " 1", - " 2", - " 3", - " 4 …", "", "● helper m", " ✉ to you", @@ -3416,6 +3470,15 @@ mod tests { "› @helper thanks", ] ); + let (chatter, before) = history.chatter("lead"); + assert_eq!(before, 0); + assert_eq!( + chatter + .iter() + .map(|chatted| (chatted.from.as_str(), chatted.to.as_str(), chatted.said())) + .collect::>(), + [("lead", "helper", "1".to_owned())] + ); } /// Sums a message up as who wrote to whom, in a line. @@ -3669,22 +3732,32 @@ mod tests { } let lines = settled(&mut history, "lead"); let at = |line: &str| lines.iter().position(|l| l == line); - assert!(at(" ↳ its task #1").is_some(), "{lines:#?}"); - assert!( - at(" lead asks lead/tests for 6 lines").is_some(), - "{lines:#?}" - ); - // Each by its name in the chat's window: its part, and the lead its - // model. - assert!(at(" ✉ tests → m #2").is_some(), "{lines:#?}"); - assert!( - at(" lead/tests asks lead for 1 lines").is_some(), - "{lines:#?}" - ); + // The task and the message stay out of the conversation. + assert!(!lines.iter().any(|l| l.contains("asks")), "{lines:#?}"); assert!(at(" Docs too.").is_some(), "{lines:#?}"); assert!(!lines.iter().any(|l| l.contains("Reading the module"))); assert!(!lines.iter().any(|l| l.contains("Not this"))); - // Its summary is the page's too. + // The turn's strip says each in a line, summed up, and the summary + // is the page's too. + for _ in 0..200 { + if history.summed(2).is_some() { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + let said: Vec = history + .chatter("lead") + .0 + .iter() + .map(|chatted| chatted.said()) + .collect(); + assert_eq!( + said, + [ + "lead asks lead/tests for 6 lines", + "lead/tests asks lead for 1 lines" + ] + ); assert_eq!( history.summed(2).as_deref(), Some("lead/tests asks lead for 1 lines") @@ -3692,7 +3765,82 @@ mod tests { } #[test] - fn without_a_model_to_sum_up_a_message_its_first_lines_are_cut() { + fn a_turn_of_several_agents_ends_with_a_line_that_sums_it_up() { + let p = Palette::new(Theme::Ink, Depth::True); + let mut board = Board::default(); + let mut history = History::default(); + let joined = |agent: &str, model: &str, by: &str| Event::Joined { + agent: agent.into(), + model: model.into(), + by: by.into(), + }; + let spent = |agent: &str, model: &str| Event::Spent { + agent: agent.into(), + model: model.into(), + usage: iq_core::Usage::default(), + cost: Some(iq_core::Usd(0.1)), + cache: None, + chat: Some("lead".into()), + }; + let posted = |from: &str, to: &str| Event::Posted { + from: from.into(), + to: to.into(), + text: "the work".into(), + }; + for event in [ + joined("lead", "lab/opus", PERSON), + Event::Turn { + chat: "lead".into(), + number: 1, + ask_at: None, + }, + Event::Working { + agent: "lead".into(), + prompt: "fix the parser".into(), + }, + joined("lead/tests", "lab/haiku", "lead"), + joined("lead/docs", "lab/haiku", "lead"), + spent("lead", "lab/opus"), + spent("lead/tests", "lab/haiku"), + spent("lead/docs", "lab/haiku"), + spent("lead", "lab/opus"), + posted("lead", "lead/tests"), + posted("lead/tests", "lead"), + Event::Text { + agent: "lead".into(), + text: "Fixed.\n".into(), + }, + Event::Done { + agent: "lead".into(), + outcome: Ok("Fixed.".into()), + }, + ] { + crew(&mut board, &mut history, event, &p); + } + let lines = settled(&mut history, "lead"); + assert!( + lines.contains( + &" ⋯ 2 agents (2 on haiku) · 2 messages · 4 calls · $0.40 · Ctrl-X every step" + .to_owned() + ), + "{lines:#?}" + ); + // Its next turn starts with no message. + crew( + &mut board, + &mut history, + Event::Turn { + chat: "lead".into(), + number: 2, + ask_at: None, + }, + &p, + ); + assert!(history.chatter("lead").0.is_empty()); + } + + #[test] + fn without_a_model_to_sum_up_a_message_its_first_line_says_it() { let p = Palette::new(Theme::Ink, Depth::True); let mut board = Board::default(); let mut history = History::default(); @@ -3719,9 +3867,9 @@ mod tests { &p, ); let lines = settled(&mut history, "lead"); - let kept: usize = lines.iter().map(|l| l.matches('x').count()).sum(); - assert!(kept < LINE_CHARS, "{lines:#?}"); - assert!(lines.iter().any(|l| l.ends_with('…')), "{lines:#?}"); - assert!(lines.contains(&" the rest".to_owned()), "{lines:#?}"); + assert!(!lines.iter().any(|l| l.contains("xxx")), "{lines:#?}"); + // Its first line says it in the strip. + let (chatter, _) = history.chatter("lead"); + assert_eq!(chatter[0].said(), "x".repeat(500)); } } diff --git a/crates/tui/src/live.rs b/crates/tui/src/live.rs index 8c0ff21..836209c 100644 --- a/crates/tui/src/live.rs +++ b/crates/tui/src/live.rs @@ -182,6 +182,33 @@ impl Live<'_> { width, )); } + // What the agents wrote each other, out of the conversation: the + // latest, a line each, the earlier counted. + let (chatter, before) = self.history.chatter(&chat); + if before > 0 { + lines.push(fit( + vec![Span::styled(format!(" ✉ {before} before"), p.fg(p.faint))], + width, + )); + } + for chatted in chatter { + lines.push(fit( + vec![ + Span::styled(" ✉ ", p.fg(p.info)), + Span::styled( + label(self.board, &chatted.from).0, + p.fg(agent_tint(self.board, &chatted.from, p)), + ), + Span::styled(" → ", p.fg(p.faint)), + Span::styled( + label(self.board, &chatted.to).0, + p.fg(agent_tint(self.board, &chatted.to, p)), + ), + Span::styled(format!(" {}", chatted.said()), p.fg(p.dim)), + ], + width, + )); + } Some(Part::Lines(lines)) } @@ -1605,6 +1632,58 @@ mod tests { ); } + #[test] + fn the_strip_shows_the_latest_messages_between_agents_a_line_each() { + let p = Palette::new(Theme::Graphite, Depth::True); + let look = iq_ui::look::Look::default().with_turn(TurnShown::Strip); + let mut board = Board::new(iq_ui::keys::Keymap::default(), look); + let mut history = History::default(); + for event in [ + Event::Joined { + agent: "fix".into(), + model: "lab/opus".into(), + by: PERSON.into(), + }, + Event::Joined { + agent: "fix/tests".into(), + model: "lab/haiku".into(), + by: "fix".into(), + }, + Event::Working { + agent: "fix/tests".into(), + prompt: "write the tests".into(), + }, + ] { + crew(&mut board, &mut history, event, &p); + } + for n in 0..12 { + crew( + &mut board, + &mut history, + Event::Posted { + from: "fix/tests".into(), + to: "fix".into(), + text: format!("note {n}\nmore"), + }, + &p, + ); + } + board.screen_mut().talk_to("fix"); + let rows = drawn(&board, &history, 100); + // The task and the eleven earlier ones counted, the latest ten + // shown. + assert!( + rows.iter().any(|row| row.trim() == "✉ 3 before"), + "{rows:#?}" + ); + assert!( + rows.iter() + .any(|row| row.trim() == "✉ tests → opus note 11"), + "{rows:#?}" + ); + assert!(!rows.iter().any(|row| row.contains("note 1 ")), "{rows:#?}"); + } + #[test] fn a_turn_under_way_says_what_each_spent_in_it() { let mut board = Board::default(); diff --git a/src/summaries.rs b/src/summaries.rs index cf72ed7..1e4a8fc 100644 --- a/src/summaries.rs +++ b/src/summaries.rs @@ -18,8 +18,9 @@ const SUMMARIZER: &str = "summaries"; /// What the summarizer's model is told. const SUMMING: &str = "You sum up for a person what one agent of a coding harness wrote to \ - another, so that they follow the work without reading it all. In at most three short lines: \ - what is asked or answered, and what matters in it (a decision, a file, a number, what failed). \ + another, so that they follow the work without reading it all. In one line of fifteen words at \ + most: what is asked or answered, and what matters in it (a decision, a file, a number, what \ + failed). \ Write in the message's own language, plainly, with no preamble and no heading. The message \ follows, after who wrote it to whom."; From c4c0a15e5bf2c6d82ff50fcfc4acfd5719187598 Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 20:57:32 +0100 Subject: [PATCH 4/5] The person may be notified when a turn of theirs ends or a question waits A long turn runs while the person is elsewhere, and nothing told them it ended. Ctrl-P (`notify` in `[keys]`) turns notifications on, before or during a turn, and off again; the status line says so while they are on. A notification comes as a question waits ("Waiting for you") and as a turn of the person's ends, once none of its chat's agents works ("Turn done", which also turns them off). Its words are iq's own, never the work's, as a screen may be shared. It goes through the system's own tool, on a thread of its own and with iq in front too, as the person may be away from the screen: `notify-send` on Linux, which needs a notification daemon, `osascript` on macOS, where a terminal's own escape showed nothing until the system allowed its notifications. --- AGENTS.md | 2 +- crates/tui/src/lib.rs | 5 ++ crates/tui/src/live.rs | 13 +++++ crates/tui/src/notify.rs | 31 ++++++++++++ crates/ui/src/board.rs | 104 +++++++++++++++++++++++++++++++++++++++ crates/ui/src/keys.rs | 12 ++++- 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 crates/tui/src/notify.rs diff --git a/AGENTS.md b/AGENTS.md index cf3a0b7..e9deed8 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 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, 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` | 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 4966f11..89e0bf0 100644 --- a/crates/tui/src/lib.rs +++ b/crates/tui/src/lib.rs @@ -27,6 +27,7 @@ mod live; mod map; mod markdown; mod motion; +mod notify; mod pages; mod summary; mod table; @@ -303,6 +304,10 @@ impl Iq { Err(TryRecvError::Disconnected) => return Ok(()), } } + // Sent even with iq in front: the person may be away from it. + for alert in self.board.take_alerts() { + notify::notify(alert); + } for post in self.board.take_posts() { self.motion.posted(&post); } diff --git a/crates/tui/src/live.rs b/crates/tui/src/live.rs index 836209c..d6a2476 100644 --- a/crates/tui/src/live.rs +++ b/crates/tui/src/live.rs @@ -1280,6 +1280,19 @@ impl Live<'_> { left.push(Span::styled(format!(" · {shuts} shuts"), p.fg(p.bad))); left.push(sep()); } + if self.board.notifying() { + let stops = self + .board + .keys() + .chord(Action::Notify) + .map(|chord| format!(" · {chord} stops")) + .unwrap_or_default(); + left.push(Span::styled( + format!("🔔 notify at the turn's end{stops}"), + p.fg(p.info), + )); + left.push(sep()); + } if crew.autopilot() { left.push(Span::styled("⏵⏵ autopilot", p.fg(p.accent))); } else { diff --git a/crates/tui/src/notify.rs b/crates/tui/src/notify.rs new file mode 100644 index 0000000..1595b9f --- /dev/null +++ b/crates/tui/src/notify.rs @@ -0,0 +1,31 @@ +//! The system's notifications, sent through its own tool whatever the +//! terminal is: `notify-send` on Linux, which needs a notification daemon +//! as most desktops run, and `osascript` on macOS, where a terminal's own +//! escape shows nothing until the system allowed its notifications. + +use std::process::{Command, Stdio}; + +/// Shows `text` as a notification of the system's, titled iq, on a thread +/// of its own: iq never waits for it, and one that cannot be shown is +/// left. Only iq's own fixed words go there, never the work's. +pub(crate) fn notify(text: &'static str) { + std::thread::spawn(move || { + let mut command = if cfg!(target_os = "macos") { + let mut osascript = Command::new("osascript"); + osascript.args([ + "-e", + &format!("display notification \"{text}\" with title \"iq\""), + ]); + osascript + } else { + let mut send = Command::new("notify-send"); + send.args(["iq", text]); + send + }; + let _ = command + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); + }); +} diff --git a/crates/ui/src/board.rs b/crates/ui/src/board.rs index 55bf0a1..62ba96c 100644 --- a/crates/ui/src/board.rs +++ b/crates/ui/src/board.rs @@ -138,6 +138,12 @@ 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; +/// What the person is notified of as a turn of theirs ends. +const DONE_ALERT: &str = "Turn done"; + +/// What they are notified of as a question waits for them. +const WAITING_ALERT: &str = "Waiting for you"; + /// How many of the person's chats the switcher shows at once. pub const SWITCH_ROWS: usize = 5; @@ -234,6 +240,11 @@ pub struct Board { /// draws with a click: a letter is then what they start writing, /// never a key. clicked: bool, + /// Whether the person asked to be notified once a turn of theirs ends + /// or a question waits. + notify: bool, + /// The notifications waiting for the terminal to send them. + alerts: Vec<&'static str>, } /// A link the person points at in the conversation iq draws, the mouse @@ -358,9 +369,24 @@ impl Board { pointed: None, listed: false, clicked: false, + notify: false, + alerts: Vec::new(), } } + /// Whether the person asked to be notified once a turn of theirs ends + /// or a question waits. + #[must_use] + pub fn notifying(&self) -> bool { + self.notify + } + + /// The notifications to send since the terminal last took them: what + /// happened, never anything of the work, as a screen may be shared. + pub fn take_alerts(&mut self) -> Vec<&'static str> { + std::mem::take(&mut self.alerts) + } + /// Whether the person reads the conversation iq draws, the arrows /// moving the mark in it. #[must_use] @@ -1391,6 +1417,16 @@ impl Board { let open = self.crew.skills() != Some(chat.as_str()); return Some(Request::Skills { agent, open }); } + Action::Notify => { + self.notify = !self.notify; + let said = if self.notify { + "You are notified when a turn of yours ends or a question waits, until a \ + turn of yours ends" + } else { + "No notification" + }; + self.screen.notice(said, now); + } Action::Allow | Action::Refuse => { // The agents' questions first: they hold work. if let Some(id) = self.crew.questions().first().map(|q| q.id) { @@ -1945,7 +1981,28 @@ impl Board { } _ => {} } + let asked = matches!(event, Event::Asked { .. } | Event::Choose { .. }); + let done = match &event { + Event::Done { agent, .. } => self.crew.chat_of(agent), + _ => None, + }; self.crew.event(event); + if self.notify { + if asked { + self.alerts.push(WAITING_ALERT); + } + // A turn of the person's chat ends once none of its + // agents works: said, and nothing more is. + let chat_rests = done.is_some_and(|chat| { + !self.crew.agents().iter().any(|agent| { + agent.working && self.crew.chat_of(&agent.name).as_ref() == Some(&chat) + }) + }); + if chat_rests { + self.alerts.push(DONE_ALERT); + self.notify = false; + } + } } Update::Back(back) => { let agent = back.agent.clone(); @@ -2084,6 +2141,53 @@ mod tests { assert!(board.take_readings().is_empty()); } + #[test] + fn notifications_come_once_asked_and_say_nothing_of_the_work() { + let mut board = Board::default(); + joined(&mut board, "lead", PERSON); + joined(&mut board, "lead/tests", "lead"); + let asked = || { + Update::Crew(Event::Asked { + id: 1, + agent: "lead".into(), + action: "run `git push` to the secret project".into(), + reason: "it publishes".into(), + widens: true, + preview: None, + }) + }; + let working = |agent: &str| { + Update::Crew(Event::Working { + agent: agent.into(), + prompt: "go".into(), + }) + }; + let done = |agent: &str| { + Update::Crew(Event::Done { + agent: agent.into(), + outcome: Ok("pushed the secret project".into()), + }) + }; + // Not asked, none. + board.update(asked()); + assert!(board.take_alerts().is_empty()); + key(&mut board, "ctrl+p"); + assert!(board.notifying()); + // A question, then the turn's end once nothing of the chat works, + // in words of iq's own. + board.update(asked()); + board.update(working("lead")); + board.update(working("lead/tests")); + board.update(done("lead/tests")); + assert_eq!(board.take_alerts(), ["Waiting for you"]); + board.update(done("lead")); + assert_eq!(board.take_alerts(), ["Turn done"]); + // Then none, until asked again. + assert!(!board.notifying()); + board.update(asked()); + assert!(board.take_alerts().is_empty()); + } + #[test] fn the_skills_open_to_the_chat_written_to_and_shut_the_same_way() { let mut board = Board::default(); diff --git a/crates/ui/src/keys.rs b/crates/ui/src/keys.rs index ecea4c2..93aff6b 100644 --- a/crates/ui/src/keys.rs +++ b/crates/ui/src/keys.rs @@ -40,6 +40,9 @@ pub enum Action { /// The person's skills open to the agents of the chat written to until /// its turn ends, or shut. Skills, + /// A notification of the system's once a turn of the person's ends or + /// a question waits, until a turn of theirs ends; or none. + Notify, /// Allows what an agent asks, the oldest question first. Allow, /// Refuses it. @@ -59,7 +62,7 @@ pub enum Action { impl Action { /// Every action, in the order the list of shortcuts gives them. - pub const ALL: [Action; 17] = [ + pub const ALL: [Action; 18] = [ Action::Switch, Action::NewChat, Action::Team, @@ -70,6 +73,7 @@ impl Action { Action::Autopilot, Action::Internet, Action::Skills, + Action::Notify, Action::Allow, Action::Refuse, Action::Changes, @@ -93,6 +97,7 @@ impl Action { Action::Autopilot => "autopilot", Action::Internet => "internet", Action::Skills => "skills", + Action::Notify => "notify", Action::Allow => "allow", Action::Refuse => "refuse", Action::Changes => "changes", @@ -119,6 +124,9 @@ impl Action { Action::Skills => { "your skills open to the agents of this chat until its turn ends; again shuts them" } + Action::Notify => { + "a notification when a turn of yours ends or a question waits; again, none" + } Action::Allow => "allow what an agent asks", Action::Refuse => "refuse it", Action::Changes => "what a sync would send, line by line", @@ -144,6 +152,8 @@ impl Action { // B for the brief the skills are; a terminal multiplexer may // keep it, `/skills` does the same. Action::Skills => "ctrl+b", + // P for ping: free in the text the person writes. + Action::Notify => "ctrl+p", Action::Allow => "ctrl+y", Action::Refuse => "ctrl+r", Action::Changes => "ctrl+d", From 14c867e7c0aba0a96d5a2ee3c1ee1d7a1d39f32d Mon Sep 17 00:00:00 2001 From: Nicolas Godzik Date: Sat, 14 Nov 2026 21:23:46 +0100 Subject: [PATCH 5/5] A test waits for every summary of the strip, each made on its own thread The test of the messages kept out of the conversation waited for the summary of one of them only: the other, made on a thread of its own, could come later, and the test failed now and then. --- crates/tui/src/history.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/tui/src/history.rs b/crates/tui/src/history.rs index 48b6775..c2cc137 100644 --- a/crates/tui/src/history.rs +++ b/crates/tui/src/history.rs @@ -3739,18 +3739,22 @@ mod tests { assert!(!lines.iter().any(|l| l.contains("Not this"))); // The turn's strip says each in a line, summed up, and the summary // is the page's too. - for _ in 0..200 { - if history.summed(2).is_some() { + // Each summary is made on a thread of its own. + let said = |history: &History| -> Vec { + history + .chatter("lead") + .0 + .iter() + .map(|chatted| chatted.said()) + .collect() + }; + for _ in 0..400 { + if said(&history).iter().all(|line| line.contains("asks")) { break; } std::thread::sleep(std::time::Duration::from_millis(5)); } - let said: Vec = history - .chatter("lead") - .0 - .iter() - .map(|chatted| chatted.said()) - .collect(); + let said = said(&history); assert_eq!( said, [