@agentproto/adapter-hermes 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -120,7 +120,13 @@ var hermes = defineAgentCli({
120
120
  // `hermes --resume <SESSION> --tui`. This lets the daemon offer
121
121
  // provider-native terminal restart for Hermes sessions, distinct from
122
122
  // its ACP-level `resumable: false` honesty.
123
- nativeTerminalResume: true
123
+ // Gated on Node ≥22.5: hermes TUI uses node:sqlite which is
124
+ // unavailable on older runtimes — attempting pty-native restart on
125
+ // Node <22.5 errors at startup, not at resume.
126
+ nativeTerminalResume: (() => {
127
+ const [major, minor] = process.versions.node.split(".").map(Number);
128
+ return (major ?? 0) > 22 || (major ?? 0) === 22 && (minor ?? 0) >= 5;
129
+ })()
124
130
  },
125
131
  modes: [
126
132
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AA8CA,SAAS,oBAAA,GAAgE;AACvE,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,EAAE,QAAA,EAAU,YAAA,EAAc,MAAA,EAAQ,YAAA,EAAa;AAAA,IAC/C,EAAE,QAAA,EAAU,QAAA,EAAU,MAAA,EAAQ,QAAA;AAAS,GACzC;AAEA,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,MAA+C,EAAC;AAEtD,EAAA,KAAA,MAAW,EAAE,QAAA,EAAU,MAAA,EAAO,IAAK,SAAA,EAAW;AAC5C,IAAA,KAAA,MAAW,SAAS,UAAA,CAAW,EAAE,MAAM,KAAA,EAAO,QAAA,EAAU,CAAA,EAAG;AACzD,MAAA,MAAM,SAAS,KAAA,CAAM,EAAA;AAIrB,MAAA,IAAI,qBAAA,CAAsB,IAAA,CAAK,MAAM,CAAA,EAAG;AACxC,MAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,GAAG,IAAI,MAAA,GAAS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AA,CAAI,IAAA,EAAM,UAAU,GAAA,CAAI,EAAA,EAAI,SAAA,EAAW,GAAA,CAAI,GAAA,EAAI;AAGjE,QAAA,IAAI,IAAI,IAAA,KAAS,IAAA,IAAQ,GAAA,CAAI,IAAA,KAAS,QAAW,OAAO,IAAA;AAAA,MAC1D;AACA,MAAA,IAAI,CAAA,GAAI,QAAA,GAAW,CAAA,EAAG,MAAM,IAAI,QAAQ,CAAA,CAAA,KAAK,UAAA,CAAW,CAAA,EAAG,QAAQ,CAAC,CAAA;AAAA,IACtE;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-hermes — AIP-45 adapter for Nous Research's Hermes Agent.\n *\n * Re-exports a `defineAgentCli` instance plus the runtime factory so\n * a host can boot Hermes with one import:\n *\n * import { hermes, hermesRuntime } from \"@agentproto/adapter-hermes\"\n * const session = await hermesRuntime().start({ env: { OPENROUTER_API_KEY } })\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n *\n * The companion HERMES.md / SECRETS.md / hermes-acp.ACP.md files in\n * this package describe the manifest, secret slots, and ACP wire\n * profile.\n */\n\nimport { join } from \"node:path\"\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport { listModels } from \"@agentproto/model-catalog\"\nimport type {\n AuthStore,\n CapabilityStrategy,\n CredSource,\n ProviderCapability,\n} from \"@agentproto/provider-kit\"\n\n/**\n * Build hermes's model menu from the shared provider catalog instead of a\n * hand-maintained allowlist. Hermes routes by the model id's own vendor\n * prefix (routeSelection: \"derived-from-model\"), so every entry carries\n * the billing provider the runtime's eligibility projection needs.\n *\n * Only providers hermes genuinely supports today are included:\n * - OpenRouter (`openrouter/<vendor>/<id>` router prefix)\n * - OpenAI (direct `openai/<id>` vendor prefix)\n *\n * Anthropic models are excluded — hermes is the budget arm and those are\n * reserved for the claude-code adapter (enforced by models.deny).\n */\nfunction buildHermesModelMenu(): Array<{ id: string; provider: string }> {\n const supported = [\n { provider: \"openrouter\", prefix: \"openrouter\" },\n { provider: \"openai\", prefix: \"openai\" },\n ] as const\n\n const seen = new Set<string>()\n const out: Array<{ id: string; provider: string }> = []\n\n for (const { provider, prefix } of supported) {\n for (const model of listModels({ kind: \"llm\", provider })) {\n const bareId = model.id\n // Skip anthropic models (reserved for claude-code adapter) and\n // tilde-prefixed OpenRouter provider aliases (~deepseek, ~google, …)\n // which aren't real vendor names and break the route-identity parser.\n if (/anthropic|claude|^~/.test(bareId)) continue\n const canonicalId = bareId.includes(\"/\") ? bareId : `${prefix}/${bareId}`\n const id = provider === \"openrouter\" ? `${bareId}@openrouter` : canonicalId\n if (seen.has(id)) continue\n seen.add(id)\n out.push({ id, provider })\n }\n }\n\n return out.sort((a, b) => {\n if (a.provider !== b.provider) return a.provider.localeCompare(b.provider)\n return a.id.localeCompare(b.id)\n })\n}\n\nexport const hermes: AgentCliHandle = defineAgentCli({\n name: \"hermes\",\n id: \"hermes\",\n description:\n \"Nous Research's Hermes Agent — autonomous CLI agent with skills, sandboxes, memory plugins, and a built-in ACP server. Spawned as `hermes acp` and driven over stdio JSON-RPC.\",\n version: \"0.1.0\",\n bin: \"hermes\",\n bin_args: [\"acp\"],\n install: [\n {\n method: \"curl\",\n url: \"https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh\",\n },\n ],\n version_check: {\n cmd: \"hermes --version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=0.13.0 <1.0.0\",\n timeout_ms: 5000,\n },\n auth: {\n ref: \"./SECRETS.md\",\n // No ANTHROPIC_API_KEY — hermes is the budget arm and deliberately does\n // not route to Anthropic (see models.deny). Anthropic stays exclusive to\n // the claude-code adapter.\n state: { env: [\"OPENROUTER_API_KEY\", \"OPENAI_API_KEY\"] },\n },\n // Billing-auth (opt-in — no authEnforce, so unconfigured spawns stay\n // ambient). Single-provider adapter: api-key mode SETS providerEnvVar\n // (\"openrouter\") = OPENROUTER_API_KEY, derived from the catalog. No\n // authSubscription ⇒ `subscription` fails loud with `unsupported_auth_mode`.\n provider: \"openrouter\",\n // The endpoint falls out of the model id's vendor prefix — `openai/*` is\n // routed through OpenAI, everything else through OpenRouter (see the\n // `model` option) — so there is nothing independent to choose: picking the\n // model already fixes the route → derived-from-model.\n routeSelection: \"derived-from-model\",\n sandbox: \"./SANDBOX.md\",\n protocol: \"acp\",\n acp: \"./hermes-acp.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n // hermes's own ACP server has been observed to hit its internal\n // max-tool-iterations cap, produce a final answer, and then never\n // send the `prompt` JSON-RPC response — hanging the daemon's turn\n // drain loop forever with no other adapter-side signal available.\n // 5 minutes of true silence (reset on any ACP traffic, so a long\n // legitimate tool-call chain doesn't false-positive) is generous\n // enough to not trip during normal use.\n turn_idle_timeout_ms: 300_000,\n },\n models: {\n // Cheap OpenRouter models by default — hermes is the budget delegation\n // arm (a Sonnet default would defeat the purpose). glm-5.2 + deepseek\n // are the go-to cheap coders.\n default: \"z-ai/glm-5.2@openrouter\",\n // Generated from the shared provider catalog so the Configuration Lab /\n // harness picker shows genuinely reachable OpenRouter + OpenAI models\n // instead of a hand-maintained static list. Anthropic models are filtered\n // out at generation time (and enforced by deny below). The free-form\n // `model` option still accepts any valid OpenRouter/OpenAI id.\n allowed: buildHermesModelMenu(),\n // Anthropic models are reserved for the dedicated claude-code adapter —\n // hermes must NEVER route to them, even if a caller passes the id\n // explicitly. Enforced at compose time (RuntimeConfigError), so the\n // budget arm can't silently burn premium Anthropic spend.\n deny: [\"anthropic/*\", \"claude-*\"],\n env: {\n openrouter: \"OPENROUTER_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n },\n // hermes keeps its own configured default when given a model via the\n // ACP session config — selection must go through a `/model <id>`\n // control turn instead. See AgentCliModels.apply.\n apply: \"command\",\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: true,\n resumable: false,\n bidirectional: true,\n // Hermes has a verified native TUI resume path:\n // `hermes --resume <SESSION> --tui`. This lets the daemon offer\n // provider-native terminal restart for Hermes sessions, distinct from\n // its ACP-level `resumable: false` honesty.\n nativeTerminalResume: true,\n },\n modes: [\n {\n id: \"default\",\n description:\n \"Standard interactive mode — loads ~/.hermes/config.yaml and auto-injects \" +\n \"rules/memory/preloaded skills as usual.\",\n },\n {\n id: \"lean\",\n description:\n \"Skip ~/.hermes/config.yaml, cutting the skills/rules/memory scaffolding hermes \" +\n \"would otherwise preload into context. Composed as `hermes --ignore-user-config \" +\n \"acp` — the global flag MUST precede the `acp` subcommand baked into `bin_args`, \" +\n \"which is why this needs bin_args_prepend rather than bin_args_append.\",\n bin_args_prepend: [\"--ignore-user-config\"],\n status: \"noop\",\n status_note:\n \"Measured no-op: --ignore-user-config skips ~/.hermes/config.yaml, but hermes \" +\n \"skills live in a separate skills dir (not config), so prompt-size is \" +\n \"byte-identical. The real lean lever is narrowing the mounted toolset, not \" +\n \"this flag.\",\n },\n ],\n options: [\n {\n id: \"skills\",\n type: \"string\" as const,\n description:\n \"Preload one or more agentskills.io-compatible skills for the session \" +\n \"(comma-separate for multiple), via hermes' `--skills` global flag. Same \" +\n \"prepend-before-`acp` constraint as the `lean` mode.\",\n bin_args_prepend: [\"--skills\", \"{value}\"],\n },\n {\n id: \"model\",\n // string (not enum) so any valid OpenRouter/OpenAI model ID is accepted\n // without a code change to expand the list. Applied via ACP\n // newSession(model:...) — hermes reads the model from the ACP session\n // config, not from its own CLI args. Anthropic ids are denied\n // (models.deny) — those are reserved for the claude-code adapter.\n type: \"string\" as const,\n description:\n \"Model ID routed through OpenRouter/OpenAI \" +\n \"(e.g. 'deepseek/deepseek-v4-pro', 'z-ai/glm-5.2@openrouter', 'moonshotai/kimi-k2@openrouter'). \" +\n \"Anthropic models are not permitted on hermes — use the claude-code \" +\n \"adapter for those. \" +\n \"Applied via a `/model <id>` control turn after the session is created \" +\n \"(hermes ignores the ACP session model config). \" +\n \"Omit to use the hermes default.\",\n },\n {\n id: \"effort\",\n type: \"enum\" as const,\n enum: [\"low\", \"medium\", \"high\", \"xhigh\", \"max\"],\n description:\n \"Reasoning effort level passed to hermes via ACP newSession. \" +\n \"Omit to use the hermes default.\",\n },\n ],\n tags: [\"hermes\", \"nous\", \"acp\", \"agent-runtime\"],\n metadata: {\n // Opts hermes into `agentproto install skill/<slug>` fan-out (no\n // --target given): skills get copied one subdir per skill into\n // hermes's own skills directory, alongside whatever it ships\n // natively. See packages/cli/src/commands/skill-install/types.ts\n // `AdapterSkillsTarget` for the shape + guard.\n skills: { format: \"flat-dir\", dir: \"~/.hermes/skills\" },\n },\n})\n\nexport function hermesRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(hermes)\n}\n\n/** Shape of one `~/.hermes/auth.json` `credential_pool` entry this strategy\n * reads. Only non-secret fields — never the credential value itself. The\n * pool's own `key_env` (when present) is preserved verbatim: hermes' native\n * kimi/moonshot slot is `KIMI_API_KEY`, NOT `MOONSHOT_API_KEY`, so this must\n * never derive/normalize an env var name from the provider id. */\ninterface HermesCredentialPoolEntry {\n provider?: unknown\n key_env?: unknown\n fingerprint?: unknown\n base_url?: unknown\n baseUrl?: unknown\n}\n\ninterface HermesAuthFile {\n credential_pool?: unknown\n}\n\ninterface HermesModelsCacheFile {\n models?: unknown\n}\n\n/**\n * Best-effort capability discovery for hermes: parses hermes' OWN native\n * stores (`~/.hermes/auth.json`, `~/.hermes/provider_models_cache.json`)\n * rather than the manifest's generic `models.env` slots, so it reflects\n * what's ACTUALLY configured on this host, not just what the adapter\n * declares it's capable of. Never throws — `discoverCapabilities` also\n * catches, but every read here is independently defensive so a single\n * malformed file doesn't blank out the providers a good file already\n * yielded.\n */\nexport const hermesCapabilities: CapabilityStrategy = async (def, ctx) => {\n const authPath = join(ctx.homeDir, \".hermes\", \"auth.json\")\n const modelsCachePath = join(ctx.homeDir, \".hermes\", \"provider_models_cache.json\")\n\n const authStores: AuthStore[] = [\n { kind: \"file\", path: \"~/.hermes/auth.json\", format: \"json\", providerKeyed: true },\n ]\n\n const providers: ProviderCapability[] = []\n const authRaw = await ctx.readFile(authPath)\n if (authRaw !== null) {\n try {\n const parsed = JSON.parse(authRaw) as HermesAuthFile\n const pool = Array.isArray(parsed.credential_pool) ? parsed.credential_pool : []\n for (const entry of pool as HermesCredentialPoolEntry[]) {\n if (typeof entry !== \"object\" || entry === null) continue\n const id = typeof entry.provider === \"string\" ? entry.provider : undefined\n if (!id) continue\n const keyEnv = typeof entry.key_env === \"string\" ? entry.key_env : undefined\n const fingerprint = typeof entry.fingerprint === \"string\" ? entry.fingerprint : undefined\n const baseUrl =\n typeof entry.base_url === \"string\"\n ? entry.base_url\n : typeof entry.baseUrl === \"string\"\n ? entry.baseUrl\n : undefined\n // Never guess an env var from the provider id (that's exactly the\n // KIMI_API_KEY vs MOONSHOT_API_KEY trap) — only trust an explicit\n // key_env; otherwise the credential's origin is the pool file itself.\n const source: CredSource = keyEnv\n ? { kind: \"env\", var: keyEnv }\n : { kind: \"file\", path: \"~/.hermes/auth.json\", pointer: `credential_pool[provider=${id}]` }\n providers.push({\n id,\n billingEndpoint: id,\n cred: {\n present: true,\n source,\n ...(fingerprint ? { fingerprint } : {}),\n },\n ...(baseUrl ? { baseUrl } : {}),\n })\n }\n } catch (err) {\n ctx.warn(\n `hermes capability discovery: could not parse ~/.hermes/auth.json: ` +\n `${err instanceof Error ? err.message : String(err)}`,\n )\n }\n }\n\n let ids: string[] | undefined\n let stale = true\n const cacheRaw = await ctx.readFile(modelsCachePath)\n if (cacheRaw !== null) {\n try {\n const parsedCache = JSON.parse(cacheRaw) as HermesModelsCacheFile\n ids = Array.isArray(parsedCache.models)\n ? parsedCache.models.filter((m): m is string => typeof m === \"string\")\n : undefined\n stale = false\n } catch (err) {\n ctx.warn(\n `hermes capability discovery: could not parse ` +\n `~/.hermes/provider_models_cache.json: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n }\n\n const modelApply = def.models?.apply\n return {\n adapter: def.id,\n source: \"discovered\",\n discoverable: \"live\",\n authStores,\n providers,\n models: {\n mechanism: \"file-cache\",\n ref: \"hermes model --refresh\",\n ...(ids ? { ids } : {}),\n stale,\n },\n endpointCompat: {},\n application: {\n modelApply: modelApply === \"command\" || modelApply === \"arg\" ? modelApply : \"config\",\n postureApply: \"none\",\n coupled: false,\n },\n }\n}\n\nimport { homedir } from \"node:os\"\n\n/** Best-effort read of a hermes session's cost/token usage from its state.db.\n *\n * hermes writes the per-turn cost to state.db slightly AFTER the ACP turn\n * ends, so a single read right at turn-end usually finds the cost column\n * still null. We poll a few times with a short backoff until the cost lands\n * (or give up — best-effort, never throws). Bounded so a missing write can't\n * hang the caller (the turn-end path awaits this). */\nexport async function readHermesUsage(\n sessionId: string,\n): Promise<{ costUsd?: number; tokensIn?: number; tokensOut?: number } | null> {\n try {\n // node:sqlite is a Node 22+ builtin. Build the specifier at runtime so the\n // bundler (esbuild/tsup) can't statically rewrite it — it strips the\n // `node:` prefix off this not-yet-recognised builtin, turning the import\n // into a missing `sqlite` package that throws and silently yields null.\n const sqliteSpecifier = [\"node\", \"sqlite\"].join(\":\")\n const { DatabaseSync } = (await import(sqliteSpecifier)) as unknown as {\n DatabaseSync: new (p: string, o?: { readOnly?: boolean }) => {\n prepare(sql: string): { get(...a: unknown[]): unknown }\n close(): void\n }\n }\n const dbPath = join(homedir(), \".hermes\", \"state.db\")\n const ATTEMPTS = 6\n const DELAY_MS = 130\n let last: { costUsd?: number; tokensIn?: number; tokensOut?: number } | null = null\n for (let i = 0; i < ATTEMPTS; i++) {\n const db = new DatabaseSync(dbPath, { readOnly: true })\n const row = db.prepare(\n \"select estimated_cost_usd as cost, input_tokens as ti, output_tokens as to_ from sessions where id = ?\",\n ).get(sessionId) as { cost?: number; ti?: number; to_?: number } | undefined\n db.close()\n if (row) {\n last = { costUsd: row.cost, tokensIn: row.ti, tokensOut: row.to_ }\n // Cost has landed (non-null) → done. Otherwise keep polling: the row\n // exists but hermes hasn't written the cost for this turn yet.\n if (row.cost !== null && row.cost !== undefined) return last\n }\n if (i < ATTEMPTS - 1) await new Promise(r => setTimeout(r, DELAY_MS))\n }\n return last\n } catch {\n return null\n }\n}\n\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AA8CA,SAAS,oBAAA,GAAgE;AACvE,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,EAAE,QAAA,EAAU,YAAA,EAAc,MAAA,EAAQ,YAAA,EAAa;AAAA,IAC/C,EAAE,QAAA,EAAU,QAAA,EAAU,MAAA,EAAQ,QAAA;AAAS,GACzC;AAEA,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,MAA+C,EAAC;AAEtD,EAAA,KAAA,MAAW,EAAE,QAAA,EAAU,MAAA,EAAO,IAAK,SAAA,EAAW;AAC5C,IAAA,KAAA,MAAW,SAAS,UAAA,CAAW,EAAE,MAAM,KAAA,EAAO,QAAA,EAAU,CAAA,EAAG;AACzD,MAAA,MAAM,SAAS,KAAA,CAAM,EAAA;AAIrB,MAAA,IAAI,qBAAA,CAAsB,IAAA,CAAK,MAAM,CAAA,EAAG;AACxC,MAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,GAAG,IAAI,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA;AACvE,MAAA,MAAM,EAAA,GAAK,QAAA,KAAa,YAAA,GAAe,CAAA,EAAG,MAAM,CAAA,WAAA,CAAA,GAAgB,WAAA;AAChE,MAAA,IAAI,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,MAAA,IAAA,CAAK,IAAI,EAAE,C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AAA,EAAK;AACP,QAAA,IAAA,GAAO,EAAE,SAAS,GAAA,CAAI,IAAA,EAAM,UAAU,GAAA,CAAI,EAAA,EAAI,SAAA,EAAW,GAAA,CAAI,GAAA,EAAI;AAGjE,QAAA,IAAI,IAAI,IAAA,KAAS,IAAA,IAAQ,GAAA,CAAI,IAAA,KAAS,QAAW,OAAO,IAAA;AAAA,MAC1D;AACA,MAAA,IAAI,CAAA,GAAI,QAAA,GAAW,CAAA,EAAG,MAAM,IAAI,QAAQ,CAAA,CAAA,KAAK,UAAA,CAAW,CAAA,EAAG,QAAQ,CAAC,CAAA;AAAA,IACtE;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.mjs","sourcesContent":["/**\n * @agentproto/adapter-hermes — AIP-45 adapter for Nous Research's Hermes Agent.\n *\n * Re-exports a `defineAgentCli` instance plus the runtime factory so\n * a host can boot Hermes with one import:\n *\n * import { hermes, hermesRuntime } from \"@agentproto/adapter-hermes\"\n * const session = await hermesRuntime().start({ env: { OPENROUTER_API_KEY } })\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n *\n * The companion HERMES.md / SECRETS.md / hermes-acp.ACP.md files in\n * this package describe the manifest, secret slots, and ACP wire\n * profile.\n */\n\nimport { join } from \"node:path\"\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\nimport { listModels } from \"@agentproto/model-catalog\"\nimport type {\n AuthStore,\n CapabilityStrategy,\n CredSource,\n ProviderCapability,\n} from \"@agentproto/provider-kit\"\n\n/**\n * Build hermes's model menu from the shared provider catalog instead of a\n * hand-maintained allowlist. Hermes routes by the model id's own vendor\n * prefix (routeSelection: \"derived-from-model\"), so every entry carries\n * the billing provider the runtime's eligibility projection needs.\n *\n * Only providers hermes genuinely supports today are included:\n * - OpenRouter (`openrouter/<vendor>/<id>` router prefix)\n * - OpenAI (direct `openai/<id>` vendor prefix)\n *\n * Anthropic models are excluded — hermes is the budget arm and those are\n * reserved for the claude-code adapter (enforced by models.deny).\n */\nfunction buildHermesModelMenu(): Array<{ id: string; provider: string }> {\n const supported = [\n { provider: \"openrouter\", prefix: \"openrouter\" },\n { provider: \"openai\", prefix: \"openai\" },\n ] as const\n\n const seen = new Set<string>()\n const out: Array<{ id: string; provider: string }> = []\n\n for (const { provider, prefix } of supported) {\n for (const model of listModels({ kind: \"llm\", provider })) {\n const bareId = model.id\n // Skip anthropic models (reserved for claude-code adapter) and\n // tilde-prefixed OpenRouter provider aliases (~deepseek, ~google, …)\n // which aren't real vendor names and break the route-identity parser.\n if (/anthropic|claude|^~/.test(bareId)) continue\n const canonicalId = bareId.includes(\"/\") ? bareId : `${prefix}/${bareId}`\n const id = provider === \"openrouter\" ? `${bareId}@openrouter` : canonicalId\n if (seen.has(id)) continue\n seen.add(id)\n out.push({ id, provider })\n }\n }\n\n return out.sort((a, b) => {\n if (a.provider !== b.provider) return a.provider.localeCompare(b.provider)\n return a.id.localeCompare(b.id)\n })\n}\n\nexport const hermes: AgentCliHandle = defineAgentCli({\n name: \"hermes\",\n id: \"hermes\",\n description:\n \"Nous Research's Hermes Agent — autonomous CLI agent with skills, sandboxes, memory plugins, and a built-in ACP server. Spawned as `hermes acp` and driven over stdio JSON-RPC.\",\n version: \"0.1.0\",\n bin: \"hermes\",\n bin_args: [\"acp\"],\n install: [\n {\n method: \"curl\",\n url: \"https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh\",\n },\n ],\n version_check: {\n cmd: \"hermes --version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n range: \">=0.13.0 <1.0.0\",\n timeout_ms: 5000,\n },\n auth: {\n ref: \"./SECRETS.md\",\n // No ANTHROPIC_API_KEY — hermes is the budget arm and deliberately does\n // not route to Anthropic (see models.deny). Anthropic stays exclusive to\n // the claude-code adapter.\n state: { env: [\"OPENROUTER_API_KEY\", \"OPENAI_API_KEY\"] },\n },\n // Billing-auth (opt-in — no authEnforce, so unconfigured spawns stay\n // ambient). Single-provider adapter: api-key mode SETS providerEnvVar\n // (\"openrouter\") = OPENROUTER_API_KEY, derived from the catalog. No\n // authSubscription ⇒ `subscription` fails loud with `unsupported_auth_mode`.\n provider: \"openrouter\",\n // The endpoint falls out of the model id's vendor prefix — `openai/*` is\n // routed through OpenAI, everything else through OpenRouter (see the\n // `model` option) — so there is nothing independent to choose: picking the\n // model already fixes the route → derived-from-model.\n routeSelection: \"derived-from-model\",\n sandbox: \"./SANDBOX.md\",\n protocol: \"acp\",\n acp: \"./hermes-acp.ACP.md\",\n session: {\n mode: \"persistent\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n // hermes's own ACP server has been observed to hit its internal\n // max-tool-iterations cap, produce a final answer, and then never\n // send the `prompt` JSON-RPC response — hanging the daemon's turn\n // drain loop forever with no other adapter-side signal available.\n // 5 minutes of true silence (reset on any ACP traffic, so a long\n // legitimate tool-call chain doesn't false-positive) is generous\n // enough to not trip during normal use.\n turn_idle_timeout_ms: 300_000,\n },\n models: {\n // Cheap OpenRouter models by default — hermes is the budget delegation\n // arm (a Sonnet default would defeat the purpose). glm-5.2 + deepseek\n // are the go-to cheap coders.\n default: \"z-ai/glm-5.2@openrouter\",\n // Generated from the shared provider catalog so the Configuration Lab /\n // harness picker shows genuinely reachable OpenRouter + OpenAI models\n // instead of a hand-maintained static list. Anthropic models are filtered\n // out at generation time (and enforced by deny below). The free-form\n // `model` option still accepts any valid OpenRouter/OpenAI id.\n allowed: buildHermesModelMenu(),\n // Anthropic models are reserved for the dedicated claude-code adapter —\n // hermes must NEVER route to them, even if a caller passes the id\n // explicitly. Enforced at compose time (RuntimeConfigError), so the\n // budget arm can't silently burn premium Anthropic spend.\n deny: [\"anthropic/*\", \"claude-*\"],\n env: {\n openrouter: \"OPENROUTER_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n },\n // hermes keeps its own configured default when given a model via the\n // ACP session config — selection must go through a `/model <id>`\n // control turn instead. See AgentCliModels.apply.\n apply: \"command\",\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: true,\n resumable: false,\n bidirectional: true,\n // Hermes has a verified native TUI resume path:\n // `hermes --resume <SESSION> --tui`. This lets the daemon offer\n // provider-native terminal restart for Hermes sessions, distinct from\n // its ACP-level `resumable: false` honesty.\n // Gated on Node ≥22.5: hermes TUI uses node:sqlite which is\n // unavailable on older runtimes — attempting pty-native restart on\n // Node <22.5 errors at startup, not at resume.\n nativeTerminalResume: (() => {\n const [major, minor] = process.versions.node.split(\".\").map(Number)\n return (major ?? 0) > 22 || ((major ?? 0) === 22 && (minor ?? 0) >= 5)\n })(),\n },\n modes: [\n {\n id: \"default\",\n description:\n \"Standard interactive mode — loads ~/.hermes/config.yaml and auto-injects \" +\n \"rules/memory/preloaded skills as usual.\",\n },\n {\n id: \"lean\",\n description:\n \"Skip ~/.hermes/config.yaml, cutting the skills/rules/memory scaffolding hermes \" +\n \"would otherwise preload into context. Composed as `hermes --ignore-user-config \" +\n \"acp` — the global flag MUST precede the `acp` subcommand baked into `bin_args`, \" +\n \"which is why this needs bin_args_prepend rather than bin_args_append.\",\n bin_args_prepend: [\"--ignore-user-config\"],\n status: \"noop\",\n status_note:\n \"Measured no-op: --ignore-user-config skips ~/.hermes/config.yaml, but hermes \" +\n \"skills live in a separate skills dir (not config), so prompt-size is \" +\n \"byte-identical. The real lean lever is narrowing the mounted toolset, not \" +\n \"this flag.\",\n },\n ],\n options: [\n {\n id: \"skills\",\n type: \"string\" as const,\n description:\n \"Preload one or more agentskills.io-compatible skills for the session \" +\n \"(comma-separate for multiple), via hermes' `--skills` global flag. Same \" +\n \"prepend-before-`acp` constraint as the `lean` mode.\",\n bin_args_prepend: [\"--skills\", \"{value}\"],\n },\n {\n id: \"model\",\n // string (not enum) so any valid OpenRouter/OpenAI model ID is accepted\n // without a code change to expand the list. Applied via ACP\n // newSession(model:...) — hermes reads the model from the ACP session\n // config, not from its own CLI args. Anthropic ids are denied\n // (models.deny) — those are reserved for the claude-code adapter.\n type: \"string\" as const,\n description:\n \"Model ID routed through OpenRouter/OpenAI \" +\n \"(e.g. 'deepseek/deepseek-v4-pro', 'z-ai/glm-5.2@openrouter', 'moonshotai/kimi-k2@openrouter'). \" +\n \"Anthropic models are not permitted on hermes — use the claude-code \" +\n \"adapter for those. \" +\n \"Applied via a `/model <id>` control turn after the session is created \" +\n \"(hermes ignores the ACP session model config). \" +\n \"Omit to use the hermes default.\",\n },\n {\n id: \"effort\",\n type: \"enum\" as const,\n enum: [\"low\", \"medium\", \"high\", \"xhigh\", \"max\"],\n description:\n \"Reasoning effort level passed to hermes via ACP newSession. \" +\n \"Omit to use the hermes default.\",\n },\n ],\n tags: [\"hermes\", \"nous\", \"acp\", \"agent-runtime\"],\n metadata: {\n // Opts hermes into `agentproto install skill/<slug>` fan-out (no\n // --target given): skills get copied one subdir per skill into\n // hermes's own skills directory, alongside whatever it ships\n // natively. See packages/cli/src/commands/skill-install/types.ts\n // `AdapterSkillsTarget` for the shape + guard.\n skills: { format: \"flat-dir\", dir: \"~/.hermes/skills\" },\n },\n})\n\nexport function hermesRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(hermes)\n}\n\n/** Shape of one `~/.hermes/auth.json` `credential_pool` entry this strategy\n * reads. Only non-secret fields — never the credential value itself. The\n * pool's own `key_env` (when present) is preserved verbatim: hermes' native\n * kimi/moonshot slot is `KIMI_API_KEY`, NOT `MOONSHOT_API_KEY`, so this must\n * never derive/normalize an env var name from the provider id. */\ninterface HermesCredentialPoolEntry {\n provider?: unknown\n key_env?: unknown\n fingerprint?: unknown\n base_url?: unknown\n baseUrl?: unknown\n}\n\ninterface HermesAuthFile {\n credential_pool?: unknown\n}\n\ninterface HermesModelsCacheFile {\n models?: unknown\n}\n\n/**\n * Best-effort capability discovery for hermes: parses hermes' OWN native\n * stores (`~/.hermes/auth.json`, `~/.hermes/provider_models_cache.json`)\n * rather than the manifest's generic `models.env` slots, so it reflects\n * what's ACTUALLY configured on this host, not just what the adapter\n * declares it's capable of. Never throws — `discoverCapabilities` also\n * catches, but every read here is independently defensive so a single\n * malformed file doesn't blank out the providers a good file already\n * yielded.\n */\nexport const hermesCapabilities: CapabilityStrategy = async (def, ctx) => {\n const authPath = join(ctx.homeDir, \".hermes\", \"auth.json\")\n const modelsCachePath = join(ctx.homeDir, \".hermes\", \"provider_models_cache.json\")\n\n const authStores: AuthStore[] = [\n { kind: \"file\", path: \"~/.hermes/auth.json\", format: \"json\", providerKeyed: true },\n ]\n\n const providers: ProviderCapability[] = []\n const authRaw = await ctx.readFile(authPath)\n if (authRaw !== null) {\n try {\n const parsed = JSON.parse(authRaw) as HermesAuthFile\n const pool = Array.isArray(parsed.credential_pool) ? parsed.credential_pool : []\n for (const entry of pool as HermesCredentialPoolEntry[]) {\n if (typeof entry !== \"object\" || entry === null) continue\n const id = typeof entry.provider === \"string\" ? entry.provider : undefined\n if (!id) continue\n const keyEnv = typeof entry.key_env === \"string\" ? entry.key_env : undefined\n const fingerprint = typeof entry.fingerprint === \"string\" ? entry.fingerprint : undefined\n const baseUrl =\n typeof entry.base_url === \"string\"\n ? entry.base_url\n : typeof entry.baseUrl === \"string\"\n ? entry.baseUrl\n : undefined\n // Never guess an env var from the provider id (that's exactly the\n // KIMI_API_KEY vs MOONSHOT_API_KEY trap) — only trust an explicit\n // key_env; otherwise the credential's origin is the pool file itself.\n const source: CredSource = keyEnv\n ? { kind: \"env\", var: keyEnv }\n : { kind: \"file\", path: \"~/.hermes/auth.json\", pointer: `credential_pool[provider=${id}]` }\n providers.push({\n id,\n billingEndpoint: id,\n cred: {\n present: true,\n source,\n ...(fingerprint ? { fingerprint } : {}),\n },\n ...(baseUrl ? { baseUrl } : {}),\n })\n }\n } catch (err) {\n ctx.warn(\n `hermes capability discovery: could not parse ~/.hermes/auth.json: ` +\n `${err instanceof Error ? err.message : String(err)}`,\n )\n }\n }\n\n let ids: string[] | undefined\n let stale = true\n const cacheRaw = await ctx.readFile(modelsCachePath)\n if (cacheRaw !== null) {\n try {\n const parsedCache = JSON.parse(cacheRaw) as HermesModelsCacheFile\n ids = Array.isArray(parsedCache.models)\n ? parsedCache.models.filter((m): m is string => typeof m === \"string\")\n : undefined\n stale = false\n } catch (err) {\n ctx.warn(\n `hermes capability discovery: could not parse ` +\n `~/.hermes/provider_models_cache.json: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n }\n\n const modelApply = def.models?.apply\n return {\n adapter: def.id,\n source: \"discovered\",\n discoverable: \"live\",\n authStores,\n providers,\n models: {\n mechanism: \"file-cache\",\n ref: \"hermes model --refresh\",\n ...(ids ? { ids } : {}),\n stale,\n },\n endpointCompat: {},\n application: {\n modelApply: modelApply === \"command\" || modelApply === \"arg\" ? modelApply : \"config\",\n postureApply: \"none\",\n coupled: false,\n },\n }\n}\n\nimport { homedir } from \"node:os\"\n\n/** Best-effort read of a hermes session's cost/token usage from its state.db.\n *\n * hermes writes the per-turn cost to state.db slightly AFTER the ACP turn\n * ends, so a single read right at turn-end usually finds the cost column\n * still null. We poll a few times with a short backoff until the cost lands\n * (or give up — best-effort, never throws). Bounded so a missing write can't\n * hang the caller (the turn-end path awaits this). */\nexport async function readHermesUsage(\n sessionId: string,\n): Promise<{ costUsd?: number; tokensIn?: number; tokensOut?: number } | null> {\n try {\n // node:sqlite is a Node 22+ builtin. Build the specifier at runtime so the\n // bundler (esbuild/tsup) can't statically rewrite it — it strips the\n // `node:` prefix off this not-yet-recognised builtin, turning the import\n // into a missing `sqlite` package that throws and silently yields null.\n const sqliteSpecifier = [\"node\", \"sqlite\"].join(\":\")\n const { DatabaseSync } = (await import(sqliteSpecifier)) as unknown as {\n DatabaseSync: new (p: string, o?: { readOnly?: boolean }) => {\n prepare(sql: string): { get(...a: unknown[]): unknown }\n close(): void\n }\n }\n const dbPath = join(homedir(), \".hermes\", \"state.db\")\n const ATTEMPTS = 6\n const DELAY_MS = 130\n let last: { costUsd?: number; tokensIn?: number; tokensOut?: number } | null = null\n for (let i = 0; i < ATTEMPTS; i++) {\n const db = new DatabaseSync(dbPath, { readOnly: true })\n const row = db.prepare(\n \"select estimated_cost_usd as cost, input_tokens as ti, output_tokens as to_ from sessions where id = ?\",\n ).get(sessionId) as { cost?: number; ti?: number; to_?: number } | undefined\n db.close()\n if (row) {\n last = { costUsd: row.cost, tokensIn: row.ti, tokensOut: row.to_ }\n // Cost has landed (non-null) → done. Otherwise keep polling: the row\n // exists but hermes hasn't written the cost for this turn yet.\n if (row.cost !== null && row.cost !== undefined) return last\n }\n if (i < ATTEMPTS - 1) await new Promise(r => setTimeout(r, DELAY_MS))\n }\n return last\n } catch {\n return null\n }\n}\n\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentproto/adapter-hermes",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "@agentproto/adapter-hermes — AIP-45 AGENT-CLI adapter for Nous Research's Hermes Agent. Spawns `hermes acp` and drives it as an agentproto agent CLI via the ACP protocol arm of @agentproto/driver-agent-cli.",
5
5
  "keywords": [
6
6
  "agentproto",
@@ -43,8 +43,8 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@agentproto/driver-agent-cli": "2.2.1",
47
- "@agentproto/model-catalog": "0.8.2",
46
+ "@agentproto/driver-agent-cli": "2.3.0",
47
+ "@agentproto/model-catalog": "0.8.3",
48
48
  "@agentproto/provider-kit": "0.4.1"
49
49
  },
50
50
  "devDependencies": {