Skip to content

Commit 346250f

Browse files
authored
Merge branch 'main' into fix/pwa-installable
2 parents b7fe86c + aef0e9c commit 346250f

17 files changed

Lines changed: 523 additions & 84 deletions

‎apps/server/src/mcp/OrchestratorMcpService.activity.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ import * as ProjectService from "../project/ProjectService.ts";
2222
import * as ScheduledTaskService from "../scheduledTasks/ScheduledTaskService.ts";
2323
import * as ServerSettings from "../serverSettings.ts";
2424
import * as SecretRequests from "../secrets/SecretRequests.ts";
25+
import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
26+
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
2527
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
2628
import type * as McpInvocationContext from "./McpInvocationContext.ts";
2729
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
2830

31+
const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
32+
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
33+
Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
34+
);
35+
2936
const environmentId = EnvironmentId.make("environment-mcp-orchestrator-detail");
3037
const projectId = ProjectId.make("project-mcp-orchestrator-detail");
3138
const parentThreadId = ThreadId.make("thread-mcp-orchestrator-parent");
@@ -127,7 +134,7 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
127134
updatedAt: now,
128135
} as unknown as OrchestrationV2ThreadProjection;
129136

130-
const layer = OrchestratorMcpService.layer.pipe(
137+
const layer = layerOrchestratorService.pipe(
131138
Layer.provide(
132139
Layer.mergeAll(
133140
Layer.mock(ThreadManagementService.ThreadManagementService)({
@@ -193,7 +200,7 @@ it("readThread prefers waiting activity status over a newer cancelled queued run
193200
updatedAt: now,
194201
} as unknown as OrchestrationV2ThreadProjection;
195202

196-
const layer = OrchestratorMcpService.layer.pipe(
203+
const layer = layerOrchestratorService.pipe(
197204
Layer.provide(
198205
Layer.mergeAll(
199206
Layer.mock(ThreadManagementService.ThreadManagementService)({
@@ -316,7 +323,7 @@ it("taskStatus returns task.providerInstanceId rather than the driver kind", asy
316323
updatedAt: now,
317324
} as unknown as OrchestrationV2ThreadProjection;
318325

319-
const layer = OrchestratorMcpService.layer.pipe(
326+
const layer = layerOrchestratorService.pipe(
320327
Layer.provide(
321328
Layer.mergeAll(
322329
Layer.mock(ThreadManagementService.ThreadManagementService)({
@@ -415,7 +422,7 @@ it("readThread and sendToThread reach threads in other projects", async () => {
415422
updatedAt: now,
416423
}) as unknown as OrchestrationV2ThreadProjection;
417424

418-
const layer = OrchestratorMcpService.layer.pipe(
425+
const layer = layerOrchestratorService.pipe(
419426
Layer.provide(
420427
Layer.mergeAll(
421428
Layer.mock(ThreadManagementService.ThreadManagementService)({

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
OrchestratorThreadAboveModeLimitError,
3030
} from "../orchestration-v2/Orchestrator.ts";
3131
import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts";
32+
import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
33+
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
3234
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
3335
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
3436
import { buildUnavailableProviderSnapshot } from "../provider/unavailableProviderSnapshot.ts";
@@ -41,6 +43,11 @@ import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.t
4143
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
4244
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
4345

46+
const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
47+
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
48+
Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
49+
);
50+
4451
describe("OrchestratorMcpService", () => {
4552
it.effect("retries terminal acknowledgement with a fresh command id", () =>
4653
Effect.gen(function* () {
@@ -170,7 +177,7 @@ describe("OrchestratorMcpService", () => {
170177
const commandIds = yield* Ref.get(acknowledgementCommandIds);
171178
assert.equal(commandIds.length, 2);
172179
assert.notEqual(commandIds[0], commandIds[1]);
173-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
180+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
174181
}),
175182
);
176183

@@ -267,7 +274,7 @@ describe("OrchestratorMcpService", () => {
267274
const settled = yield* service.taskStatus(scope, taskId);
268275
assert.equal(settled.status, "cancelled");
269276
assert.equal(yield* Ref.get(dispatched), 1);
270-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
277+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
271278
}),
272279
);
273280

@@ -343,7 +350,7 @@ describe("OrchestratorMcpService", () => {
343350
.pipe(Effect.flip);
344351
assert.equal(error.code, "task_not_cancellable");
345352
assert.deepEqual(yield* Ref.get(dispatched), []);
346-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
353+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
347354
}),
348355
);
349356

@@ -423,7 +430,7 @@ describe("OrchestratorMcpService", () => {
423430
(yield* Ref.get(dispatched)).map((command) => (command as { type: string }).type),
424431
["thread.stop"],
425432
);
426-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
433+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
427434
}),
428435
);
429436

@@ -509,7 +516,7 @@ describe("OrchestratorMcpService", () => {
509516
(yield* Ref.get(dispatched)).map((command) => (command as { type: string }).type),
510517
["thread.stop", "delegated_task.completion-delivery.dispose"],
511518
);
512-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
519+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
513520
}),
514521
);
515522

@@ -592,7 +599,7 @@ describe("OrchestratorMcpService", () => {
592599
.pipe(Effect.flip);
593600
assert.equal(error.code, "runtime_mode_escalation_denied");
594601
assert.deepEqual(yield* Ref.get(dispatched), []);
595-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
602+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
596603
}),
597604
);
598605

@@ -736,7 +743,7 @@ describe("OrchestratorMcpService", () => {
736743
dispatched: yield* Ref.get(dispatched),
737744
stoppedBelow: yield* Ref.get(stoppedBelow),
738745
};
739-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
746+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
740747
});
741748

742749
it.effect("refuses to cancel a task when a task under it now runs above the parent's modes", () =>
@@ -1019,9 +1026,7 @@ describe("OrchestratorMcpService provider resolution", () => {
10191026
assert.isTrue(
10201027
fork!.constraints.includes("Driver 'forkOnly' is not registered in this build."),
10211028
);
1022-
}).pipe(
1023-
Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))),
1024-
);
1029+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
10251030
}),
10261031
);
10271032

@@ -1066,7 +1071,7 @@ describe("OrchestratorMcpService provider resolution", () => {
10661071
capabilities.providers[0]?.models.map((model) => model.id),
10671072
["gpt-5.4", "my-model"],
10681073
);
1069-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1074+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
10701075
}),
10711076
);
10721077

@@ -1166,9 +1171,7 @@ describe("OrchestratorMcpService provider resolution", () => {
11661171
assert.equal(request.type, "delegated_task.request");
11671172
assert.equal(request.modelSelection.instanceId, antigravityInstanceId);
11681173
assert.equal(request.modelSelection.model, "ant-model");
1169-
}).pipe(
1170-
Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))),
1171-
);
1174+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
11721175
}),
11731176
);
11741177

@@ -1264,7 +1267,7 @@ describe("OrchestratorMcpService provider resolution", () => {
12641267
};
12651268
assert.equal(request.modelSelection.instanceId, antigravityInstanceId);
12661269
assert.equal(request.modelSelection.model, "ant-model");
1267-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1270+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
12681271
}),
12691272
);
12701273

@@ -1323,7 +1326,7 @@ describe("OrchestratorMcpService provider resolution", () => {
13231326
assert.isTrue(
13241327
byDriver.message.includes("No V2 provider adapter is registered for driver forkOnly."),
13251328
);
1326-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1329+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
13271330
}),
13281331
);
13291332

@@ -1369,7 +1372,7 @@ describe("OrchestratorMcpService provider resolution", () => {
13691372
})
13701373
.pipe(Effect.flip);
13711374
assert.equal(error.code, "invalid_request");
1372-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1375+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
13731376
}),
13741377
);
13751378

@@ -1474,7 +1477,7 @@ describe("OrchestratorMcpService provider resolution", () => {
14741477
modelSelection: { instanceId: string; model: string };
14751478
};
14761479
assert.equal(request.modelSelection.instanceId, altInstanceId);
1477-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1480+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
14781481
}),
14791482
);
14801483

@@ -1599,9 +1602,7 @@ describe("OrchestratorMcpService provider resolution", () => {
15991602
modelSelection: { instanceId: string; model: string };
16001603
};
16011604
assert.equal(retryCommand.modelSelection.instanceId, codexInstanceId);
1602-
}).pipe(
1603-
Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))),
1604-
);
1605+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
16051606
}),
16061607
);
16071608

@@ -1706,7 +1707,7 @@ describe("OrchestratorMcpService provider resolution", () => {
17061707
assert.equal(result.providerInstanceId, claudeInstanceId);
17071708
assert.equal(yield* Ref.get(probes), 2);
17081709
assert.equal(yield* Ref.get(dispatched), 1);
1709-
}).pipe(Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))));
1710+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
17101711
}),
17111712
);
17121713

@@ -1917,9 +1918,7 @@ describe("OrchestratorMcpService provider resolution", () => {
19171918
} else {
19181919
assert.equal(request.modelSelection.model, "codex-alt-model", testCase.name);
19191920
}
1920-
}).pipe(
1921-
Effect.provide(OrchestratorMcpService.layer.pipe(Layer.provide(layerDependencies))),
1922-
);
1921+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(layerDependencies))));
19231922
}
19241923
}),
19251924
);
@@ -1972,7 +1971,7 @@ describe("OrchestratorMcpService provider resolution", () => {
19721971
boundThread: OrchestrationV2ThreadShell | null,
19731972
upserted: Ref.Ref<number>,
19741973
) =>
1975-
OrchestratorMcpService.layer.pipe(
1974+
layerOrchestratorService.pipe(
19761975
Layer.provide(
19771976
Layer.mergeAll(
19781977
NodeServices.layer,
@@ -2040,7 +2039,7 @@ describe("OrchestratorMcpService provider resolution", () => {
20402039
),
20412040
),
20422041
Effect.provide(
2043-
OrchestratorMcpService.layer.pipe(
2042+
layerOrchestratorService.pipe(
20442043
Layer.provide(
20452044
Layer.mergeAll(
20462045
NodeServices.layer,
@@ -2123,7 +2122,7 @@ describe("OrchestratorMcpService provider resolution", () => {
21232122
// The edit's own check reads the thread; the read after the save fails.
21242123
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
21252124
Effect.provide(
2126-
OrchestratorMcpService.layer.pipe(
2125+
layerOrchestratorService.pipe(
21272126
Layer.provide(
21282127
Layer.mergeAll(
21292128
NodeServices.layer,

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type OrchestrationV2Subagent,
1111
type OrchestrationV2ThreadProjection,
1212
type OrchestrationV2ThreadShell,
13+
type OrchestrationV2ThreadLaunchWorkspaceStrategy,
1314
type OrchestrationV2TurnItem,
1415
OrchestratorMcpFailure,
1516
type OrchestratorMcpCapabilitiesResult,
@@ -81,6 +82,8 @@ import {
8182
type DispatchModeRefusal,
8283
} from "../orchestration-v2/DispatchModeLimit.ts";
8384
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
85+
import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
86+
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
8487
import { isSnoozed } from "../orchestration-v2/ThreadSettlementService.ts";
8588
import * as ProjectService from "../project/ProjectService.ts";
8689
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
@@ -904,6 +907,8 @@ const make = Effect.gen(function* () {
904907
const providerAdapters = yield* ProviderAdapterRegistry.ProviderAdapterRegistryV2;
905908
const scheduledTasks = yield* ScheduledTaskService.ScheduledTaskService;
906909
const projects = yield* ProjectService.ProjectService;
910+
const threadLaunch = yield* ThreadLaunchService.ThreadLaunchService;
911+
const gitDriver = yield* GitVcsDriver.GitVcsDriver;
907912
const serverSettings = yield* ServerSettings.ServerSettingsService;
908913

909914
/** A caller-named project, which must exist before anything is recorded against it. */
@@ -1993,6 +1998,21 @@ const make = Effect.gen(function* () {
19931998
parent.thread.interactionMode,
19941999
input.interactionMode,
19952000
);
2001+
let workspaceStrategy: OrchestrationV2ThreadLaunchWorkspaceStrategy | undefined;
2002+
if (input.isolation === "worktree" && !isRetryOfAcceptedDelegation) {
2003+
const project = yield* requireProject(parent.thread.projectId);
2004+
const base = yield* gitDriver
2005+
.resolveCommit({
2006+
cwd: parent.thread.worktreePath ?? project.workspaceRoot,
2007+
revision: "HEAD",
2008+
})
2009+
.pipe(
2010+
Effect.mapError(() =>
2011+
failure("invalid_request", "Unable to resolve the parent checkout commit."),
2012+
),
2013+
);
2014+
workspaceStrategy = { type: "worktree", baseRef: base.commitSha, startFromOrigin: false };
2015+
}
19962016
// ThreadManagementService.dispatch is the chokepoint for this command
19972017
// type's own enablement check, using the same command id and its
19982018
// receipt-replay exemption, so no separate assert runs here.
@@ -2010,6 +2030,7 @@ const make = Effect.gen(function* () {
20102030
modelSelection: target.modelSelection,
20112031
runtimeMode,
20122032
interactionMode,
2033+
...(workspaceStrategy === undefined ? {} : { workspaceStrategy }),
20132034
// Async delegations wake the parent on every child terminal; wait
20142035
// delegations deliver through the blocking tool call, so a wake is
20152036
// only needed if the parent settled first (timeout, disconnect).
@@ -2036,6 +2057,22 @@ const make = Effect.gen(function* () {
20362057
);
20372058
}
20382059
const taskId = taskEvent.event.payload.id;
2060+
const childThreadId = taskEvent.event.payload.childThreadId;
2061+
const childRunEvent = result.storedEvents.find(
2062+
(stored) =>
2063+
stored.event.type === "run.created" && stored.event.threadId === childThreadId,
2064+
);
2065+
if (
2066+
childThreadId !== null &&
2067+
childRunEvent?.event.type === "run.created" &&
2068+
childRunEvent.event.payload.workspacePreparation !== undefined
2069+
) {
2070+
yield* threadLaunch.prepareRun({
2071+
commandId,
2072+
threadId: childThreadId,
2073+
runId: childRunEvent.event.payload.id,
2074+
});
2075+
}
20392076

20402077
if (input.mode !== "wait") {
20412078
return yield* readTask(scope, taskId, false, true);
@@ -2660,6 +2697,8 @@ export const layer: Layer.Layer<
26602697
never,
26612698
| Crypto.Crypto
26622699
| ThreadManagementService.ThreadManagementService
2700+
| ThreadLaunchService.ThreadLaunchService
2701+
| GitVcsDriver.GitVcsDriver
26632702
| ProviderRegistry.ProviderRegistry
26642703
| ProviderAdapterRegistry.ProviderAdapterRegistryV2
26652704
| ScheduledTaskService.ScheduledTaskService

‎apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ import { threadShellFromProjection } from "../orchestration-v2/ProjectionStore.t
5757
import * as CommandReceiptStore from "../orchestration-v2/CommandReceiptStore.ts";
5858
import * as EventSink from "../orchestration-v2/EventSink.ts";
5959
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
60+
import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
61+
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
6062
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
6163
import * as ServerSettings from "../serverSettings.ts";
6264
import * as SqlitePersistence from "../persistence/Sqlite.ts";
@@ -80,6 +82,11 @@ import * as McpInvocationContext from "./McpInvocationContext.ts";
8082
import { delegatedTaskRun, hasPendingChildRuns } from "./OrchestratorMcpService.ts";
8183
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
8284

85+
const layerOrchestratorToolkit = McpHttpServer.layerOrchestratorToolkit.pipe(
86+
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
87+
Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
88+
);
89+
8390
// Effect returns a declared tool failure as `isError` with its encoded payload
8491
// as JSON text, never as `structuredContent`.
8592
const declaredFailure = (result: McpSchema.CallToolResult) => {
@@ -682,7 +689,7 @@ describe("orchestrator MCP toolkit", () => {
682689
}),
683690
);
684691
const layerTest = Layer.merge(
685-
McpHttpServer.layerOrchestratorToolkit,
692+
layerOrchestratorToolkit,
686693
McpHttpServer.layerThreadToolkit,
687694
).pipe(
688695
Layer.provideMerge(McpServer.McpServer.layer),
@@ -3838,7 +3845,7 @@ describe("orchestrator MCP toolkit", () => {
38383845
model: codexModel,
38393846
}),
38403847
]);
3841-
const layerTest = McpHttpServer.layerOrchestratorToolkit.pipe(
3848+
const layerTest = layerOrchestratorToolkit.pipe(
38423849
Layer.provideMerge(McpServer.McpServer.layer),
38433850
Layer.provideMerge(layerOrchestration),
38443851
Layer.provide(

0 commit comments

Comments
 (0)