Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Docs:

- Codex App Server docs: https://developers.openai.com/codex/sdk/#app-server

## ACP Registry

In addition to the four bespoke providers (Codex, Claude, Cursor, OpenCode),
T3 Code bundles a snapshot of the
[Agent Client Protocol registry](https://agentclientprotocol.com/get-started/registry)
and exposes a Zed-style installer at **Settings → ACP Registry**. See
[docs/providers/acp-registry.md](./docs/providers/acp-registry.md) for the
install pipeline, distribution channels, and how to refresh the bundled
snapshot (`bun run sync:acp-registry`).

## Reference Repos

- Open-source Codex repo: https://github.com/openai/codex
Expand Down
134 changes: 134 additions & 0 deletions apps/server/src/acpRegistry/AcpRegistryService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import {
ACP_REGISTRY,
acpRegistryEntryById,
AcpRegistryError,
type AcpRegistryEntry,
type AcpRegistryEntryWithStatus,
type AcpRegistryInstallState,
type AcpRegistryInstallStatus,
} from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Schema from "effect/Schema";

import { ServerConfig } from "../config.ts";
import { ServerSettingsService } from "../serverSettings.ts";

import { availableChannels, installAgent, uninstallAgent } from "./installer.ts";
import { resolveCurrentPlatform } from "./platform.ts";

export interface AcpRegistryServiceShape {
readonly list: () => Effect.Effect<ReadonlyArray<AcpRegistryEntryWithStatus>, AcpRegistryError>;
readonly install: (agentId: string) => Effect.Effect<AcpRegistryInstallState, AcpRegistryError>;
readonly uninstall: (agentId: string) => Effect.Effect<void, AcpRegistryError>;
}

export class AcpRegistryService extends Context.Service<
AcpRegistryService,
AcpRegistryServiceShape
>()("t3/acpRegistry/AcpRegistryService") {}

export const layer: Layer.Layer<AcpRegistryService, never, ServerConfig | ServerSettingsService> =
Layer.effect(
AcpRegistryService,
Effect.gen(function* () {
const config = yield* ServerConfig;
const settingsService = yield* ServerSettingsService;
const platform = resolveCurrentPlatform();
const cacheRoot = config.acpRegistryCacheDir;

const wrapSettingsError = (detail: string) => (cause: unknown) =>
new AcpRegistryError({ detail, cause });

const readInstalls = settingsService.getSettings.pipe(
Effect.map((s) => s.acpRegistryInstalls),
Effect.mapError(wrapSettingsError("Failed to read server settings")),
);

const writeInstalls = (next: Readonly<Record<string, AcpRegistryInstallState>>) =>
settingsService
.updateSettings({ acpRegistryInstalls: next })
.pipe(
Effect.asVoid,
Effect.mapError(wrapSettingsError("Failed to persist server settings")),
);

const requireEntry = (agentId: string): Effect.Effect<AcpRegistryEntry, AcpRegistryError> => {
const entry = acpRegistryEntryById(agentId);
return entry
? Effect.succeed(entry)
: Effect.fail(new AcpRegistryError({ agentId, detail: "Unknown ACP registry agent." }));
};

const isAcpRegistryError = Schema.is(AcpRegistryError);
const toAcpRegistryError =
(agentId: string, fallback: string) =>
(cause: unknown): AcpRegistryError => {
if (isAcpRegistryError(cause)) return cause;
return new AcpRegistryError({
agentId,
detail: cause instanceof Error ? cause.message : fallback,
cause,
});
};

return {
list: () =>
Effect.gen(function* () {
const installs = yield* readInstalls;
return ACP_REGISTRY.map((entry) =>
buildEntryStatus(entry, installs[entry.id], availableChannels(entry, platform)),
);
}),

install: (agentId) =>
Effect.gen(function* () {
const entry = yield* requireEntry(agentId);
const result = yield* Effect.tryPromise({
try: () => installAgent(entry, { cacheRoot }),
catch: toAcpRegistryError(agentId, "Install failed"),
});
const installs = yield* readInstalls;
yield* writeInstalls({ ...installs, [agentId]: result.state });
return result.state;
}),

uninstall: (agentId) =>
Effect.gen(function* () {
const entry = yield* requireEntry(agentId);
yield* Effect.tryPromise({
try: () => uninstallAgent(entry, cacheRoot),
catch: toAcpRegistryError(agentId, "Uninstall failed"),
});
const installs = yield* readInstalls;
if (!(agentId in installs)) return;
const { [agentId]: _removed, ...rest } = installs;
yield* writeInstalls(rest);
}),
} satisfies AcpRegistryServiceShape;
}),
);

function buildEntryStatus(
entry: AcpRegistryEntry,
installed: AcpRegistryInstallState | undefined,
channels: ReadonlyArray<ReturnType<typeof availableChannels>[number]>,
): AcpRegistryEntryWithStatus {
return {
entry,
availableChannels: channels,
status: rollupStatus(entry, installed, channels),
...(installed ? { installed } : {}),
};
}

function rollupStatus(
entry: AcpRegistryEntry,
installed: AcpRegistryInstallState | undefined,
channels: ReadonlyArray<ReturnType<typeof availableChannels>[number]>,
): AcpRegistryInstallStatus {
if (channels.length === 0) return "unsupported";
if (!installed) return "not_installed";
return installed.version === entry.version ? "installed" : "update_available";
}
Loading
Loading