-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(providers): add ACP registry for Gemini, Pi, and more #6071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /** | ||
| * AcpRegistryDriver — generic ACP catalog driver. | ||
| * | ||
| * One driver kind covers Gemini, Copilot, Pi, Hermes, Qwen, Kimi, and any | ||
| * custom ACP stdio agent. Launch command/args live on the instance config. | ||
| * | ||
| * @module provider/Drivers/AcpRegistryDriver | ||
| */ | ||
| import { | ||
| AcpRegistrySettings, | ||
| parseAcpLaunchArgs, | ||
| ProviderDriverKind, | ||
| TextGenerationError, | ||
| type ServerProvider, | ||
| } from "@t3tools/contracts"; | ||
| import * as Crypto from "effect/Crypto"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { ChildProcessSpawner } from "effect/unstable/process"; | ||
|
|
||
| import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; | ||
| import { ServerConfig } from "../../config.ts"; | ||
| import { ServerSettingsService } from "../../serverSettings.ts"; | ||
| import { ProviderDriverError } from "../Errors.ts"; | ||
| import { makeGenericAcpAdapter } from "../Layers/GenericAcpAdapter.ts"; | ||
| import { | ||
| buildInitialAcpRegistryProviderSnapshot, | ||
| checkAcpRegistryProviderStatus, | ||
| } from "../Layers/AcpRegistryProvider.ts"; | ||
| import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts"; | ||
| import { makeManagedServerProvider } from "../makeManagedServerProvider.ts"; | ||
| import { | ||
| defaultProviderContinuationIdentity, | ||
| type ProviderDriver, | ||
| type ProviderInstance, | ||
| } from "../ProviderDriver.ts"; | ||
| import type { ServerProviderDraft } from "../providerSnapshot.ts"; | ||
| import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts"; | ||
| import { | ||
| makeManualOnlyProviderMaintenanceCapabilities, | ||
| makeStaticProviderMaintenanceResolver, | ||
| resolveProviderMaintenanceCapabilitiesEffect, | ||
| } from "../providerMaintenance.ts"; | ||
| import { | ||
| haveProviderSnapshotSettingsChanged, | ||
| makeProviderSnapshotSettingsSource, | ||
| type ProviderSnapshotSettings, | ||
| } from "../providerUpdateSettings.ts"; | ||
|
|
||
| const decodeAcpRegistrySettings = Schema.decodeSync(AcpRegistrySettings); | ||
| const DRIVER_KIND = ProviderDriverKind.make("acpRegistry"); | ||
| const UPDATE = makeStaticProviderMaintenanceResolver( | ||
| makeManualOnlyProviderMaintenanceCapabilities({ | ||
| provider: DRIVER_KIND, | ||
| packageName: null, | ||
| }), | ||
| ); | ||
|
|
||
| export type AcpRegistryDriverEnv = | ||
| | BackgroundPolicy.BackgroundPolicy | ||
| | ChildProcessSpawner.ChildProcessSpawner | ||
| | Crypto.Crypto | ||
| | FileSystem.FileSystem | ||
| | Path.Path | ||
| | ProviderEventLoggers | ||
| | ServerConfig | ||
| | ServerSettingsService; | ||
|
|
||
| const unsupportedTextGeneration = (operation: string) => | ||
| Effect.fail( | ||
| new TextGenerationError({ | ||
| operation, | ||
| detail: "Generic ACP providers do not support git text generation yet.", | ||
| }), | ||
| ); | ||
|
|
||
| const makeTextGeneration = () => ({ | ||
| generateCommitMessage: () => unsupportedTextGeneration("generateCommitMessage"), | ||
| generatePrContent: () => unsupportedTextGeneration("generatePrContent"), | ||
| generateBranchName: () => unsupportedTextGeneration("generateBranchName"), | ||
| generateThreadTitle: () => unsupportedTextGeneration("generateThreadTitle"), | ||
| }); | ||
|
|
||
| const withInstanceIdentity = | ||
| (input: { | ||
| readonly instanceId: ProviderInstance["instanceId"]; | ||
| readonly displayName: string | undefined; | ||
| readonly accentColor: string | undefined; | ||
| readonly continuationGroupKey: string; | ||
| }) => | ||
| (snapshot: ServerProviderDraft): ServerProvider => ({ | ||
| ...snapshot, | ||
| instanceId: input.instanceId, | ||
| driver: DRIVER_KIND, | ||
| ...(input.displayName ? { displayName: input.displayName } : {}), | ||
| ...(input.accentColor ? { accentColor: input.accentColor } : {}), | ||
| continuation: { groupKey: input.continuationGroupKey }, | ||
| }); | ||
|
|
||
| export const AcpRegistryDriver: ProviderDriver<AcpRegistrySettings, AcpRegistryDriverEnv> = { | ||
| driverKind: DRIVER_KIND, | ||
| metadata: { | ||
| displayName: "ACP Registry", | ||
| supportsMultipleInstances: true, | ||
| }, | ||
| configSchema: AcpRegistrySettings, | ||
| defaultConfig: (): AcpRegistrySettings => decodeAcpRegistrySettings({}), | ||
| create: ({ instanceId, displayName, accentColor, environment, enabled, config }) => | ||
| Effect.gen(function* () { | ||
| const crypto = yield* Crypto.Crypto; | ||
| const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; | ||
| const serverSettings = yield* ServerSettingsService; | ||
| const eventLoggers = yield* ProviderEventLoggers; | ||
| const processEnv = mergeProviderInstanceEnvironment(environment); | ||
| const continuationIdentity = defaultProviderContinuationIdentity({ | ||
| driverKind: DRIVER_KIND, | ||
| instanceId, | ||
| }); | ||
| const stampIdentity = withInstanceIdentity({ | ||
| instanceId, | ||
| displayName, | ||
| accentColor, | ||
| continuationGroupKey: continuationIdentity.continuationKey, | ||
| }); | ||
| const effectiveConfig = { ...config, enabled } satisfies AcpRegistrySettings; | ||
| const maintenanceCapabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(UPDATE, { | ||
| binaryPath: effectiveConfig.command, | ||
| env: processEnv, | ||
| }); | ||
|
|
||
| const adapter = yield* makeGenericAcpAdapter( | ||
| { | ||
| enabled: effectiveConfig.enabled, | ||
| command: effectiveConfig.command.trim() || "acp", | ||
| args: parseAcpLaunchArgs(effectiveConfig.launchArgs), | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty command spawns acp binaryMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit bba5635. Configure here. |
||
| { | ||
| provider: DRIVER_KIND, | ||
| instanceId, | ||
| environment: processEnv, | ||
| readyReason: "ACP session ready", | ||
| ...(effectiveConfig.authMethodId.trim() | ||
| ? { authMethodId: effectiveConfig.authMethodId.trim() } | ||
| : {}), | ||
| ...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}), | ||
| }, | ||
| ); | ||
|
|
||
| const checkProvider = checkAcpRegistryProviderStatus(effectiveConfig, processEnv).pipe( | ||
| Effect.map(stampIdentity), | ||
| Effect.provideService(Crypto.Crypto, crypto), | ||
| Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), | ||
| ); | ||
|
|
||
| const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, serverSettings); | ||
| const snapshot = yield* makeManagedServerProvider< | ||
| ProviderSnapshotSettings<AcpRegistrySettings> | ||
| >({ | ||
| maintenanceCapabilities, | ||
| getSettings: snapshotSettings.getSettings, | ||
| streamSettings: snapshotSettings.streamSettings, | ||
| haveSettingsChanged: haveProviderSnapshotSettingsChanged, | ||
| initialSnapshot: (settings) => | ||
| buildInitialAcpRegistryProviderSnapshot(settings.provider).pipe( | ||
| Effect.map(stampIdentity), | ||
| ), | ||
| checkProvider, | ||
| }).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new ProviderDriverError({ | ||
| driver: DRIVER_KIND, | ||
| instanceId, | ||
| detail: `Failed to build ACP Registry snapshot: ${cause.message ?? String(cause)}`, | ||
| cause, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| return { | ||
| instanceId, | ||
| driverKind: DRIVER_KIND, | ||
| continuationIdentity, | ||
| displayName, | ||
| accentColor, | ||
| enabled, | ||
| snapshot, | ||
| adapter, | ||
| textGeneration: makeTextGeneration(), | ||
| } satisfies ProviderInstance; | ||
| }), | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { AcpRegistrySettings } from "@t3tools/contracts"; | ||
|
|
||
| import { | ||
| buildInitialAcpRegistryProviderSnapshot, | ||
| checkAcpRegistryProviderStatus, | ||
| } from "./AcpRegistryProvider.ts"; | ||
|
|
||
| const decodeSettings = Schema.decodeSync(AcpRegistrySettings); | ||
|
|
||
| describe("buildInitialAcpRegistryProviderSnapshot", () => { | ||
| it.effect("returns a disabled snapshot when settings.enabled is false", () => | ||
| Effect.gen(function* () { | ||
| const snapshot = yield* buildInitialAcpRegistryProviderSnapshot( | ||
| decodeSettings({ enabled: false, catalogId: "gemini", command: "gemini" }), | ||
| ); | ||
| expect(snapshot.enabled).toBe(false); | ||
| expect(snapshot.status).toBe("disabled"); | ||
| expect(snapshot.displayName).toBe("Gemini"); | ||
| expect(snapshot.message).toContain("disabled"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("asks for a launch command when none is configured", () => | ||
| Effect.gen(function* () { | ||
| const snapshot = yield* buildInitialAcpRegistryProviderSnapshot( | ||
| decodeSettings({ enabled: true, catalogId: "gemini" }), | ||
| ); | ||
| expect(snapshot.enabled).toBe(false); | ||
| expect(snapshot.status).toBe("disabled"); | ||
| expect(snapshot.message).toMatch(/launch command/i); | ||
| expect(snapshot.message).toContain("gemini"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("returns a pending snapshot while probing a configured command", () => | ||
| Effect.gen(function* () { | ||
| const snapshot = yield* buildInitialAcpRegistryProviderSnapshot( | ||
| decodeSettings({ enabled: true, catalogId: "gemini", command: "gemini" }), | ||
| ); | ||
| expect(snapshot.enabled).toBe(true); | ||
| expect(snapshot.installed).toBe(true); | ||
| expect(snapshot.status).toBe("warning"); | ||
| expect(snapshot.message).toContain("Checking ACP"); | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it.layer(NodeServices.layer)("checkAcpRegistryProviderStatus", (it) => { | ||
| it.effect("reports the command as missing when it does not resolve", () => | ||
| Effect.gen(function* () { | ||
| const snapshot = yield* checkAcpRegistryProviderStatus( | ||
| decodeSettings({ | ||
| enabled: true, | ||
| catalogId: "gemini", | ||
| command: "/definitely/not/installed/gemini-acp", | ||
| }), | ||
| ); | ||
| expect(snapshot.enabled).toBe(true); | ||
| expect(snapshot.installed).toBe(false); | ||
| expect(snapshot.status).toBe("error"); | ||
| expect(snapshot.message).toMatch(/not installed|not on PATH/i); | ||
| }), | ||
| ); | ||
| }); |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
Drivers/AcpRegistryDriver.ts:136An enabled ACP instance with a blank
commandsilently launches an executable namedacpfromPATHinstead of rejecting the invalid configuration. ThemakeGenericAcpAdaptercall useseffectiveConfig.command.trim() || "acp", so an empty command falls back to the literal string"acp", bypassing the blank-command validation the adapter would otherwise enforce. This contradicts the snapshot/probe path, which treats a blank command as unconfigured/disabled. Require a non-emptycommandfor enabled ACP instances — or at minimum drop the|| "acp"fallback so the adapter's own validation rejects the empty value.Also found in 1 other location(s)
packages/contracts/src/settings.ts:434🤖 Copy this AI Prompt to have your agent fix this: