diff --git a/AGENTS.md b/AGENTS.md index c738703..0039bc7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,19 +56,19 @@ Separation of concerns is **enforced by the crate dependency graph**, not by con | Crate | Single responsibility | |------------|----------------------------------------------------------------------------| | `iq-core` | Domain types and traits, zero I/O, zero network | -| `iq-llm` | Model providers, one `impl ChatModel` per protocol: Requesty's router, and any OpenAI compatible endpoint, with the models it lists and their prices, dearer past a size of conversation where its tiers say, and whether an error says the provider is out of capacity for now (a quota for the minute, an overload, a connection never made) with how long it asked to be left, from its headers or its words; what it said as it refused a call, in its own words (`Refusal`); the signature a model gives its reasoning kept with its answer and sent back as it came; Claude's requests marked for the cache by iq itself, and those of any model whose name holds a word the settings' `cache_marks` give, the others left to the router | +| `iq-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 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, taken off then, their text whole, and a call refused for a signature its provider cannot check sent again once without those of the earlier turns), a call to a provider out of capacity sent again as many times as the settings say, after as long as it asks and a wait doubling at each try, each wait said, then the turn ended saying the conversation is kept to go on later or on another model, a call the provider refused reported with its status, the provider's own words, the model, about how many tokens it held and what the agent had spent until then (`Event::Failed`, which the binary writes to iq's log), the agent that started the failed one told those facts as iq's, never left to an agent to tell, and the tools another part of iq offers some agents as an extension, read again at each call so that one an agent asked for is offered from its next step, whose calls act through the crew and ask the person through it, an extension answering a call of a tool it has not described whole yet, and showing a model an image after its step's results (an image a file holds, read with `read_file`, a folder listed the latest first; one an MCP tool answers with; one the person attached, with a chat's task or a message); `ask_person`, a question with two to four choices for the person, its answer kept with what they asked of the agent, an agent another started asking that agent first (a message it must answer, with iq's account of the asker's role and what it spent, which it answers or puts to the person, who is then told who raised it, through whom, and what they spent), so that the person is never asked the same thing by several agents at once, every agent told to stop and ask rather than go on alone past its part, its brief or its budget, or with what it found of uncertain worth; `run` that failed in the sandbox for want of the person's ssh keys, as its output shows, told that a git command reaching a remote over ssh runs on the machine; `run` left in the background, read as it runs, stopped, its end waking its agent, its latest lines said at most twice a second as they change (`Event::JobOutput`) and the end of its output said with its end; `wake_me`, a wake after a time the agent chooses, three waiting at once and twelve within an hour, so that an agent waking itself again and again is held; whom a chat waits for said (`Event::Waiting`). Generic over `ChatModel` | +| `iq-agent` | The crew: iq's agents (a model of the provider in a loop with its tools, each acting through the gate, each file one writes or edits said with how its lines changed, a unified diff with three lines around each change, what both ends share at their start and their end set aside first, a line past 400 characters cut (`diff.rs`, `Event::Changed`), before the step that wrote it, never for a file of secrets, as the agent named it or as the file 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-observe` | What iq's work goes to: the journal's tasks, the categories of work the person names in their settings with rules if they wish, the rules placing a task first, then a cheap model in the background, shown the categories and the tasks placed before so that it keeps to them, its placements kept beside the journal, a day's placing capped; nothing leaves the machine. Generic over `ChatModel` | -| `iq-memory` | What the agents the person starts know beyond their task: the project's notes, each a Markdown file with its name and what it holds, kept by the address of the project's repository so that the same project on another machine finds them, the notes kept of the project under `~/.claude` read beside them and never changed; and the person's skills, Markdown files in the folders the settings list (a folder with its `SKILL.md`, or a file), each listed by name and read whole with a tool before the work it is for. A secret is never kept nor given. The selected skill for permission reviews is read again at each decision and kept outside the workspace so commands cannot rewrite their own policy, never shown to the agents, a missing, unreadable or unsafe skill leaving the decision to the person. Extensions of the crew: the notes for leads, the skills for every agent (one another started may start agents in turn, and chooses them as the skills say), and review policy | +| `iq-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 | | `iq-mcp` | A client of the Model Context Protocol: the servers the person's settings declare, over streamable HTTP (with the headers they give, each value read from a variable, or with OAuth when the server asks for it: its metadata found where its refusal points, else where it is looked for, a client registered for iq, the person's consent in the browser with PKCE, the grant kept in iq's own folder for the address it was given for alone, renewed before it ends, asked again once refused) or over stdio (a program run on the machine as the person's, with their environment but iq's variables, its line written to the audit log, its own requests answered, the last lines of its errors said when it stops, started again for the next call), each started on a task of its own and said to the person as it answers, their tools listed to every agent by one tool, each by its name and the first line of what it does, and given whole to an agent once it asks for a server's (or calls one of its tools), as `__`, so that what a server offers weighs on no call that does not need it, the settings choosing which of a server's tools are offered at all, each call judged by the gate and made only with the permit it gives, its answer cut where a command's output is. An extension of the crew | | `iq-web` | The web as the crew's agents read it, with tools of iq's own: `fetch`, a page of the public web as Markdown, its main content alone (its menus, scripts, styles and forms dropped, its headings, links, lists, tables and code kept), in parts from an offset, kept a quarter of an hour, a question on it answered by the cheap model the settings give when the agent asks one; and `search`, when the settings choose an engine, DuckDuckGo's page of plain HTML for now, a fallback for moderate use, its results read from its markup and its refusals said. Each an action of the gate given as a command with the internet is, a query holding a secret refused before it leaves; only the public web reached (this machine, private networks, a link's own addresses and names without a dot refused, the name resolved and checked before the connection is made to the address checked, each redirection checked again), no cookie, no proxy of the environment's, bounded in size and time, in plain Rust; what comes back marked as text from outside. An extension of the crew | | `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 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, a chat of the person's whose model nobody chose (`SETTINGS_MODEL`) moved to the settings' lead when they changed it, said as iq starts and kept with its choices, one given a model with `/model`, `--model`, `/new` or its first message staying on it, one whose starter did not come back let go, each with its thread and when it was last at work, those untouched for as long as the settings say forgotten first, their worktree with them; each chat's folder of scratch in iq's cache, never synced, given to the gate, following its chat as it is renamed and gone once it is forgotten; the provider's models handed to the crew, which starts agents only on them; what agents write to each other summed up for the person by the model the settings name, its cost counted as any call's; the models the settings use that those they allow leave out said as iq starts; and, run with one of its flags, the sandbox's helper | +| `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` | 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/agent/src/crew.rs b/crates/agent/src/crew.rs index 89a2230..d4b4af6 100644 --- a/crates/agent/src/crew.rs +++ b/crates/agent/src/crew.rs @@ -118,6 +118,10 @@ pub const BUSY_WAIT: Duration = Duration::from_secs(10); /// The longest one wait lasts, whatever the provider asks. pub const BUSY_MOST: Duration = Duration::from_secs(300); +/// How long a call to a model with a backup left waits for its answer, +/// unless the settings say: past it, the call goes to the backup. +pub const BACKUP_AFTER: Duration = Duration::from_secs(180); + /// How long a command may write nothing before it is stopped, unless the /// settings say: one waiting for a login in a browser, or for an answer at /// a terminal it does not have, would hold its agent until its time ran @@ -193,6 +197,13 @@ pub struct Settings { pub busy_wait: Duration, /// The longest one wait lasts, whatever the provider asks. pub busy_most: Duration, + /// The models a call to a model goes to in turn when it gets no answer + /// in time or its provider is out of capacity, by that model: best the + /// same model in another region, so that the cache and the reasoning + /// are lost once at most. A refusal goes to none. + pub backups: HashMap>, + /// How long a call to a model with a backup left waits for its answer. + pub backup_after: Duration, /// The model of the provider that names the person's chats after what /// their work is about: none, and they keep the name they started /// with. @@ -229,6 +240,8 @@ impl Default for Settings { busy_tries: BUSY_TRIES, busy_wait: BUSY_WAIT, busy_most: BUSY_MOST, + backups: HashMap::new(), + backup_after: BACKUP_AFTER, namer: None, turn_ask: None, light_from: LIGHT_FROM, @@ -501,6 +514,9 @@ struct Failure { /// Whether the provider stayed out of capacity through every try, /// which `said` tells whole. busy: bool, + /// Whether the call may go to its model's next backup: it got no + /// answer in time, or its provider is out of capacity. + hand_over: bool, } /// The wakes an agent asked for: how many wait, and when it asked those of @@ -758,6 +774,9 @@ struct Member { forget_reasoning: bool, /// Whether it was told the person's skills are open to it. skills_told: bool, + /// The names of the tools its last call offered: offered others, its + /// answers' reasoning, signed with those it was offered, goes. + offered: Vec, /// The messages its compactions replaced, in order. compacted_away: Vec, /// How many of its messages, after its standing instructions, its last @@ -1004,7 +1023,15 @@ where Message::system(self.instructions(&name, &saved.by, saved.role.as_deref(), &place)); let mut messages = saved.messages; match messages.first_mut() { - Some(first @ Message::System(_)) => *first = instructions, + Some(first @ Message::System(_)) => { + // Written otherwise (the person's rules, a skill, its + // place), they unseal the reasoning its answers carry, + // which a provider checks against all that came before. + if *first != instructions { + forget_reasoning(&mut messages); + } + messages[0] = instructions; + } _ => messages.insert(0, instructions), } if messages.len() == 1 { @@ -1048,6 +1075,7 @@ where models_chosen: saved.models_chosen, forget_reasoning: false, skills_told: false, + offered: Vec::new(), compacted_away: saved.compacted_away, compacted_head: saved.compacted_head, }, @@ -1590,6 +1618,7 @@ where }], forget_reasoning: false, skills_told: false, + offered: Vec::new(), compacted_away: Vec::new(), compacted_head: 0, }, @@ -2888,6 +2917,7 @@ where .collect(); let older = &results[..results.len().saturating_sub(LIGHT_KEPT)]; let (mut count, mut chars) = (0, 0); + let mut first = None; for &at in older { let Message::Tool { call_id, content } = &messages[at] else { continue; @@ -2917,10 +2947,16 @@ where ); count += 1; chars += size; + first.get_or_insert(at); if let Message::Tool { content, .. } = &mut messages[at] { *content = line; } } + // The answers after the first result changed carry a reasoning + // signed with what it was: a provider would refuse it. + if let Some(first) = first { + forget_reasoning(&mut messages[first..]); + } if count > 0 { member.lightened = member.context; } @@ -2976,13 +3012,35 @@ where &self, agent: &str, request: &ChatRequest, + backup: bool, ) -> Result { let settings = &self.inner.settings; let started = Instant::now(); let mut wait = settings.busy_wait; let mut tries = 0; loop { - let error = match self.inner.provider.complete(request).await { + // With a backup left, a call waits only so long. + let answer = if backup { + let after = settings.backup_after; + match tokio::time::timeout(after, self.inner.provider.complete(request)).await { + Ok(answer) => answer, + Err(_) => { + return Err(Failure { + said: format!( + "{} gave no answer within {}", + request.model, + lasted(after) + ), + refusal: None, + busy: false, + hand_over: true, + }); + } + } + } else { + self.inner.provider.complete(request).await + }; + let error = match answer { Ok(response) => { if tries > 0 { self.report(Event::Notice { @@ -2999,14 +3057,26 @@ where said: chain(&error), refusal: self.inner.provider.refusal(&error), busy: false, + hand_over: false, }); }; let said = cut_to(&chain(&error), BUSY_SAID); + // Out of capacity, it goes to its backup at once rather than + // waiting through the tries. + if backup { + return Err(Failure { + said: format!("{} is out of capacity ({said})", request.model), + refusal: self.inner.provider.refusal(&error), + busy: true, + hand_over: true, + }); + } if tries >= settings.busy_tries { let refusal = self.inner.provider.refusal(&error); return Err(Failure { refusal, busy: true, + hand_over: false, said: format!( "the provider of {} stayed out of capacity for {}, through {} tries ({said}). \ The conversation is kept: write to the agent to try again later, or give \ @@ -3064,13 +3134,32 @@ where // The turns before this one, whose reasoning may be another // model's. let earlier = messages.len(); - let mut forgotten = false; + // How far a refused signature took the reasoning off: the earlier + // turns', then all of it. + let mut forgotten = 0; + // The model each call goes to: the agent's, then its backups in + // turn, for the rest of the turn. + let backups = self + .inner + .settings + .backups + .get(model) + .cloned() + .unwrap_or_default(); + let mut next_backup = 0; + let mut current = model.clone(); messages.push(Message::user(prompt)); if let Some(member) = lock(&self.inner.board).members.get_mut(name) { member.reason = None; } let mut urged = false; for step in 0..self.inner.settings.steps { + let model = ¤t; + // The next backup the person allows, when one is left. + let backup = backups[next_backup..] + .iter() + .position(|backup| self.refused_model(backup).is_none()) + .map(|at| next_backup + at); if let Some(news) = self.unread(name) { messages.push(Message::user(news)); } @@ -3100,6 +3189,15 @@ where // agent asked for it. let mut tools = tools::work(); tools.extend(self.tools_for(name)); + // Other tools offered, the reasoning signed with the others + // goes: a provider checks it against them. + let names: Vec = tools.iter().map(|tool| tool.name.clone()).collect(); + if let Some(member) = lock(&self.inner.board).members.get_mut(name) { + if !member.offered.is_empty() && member.offered != names { + forget_reasoning(&mut messages); + } + member.offered = names; + } let request = ChatRequest { model: model.clone(), messages: messages.clone(), @@ -3111,25 +3209,49 @@ where return (messages, Err(stopped)); } self.measure(name, model).await; - let response = match self.ask_model(name, &request).await { + let response = match self.ask_model(name, &request, backup.is_some()).await { Ok(response) => response, - // A signature its provider cannot check, written as another - // model answered: the call goes again once without them. + // A signature its provider cannot check, for a change iq + // could not foresee: the call goes again without the + // reasoning of the earlier turns, then without any. Err(failed) - if !forgotten - && signature_refused(&failed) - && forget_reasoning(&mut messages[..earlier]) => + if forgotten < 2 && signature_refused(&failed) && { + let mut forgot = false; + while forgotten < 2 && !forgot { + let upto = if forgotten == 0 { + earlier + } else { + messages.len() + }; + forgotten += 1; + forgot = forget_reasoning(&mut messages[..upto]); + } + forgot + } => { - forgotten = true; self.report(Event::Notice { agent: name.to_owned(), - text: "its provider refused the reasoning its earlier answers carry, \ - signed for another model: it is called again without it" + text: "its provider could not check the reasoning its earlier answers \ + carry: they go on without it" .into(), }); continue; } Err(failed) => { + if failed.hand_over + && let Some(at) = backup + { + next_backup = at + 1; + let to = backups[at].clone(); + self.report(Event::Notice { + agent: name.to_owned(), + text: format!("{}: the call goes to {to}, its backup", failed.said), + }); + // Another model reads none of its reasoning. + forget_reasoning(&mut messages); + current = to; + continue; + } let said = self.failed(name, model, failed, &messages[counted..]); return (messages, Err(said)); } @@ -4395,7 +4517,7 @@ where effort: Some(self.inner.settings.reviewer_effort), }; let response = self - .ask_model(agent, &request) + .ask_model(agent, &request, false) .await .map_err(|failed| failed.said)?; let cost = match response.cost { @@ -5113,9 +5235,10 @@ const TITLE_CHARS: usize = 24; const NAMING: &str = "You name a chat of a coding harness after what its work is about, from the \ first request the person wrote in it, which follows. Answer with two or three words in the \ request's own language, lower case, joined by dashes, that name its subject (the feature, the \ - module, the bug), not the way it is asked: for \"could you code the payment part of the \ - invoice module so that a refund can be made?\", payment-refunds. The name alone, nothing \ - else."; + module, the bug), not the way it is asked: never a verb of asking (can, could, want, need) \ + nor a politeness (please, thanks, hello), in any language. For \"could you code the payment \ + part of the invoice module so that a refund can be made?\", payment-refunds; for \"hi, can \ + you please review pull request 482?\", pr-482-review. The name alone, nothing else."; /// The name a namer's `answer` gives a chat, as the board writes names; /// none when it gives none. diff --git a/crates/agent/src/keep.rs b/crates/agent/src/keep.rs index 2fde927..516a03c 100644 --- a/crates/agent/src/keep.rs +++ b/crates/agent/src/keep.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::PERSON; /// How a chat came to run on the model the settings name for the person's -/// chats: chosen by none, it follows them as they change. +/// chats, as it started or came back. pub const SETTINGS_MODEL: &str = "the settings' model"; /// An agent and its conversation, as kept. @@ -79,16 +79,12 @@ fn is_zero(count: &usize) -> bool { } impl Saved { - /// Whether the chat runs on the model the settings name, as the person - /// started it: they chose none for it, and it follows the settings as - /// they change. + /// Whether the chat comes back on the settings' lead and effort: the + /// person leads it. A model or an effort they chose for it lasts until + /// iq starts again. #[must_use] pub fn follows_settings(&self) -> bool { self.by == PERSON - && self - .models_chosen - .last() - .is_none_or(|choice| choice.how == SETTINGS_MODEL) } /// Its conversation as it went: what its compactions replaced, in diff --git a/crates/agent/src/lib.rs b/crates/agent/src/lib.rs index 62ad5c7..18400bc 100644 --- a/crates/agent/src/lib.rs +++ b/crates/agent/src/lib.rs @@ -32,8 +32,8 @@ mod team; mod tools; pub use crew::{ - ALL, BUSY_MOST, BUSY_TRIES, BUSY_WAIT, COMMAND_QUIET, COMMAND_TIMEOUT, CONTEXT_EVERY, Crew, - LIGHT_FROM, Listed, Posted, REFUSALS, Report, SCRATCH_MOST, Settings, + ALL, BACKUP_AFTER, BUSY_MOST, BUSY_TRIES, BUSY_WAIT, COMMAND_QUIET, COMMAND_TIMEOUT, + CONTEXT_EVERY, Crew, LIGHT_FROM, Listed, Posted, REFUSALS, Report, SCRATCH_MOST, Settings, }; pub use event::{Event, PERSON}; pub use extension::{Called, Extension}; diff --git a/crates/agent/tests/crew.rs b/crates/agent/tests/crew.rs index 8a8979e..eba602c 100644 --- a/crates/agent/tests/crew.rs +++ b/crates/agent/tests/crew.rs @@ -26,6 +26,10 @@ struct Scripted { /// Whether the provider refuses a call that sends a reasoning back, as /// one refuses another's signature. refuses_signed: Mutex, + /// The models whose provider is out of capacity, whoever calls them. + busy_models: Mutex>, + /// How long the models that answer slowly take. + slow_models: Mutex>, } /// What the scripted provider fails with. @@ -67,6 +71,8 @@ impl Scripted { busy: Mutex::default(), refused: Mutex::default(), refuses_signed: Mutex::default(), + busy_models: Mutex::default(), + slow_models: Mutex::default(), }) } @@ -187,6 +193,14 @@ impl ChatModel for Model { if *self.refuses_signed.lock().unwrap() && signed(request) { return Err(Failed::Signed); } + let model = request.model.to_string(); + if self.busy_models.lock().unwrap().contains(&model) { + return Err(Failed::Busy); + } + let slow = self.slow_models.lock().unwrap().get(&model).copied(); + if let Some(slow) = slow { + tokio::time::sleep(slow).await; + } let next = self .scripts .lock() @@ -233,6 +247,14 @@ fn signed(request: &ChatRequest) -> bool { }) } +/// `response`, given with a reasoning its provider signed. +fn signing(response: ChatResponse) -> ChatResponse { + ChatResponse { + reasoning_signature: Some(serde_json::json!("c2lnbmVk")), + ..response + } +} + /// `text`, said with a reasoning its provider signed. fn reasoned(text: &str) -> ChatResponse { ChatResponse { @@ -1833,7 +1855,7 @@ async fn a_reasoning_another_provider_cannot_check_is_left_out_and_the_call_made ); assert!(events.iter().any(|event| matches!( event, - Event::Notice { text, .. } if text.starts_with("its provider refused the reasoning") + Event::Notice { text, .. } if text.starts_with("its provider could not check the reasoning") ))); // Once left out, it is sent no more. let requests = f.model.requests_of("lead"); @@ -1844,6 +1866,219 @@ async fn a_reasoning_another_provider_cannot_check_is_left_out_and_the_call_made assert_eq!(f.model.requests_of("lead").len(), 4); } +#[tokio::test] +async fn a_signature_refused_with_no_earlier_turn_to_blame_goes_with_all_the_reasoning() { + let f = fixture( + &[( + "lead", + vec![ + signing(calls("list_agents", serde_json::json!({}))), + say("Done."), + ], + )], + Settings::default(), + ); + *f.model.refuses_signed.lock().unwrap() = true; + f.crew.start("lead", &model("lab/m"), "go".into(), PERSON); + f.settled().await; + assert!(f.events().contains(&Event::Done { + agent: "lead".into(), + outcome: Ok("Done.".into()) + })); + let requests = f.model.requests_of("lead"); + assert_eq!(requests.len(), 3); + assert!(signed(&requests[1]) && !signed(&requests[2])); +} + +#[tokio::test] +async fn results_set_apart_take_off_the_reasoning_signed_after_them() { + let f = fixture( + &[( + "lead", + (0..8) + .map(|_| { + signing(reading( + 2_000, + calls("read_file", serde_json::json!({"path": "long.txt"})), + )) + }) + .chain([say("Read.")]) + .collect(), + )], + Settings { + light_from: 1_000, + ..Settings::default() + }, + ); + std::fs::write(f.root.join("long.txt"), "a line of text\n".repeat(80)).unwrap(); + f.crew.start("lead", &model("lab/m"), "read".into(), PERSON); + f.settled().await; + let requests = f.model.requests_of("lead"); + let last = requests.last().unwrap(); + assert!(format!("{:?}", last.messages).contains("set apart to keep your conversation light")); + // The answer before the first result set apart keeps its reasoning, + // those after it go without, and one given since was signed with the + // results as they are now. + let signed: Vec = last + .messages + .iter() + .filter_map(|message| match message { + Message::Assistant { + reasoning_signature, + .. + } => Some(reasoning_signature.is_some()), + _ => None, + }) + .collect(); + assert_eq!( + signed, + [true, false, false, false, false, false, false, true] + ); +} + +#[tokio::test] +async fn other_tools_offered_take_off_the_reasoning_signed_with_the_others() { + let f = fixture( + &[("lead", vec![reasoned("First."), say("Second.")])], + Settings::default(), + ); + f.crew.start("lead", &model("lab/m"), "go".into(), PERSON); + f.settled().await; + f.crew.extend(Arc::new(ForLeads)); + f.crew.tell("lead", "and then?".into()).unwrap(); + f.settled().await; + let requests = f.model.requests_of("lead"); + assert_eq!(requests.len(), 2); + assert!(!signed(&requests[1])); +} + +#[tokio::test] +async fn a_chat_resumed_under_other_instructions_sends_its_reasoning_back_no_more() { + let f = fixture(&[("lead", vec![reasoned("First.")])], Settings::default()); + let kept = Arc::new(Kept::default()); + f.crew + .set_keeper(Some(Arc::clone(&kept) as Arc)); + f.crew.start("lead", &model("lab/m"), "go".into(), PERSON); + f.settled().await; + let saved = kept.0.lock().unwrap()["lead"].clone(); + // In the same place, its instructions the same: its reasoning goes back. + let scripted = Scripted::new(&[("lead", vec![say("Again.")])]); + let same = Crew::new( + Model(Arc::clone(&scripted)), + Gate::builder(&f.root).build().unwrap(), + Helper::new("/nonexistent", Vec::::new()), + Settings::default(), + Arc::new(|_| {}), + ); + same.resume(saved.clone(), None).unwrap(); + same.tell("lead", "and then?".into()).unwrap(); + tokio::time::timeout(Duration::from_secs(10), same.settled()) + .await + .unwrap(); + assert!(signed(scripted.requests_of("lead").last().unwrap())); + // Elsewhere, its instructions written otherwise: it goes without. + let again = fixture(&[("lead", vec![say("Again.")])], Settings::default()); + again.crew.resume(saved, None).unwrap(); + again.crew.tell("lead", "and then?".into()).unwrap(); + again.settled().await; + let last = again.model.requests_of("lead").pop().unwrap(); + assert!(!signed(&last)); + assert!(format!("{:?}", last.messages).contains("First.")); +} + +/// The settings with `primary`'s backups. +fn with_backups(primary: &str, backups: &[&str]) -> Settings { + Settings { + backups: [(model(primary), backups.iter().map(|b| model(b)).collect())].into(), + backup_after: Duration::from_millis(200), + busy_wait: Duration::from_millis(1), + ..Settings::default() + } +} + +#[tokio::test] +async fn a_model_out_of_capacity_hands_the_call_to_its_backup_at_once() { + let f = fixture( + &[( + "lead", + vec![ + signing(calls("list_agents", serde_json::json!({}))), + say("Done."), + ], + )], + with_backups("lab/main", &["lab/main@eu", "lab/other"]), + ); + f.model.busy_models.lock().unwrap().push("lab/main".into()); + f.crew + .start("lead", &model("lab/main"), "go".into(), PERSON); + f.settled().await; + // Once, without the tries, then the backup for the rest of the turn. + assert_eq!( + f.model.models_of("lead"), + ["lab/main", "lab/main@eu", "lab/main@eu"] + ); + assert!(f.events().contains(&Event::Done { + agent: "lead".into(), + outcome: Ok("Done.".into()) + })); + let said: Vec = f + .events() + .iter() + .filter_map(|event| match event { + Event::Notice { text, .. } => Some(text.clone()), + _ => None, + }) + .collect(); + assert!( + said.iter() + .any(|text| text.starts_with("lab/main is out of capacity") + && text.ends_with("the call goes to lab/main@eu, its backup")), + "{said:#?}" + ); + // What it answered is billed to the model that answered. + assert!(f.events().iter().any(|event| matches!( + event, + Event::Spent { model, .. } if model == "lab/main@eu" + ))); + // Its next turn begins on its own model again. + f.model.busy_models.lock().unwrap().clear(); + f.crew.tell("lead", "and then?".into()).unwrap(); + f.settled().await; + assert_eq!(f.model.models_of("lead").last().unwrap(), "lab/main"); +} + +#[tokio::test] +async fn a_model_too_slow_hands_the_call_to_its_backup() { + let f = fixture( + &[("lead", vec![say("Done.")])], + with_backups("lab/main", &["lab/main@eu"]), + ); + f.model + .slow_models + .lock() + .unwrap() + .insert("lab/main".into(), Duration::from_secs(5)); + f.crew + .start("lead", &model("lab/main"), "go".into(), PERSON); + f.settled().await; + assert_eq!(f.model.models_of("lead"), ["lab/main", "lab/main@eu"]); + assert!(f.events().iter().any(|event| matches!( + event, + Event::Notice { text, .. } if text.starts_with("lab/main gave no answer within") + ))); + // The last backup is waited for as long as it takes, and a refusal + // goes to none. + let g = fixture( + &[("lead", vec![say("Done.")])], + with_backups("lab/main", &["lab/main@eu"]), + ); + g.model.refuses_after("lead", 0); + g.crew + .start("lead", &model("lab/main"), "go".into(), PERSON); + g.settled().await; + assert_eq!(g.model.models_of("lead"), ["lab/main"]); +} + #[tokio::test] async fn an_agent_names_a_model_whole_as_the_provider_lists_it() { let f = fixture( diff --git a/crates/llm/src/openai_compat.rs b/crates/llm/src/openai_compat.rs index e03df69..3c9acd7 100644 --- a/crates/llm/src/openai_compat.rs +++ b/crates/llm/src/openai_compat.rs @@ -57,6 +57,10 @@ impl fmt::Debug for OpenAiCompatible { } } +/// What iq's calls say they come from: a provider's view of them names +/// iq rather than no client at all. +const USER_AGENT: &str = concat!("iq/", env!("CARGO_PKG_VERSION")); + impl OpenAiCompatible { /// A provider at `base_url`, authenticated with `api_key` as a bearer token. pub fn new(base_url: impl Into, api_key: impl Into) -> Self { @@ -70,8 +74,13 @@ impl OpenAiCompatible { } fn with_key(base_url: impl Into, api_key: Option) -> Self { + // A client that cannot be built so is one that names nothing. + let http = reqwest::Client::builder() + .user_agent(USER_AGENT) + .build() + .unwrap_or_default(); Self { - http: reqwest::Client::new(), + http, base_url: base_url.into().trim_end_matches('/').to_owned(), api_key, known: Arc::new(Mutex::new(None)), @@ -784,6 +793,37 @@ mod tests { ); } + #[tokio::test] + async fn a_call_says_it_comes_from_iq() { + use std::io::{Read, Write}; + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let address = listener.local_addr().unwrap(); + let heard = std::thread::spawn(move || { + let (mut stream, _) = listener.accept().unwrap(); + let mut request = Vec::new(); + let mut buffer = [0u8; 1024]; + while !request.windows(4).any(|end| end == b"\r\n\r\n") { + let read = stream.read(&mut buffer).unwrap(); + request.extend_from_slice(&buffer[..read]); + } + let body = r#"{"data":[]}"#; + write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\nContent-Type: application/json\r\n\r\n{body}", + body.len() + ) + .unwrap(); + String::from_utf8_lossy(&request).to_lowercase() + }); + let provider = OpenAiCompatible::new(format!("http://{address}"), "k"); + assert!(provider.list().await.unwrap().is_empty()); + let request = heard.join().unwrap(); + assert!( + request.contains(&format!("user-agent: iq/{}", env!("CARGO_PKG_VERSION"))), + "{request}" + ); + } + #[tokio::test] async fn a_request_held_without_answer_says_it_may_have_been_billed() { // A server that accepts and never answers. diff --git a/crates/memory/src/skills.rs b/crates/memory/src/skills.rs index a4ccaee..2b2e02f 100644 --- a/crates/memory/src/skills.rs +++ b/crates/memory/src/skills.rs @@ -27,6 +27,8 @@ const SKILL_MOST: usize = 40_000; pub struct Skills { folders: Vec, reviewer: Option<(String, PathBuf)>, + /// The skills given whole to the leads of the person's chats. + lead: Vec, } /// One skill, as listed. @@ -48,9 +50,47 @@ impl Skills { Self { folders, reviewer: None, + lead: Vec::new(), } } + /// Gives the skills named `names` whole to the leads of the person's + /// chats, in their instructions: a few short ones a lead uses often, + /// which a cheap one would read wrong or not at all. The others, and + /// every skill for the agents a chat starts, are read on demand. + /// + /// # Examples + /// + /// ``` + /// use iq_memory::Skills; + /// let skills = Skills::new(vec!["/home/person/.iq/skills".into()]) + /// .with_lead(["teams"]); + /// ``` + #[must_use] + pub fn with_lead(mut self, names: impl IntoIterator>) -> Self { + self.lead = names.into_iter().map(Into::into).collect(); + self + } + + /// What the lead of a chat of the person's is given whole, after what + /// every agent is told; `None` when the settings give none. + fn given_whole(&self) -> Option { + if self.lead.is_empty() { + return None; + } + let mut out = "The skills the person gives you whole, as you lead their chat: follow them without reading them again." + .to_owned(); + for name in &self.lead { + match self.read(name) { + Ok(text) => out.push_str(&format!("\n\n{text}")), + Err(why) => out.push_str(&format!( + "\n\n({name}, which the settings give whole, is not: {why}.)" + )), + } + } + Some(out) + } + /// Selects the skill used for permission reviews, reloaded at each decision. /// It must live outside `workspace`, where sandboxed commands cannot edit it. /// @@ -247,8 +287,14 @@ where }] } - fn instructions(&self, _agent: &str) -> Option { - self.told() + fn instructions(&self, agent: &str) -> Option { + let told = self.told()?; + // The person's chats alone: an agent another started is named + // after its chat. + match self.given_whole().filter(|_| !agent.contains('/')) { + Some(whole) => Some(format!("{told}\n\n{whole}")), + None => Some(told), + } } fn review_instructions(&self) -> Result, String> { @@ -286,6 +332,36 @@ mod tests { assert!(told.contains("code-work: how code is written"), "{told}"); } + #[test] + fn the_lead_skills_are_given_whole_to_the_person_s_chats_only() { + let home = tempfile::tempdir().unwrap(); + std::fs::write( + home.path().join("teams.md"), + "---\nname: teams\ndescription: which team for which work\n---\nFor code, a writer and its reviewer.", + ) + .unwrap(); + std::fs::write(home.path().join("deploy.md"), "Staging first.").unwrap(); + let skills = Skills::new(vec![home.path().into()]).with_lead(["teams", "missing"]); + let lead = >::instructions(&skills, "fix").unwrap(); + assert!( + lead.contains("For code, a writer and its reviewer."), + "{lead}" + ); + assert!( + lead.contains("(missing, which the settings give whole, is not: no skill is named"), + "{lead}" + ); + // The others are read on demand. + assert!(!lead.contains("Staging first."), "{lead}"); + // An agent a chat started is told which there are, as before. + let started = >::instructions(&skills, "fix/writer").unwrap(); + assert!( + started.contains("- teams: which team for which work"), + "{started}" + ); + assert!(!started.contains("For code, a writer"), "{started}"); + } + #[test] fn review_skills_reload_and_fail_closed() { let home = tempfile::tempdir().unwrap(); diff --git a/crates/tui/src/live.rs b/crates/tui/src/live.rs index 2460d9e..8c0ff21 100644 --- a/crates/tui/src/live.rs +++ b/crates/tui/src/live.rs @@ -472,8 +472,11 @@ impl Live<'_> { Span::styled(turn.total.to_string(), p.fg(p.text)), ]; for spent in by { + // The chat's own agent is the chat: its name, made of its first + // request, says nothing more here. let who = match spent.who.as_str() { "reviewer" => "autopilot".to_owned(), + who if who == window => "chat".to_owned(), who => part(who), }; spans.push(Span::styled(" · ", p.fg(p.faint))); @@ -1115,9 +1118,13 @@ impl Live<'_> { Span::styled(format!(" {model} "), p.fg(p.faint)), ]), Line::from(Span::styled(spent, p.fg(p.faint))), - // The chat is named after its work: its first request - // says nothing the next one needs. - format!("Write to {agent}…"), + // The person's own chat is the chat, whatever it is + // named; an agent it started goes by its name. + if view.is_some_and(|view| view.by == iq_agent::PERSON) { + "Write to the chat…".to_owned() + } else { + format!("Write to {agent}…") + }, ) } Talk::New(chat) => { @@ -1652,8 +1659,14 @@ mod tests { .unwrap_or_else(|| panic!("{rows:#?}")); assert_eq!( line.trim_end(), - " $ turn 3 $0.77 · fix $0.71 · review $0.04 · autopilot $0.02" + " $ turn 3 $0.77 · chat $0.71 · review $0.04 · autopilot $0.02" ); + // Where the person writes, their chat is the chat; an agent it + // started goes by its name. + assert!(rows.iter().any(|row| row.contains("Write to the chat…"))); + board.screen_mut().talk_to("fix/review"); + let rows = drawn(&board, &history, 100); + assert!(rows.iter().any(|row| row.contains("Write to fix/review…"))); } #[test] diff --git a/src/chats.rs b/src/chats.rs index b193ee6..447c0ae 100644 --- a/src/chats.rs +++ b/src/chats.rs @@ -197,19 +197,31 @@ impl Keeper for Chats { } } -/// Moves `chat` to `lead`, the settings' lead, at `at`, when it follows -/// the settings and runs on another: the person changed their lead since. -/// Returns what the person is told of it. -pub(crate) fn on_the_lead(chat: &mut Saved, lead: &str, at: u64) -> Option { - if !chat.follows_settings() || chat.model == lead { - return None; +/// Puts `chat`, one the person leads, back on `lead`, the settings' lead, +/// at `at`, and on the settings' effort: a model or an effort chosen for +/// it lasted until iq started again, and the person may have changed the +/// settings since. Returns what the person is told of it. +pub(crate) fn on_the_lead(chat: &mut Saved, lead: &str, at: u64) -> Vec { + let mut said = Vec::new(); + if !chat.follows_settings() { + return said; } - let was = chat.model.clone(); - chat.move_to(lead, iq_agent::PERSON, iq_agent::SETTINGS_MODEL, at); - Some(format!( - "{} answers on {lead}, the settings' lead, from its next turn (it was on {was})", - chat.name - )) + if chat.model != lead { + let was = chat.model.clone(); + chat.move_to(lead, iq_agent::PERSON, iq_agent::SETTINGS_MODEL, at); + said.push(format!( + "{} answers on {lead}, the settings' lead, from its next turn (it was on {was})", + chat.name + )); + } + if let Some(was) = chat.effort.take() { + said.push(format!( + "{} thinks as the settings say from its next turn (it thought {})", + chat.name, + was.as_str() + )); + } + said } /// Where the agents retired are kept, under a project's chats. @@ -274,20 +286,23 @@ mod tests { } #[test] - fn a_chat_on_the_settings_model_follows_them_and_one_chosen_stays() { + fn a_chat_the_person_leads_comes_back_on_the_settings_lead() { + // Its model chosen with /new, its effort with /effort. let mut chat = saved("fix"); - chat.models_chosen[0].how = iq_agent::SETTINGS_MODEL.to_owned(); + chat.effort = Some(iq_core::Effort::High); chat.messages.push(Message::Assistant { content: Some("Fixed.".into()), tool_calls: Vec::new(), reasoning_signature: Some(serde_json::json!("c2lnbmVk")), }); assert_eq!( - on_the_lead(&mut chat, "lab/haiku", 9).as_deref(), - Some( - "fix answers on lab/haiku, the settings' lead, from its next turn (it was on lab/model)" - ) + on_the_lead(&mut chat, "lab/haiku", 9), + [ + "fix answers on lab/haiku, the settings' lead, from its next turn (it was on lab/model)", + "fix thinks as the settings say from its next turn (it thought high)" + ] ); + assert_eq!(chat.effort, None); assert_eq!(chat.model, "lab/haiku"); let last = chat.models_chosen.last().unwrap(); assert_eq!((last.how.as_str(), last.at), (iq_agent::SETTINGS_MODEL, 9)); @@ -299,21 +314,15 @@ mod tests { .. } ))); - // On the lead, and once it was moved, it stays. - assert_eq!(on_the_lead(&mut chat, "lab/haiku", 10), None); + // On the lead, nothing more is said. + assert!(on_the_lead(&mut chat, "lab/haiku", 10).is_empty()); assert_eq!(chat.models_chosen.len(), 2); - // A model the person chose for it stays, as does an agent's. - let mut chosen = saved("chosen"); - chosen.models_chosen[0].how = "/model".to_owned(); - assert_eq!(on_the_lead(&mut chosen, "lab/haiku", 9), None); + // The agents a lead started keep what it chose for them. let mut started = saved("lead/tests"); started.by = "lead".to_owned(); - started.models_chosen.clear(); - assert_eq!(on_the_lead(&mut started, "lab/haiku", 9), None); - // One kept before choices were, the settings'. - let mut older = saved("older"); - older.models_chosen.clear(); - assert!(on_the_lead(&mut older, "lab/haiku", 9).is_some()); + started.effort = Some(iq_core::Effort::Low); + assert!(on_the_lead(&mut started, "lab/haiku", 9).is_empty()); + assert_eq!(started.effort, Some(iq_core::Effort::Low)); } #[test] diff --git a/src/main.rs b/src/main.rs index 666fcab..823f74e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -339,7 +339,8 @@ fn crew( .with_claude(claude); crew.extend(Arc::new(memory)); // And the skills the person wrote for them. - let mut skills = iq_memory::Skills::new(settings.skill_folders(&home, &workspace)); + let mut skills = iq_memory::Skills::new(settings.skill_folders(&home, &workspace)) + .with_lead(settings.lead_skills.iter().cloned()); if let Some(name) = &settings.autopilot_skill { skills = skills.with_reviewer(name, &workspace); } @@ -765,6 +766,13 @@ fn in_use(settings: &Settings, lead: &ModelId) -> Result, its path under where you write; your checkout is left as it is //! worktree_from = "HEAD" # what a worktree starts from: your checkout's commit, or a branch such as "origin/main" //! worktree_copy = [".env"] # files of your checkout git does not keep, copied into a worktree as it is made, where it has their folder, never over one; a name alone is looked for in every folder @@ -37,10 +38,14 @@ //! rules = ["~/.iq/AGENTS.md"] # your rules for every project, given to the agents you start; unless set, this one, else ~/.claude/CLAUDE.md //! autopilot_skill = "local-review" # a skill of yours the reviewer follows, kept outside the workspace, read again at each decision, never shown to the agents //! skills = ["~/.iq/skills"] # folders of your skills (a folder with its SKILL.md, or a .md file); this one unless set; the project's .claude/skills are read after them, yours winning a name both hold +//! lead_skills = ["teams"] # a few short skills given whole to the lead of each chat you start, read every call; the others, and all of them for the agents it starts, read on demand //! claude_memory = true # the notes kept of the project under ~/.claude read beside iq's own //! plugins = ["name"] # programs of their own iq starts and speaks with: iq-name for name, found on the PATH, run on your machine as you //! mermaid = "auto" # Mermaid diagrams drawn as images in Kitty, by mmdr (cargo install mermaid-rs-renderer) run in the sandbox, dark, on the terminal's own background; or a command with {input} and {output}, and {look} for iq's look; off unless set //! +//! [backups] # the models a call goes to in turn when its model gives no answer in time or is out of capacity, never when it is refused: best the same model in another region, as your provider names it, so that the cache and the reasoning are lost once at most +//! "anthropic/claude-opus-5-5" = ["anthropic/claude-opus-5-5@eu"] +//! //! [keys] # any shortcut moved, "" for none; Ctrl-S lists them //! costs = "ctrl+o" //! @@ -74,7 +79,7 @@ //! auto = false # true: what changes is sent without asking, and said; else iq asks first //! ``` -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; use std::path::{Path, PathBuf}; use anyhow::{Context, Result}; @@ -150,6 +155,11 @@ pub(crate) struct Settings { command_quiet: Option, /// Times a call is sent again while its provider is out of capacity. provider_retries: Option, + /// Seconds a call to a model with a backup left waits for its answer. + backup_after: Option, + /// The models a call goes to in turn, by its model. + #[serde(default)] + backups: BTreeMap>, /// How many tokens an agent's conversation grows between two words to /// it of its size. context_every: Option, @@ -207,6 +217,9 @@ pub(crate) struct Settings { rules: Option>, /// The folders of the person's skills. skills: Option>, + /// The skills given whole to the leads of the person's chats. + #[serde(default)] + pub(crate) lead_skills: Vec, /// Whether the notes kept of the project under `~/.claude` are read /// beside iq's. claude_memory: Option, @@ -635,6 +648,25 @@ impl Settings { .collect()) } + /// The models a call goes to in turn, by its model, as `[backups]` + /// names them. + /// + /// # Errors + /// + /// One is no model's name. + pub(crate) fn backups(&self) -> Result>> { + self.backups + .iter() + .map(|(model, backups)| { + let backups = backups + .iter() + .map(|backup| ModelId::new(backup.trim())) + .collect::, _>>()?; + Ok((ModelId::new(model.trim())?, backups)) + }) + .collect() + } + /// What a worktree starts from: as set, else `HEAD`. pub(crate) fn worktree_from(&self) -> &str { self.worktree_from.as_deref().map_or("HEAD", str::trim) @@ -761,6 +793,10 @@ impl Settings { .command_quiet .map_or(iq_agent::COMMAND_QUIET, std::time::Duration::from_secs), busy_tries: self.provider_retries.unwrap_or(iq_agent::BUSY_TRIES), + backups: self.backups()?, + backup_after: self + .backup_after + .map_or(iq_agent::BACKUP_AFTER, std::time::Duration::from_secs), // The cheap model that places the tasks names the chats. namer: Some(self.observing()?.model), light_from: self.light_from.unwrap_or(iq_agent::LIGHT_FROM), @@ -861,6 +897,17 @@ mod tests { assert_eq!(set.crew().unwrap().compact_at, None); let under: Settings = toml::from_str("compact_at = 100000").unwrap(); assert_eq!(under.crew().unwrap().compact_at, Some(100_000)); + // Backups, by the model a call goes to first. + let backed: Settings = + toml::from_str("backup_after = 60\n[backups]\n\"lab/main\" = [\"lab/main@eu\"]") + .unwrap(); + let crew = backed.crew().unwrap(); + assert_eq!(crew.backup_after, std::time::Duration::from_secs(60)); + assert_eq!( + crew.backups[&ModelId::new("lab/main").unwrap()], + [ModelId::new("lab/main@eu").unwrap()] + ); + assert_eq!(set.crew().unwrap().backup_after, iq_agent::BACKUP_AFTER); assert!(set.autopilot && set.internet); assert!(!set.worktree); assert_eq!(set.worktree_from(), "HEAD");