The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop-plugins): install on a backend that predates inspected_sha
Teknium56bd8a19357a
diff --git a/apps/desktop/src/store/agent-plugins.test.ts b/apps/desktop/src/store/agent-plugins.test.tsindex 0e190938c65..610f5fbf227 100644--- a/apps/desktop/src/store/agent-plugins.test.ts+++ b/apps/desktop/src/store/agent-plugins.test.ts@@ -61,6 +61,45 @@ describe('installAgentPlugin', () => {timedOut: true})})++ const reviewed = 'e404b6816b20237a82f6fbe2749b5a576cf75dba'++ it('installs on a backend that predates inspected_sha by sending the install without it', async () => {+ // The admission refusal an origin/main backend gives the field (validate_params, handler never ran).+ const request = vi.fn(async (_method: string, params: Record<string, unknown>) => {+ if ('inspected_sha' in params) {+ throw new JsonRpcGatewayError(+ 'invalid params for plugins.manage: inspected_sha: Extra inputs are not permitted — the client and the ' ++ 'Hermes backend are out of sync (different versions); run `hermes update` and restart both',+ { code: 4000 }+ )+ }++ return { ok: true, plugin_name: 'pkg', enabled: true }+ })++ expect(+ await installAgentPlugin(request as never, { identifier: 'https://github.com/example/pkg', inspectedSha: reviewed })+ ).toMatchObject({ ok: true, pluginName: 'pkg' })+ expect(request).toHaveBeenCalledTimes(2)+ expect(request.mock.calls[1][1]).toMatchObject({ action: 'install', identifier: 'https://github.com/example/pkg' })+ expect(request.mock.calls[1][1]).not.toHaveProperty('inspected_sha')+ })++ it('holds a current backend to the inspected commit and never resends a refusal of the moved branch', async () => {+ const request = vi.fn(async () => {+ throw new JsonRpcGatewayError(+ 'The source changed since you reviewed it: it is now at commit 0a415bc5c1d2, not e404b6816b20.',+ { code: 5026 }+ )+ })++ expect(+ await installAgentPlugin(request as never, { identifier: 'https://github.com/example/pkg', inspectedSha: reviewed })+ ).toMatchObject({ ok: false })+ expect(request).toHaveBeenCalledTimes(1)+ expect(request.mock.calls[0]).toEqual(['plugins.manage', expect.objectContaining({ inspected_sha: reviewed }), 120_000])+ })})describe('inspectAgentPlugin', () => {diff --git a/apps/desktop/src/store/agent-plugins.ts b/apps/desktop/src/store/agent-plugins.tsindex f63d83f2cf4..855c0b2c0e7 100644--- a/apps/desktop/src/store/agent-plugins.ts+++ b/apps/desktop/src/store/agent-plugins.ts@@ -286,6 +286,33 @@ const NO_LIVE: AgentPluginLiveNow = { mcpServers: [], skills: [] }// giving normal installs time to return their authoritative result.const PLUGIN_INSTALL_REQUEST_TIMEOUT_MS = 120_000+interface InstallReply {+ ok?: boolean+ plugin_name?: string+ warnings?: string[]+ missing_env?: string[]+ enabled?: boolean+ activation?: {+ live_now?: {+ mcp_servers?: AgentPluginLiveServer[]+ skills?: { name: string }[]+ } | null+ deferred?: Record<string, string[]>+ } | null+ error?: string+}++/** A backend predating `inspected_sha` (native Desktop on an older SSH/URL/Cloud runtime) refuses the+ * whole install at admission (`tui_gateway/contracts/registry.py::validate_params`, code 4000, handler+ * never ran), so resending without it installs the branch tip exactly as those backends always did.+ * Matched on the stable prefix, as `session-create-request.ts` does. Delete once no supported backend+ * predates the field. */+function backendPredatesInspectedSha(params: Record<string, unknown>, error: unknown): boolean {+ const message = error instanceof Error ? error.message : String(error)++ return 'inspected_sha' in params && message.includes('invalid params for plugins.manage: inspected_sha:')+}+export async function installAgentPlugin(request: GatewayRequest,opts: {@@ -304,37 +331,32 @@ export async function installAgentPlugin(profile?: string | null}): Promise<AgentPluginInstallResult> {+ const params = withProfile(+ {+ action: 'install',+ identifier: opts.identifier,+ force: Boolean(opts.force),+ enable: opts.enable ?? true,+ ...(opts.catalogName ? { catalog_name: opts.catalogName } : {}),+ ...(opts.ref ? { ref: opts.ref } : {}),+ ...(!opts.ref && opts.inspectedSha ? { inspected_sha: opts.inspectedSha } : {})+ },+ opts.profile+ )++ const send = (requestParams: Record<string, unknown>) =>+ request<InstallReply>('plugins.manage', requestParams, PLUGIN_INSTALL_REQUEST_TIMEOUT_MS)+try {- const result = await request<{- ok?: boolean- plugin_name?: string- warnings?: string[]- missing_env?: string[]- enabled?: boolean- activation?: {- live_now?: {- mcp_servers?: AgentPluginLiveServer[]- skills?: { name: string }[]- } | null- deferred?: Record<string, string[]>- } | null- error?: string- }>(- 'plugins.manage',- withProfile(- {- action: 'install',- identifier: opts.identifier,- force: Boolean(opts.force),- enable: opts.enable ?? true,- ...(opts.catalogName ? { catalog_name: opts.catalogName } : {}),- ...(opts.ref ? { ref: opts.ref } : {}),- ...(!opts.ref && opts.inspectedSha ? { inspected_sha: opts.inspectedSha } : {})- },- opts.profile- ),- PLUGIN_INSTALL_REQUEST_TIMEOUT_MS- )+ const result = await send(params).catch((error: unknown) => {+ if (!backendPredatesInspectedSha(params, error)) {+ throw error+ }++ const { inspected_sha: _dropped, ...compatible } = params++ return send(compatible)+ })if (!result?.ok) {return { ok: false, error: result?.error || 'Install failed', live: NO_LIVE, nextChat: false }