feat(server): add Hermes ACP spawn support
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
2 files changed
+105
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
|
||||
import { buildHermesAcpSpawnInput, HERMES_AUTH_METHOD_ID } from "./HermesAcpSupport.ts";
|
||||
|
||||
describe("buildHermesAcpSpawnInput", () => {
|
||||
it("spawns the configured binary with the acp subcommand", () => {
|
||||
const spawn = buildHermesAcpSpawnInput({ binaryPath: "/opt/hermes" }, "/tmp/project", {
|
||||
PATH: "/usr/bin",
|
||||
});
|
||||
|
||||
expect(spawn).toEqual({
|
||||
command: "/opt/hermes",
|
||||
args: ["acp"],
|
||||
cwd: "/tmp/project",
|
||||
env: {
|
||||
PATH: "/usr/bin",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the default binary name", () => {
|
||||
const spawn = buildHermesAcpSpawnInput({ binaryPath: "" }, "/tmp/project");
|
||||
expect(spawn.command).toBe("hermes");
|
||||
});
|
||||
|
||||
it("falls back when settings are absent", () => {
|
||||
const spawn = buildHermesAcpSpawnInput(null, "/tmp/project");
|
||||
expect(spawn.command).toBe("hermes");
|
||||
});
|
||||
|
||||
it("omits env entirely when no environment is provided", () => {
|
||||
const spawn = buildHermesAcpSpawnInput({ binaryPath: "/opt/hermes" }, "/tmp/project");
|
||||
expect(spawn).toEqual({
|
||||
command: "/opt/hermes",
|
||||
args: ["acp"],
|
||||
cwd: "/tmp/project",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("HERMES_AUTH_METHOD_ID", () => {
|
||||
it("targets the Hermes custom-credentials auth method", () => {
|
||||
expect(HERMES_AUTH_METHOD_ID).toBe("custom");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { HermesSettings } from "@t3tools/contracts";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
|
||||
import * as EffectAcpErrors from "effect-acp/errors";
|
||||
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
|
||||
/** Auth method advertised by `hermes acp` for pre-configured runtime credentials. */
|
||||
export const HERMES_AUTH_METHOD_ID = "custom";
|
||||
|
||||
type HermesAcpRuntimeHermesSettings = Pick<HermesSettings, "binaryPath">;
|
||||
|
||||
interface HermesAcpRuntimeInput extends Omit<
|
||||
AcpSessionRuntime.AcpSessionRuntimeOptions,
|
||||
"authMethodId" | "clientCapabilities" | "spawn"
|
||||
> {
|
||||
readonly childProcessSpawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
|
||||
readonly hermesSettings: HermesAcpRuntimeHermesSettings | null | undefined;
|
||||
readonly environment?: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
export function buildHermesAcpSpawnInput(
|
||||
hermesSettings: HermesAcpRuntimeHermesSettings | null | undefined,
|
||||
cwd: string,
|
||||
environment?: NodeJS.ProcessEnv,
|
||||
): AcpSessionRuntime.AcpSpawnInput {
|
||||
return {
|
||||
command: hermesSettings?.binaryPath || "hermes",
|
||||
args: ["acp"],
|
||||
cwd,
|
||||
...(environment ? { env: environment } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export const makeHermesAcpRuntime = (
|
||||
input: HermesAcpRuntimeInput,
|
||||
): Effect.Effect<
|
||||
AcpSessionRuntime.AcpSessionRuntime["Service"],
|
||||
EffectAcpErrors.AcpError,
|
||||
Crypto.Crypto | Scope.Scope
|
||||
> =>
|
||||
Effect.gen(function* () {
|
||||
const acpContext = yield* Layer.build(
|
||||
AcpSessionRuntime.layer({
|
||||
...input,
|
||||
spawn: buildHermesAcpSpawnInput(input.hermesSettings, input.cwd, input.environment),
|
||||
authMethodId: HERMES_AUTH_METHOD_ID,
|
||||
}).pipe(
|
||||
Layer.provide(
|
||||
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, input.childProcessSpawner),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* Effect.service(AcpSessionRuntime.AcpSessionRuntime).pipe(
|
||||
Effect.provide(acpContext),
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user