diff --git a/docs/custom-providers.md b/docs/custom-providers.md index ef0281ec7f..d9ff8a1e5d 100644 --- a/docs/custom-providers.md +++ b/docs/custom-providers.md @@ -514,7 +514,7 @@ The [Agent Client Protocol (ACP)](https://agentclientprotocol.com) is an open st ACP agents communicate over JSON-RPC 2.0 on stdio. Paseo spawns the agent process and talks to it through stdin/stdout. -Paseo also ships an in-app ACP provider catalog for common agents, including CodeWhale, Cursor, DeepAgents, DimCode, Gemini CLI, Hermes, Qwen Code, and Kimi Code. Most catalog entries create the same `extends: "acp"` provider config shown below. Hoplite activates its [bundled provider](plugins.md#built-in-plugins) instead. +Paseo also ships an in-app ACP provider catalog for common agents, including CodeWhale, Cursor, DeepAgents, DimCode, Gemini CLI, Hermes, Qwen Code, and Kimi Code. Most catalog entries create the same `extends: "acp"` provider config shown below. Goose, Hermes, and Hoplite activate their [bundled providers](plugins.md#built-in-plugins) instead. An existing `extends: "acp"` entry for goose or Hermes migrates to the bundled provider on load and keeps a custom command. Hermes agents saved with the old adapter resume with their mode translated (`plugins/hermes-provider/server/legacy-modes.ts`). ### Adding a generic ACP provider @@ -627,32 +627,6 @@ ACP probes use short timeouts and browser-suppression environment variables so a Ref: [Gemini CLI ACP mode docs](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/acp-mode.md) -### Example: Hermes (Nous Research) - -[Hermes](https://github.com/NousResearch/hermes-agent) is an open-source coding agent by Nous Research with persistent memory and multi-provider LLM support. It supports ACP via the `acp` subcommand. - -1. Install: `curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash` -2. Install ACP support: `pip install -e '.[acp]'` -3. Configure Hermes credentials in `~/.hermes/` -4. Add to config.json: - -```json -{ - "agents": { - "providers": { - "hermes": { - "extends": "acp", - "label": "Hermes", - "description": "Nous Research self-improving AI agent", - "command": ["hermes", "acp"] - } - } - } -} -``` - -Ref: [Hermes ACP docs](https://hermes-agent.nousresearch.com/docs/user-guide/features/acp) - ### How ACP providers work in Paseo When you launch an agent with an ACP provider: @@ -853,12 +827,6 @@ A config.json with multiple custom providers: "extends": "acp", "label": "Google Gemini", "command": ["gemini", "--acp"] - }, - - "hermes": { - "extends": "acp", - "label": "Hermes", - "command": ["hermes", "acp"] } } } diff --git a/docs/plugins.md b/docs/plugins.md index e370283a11..4fd8d84cc9 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -118,7 +118,7 @@ appear in the plugin catalog. Editing one in development requires a daemon resta Directory, Git, and npm installs cannot use a built-in ID. A provider registration with `requiresConfiguration: true` participates only while its ID exists -under `agents.providers`. Hoplite and fx use this for catalog opt-in. Add writes `{ "enabled": true }` +under `agents.providers`. Hoplite, fx, goose, and Hermes use this for catalog opt-in. Add writes `{ "enabled": true }` without `extends`, so it selects the bundled adapter. Remove deletes the config entry; setting `enabled: false` keeps the entry. The bundled JavaScript still loads at startup, but an absent provider does not enter executable resolution or catalog discovery. @@ -583,8 +583,12 @@ daemon launch from `connect` and the per-session env and MCP servers from `sessi no provider reload input. For an ACP command, register `runAcpProvider({ id, label, command })` from -`@getpaseo/plugin/server/acp`. Its transformer hooks cover narrow vendor differences; do not translate the -whole provider event stream. The shim uses the resolved launch for every probe and session, overlaying +`@getpaseo/plugin/server/acp`. The shim builds the standard row for each ACP tool `kind` +(`acp-internal/tool-call-detail.ts`). Its transformer hooks cover narrow vendor differences; do not translate the +whole provider event stream. A `toolCall` transformer sees the raw `input`, `output` and `content`, and a +`detail` it sets replaces the standard row. Parse vendor display text defensively and return the call +unchanged when the shape does not match, so an upstream format change falls back to the standard row +(`plugins/hermes-provider/server/terminal-command.ts`). The shim uses the resolved launch for every probe and session, overlaying only the supplied per-session env for sessions. The direct and ACP examples live in `plugin-examples/provider-direct` and `plugin-examples/provider-acp-transformer`. diff --git a/packages/app/src/data/acp-provider-catalog.ts b/packages/app/src/data/acp-provider-catalog.ts index 0bcc218bbf..23c388e5b8 100644 --- a/packages/app/src/data/acp-provider-catalog.ts +++ b/packages/app/src/data/acp-provider-catalog.ts @@ -244,6 +244,7 @@ const CATALOG_DATA = [ }, { id: "hermes", + bundledProvider: { hostFeature: "hermesProvider" }, title: "Hermes", description: "Nous Research self-improving AI agent", version: "manual", diff --git a/packages/app/src/hooks/use-acp-provider-catalog.test.ts b/packages/app/src/hooks/use-acp-provider-catalog.test.ts index 9713a87cfa..3220fed57b 100644 --- a/packages/app/src/hooks/use-acp-provider-catalog.test.ts +++ b/packages/app/src/hooks/use-acp-provider-catalog.test.ts @@ -151,20 +151,26 @@ describe("ACP provider catalog", () => { }); }); -it("adds bundled goose on capable hosts and uses the ACP config on older hosts", () => { - const goose = findProvider("goose"); - expect(buildAcpProviderConfigPatch(goose, (feature) => feature === "gooseProvider")).toEqual({ - providers: { goose: { enabled: true } }, - }); - expect(buildAcpProviderConfigPatch(goose)).toEqual({ - providers: { - goose: { - extends: "acp", - label: "goose", - description: goose.description, - command: ["goose", "acp"], - env: {}, +it.each([ + { id: "goose", feature: "gooseProvider" }, + { id: "hermes", feature: "hermesProvider" }, +] as const)( + "adds bundled $id on capable hosts and uses the ACP config on older hosts", + ({ id, feature }) => { + const entry = findProvider(id); + expect(buildAcpProviderConfigPatch(entry, (supported) => supported === feature)).toEqual({ + providers: { [id]: { enabled: true } }, + }); + expect(buildAcpProviderConfigPatch(entry)).toEqual({ + providers: { + [id]: { + extends: "acp", + label: entry.title, + description: entry.description, + command: [id, "acp"], + env: {}, + }, }, - }, - }); -}); + }); + }, +); diff --git a/packages/app/src/hooks/use-acp-provider-catalog.ts b/packages/app/src/hooks/use-acp-provider-catalog.ts index 8bd31c05de..f81cd37adf 100644 --- a/packages/app/src/hooks/use-acp-provider-catalog.ts +++ b/packages/app/src/hooks/use-acp-provider-catalog.ts @@ -24,9 +24,10 @@ export function buildAcpProviderConfigPatch( return { providers: { [entry.id]: { enabled: true } } }; } // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once host floor includes the bundled adapter. + // COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once host floor includes the bundled adapter. // COMPAT(hopliteProvider): added after v0.11.2, remove after 2027-04-15 once host floor includes the bundled adapter. // COMPAT(fxProvider): added after v0.15.3, remove after 2027-05-09 once host floor includes the bundled adapter. - if (feature !== "gooseProvider") { + if (feature !== "gooseProvider" && feature !== "hermesProvider") { throw new Error(`Update the host to add ${entry.title}.`); } } diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index 36375e4955..bc7c73cd83 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -13,14 +13,15 @@ import { type RequestPermissionRequest, type RequestPermissionResponse, type SessionConfigOption, + type SessionInfo, type SessionNotification, type SessionUpdate, type ToolCall, - type ToolCallContent, type ToolCallUpdate, type Stream, } from "@agentclientprotocol/sdk"; import { z } from "zod"; +import type { JsonValue } from "@getpaseo/protocol/agent-types"; import type { AcpConfigAccess, AcpConfigChange, @@ -31,6 +32,7 @@ import type { AcpVendorUpdate, RunAcpProviderOptions, } from "../acp.js"; +import { standardToolCallDetail } from "./tool-call-detail.js"; import { PROVIDER_PROTOCOL_VERSION, ProviderEventSchema, @@ -48,6 +50,7 @@ import { type ProviderLaunch, type ProviderModel, type ProviderPermissionResponse, + type ProviderToolCallDetail, type ProviderPersistence, type ProviderSessionConfig, type ProviderSetting, @@ -296,8 +299,7 @@ async function listSessions( emit: state.emit, }); try { - const response = await runtime.listSessions(input.cwd); - const selected = input.limit ? response.sessions.slice(0, input.limit) : response.sessions; + const selected = await runtime.listSessions({ cwd: input.cwd, limit: input.limit }); state.emit({ type: "sessions", requestId: input.requestId, @@ -408,14 +410,14 @@ interface ActivePrompt { } const DEFAULT_DEFERRED_SETTLE_DELAY_MS = 500; +const SESSION_SCAN_LIMIT = 500; +// COMPAT(acpAutoAccept): added in v0.17.4, remove after 2027-05-23. The generic ACP adapter saves +// its Auto Accept toggle as this setting on agents that later moved to a bundled ACP provider. +const LEGACY_AUTO_ACCEPT_SETTING = "auto_accept"; const DEFAULT_DEFERRED_QUIET_LIMIT_MS = 120_000; -type AcpToolCallSource = AcpToolCallSnapshot & { - diff?: Extract; -}; - interface AcpToolCallState { - source: AcpToolCallSource; + source: AcpToolCallSnapshot; presentation: AcpToolCallSnapshot; } @@ -916,8 +918,17 @@ class AcpRuntime { return true; } - listSessions(cwd?: string) { - return this.call(this.connection.listSessions({ cwd })); + /** Follows `nextCursor` until `limit` sessions, the last page, or the scan cap. */ + async listSessions({ cwd, limit }: { cwd?: string; limit?: number }): Promise { + const wanted = Math.min(limit ?? SESSION_SCAN_LIMIT, SESSION_SCAN_LIMIT); + const sessions: SessionInfo[] = []; + let cursor: string | undefined; + do { + const page = await this.call(this.connection.listSessions({ cwd, cursor })); + sessions.push(...page.sessions); + cursor = page.nextCursor ?? undefined; + } while (cursor && sessions.length < wanted); + return sessions.slice(0, wanted); } async drainNotifications(): Promise { @@ -1072,17 +1083,41 @@ class AcpRuntime { const requested: AcpConfigChange[] = []; if (config.model) requested.push({ target: "model", value: config.model }); const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; - const mode = config.mode ?? (autoAcceptMode?.default ? autoAcceptMode.mode.id : undefined); + const { settings, legacyAutoAccept } = this.withoutLegacyAutoAccept(config.settings); + // The toggle stays saved after a mode is chosen here, so it counts only while the saved mode + // is one the generic adapter wrote. + const mode = + legacyAutoAccept && autoAcceptMode && !this.offersMode(config.mode) + ? autoAcceptMode.mode.id + : (config.mode ?? (autoAcceptMode?.default ? autoAcceptMode.mode.id : undefined)); if (mode) requested.push({ target: "mode", value: mode }); if (config.thinkingOption) { requested.push({ target: "thinking", value: config.thinkingOption }); } - for (const [id, value] of Object.entries(config.settings)) { + for (const [id, value] of Object.entries(settings)) { requested.push({ target: "setting", id, value }); } for (const change of this.inAgentOrder(requested)) await this.applyConfigChange(change); } + private offersMode(mode: string | undefined): boolean { + if (mode === undefined) return false; + if (mode === this.options.options.acpOptions?.autoAcceptMode?.mode.id) return true; + return toProviderCatalog(this.modes, this.configOptions).modes.some(({ id }) => id === mode); + } + + /** Reads the generic ACP adapter's saved Auto Accept toggle unless the agent has such a setting. */ + private withoutLegacyAutoAccept(settings: Readonly>): { + settings: Readonly>; + legacyAutoAccept: boolean; + } { + if (this.configOptions.some((option) => option.id === LEGACY_AUTO_ACCEPT_SETTING)) { + return { settings, legacyAutoAccept: false }; + } + const { [LEGACY_AUTO_ACCEPT_SETTING]: saved, ...rest } = settings; + return { settings: rest, legacyAutoAccept: saved === true }; + } + // One option can reset another: choosing an fx provider also selects that provider's saved // model, so a model applied first would be lost. Agents list the option that decides first. private inAgentOrder(changes: readonly AcpConfigChange[]): AcpConfigChange[] { @@ -1282,6 +1317,7 @@ class AcpRuntime { } } const permissionId = `permission:${request.toolCall.toolCallId}`; + const { presentation } = this.presentToolCall(request.toolCall); return new Promise((resolve) => { this.permissions.set(permissionId, { request, resolve, turnId: this.activePrompt?.turnId }); if (this.activePrompt?.deferred) this.scheduleDeferredSettle(); @@ -1294,6 +1330,7 @@ class AcpRuntime { kind: "tool", title: request.toolCall.title ?? undefined, input: jsonRecord(request.toolCall.rawInput), + detail: toolCallDetail(presentation), actions: request.options.map((option) => ({ id: option.optionId, label: option.name, @@ -1562,6 +1599,21 @@ class AcpRuntime { this.pendingCompactions.clear(); } + /** Merges an update into the call's earlier updates and runs it through the transformers. */ + private presentToolCall(update: ToolCall | ToolCallUpdate): AcpToolCallState { + const tool = this.toolCalls.get(update.toolCallId); + const source = mergeToolCallSnapshot(update, tool?.source); + const context = { + sessionId: this.options.boundarySessionId, + mcpServerNames: this.mcpServerNames, + previous: tool?.presentation, + }; + let presentation: AcpToolCallSnapshot = source; + for (const transformer of this.transformers) + presentation = transformer.toolCall?.(presentation, context) ?? presentation; + return { source, presentation }; + } + private reduceToolCall( update: Extract, wireSeq: number, @@ -1581,25 +1633,7 @@ class AcpRuntime { current !== undefined && this.liveOpenToolIds.has(current.id) && this.toolKeepsTurnOpen(current); - const source = mergeToolCallSnapshot(update, tool?.source); - let snapshot: AcpToolCallSnapshot = source; - const context = { - sessionId: this.options.boundarySessionId, - mcpServerNames: this.mcpServerNames, - }; - for (const transformer of this.transformers) - snapshot = transformer.toolCall?.(snapshot, context) ?? snapshot; - if (!snapshot.detail && source.diff && snapshot.kind === "edit") { - snapshot = { - ...snapshot, - detail: { - type: "edit", - filePath: source.diff.path, - oldString: source.diff.oldText ?? undefined, - newString: source.diff.newText, - }, - }; - } + const { source, presentation: snapshot } = this.presentToolCall(update); this.toolCalls.set(snapshot.id, { source, presentation: snapshot }); const isOpen = snapshot.status === "pending" || snapshot.status === "in_progress"; if (this.replayWindow === null) { @@ -2179,8 +2213,8 @@ function ownConnectorStream(source: Stream): { function mergeToolCallSnapshot( update: ToolCall | ToolCallUpdate, - current: AcpToolCallSource | undefined, -): AcpToolCallSource { + current: AcpToolCallSnapshot | undefined, +): AcpToolCallSnapshot { return { id: update.toolCallId, name: firstText(update.name, current?.name), @@ -2190,10 +2224,7 @@ function mergeToolCallSnapshot( input: jsonValue(firstDefined(update.rawInput, current?.input, null)), output: jsonValue(firstDefined(update.rawOutput, current?.output, null)), locations: update.locations?.map((location) => location.path) ?? current?.locations ?? [], - diff: - update.content === undefined - ? current?.diff - : update.content?.find((item) => item.type === "diff"), + content: update.content === undefined ? current?.content : jsonValue(update.content), }; } @@ -2367,21 +2398,12 @@ function configValues( type ToolCallTimelineItem = Extract; +function toolCallDetail(snapshot: AcpToolCallSnapshot): ProviderToolCallDetail { + return snapshot.detail ?? standardToolCallDetail(snapshot); +} + function toolTimelineItem(snapshot: AcpToolCallSnapshot): ToolCallTimelineItem { - const input = jsonRecord(snapshot.input); - const isEdit = snapshot.kind === "edit" || snapshot.name?.toLowerCase().includes("edit") === true; - const detail = - snapshot.detail ?? - (isEdit - ? { - type: "edit" as const, - filePath: - typeof input.filePath === "string" ? input.filePath : (snapshot.locations[0] ?? ""), - oldString: typeof input.oldString === "string" ? input.oldString : undefined, - newString: typeof input.newString === "string" ? input.newString : undefined, - unifiedDiff: typeof input.unifiedDiff === "string" ? input.unifiedDiff : undefined, - } - : { type: "unknown" as const, input: snapshot.input, output: snapshot.output }); + const detail = toolCallDetail(snapshot); const status = snapshot.status === "in_progress" || snapshot.status === "pending" ? "running" @@ -2416,6 +2438,7 @@ function jsonValue(value: unknown) { } function jsonRecord(value: unknown): Record> { + if (value === undefined) return {}; const parsed = jsonValue(value); if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {}; return parsed; diff --git a/packages/plugin/src/server/acp-internal/tool-call-detail.ts b/packages/plugin/src/server/acp-internal/tool-call-detail.ts new file mode 100644 index 0000000000..ce46b505d8 --- /dev/null +++ b/packages/plugin/src/server/acp-internal/tool-call-detail.ts @@ -0,0 +1,164 @@ +import type { JsonValue } from "@getpaseo/protocol/agent-types"; +import type { AcpToolCallSnapshot } from "../acp.js"; +import type { ProviderToolCallDetail } from "../provider.js"; + +type JsonRecord = Readonly>; + +interface ToolCallParts { + call: AcpToolCallSnapshot; + input: JsonRecord; + output: JsonRecord; + text: string | undefined; +} + +type KindDetail = (parts: ToolCallParts) => ProviderToolCallDetail; + +const KIND_DETAILS = new Map( + Object.entries({ + read: ({ call, input, output, text }) => ({ + type: "read", + filePath: call.locations[0] ?? string(input, "path", "filePath", "file") ?? call.title, + content: text ?? string(output, "content", "text"), + offset: number(input, "offset", "line"), + limit: number(input, "limit"), + }), + edit: editDetail, + delete: editDetail, + search: ({ call, input, output, text }) => ({ + type: "search", + query: string(input, "query", "pattern") ?? call.title, + toolName: "search", + content: text ?? string(output, "content", "text"), + filePaths: call.locations.length > 0 ? [...call.locations] : undefined, + }), + execute: ({ call, input, output, text }) => ({ + type: "shell", + command: shellCommand(input) ?? call.title, + cwd: string(input, "cwd"), + output: text ?? string(output, "output", "text"), + exitCode: number(output, "exitCode"), + }), + fetch: ({ call, input, output, text }) => ({ + type: "fetch", + url: string(input, "url") ?? call.title, + prompt: string(input, "prompt"), + result: text ?? string(output, "result", "text", "content"), + code: number(output, "status", "code"), + }), + think: ({ call, text }) => ({ type: "plain_text", label: call.title, icon: "brain", text }), + switch_mode: ({ call, text }) => ({ + type: "plain_text", + label: call.title, + icon: "sparkles", + text, + }), + } satisfies Record), +); + +/** + * The row for a tool call whose transformers set no detail, read from the call's ACP `kind`, + * `rawInput`, `rawOutput`, `content` and `locations` the way the ACP spec defines them. + */ +export function standardToolCallDetail(call: AcpToolCallSnapshot): ProviderToolCallDetail { + const parts: ToolCallParts = { + call, + input: record(call.input), + output: record(call.output), + text: contentText(call.content), + }; + const kindDetail = call.kind === undefined ? undefined : KIND_DETAILS.get(call.kind); + if (kindDetail) return kindDetail(parts); + if (call.name?.toLowerCase().includes("edit")) return editDetail(parts); + // Raw input or output is the most a client can show for a tool it does not know. + if (parts.text !== undefined && call.input === null && call.output === null) { + return { type: "plain_text", label: call.title, icon: "wrench", text: parts.text }; + } + return { type: "unknown", input: call.input, output: call.output }; +} + +function editDetail({ call, input, text }: ToolCallParts): ProviderToolCallDetail { + const diff = contentDiff(call.content); + const filePath = + diff?.path ?? string(input, "filePath", "path", "file") ?? call.locations[0] ?? ""; + if (call.kind === "delete") { + return { + type: "edit", + filePath, + oldString: diff?.oldText ?? fileText(input, "oldText"), + newString: "", + unifiedDiff: text, + }; + } + return { + type: "edit", + filePath, + oldString: diff?.oldText ?? fileText(input, "oldString", "oldText"), + newString: diff?.newText ?? fileText(input, "newString", "newText"), + unifiedDiff: string(input, "unifiedDiff") ?? text, + }; +} + +function shellCommand(input: JsonRecord): string | undefined { + const command = string(input, "command"); + if (!command) return undefined; + const args = Array.isArray(input.args) + ? input.args.filter((arg): arg is string => typeof arg === "string") + : []; + return args.length > 0 ? `${command} ${args.join(" ")}` : command; +} + +function contentText(content: JsonValue | undefined): string | undefined { + const parts = contentBlocks(content).flatMap((block) => { + if (block.type !== "content") return []; + const body = record(block.content ?? null); + return body.type === "text" && typeof body.text === "string" && body.text.length > 0 + ? [body.text] + : []; + }); + return parts.length > 0 ? parts.join("\n") : undefined; +} + +function contentDiff( + content: JsonValue | undefined, +): { path?: string; oldText?: string; newText?: string } | undefined { + const diff = contentBlocks(content).find((block) => block.type === "diff"); + if (!diff) return undefined; + return { + path: string(diff, "path"), + oldText: typeof diff.oldText === "string" ? diff.oldText : undefined, + newText: typeof diff.newText === "string" ? diff.newText : undefined, + }; +} + +function contentBlocks(content: JsonValue | undefined): JsonRecord[] { + return Array.isArray(content) ? content.map((block) => record(block)) : []; +} + +function record(value: JsonValue): JsonRecord { + return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {}; +} + +function string(value: JsonRecord, ...keys: string[]): string | undefined { + for (const key of keys) { + const entry = value[key]; + if (typeof entry === "string" && entry.trim().length > 0) return entry; + } + return undefined; +} + +/** File text is kept as written: whitespace or an empty string is the edit itself. */ +function fileText(value: JsonRecord, ...keys: string[]): string | undefined { + for (const key of keys) { + const entry = value[key]; + if (typeof entry === "string") return entry; + } + return undefined; +} + +function number(value: JsonRecord, ...keys: string[]): number | undefined { + for (const key of keys) { + const entry = value[key]; + if (typeof entry === "number" && Number.isFinite(entry)) return entry; + } + return undefined; +} diff --git a/packages/plugin/src/server/acp.test.ts b/packages/plugin/src/server/acp.test.ts index f2d61c2627..752870c0fd 100644 --- a/packages/plugin/src/server/acp.test.ts +++ b/packages/plugin/src/server/acp.test.ts @@ -9,6 +9,7 @@ import { } from "@agentclientprotocol/sdk"; import type { ProviderConnection, ProviderEvent, ProviderInput } from "./provider.js"; import { afterEach, describe, expect, it } from "vitest"; +import type { JsonValue } from "@getpaseo/protocol/agent-types"; import { AgentTimelineItemPayloadSchema } from "@getpaseo/protocol/messages"; import { runAcpProvider, type AcpStreamMessage } from "./acp.js"; @@ -6724,3 +6725,403 @@ describe("deferTurnOnRunningTools", () => { await connection.close(); }); }); + +describe("ACP tool call rows", () => { + function jsonRecord(value: JsonValue | undefined): Readonly> { + return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {}; + } + + function text(value: string) { + return [{ type: "content", content: { type: "text", text: value } }]; + } + + async function toolRows( + updates: unknown[], + transformers?: Parameters[0]["transformers"], + ) { + const harness = connectorHarness({ promptUpdates: () => updates }); + const registration = runAcpProvider({ + id: "tool-rows-acp", + label: "Tool rows ACP", + connector: harness.connector, + transformers, + }); + const connection = await registration.connect({ + versions: [1], + capabilities: ["prompt.message"], + }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send(openInput()); + await waitForEvent(events, (event) => event.type === "session.ready"); + await connection.send({ + type: "session.prompt", + sessionId: "session-1", + prompt: { + clientMessageId: "first", + delivery: "auto", + input: { type: "message", content: [{ type: "text", text: "Use a tool" }] }, + }, + }); + await waitForEvent( + events, + (event) => event.type === "session.turn" && event.state === "completed", + ); + const rows = events.flatMap((event) => + event.type === "timeline.item" && event.item.type === "tool_call" ? [event.item] : [], + ); + for (const row of rows) { + expect(AgentTimelineItemPayloadSchema.safeParse(row).success).toBe(true); + } + return rows; + } finally { + await connection.close(); + } + } + + it.each([ + { + kind: "execute", + start: { title: "Run tests", rawInput: { command: "npm", args: ["test"], cwd: "/repo" } }, + end: { content: text("passed"), rawOutput: { exitCode: 0 } }, + detail: { type: "shell", command: "npm test", cwd: "/repo", output: "passed", exitCode: 0 }, + }, + { + kind: "execute", + start: { title: "Run tests" }, + end: { content: text("passed") }, + detail: { type: "shell", command: "Run tests", output: "passed" }, + }, + { + kind: "read", + start: { title: "Read a.ts", locations: [{ path: "/repo/a.ts" }], rawInput: { offset: 3 } }, + end: { content: text("const a = 1;") }, + detail: { type: "read", filePath: "/repo/a.ts", content: "const a = 1;", offset: 3 }, + }, + { + kind: "search", + start: { title: "Search TODO", rawInput: { pattern: "TODO" } }, + end: { content: text("a.ts:1"), locations: [{ path: "/repo/a.ts" }] }, + detail: { + type: "search", + query: "TODO", + toolName: "search", + content: "a.ts:1", + filePaths: ["/repo/a.ts"], + }, + }, + { + kind: "fetch", + start: { title: "Fetch example", rawInput: { url: "https://example.com" } }, + end: { content: text("Example Domain") }, + detail: { type: "fetch", url: "https://example.com", result: "Example Domain" }, + }, + { + kind: "edit", + start: { + title: "Edit a.ts", + content: [{ type: "diff", path: "/repo/a.ts", oldText: "a", newText: "b" }], + }, + end: {}, + detail: { type: "edit", filePath: "/repo/a.ts", oldString: "a", newString: "b" }, + }, + { + kind: "edit", + start: { title: "Edit a.ts", locations: [{ path: "/repo/a.ts" }] }, + end: { content: text("Replaced 1 occurrence") }, + detail: { type: "edit", filePath: "/repo/a.ts", unifiedDiff: "Replaced 1 occurrence" }, + }, + { + kind: "edit", + start: { + title: "Edit a.ts", + rawInput: { filePath: "/repo/a.ts", oldString: "remove me", newString: " " }, + }, + end: {}, + detail: { type: "edit", filePath: "/repo/a.ts", oldString: "remove me", newString: " " }, + }, + { + kind: "delete", + start: { title: "Delete a.ts", locations: [{ path: "/repo/a.ts" }] }, + end: {}, + detail: { type: "edit", filePath: "/repo/a.ts", newString: "" }, + }, + { + kind: "think", + start: { title: "Plan" }, + end: { content: text("First read the tests") }, + detail: { type: "plain_text", label: "Plan", icon: "brain", text: "First read the tests" }, + }, + { + kind: "other", + start: { title: "Update todos" }, + end: { content: text("2 open") }, + detail: { type: "plain_text", label: "Update todos", icon: "wrench", text: "2 open" }, + }, + { + kind: "other", + start: { title: "Custom tool", rawInput: { value: 1 } }, + end: { content: text("done"), rawOutput: { ok: true } }, + detail: { type: "unknown", input: { value: 1 }, output: { ok: true } }, + }, + ])("presents a completed $kind call as its standard row ($start.title)", async (example) => { + const rows = await toolRows([ + { + sessionUpdate: "tool_call", + toolCallId: "tool-1", + kind: example.kind, + status: "in_progress", + ...example.start, + }, + { + sessionUpdate: "tool_call_update", + toolCallId: "tool-1", + status: "completed", + ...example.end, + }, + ]); + expect(rows.at(-1)?.detail).toEqual(example.detail); + }); + + it("gives transformers the call's content and the call as it was last presented", async () => { + const commandFromStart: NonNullable< + NonNullable[0]["transformers"]>[number]["toolCall"] + > = (call, { previous }) => { + const first = Array.isArray(call.content) ? call.content[0] : undefined; + const startText = jsonRecord(jsonRecord(first).content).text; + if (typeof startText === "string" && startText.startsWith("$ ")) { + return { ...call, input: { command: startText.slice(2) } }; + } + const command = jsonRecord(previous?.input).command; + return typeof command === "string" ? { ...call, input: { command } } : call; + }; + const rows = await toolRows( + [ + { + sessionUpdate: "tool_call", + toolCallId: "tool-1", + title: "git status + 1 command", + kind: "execute", + status: "in_progress", + content: text("$ git status && git diff"), + }, + { + sessionUpdate: "tool_call_update", + toolCallId: "tool-1", + status: "completed", + content: text("clean"), + }, + ], + [{ toolCall: commandFromStart }], + ); + expect(rows.map((row) => row.detail)).toEqual([ + { type: "shell", command: "git status && git diff", output: "$ git status && git diff" }, + { type: "shell", command: "git status && git diff", output: "clean" }, + ]); + }); + + it("keeps a transformer's own detail over the standard row", async () => { + const rows = await toolRows( + [ + { + sessionUpdate: "tool_call", + toolCallId: "tool-1", + title: "Run tests", + kind: "execute", + status: "completed", + rawInput: { command: "npm test" }, + }, + ], + [ + { + toolCall: (call) => ({ + ...call, + detail: { type: "unknown", input: call.input, output: null }, + }), + }, + ], + ); + expect(rows.at(-1)?.detail).toEqual({ + type: "unknown", + input: { command: "npm test" }, + output: null, + }); + }); + + it("shows the call's row on its approval", async () => { + const harness = connectorHarness({ + handleRequest(runtime, request) { + if (request.method !== "session/prompt") return false; + void runtime.request("session/request_permission", { + sessionId: "connector-session", + toolCall: { + toolCallId: "edit-1", + title: "Edit a.ts", + kind: "edit", + status: "pending", + content: [{ type: "diff", path: "/repo/a.ts", oldText: "a", newText: "b" }], + }, + options: [ + { optionId: "allow", name: "Allow edit", kind: "allow_once" }, + { optionId: "deny", name: "Deny", kind: "reject_once" }, + ], + }); + return true; + }, + }); + const connection = await runAcpProvider({ + id: "approval-rows", + label: "Approval rows", + connector: harness.connector, + }).connect({ versions: [1], capabilities: ["prompt.message", "permission"] }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send(openInput()); + await waitForEvent(events, (event) => event.type === "session.ready"); + await connection.send({ + type: "session.prompt", + sessionId: "session-1", + prompt: { + clientMessageId: "edit", + delivery: "auto", + input: { type: "message", content: [{ type: "text", text: "Edit a.ts" }] }, + }, + }); + expect( + await waitForEvent(events, (event) => event.type === "session.permission"), + ).toMatchObject({ + request: { + id: "permission:edit-1", + title: "Edit a.ts", + detail: { type: "edit", filePath: "/repo/a.ts", oldString: "a", newString: "b" }, + }, + }); + } finally { + await connection.close(); + } + }); + + it("lists sessions across every page the agent returns", async () => { + const pages: Record = { + first: { + sessions: [{ sessionId: "s1", cwd: "/repo", title: "One" }], + nextCursor: "second", + }, + second: { sessions: [{ sessionId: "s2", cwd: "/repo", title: "Two" }] }, + }; + const harness = connectorHarness({ + capabilities: { sessionCapabilities: { list: {} } }, + handleRequest(runtime, request) { + if (request.method !== "session/list") return false; + const { cursor } = request.params as { cursor?: string }; + runtime.respond(request, pages[cursor ?? "first"]); + return true; + }, + }); + const connection = await runAcpProvider({ + id: "paged-sessions", + label: "Paged sessions", + connector: harness.connector, + }).connect({ versions: [1], capabilities: ["prompt.message", "session.list"] }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send({ type: "sessions", requestId: "list" }); + const listed = await waitForEvent(events, (event) => event.type === "sessions"); + expect(listed.type === "sessions" && listed.sessions.map((session) => session.title)).toEqual( + ["One", "Two"], + ); + } finally { + await connection.close(); + } + }); + + it("resumes the generic ACP adapter's saved Auto Accept toggle in the unattended mode", async () => { + const harness = connectorHarness({ + configOptions: [ + { + id: "edit_approval_policy", + name: "Edits", + category: "mode", + type: "select", + currentValue: "ask", + options: [ + { value: "ask", name: "Default" }, + { value: "session", name: "Don't Ask" }, + ], + }, + ], + }); + const connection = await runAcpProvider({ + id: "former-generic", + label: "Former generic", + connector: harness.connector, + acpOptions: { + autoAcceptMode: { mode: { id: "full-access", label: "Full access" }, nativeMode: "ask" }, + }, + }).connect({ versions: [1], capabilities: ["prompt.message", "session.configure"] }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + const input = openInput(); + input.config.settings = { auto_accept: true }; + await connection.send(input); + await waitForEvent(events, (event) => event.type === "session.ready"); + const configs = events.flatMap((event) => + event.type === "session.config" ? [event.config.mode] : [], + ); + expect(configs.at(-1)).toBe("full-access"); + const sentOptions = harness.instances + .flatMap((instance) => instance.requests) + .filter((request) => request.method === "session/set_config_option") + .map((request) => (request.params as { configId: string }).configId); + expect(sentOptions).not.toContain("auto_accept"); + expect(events.some((event) => event.type === "request.failed")).toBe(false); + } finally { + await connection.close(); + } + }); + + it("keeps a mode chosen after the generic ACP adapter's Auto Accept toggle was saved", async () => { + const harness = connectorHarness({ + configOptions: [ + { + id: "edit_approval_policy", + name: "Edits", + category: "mode", + type: "select", + currentValue: "session", + options: [ + { value: "ask", name: "Default" }, + { value: "session", name: "Don't Ask" }, + ], + }, + ], + }); + const connection = await runAcpProvider({ + id: "former-generic", + label: "Former generic", + connector: harness.connector, + acpOptions: { + autoAcceptMode: { mode: { id: "full-access", label: "Full access" }, nativeMode: "ask" }, + }, + }).connect({ versions: [1], capabilities: ["prompt.message", "session.configure"] }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + const input = openInput(); + input.config.mode = "ask"; + input.config.settings = { auto_accept: true }; + await connection.send(input); + await waitForEvent(events, (event) => event.type === "session.ready"); + const configs = events.flatMap((event) => + event.type === "session.config" ? [event.config.mode] : [], + ); + expect(configs.at(-1)).toBe("ask"); + } finally { + await connection.close(); + } + }); +}); diff --git a/packages/plugin/src/server/acp.ts b/packages/plugin/src/server/acp.ts index 43b17202e2..65631c5e10 100644 --- a/packages/plugin/src/server/acp.ts +++ b/packages/plugin/src/server/acp.ts @@ -117,9 +117,14 @@ export interface AcpToolCallSnapshot { title: string; kind?: string; status: "pending" | "in_progress" | "completed" | "failed"; + /** The call's ACP `rawInput`. */ input: JsonValue; + /** The call's ACP `rawOutput`. */ output: JsonValue; + /** The call's ACP `content` blocks. An update that sends `content` replaces them. */ + content?: JsonValue; locations: readonly string[]; + /** The row Paseo shows. Without it, Paseo builds the standard row for the call's ACP `kind`. */ detail?: ProviderToolCallDetail; } @@ -150,9 +155,14 @@ export interface AcpTransformer { notification: { method: string; params: JsonValue }, context: AcpContext, ): AcpVendorUpdate | readonly AcpVendorUpdate[] | null; + /** Rewrites each update of a tool call, merged with the call's earlier updates. */ toolCall?( toolCall: AcpToolCallSnapshot, - context: AcpContext & { mcpServerNames?: readonly string[] }, + context: AcpContext & { + mcpServerNames?: readonly string[]; + /** The call as Paseo last presented it, after every transformer. Absent on its first update. */ + previous?: AcpToolCallSnapshot; + }, ): AcpToolCallSnapshot; } diff --git a/packages/protocol/src/messages.checkout-pr-schema.test.ts b/packages/protocol/src/messages.checkout-pr-schema.test.ts index ffdbbb4109..9fe5002725 100644 --- a/packages/protocol/src/messages.checkout-pr-schema.test.ts +++ b/packages/protocol/src/messages.checkout-pr-schema.test.ts @@ -814,7 +814,7 @@ describe("checkout PR schemas", () => { }); test.each( - ["hopliteProvider", "fxProvider", "gooseProvider"].flatMap((name) => + ["hopliteProvider", "fxProvider", "gooseProvider", "hermesProvider"].flatMap((name) => [undefined, false, true].map((value) => [name, value] as const), ), )("accepts optional bundled provider capability (%s: %s)", (name, value) => { diff --git a/packages/protocol/src/messages.ts b/packages/protocol/src/messages.ts index efce6f9796..7ef069480c 100644 --- a/packages/protocol/src/messages.ts +++ b/packages/protocol/src/messages.ts @@ -4168,6 +4168,8 @@ export const ServerInfoStatusPayloadSchema = z fxProvider: z.boolean().optional(), // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once host floor includes the bundled adapter. gooseProvider: z.boolean().optional(), + // COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once host floor includes the bundled adapter. + hermesProvider: z.boolean().optional(), // COMPAT(importSessionWorkspaceTarget): added in v0.1.110, remove gate after 2027-01-16. importSessionWorkspaceTarget: z.boolean().optional(), // COMPAT(importSessionSearch): added in v0.8.0, remove gate after 2027-03-02. diff --git a/packages/server/src/server/agent/activity-curator.test.ts b/packages/server/src/server/agent/activity-curator.test.ts index 6b8e5d4845..afe7383c66 100644 --- a/packages/server/src/server/agent/activity-curator.test.ts +++ b/packages/server/src/server/agent/activity-curator.test.ts @@ -237,6 +237,20 @@ second line'`, expect(result).toBe('[paseo__create_agent] {"cwd":"/tmp/repo","initialPrompt":"do the thing"}'); }); + it("summarizes a typed row by its detail when its name looks external", () => { + const timeline: AgentTimelineItem[] = [ + toolCallItem({ + callId: "hermes-terminal", + name: 'terminal: echo "whoami: $(whoami)" + 1 command', + detail: { type: "shell", command: 'echo "whoami: $(whoami)" && uname -s' }, + }), + ]; + + const result = curateAgentActivity(timeline); + + expect(result).toBe('[Shell] echo "whoami: $(whoami)" && uname -s'); + }); + it("collapses repeated tool updates by callId", () => { const timeline: AgentTimelineItem[] = [ toolCallItem({ diff --git a/packages/server/src/server/agent/activity-curator.ts b/packages/server/src/server/agent/activity-curator.ts index f76c0ffbb4..dc9d3fc74a 100644 --- a/packages/server/src/server/agent/activity-curator.ts +++ b/packages/server/src/server/agent/activity-curator.ts @@ -84,7 +84,7 @@ function formatToolSummary(summary: string | undefined): string | null { function inputFromUnknownDetail( detail: Extract["detail"], ): unknown { - return detail.type === "unknown" ? detail.input : null; + return detail.type === "unknown" ? detail.input : undefined; } function projectForCuration(items: readonly AgentTimelineItem[]): AgentTimelineItem[] { diff --git a/packages/server/src/server/agent/plugin-provider.test.ts b/packages/server/src/server/agent/plugin-provider.test.ts index 8835f8cb1b..334d0be0cb 100644 --- a/packages/server/src/server/agent/plugin-provider.test.ts +++ b/packages/server/src/server/agent/plugin-provider.test.ts @@ -3063,31 +3063,34 @@ test("plugin provider import keeps the stats the plugin reported with its histor } }); -test("resumes a goose session saved by the generic ACP provider", async () => { - const logger = createTestLogger(); - const harness = createProviderHarness(); - const plugins = new PluginAgentClientRegistry(logger); - plugins.replace([{ ...harness.registration, id: "goose" }]); - const registry = buildProviderRegistry(logger, { pluginProviders: plugins.definitions() }); - const client = registry.goose.createClient(logger); +test.each(["goose", "hermes"])( + "resumes a %s session saved by the generic ACP provider", + async (provider) => { + const logger = createTestLogger(); + const harness = createProviderHarness(); + const plugins = new PluginAgentClientRegistry(logger); + plugins.replace([{ ...harness.registration, id: provider }]); + const registry = buildProviderRegistry(logger, { pluginProviders: plugins.definitions() }); + const client = registry[provider].createClient(logger); - try { - const session = await client.resumeSession( - { - provider: "goose", - sessionId: "native-goose-session", - nativeHandle: "native-goose-session", - }, - { provider: "goose", cwd: "/tmp" }, - ); - expect(harness.inputs.findLast((input) => input.type === "session.open")).toMatchObject({ - persistence: { version: 1, data: { sessionId: "native-goose-session" } }, - }); - await session.close(); - } finally { - await plugins.shutdown(); - } -}); + try { + const session = await client.resumeSession( + { + provider, + sessionId: "native-session", + nativeHandle: "native-session", + }, + { provider, cwd: "/tmp" }, + ); + expect(harness.inputs.findLast((input) => input.type === "session.open")).toMatchObject({ + persistence: { version: 1, data: { sessionId: "native-session" } }, + }); + await session.close(); + } finally { + await plugins.shutdown(); + } + }, +); test("preserves a deferred ACP background job on steer and cancels it on explicit Stop through AgentManager", async () => { const logger = createTestLogger(); diff --git a/packages/server/src/server/agent/plugin-provider.ts b/packages/server/src/server/agent/plugin-provider.ts index 00a674eccf..bdd824d400 100644 --- a/packages/server/src/server/agent/plugin-provider.ts +++ b/packages/server/src/server/agent/plugin-provider.ts @@ -2245,13 +2245,20 @@ function encodePersistence(persistence: ProviderPersistence): string { return `plugin:${JSON.stringify(persistence)}`; } +// Providers whose agents were saved by the generic ACP provider before they became plugins. +const FORMER_ACP_PROVIDERS = new Set([ + // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once legacy handles have migrated. + "goose", + // COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once legacy handles have migrated. + "hermes", +]); + function decodePersistence(handle: AgentPersistenceHandle): ProviderPersistence { const fromMetadata = handle.metadata?.pluginProviderPersistence; if (fromMetadata !== undefined) { return ProviderPersistenceSchema.parse(fromMetadata); } - // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once legacy handles have migrated. - if (handle.provider === "goose" && !handle.sessionId.startsWith("plugin:")) { + if (FORMER_ACP_PROVIDERS.has(handle.provider) && !handle.sessionId.startsWith("plugin:")) { return { version: 1, data: { sessionId: handle.sessionId } }; } return decodePersistenceId(handle.sessionId); diff --git a/packages/server/src/server/persisted-config.test.ts b/packages/server/src/server/persisted-config.test.ts index 64cc838134..f3eddf19e6 100644 --- a/packages/server/src/server/persisted-config.test.ts +++ b/packages/server/src/server/persisted-config.test.ts @@ -1091,29 +1091,28 @@ describe("speech provider config normalization", () => { }); test.each([ - ["goose", "acp"], - ["/opt/bin/goose", "acp"], -])( - "migrates the legacy goose entry and preserves command overrides (%s %s)", - (binary, subcommand) => { - const command = [binary, subcommand]; - const overrides = { - enabled: false, - label: "My goose", - env: { GOOSE_PROVIDER: "openai" }, - models: [{ id: "primary", label: "Primary" }], - additionalModels: [{ id: "secondary", label: "Secondary" }], - }; - const parsed = PersistedConfigSchema.parse({ - agents: { - providers: { - goose: { ...overrides, extends: "acp", description: "Old description", command }, - }, + ["goose", "goose"], + ["goose", "/opt/bin/goose"], + ["hermes", "hermes"], + ["hermes", "/opt/bin/hermes"], +])("migrates the legacy %s entry and preserves command overrides (%s acp)", (provider, binary) => { + const command = [binary, "acp"]; + const overrides = { + enabled: false, + label: `My ${provider}`, + env: { PROVIDER_ENV: "value" }, + models: [{ id: "primary", label: "Primary" }], + additionalModels: [{ id: "secondary", label: "Secondary" }], + }; + const parsed = PersistedConfigSchema.parse({ + agents: { + providers: { + [provider]: { ...overrides, extends: "acp", description: "Old description", command }, }, - }); - expect(parsed.agents?.providers?.goose).toEqual({ - ...overrides, - ...(command[0] === "goose" ? {} : { command }), - }); - }, -); + }, + }); + expect(parsed.agents?.providers?.[provider]).toEqual({ + ...overrides, + ...(binary === provider ? {} : { command }), + }); +}); diff --git a/packages/server/src/server/persisted-config.ts b/packages/server/src/server/persisted-config.ts index 7b1f6e8659..5181194b1c 100644 --- a/packages/server/src/server/persisted-config.ts +++ b/packages/server/src/server/persisted-config.ts @@ -198,25 +198,30 @@ function isLegacyProviderEntry(value: unknown): boolean { return typeof (command as Record).mode === "string"; } +// Catalog providers that moved from `extends: "acp"` to a bundled plugin with the same ID. +const BUNDLED_FORMER_ACP_PROVIDERS = [ + // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once legacy configs have migrated. + "goose", + // COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once legacy configs have migrated. + "hermes", +] as const; + function normalizeAgentProviders(value: unknown): unknown { if (!isConfigRecord(value)) return value; - let rawProviders = value; - const goose = configRecord(value.goose); - // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once legacy configs have migrated. - if (goose?.extends === "acp") { - const { extends: _base, description: _description, command, ...overrides } = goose; + const rawProviders: Record = { ...value }; + for (const providerId of BUNDLED_FORMER_ACP_PROVIDERS) { + const entry = configRecord(rawProviders[providerId]); + if (entry?.extends !== "acp") continue; + const { extends: _base, description: _description, command, ...overrides } = entry; const usesDefaultCommand = Array.isArray(command) && command.length === 2 && - command[0] === "goose" && + command[0] === providerId && command[1] === "acp"; - rawProviders = { - ...value, - goose: { - ...overrides, - ...(command !== undefined && !usesDefaultCommand ? { command } : {}), - }, + rawProviders[providerId] = { + ...overrides, + ...(command !== undefined && !usesDefaultCommand ? { command } : {}), }; } diff --git a/packages/server/src/server/plugins/builtin/index.ts b/packages/server/src/server/plugins/builtin/index.ts index 9ffb4cadb4..8abf03805b 100644 --- a/packages/server/src/server/plugins/builtin/index.ts +++ b/packages/server/src/server/plugins/builtin/index.ts @@ -11,6 +11,7 @@ export const builtinPlugins = [ "fx-provider", "goose-provider", "grok-usage-source", + "hermes-provider", "hoplite-provider", "kimi-usage-source", "minimax-usage-source", diff --git a/packages/server/src/server/websocket-server.ts b/packages/server/src/server/websocket-server.ts index 75de0205ef..239f76510c 100644 --- a/packages/server/src/server/websocket-server.ts +++ b/packages/server/src/server/websocket-server.ts @@ -2242,6 +2242,8 @@ export class VoiceAssistantWebSocketServer { fxProvider: this.providerSnapshotManager.supportsConfigRequiredProvider("fx"), // COMPAT(gooseProvider): added in v0.17.0, remove after 2027-05-20 once host floor includes the bundled adapter. gooseProvider: this.providerSnapshotManager.supportsConfigRequiredProvider("goose"), + // COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once host floor includes the bundled adapter. + hermesProvider: this.providerSnapshotManager.supportsConfigRequiredProvider("hermes"), // COMPAT(importSessionWorkspaceTarget): added in v0.1.110, remove gate after 2027-01-16. importSessionWorkspaceTarget: true, // COMPAT(importSessionSearch): added in v0.7.3, remove gate after 2027-03-02. diff --git a/plugins/hermes-provider/icon.svg b/plugins/hermes-provider/icon.svg new file mode 100644 index 0000000000..c6fdd22500 --- /dev/null +++ b/plugins/hermes-provider/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/plugins/hermes-provider/index.server.ts b/plugins/hermes-provider/index.server.ts new file mode 100644 index 0000000000..3cf0ab2e97 --- /dev/null +++ b/plugins/hermes-provider/index.server.ts @@ -0,0 +1,7 @@ +import type { PluginServerContext } from "@getpaseo/plugin/server"; +import { createHermesProvider } from "./server/provider.js"; + +export default function contribute(server: PluginServerContext) { + server.registerProvider(createHermesProvider()); + return () => {}; +} diff --git a/plugins/hermes-provider/paseo-plugin.json b/plugins/hermes-provider/paseo-plugin.json new file mode 100644 index 0000000000..5abff98972 --- /dev/null +++ b/plugins/hermes-provider/paseo-plugin.json @@ -0,0 +1 @@ +{ "id": "hermes-provider", "requirements": { "paseo": ">=0.17.3" } } diff --git a/plugins/hermes-provider/server/legacy-modes.test.ts b/plugins/hermes-provider/server/legacy-modes.test.ts new file mode 100644 index 0000000000..7c80917e07 --- /dev/null +++ b/plugins/hermes-provider/server/legacy-modes.test.ts @@ -0,0 +1,69 @@ +import type { AcpConfigChange, AcpConfigureContext } from "@getpaseo/plugin/server/acp"; +import { describe, expect, it } from "vitest"; +import { legacyModes } from "./legacy-modes.js"; + +// The modes `hermes acp` (hermes-agent 8da31006f3) offers through `edit_approval_policy`. +const POLICY_MODES = [ + { id: "ask", label: "Default" }, + { id: "workspace_session", label: "Accept Edits" }, + { id: "session", label: "Don't Ask" }, +]; + +async function configure(change: AcpConfigChange, modes = POLICY_MODES) { + const applied: AcpConfigChange[] = []; + const context: AcpConfigureContext = { + sessionId: "session-1", + config: { read: async () => ({}), set: async () => {} }, + request: async () => null, + catalog: () => ({ models: [], modes }), + apply: async (nativeChange) => { + applied.push(nativeChange); + }, + }; + const result = await legacyModes.configure!(change, context); + return { result, applied }; +} + +describe("Hermes modes saved before Hermes was bundled", () => { + it.each([ + ["default", "ask"], + ["accept_edits", "workspace_session"], + ["dont_ask", "session"], + ])("applies saved mode %s as policy %s", async (saved, policy) => { + expect(await configure({ target: "mode", value: saved })).toEqual({ + result: "handled", + applied: [{ target: "mode", value: policy }], + }); + }); + + it("passes current policy modes through", async () => { + expect(await configure({ target: "mode", value: "workspace_session" })).toEqual({ + result: "pass", + applied: [], + }); + }); + + it("passes a saved mode through when Hermes offers it directly", async () => { + const sessionModes = [ + { id: "default", label: "Default" }, + { id: "accept_edits", label: "Accept Edits" }, + ]; + expect(await configure({ target: "mode", value: "default" }, sessionModes)).toEqual({ + result: "pass", + applied: [], + }); + }); + + it("passes a saved mode through when Hermes no longer offers its policy", async () => { + expect( + await configure({ target: "mode", value: "default" }, [{ id: "plan", label: "Plan" }]), + ).toEqual({ result: "pass", applied: [] }); + }); + + it("leaves other settings alone", async () => { + expect(await configure({ target: "model", value: "default" })).toEqual({ + result: "pass", + applied: [], + }); + }); +}); diff --git a/plugins/hermes-provider/server/legacy-modes.ts b/plugins/hermes-provider/server/legacy-modes.ts new file mode 100644 index 0000000000..8411fed8b8 --- /dev/null +++ b/plugins/hermes-provider/server/legacy-modes.ts @@ -0,0 +1,28 @@ +import type { AcpTransformer } from "@getpaseo/plugin/server/acp"; + +// Hermes offers each edit mode twice: as an ACP session mode and as a value of its +// `edit_approval_policy` config option (`acp_adapter/modes.py`). Agents created before Hermes was +// bundled saved the session mode ID; this provider uses the config option, as ACP prefers. +const POLICY_BY_SESSION_MODE = new Map([ + ["default", "ask"], + ["accept_edits", "workspace_session"], + ["dont_ask", "session"], +]); + +/** + * Applies a saved session mode ID as its edit approval policy. Passes the mode through unchanged + * when Hermes still offers it or no longer offers the policy. + */ +// COMPAT(hermesProvider): added in v0.17.4, remove after 2027-05-23 once legacy agents have resumed. +export const legacyModes: AcpTransformer = { + async configure(change, { apply, catalog }) { + if (change.target !== "mode" || change.value === null) return "pass"; + const policy = POLICY_BY_SESSION_MODE.get(change.value); + if (policy === undefined) return "pass"; + const { modes } = catalog(); + if (modes.some((mode) => mode.id === change.value)) return "pass"; + if (!modes.some((mode) => mode.id === policy)) return "pass"; + await apply({ target: "mode", value: policy }); + return "handled"; + }, +}; diff --git a/plugins/hermes-provider/server/provider.ts b/plugins/hermes-provider/server/provider.ts new file mode 100644 index 0000000000..92ca1abafe --- /dev/null +++ b/plugins/hermes-provider/server/provider.ts @@ -0,0 +1,30 @@ +import { runAcpProvider } from "@getpaseo/plugin/server/acp"; +import type { ProviderRegistration } from "@getpaseo/plugin/server/provider"; +import { legacyModes } from "./legacy-modes.js"; +import { terminalCommand } from "./terminal-command.js"; + +export function createHermesProvider(): ProviderRegistration { + return { + requiresConfiguration: true, + ...runAcpProvider({ + id: "hermes", + label: "Hermes", + description: "Nous Research self-improving AI agent", + icon: "icon.svg", + command: ["hermes", "acp"], + acpOptions: { + autoAcceptMode: { + mode: { + id: "full-access", + label: "Full access", + description: "Approve tool requests without asking.", + icon: "ShieldOff", + colorTier: "dangerous", + }, + nativeMode: "ask", + }, + }, + transformers: [terminalCommand, legacyModes], + }), + }; +} diff --git a/plugins/hermes-provider/server/terminal-command.test.ts b/plugins/hermes-provider/server/terminal-command.test.ts new file mode 100644 index 0000000000..77a971e404 --- /dev/null +++ b/plugins/hermes-provider/server/terminal-command.test.ts @@ -0,0 +1,62 @@ +import type { AcpToolCallSnapshot } from "@getpaseo/plugin/server/acp"; +import { describe, expect, it } from "vitest"; +import { terminalCommand } from "./terminal-command.js"; + +const FULL_COMMAND = + 'echo "whoami: $(whoami)" && id -u && echo cleaned && ls -la /tmp | head -3 && date +%Y && uname -s'; + +function text(value: string): AcpToolCallSnapshot["content"] { + return [{ type: "content", content: { type: "text", text: value } }]; +} + +// Shapes captured from `hermes acp` (hermes-agent 8da31006f3) running its terminal tool. +const started: AcpToolCallSnapshot = { + id: "call_95ed298464d44b0c9a23d24e72c96afc", + title: 'terminal: echo "whoami: $(whoami)" + 5 commands', + kind: "execute", + status: "pending", + input: null, + output: null, + content: text(`$ ${FULL_COMMAND}`), + locations: [], +}; + +const completed: AcpToolCallSnapshot = { + ...started, + status: "completed", + content: text("terminal result\n- **output:** whoami: moboudra\n- **exit_code:** 0"), +}; + +function present(call: AcpToolCallSnapshot, previous?: AcpToolCallSnapshot) { + return terminalCommand.toolCall!(call, { sessionId: "session-1", previous }); +} + +describe("Hermes terminal calls", () => { + it("runs the command from the start text, not the summary title", () => { + expect(present(started).input).toEqual({ command: FULL_COMMAND }); + }); + + it("keeps the command once the result replaces the start text", () => { + const first = present(started); + expect(present(completed, first).input).toEqual({ command: FULL_COMMAND }); + }); + + it("prefers a command Hermes sends as input", () => { + const call = { ...started, input: { command: "git status" } }; + expect(present(call)).toEqual(call); + }); + + it.each([ + { name: "a start text without the prompt", content: text(`Running ${FULL_COMMAND}`) }, + { name: "no start text", content: undefined }, + { name: "an unexpected content shape", content: { text: `$ ${FULL_COMMAND}` } }, + ])("passes the call through for $name", ({ content }) => { + const call = { ...started, content }; + expect(present(call)).toEqual(call); + }); + + it("leaves other tools alone", () => { + const read = { ...started, kind: "read", content: text("$ not a command") }; + expect(present(read)).toEqual(read); + }); +}); diff --git a/plugins/hermes-provider/server/terminal-command.ts b/plugins/hermes-provider/server/terminal-command.ts new file mode 100644 index 0000000000..1f99266290 --- /dev/null +++ b/plugins/hermes-provider/server/terminal-command.ts @@ -0,0 +1,29 @@ +import type { AcpToolCallSnapshot, AcpTransformer } from "@getpaseo/plugin/server/acp"; +import { z } from "zod"; + +const commandInput = z.object({ command: z.string() }); +const startText = z.tuple([ + z.object({ + type: z.literal("content"), + content: z.object({ type: z.literal("text"), text: z.string().startsWith("$ ") }), + }), +]); + +// Hermes titles a terminal call with a summary (`terminal: git status + 2 commands`) and sends the +// command only as `$ ` text in the call's first update; the completed update replaces that +// text with the result. Keeping the command as the call's input lets Paseo's Shell row show it. +// When Hermes sends neither shape, the call passes through and the row shows Hermes's title. +export const terminalCommand: AcpTransformer = { + toolCall(call, { previous }) { + if (call.kind !== "execute" || commandInput.safeParse(call.input).success) return call; + const command = + commandFromStartText(call) ?? commandInput.safeParse(previous?.input).data?.command; + if (command === undefined) return call; + const input = typeof call.input === "object" && !Array.isArray(call.input) ? call.input : null; + return { ...call, input: { ...input, command } }; + }, +}; + +function commandFromStartText(call: AcpToolCallSnapshot): string | undefined { + return startText.safeParse(call.content).data?.[0].content.text.slice("$ ".length); +} diff --git a/public-docs/custom-providers.md b/public-docs/custom-providers.md index 49f0876538..16599ad836 100644 --- a/public-docs/custom-providers.md +++ b/public-docs/custom-providers.md @@ -13,7 +13,7 @@ Everything beyond the [supported providers](/docs/supported-providers) lives und - **Extend** a first-class provider to point at a different API (Z.AI, Alibaba/Qwen, a proxy, a self-hosted endpoint). - **Add profiles**, multiple entries against the same underlying provider with different credentials or curated model lists. - **Override the binary**, run a nightly build, a wrapper script, or a Docker image instead of the installed CLI. -- **Add ACP agents**, Gemini CLI, Hermes, or any agent speaking the Agent Client Protocol over stdio. +- **Add ACP agents**, Gemini CLI, Qwen Code, or any agent speaking the Agent Client Protocol over stdio. - **Disable** a provider you don't use. Run `paseo reload` after editing the file. Provider changes apply to future launches without restarting the daemon. @@ -166,11 +166,6 @@ Any agent that speaks [ACP](https://agentclientprotocol.com) over stdio can be a "extends": "acp", "label": "Google Gemini", "command": ["gemini", "--acp"] - }, - "hermes": { - "extends": "acp", - "label": "Hermes", - "command": ["hermes", "acp"] } } } diff --git a/public-docs/custom-providers.zh-CN.md b/public-docs/custom-providers.zh-CN.md index ed139a85e2..ed5b8cee58 100644 --- a/public-docs/custom-providers.zh-CN.md +++ b/public-docs/custom-providers.zh-CN.md @@ -11,7 +11,7 @@ nav: 自定义 Provider - **扩展**一个一等 Provider,让它指向不同的 API(Z.AI、阿里巴巴/通义千问、代理或自托管端点)。 - **添加多个配置**:针对同一个底层 Provider 创建多个条目,使用不同的凭据或精选的模型列表。 - **覆盖二进制文件**:运行 nightly 构建、包装脚本或 Docker 镜像,而不是已安装的 CLI。 -- **添加 ACP Agent**:Gemini CLI、Hermes,或任何通过 stdio 使用 Agent Client Protocol 的 Agent。 +- **添加 ACP Agent**:Gemini CLI、Qwen Code,或任何通过 stdio 使用 Agent Client Protocol 的 Agent。 - **禁用**你不使用的 Provider。 编辑文件后运行 `paseo reload`。Provider 的修改会应用到之后的启动,无需重启 daemon。 @@ -159,11 +159,6 @@ Z.AI 通过兼容 Anthropic 的端点提供 GLM 模型。把 `ANTHROPIC_BASE_URL "extends": "acp", "label": "Google Gemini", "command": ["gemini", "--acp"] - }, - "hermes": { - "extends": "acp", - "label": "Hermes", - "command": ["hermes", "acp"] } } } diff --git a/public-docs/plugins/providers.md b/public-docs/plugins/providers.md index e78b222df3..48bce6059e 100644 --- a/public-docs/plugins/providers.md +++ b/public-docs/plugins/providers.md @@ -687,9 +687,20 @@ export const vendorEdits: AcpTransformer = { }; ``` -Set `detail` on the returned tool call to supply a Paseo tool card when the ACP kind does not -describe the operation. For example, an agent can report a new file as an ACP edit, while the -plugin returns a `write` detail with the file path and contents. +Paseo builds a standard tool card from each call's ACP `kind`: Shell for `execute`, Read for `read`, +Edit for `edit` and `delete`, Search for `search`, and Fetch for `fetch`. The card reads the call's +`input` (ACP `rawInput`), `output` (`rawOutput`), `content`, and `locations`. A call of another kind +shows its raw input and output, or its text content when the agent sends neither. + +Set `detail` on the returned tool call to replace the standard card. For example, an agent can +report a new file as an ACP edit, while the plugin returns a `write` detail with the file path and +contents. Return `{ type: "unknown", input, output }` to show the raw values. + +`toolCall` runs on every update of a call, with the updates merged so far. An update that sends +`content` replaces the earlier content, as ACP defines. When an agent sends a value only in an +early update, read it from `context.previous`, the call as Paseo last presented it. The +[Hermes terminal transformer](https://github.com/getpaseo/paseo/blob/main/plugins/hermes-provider/server/terminal-command.ts) +keeps the command from Hermes's first update this way. Use `sessionOpen` when an ACP agent needs extension metadata on `session/new` or `session/load`. The hook receives the system prompt and the agent capabilities' `_meta` from `initialize`. diff --git a/public-docs/plugins/providers.zh-CN.md b/public-docs/plugins/providers.zh-CN.md index fd8c60b140..7df6e4cf17 100644 --- a/public-docs/plugins/providers.zh-CN.md +++ b/public-docs/plugins/providers.zh-CN.md @@ -573,6 +573,12 @@ export const vendorEdits: AcpTransformer = { }; ``` +Paseo 根据每个调用的 ACP `kind` 生成标准工具卡片:`execute` 显示为 Shell,`read` 显示为 Read,`edit` 和 `delete` 显示为 Edit,`search` 显示为 Search,`fetch` 显示为 Fetch。卡片读取调用的 `input`(ACP `rawInput`)、`output`(`rawOutput`)、`content` 和 `locations`。其他类型的调用显示原始输入和输出;如果 Agent 两者都没有发送,则显示文本内容。 + +在返回的工具调用上设置 `detail` 可以替换标准卡片。例如,Agent 可能把新建文件报告为 ACP 编辑,而插件返回带有文件路径和内容的 `write` detail。返回 `{ type: "unknown", input, output }` 可以显示原始值。 + +`toolCall` 会在调用的每次更新时运行,参数是到目前为止合并后的调用。按照 ACP 的定义,发送了 `content` 的更新会替换之前的内容。如果 Agent 只在较早的更新中发送某个值,请从 `context.previous` 读取,它是 Paseo 上一次展示的调用。[Hermes 终端转换器](https://github.com/getpaseo/paseo/blob/main/plugins/hermes-provider/server/terminal-command.ts)就是这样保留 Hermes 第一次更新中的命令。 + 如果 Agent 只为当前选中的模型列出 `thought_level` 选项,请设置 `acpOptions.perModelThinkingOptions`。目录发现会依次选中每个模型,并为它记录 Agent 列出的思考选项。没有 `thought_level` 选项的模型不会显示思考选择器。 ## 测试与发布 {#test-and-publish} diff --git a/public-docs/plugins/reference.md b/public-docs/plugins/reference.md index fac1bd7d01..2b1e8ed0b7 100644 --- a/public-docs/plugins/reference.md +++ b/public-docs/plugins/reference.md @@ -442,7 +442,10 @@ request. The promise returns a JSON value or rejects with the agent's JSON-RPC e In `toolCall`, use `context.mcpServerNames` to recognize servers that Paseo supplied when it opened the ACP session. Include an empty-list fallback for older SDK versions or servers configured -directly in the agent. +directly in the agent. `toolCall.content` holds the call's ACP `content` blocks, and +`context.previous` is the call as Paseo last presented it, after every transformer. Both are absent +on older SDK versions, and `previous` is absent on a call's first update. See +[Adapt an ACP agent](/docs/plugins/providers#adapt-an-acp-agent) for the standard tool cards. Use `config(state, context)` to return the configuration snapshot that Paseo displays. Paseo calls this synchronous hook for initial, notification, and committed configuration snapshots. diff --git a/public-docs/plugins/reference.zh-CN.md b/public-docs/plugins/reference.zh-CN.md index 3c92241d82..ee2b9b4d3c 100644 --- a/public-docs/plugins/reference.zh-CN.md +++ b/public-docs/plugins/reference.zh-CN.md @@ -369,7 +369,9 @@ Paseo 刷新 Agent 的方式是关闭它当前的 Provider 会话,再用当前 Promise 返回 JSON 值,或以 Agent 的 JSON-RPC 错误拒绝。 在 `toolCall` 中,通过 `context.mcpServerNames` 识别 Paseo 打开 ACP 会话时提供的服务器。 -兼容旧版 SDK 或处理直接在 agent 中配置的服务器时,可以回退到空列表。 +兼容旧版 SDK 或处理直接在 agent 中配置的服务器时,可以回退到空列表。`toolCall.content` 包含调用的 ACP `content` 块, +`context.previous` 是 Paseo 上一次展示的调用(经过所有转换器之后)。旧版 SDK 中两者都不存在;调用的第一次更新没有 `previous`。 +标准工具卡片见[适配 ACP Agent](/zh-CN/docs/plugins/providers#adapt-an-acp-agent)。 使用 `config(state, context)` 返回 Paseo 显示的配置快照。 Paseo 在会话就绪、收到配置通知或提交配置更改时调用此同步钩子。 diff --git a/public-docs/supported-providers/index.md b/public-docs/supported-providers/index.md index 1a9c3928b6..6c11ad0c75 100644 --- a/public-docs/supported-providers/index.md +++ b/public-docs/supported-providers/index.md @@ -59,7 +59,7 @@ Entries that launch through `npx` or `uvx` need only that tool on your daemon ho - [GLM Agent](https://github.com/stefandevo/glm-acp-agent), Zhipu AI's GLM coding agent. - [goose](https://block.github.io/goose/), Block's local open-source AI agent. Paseo lists models from all providers configured in goose when goose supports model inventory discovery. - [Grok](https://docs.x.ai/build/overview), xAI's Grok Build agentic coding CLI. -- [Hermes Agent](https://hermes-agent.nousresearch.com/docs/user-guide/features/acp), Nous Research's self-improving agent. +- [Hermes Agent](https://hermes-agent.nousresearch.com/docs/user-guide/features/acp), Nous Research's self-improving agent. Paseo shows the full command of each terminal call. - [Junie](https://junie.jetbrains.com/docs/junie-cli-acp.html), JetBrains' coding agent. - [Kilo Code](https://kilo.ai/docs/code-with-ai/platforms/cli), open-source coding agent. - [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code), Moonshot AI's coding assistant. diff --git a/public-docs/supported-providers/index.zh-CN.md b/public-docs/supported-providers/index.zh-CN.md index de359f3a58..a9d5e24c61 100644 --- a/public-docs/supported-providers/index.zh-CN.md +++ b/public-docs/supported-providers/index.zh-CN.md @@ -57,7 +57,7 @@ Paseo 可以运行任何使用 [Agent Client Protocol](https://agentclientprotoc - [GLM Agent](https://github.com/stefandevo/glm-acp-agent):智谱 AI 的 GLM 编程 Agent。 - [goose](https://block.github.io/goose/):Block 的本地开源 AI Agent。如果 goose 支持发现模型清单,Paseo 会列出 goose 中所有已配置 Provider 的模型。 - [Grok](https://docs.x.ai/build/overview):xAI 的 Grok Build Agent 编程 CLI。 -- [Hermes Agent](https://hermes-agent.nousresearch.com/docs/user-guide/features/acp):Nous Research 的自我改进型 Agent。 +- [Hermes Agent](https://hermes-agent.nousresearch.com/docs/user-guide/features/acp):Nous Research 的自我改进型 Agent。Paseo 会显示每次终端调用的完整命令。 - [Junie](https://junie.jetbrains.com/docs/junie-cli-acp.html):JetBrains 的编程 Agent。 - [Kilo Code](https://kilo.ai/docs/code-with-ai/platforms/cli):开源编程 Agent。 - [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code):月之暗面的编程助手。