Skip to content

Commit fd7f1cd

Browse files
refactor(providers): adapter factories yield their services
Our Effect service conventions take dependencies from the environment, not as parameters. The provider adapter factories took ProviderHost, IdAllocator, FileSystem, Crypto, Path, the child process spawner, and provider runtimes (OpenCode runtime, Cursor SDK runner) as options. Each factory is now an Effect.fn that yields those services, so its type shows what it needs: Pi, Muse, OpenCode, Cursor, the shared ACP adapter, Grok, Antigravity, and the ACP Registry. Options keep only configuration and deliberate callbacks (settings, environment, continuation offers, test hooks, runtime factories). ProviderHostShape becomes ProviderHost["Service"]. Tests provide fakes as services (Effect.provideService) instead of passing them in; tests that passed the environment's own instances just drop the arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b707eeb commit fd7f1cd

27 files changed

Lines changed: 270 additions & 1030 deletions

‎apps/server/scripts/record-grok-acp-replay-fixture.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { HostProcessEnvironment, HostProcessPlatform } from "@t3tools/shared/hos
1616
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
1717
import * as Clock from "effect/Clock";
1818
import * as Console from "effect/Console";
19-
import * as Crypto from "effect/Crypto";
2019
import * as Effect from "effect/Effect";
2120
import * as FileSystem from "effect/FileSystem";
2221
import * as Layer from "effect/Layer";
@@ -25,7 +24,6 @@ import * as Schema from "effect/Schema";
2524
import { ChildProcessSpawner } from "effect/process";
2625
import type * as EffectAcpProtocol from "effect-acp/protocol";
2726

28-
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
2927
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
3028
import {
3129
GROK_DEFAULT_INSTANCE_ID,
@@ -447,16 +445,11 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s
447445
Effect.gen(function* () {
448446
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
449447
const environment = yield* HostProcessEnvironment;
450-
const adapter = makeGrokAdapterV2({
448+
const adapter = yield* makeGrokAdapterV2({
451449
instanceId: GROK_DEFAULT_INSTANCE_ID,
452450
settings,
453451
environment,
454452
hostPlatform: yield* HostProcessPlatform,
455-
childProcessSpawner,
456-
crypto: yield* Crypto.Crypto,
457-
fileSystem: yield* FileSystem.FileSystem,
458-
idAllocator: yield* IdAllocator.IdAllocatorV2,
459-
host: yield* ProviderHost.ProviderHost,
460453
selfInvocation: yield* resolveSelfInvocation(),
461454
continuationRequests: yield* ProviderContinuationRequests.ProviderContinuationRequests,
462455
// Production's runtime factory, with the protocol logger teeing raw lines.

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 86 additions & 623 deletions
Large diffs are not rendered by default.

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ProviderInstanceId, ProviderSessionId, ThreadId } from "@t3tools/contra
44
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
55
import * as Deferred from "effect/Deferred";
66
import * as Effect from "effect/Effect";
7-
import * as Crypto from "effect/Crypto";
87
import * as FileSystem from "effect/FileSystem";
98
import * as Layer from "effect/Layer";
109
import * as Option from "effect/Option";
@@ -188,8 +187,7 @@ describe("AcpRegistryAdapterV2", () => {
188187
ACP_REGISTRY_PROVIDER,
189188
);
190189
const instanceId = ProviderInstanceId.make("acp-registry-mode-pick");
191-
const adapter = makeAcpRegistryAdapterV2({
192-
crypto: yield* Crypto.Crypto,
190+
const adapter = yield* makeAcpRegistryAdapterV2({
193191
selfInvocation: yield* resolveSelfInvocation(),
194192
instanceId,
195193
settings: yield* decodeAcpRegistryAdapterSettings({
@@ -198,10 +196,7 @@ describe("AcpRegistryAdapterV2", () => {
198196
}),
199197
environment: {},
200198
childProcessSpawner,
201-
fileSystem,
202-
idAllocator: yield* IdAllocator.IdAllocatorV2,
203199
resolver: { resolve: () => Effect.die("the runtime is injected") },
204-
host: yield* ProviderHost.ProviderHost,
205200
makeRuntime: makeAcpReplayRuntime({
206201
transcript,
207202
statusPath,
@@ -268,10 +263,7 @@ describe("AcpRegistryAdapterV2", () => {
268263
it.effect("offers client terminals to Devin only and client fs to no registry agent", () =>
269264
Effect.gen(function* () {
270265
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
271-
const fileSystem = yield* FileSystem.FileSystem;
272-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
273266
const path = yield* Path.Path;
274-
const host = yield* ProviderHost.ProviderHost;
275267
const mockAgentPath = yield* path.fromFileUrl(
276268
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
277269
);
@@ -280,17 +272,13 @@ describe("AcpRegistryAdapterV2", () => {
280272
) {
281273
let clientCapabilities: unknown;
282274
const instanceId = ProviderInstanceId.make(`acp-registry-capabilities-${agentId}`);
283-
const adapter = makeAcpRegistryAdapterV2({
284-
crypto: yield* Crypto.Crypto,
275+
const adapter = yield* makeAcpRegistryAdapterV2({
285276
selfInvocation: yield* resolveSelfInvocation(),
286277
instanceId,
287278
settings: yield* decodeAcpRegistryAdapterSettings({ agentId, authMethodId: "test" }),
288279
environment: {},
289280
childProcessSpawner,
290-
fileSystem,
291-
idAllocator,
292281
resolver: { resolve: () => Effect.die("the runtime is injected") },
293-
host,
294282
makeRuntime: (input) =>
295283
Effect.gen(function* () {
296284
clientCapabilities = input.clientCapabilities;
@@ -344,8 +332,6 @@ describe("AcpRegistryAdapterV2", () => {
344332
it.effect("opens a real ACP child process resolved from registry configuration", () =>
345333
Effect.gen(function* () {
346334
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
347-
const fileSystem = yield* FileSystem.FileSystem;
348-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
349335
const path = yield* Path.Path;
350336
const host = yield* ProviderHost.ProviderHost;
351337
const mockAgentPath = yield* path.fromFileUrl(
@@ -369,8 +355,7 @@ describe("AcpRegistryAdapterV2", () => {
369355
readonly commands: AcpRegistryAvailableCommands;
370356
}>();
371357
const configurationPublished = yield* Deferred.make<AcpRegistryLiveConfiguration>();
372-
const adapter = makeAcpRegistryAdapterV2({
373-
crypto: yield* Crypto.Crypto,
358+
const adapter = yield* makeAcpRegistryAdapterV2({
374359
selfInvocation: yield* resolveSelfInvocation(),
375360
instanceId,
376361
settings,
@@ -379,8 +364,6 @@ describe("AcpRegistryAdapterV2", () => {
379364
T3_ACP_COMMAND_ADVERTISEMENT_DELAY_MS: "750",
380365
},
381366
childProcessSpawner,
382-
fileSystem,
383-
idAllocator,
384367
runtimeCoordinator: {
385368
withForegroundStartup: (agentId, effect) =>
386369
Effect.acquireUseRelease(
@@ -428,7 +411,6 @@ describe("AcpRegistryAdapterV2", () => {
428411
})),
429412
),
430413
},
431-
host,
432414
});
433415
const threadId = ThreadId.make("thread-acp-registry-fixture");
434416
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.testkit.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { AcpRegistrySettings } from "@t3tools/contracts";
33
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
44
import * as Effect from "effect/Effect";
5-
import * as Crypto from "effect/Crypto";
65
import * as FileSystem from "effect/FileSystem";
76
import * as Layer from "effect/Layer";
87
import * as Path from "effect/Path";
98
import * as Schema from "effect/Schema";
109
import { ChildProcessSpawner } from "effect/process";
1110

12-
import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
1311
import { layerTestProviderHost } from "@t3tools/provider-testing/host";
1412
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
1513
import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts";
@@ -44,9 +42,6 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
4442
const fileSystem = yield* FileSystem.FileSystem;
4543
const path = yield* Path.Path;
4644
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
47-
const crypto = yield* Crypto.Crypto;
48-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
49-
const host = yield* ProviderHost.ProviderHost;
5045
const replayGate = options.replayGate;
5146
const replayDir = yield* fileSystem
5247
.makeTempDirectory({
@@ -57,18 +52,14 @@ function layerAcpRegistryProviderAdapterRegistryReplay(
5752
const scriptPath = yield* path
5853
.fromFileUrl(new URL("../../../scripts/acp-replay-agent.ts", import.meta.url))
5954
.pipe(Effect.orDie);
60-
const adapter = makeAcpRegistryAdapterV2({
55+
const adapter = yield* makeAcpRegistryAdapterV2({
6156
instanceId: ACP_REGISTRY_DEFAULT_INSTANCE_ID,
6257
settings: REPLAY_SETTINGS,
6358
environment: {},
6459
childProcessSpawner,
65-
crypto,
66-
fileSystem,
67-
idAllocator,
6860
resolver: {
6961
resolve: () => Effect.die("ACP registry resolver must not run during replay"),
7062
},
71-
host,
7263
selfInvocation: yield* resolveSelfInvocation(),
7364
makeRuntime: makeAcpReplayRuntime({
7465
transcript,

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.ts‎

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,9 @@ export interface AcpRegistryAdapterV2Options {
5959
readonly settings: AcpRegistrySettings;
6060
readonly environment: NodeJS.ProcessEnv;
6161
readonly childProcessSpawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
62-
readonly crypto: Crypto.Crypto;
6362
readonly selfInvocation: SelfInvocation;
64-
readonly fileSystem: FileSystem.FileSystem;
65-
readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
6663
readonly resolver: Pick<AcpRegistrySupport.AcpRegistryCatalog["Service"], "resolve">;
6764
readonly runtimeCoordinator?: AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator["Service"];
68-
readonly host: ProviderHost.ProviderHostShape;
6965
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
7066
readonly makeRuntime?: (
7167
input: AcpAdapterV2RuntimeInput,
@@ -181,7 +177,9 @@ function makeAcpRegistryRuntime(options: AcpRegistryAdapterV2Options) {
181177
});
182178
}
183179

184-
export function makeAcpRegistryAdapterV2(options: AcpRegistryAdapterV2Options) {
180+
export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(function* (
181+
options: AcpRegistryAdapterV2Options,
182+
) {
185183
const runtimeCoordinator = options.runtimeCoordinator;
186184
const registryAgentId = options.settings.source === "local" ? "" : options.settings.agentId;
187185
const startupKey =
@@ -237,13 +235,9 @@ export function makeAcpRegistryAdapterV2(options: AcpRegistryAdapterV2Options) {
237235
}),
238236
...(options.assertComplete === undefined ? {} : { assertComplete: options.assertComplete }),
239237
};
240-
return makeAcpAdapterV2({
238+
return yield* makeAcpAdapterV2({
241239
instanceId: options.instanceId,
242240
flavor,
243-
crypto: options.crypto,
244-
fileSystem: options.fileSystem,
245-
idAllocator: options.idAllocator,
246-
host: options.host,
247241
selfInvocation: options.selfInvocation,
248242
// Per-agent exception (see the note above registerMistralVibeAcpExtensions):
249243
// Devin runs commands through client terminals and has no ask mode over
@@ -259,7 +253,7 @@ export function makeAcpRegistryAdapterV2(options: AcpRegistryAdapterV2Options) {
259253
: {}),
260254
...(options.nativeLogging === undefined ? {} : { nativeLogging: options.nativeLogging }),
261255
});
262-
}
256+
});
263257

264258
export type AcpRegistryAdapterV2DriverEnv =
265259
| ChildProcessSpawner.ChildProcessSpawner
@@ -283,29 +277,21 @@ export const AcpRegistryAdapterV2Driver: ProviderAdapterDriver<
283277
const hostEnvironment = yield* HostProcessEnvironment;
284278
const selfInvocation = yield* resolveSelfInvocation();
285279
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
286-
const crypto = yield* Crypto.Crypto;
287-
const fileSystem = yield* FileSystem.FileSystem;
288-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
289280
const providerEventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
290-
const host = yield* ProviderHost.ProviderHost;
291281
const makeNativeLogger = yield* makeAcpNativeLoggerFactory();
292282
const resolver = yield* AcpRegistrySupport.AcpRegistryCatalog;
293283
const runtimeCoordinator = yield* Effect.serviceOption(
294284
AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator,
295285
);
296-
return makeAcpRegistryAdapterV2({
286+
return yield* makeAcpRegistryAdapterV2({
297287
instanceId: input.instanceId,
298288
settings: { ...input.config, enabled: input.enabled },
299289
environment: mergeProviderInstanceEnvironment(input.environment, hostEnvironment),
300290
childProcessSpawner,
301-
crypto,
302-
fileSystem,
303-
idAllocator,
304291
resolver,
305292
...(Option.isSome(runtimeCoordinator)
306293
? { runtimeCoordinator: runtimeCoordinator.value }
307294
: {}),
308-
host,
309295
selfInvocation,
310296
nativeLogging: (threadId) =>
311297
makeNativeLogger({

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const flavor = makeAntigravityAcpAdapterFlavor({
3838
crypto: undefined as never,
3939
fileSystem: undefined as never,
4040
path: undefined as never,
41-
idAllocator: undefined as never,
4241
host: undefined as never,
4342
selfInvocation: undefined as never,
4443
makeRuntime: () => Effect.die("not spawned in this test"),
@@ -149,14 +148,9 @@ describe("AntigravityAdapterV2 client file system", () => {
149148
let writeTextFile: Parameters<RuntimeService["handleWriteTextFile"]>[0] | undefined;
150149
const crypto = yield* Crypto.Crypto;
151150
const instanceId = ProviderInstanceId.make("antigravity-containment-test");
152-
const adapter = makeAntigravityAdapterV2({
151+
const adapter = yield* makeAntigravityAdapterV2({
153152
instanceId,
154-
crypto,
155153
selfInvocation: yield* resolveSelfInvocation(),
156-
fileSystem,
157-
path,
158-
idAllocator: yield* IdAllocator.IdAllocatorV2,
159-
host,
160154
makeRuntime: (input) =>
161155
makeAntigravityAcpRuntime({
162156
...input,
@@ -293,22 +287,16 @@ describe("AntigravityAdapterV2 workspace changes", () => {
293287
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
294288
const fileSystem = yield* FileSystem.FileSystem;
295289
const path = yield* Path.Path;
296-
const host = yield* ProviderHost.ProviderHost;
297290
const crypto = yield* Crypto.Crypto;
298291
const mockAgentPath = yield* path.fromFileUrl(
299292
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
300293
);
301294
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
302295
let readTextFile: Parameters<RuntimeService["handleReadTextFile"]>[0] | undefined;
303296
const instanceId = ProviderInstanceId.make("antigravity-workspace-change-test");
304-
const adapter = makeAntigravityAdapterV2({
297+
const adapter = yield* makeAntigravityAdapterV2({
305298
instanceId,
306-
crypto,
307299
selfInvocation: yield* resolveSelfInvocation(),
308-
fileSystem,
309-
path,
310-
idAllocator: yield* IdAllocator.IdAllocatorV2,
311-
host,
312300
makeRuntime: (input) =>
313301
makeAntigravityAcpRuntime({
314302
...input,
@@ -430,7 +418,6 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
430418
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
431419
const fileSystem = yield* FileSystem.FileSystem;
432420
const path = yield* Path.Path;
433-
const host = yield* ProviderHost.ProviderHost;
434421
const crypto = yield* Crypto.Crypto;
435422
const mockAgentPath = yield* path.fromFileUrl(
436423
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
@@ -451,14 +438,9 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
451438
let readTextFile: Parameters<RuntimeService["handleReadTextFile"]>[0] | undefined;
452439
let writeTextFile: Parameters<RuntimeService["handleWriteTextFile"]>[0] | undefined;
453440
const instanceId = ProviderInstanceId.make(`antigravity-restrictive-${policy.runtimeMode}`);
454-
const adapter = makeAntigravityAdapterV2({
441+
const adapter = yield* makeAntigravityAdapterV2({
455442
instanceId,
456-
crypto,
457443
selfInvocation: yield* resolveSelfInvocation(),
458-
fileSystem,
459-
path,
460-
idAllocator: yield* IdAllocator.IdAllocatorV2,
461-
host,
462444
makeRuntime: (input) =>
463445
makeAntigravityAcpRuntime({
464446
...input,

0 commit comments

Comments
 (0)