The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
Buddy model switch Implementation Plan
For agentic workers: This plan is carried out by the task's Engineer by the project's instructions (Engineer role): task by task, each failing test committed before its code, one pull request, one independent review step at the end. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: A person switches their Buddy between their own Claude subscription and a model shared in the Swarm, and back, keeping the Buddy chat and its conversation (or a fresh session when the conversation is too long).
Architecture: The person asks the server (buddy.model); the server checks the model against the Swarm's served
models and records a request on the Buddy's agent; the Buddy's host carries it out through its own daemon's existing
agent_retarget (respawn in place with --resume), measuring the conversation first and starting fresh when it does
not fit; the host reports buddy.modelResult, which sets Agent.gridModel and writes the line in the Buddy chat.
Tech Stack: TypeScript backend (vitest), TypeScript CLI/daemon (node:test specs), Flutter Desktop (flutter_test).
Spec: docs/plans/2026-11-03-buddy-model-switch-design.md
Global Constraints
- PR body first line: "Requested by [email protected] through Harness."
- The Buddy guard and Buddy privacy rules stay as they are (docs/swarms.md, Buddies); two security reviews.
- Swarm code stays out of
cli/src/core; the core change is generic (freshand the remembered session on any pane). - Never run a test that signs the Mac out of the real CLI; Desktop tests use a memory store and a fake sign-in.
- Before Ready: a failing-then-passing test for every risk below, red/green evidence in a PR comment, the full Super Tab
integration suite (
npm run test:integrationper docs/validation-and-release.md) for the backend change. - Copy, exact:
Your subscription,SHARED IN THIS SWARM,served by <machine>[, <machine>…],<person>'s saved API,Switching to <model>…,not served now,Your Buddy now runs on <model>, served by <servers>.,Your Buddy started a fresh session on <model>: this conversation is too long for it (<window>K). Switch back to your subscription to continue the earlier one.,Your Buddy is back on your subscription.,Couldn't switch your Buddy: <reason>. It is still on <current>.,Couldn't switch your Buddy: its computer didn't answer. It is still on <current>.,<person>'s Buddy now runs on <model>, served by your <machine>./…on your saved API.,<model> hit a limit, so your Buddy is back on your subscription.,Nobody serves <model> now, so your Buddy is back on your subscription. - Fresh-session threshold: context tokens ≥ 80% of the target's context window. Unknown size or window: resume.
- Request lease: 10 minutes (
BUDDY_MODEL_LEASE_MS = 10 * 60_000). - Host capability name:
buddyModel. - Platforms: picker on Desktop (macOS/Linux/Windows), web, phone; switch on macOS and Linux hosts.
Review Focus
- A Buddy relaunched onto a grid model keeps every Buddy launch flag and gets no MCP server (the grid's web MCP) — the guard must hold on the grid. Test in Task 2.
- The way home after a fresh move resumes the earlier session, not the grid one, and the registry rebinds the agent to it rather than minting a new agent. Test in Task 3.
- A switch asked while the Buddy is mid-turn is refused with the reason, and the Buddy keeps running on its model. Test in Task 5.
- A model that is served when picked but gone when the host carries it out is refused, not half-applied. Test in Task 5.
- Someone other than the Buddy's owner (another member, the Swarm owner, the Buddy itself) cannot switch it, and a result for a stale request id is refused. Test in Task 1.
Task 1: Backend — buddy.model, the request, the result and its lines
Files:
- Modify:
backend/src/superTabs/model.ts(Agent:modelRequest?) - Modify:
backend/src/superTabs/commands.ts(schemas, handlers,BUDDY_MODEL_CAPABILITY) - Modify:
backend/src/superTabs/buddies.ts(BUDDY_COMMANDSgetsbuddy.modelResult; line texts) - Modify:
backend/src/superTabs/tidy.ts(expire a request past its lease) - Modify:
backend/src/superTabs/closedAgents.ts(stripmodelRequest) - Test:
backend/src/superTabs/buddyModel.test.ts
Interfaces:
Produces: command
{ type: 'buddy.model', gridModel: string | null }(null = the subscription); the grid is always the Swarm's (state.localModels.grid).Produces:
Agent.modelRequest?: { id: string; gridModel: string | null; requestedBy: string; at: string }.Produces: command
{ type: 'buddy.modelResult', agentId: string, requestId: string, ok: boolean, fresh?: boolean, contextWindow?: number, error?: string }(error ≤ 300 chars, control characters removed).Produces:
Agent.gridModelset on an ok result to a grid model, deleted on an ok result home.Step 1: Write the failing tests in
buddyModel.test.ts(state built asbuddies.test.tsbuilds a running Swarm Buddy on its owner's machine, the machine reportingcapabilities: [..., 'buddyModel']and servingdeepseek-4.1-flashon the Swarm grid from another member's machine):buddy.modelby the owner recordsmodelRequest { gridModel: 'deepseek-4.1-flash', requestedBy: owner }.- refused
BUDDY_MODEL_UNAVAILABLEfor a model no fresh reading serves on the Swarm grid, for akind: sharedmodel of another grid, and whenlocalModelsis off. - refused
BUDDY_OWNERfor another member and for the Swarm's owner; refusedBUDDY_FORBIDDENwhen sent by the Buddy agent itself. - refused
BUDDY_SWITCHINGwhile a request is pending;HOST_OUTDATEDwhen the machine lacksbuddyModel;BUDDY_MODEL_MACHINEwhen the Buddy runs on a Buddy-only machine;MACHINE_OFFLINEwhen its reading is stale;NO_BUDDYwith no running Buddy. buddy.modelResultfrom the Buddy agent with the pending id andoksetsgridModel, clearsmodelRequest, and writesYour Buddy now runs on DeepSeek 4.1 Flash, served by Ken's Mac Studio.in the owner's Buddy chat only; withfresh: true, contextWindow: 131072writes the fresh-session line with(128K); home with ok deletesgridModeland writesYour Buddy is back on your subscription.;ok: falsewrites the Couldn't-switch line and leavesgridModelas it was.buddy.modelResultwith another id →STALE_SWITCH; from another agent →BUDDY_FORBIDDEN/403.- tidy at
at + 10 minclears the request and writesCouldn't switch your Buddy: Your Buddy's computer didn't answer. It is still on your subscription.
Step 2: Run to see them fail Run:
cd backend && npm test -- src/superTabs/buddyModel.test.tsExpected: FAIL (unknown command typebuddy.model).Step 3: Implement the schemas next to
buddy.rename; the handler checks, in order: person actor, the main Swarm Buddy of the actor (mainBuddyOf), its machine listed and notbuddyOnly, fresh, capability, no pending request, and for a non-null modelservedLocalModels(state, now).some(l => l.model === gridModel). The result handler mirrorsagent.switchResult. Server names: the machines serving the model now (servedLocalModels), each by its name; anapireading by<person>'s saved API.Step 4: Run to see them pass — same command, Expected: PASS.
Step 5: Commit —
git commit -m "Swarm: a person asks to switch their Buddy's model; the server checks it and records the outcome (#2354)"
Task 1b: Backend — the contributor is told, and a Buddy comes home on a limit or a model gone
Files:
- Modify:
backend/src/superTabs/buddyModel.ts(modelRequest.reason, contributor lines,buddyModelHome) - Modify:
backend/src/superTabs/commands.ts(agent.alerton a Buddy on a grid model),backend/src/superTabs/tidy.ts(the sweep moves a Buddy whose model nobody served for 2 minutes) - Test:
backend/src/superTabs/buddyModel.test.ts
Interfaces:
Produces:
Agent.modelRequest.reason?: 'limit' | 'gone';Agent.gridModelUnservedSince?: number(ms; set by the sweep when the model first goes unserved, cleared when it is served again or the Buddy leaves it).Produces:
BUDDY_MODEL_GONE_MS = 2 * 60_000.Step 1: Failing tests:
- an ok result onto
deepseek-4.1-flash(served by owner's Mac Studio) also writes, in owner's Buddy chat,peer's Buddy now runs on DeepSeek 4.1 Flash, served by your Mac Studio.; onto owner's API,…on your saved API.; nothing for a model peer's own machine serves. agent.alert { alert: 'limit', active: true }from a Buddy on a grid model recordsmodelRequest { gridModel: null, reason: 'limit' }; its ok result writesDeepSeek 4.1 Flash hit a limit, so your Buddy is back on your subscription.; the same alert from a Buddy on its subscription records nothing; a request already pending is left as it is.- the sweep with the model unserved for under 2 minutes changes nothing; at 2 minutes records
reason: 'gone', whose result line isNobody serves DeepSeek 4.1 Flash now, so your Buddy is back on your subscription.; served again before then clears the mark.
- an ok result onto
Step 2: Run
cd backend && npm test -- src/superTabs/buddyModel.test.ts— FAIL.Step 3: Implement.
Step 4: Run — PASS.
Step 5: Commit —
Swarm: the member serving a Buddy's model is told, and the Buddy comes home on a limit or when nobody serves it (#2354)
Task 2: CLI — a Buddy's grid launch carries no MCP server
Files:
- Modify:
cli/src/lib/launchOverrides.ts(where the grid launch is built for a source) - Test:
cli/src/lib/launchOverrides.spec.ts
Interfaces:
Consumes:
LaunchSource.swarmSkill.role === 'buddy',GridLaunchOverride.mcpUrl.Step 1: Failing test
a Buddy moved onto a grid gets no web MCP and keeps its Buddy launch: build overrides for a Buddy source with a grid override carryingmcpUrl; assertextraArgshas no--mcp-configand no allow-web argument,envhas no grid web key variable, and the Buddy's own args (permission mode, settings) are present as in the same source without a grid. A non-Buddy source with the same grid still gets--mcp-config.Step 2: Run
cd cli && node --test --import tsx src/lib/launchOverrides.spec.ts— Expected: FAIL.Step 3: Implement: for a Buddy source the grid override is used without
mcpUrl.Step 4: Run — Expected: PASS.
Step 5: Commit —
fix(cli): a Buddy on a grid model starts no MCP server, as on its own login (#2354)
Task 3: Daemon — agent_retarget can start fresh, and the way home reopens the session it left
Files:
- Modify:
cli/src/backendSocket.ts(agent_retarget:fresh: trueaccepted with a grid target only) - Modify:
cli/src/core/agents/retarget.ts(retargetAgent({ agentId, grid, fresh })) - Modify:
cli/src/lib/registry.ts(subscriptionSessionId,setSubscriptionSession(agentId, id | null)) - Test:
cli/src/core/agents/retarget.spec.ts,cli/src/backendSocket.spec.ts
Interfaces:
Produces: frame
agent_retarget { agentId, gridModel, gridName, fresh?: true };freshwithclearGrid→INVALID_GRID.Produces:
RegisteredSession.subscriptionSessionId?: string.Step 1: Failing tests (retarget.spec.ts, with its existing fake pane/restart deps):
a fresh move onto a grid relaunches without --resume and keeps the session it left:restartAgentreceives an empty session id; after successregistry.setSubscriptionSession(agentId, 'S1').the move home reopens the session a fresh move left: a row on a grid withsubscriptionSessionId: 'S1'andsessionId: 'S2'; clearGrid relaunches with--resume S1; after success the remembered session is cleared.a grid-to-grid move keeps the remembered session;a refused move leaves it unchanged.- backendSocket.spec:
freshwithclearGrid→INVALID_GRID;freshis passed through toonRetargetAgent.
Step 2: Run
cd cli && node --test --import tsx src/core/agents/retarget.spec.ts src/backendSocket.spec.ts— FAIL.Step 3: Implement:
freshonly when leaving the own login records the old id (a grid-to-grid fresh move keeps the earlier remembered one); home with a remembered id passes it as the session to resume.Step 4: Run — PASS. Also run
cd cli && npm run test:core.Step 5: Commit —
feat(cli): a model switch can start a fresh session and the way home reopens the earlier one (#2354)
Task 4: CLI — how long a Claude Code conversation is now
Files:
- Create:
cli/src/lib/conversationSize.ts - Test:
cli/src/lib/conversationSize.spec.ts
Interfaces:
Produces:
conversationTokens(transcriptPath: string): Promise<number | null>— the newest assistant entry'susage.input_tokens + cache_read_input_tokens + cache_creation_input_tokens + output_tokens, read from at most the last 256 KB; null when none is found or the file is unreadable.Step 1: Failing tests: a transcript whose last assistant usage sums to 150 000 → 150000; a later user entry after it does not change it; a 1 MB transcript whose newest usage is in the last 256 KB → found; none → null; a missing file → null.
Step 2: Run
cd cli && node --test --import tsx src/lib/conversationSize.spec.ts— FAIL.Step 3: Implement with a bounded read from the end (
open+readatsize - 256 KB), lines parsed newest first.Step 4: Run — PASS.
Step 5: Commit —
feat(cli): read how long a Claude Code conversation is from its transcript's tail (#2354)
Task 5: CLI host — carry out a Buddy's model request
Files:
- Create:
cli/src/superTabs/buddyModel.ts - Modify:
cli/src/superTabs/host.ts(serve Buddy rows),cli/src/superTabs/machines.ts(CAPABILITIES.push('buddyModel')) - Test:
cli/src/superTabs/buddyModel.spec.ts
Interfaces:
Consumes: Task 3's frame, Task 4's
conversationTokens, Task 1's commands.Produces:
class BuddyModelRequests { serve(row: BuddyModelRow): Promise<void> }, with deps{ open, post, now, log, sessions(buddyAgentId): RegisteredSession[] }; the done-ids record under<dataDir>/super-tabs/buddy-model/.Step 1: Failing tests (fake daemon answering
agent_retarget, fake post):- a request to
deepseek-4.1-flashwith the target window 131072 and a 40 000-token conversation → oneagent_retarget { gridModel, gridName: <swarm grid>, }withoutfresh, thenbuddy.modelResult { ok: true }. - a 120 000-token conversation →
fresh: true, result{ ok: true, fresh: true, contextWindow: 131072 }. - unknown window or unreadable transcript → no
fresh. - home →
agent_retarget { clearGrid: true }. - a thread session of the same Buddy is moved too; one that fails is named in the result's error, the main move stands.
- the daemon answers
AGENT_BUSY→ result{ ok: false, error: 'Your Buddy is answering. Try again when it has finished' }. GRID_UNAVAILABLE→{ ok: false, error: "<servers> isn't serving <model> now" }.- the same request id seen again (and after a restart, from the record) → no second retarget.
- a request to
Step 2: Run
cd cli && node --test --import tsx src/superTabs/buddyModel.spec.ts— FAIL.Step 3: Implement; the target's context window comes from the request's reading (server adds
contextWindowtomodelRequestfrom the serving reading) — add it to Task 1's request if missing.Step 4: Run — PASS; then
cd cli && npm run test:orchestrator(host coverage gate).Step 5: Commit —
feat(cli): a Buddy's machine switches its model when its owner asks (#2354)
Task 6: Backend — a new thread session starts on the Buddy's model
Files:
Modify:
backend/src/superTabs/commands.ts(message.sendwithnewSession)Test:
backend/src/superTabs/buddyModel.test.tsStep 1: Failing test: with the main Buddy on
gridModel: 'deepseek-4.1-flash', a new thread session's start request carriesgridModelandgridName= the Swarm grid and nomodel/effort; with the model no longer served it starts on the subscription.Step 2: Run
cd backend && npm test -- src/superTabs/buddyModel.test.ts— FAIL.Step 3: Implement where the thread session's request copies the main Buddy's engine.
Step 4: Run — PASS.
Step 5: Commit —
Swarm: a Buddy's new thread session starts on the model its owner chose (#2354)
Task 7: Desktop/web/phone — the picker in the Buddy bar
Files:
- Create:
desktop/lib/super_tabs/buddy_model.dart(offers + picker widget) - Modify:
desktop/lib/super_tabs/buddies.dart(SuperTabBuddyBar),desktop/lib/super_tabs/controller.dart(switchBuddyModel(String? gridModel)),desktop/lib/super_tabs/model.dart(SuperTabAgent.gridModel,modelRequest) - Test:
desktop/test/super_tab_buddy_model_test.dart
Interfaces:
Produces:
List<BuddyModelOffer> buddyModelOffers(SuperTabSnapshot snapshot, {required DateTime now})whereBuddyModelOffer = ({String model, String name, List<String> servedBy, bool api}), fromsuperTabLocalModelRowsrows on the Swarm grid, grouped by model;servedByis machine names forlocal, and<person>'s saved APIforapi.Step 1: Failing widget tests (memory store, fake sign-in, snapshot fixture as
super_tab_buddies_test.dart):- the bar shows
Your subscription ▾ · Claude Code on <machine> · …; opening it listsYour subscriptionchecked,SHARED IN THIS SWARM,DeepSeek 4.1 Flash served by Ken's Mac Studio, a two-machine model naming both, an API asDiego's saved API, and the footer line. - a
kind: sharedmodel, a stale reading and a starting model are not listed. - picking a model sends
buddy.model { gridModel }; pickingYour subscriptionsendsgridModel: null. - with
modelRequestpending the bar readsSwitching to DeepSeek 4.1 Flash…and the picker is disabled. - on
gridModelno longer served the bar readsDeepSeek 4.1 Flash ▾ · not served now. - on a Buddy-only machine the menu shows
Add <machine> to the Swarm's Machines to use shared modelsand no models. - phone width: the menu opens as a sheet with finger-size rows.
- the bar shows
Step 2: Run
cd desktop && flutter test test/super_tab_buddy_model_test.dart— FAIL.Step 3: Implement in the design language (DesktopChrome metadata/control styles, the shared menu anchor the ⋮ menu uses; phone sheet as other phone menus).
Step 4: Run — PASS; then
flutter analyze,scripts/check-ui-styleandtest/laid_out_list_test.dart(Desktop guard tests before Ready).Step 5: Commit —
Desktop: a model picker in the Buddy bar names who serves each model (#2354); screenshots committed for the PR and removed in the next commit.
Task 8: Docs
Files:
Modify:
docs/swarms.md(Buddies: a paragraph on switching the model, who serves it, fresh sessions, the guard on a grid)Step 1: Write the paragraph; Step 2: commit
Docs: a Buddy's model switch (#2354).
Before Ready
-
cd backend && npm test(unit),npm run test:integration— the full Super Tab integration suite. -
cd cli && npm run test:core && npm run test:orchestratorand the changed specs. - Desktop changed tests + guard tests on this Mac.
- Red/green evidence comment on the PR, one line per risk with the failing and passing commit.
- Review steps: two security reviews (Buddy guard and privacy), and a test step on a Mac (Desktop) with a shared grid model: switch mid-conversation, keep chatting, switch back.