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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Backend: a New Harness joins with its custom role (#1667)
0xken15c1432776fffd
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex bcc531017..417dbd808 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -1372,8 +1372,8 @@ describe('Super Tabs on a real Mongo replica set', () => {const rowOf = async (id: string) => (await rows()).find(r => r.agent.id === id)!expect(await rowOf(worker)).not.toHaveProperty('role')await run(tab, { type: 'project.skills', projectId: 'lead', mode: 'custom' })- expect(await rowOf(lead)).toMatchObject({ skillMode: 'default', role: { id: 'lead', name: 'Product Manager', kind: 'lead', version: version('LEAD-TEXT') } })- expect(await rowOf(worker)).toMatchObject({ skillMode: 'default', role: { id: 'dev', name: 'Engineer', kind: 'builder', version: version('DEV-TEXT') } })+ expect(await rowOf(lead)).toMatchObject({ skillMode: 'default', role: { id: 'lead', name: 'Product Manager', kind: 'lead', version: version('LEAD-TEXT'), projectId: 'lead' } })+ expect(await rowOf(worker)).toMatchObject({ skillMode: 'default', role: { id: 'dev', name: 'Engineer', kind: 'builder', version: version('DEV-TEXT'), projectId: 'lead' } })const stored = JSON.stringify((await db.superTab.findUniqueOrThrow({ where: { id: tab } })).state)for (const text of [JSON.stringify(await rows()), stored, JSON.stringify((await store.read(owner, tab)).state)]) expect(text).not.toMatch(/LEAD-TEXT|DEV-TEXT/)@@ -1399,7 +1399,7 @@ describe('Super Tabs on a real Mongo replica set', () => {expect((await text(host, 'dev')).statusCode).toBe(200)await run(tab, { type: 'project.role.set', projectId: 'lead', role: { ...roles[1]!, text: 'DEV-TEXT v2' } })- expect((await rowOf(worker)).role).toMatchObject({ id: 'dev', version: version('DEV-TEXT v2') })+ expect((await rowOf(worker)).role).toMatchObject({ id: 'dev', version: version('DEV-TEXT v2'), projectId: 'lead' })expect((await text(owner, 'dev')).json().data).toEqual({ version: version('DEV-TEXT v2'), text: 'DEV-TEXT v2' })await run(tab, { type: 'project.role.remove', projectId: 'lead', roleId: 'review' })expect((await text(owner, 'review')).statusCode).toBe(404)diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 52dd62419..1277c3218 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -87,7 +87,7 @@ export const commandSchema = z.discriminatedUnion('type', [.refine(c => !c.task || renderWorkTask(c.task).length <= 8000, 'Keep the rendered task within 8,000 characters.'),z.object({ type: z.literal('conversation.rename'), conversationId: id, title }).strict(),z.object({ type: z.literal('conversation.archive'), conversationId: id, archived: z.boolean() }).strict(),- z.object({ type: z.literal('agent.add'), conversationId: id, machineId: id, harnessId: id, name: title, configuration, lead: z.boolean(), project: project.optional(), initialMessage: text.optional() }).strict(),+ z.object({ type: z.literal('agent.add'), conversationId: id, machineId: id, harnessId: id, name: title, configuration, lead: z.boolean(), project: project.optional(), roleId: roleId.optional(), initialMessage: text.optional() }).strict(),z.object({ type: z.literal('agent.start'), request: startRequestSchema, routeDecisionId: id.optional(), overrideReason: reason.optional() }).strict(),z.object({ type: z.literal('agent.startDispatch'), startId: id }).strict(),z.object({ type: z.literal('agent.started'), startId: id, harnessId: id, configuration,@@ -837,6 +837,12 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaconst agentId = stableId(command.machineId, command.harnessId)const existing = state.agents.find(a => a.id === agentId)if (existing) sameProject(state, group, existing)+ // A New Harness chooses its role here: a reviewer role joins it as a Reviewer, a builder role as an Engineer,+ // and a lead role only as the Lead. Later changes go through work.assign. An agent already in the Swarm keeps+ // the kind it runs, so a retry is checked against that.+ const roleKind = command.roleId ? project.roles?.find(r => r.id === command.roleId)?.kind : undefined+ const kind = existing ? agentKind(state, existing) : command.lead ? 'lead' : roleKind === 'reviewer' ? 'reviewer' : 'builder'+ const chosen = command.roleId ? chosenRole(project, command.roleId, kind) : nullif (existing?.workDecision === 'stop' && command.lead) fail('STOP_REQUESTED', 'This worker is stopping. Wait for its execution host.')if (existing && agentRole(existing) === 'reviewer' && command.lead) fail('REVIEWER_NOT_LEAD', 'A Reviewer reviews work and cannot lead a group.')if (!existing) reserveHarnessSlot(state, command.machineId, command.harnessId, operationId)@@ -846,7 +852,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma...(state.projects ? { projectId: project.id } : {}),machineOwnerId: grant.machineOwnerId, contributorId: grant.contributorId, membershipGeneration: contributor.generation,hostGrant: grant.hostGrant ?? null,- name: command.name, configuration: command.configuration, configurationVersion: operationId })+ name: command.name, configuration: command.configuration, configurationVersion: operationId,+ ...(chosen?.kind === 'reviewer' ? { role: 'reviewer' as const } : {}), ...(chosen ? { roleId: chosen.id } : {}) })if (existing && (existing.machineOwnerId !== grant.machineOwnerId || existing.contributorId !== grant.contributorId)) {fail('ALREADY_SHARED', 'This session already has a contributor. Use the existing tab agent.')}diff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.tsindex 6d47963db..2cec74d15 100644--- a/backend/src/superTabs/projects.test.ts+++ b/backend/src/superTabs/projects.test.ts@@ -1,6 +1,6 @@import { createHash } from 'node:crypto'import { describe, expect, it } from 'vitest'-import { applyCommand, type Command, type CommandContext } from './commands.js'+import { applyCommand, commandSchema, type Command, type CommandContext } from './commands.js'import { createSuperTab, visibleState, type Actor, type MessageDraft } from './model.js'import { canReadAgent, projectOf, projectsOf, readConversation, skillModeOf, skillSetOf } from './projects.js'@@ -460,6 +460,29 @@ describe('custom role sets', () => {expect(() => f.run({ type: 'agent.start', request: request(plain.conversationId, { roleId: 'dev' }) } as Command)).toThrow('not in this project')})+ it('joins an agent with the role the New Harness form sends, and a reviewer role makes it a Reviewer', () => {+ const { f, p } = custom()+ let harness = 0+ /** Exactly what Desktop's New Harness form sends (PR #1659): lead, the chosen role id, its configuration. */+ const add = (lead: boolean, roleId?: string) => commandSchema.parse({ type: 'agent.add', conversationId: p.conversationId,+ machineId: 'machine', harnessId: `added-${++harness}`, name: lead ? 'Lead' : 'Added', lead, ...(roleId ? { roleId } : {}), configuration })+ const added = (agentId: string) => f.state.agents.find(a => a.id === agentId)!+ const engineer = added(String(f.run(add(false, 'dev')).agentId))+ expect(engineer).toMatchObject({ roleId: 'dev' })+ expect(engineer).not.toHaveProperty('role')+ expect(added(String(f.run(add(false, 'review')).agentId))).toMatchObject({ roleId: 'review', role: 'reviewer' })+ const lead = added(String(f.run(add(true, 'lead')).agentId))+ expect(lead).toMatchObject({ roleId: 'lead' })+ expect(lead).not.toHaveProperty('role')+ expect(added(String(f.run(add(false)).agentId))).not.toHaveProperty('roleId')+ // A lead role joins only as the Lead, a lead cannot take a builder or reviewer role, and unknown ids are refused.+ for (const [isLead, roleId, why] of [[false, 'lead', 'kind'], [true, 'dev', 'kind'], [true, 'review', 'kind'],+ [false, 'eeeeeeeeeeee', 'not in this project']] as const) expect(() => f.run(add(isLead, roleId))).toThrow(why)+ const plain = f.project('public', peer)+ expect(() => f.run(commandSchema.parse({ type: 'agent.add', conversationId: plain.conversationId, machineId: 'machine',+ harnessId: 'plain', name: 'Plain', configuration, lead: false, roleId: 'dev' }))).toThrow('not in this project')+ })+it('tells agents whose kind has no role in the new set, then gives them no new work, and refuses review groups without a reviewer role', () => {const { f, p } = custom([role('lead', 'Product Manager', 'lead'), role('dev', 'Engineer', 'builder')])const lead = f.add(p.conversationId, 'app-lead')diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 0cb617be1..e423fa684 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -1053,7 +1053,10 @@ export class SuperTabStore {const home = projectsOf(state).find(p => p.id === agentProjectId(state, target))const skillMode = home ? skillModeOf(home) : 'orchestration'// On Custom, the role it runs and its text's version, never the text (roleText); null when its kind has no role there.- const role = home && skillSetOf(home) === 'custom' ? { role: agentSetRole(state, home, target) } : {}+ // The project lets the host fetch that text (roleText).+ const custom = home && skillSetOf(home) === 'custom' ? home : null+ const chosen = custom ? agentSetRole(state, custom, target) : null+ const role = custom ? { role: chosen && { ...chosen, projectId: custom.id } } : {}result.push({ tabId: row.id, tabName: state.name, revision: row.revision, paused: state.paused, active, attention, agent: target, joinSwarm, skillMode, ...role,lead: !!ledProject(state, target.id),stopRequested: target.workDecision === 'stop' && !state.conversations.some(c => activeWork(c) && c.assignment?.agentId === target.id),