From 297c150cad6f6410e7cb1d8a66e434ed5c9ea8bb Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Mon, 16 Nov 2026 15:27:08 +0100 Subject: [PATCH] feat(mcp): let agents create tasks in other projects Global setting, off by default. create_task with relation 'independent' takes an optional project, by id or by name ignoring case; an unknown or ambiguous name lists the projects. Each task in another project asks the user first in a native dialog that shows both projects, the task and its prompt, with Deny as the default, one dialog at a time. The call waits for the answer, and rechecks the setting, pause, orchestration and session after it. The task is otherwise an ordinary independent task of the target project: the creator's agent, sandbox and permission propagation, its main branch, and the creator's independent-task cap. Children stay in the creator's project. Co-Authored-By: Claude Opus 5.5 --- docs/design-doc.md | 2 + electron/ipc/mcp-runtime.ts | 7 + electron/ipc/register.ts | 21 +++ electron/mcp/cross-project-tasks.ts | 45 ++++++ electron/mcp/delegation.test.ts | 160 ++++++++++++++++++++ electron/mcp/delegation.ts | 85 ++++++++++- electron/mcp/mcp-tool-list.ts | 9 ++ electron/shared/delegation-types.ts | 3 + src/components/settings/AgentSettings.tsx | 26 ++++ src/store/autosave.ts | 1 + src/store/core.ts | 1 + src/store/delegation.ts | 5 + src/store/persistence.test.ts | 20 +++ src/store/persistence.ts | 7 + src/store/remoteTaskHandler.client.test.tsx | 68 +++++++++ src/store/remoteTaskHandler.ts | 10 +- src/store/store.ts | 6 +- src/store/types.ts | 3 + 18 files changed, 473 insertions(+), 6 deletions(-) create mode 100644 electron/mcp/cross-project-tasks.ts diff --git a/docs/design-doc.md b/docs/design-doc.md index c9a23d872..b52f1f971 100644 --- a/docs/design-doc.md +++ b/docs/design-doc.md @@ -101,6 +101,8 @@ In V2, **Allow peer access between tasks** defaults off and explicitly enables d **Allow agents to read tasks in other projects** (Settings > Agents, global, defaults off) adds read-only access across projects: discovery (`list_agent_sessions`), output (`get_agent_output`) and diffs (`get_task_diff`) of top-level worktree tasks in other projects, from top-level worktree tasks only. Children stay limited to their parent; page agents, shells and checkout-mode tasks stay excluded on both sides. `send_agent_prompt` and every other write or prompt path stay within the project and refuse other projects with a read-only error. Discovery needs only the setting. The first output or diff read of another project asks the user to allow or deny it, once per agent session (launch instance) and project, in a native dialog with Deny as the default. Reads fail at once while the dialog is pending or after a denial, and agents never wait on it. A denied project also drops out of that session's discovery. Turning the setting off revokes every approval and ignores answers to dialogs still open. Peer results (sessions, output and diffs) carry `projectId` and `projectName`, and sessions in other projects are marked `readOnly`. The renderer sends the setting with `crossProjectReadSetting`, and project names with each project policy, before restoring task authority. +**Allow agents to create tasks in other projects** (Settings > Agents, global, defaults off) is the one cross-project write. `create_task` with relation `independent` takes an optional `project`, an id or a name matched without case (an unknown or ambiguous name answers with the list of projects), from any session that may create independent tasks. Naming the creator's own project is an ordinary independent task. Any other project asks the user before each task, in a native dialog naming both projects, the task and its prompt, with Deny as the default; dialogs show one at a time. Unlike reads, the call waits for the answer, since the agent needs the result and the user is approving that exact task. The setting, pause, orchestration and session checks run again before the dialog opens and after the user answers, so switching any of them off meanwhile refuses the task. The created task is an independent task of the target project in every other respect: it starts from that project's main branch, uses the creator's agent, sandbox and permission propagation, counts against the creator's independent-task cap, and the user reviews it. Children (`relation: 'child'`) stay in the creator's project. The renderer sends the setting with `crossProjectTaskSetting`, and lists projects for resolution through the same request the phone uses. + ### Exact V1 tool exposure and completion loop Use these named sets in `selectTools()` and capability-based dispatch. Tool discovery is not the security boundary: HTTP handlers enforce the same scope and current consent/policy, including calls to hidden or legacy handler names. diff --git a/electron/ipc/mcp-runtime.ts b/electron/ipc/mcp-runtime.ts index be25083e2..d6684edb2 100644 --- a/electron/ipc/mcp-runtime.ts +++ b/electron/ipc/mcp-runtime.ts @@ -14,6 +14,7 @@ import { } from './remote-transport.js'; import { DelegationService } from '../mcp/delegation.js'; import type { CrossProjectReadRequest } from '../mcp/cross-project-reads.js'; +import type { CrossProjectTaskRequest, TaskProject } from '../mcp/cross-project-tasks.js'; import type { Coordinator } from '../mcp/coordinator.js'; import { removeCanvasConfig } from '../mcp/canvas-config.js'; import { getMCPRemoteServerUrl } from '../mcp/config.js'; @@ -39,6 +40,10 @@ export interface McpRuntimeOptions { ) => Promise<{ taskId: string; resumedSessionId: string | null }>; /** Asks the user whether a session may read another project; true allows. */ confirmCrossProjectRead: (request: CrossProjectReadRequest) => Promise; + /** The projects that take tasks, as the renderer lists them. */ + listProjects: () => Promise; + /** Asks the user whether an agent may create a task in another project; true allows. */ + confirmCrossProjectTask: (request: CrossProjectTaskRequest) => Promise; } export interface McpRuntime { @@ -114,6 +119,8 @@ export function createMcpRuntime(opts: McpRuntimeOptions): McpRuntime { createIndependent: opts.createIndependentTask, importWorktree: opts.importWorktree, confirmCrossProjectRead: opts.confirmCrossProjectRead, + listProjects: opts.listProjects, + confirmCrossProjectTask: opts.confirmCrossProjectTask, }); async function prepareDelegationParent(task: TaskAuthorityInput): Promise { diff --git a/electron/ipc/register.ts b/electron/ipc/register.ts index 605e7b3c0..525296250 100644 --- a/electron/ipc/register.ts +++ b/electron/ipc/register.ts @@ -719,6 +719,27 @@ export function registerAllHandlers(win: BrowserWindow): void { }); return response === 0; }, + listProjects: async () => + ( + await callRenderer>(IPC.Remote_GetProjectsRequest, {}) + ).map(({ id, name }) => ({ id, name })), + confirmCrossProjectTask: async (request) => { + if (win.isDestroyed()) throw new Error('Desktop app is not available'); + const prompt = + request.prompt.length > 600 ? `${request.prompt.slice(0, 600)}…` : request.prompt; + const { response } = await dialog.showMessageBox(win, { + type: 'question', + title: 'Create a task in another project?', + message: `An agent in project "${request.projectName}" wants to create a task in project "${request.targetProjectName}".`, + // Names and prompts come from agents, so they stay out of the headline the user acts on. + detail: `Asking task: ${request.creatorTaskName.slice(0, 80)}\nNew task: ${request.name.slice(0, 80)}\n\nPrompt:\n${prompt}\n\nIf you allow it, the task starts in "${request.targetProjectName}" with the asking agent, its sandbox and its permission settings, and you review it like any other task.`, + buttons: ['Create task', 'Deny'], + // Deny is the default: Enter or Escape on an unexpected dialog must not start work. + defaultId: 1, + cancelId: 1, + }); + return response === 0; + }, }); const { transport, delegation, pendingSpawns, canvasOwners, wideBindAgents, needsWideBind } = mcp; const taskNames = new Map(); diff --git a/electron/mcp/cross-project-tasks.ts b/electron/mcp/cross-project-tasks.ts new file mode 100644 index 000000000..1a4cd22a6 --- /dev/null +++ b/electron/mcp/cross-project-tasks.ts @@ -0,0 +1,45 @@ +/** A project that takes tasks, as the renderer lists it. */ +export interface TaskProject { + id: string; + name: string; +} + +/** What the user is asked before an agent creates a task in another project. */ +export interface CrossProjectTaskRequest { + creatorTaskName: string; + projectName: string; + targetProjectName: string; + name: string; + prompt: string; +} + +const LISTED_PROJECTS = 30; + +function describe(projects: readonly TaskProject[], withIds: boolean): string { + const shown = projects + .slice(0, LISTED_PROJECTS) + .map((p) => (withIds ? `"${p.name}" (id ${p.id})` : `"${p.name}"`)); + const more = projects.length - shown.length; + return shown.join(', ') + (more > 0 ? ` and ${more} more` : ''); +} + +/** + * Finds the project an agent named, by exact id or by name ignoring case. Agents usually + * know a project by name ("phpstan"), so an unknown or ambiguous name returns an error + * message that lists the choices. + */ +export function resolveTaskProject( + projects: readonly TaskProject[], + ref: string, +): TaskProject | string { + const byId = projects.find((p) => p.id === ref); + if (byId) return byId; + const wanted = ref.trim().toLowerCase(); + const byName = projects.filter((p) => p.name.trim().toLowerCase() === wanted); + if (byName.length === 1) return byName[0]; + if (byName.length > 1) + return `Several projects are named "${ref}"; pass the id of one of them as project: ${describe(byName, true)}`; + return projects.length + ? `No project is named "${ref}". Projects: ${describe(projects, false)}` + : `No project is named "${ref}"`; +} diff --git a/electron/mcp/delegation.test.ts b/electron/mcp/delegation.test.ts index a9e758ffe..c7bf49bed 100644 --- a/electron/mcp/delegation.test.ts +++ b/electron/mcp/delegation.test.ts @@ -15,6 +15,7 @@ import type { import { DEFAULT_INDEPENDENT_TASKS_PER_CREATOR } from '../shared/coordinator-limits.js'; import { setProjectWorktreeSettings } from '../ipc/project-worktree.js'; import type { CrossProjectReadRequest } from './cross-project-reads.js'; +import type { CrossProjectTaskRequest, TaskProject } from './cross-project-tasks.js'; const mocks = vi.hoisted(() => ({ git: vi.fn(), @@ -99,6 +100,10 @@ let importWorktree: Mock< let confirmCrossProjectRead: Mock<(request: CrossProjectReadRequest) => Promise>; /** Answers the oldest open cross-project confirmation. */ let answers: Array<(allowed: boolean) => void>; +let listProjects: Mock<() => Promise>; +let confirmCrossProjectTask: Mock<(request: CrossProjectTaskRequest) => Promise>; +/** Answers the oldest open cross-project task confirmation. */ +let taskAnswers: Array<(allowed: boolean) => void>; function task(taskId: string, extra: Partial = {}): TaskAuthorityInput { return { @@ -231,6 +236,14 @@ beforeEach(() => { createIndependent = vi.fn(async () => ({ taskId: 'sibling' })); importWorktree = vi.fn(async () => ({ taskId: 'imported', resumedSessionId: null })); answers = []; + taskAnswers = []; + listProjects = vi.fn(async () => [ + { id: 'project', name: 'Project' }, + { id: 'phpstan-id', name: 'phpstan' }, + ]); + confirmCrossProjectTask = vi.fn( + () => new Promise((resolveAnswer) => taskAnswers.push(resolveAnswer)), + ); confirmCrossProjectRead = vi.fn( () => new Promise((resolveAnswer) => answers.push(resolveAnswer)), ); @@ -244,6 +257,8 @@ beforeEach(() => { createIndependent, importWorktree, confirmCrossProjectRead, + listProjects, + confirmCrossProjectTask, }); }); afterEach(() => { @@ -2225,3 +2240,148 @@ describe('cross-project reads', () => { expect(confirmCrossProjectRead).not.toHaveBeenCalled(); }); }); + +describe('cross-project tasks', () => { + const setting = (enabled: boolean) => + service.request({ action: 'crossProjectTaskSetting', enabled }); + const create = (caller: SessionCaller, project: string, requestId = 'bug') => + service.callTool(caller, 'create_task', { + requestId, + relation: 'independent', + name: 'Fix generics bug', + prompt: 'Reproduce with this snippet, then fix it', + project, + }); + const asked = (count: number) => + vi.waitFor(() => expect(confirmCrossProjectTask).toHaveBeenCalledTimes(count)); + async function parent() { + await register('parent'); + policy(); + return session('parent'); + } + + it('refuses another project while the setting is off, without asking', async () => { + const caller = await parent(); + await expect(create(caller, 'phpstan')).rejects.toThrow( + 'Allow agents to create tasks in other projects', + ); + expect(listProjects).not.toHaveBeenCalled(); + expect(confirmCrossProjectTask).not.toHaveBeenCalled(); + expect(createIndependent).not.toHaveBeenCalled(); + }); + + it('asks the user, waits, and creates the task in the project named', async () => { + const caller = await parent(); + await setting(true); + const created = create(caller, 'PHPStan'); + await asked(1); + expect(confirmCrossProjectTask).toHaveBeenCalledWith({ + creatorTaskName: 'parent', + projectName: 'Project', + targetProjectName: 'phpstan', + name: 'Fix generics bug', + prompt: 'Reproduce with this snippet, then fix it', + }); + expect(createIndependent).not.toHaveBeenCalled(); + taskAnswers.shift()?.(true); + await expect(created).resolves.toEqual({ taskId: 'sibling', relation: 'independent' }); + expect(createIndependent).toHaveBeenCalledWith({ + creatorTaskId: 'parent', + name: 'Fix generics bug', + prompt: 'Reproduce with this snippet, then fix it', + launchId: expect.any(String), + projectId: 'phpstan-id', + }); + // A retry of the same request answers again without a second dialog or task. + await expect(create(caller, 'PHPStan')).resolves.toMatchObject({ taskId: 'sibling' }); + expect(confirmCrossProjectTask).toHaveBeenCalledOnce(); + expect(createIndependent).toHaveBeenCalledOnce(); + // The same request ID for another project is a different assignment. + await expect(create(caller, 'Project')).rejects.toThrow('Request ID reused'); + }); + + it('creates nothing when the user denies it', async () => { + const caller = await parent(); + await setting(true); + const created = create(caller, 'phpstan-id'); + await asked(1); + taskAnswers.shift()?.(false); + await expect(created).rejects.toThrow('declined creating this task in project "phpstan"'); + expect(createIndependent).not.toHaveBeenCalled(); + }); + + it('treats its own project as an ordinary independent task', async () => { + const caller = await parent(); + await setting(true); + await expect(create(caller, 'project')).resolves.toMatchObject({ relation: 'independent' }); + expect(confirmCrossProjectTask).not.toHaveBeenCalled(); + expect(createIndependent).toHaveBeenCalledWith( + expect.not.objectContaining({ projectId: expect.anything() }), + ); + }); + + it('lists the projects when the name is unknown or ambiguous', async () => { + const caller = await parent(); + await setting(true); + await expect(create(caller, 'psalm', 'a')).rejects.toThrow( + 'No project is named "psalm". Projects: "Project", "phpstan"', + ); + listProjects.mockResolvedValue([ + { id: 'one', name: 'Lib' }, + { id: 'two', name: 'lib' }, + ]); + await expect(create(caller, 'LIB', 'b')).rejects.toThrow( + 'pass the id of one of them as project: "Lib" (id one), "lib" (id two)', + ); + expect(confirmCrossProjectTask).not.toHaveBeenCalled(); + expect(createIndependent).not.toHaveBeenCalled(); + }); + + it('refuses after approval when the setting or creation was switched off meanwhile', async () => { + const caller = await parent(); + await setting(true); + const created = create(caller, 'phpstan'); + await asked(1); + await setting(false); + taskAnswers.shift()?.(true); + await expect(created).rejects.toThrow('Allow agents to create tasks in other projects'); + + await setting(true); + const paused = create(caller, 'phpstan', 'paused'); + await asked(2); + await service.request({ action: 'pause', taskId: 'parent', paused: true }); + taskAnswers.shift()?.(true); + await expect(paused).rejects.toThrow('Task creation is paused'); + expect(createIndependent).not.toHaveBeenCalled(); + }); + + it('shows one dialog at a time', async () => { + const caller = await parent(); + await setting(true); + const first = create(caller, 'phpstan', 'first'); + const second = create(caller, 'phpstan', 'second'); + await asked(1); + await new Promise((resolveTick) => setTimeout(resolveTick, 0)); + expect(confirmCrossProjectTask).toHaveBeenCalledOnce(); + taskAnswers.shift()?.(false); + await expect(first).rejects.toThrow('declined'); + await asked(2); + taskAnswers.shift()?.(true); + await expect(second).resolves.toMatchObject({ relation: 'independent' }); + }); + + it('keeps children in the creator project', async () => { + const caller = await parent(); + await setting(true); + await expect( + service.callTool(caller, 'create_task', { + requestId: 'child', + relation: 'child', + name: 'Child', + prompt: 'Do it', + project: 'phpstan', + }), + ).rejects.toThrow("use relation 'independent'"); + expect(core.createTask).not.toHaveBeenCalled(); + }); +}); diff --git a/electron/mcp/delegation.ts b/electron/mcp/delegation.ts index d65321e14..fd74c7ce7 100644 --- a/electron/mcp/delegation.ts +++ b/electron/mcp/delegation.ts @@ -14,6 +14,11 @@ import { type CrossProjectReadAccess, type CrossProjectReadRequest, } from './cross-project-reads.js'; +import { + resolveTaskProject, + type CrossProjectTaskRequest, + type TaskProject, +} from './cross-project-tasks.js'; import { isProjectPageAgentTaskId } from '../shared/project-page-agents.js'; import { getAgentPromptReadiness, @@ -77,6 +82,8 @@ const CROSS_PROJECT_REFUSALS: Record, denied: 'The user denied this session access to project "{project}". Do not retry; ask the user if you need it.', }; +const CROSS_PROJECT_TASKS_OFF = + 'Creating tasks in other projects is off. Only the user can turn on "Allow agents to create tasks in other projects" in Settings > Agents; tell the user what the task would be instead.'; // Shown on a queued message, so a delivery that cannot happen yet says why. const WAITING_FOR_PROMPT: Record = { ready: undefined, @@ -211,6 +218,9 @@ export class DelegationService { private readonly readyMessages = new Map(); private readonly closes = new Map>(); private readonly crossProject: ReturnType; + private crossProjectTasksEnabled = false; + // One confirmation at a time, so several agents asking at once don't stack native dialogs. + private crossProjectTaskQueue: Promise = Promise.resolve(); constructor( private readonly options: { @@ -228,6 +238,10 @@ export class DelegationService { ) => Promise<{ taskId: string; resumedSessionId: string | null }>; /** Asks the user; resolves true to allow. Agents never wait on it. */ confirmCrossProjectRead: (request: CrossProjectReadRequest) => Promise; + /** The projects that take tasks, to resolve the project an agent names. */ + listProjects: () => Promise; + /** Asks the user before each task an agent creates in another project; true allows. */ + confirmCrossProjectTask: (request: CrossProjectTaskRequest) => Promise; }, ) { this.orchestrationEnabled = options.orchestrationEnabled ?? true; @@ -560,14 +574,17 @@ export class DelegationService { }; if (Buffer.byteLength(request.prompt) > MAX_PROMPT_BYTES) throw new DelegationError('Prompt too large'); + const project = params.project === undefined ? undefined : text(params.project, 'project'); const key = `${creatorTaskId}:${requestId}`; - const payload = JSON.stringify(request); + const payload = JSON.stringify({ ...request, project }); const previous = this.independentRequests.get(key); if (previous) { if (previous.payload !== payload) throw new DelegationError('Request ID reused with a different assignment'); return previous.promise; } + if (project !== undefined && !this.crossProjectTasksEnabled) + throw new DelegationError(CROSS_PROJECT_TASKS_OFF, 403); const prefix = `${creatorTaskId}:`; const open = [...this.openIndependent.keys()].filter((k) => k.startsWith(prefix)); if (open.length >= this.maxIndependentPerCreator) @@ -583,8 +600,17 @@ export class DelegationService { this.creationGuard(creatorTaskId, caller, true); }); this.openIndependent.set(key, undefined); - const promise = this.options - .createIndependent({ ...request, launchId }) + const launch = (projectId?: string) => + this.options.createIndependent({ + ...request, + launchId, + ...(projectId !== undefined && { projectId }), + }); + const promise = ( + project === undefined + ? launch() + : this.confirmCrossProjectTask(creatorTaskId, project, request, epoch, caller).then(launch) + ) .then(({ taskId }) => { // A task closed before its launch resolved never comes back to free the slot. if (this.openIndependent.has(key) && !this.tasks.get(taskId)?.closed) @@ -601,6 +627,50 @@ export class DelegationService { return promise; } + /** + * Resolves the project an agent named and, when it is not the creator's own, asks the user + * before the task starts there. Unlike reads, creation waits for the answer: the agent needs + * the result, and every task it starts in another project is one the user approved. + * Resolves to the target project's id, or undefined for the creator's own project. + */ + private async confirmCrossProjectTask( + creatorTaskId: string, + ref: string, + request: { name: string; prompt: string }, + epoch: number, + caller: SessionCaller, + ): Promise { + const creator = this.requireTask(creatorTaskId); + const target = resolveTaskProject(await this.options.listProjects(), ref); + if (typeof target === 'string') throw new DelegationError(target); + if (target.id === creator.projectId) return undefined; + // Anything that changed while the agent waited (setting, pause, orchestration, session) + // is checked again both before the dialog opens and after the user answers. + const recheck = () => { + if (!this.crossProjectTasksEnabled) throw new DelegationError(CROSS_PROJECT_TASKS_OFF, 403); + this.assertOrchestrationEnabled(epoch); + this.creationGuard(creatorTaskId, caller, true); + }; + const answer = this.crossProjectTaskQueue.then(() => { + recheck(); + return this.options.confirmCrossProjectTask({ + creatorTaskName: creator.name, + projectName: this.projectOf(creator).projectName, + targetProjectName: target.name, + name: request.name, + prompt: request.prompt, + }); + }); + this.crossProjectTaskQueue = answer.catch(() => undefined); + if (!(await answer)) + throw new DelegationError( + `The user declined creating this task in project "${target.name}". Do not retry; ask the user if you still need it.`, + 403, + ); + recheck(); + return target.id; + } + /** Brings a worktree back as a top-level task the user reviews, open to the same sessions * as independent tasks. The renderer checks the path is one of the creator's project's * worktrees, since only it knows which ones are already tracked. */ @@ -695,6 +765,10 @@ export class DelegationService { return this.createIndependent(task.taskId, params, caller); if (params.relation !== 'child') throw new DelegationError("relation must be 'child' or 'independent'"); + if (params.project !== undefined) + throw new DelegationError( + "Children stay in your project; use relation 'independent' to create a task in another project", + ); this.creationGuard(task.taskId, caller); const requestId = id(params.requestId, 'requestId'); const previous = this.requests.get(`${task.taskId}:${requestId}`); @@ -1282,6 +1356,11 @@ export class DelegationService { throw new DelegationError('Invalid cross-project read setting'); this.crossProject.setEnabled(request.enabled); return { enabled: request.enabled }; + case 'crossProjectTaskSetting': + if (typeof request.enabled !== 'boolean') + throw new DelegationError('Invalid cross-project task setting'); + this.crossProjectTasksEnabled = request.enabled; + return { enabled: request.enabled }; case 'unregister': { const taskId = id(request.taskId); if (this.tasks.get(taskId)?.delegationParent || this.tasks.get(taskId)?.coordinatorMode) diff --git a/electron/mcp/mcp-tool-list.ts b/electron/mcp/mcp-tool-list.ts index 62d33e2e8..873663ff8 100644 --- a/electron/mcp/mcp-tool-list.ts +++ b/electron/mcp/mcp-tool-list.ts @@ -633,6 +633,13 @@ const ARCHIVE_TOOL: ToolDef = { }, }; +/** Shared by every create_task that offers independent tasks. */ +const CROSS_PROJECT_PROJECT_PARAM = { + type: 'string', + description: + "relation 'independent' only: create the task in another Parallel Code project, given by name (for example the library whose bug you found) or id. Needs the user's setting \"Allow agents to create tasks in other projects\", and the user confirms each task, so the call waits for their answer. The task starts from that project's main branch with no access to your worktree: put everything it needs, such as the reproduction, in prompt. An unknown name lists the projects. Omit it for your own project.", +}; + const SUPERVISION_TOOLS: ToolDef[] = COORDINATOR_TOOLS.filter( (tool) => !['merge_task', 'close_task'].includes(tool.name), ).map((tool) => { @@ -648,6 +655,7 @@ const SUPERVISION_TOOLS: ToolDef[] = COORDINATOR_TOOLS.filter( prompt: { type: 'string' }, relation: { type: 'string', enum: ['child', 'independent'] }, requestId: { type: 'string' }, + project: CROSS_PROJECT_PROJECT_PARAM, expectedBranch: { type: 'string' }, expectedHeadSha: { type: 'string' }, useLastCommit: { type: 'boolean', default: false }, @@ -715,6 +723,7 @@ const PAGE_TOOLS: ToolDef[] = [ prompt: { type: 'string' }, relation: { type: 'string', enum: ['independent'] }, requestId: { type: 'string' }, + project: CROSS_PROJECT_PROJECT_PARAM, }, required: ['name', 'prompt', 'relation', 'requestId'], }, diff --git a/electron/shared/delegation-types.ts b/electron/shared/delegation-types.ts index 81e73ba4d..d93fecd65 100644 --- a/electron/shared/delegation-types.ts +++ b/electron/shared/delegation-types.ts @@ -67,6 +67,8 @@ export interface IndependentTaskRequest { prompt: string; /** Pass to `assertIndependentLaunch` right before the agent starts. */ launchId: string; + /** Another project the user approved; without it, the creator's project. */ + projectId?: string; } /** An agent's request to bring an existing worktree of its project back as a top-level @@ -136,6 +138,7 @@ export type DelegationRequest = | { action: 'projectPolicy'; policy: ProjectDelegationPolicy } | { action: 'orchestrationSetting'; enabled: boolean } | { action: 'crossProjectReadSetting'; enabled: boolean } + | { action: 'crossProjectTaskSetting'; enabled: boolean } | { action: 'pause'; taskId: string; paused: boolean } | { action: 'childLimit'; taskId: string; limit: number } | { action: 'inbox'; taskId: string } diff --git a/src/components/settings/AgentSettings.tsx b/src/components/settings/AgentSettings.tsx index 0ac0f7b82..720cb5caf 100644 --- a/src/components/settings/AgentSettings.tsx +++ b/src/components/settings/AgentSettings.tsx @@ -6,6 +6,7 @@ import { setShareDockerAgentAuth, setMcpOrchestrationEnabled, setAllowCrossProjectReads, + setAllowCrossProjectTasks, setCoordinatorNotificationDelayMs, setMaxIndependentTasksPerCreator, setPreferUiMode, @@ -59,6 +60,21 @@ export function AgentSettings() { setSavingCrossProject(false); } } + + const [savingCrossProjectTasks, setSavingCrossProjectTasks] = createSignal(false); + const [crossProjectTasksError, setCrossProjectTasksError] = createSignal(null); + + async function changeCrossProjectTasks(enabled: boolean) { + setSavingCrossProjectTasks(true); + setCrossProjectTasksError(null); + try { + await setAllowCrossProjectTasks(enabled); + } catch (error) { + setCrossProjectTasksError(`Could not change cross-project tasks: ${String(error)}`); + } finally { + setSavingCrossProjectTasks(false); + } + } return ( <> @@ -122,6 +138,16 @@ export function AgentSettings() { {crossProjectError()} + void changeCrossProjectTasks(enabled)} + description="Top-level agents can start a task in another project, for example to fix a bug they found in a library you also work on. Each one asks you first and shows its prompt. The task uses the asking agent, its sandbox and its permission settings, and you review it like any other. Needs agent orchestration" + /> + + {crossProjectTasksError()} +