Add generic ACP adapter support

- Route ACP registry sessions through a generic ACP runtime
- Make ACP auth optional and skip Cursor-only extensions for generic providers
This commit is contained in:
Julius Marminge committed 2026-05-04 01:18:22 -07:00
1 parent 94eedd7c77
commit 1d1d67c4bd
5 files changed
+214 -109

No files matched your search

@@ -9,7 +9,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
import { ServerConfig } from "../../config.ts";
import { ProviderDriverError } from "../Errors.ts";
import { makeCursorAdapter } from "../Layers/CursorAdapter.ts";
import { makeGenericAcpAdapter } from "../Layers/GenericAcpAdapter.ts";
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
import {
@@ -123,11 +123,10 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
continuationGroupKey: continuationIdentity.continuationKey,
});
const adapter = yield* makeCursorAdapter(
const adapter = yield* makeGenericAcpAdapter(
{
enabled: effectiveConfig.enabled,
binaryPath: effectiveConfig.command || "acp",
apiEndpoint: "",
customModels: effectiveConfig.customModels,
},
{
@@ -135,8 +134,6 @@ export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryD
instanceId,
environment: processEnv,
readyReason: "ACP session ready",
applyCursorModelOptions: false,
normalizeModel: (model) => model?.trim() || "default",
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
spawn: ({ cwd, environment: spawnEnv }) => ({
command: effectiveConfig.command.trim(),
+134 -95
View File
@@ -65,6 +65,7 @@ import {
} from "../acp/AcpRuntimeModel.ts";
import { makeAcpNativeLoggers } from "../acp/AcpNativeLogging.ts";
import { applyCursorAcpModelSelection, makeCursorAcpRuntime } from "../acp/CursorAcpSupport.ts";
import { makeGenericAcpRuntime } from "../acp/GenericAcpSupport.ts";
import {
CursorAskQuestionRequest,
CursorCreatePlanRequest,
@@ -101,6 +102,9 @@ export interface CursorAdapterLiveOptions {
};
readonly normalizeModel?: (model: string | null | undefined) => string;
readonly applyCursorModelOptions?: boolean;
readonly cursorExtensions?: boolean;
readonly authMethodId?: string | undefined;
readonly clientCapabilities?: EffectAcpSchema.InitializeRequest["clientCapabilities"];
/**
* Selections are honored when `modelSelection.instanceId` matches this value.
* Defaults to the legacy built-in instance id (`cursor`).
@@ -338,6 +342,7 @@ export function makeCursorAdapter(
const readyReason = options?.readyReason ?? "Cursor ACP session ready";
const normalizeModel = options?.normalizeModel ?? resolveCursorAcpBaseModelId;
const applyCursorModelOptions = options?.applyCursorModelOptions ?? true;
const cursorExtensions = options?.cursorExtensions ?? true;
const boundInstanceId = options?.instanceId ?? ProviderInstanceId.make("cursor");
const fileSystem = yield* FileSystem.FileSystem;
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -530,24 +535,53 @@ export function makeCursorAdapter(
? yield* options.resolveSettings
: cursorSettings;
const acp = yield* makeCursorAcpRuntime({
cursorSettings: effectiveCursorSettings,
...(options?.environment ? { environment: options.environment } : {}),
...(options?.spawn
? {
spawn: options.spawn({
settings: effectiveCursorSettings,
cwd,
...(options.environment ? { environment: options.environment } : {}),
}),
}
: {}),
childProcessSpawner,
cwd,
...(resumeSessionId ? { resumeSessionId } : {}),
clientInfo: { name: "t3-code", version: "0.0.0" },
...acpNativeLoggers,
}).pipe(
const spawn = options?.spawn
? options.spawn({
settings: effectiveCursorSettings,
cwd,
...(options.environment ? { environment: options.environment } : {}),
})
: undefined;
const acp = yield* (
cursorExtensions
? makeCursorAcpRuntime({
cursorSettings: effectiveCursorSettings,
...(options?.environment ? { environment: options.environment } : {}),
...(spawn ? { spawn } : {}),
childProcessSpawner,
cwd,
...(resumeSessionId ? { resumeSessionId } : {}),
clientInfo: { name: "t3-code", version: "0.0.0" },
...acpNativeLoggers,
})
: makeGenericAcpRuntime({
spawn:
spawn ??
(() => {
const fallback = options?.spawn?.({
settings: effectiveCursorSettings,
cwd,
...(options.environment ? { environment: options.environment } : {}),
});
if (fallback) return fallback;
return {
command: effectiveCursorSettings.binaryPath,
args: [],
cwd,
...(options?.environment ? { env: options.environment } : {}),
};
})(),
childProcessSpawner,
cwd,
...(resumeSessionId ? { resumeSessionId } : {}),
clientInfo: { name: "t3-code", version: "0.0.0" },
...(options?.authMethodId ? { authMethodId: options.authMethodId } : {}),
...(options?.clientCapabilities
? { clientCapabilities: options.clientCapabilities }
: {}),
...acpNativeLoggers,
})
).pipe(
Effect.provideService(Scope.Scope, sessionScope),
Effect.mapError(
(cause) =>
@@ -560,92 +594,97 @@ export function makeCursorAdapter(
),
);
const started = yield* Effect.gen(function* () {
yield* acp.handleExtRequest("cursor/ask_question", CursorAskQuestionRequest, (params) =>
Effect.gen(function* () {
yield* logNative(
input.threadId,
"cursor/ask_question",
params,
"acp.cursor.extension",
);
const requestId = ApprovalRequestId.make(crypto.randomUUID());
const runtimeRequestId = RuntimeRequestId.make(requestId);
const answers = yield* Deferred.make<ProviderUserInputAnswers>();
pendingUserInputs.set(requestId, { answers });
yield* offerRuntimeEvent({
type: "user-input.requested",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
requestId: runtimeRequestId,
payload: { questions: extractAskQuestions(params) },
raw: {
source: "acp.cursor.extension",
method: "cursor/ask_question",
payload: params,
},
});
const resolved = yield* Deferred.await(answers);
pendingUserInputs.delete(requestId);
yield* offerRuntimeEvent({
type: "user-input.resolved",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
requestId: runtimeRequestId,
payload: { answers: resolved },
});
return { answers: resolved };
}),
);
yield* acp.handleExtRequest("cursor/create_plan", CursorCreatePlanRequest, (params) =>
Effect.gen(function* () {
yield* logNative(
input.threadId,
"cursor/create_plan",
params,
"acp.cursor.extension",
);
yield* offerRuntimeEvent({
type: "turn.proposed.completed",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
payload: { planMarkdown: extractPlanMarkdown(params) },
raw: {
source: "acp.cursor.extension",
method: "cursor/create_plan",
payload: params,
},
});
return { accepted: true } as const;
}),
);
yield* acp.handleExtNotification(
"cursor/update_todos",
CursorUpdateTodosRequest,
(params) =>
if (cursorExtensions) {
yield* acp.handleExtRequest(
"cursor/ask_question",
CursorAskQuestionRequest,
(params) =>
Effect.gen(function* () {
yield* logNative(
input.threadId,
"cursor/ask_question",
params,
"acp.cursor.extension",
);
const requestId = ApprovalRequestId.make(crypto.randomUUID());
const runtimeRequestId = RuntimeRequestId.make(requestId);
const answers = yield* Deferred.make<ProviderUserInputAnswers>();
pendingUserInputs.set(requestId, { answers });
yield* offerRuntimeEvent({
type: "user-input.requested",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
requestId: runtimeRequestId,
payload: { questions: extractAskQuestions(params) },
raw: {
source: "acp.cursor.extension",
method: "cursor/ask_question",
payload: params,
},
});
const resolved = yield* Deferred.await(answers);
pendingUserInputs.delete(requestId);
yield* offerRuntimeEvent({
type: "user-input.resolved",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
requestId: runtimeRequestId,
payload: { answers: resolved },
});
return { answers: resolved };
}),
);
yield* acp.handleExtRequest("cursor/create_plan", CursorCreatePlanRequest, (params) =>
Effect.gen(function* () {
yield* logNative(
input.threadId,
"cursor/update_todos",
"cursor/create_plan",
params,
"acp.cursor.extension",
);
if (ctx) {
yield* emitPlanUpdate(
ctx,
extractTodosAsPlan(params),
yield* offerRuntimeEvent({
type: "turn.proposed.completed",
...(yield* makeEventStamp()),
provider: providerKind,
threadId: input.threadId,
turnId: ctx?.activeTurnId,
payload: { planMarkdown: extractPlanMarkdown(params) },
raw: {
source: "acp.cursor.extension",
method: "cursor/create_plan",
payload: params,
},
});
return { accepted: true } as const;
}),
);
yield* acp.handleExtNotification(
"cursor/update_todos",
CursorUpdateTodosRequest,
(params) =>
Effect.gen(function* () {
yield* logNative(
input.threadId,
"cursor/update_todos",
params,
"acp.cursor.extension",
"cursor/update_todos",
);
}
}),
);
if (ctx) {
yield* emitPlanUpdate(
ctx,
extractTodosAsPlan(params),
params,
"acp.cursor.extension",
"cursor/update_todos",
);
}
}),
);
}
yield* acp.handleRequestPermission((params) =>
Effect.gen(function* () {
yield* logNative(
@@ -0,0 +1,38 @@
import {
type CursorSettings,
type ProviderDriverKind,
type ProviderInstanceId,
} from "@t3tools/contracts";
import type * as EffectAcpSchema from "effect-acp/schema";
import { makeCursorAdapter, type CursorAdapterLiveOptions } from "./CursorAdapter.ts";
type GenericAcpAdapterSettings = Pick<CursorSettings, "enabled" | "binaryPath" | "customModels">;
type GenericAcpAdapterOptions = Omit<
CursorAdapterLiveOptions,
"applyCursorModelOptions" | "authMethodId" | "clientCapabilities" | "cursorExtensions"
> & {
readonly provider: ProviderDriverKind;
readonly instanceId: typeof ProviderInstanceId.Type;
readonly authMethodId?: string | undefined;
readonly clientCapabilities?: EffectAcpSchema.InitializeRequest["clientCapabilities"];
};
export function makeGenericAcpAdapter(
settings: GenericAcpAdapterSettings,
options: GenericAcpAdapterOptions,
) {
return makeCursorAdapter(
{
...settings,
apiEndpoint: "",
},
{
...options,
applyCursorModelOptions: false,
cursorExtensions: false,
normalizeModel: options.normalizeModel ?? ((model) => model?.trim() || "default"),
},
);
}
@@ -33,7 +33,7 @@ export interface AcpSessionRuntimeOptions {
readonly name: string;
readonly version: string;
};
readonly authMethodId: string;
readonly authMethodId?: string;
readonly requestLogger?: (event: AcpSessionRequestLogEvent) => Effect.Effect<void, never>;
readonly protocolLogging?: {
readonly logIncoming?: boolean;
@@ -365,15 +365,17 @@ const makeAcpSessionRuntime = (
acp.agent.initialize(initializePayload),
);
const authenticatePayload = {
methodId: options.authMethodId,
} satisfies EffectAcpSchema.AuthenticateRequest;
if (options.authMethodId) {
const authenticatePayload = {
methodId: options.authMethodId,
} satisfies EffectAcpSchema.AuthenticateRequest;
yield* runLoggedRequest(
"authenticate",
authenticatePayload,
acp.agent.authenticate(authenticatePayload),
);
yield* runLoggedRequest(
"authenticate",
authenticatePayload,
acp.agent.authenticate(authenticatePayload),
);
}
let sessionId: string;
let sessionSetupResult:
@@ -0,0 +1,29 @@
import { Effect, Layer, Scope } from "effect";
import { ChildProcessSpawner } from "effect/unstable/process";
import type * as EffectAcpErrors from "effect-acp/errors";
import {
AcpSessionRuntime,
type AcpSessionRuntimeOptions,
type AcpSessionRuntimeShape,
type AcpSpawnInput,
} from "./AcpSessionRuntime.ts";
export interface GenericAcpRuntimeInput extends Omit<AcpSessionRuntimeOptions, "spawn"> {
readonly childProcessSpawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
readonly spawn: AcpSpawnInput;
}
export const makeGenericAcpRuntime = (
input: GenericAcpRuntimeInput,
): Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope> =>
Effect.gen(function* () {
const acpContext = yield* Layer.build(
AcpSessionRuntime.layer(input).pipe(
Layer.provide(
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, input.childProcessSpawner),
),
),
);
return yield* Effect.service(AcpSessionRuntime).pipe(Effect.provide(acpContext));
});