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
fix(swarms): share lead repository so other machines can start agents
tony0d879f643033
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 6a7c52d19..a61923dc5 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -477,4 +477,7 @@ it('restricts recording a legacy project to the owner or controlling lead', () =})it('rejects embedded credentials in shared project metadata', () => {expect(commandSchema.safeParse({ type: 'tab.project', machineId: 'host', project: { cwd: '/repo', repositoryUrl: 'https://[email protected]/example/project' } }).success).toBe(false)+ expect(commandSchema.safeParse({ type: 'project.repository', projectId: 'lead', repositoryUrl: 'https://[email protected]/example/project' }).success).toBe(false)+ expect(commandSchema.safeParse({ type: 'project.repository', projectId: 'lead', repositoryUrl: 'github.com/example/project' }).success).toBe(false)+ expect(commandSchema.safeParse({ type: 'project.repository', projectId: 'lead', repositoryUrl: null }).success).toBe(false)})diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 4b74ed63c..813cf2ba7 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -18,7 +18,7 @@ const configuration = z.object({engineVersion: z.string().max(160).nullable(),}).strict()const path = z.string().min(1).max(4096).regex(/^\//).refine(value => !/[\x00-\x1f\x7f]/.test(value))-const project = z.object({ cwd: path, repositoryUrl: z.string().max(4096).refine(value => {+const repositoryUrl = z.string().max(4096).refine(value => {if (/[\x00-\x20\x7f]/.test(value)) return falseif (/^git@[^/@:]+:[^@]+$/.test(value)) return truetry {@@ -26,7 +26,8 @@ const project = z.object({ cwd: path, repositoryUrl: z.string().max(4096).refinereturn ['https:', 'http:', 'ssh:', 'git:'].includes(uri.protocol) && !!uri.hostname && !uri.password &&(!uri.username || (uri.protocol === 'ssh:' && uri.username === 'git'))} catch { return false }-}, 'Share a repository URL without credentials.').nullable() }).strict()+}, 'Share a repository URL without credentials.')+const project = z.object({ cwd: path, repositoryUrl: repositoryUrl.nullable() }).strict()export const startRequestSchema = z.object({conversationId: id, machineId: id, engine: z.string().min(1).max(80), name: title, cwd: path,worktree: z.boolean(), branchRef: z.string().max(1024).regex(/^refs\/(heads|remotes)\/[^\s\x00-\x1f\x7f]+$/).optional(),@@ -52,6 +53,7 @@ export const commandSchema = z.discriminatedUnion('type', [z.object({ type: z.literal('project.sharing'), projectId: id, visibility: z.enum(['public', 'private']), memberIds: z.array(id).max(200) }).strict(),z.object({ type: z.literal('project.cadence'), projectId: id, minutes: z.union([z.literal(1), z.literal(5), z.literal(15), z.literal(30)]) }).strict(),z.object({ type: z.literal('project.report'), projectId: id, throughRevision: z.number().int().nonnegative().safe(), text: text.nullable() }).strict(),+ z.object({ type: z.literal('project.repository'), projectId: id, repositoryUrl }).strict(),z.object({ type: z.literal('conversation.create'), projectId: id.optional(), title, brief: z.string().trim().max(8000), checks: z.array(check).max(40) }).strict(),z.object({ type: z.literal('conversation.rename'), conversationId: id, title }).strict(),z.object({ type: z.literal('conversation.archive'), conversationId: id, archived: z.boolean() }).strict(),@@ -212,6 +214,23 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaif (command.text) message(group.id, command.text, [], null, { kind: 'project-report' })break}+ case 'project.repository': {+ // Desktop once dropped the daemon's scheme-less remote, so some leads recorded a folder without an address and+ // other machines could not clone it. Its owner or lead fills it in; an address already shared is never replaced.+ const project = readProject(state, actor, command.projectId)+ author(state, actor, true)+ const group = conversation(state, project.leadConversationId)+ if (!(actor.kind === 'person' && actor.userId === project.ownerId) && !(actor.kind === 'agent' && group.leadId === actor.agentId)) {+ fail('PROJECT_OWNER_REQUIRED', 'Only the project owner or its lead can share its repository.', 403)+ }+ // On a tab from before projects this is `state.project` itself (projectsOf).+ const repository = project.repository ?? fail('PROJECT_FOLDER_REQUIRED', 'Start this project’s lead in its repository first.')+ if (repository.repositoryUrl && repository.repositoryUrl !== command.repositoryUrl) {+ fail('PROJECT_REPOSITORY_SET', 'This project already shares another repository.')+ }+ repository.repositoryUrl = command.repositoryUrl+ break+ }case 'project.create': {if (actor.kind !== 'person') fail('HUMAN_REQUIRED', 'A person creates a project and chooses its lead.', 403)if (state.paused) fail('PAUSED', 'New work is paused in this swarm.')diff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.tsindex 0038a2646..c8075207a 100644--- a/backend/src/superTabs/projects.test.ts+++ b/backend/src/superTabs/projects.test.ts@@ -190,6 +190,33 @@ describe('projects inside an invite-only swarm', () => {expect(() => f.run({ type: 'agent.started', startId, harnessId: 'late', configuration })).toThrow('unavailable')})+ it('lets the owner or lead share a missing repository address once, without replacing it', () => {+ const f = setup(), p = f.project('public'), url = 'https://github.com/example/project'+ const share = (repositoryUrl: string): Command => ({ type: 'project.repository', projectId: p.projectId, repositoryUrl })+ expect(() => f.run(share(url))).toThrow('lead in its repository')+ // What Desktop recorded while it dropped the daemon's scheme-less remote.+ f.run({ type: 'agent.add', conversationId: p.conversationId, harnessId: 'lead', machineId: 'machine', name: 'Lead', configuration,+ lead: true, project: { cwd: '/work/project', repositoryUrl: null } })+ const lead: Actor = { kind: 'agent', agentId: f.state.agents[0]!.id, machineOwnerId: 'host' }+ const worker: Actor = { kind: 'agent', agentId: f.add(p.conversationId, 'worker', false), machineOwnerId: 'host' }+ expect(() => f.run(share(url), peer)).toThrow('Only the project owner or its lead')+ expect(() => f.run(share(url), worker)).toThrow('Only the project owner or its lead')+ f.run(share(url), lead)+ const repository = () => projectsOf(f.state).find(item => item.id === p.projectId)!.repository+ expect(repository()).toEqual({ machineId: 'machine', cwd: '/work/project', repositoryUrl: url })+ f.run(share(url))+ expect(() => f.run(share('https://github.com/example/another'))).toThrow('already shares another repository')+ expect(repository()!.repositoryUrl).toBe(url)+ })++ it('shares a missing repository address on a tab from before projects', () => {+ const f = setup(), url = '[email protected]:example/project.git'+ f.state.project = { machineId: 'machine', cwd: '/old', repositoryUrl: null }+ f.run({ type: 'project.repository', projectId: 'lead', repositoryUrl: url })+ expect(f.state.project).toEqual({ machineId: 'machine', cwd: '/old', repositoryUrl: url })+ expect(projectsOf(f.state)[0]!.repository).toEqual(f.state.project)+ })+it('keeps active work visible after its contributed agent is removed', () => {const f = setup(), p = f.project(), agentId = f.add(p.conversationId, 'worker')f.run({ type: 'work.define', conversationId: p.conversationId, brief: 'Finish the task',diff --git a/cli/src/superTabs/projectFolder.spec.ts b/cli/src/superTabs/projectFolder.spec.tsindex 525e9a92d..8431abe1d 100644--- a/cli/src/superTabs/projectFolder.spec.ts+++ b/cli/src/superTabs/projectFolder.spec.ts@@ -47,6 +47,12 @@ describe('per-project checkouts on a contributed swarm machine', () => {f.start.request.conversationId = 'unknown'await expect(f.run()).rejects.toThrow('no authorized project')})+ it('tells the lead how to share a project recorded without a repository address', async () => {+ const f = fixture()+ f.repository.repositoryUrl = null as unknown as string+ await expect(f.run()).rejects.toThrow(/Share a GitHub repository.*project\.repository command/)+ expect(f.prepare).not.toHaveBeenCalled()+ })it('refuses missing or unsafe repositories and a mismatched prepared checkout', async () => {const f = fixture()for (const url of [undefined, 'file:///private/repo', 'https://[email protected]/example/project', 'ext::command']) {diff --git a/cli/src/superTabs/projectFolder.ts b/cli/src/superTabs/projectFolder.tsindex ed251ea90..4d2465436 100644--- a/cli/src/superTabs/projectFolder.ts+++ b/cli/src/superTabs/projectFolder.ts@@ -27,7 +27,8 @@ export async function prepareSwarmProject(core: CoreApi, row: Json, start: Json,if (repository.machineId === core.daemon.machineId() && sameFolder(request.cwd, repository.cwd)) returnconst expected = join(expectedRoot, project.id)if (!sameFolder(request.cwd, expected)) throw new Error('The requested folder is outside this project.')- if (typeof repository.repositoryUrl !== 'string') throw new Error('Share a GitHub repository for this project before starting agents on another machine.')+ // The Lead reads this from the failed start; it can record its checkout's origin and start again.+ if (typeof repository.repositoryUrl !== 'string') throw new Error('Share a GitHub repository for this project before starting agents on another machine. Its lead can share its checkout\'s GitHub origin with the project.repository command, then start again.')const source = parseProjectFolder({ projectSource: 'remote', repositoryUrl: repository.repositoryUrl })if (source?.source !== 'remote') throw new Error('This project repository is unavailable.')const cwd = await prepare({ ...source, name: project.id }, { root: expectedRoot })diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.tsindex 73101099e..96b44757b 100644--- a/cli/src/superTabs/service.spec.ts+++ b/cli/src/superTabs/service.spec.ts@@ -51,6 +51,11 @@ it('limits the owner proxy to Super Tab endpoints and preserves backend failuresvi.mocked(t.core.account.backend).mockResolvedValueOnce({ status: 403, body: { success: false, error: { code: 'FORBIDDEN', message: 'Access withdrawn' } } })expect(await t.ask({ action: 'backend', method: 'GET', path: '/api/super-tabs/tab' }, owner)).toEqual({ error: 'FORBIDDEN', detail: 'Access withdrawn', status: 403 })})+it('documents how a lead shares its project repository for other machines', async () => {+ const t = setup()+ const answer = await t.ask({ action: 'help' }, owner) as { help: { commands: Array<Record<string, unknown>> } }+ expect(answer.help.commands).toContainEqual({ type: 'project.repository', projectId: 'PROJECT', repositoryUrl: 'https://github.com/OWNER/REPOSITORY' })+})it('resolves a native caller to its exact contribution and rechecks it before every agent command', async () => {const t = setup()expect(await t.ask({ action: 'status', tabId: 'tab', harnessId: 'native' }, owner)).toMatchObject({ ok: true })diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex 50c9efa62..a2d84253d 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -24,6 +24,7 @@ const HELP = {command: 'command OPERATION_ID JSON: send one of the commands below. Reuse exactly the same ID and JSON after an interrupted request.',commands: [{ type: 'project.report', projectId: 'PROJECT', throughRevision: 123, text: 'What changed, what is blocked, and what comes next. Use null when nothing merits repeating.' },+ { type: 'project.repository', projectId: 'PROJECT', repositoryUrl: 'https://github.com/OWNER/REPOSITORY' },{ type: 'message.send', conversationId: 'GROUP', text: 'A message addressed to an agent', replyTo: null, recipientIds: ['AGENT'] },{ type: 'conversation.create', title: 'Outcome', brief: 'An independently assignable result', checks: [{ description: 'Observable acceptance evidence', independent: false }] },{ type: 'conversation.agent', conversationId: 'GROUP', agentId: 'AGENT', present: true, lead: false },diff --git a/desktop/lib/super_tabs/model.dart b/desktop/lib/super_tabs/model.dartindex 63e4111b3..53e48916b 100644--- a/desktop/lib/super_tabs/model.dart+++ b/desktop/lib/super_tabs/model.dart@@ -265,11 +265,24 @@ class SuperTabMessage {bool get uncertain => deliveries.any((d) => d['status'] == 'uncertain');}+/// The `remote` a daemon reports for a project: `host/owner/repo`, already+/// without credentials or transport (the CLI's `canonicalRepository`). A port+/// there may be SSH's, so only a plain host is read as an HTTPS address.+final _canonicalRemote = RegExp(+ r'^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}/\S+$',+ caseSensitive: false,+);+/// A remote may contain a developer's embedded credential. Never share it.+/// Contributed machines clone this address, so a daemon's canonical remote+/// becomes the HTTPS URL that Harness's GitHub project source also clones.String? superTabRepositoryUrl(String? remote) {if (remote == null || remote.isEmpty) return null;if (remote.startsWith('git@') && !remote.contains('://')) return remote;- final uri = Uri.tryParse(remote);+ final address = _canonicalRemote.hasMatch(remote)+ ? 'https://$remote'+ : remote;+ final uri = Uri.tryParse(address);if (uri == null ||uri.host.isEmpty ||!['https', 'http', 'ssh', 'git'].contains(uri.scheme)) {@@ -279,5 +292,5 @@ String? superTabRepositoryUrl(String? remote) {!(uri.scheme == 'ssh' && uri.userInfo == 'git')) {return null;}- return remote;+ return address;}diff --git a/desktop/test/super_tab_launch_test.dart b/desktop/test/super_tab_launch_test.dartindex 7c1a2f879..2e1ac413e 100644--- a/desktop/test/super_tab_launch_test.dart+++ b/desktop/test/super_tab_launch_test.dart@@ -48,6 +48,10 @@ class SuperTabFixtureConnection extends WsConn {static const streamId = '00112233-4455-6677-8899-aabbccddeeff';Map<String, dynamic>? native;String nativeName = 'Lead';+ Map<String, dynamic> nativeProject = {+ 'cwd': '/work/project',+ 'label': 'Project',+ };bool cancelledCreation = false;Future<Map<String, dynamic>> Function(String, Map<String, dynamic>)?creationRecovery;@@ -272,7 +276,7 @@ class SuperTabFixtureConnection extends WsConn {'engine': payload['engine'],'closeSupported': true,'terminal': {'available': true},- 'project': {'cwd': '/work/project', 'label': 'Project'},+ 'project': nativeProject,};if (loseCreate) {loseCreate = false;@@ -729,6 +733,26 @@ void main() {);}+ test(+ 'a lead in a GitHub checkout shares its repository for other machines',+ () async {+ // The daemon's frame carries origin in its canonical form, without a scheme.+ final f = SuperTabLaunchFixture()+ ..connection.nativeProject = {+ 'name': 'project',+ 'cwd': '/work/project/mobile',+ 'root': '/work/project',+ 'remote': 'github.com/example/project',+ };+ final box = await f.box(engine: 'claude');+ expect(await box.create(), NewHarnessOutcome.created, reason: box.error);+ expect(f.connection.joins.single['command']['project'], {+ 'cwd': '/work/project',+ 'repositoryUrl': 'https://github.com/example/project',+ });+ },+ );+test('the lead prompt routes before starting or assigning work', () async {final f = SuperTabLaunchFixture()..connection.nativeName = 'hi';final box = await f.box(engine: 'claude');diff --git a/desktop/test/super_tab_machines_test.dart b/desktop/test/super_tab_machines_test.dartindex 16cbccf1d..d20d073b6 100644--- a/desktop/test/super_tab_machines_test.dart+++ b/desktop/test/super_tab_machines_test.dart@@ -69,6 +69,23 @@ void main() {'https://github.com/example/project',);});+ test('a daemon\'s canonical remote is shared as an HTTPS repository', () {+ // The CLI daemon reports `origin` as host/owner/repo, without a scheme.+ expect(+ superTabRepositoryUrl('github.com/autonomous-ai/openharness'),+ 'https://github.com/autonomous-ai/openharness',+ );+ expect(+ superTabRepositoryUrl('gitlab.example.co.uk/team/group/project'),+ 'https://gitlab.example.co.uk/team/group/project',+ );+ // A canonical port may be SSH's; it is not guessed as HTTPS.+ expect(superTabRepositoryUrl('git.example.com:2222/team/project'), isNull);+ // Local and relative remotes are not shareable repositories.+ expect(superTabRepositoryUrl('../project'), isNull);+ expect(superTabRepositoryUrl('/Users/me/project.git'), isNull);+ expect(superTabRepositoryUrl('github.com'), isNull);+ });testWidgets('Add machine has one field and contributes the prepared project and installed engines',(tester) async {diff --git a/docs/swarms.md b/docs/swarms.mdindex 15a8d056e..a01e06922 100644--- a/docs/swarms.md+++ b/docs/swarms.md@@ -40,7 +40,10 @@ Each section's plus button has one purpose:A machine contribution is a workspace grant for this Swarm. The host prepareseach project's repository before starting an agent. A project on anothermachine needs a shared GitHub repository; a local-only folder is not silently-replaced with an unrelated directory.+replaced with an unrelated directory. The project records its lead checkout's+GitHub `origin` as an HTTPS address when the lead starts. If a project has no+address yet, its owner or lead can share one once with `project.repository`.+An address that is already shared is not replaced.Ordinary guest machine sharing does not authorize Swarm controls under theowner's account. The owner contributes the machine or an agent. The lead's