A desktop coding agent with free access to frontier models.
TypeScript
fix(swarm): simple work stays in the main session; sub-agents do their own part
Samrat Talukdar0e4f03ee5aac
diff --git a/apps/server/src/omnirush-agent-prompt.ts b/apps/server/src/omnirush-agent-prompt.tsindex e5be8c95..a126e5d2 100644--- a/apps/server/src/omnirush-agent-prompt.ts+++ b/apps/server/src/omnirush-agent-prompt.ts@@ -38,8 +38,10 @@ Hard rule: never copy private memory into repo files. Store only redacted summar- If required setup or credentials are missing, ask one targeted question and continue once provided.- If you change code, run the smallest meaningful test.- Write long files in chunks: create a file with its first section, then append the rest in a few smaller edit (or patch) calls instead of one very large write. A single multi-thousand-token patch is the write most likely to be cut off in transit; if a write is interrupted, re-issue only the missing part.-- Use the subagent tool to delegate bounded, independent work to subagents when parallel exploration, implementation, or review will materially improve the result. Keep delegated activity visible in the session and synthesize it before answering.-- When the user explicitly asks to spawn, use, or delegate to a specific number of agents, make that many distinct subagent-tool calls. Use the general subagent unless a more specialized subagent is clearly better. Never replace an explicit delegation request with a simulated multi-role answer, and never claim subagents are unavailable while the subagent tool is present. Wait for every delegated task and then synthesize their actual results.+- Do simple work yourself: a question a few tool calls can answer needs no sub-agent. Use the subagent tool only when the user asks for sub-agents or the work clearly splits into independent parts that each take real effort.+- When the user asks for a specific number of agents, make exactly that many subagent calls, no more and no fewer, and start them all in one message so they run in parallel. Use the general subagent unless a more specialized subagent is clearly better. Never replace an explicit delegation request with a simulated multi-role answer, and never claim subagents are unavailable while the subagent tool is present.+- Write each sub-agent's prompt yourself: self-contained, limited to that sub-agent's part, saying what to return. Never paste the user's whole message, or the user's instructions about sub-agents, into a sub-agent's prompt: the sub-agent would follow them again.+- Wait for every delegated task, then synthesize their actual results before answering; keep delegated activity visible in the session.- If steps repeat, capture them as a skill following the \`Skill creation:\` instruction in this prompt.- Prefer clear, practical steps over abstract explanations.diff --git a/apps/server/src/omnirush-runtime-config.test.ts b/apps/server/src/omnirush-runtime-config.test.tsindex cc9b0a22..f991c555 100644--- a/apps/server/src/omnirush-runtime-config.test.ts+++ b/apps/server/src/omnirush-runtime-config.test.ts@@ -25,6 +25,7 @@ import {OMNIRUSH_SWARM_TOOL_NAME,omnirushSwarmSkillMarkdown,omnirushSwarmSubagentNote,+ omnirushSubagentNote,} from "./omnirush-swarm.js";import { parseFrontmatter } from "./frontmatter.js";import {@@ -323,8 +324,9 @@ describe("omnirush runtime config file", () => {expect(prompt).toContain("## Memory\n");expect(prompt).toContain("## OmniRush.ai Artifacts");expect(prompt).toContain("## Connected work");- expect(prompt).toContain("delegate bounded, independent work to subagents");- expect(prompt).toContain("make that many distinct subagent-tool calls");+ expect(prompt).toContain("Do simple work yourself: a question a few tool calls can answer needs no sub-agent.");+ expect(prompt).toContain("make exactly that many subagent calls, no more and no fewer, and start them all in one message");+ expect(prompt).toContain("Never paste the user's whole message, or the user's instructions about sub-agents, into a sub-agent's prompt");expect(prompt).toContain("Never replace an explicit delegation request with a simulated multi-role answer");expect(prompt).toContain("Wait for every delegated task");// Den removed the Memory Bank; the prompt must not teach capabilities that@@ -374,7 +376,7 @@ describe("omnirush runtime config file", () => {const section = prompt.slice(prompt.indexOf("## Sub-agent swarms"), prompt.indexOf("## Editing files"));expect(section).toContain(`load the \`${OMNIRUSH_SWARM_SKILL_NAME}\` skill first`);expect(section).toContain("Before you start 3 or more sub-agents for one request");- expect(section).toContain("at most 1-2 sub-agents with the subagent tool and no board");+ expect(section).toContain("the 1-2 sub-agents the work needs with the subagent tool and no board");// No board mechanics on every request: no file name, no table, no layers.expect(prompt).not.toContain("swarm.md");expect(prompt).not.toContain("## Tasks");@@ -383,7 +385,8 @@ describe("omnirush runtime config file", () => {expect(OMNIRUSH_SWARM_SKILL).toContain("`.omnirush/swarm.md`");expect(OMNIRUSH_SWARM_SKILL).toContain("never a file in the project root");expect(OMNIRUSH_SWARM_SKILL).toContain("For 1-2 sub-agents, stop here");- expect(OMNIRUSH_SWARM_SKILL).toContain("There is no limit on how many run at once or start per turn");+ expect(OMNIRUSH_SWARM_SKILL).toContain("Sub-agents do their own task themselves");+ expect(OMNIRUSH_SWARM_SKILL).toContain("never the user's whole message or instructions about sub-agents");// Sub-agents use the board tool instead of reading the whole board, and// omnirush.ai (not the model) clears the board when the turn ends.expect(OMNIRUSH_SWARM_SKILL).toContain(`use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id`);@@ -397,7 +400,7 @@ describe("omnirush runtime config file", () => {test("no prompt, skill or sub-agent note points a model at archived boards", () => {const prompt = (buildOmniRushRuntimeConfigObjectFromSnapshot({}).agent as Record<string, { prompt: string }>).omnirush!.prompt;- for (const text of [prompt, OMNIRUSH_SWARM_SKILL, omnirushSwarmSkillMarkdown(), omnirushSwarmSubagentNote(1), omnirushSwarmSubagentNote(3)]) {+ for (const text of [prompt, OMNIRUSH_SWARM_SKILL, omnirushSwarmSkillMarkdown(), omnirushSwarmSubagentNote(1), omnirushSwarmSubagentNote(3), omnirushSubagentNote(1), omnirushSubagentNote(3)]) {expect(text).not.toContain(OMNIRUSH_SWARM_ARCHIVE_DIR);expect(text).not.toContain("swarms/");}diff --git a/apps/server/src/omnirush-swarm.ts b/apps/server/src/omnirush-swarm.tsindex 2f39f0cb..e432e1aa 100644--- a/apps/server/src/omnirush-swarm.ts+++ b/apps/server/src/omnirush-swarm.ts@@ -102,7 +102,7 @@ export const OMNIRUSH_SWARM_TOOL_NAME = "swarm_board";/** The on-demand skill that carries the swarm procedure. */export const OMNIRUSH_SWARM_SKILL_NAME = "omnirush-swarm";-export const OMNIRUSH_SWARM_SKILL_DESCRIPTION = `Required before starting ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents for one request (a swarm, or the user asks for several agents): the shared-board procedure. Never for 1-2 sub-agents or a small request.`;+export const OMNIRUSH_SWARM_SKILL_DESCRIPTION = `Required before starting ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents for one request (a swarm, or the user asks for ${OMNIRUSH_SWARM_MIN_AGENTS}+ agents): the shared-board procedure. Never for 1-2 sub-agents or a small request.`;/*** The main agent's always-on swarm text (part of OMNIRUSH_AGENT_PROMPT). The@@ -110,18 +110,18 @@ export const OMNIRUSH_SWARM_SKILL_DESCRIPTION = `Required before starting ${OMNI*/export const OMNIRUSH_SWARM_PROMPT = `## Sub-agent swarms-Before you start ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents for one request (large work that splits into ${OMNIRUSH_SWARM_MIN_AGENTS}+ independent parts, or the user asks for a swarm or for several agents), load the \`${OMNIRUSH_SWARM_SKILL_NAME}\` skill first and follow it. Otherwise answer directly, or use at most 1-2 sub-agents with the subagent tool and no board or coordination file.`;+Before you start ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents for one request (large work that splits into ${OMNIRUSH_SWARM_MIN_AGENTS}+ independent parts, or the user asks for a swarm or for ${OMNIRUSH_SWARM_MIN_AGENTS}+ agents), load the \`${OMNIRUSH_SWARM_SKILL_NAME}\` skill first and follow it. Otherwise do simple work yourself, or use the 1-2 sub-agents the work needs with the subagent tool and no board or coordination file.`;/** The body of the omnirush-swarm skill (without frontmatter). */export const OMNIRUSH_SWARM_SKILL = `# Sub-agent swarm-Use this only for a real swarm: ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents working in parallel, or the user asked for a swarm or for several agents. For 1-2 sub-agents, stop here: call the subagent tool directly and do not create or touch a board.+Use this only for a real swarm: ${OMNIRUSH_SWARM_MIN_AGENTS} or more sub-agents working in parallel, or the user asked for a swarm or for ${OMNIRUSH_SWARM_MIN_AGENTS}+ agents. For 1-2 sub-agents, stop here: call the subagent tool directly and do not create or touch a board.The board is \`${OMNIRUSH_SWARM_FILE}\` in the workspace, never a file in the project root. It is a short status board, not a report: every agent re-reads it, so keep it small. omnirush.ai keeps it out of git and clears it when your turn ends. Ignore any \`swarm.md\` in the project root: it is not this swarm's board.1. Before delegating, create \`${OMNIRUSH_SWARM_FILE}\` (replace it if one exists) with: \`# Goal\` (at most 3 sentences), \`## Tasks\` (a table: id, task, owner, status, result; ids like T1, T2, and T1.1 for a sub-task of T1; status is todo, running, done or blocked; every cell one short line), \`## Findings\` (empty) and \`## Decisions\` (choices every agent must follow, one line each).-2. Give each sub-agent one task id. Its subagent-tool prompt names the id and the task, and says: use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id (it shows your row and the Decisions, and sets your status, one-line result and at most ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} one-line findings); do not read or edit the board file; report back briefly.-3. Sub-agents may split their own task: they add sub-task rows (T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` and give the same instructions to their own sub-agents. Sub-agents nest at most ${OMNIRUSH_SUBAGENT_DEPTH} layers deep. There is no limit on how many run at once or start per turn: start as many as the work needs, and no more.+2. Give each sub-agent one task id. Its subagent-tool prompt names the id and only its own part of the work (never the user's whole message or instructions about sub-agents), and says: use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id (it shows your row and the Decisions, and sets your status, one-line result and at most ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} one-line findings); do not read or edit the board file; report back briefly.+3. Sub-agents do their own task themselves. Only a large task that splits into clearly independent parts is split further: its sub-agent adds sub-task rows (T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` and gives the same instructions to its own sub-agents. Sub-agents nest at most ${OMNIRUSH_SUBAGENT_DEPTH} layers deep. Start as many sub-agents as the work needs, and no more.4. Launch independent tasks in parallel (several subagent calls in one message); give tasks that edit the same files to one agent.5. When every task is done, read \`${OMNIRUSH_SWARM_FILE}\` once, check the results against the task reports, and answer the user. Do not move, copy or archive the board: omnirush.ai does that when the turn ends. Board cells over ${OMNIRUSH_SWARM_CELL_MAX_CHARS} characters, lines over ${OMNIRUSH_SWARM_LINE_MAX_CHARS} and findings past ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} per task are cut.`;@@ -137,22 +137,48 @@ export function omnirushSwarmArchiveName(date: Date = new Date()): string {}/**- * System text for a sub-agent session of a running swarm (its main session- * started one and the board exists): every layer follows the board even when- * a prompt forgot to say so. It never changes during a session, so it never- * invalidates the model's prompt cache; the board itself comes from the tool.+ * System text for every sub-agent session (any layer, swarm or not): a+ * sub-agent does its own task and delegates only when its task is large.+ * Delegation instructions a main agent copied from the user's message into+ * a task prompt were meant for the main agent; without this note a sub-agent+ * obeys them again and the tree grows a layer each time. It depends only on+ * the layer, so it never changes during a session (prompt cache).+ */+export function omnirushSubagentNote(depth: number): string {+ return [+ `You are a sub-agent (layer ${depth} of at most ${OMNIRUSH_SUBAGENT_DEPTH}). Do your task yourself.`,+ "Instructions about sub-agents in your task text (how many agents to use, what to delegate) were meant for the main session, not you: do not follow them.",+ depth < OMNIRUSH_SUBAGENT_DEPTH+ ? "Delegate with the subagent tool only if your task is large and splits into clearly independent parts that would take much longer alone; never re-delegate your whole task."+ : "You cannot delegate further: do the work yourself.",+ ].join("\n");+}++/**+ * Extra system text for a sub-agent session of a running swarm (its main+ * session started one and the board exists): every layer follows the board+ * even when a prompt forgot to say so. It never changes during a session, so+ * it never invalidates the model's prompt cache; the board itself comes from+ * the tool.*/export function omnirushSwarmSubagentNote(depth: number): string {const canDelegate = depth < OMNIRUSH_SUBAGENT_DEPTH;return [- `You are a sub-agent (layer ${depth} of at most ${OMNIRUSH_SUBAGENT_DEPTH}) in a swarm coordinated through the board \`${OMNIRUSH_SWARM_FILE}\`.`,+ `You are part of a swarm coordinated through the board \`${OMNIRUSH_SWARM_FILE}\`.`,`Do not read, search or edit the board file: use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id (from your prompt); it answers with your rows and the Decisions. Call it once when you start (status running) and once when you finish (status done, a one-line result, at most ${OMNIRUSH_SWARM_FINDINGS_PER_TASK} one-line findings other agents need). Put details in your final report, not on the board. Do not move or archive the board: omnirush.ai does that.`,- canDelegate- ? `If your task splits into independent parts that each take real effort, you may delegate them with the subagent tool: add sub-task rows (for example T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` first and give each sub-agent the same instructions. Otherwise do the work yourself.`- : "You cannot delegate further: do the work yourself.",+ ...(canDelegate+ ? [`If you do delegate part of your task, add sub-task rows (for example T1.1, T1.2) with \`${OMNIRUSH_SWARM_TOOL_NAME}\` first and give each sub-agent the same board instructions.`]+ : []),].join("\n");}+/**+ * Appended to the engine's subagent tool (the 1.x task tool) description+ * (every agent that has the tool, main or sub-agent). The engine's own text+ * asks for detailed prompts and parallel launches; this bounds both.+ */+export const OMNIRUSH_TASK_TOOL_NOTE = "omnirush.ai: do simple work yourself; start sub-agents only when the user asks for them or the work clearly splits into independent parts. When the user names a number of agents, start exactly that many, all in one message. Each prompt covers only that agent's part and is self-contained: never paste the user's whole message or the user's instructions about sub-agents into it.";+export const OMNIRUSH_SWARM_STATUSES = ["todo", "running", "done", "blocked"] as const;export type SwarmTaskStatus = (typeof OMNIRUSH_SWARM_STATUSES)[number];diff --git a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts b/apps/server/src/opencode-plugins/omnirush-swarm.test.tsindex d8e043c3..fda10525 100644--- a/apps/server/src/opencode-plugins/omnirush-swarm.test.ts+++ b/apps/server/src/opencode-plugins/omnirush-swarm.test.ts@@ -18,6 +18,8 @@ import {OMNIRUSH_SWARM_MAX_PER_TURN,OMNIRUSH_SWARM_MAX_RUNNING,OMNIRUSH_SWARM_SKILL_NAME,+ OMNIRUSH_TASK_TOOL_NOTE,+ omnirushSubagentNote,} from "../omnirush-swarm.js";type Hooks = Awaited<ReturnType<typeof OmniRushSwarm>>;@@ -96,18 +98,19 @@ describe("omnirush swarm plugin", () => {await created(hooks, "ses_great", "ses_grand");const system = systemOf(hooks);await loadSwarmSkill(hooks, "ses_main");- expect(await system("ses_child")).toBe("");+ expect(await system("ses_child")).toBe(omnirushSubagentNote(1));await writeBoard(directory);expect(await system("ses_main")).toBe("");const child = await system("ses_child");expect(child).toContain("layer 1 of at most 3");expect(child).toContain("Do not read, search or edit the board file");expect(child).toContain(`use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool`);- expect(child).toContain("you may delegate");+ expect(child).toContain("If you do delegate part of your task, add sub-task rows");expect(await system("ses_grand")).toContain("layer 2 of at most 3");const great = await system("ses_great");expect(great).toContain(`layer ${OMNIRUSH_SUBAGENT_DEPTH} of at most ${OMNIRUSH_SUBAGENT_DEPTH}`);expect(great).toContain("You cannot delegate further");+ expect(great).not.toContain("If you do delegate");});test("1-2 plain task calls get no board note, whatever board files exist", async () => {@@ -118,7 +121,42 @@ describe("omnirush swarm plugin", () => {// A root swarm.md from an older version and a board no swarm of this session started.await writeFile(join(directory, "swarm.md"), "# Goal\nold\n");await writeBoard(directory);- expect(await systemOf(hooks)("ses_child")).toBe("");+ expect(await systemOf(hooks)("ses_child")).toBe(omnirushSubagentNote(1));+ });++ test("every sub-agent is told to do its own task and to ignore sub-agent instructions meant for the main session", async () => {+ const { hooks } = await setup();+ await created(hooks, "ses_main");+ await created(hooks, "ses_child", "ses_main");+ await created(hooks, "ses_grand", "ses_child");+ await created(hooks, "ses_great", "ses_grand");+ const system = systemOf(hooks);+ // The main session keeps its own prompt: it is the one that delegates.+ expect(await system("ses_main")).toBe("");+ const child = await system("ses_child");+ expect(child).toContain("Do your task yourself.");+ expect(child).toContain("Instructions about sub-agents in your task text");+ expect(child).toContain("were meant for the main session, not you");+ expect(child).toContain("never re-delegate your whole task");+ expect(await system("ses_grand")).toContain("layer 2 of at most 3");+ const great = await system("ses_great");+ expect(great).toContain("You cannot delegate further");+ expect(great).not.toContain("Delegate with the subagent tool");+ // Same text on every step (prompt cache).+ expect(await system("ses_child")).toBe(child);+ });++ test("the task tool description carries omnirush.ai's delegation rules, once", async () => {+ const { hooks } = await setup();+ const task = { description: "Launch a new agent." };+ await hooks["tool.definition"]({ toolID: "task" }, task);+ await hooks["tool.definition"]({ toolID: "task" }, task);+ expect(task.description).toBe(`Launch a new agent.\n\n${OMNIRUSH_TASK_TOOL_NOTE}`);+ expect(OMNIRUSH_TASK_TOOL_NOTE).toContain("start exactly that many, all in one message");+ expect(OMNIRUSH_TASK_TOOL_NOTE).toContain("never paste the user's whole message");+ const bash = { description: "Run a command." };+ await hooks["tool.definition"]({ toolID: "bash" }, bash);+ expect(bash.description).toBe("Run a command.");});test("writing the board marks the swarm too, and keeps the board out of git", async () => {@@ -185,7 +223,7 @@ describe("omnirush swarm plugin", () => {expect(contents.some((text) => text.includes("live"))).toBe(true);// The swarm is over: its sub-agents hear of no board, and a later small request finds none.await writeBoard(directory);- expect(await systemOf(hooks)("ses_child")).toBe("");+ expect(await systemOf(hooks)("ses_child")).toBe(omnirushSubagentNote(1));});test("the root swarm.md of older versions is never moved", async () => {diff --git a/apps/server/src/opencode-plugins/omnirush-swarm.ts b/apps/server/src/opencode-plugins/omnirush-swarm.tsindex eb80e6ef..a420b241 100644--- a/apps/server/src/opencode-plugins/omnirush-swarm.ts+++ b/apps/server/src/opencode-plugins/omnirush-swarm.ts@@ -12,6 +12,11 @@* A task call over a limit fails before it creates a session, with a message* telling the model to do the work itself.*+ * Delegation restraint: every sub-agent session gets a system note+ * (omnirushSubagentNote) to do its own task and ignore sub-agent+ * instructions copied into its prompt, and the task tool description gains+ * omnirush.ai's delegation rules (OMNIRUSH_TASK_TOOL_NOTE).+ ** Swarm board: a main session runs a swarm once its tree loads the* omnirush-swarm skill or writes the board (`.omnirush/swarm.md`). Only then* are its sub-agents reminded of the board (while it exists), so 1-2 plain@@ -70,7 +75,9 @@ import {OMNIRUSH_SWARM_FILE,OMNIRUSH_SWARM_MAX_PER_TURN,OMNIRUSH_SWARM_MAX_RUNNING,+ omnirushSubagentNote,omnirushSwarmSubagentNote,+ OMNIRUSH_TASK_TOOL_NOTE,} from "../omnirush-swarm.js";type SessionInfo = { id?: unknown; parentID?: unknown; title?: unknown };@@ -665,12 +672,23 @@ export const OmniRushSwarm = async (input?: { client?: SwarmClient; directory?:if (!directory || typeof request?.sessionID !== "string" || !Array.isArray(output?.system)) return;if ((await parentOf(request.sessionID)) === null) return;const { root, depth } = await locate(request.sessionID);- // Only the sub-agents of a running swarm, and only while its board exists.+ const layer = Math.min(Math.max(depth, 1), OMNIRUSH_SUBAGENT_DEPTH);+ // Every sub-agent does its own task (whatever its prompt says about+ // sub-agents). The notes are the same on every step (a changing system+ // prompt would defeat the model's prompt cache).+ output.system.push(omnirushSubagentNote(layer));+ // The board note: only the sub-agents of a running swarm, and only+ // while its board exists; the agent's rows come from the tool.if (!swarms.has(root)) return;if (!existsSync(join(directory, OMNIRUSH_SWARM_FILE))) return;- // The note is the same on every step (a changing system prompt would- // defeat the model's prompt cache); the agent's rows come from the tool.- output.system.push(omnirushSwarmSubagentNote(Math.min(Math.max(depth, 1), OMNIRUSH_SUBAGENT_DEPTH)));+ output.system.push(omnirushSwarmSubagentNote(layer));+ },++ // The engine's task tool text asks for detailed prompts and parallel+ // launches "whenever possible"; omnirush.ai's delegation rules follow it.+ "tool.definition": async (request: { toolID?: string }, output: { description?: unknown }) => {+ if (request?.toolID !== "task" || typeof output?.description !== "string") return;+ if (!output.description.includes(OMNIRUSH_TASK_TOOL_NOTE)) output.description = `${output.description}\n\n${OMNIRUSH_TASK_TOOL_NOTE}`;},tool: {