Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
add swarm mode to the CoS claim-issue schedule (/do:next --swarm)
[._.]/ Adam Eivyc11626374a4b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex c75a9c7669..71b39e3e2c 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -7,6 +7,7 @@## Added+- **CoS `claim-issue` swarm mode** — the schedule config (CoS → Schedule → Claim Issue, and the resolved `claim-work` flow) gains a **Swarm Mode** selector that runs each scheduled claim in slashdo `/do:next --swarm` mode: instead of claiming one issue per run, it partitions up to N (2–6) mutually-independent open issues, fans out one worktree subagent per issue (each running the unchanged single-issue claim → implement → review flow), and serializes only the merges. Configurable globally with a per-app override; GitHub/GitLab issue trackers only (plan-task / JIRA are a no-op). The swarm directive is prepended to the dispatched prompt only when enabled, so it's a pure opt-in wrapper with no prompt-default version bump; `swarmCount` is range-validated (0 = off, 2–6 = swarm size) in `sanitizeTaskMetadata`.- **Creative Director auto-compose** — the Overview tab's Auto-cast control now has a `+ treatment` toggle (shown only before a treatment exists): with it on, once the director seeds the cast from the catalog it autonomously writes a first-pass treatment + scene plan grounded in that cast, instead of stopping at cast seeding. Director-first — the autonomous treatment is a starting point you keep editing on the same board, and it never clobbers an existing treatment. (#1817)- **Creative Director first-pass portraits** — the Overview tab's Auto-cast control gains a `+ portraits` toggle: with it on, once the director seeds the cast from the catalog it queues an on-model portrait render for each newly-cast member that has no portrait yet, so the cast "arrives on-model" without hand-rendering each ingredient. Reuses the existing media-job queue and the durable catalog image-attach hook (the render lands as the ingredient's portrait even if you've navigated away), is strictly optional and idempotent (members that already have a portrait are skipped), and seeds only the queue-backed image-gen modes (local / codex) — external SD-API and a disabled codex are skipped gracefully rather than failing the auto-cast. (#1818)- Shell page now has a **Fullscreen** button that promotes the terminal to a full-viewport overlay (above the sidebar), hiding the stacked header/tabs/quick-commands toolbars so the TUI gets the whole screen — a major mobile usability win where those toolbars previously ate most of the display. Fullscreen keeps a compact, horizontally-scrollable control bar (Exit, Ctrl+C, Paste, arrow/Enter keys) so you can still drive a TUI by thumb, and the Ctrl+C/Paste labels now collapse on small screens to save width.diff --git a/client/src/components/cos/constants.js b/client/src/components/cos/constants.jsindex d6cc5891d0..083a5f9da2 100644--- a/client/src/components/cos/constants.js+++ b/client/src/components/cos/constants.js@@ -102,6 +102,21 @@ export const ISSUE_AUTHOR_FILTER_OPTIONS = [// issue-claiming task type here rather than OR-ing literals across components.export const ISSUE_AUTHOR_FILTER_TASK_TYPES = new Set(['claim-issue', 'claim-work']);+// Swarm fan-out (taskMetadata.swarmCount). Mirrors slashdo `/do:next --swarm=<N>`+// (clamped 1..6; bare --swarm = 3). 0 = off (single issue per run, the default);+// 2..6 = claim & ship that many independent issues in parallel. Server-side+// SWARM_COUNT_MIN/MAX (cosValidation.js) enforce the same 2..6 range. Exposed on+// the same forge-issue task types as the author filter.+export const SWARM_TASK_TYPES = ISSUE_AUTHOR_FILTER_TASK_TYPES;+export const SWARM_COUNT_OPTIONS = [+ { value: 0, label: 'Off (one issue per run)', description: 'Claim and ship a single issue per scheduled run (default)' },+ { value: 2, label: '2 in parallel', description: 'Claim and ship up to 2 independent issues per run, merges serialized' },+ { value: 3, label: '3 in parallel', description: 'Claim and ship up to 3 independent issues per run, merges serialized' },+ { value: 4, label: '4 in parallel', description: 'Claim and ship up to 4 independent issues per run, merges serialized' },+ { value: 5, label: '5 in parallel', description: 'Claim and ship up to 5 independent issues per run, merges serialized' },+ { value: 6, label: '6 in parallel', description: 'Claim and ship up to 6 independent issues per run, merges serialized' }+];+export const DEFAULT_REVIEWER = 'copilot';export const DEFAULT_REVIEWERS = ['copilot'];diff --git a/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx b/client/src/components/cos/tabs/schedule/AppOverrideRow.jsxindex ce202f0d23..67535294a9 100644--- a/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx+++ b/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx@@ -1,7 +1,7 @@import { useState, memo } from 'react';import AppIcon from '../../../AppIcon';import CronInput from '../../../CronInput';-import { AGENT_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, toggleAppMetadataOverride, agentOptionButtonClass } from '../../constants';+import { AGENT_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES, toggleAppMetadataOverride, agentOptionButtonClass } from '../../constants';import { isCronExpression, describeCron } from '../../../../utils/cronHelpers';import ToggleSwitch from '../../../ToggleSwitch';import { INTERVAL_LABELS } from './scheduleConstants';@@ -58,6 +58,19 @@ const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalIntersetUpdating(false);};+ // claim-issue per-app swarm override. '' = inherit the global default; '0'+ // = explicit off; 2..6 = swarm with that many agents. Sent as a Number so the+ // server's integer-range check keeps it (0 collapses to off and is dropped).+ const handleSwarmCountChange = async (raw) => {+ setUpdating(true);+ const next = { ...(override?.taskMetadata || {}) };+ if (raw === '') delete next.swarmCount;+ else next.swarmCount = Number(raw);+ const taskMetadata = Object.keys(next).length ? next : null;+ await onUpdate(app.id, taskType, { taskMetadata }).catch(() => {});+ setUpdating(false);+ };+return (<div className="flex flex-col sm:flex-row sm:flex-wrap sm:items-center gap-2 sm:gap-3 py-2 px-3 rounded hover:bg-port-card/30"><div className="flex items-center gap-2 min-w-0 w-full sm:w-auto sm:flex-1">@@ -149,6 +162,22 @@ const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalInter</select>)}+ {SWARM_TASK_TYPES.has(taskType) && (+ <select+ value={override?.taskMetadata?.swarmCount ?? ''}+ onChange={(e) => handleSwarmCountChange(e.target.value)}+ disabled={updating}+ aria-label={`Swarm mode for ${app.name}`}+ title="How many independent issues this app claims in parallel per run"+ className="bg-port-card border border-port-border rounded px-2 py-1.5 text-xs text-white min-w-[120px] min-h-[40px]"+ >+ <option value="">Inherit ({SWARM_COUNT_OPTIONS.find(o => o.value === (globalTaskMetadata?.swarmCount || 0))?.label})</option>+ {SWARM_COUNT_OPTIONS.map(opt => (+ <option key={opt.value} value={opt.value}>{opt.label}</option>+ ))}+ </select>+ )}+<div className="hidden sm:block"><ToggleSwitchenabled={isEnabled}diff --git a/client/src/components/cos/tabs/schedule/AppTaskCard.test.jsx b/client/src/components/cos/tabs/schedule/AppTaskCard.test.jsxindex eaf34f5c3b..d6e851e4e6 100644--- a/client/src/components/cos/tabs/schedule/AppTaskCard.test.jsx+++ b/client/src/components/cos/tabs/schedule/AppTaskCard.test.jsx@@ -84,4 +84,17 @@ describe('AppTaskCard', () => {renderCard({ globalLastRun: null });expect(screen.getByText('Never run')).toBeTruthy();});++ it('shows a swarm badge when swarmCount ≥ 2 and hides it otherwise', () => {+ renderCard({ taskMetadata: { swarmCount: 3 } });+ expect(screen.getByText('×3')).toBeTruthy();+ expect(screen.getByTitle(/Swarm mode/)).toBeTruthy();+ });++ it('hides the swarm badge when swarm is off (absent / 0)', () => {+ renderCard({ taskMetadata: { swarmCount: 0 } });+ expect(screen.queryByText(/^×\d/)).toBeNull();+ renderCard({});+ expect(screen.queryByText(/^×\d/)).toBeNull();+ });});diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsxindex b401779889..283e5df662 100644--- a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx@@ -1,7 +1,7 @@import { useState, useEffect } from 'react';import { RotateCcw, AlertCircle, Info } from 'lucide-react';import CronInput from '../../../CronInput';-import { AGENT_OPTIONS, DEFAULT_REVIEW_STOP_MODE, PR_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES } from '../../constants';+import { AGENT_OPTIONS, DEFAULT_REVIEW_STOP_MODE, PR_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES } from '../../constants';import ReviewerPicker from '../../ReviewerPicker';import Banner from '../../../ui/Banner';import { useCodeReviewDefaults } from '../../../../hooks/useCodeReviewDefaults';@@ -127,6 +127,16 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTrisetUpdating(false);};+ const handleSwarmCountChange = async (value) => {+ setUpdating(true);+ // 0 = off, 2..6 = swarm size (server keeps both; 1/out-of-range are dropped).+ // taskMetadata is replaced wholesale server-side, so spread the existing keys.+ await onUpdate(taskType, {+ taskMetadata: { ...(config.taskMetadata || {}), swarmCount: value }+ });+ setUpdating(false);+ };+const handleSavePrompt = async () => {setUpdating(true);const prompt = promptValue.trim() === '' ? null : promptValue;@@ -333,6 +343,27 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri</div>)}+ {SWARM_TASK_TYPES.has(taskType) && (+ <div>+ <label htmlFor={`swarm-count-${taskType}`} className="text-sm text-gray-400 block mb-2">Swarm Mode</label>+ <select+ id={`swarm-count-${taskType}`}+ value={config.taskMetadata?.swarmCount || 0}+ onChange={(e) => handleSwarmCountChange(Number(e.target.value))}+ disabled={updating}+ className="w-full bg-port-card border border-port-border rounded px-3 py-2 text-white text-sm"+ >+ {SWARM_COUNT_OPTIONS.map(opt => (+ <option key={opt.value} value={opt.value}>{opt.label}</option>+ ))}+ </select>+ <p className="text-xs text-gray-500 mt-1">+ {SWARM_COUNT_OPTIONS.find(o => o.value === (config.taskMetadata?.swarmCount || 0))?.description}.+ {' '}Mirrors slashdo <code>/do:next --swarm</code> — each run partitions independent issues, fans out one worktree agent per issue, and serializes the merges. GitHub/GitLab issue trackers only.+ </p>+ </div>+ )}+<PromptEditorconfig={config}promptValue={promptValue}diff --git a/client/src/components/cos/tabs/schedule/TaskHeader.jsx b/client/src/components/cos/tabs/schedule/TaskHeader.jsxindex 8161f944ac..eee96b56f1 100644--- a/client/src/components/cos/tabs/schedule/TaskHeader.jsx+++ b/client/src/components/cos/tabs/schedule/TaskHeader.jsx@@ -1,18 +1,29 @@-import { GitMerge } from 'lucide-react';+import { GitMerge, Users } from 'lucide-react';import { badge, statusDot, getTaskStatusGroup } from './scheduleConstants';import IntervalBadge from './IntervalBadge';-// Shared task identity row — status dot, monospace name, pipeline badge, and-// interval badge. Used by both the schedule card and the config drawer so the-// header stays consistent in one place.+// Shared task identity row — status dot, monospace name, pipeline + swarm+// badges, and interval badge. Used by both the schedule card and the config+// drawer so the header stays consistent in one place.export default function TaskHeader({ taskType, config }) {const group = getTaskStatusGroup(config);const stages = config.taskMetadata?.pipeline?.stages;+ // Swarm (`/do:next --swarm`) is on when the global default carries a size ≥2.+ // Per-app overrides aren't reflected in this global header (the per-app row+ // shows its own override select).+ const swarmCount = config.taskMetadata?.swarmCount;+ const swarmOn = Number.isInteger(swarmCount) && swarmCount >= 2;return (<div className="flex items-start gap-2"><span className={`mt-1.5 w-2 h-2 rounded-full shrink-0 ${statusDot(group)}`} title={group} aria-hidden="true" /><span className="font-mono text-sm text-white break-all leading-tight flex-1 min-w-0">{taskType}</span><div className="flex items-center gap-1.5 shrink-0">+ {swarmOn && (+ <span className={badge('cyan')} title={`Swarm mode — claims & ships up to ${swarmCount} independent issues in parallel per run`}>+ <Users size={11} className="inline mr-0.5" />+ ×{swarmCount}+ </span>+ )}{stages?.length > 0 && (<span className={badge('purple')} title={stages.map(s => s.name).join(' → ')}><GitMerge size={11} className="inline mr-0.5" />diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.jsindex 35df341453..22a6f67beb 100644--- a/server/lib/cosValidation.js+++ b/server/lib/cosValidation.js@@ -271,6 +271,16 @@ export const PR_AUTHOR_FILTERS = ['any', 'self', 'others'];// prompt-builder agree on the vocabulary.export const ISSUE_AUTHOR_FILTERS = ['self', 'owner', 'any'];+// claim-issue `--swarm` fan-out size. Mirrors slashdo `/do:next --swarm=<N>`,+// which clamps N to 1..6 and treats bare `--swarm` as 3. Here a swarmCount of+// 0 (or absent) means swarm OFF (the default one-issue-per-run flow); a value+// of 2..6 turns on swarm with that many parallel claim agents. 1 is collapsed+// to off (a one-agent swarm is just the single-issue flow with overhead), so+// the smallest meaningful swarm is 2. Kept here so the sanitizer and the+// claim-issue prompt-builder agree on the vocabulary.+export const SWARM_COUNT_MIN = 2;+export const SWARM_COUNT_MAX = 6;+/*** Sanitize taskMetadata to an allow-list of agent-option keys. Boolean flags* (`useWorktree`/`openPR`/`simplify`/`reviewLoop`/`readOnly`/`reviewerApplies`)@@ -328,6 +338,19 @@ export function sanitizeTaskMetadata(raw) {clean.issueAuthorFilter = raw.issueAuthorFilter;hasKeys = true;}+ // `swarmCount` turns claim-issue `--swarm` fan-out on (2..6 parallel agents)+ // or off. 0 is kept as an explicit "off" (so a per-app override can disable+ // swarm even when the global default has it on — `0` = off, absent = inherit);+ // 2..6 is the swarm size. 1/non-integer/out-of-range are dropped, so a+ // hand-edited config can't smuggle in an unbounded swarm size. The prompt+ // builder treats anything below SWARM_COUNT_MIN as off (resolveSwarmBlock).+ if (Object.prototype.hasOwnProperty.call(raw, 'swarmCount')+ && Number.isInteger(raw.swarmCount)+ && (raw.swarmCount === 0+ || (raw.swarmCount >= SWARM_COUNT_MIN && raw.swarmCount <= SWARM_COUNT_MAX))) {+ clean.swarmCount = raw.swarmCount;+ hasKeys = true;+ }// Pass through pipeline config (validated shape: object with stages array)if (raw.pipeline && typeof raw.pipeline === 'object' && Array.isArray(raw.pipeline.stages)) {clean.pipeline = raw.pipeline;diff --git a/server/lib/validation.test.js b/server/lib/validation.test.jsindex 597a6e8a71..2d039c490d 100644--- a/server/lib/validation.test.js+++ b/server/lib/validation.test.js@@ -593,6 +593,25 @@ describe('validation.js', () => {.toEqual({ useWorktree: true });});+ it('should accept swarmCount 0 + 2..6 and drop 1/out-of-range/non-integer', () => {+ // 0 is an explicit "off" (kept so a per-app override can disable swarm).+ expect(sanitizeTaskMetadata({ swarmCount: 0 })).toEqual({ swarmCount: 0 });+ expect(sanitizeTaskMetadata({ swarmCount: 2 })).toEqual({ swarmCount: 2 });+ expect(sanitizeTaskMetadata({ swarmCount: 6 })).toEqual({ swarmCount: 6 });+ // 1 (a one-agent swarm is just the single-issue flow) and out-of-range are dropped.+ expect(sanitizeTaskMetadata({ swarmCount: 1 })).toBeNull();+ expect(sanitizeTaskMetadata({ swarmCount: 7 })).toBeNull();+ expect(sanitizeTaskMetadata({ swarmCount: -1 })).toBeNull();+ // Non-integers can't smuggle an unbounded swarm size.+ expect(sanitizeTaskMetadata({ swarmCount: 3.5 })).toBeNull();+ expect(sanitizeTaskMetadata({ swarmCount: '3' })).toBeNull();+ // Drops the bad value but keeps a valid sibling key.+ expect(sanitizeTaskMetadata({ useWorktree: true, swarmCount: 99 }))+ .toEqual({ useWorktree: true });+ expect(sanitizeTaskMetadata({ issueAuthorFilter: 'any', swarmCount: 3 }))+ .toEqual({ issueAuthorFilter: 'any', swarmCount: 3 });+ });+it('should accept an ordered reviewers list, dedupe, and drop unknowns', () => {expect(sanitizeTaskMetadata({ reviewers: ['codex', 'antigravity', 'copilot'] })).toEqual({ reviewers: ['codex', 'antigravity', 'copilot'] });diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex d2d17845dc..59fabed592 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -22,7 +22,7 @@import { readFile } from 'fs/promises';import { existsSync } from 'fs';import { join } from 'path';-import { sanitizeTaskMetadata, PIPELINE_BEHAVIOR_FLAGS, MAX_TOTAL_SPAWNS, normalizeReviewers, LOCAL_LLM_REVIEWERS, DEFAULT_REVIEWERS } from '../lib/validation.js';+import { sanitizeTaskMetadata, PIPELINE_BEHAVIOR_FLAGS, MAX_TOTAL_SPAWNS, normalizeReviewers, LOCAL_LLM_REVIEWERS, DEFAULT_REVIEWERS, SWARM_COUNT_MIN } from '../lib/validation.js';import { parsePlanItems, extractAllIds, findInProgressIds, pickFirstAvailable, diagnoseUnpickablePlan } from '../lib/planIds.js';import { loadState, saveState, withStateLock, isImprovementEnabled, isDaemonRunning } from './cosState.js';import { getDomainMode } from '../lib/domainAutonomy.js';@@ -211,6 +211,58 @@ export function resolveIssueAuthorFilterBlock(promptTaskType, mode = 'self') {return (ISSUE_AUTHOR_FILTER_BLOCKS[issueForge] || ISSUE_AUTHOR_FILTER_BLOCKS.gh)[filterMode];}+// Per-forge nouns/commands for the swarm directive. The orchestration shape is+// forge-agnostic (partition → fan-out → serialized merge); only the PR/MR noun+// and the merge command differ between GitHub (`gh`) and GitLab (`glab`).+const SWARM_FORGE = {+ gh: { pr: 'PR', mergeCmd: 'gh pr merge' },+ glab: { pr: 'MR', mergeCmd: 'glab mr merge' }+};++/**+ * Resolve the `{swarm}` directive prepended to the claim-issue prompt when the+ * task's `taskMetadata.swarmCount` turns on slashdo `/do:next --swarm` mode.+ *+ * Returns '' (no-op) when swarm is off (count < SWARM_COUNT_MIN) OR the resolved+ * prompt type is not a forge issue tracker (plan-task / claim-issue-jira have no+ * swarm flow — swarm is GitHub/GitLab issues only, matching slashdo). Otherwise+ * returns a Markdown block that converts the single-issue prompt below it into a+ * partition → parallel fan-out → serialized-merge orchestration over up to+ * `count` independent issues. The block does NOT restate the per-issue phases —+ * each fan-out agent reuses the single-issue Phases 2–6 verbatim, so the swarm+ * layer stays a thin orchestration wrapper (never a divergent claim path).+ */+export function resolveSwarmBlock(promptTaskType, count) {+ const n = Number.isInteger(count) ? count : 0;+ if (n < SWARM_COUNT_MIN) return '';+ const forgeKey = promptTaskType === 'claim-issue-gitlab' ? 'glab'+ : promptTaskType === 'claim-issue' ? 'gh'+ : null;+ if (!forgeKey) return ''; // plan-task / jira have no swarm flow+ const { pr, mergeCmd } = SWARM_FORGE[forgeKey];+ return `# ⚡ SWARM MODE — claim and ship up to ${n} independent issues in parallel++**This run operates in slashdo \`/do:next --swarm=${n}\` mode.** The single-issue framing in the task body below is your PER-AGENT playbook, not the shape of the whole run: instead of claiming ONE issue, claim up to ${n} *mutually independent* open issues and ship them concurrently, then serialize only the merges. Swarm adds exactly two things over the single-issue flow — a partition step up front and a serialized merge queue at the end; everything in between (claim, worktree, verify, implement, changelog, review gate) is the unchanged single-issue flow run once per agent. Never special-case a swarm agent's claim/ship logic.++**Swarm is issues-mode only.** If the resolved work tracker is not a forge issue tracker (no claimable open issues), ignore this section entirely and run the normal single-issue flow below.++## Phase A — Partition the batch (ONCE, up front)+1. Run Phase 1's candidate scan + in-flight filter (below) to build the eligible-issue queue (oldest-first, honoring the author filter).+2. From that queue pick up to ${n} issues that are **mutually independent** — no shared files/subsystems likely to collide on merge, no parent/child or dependency links; prefer issues that touch disjoint areas. **Under-fill is fine:** if fewer than ${n} independent issues exist, run a smaller swarm and say so. **If only ONE is eligible, just run the single-issue flow below and say so** — a one-agent swarm is pure overhead.++## Phase B — Fan out (one subagent per picked issue)+For EACH picked issue, spawn a subagent that runs the single-issue **Phases 2–6 below** for that one issue — claim (own \`claim/issue-<num>\` worktree + assignee + \`in-progress\` label) → verify → implement → changelog → open the ${pr} → run the review gate ({reviewers}) — **but with NO merge and NO Phase 7 cleanup** (the orchestrator owns those; each agent opens its ${pr} the equivalent of \`--no-merge\`). Because each agent claims through the normal Phase 2 assignee marker + race read-back, two agents can never ship the same issue.++## Phase C — Serialize the merges (orchestrator, after all agents finish)+Merge the ready ${pr}s ONE AT A TIME. For each: re-sync onto the latest default branch, gate on **required** CI (one re-run on a flaky required check, then proceed; a real failure or an irreconcilable conflict leaves that ${pr} OPEN and recorded — move to the next), then \`${mergeCmd}\`. After all merges, run Phase 7 cleanup once per merged worktree.++Everything not covered above (claim mechanics, branch naming, verify/skip rules, implement conventions, ${pr} body, review loop) is exactly the single-issue flow documented below.++---++`;+}+/*** Build a one-off "claim the next work item" task for `app`, routed by the app's* configured workTracker — the manual (Slashdo `/do:next` button) counterpart to@@ -279,8 +331,14 @@ export async function buildClaimWorkTask(app, { issueAuthorFilter, reviewers } =}const reviewersCsv = (reviewersList.length ? reviewersList : [...DEFAULT_REVIEWERS]).join(',');const issueAuthorFilterBlock = resolveIssueAuthorFilterBlock(promptTaskType, resolvedAuthorFilter);-- const prompt = template+ // Swarm mode (`/do:next --swarm`) is prepended (not an in-template+ // placeholder) so it stays an opt-in orchestration wrapper that needs no+ // prompt-default version bump; empty when swarmCount is off or the tracker+ // isn't a forge issue tracker. {reviewers} inside the block is substituted by+ // the same replacer below.+ const swarmBlock = resolveSwarmBlock(promptTaskType, metadata.swarmCount);++ const prompt = `${swarmBlock}${template}`.replace(/\{appName\}/g, app.name).replace(/\{repoPath\}/g, app.repoPath).replace(/\{appId\}/g, app.id)@@ -1681,8 +1739,13 @@ export async function generateManagedAppImprovementTaskForType(taskType, app, st// from `metadata` (default 'self', the slashdo `/do:next --self` security// boundary — only claim issues you filed).const issueAuthorFilterBlock = resolveIssueAuthorFilterBlock(promptTaskType, metadata.issueAuthorFilter || 'self');+ // Swarm directive — prepended (see buildClaimWorkTask note). swarmCount was+ // merged (global → per-app override) + value-constrained by+ // sanitizeTaskMetadata, so read it from `metadata`. Empty for non-issue+ // trackers and when swarm is off.+ const swarmBlock = resolveSwarmBlock(promptTaskType, metadata.swarmCount);- const description = promptTemplate+ const description = `${swarmBlock}${promptTemplate}`.replace(/\{appName\}/g, app.name).replace(/\{repoPath\}/g, app.repoPath).replace(/\{appId\}/g, app.id)diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.jsindex 92054a7221..ece7154b1b 100644--- a/server/services/cosTaskGenerator.test.js+++ b/server/services/cosTaskGenerator.test.js@@ -15,7 +15,7 @@ import { describe, it, expect } from 'vitest';import { readFileSync } from 'fs';import { fileURLToPath } from 'url';import { dirname, join } from 'path';-import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock, isCooldownExemptTask } from './cosTaskGenerator.js';+import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock, resolveSwarmBlock, isCooldownExemptTask } from './cosTaskGenerator.js';import { MAX_TOTAL_SPAWNS } from '../lib/validation.js';const __dirname = dirname(fileURLToPath(import.meta.url));@@ -252,6 +252,53 @@ describe('resolveIssueAuthorFilterBlock', () => {});});+// resolveSwarmBlock is prepended to the claim-issue prompt when swarmCount turns+// on `/do:next --swarm` mode. Like the author filter, it's a standalone pure+// helper shared by the scheduled router and the manual /do:next button.+describe('resolveSwarmBlock', () => {+ it('returns empty (off) below the swarm minimum', () => {+ expect(resolveSwarmBlock('claim-issue', 0)).toBe('');+ expect(resolveSwarmBlock('claim-issue', 1)).toBe('');+ expect(resolveSwarmBlock('claim-issue', undefined)).toBe('');+ expect(resolveSwarmBlock('claim-issue', 3.5)).toBe('');+ });++ it('returns a gh swarm directive for the github claim body', () => {+ const block = resolveSwarmBlock('claim-issue', 3);+ expect(block).toContain('SWARM MODE');+ expect(block).toContain('--swarm=3');+ expect(block).toContain('3 independent issues');+ expect(block).toContain('gh pr merge');+ // Ends with a separator so the single-issue body reads as the per-agent flow.+ expect(block.trimEnd().endsWith('---')).toBe(true);+ });++ it('returns a glab/MR swarm directive for the gitlab claim body', () => {+ const block = resolveSwarmBlock('claim-issue-gitlab', 4);+ expect(block).toContain('--swarm=4');+ expect(block).toContain('glab mr merge');+ expect(block).toContain('open the MR');+ });++ it('is a no-op for non-forge claim types (plan-task / jira have no swarm flow)', () => {+ expect(resolveSwarmBlock('plan-task', 6)).toBe('');+ expect(resolveSwarmBlock('claim-issue-jira', 6)).toBe('');+ });+});++// Source-level guard: the swarm block must be PREPENDED at both render sites+// (the scheduled dispatch and the manual buildClaimWorkTask), not gated behind+// an in-template placeholder — that's what keeps it an opt-in wrapper with no+// prompt-default version bump.+describe('swarm block wiring', () => {+ it('prepends resolveSwarmBlock(...) to the rendered prompt at both render sites', () => {+ const occurrences = GEN_SRC.match(/resolveSwarmBlock\(promptTaskType, metadata\.swarmCount\)/g) || [];+ expect(occurrences.length).toBe(2);+ expect(GEN_SRC).toContain('`${swarmBlock}${template}`');+ expect(GEN_SRC).toContain('`${swarmBlock}${promptTemplate}`');+ });+});+describe('exceedsMaxSpawns', () => {it('is false below the ceiling and true at/above it — no mutation', () => {expect(exceedsMaxSpawns(task('a', { totalSpawnCount: 0 }))).toBe(false);