Skip to main content

Module agent_cli

Module agent_cli 

Source
Expand description

Which agent CLIs this machine has, and how recall-echo wires itself into them.

Three questions are asked about the same four CLIs, and before this module each was answered somewhere else, or not at all:

  • which one extracts knowledgecrate::config::Provider, chosen by a six-item menu that only ever auto-detected Claude Code;
  • whose sessions get capturedcrate::transcript::detect_installed, which answers for the three CLIs that have transcript adapters;
  • who can query memory over MCP — nobody, because registering the server was a command in the README.

AgentCli is the one place that knows a CLI end to end: its binary, its provider preset, its transcript source if it has one, and the exact mcp add incantation it wants. init asks here and stops guessing.

§Detection

A CLI counts as installed when its binary resolves — on PATH, or at the absolute path an override names. Recorded transcripts are a different question (a machine can hold Codex sessions long after Codex was uninstalled) and the capture layer already answers it; both extraction and MCP registration need a binary to run, so that is what is tested here.

The binary name comes from CliSpec, so CLAUDE_BIN, GEMINI_BIN, GROK_BIN and CODEX_BIN steer detection exactly as they steer the calls made later.

§mcp add is four different commands

Every one of these CLIs registers stdio MCP servers, and no two agree on how. Each argv below was verified against the installed binary (claude 2.x, gemini 0.27, grok, codex 0.146) by running it against a throwaway HOME and reading back the config it wrote:

claude mcp add recall-echo -s user -- <exe> mcp --entity-root <root>
gemini mcp add -s user recall-echo  <exe> mcp --entity-root <root>
grok   mcp add recall-echo -s user -- <exe> mcp --entity-root <root>
codex  mcp add recall-echo          -- <exe> mcp --entity-root <root>

Gemini takes the server name after its flags and rejects a -- separator; Codex has no scope flag at all and always writes ~/.codex/config.toml.

§Idempotency

Every client stores servers in a map keyed by name, so re-registering the same name with the same argv is a no-op by construction. What differs is what they say about it: Claude refuses with a non-zero exit and “already exists”, Gemini says “already configured” and rewrites, Grok and Codex rewrite silently. classify folds those four dialects into one McpStatus so the user reads a result rather than four vendors’ opinions.

Structs§

McpReport
One client’s outcome, with the command that produced it — so a failure can be handed to the user verbatim instead of described.

Enums§

AgentCli
An agent CLI recall-echo can extract with, capture from, or serve over MCP.
McpStatus
What happened when recall-echo’s MCP server was offered to one client.

Constants§

MCP_SERVER_NAME
Name recall-echo registers its MCP server under, in every client.

Functions§

capturing
Which CLIs have actually recorded sessions here — the capture layer’s own answer, mapped back onto AgentCli.
classify
Read one client’s answer to mcp add.
current
The CLI this process is running under, when it says so.
installed
Every agent CLI whose binary resolves on this machine.
register_mcp
Register recall-echo’s MCP server with one client.
resolve_binary
Find command the way a shell would: as a path if it looks like one, otherwise by walking PATH.
shell_line
An argv as a line a user can paste back into a shell.