Skip to main content

Module m4a_adopt

Module m4a_adopt 

Source
Expand description

Adoption of a provider session the node did not spawn: the node gives it a per-session m4a account and puts the node’s own m4a MCP server (m4a-agent mcp, stdio) in the provider’s config, removing a stale standalone mailbox MCP entry (a loopback HTTP url) with a backup.

POST /m4a/adopt?provider=<id>&session=<provider session id>[&stale=<entry name>] (owner token, same policy as /m4a/attach):

  1. provisions the account under the same key /m4a/attach uses for that session, so the MCP server’s own attach later gets the same nick;
  2. records a pending adoption, so an attach whose caller carries no session id (an MCP child of a shared provider backend) is bound to this session and not to the backend’s pid;
  3. for grok: rewrites <grok home>/config.toml (backup first) and returns the mcpServers entry an ACP session/load can carry, which grok reads when the session is (re)loaded.

The MCP entry in the shared config names no account: each MCP process attaches by its own ancestry and session, so every session gets its own nick from one config.

Structs§

ConfigEdit

Constants§

DEFAULT_STALE_ENTRY
NODE_ENTRY

Functions§

add_pending
apply_grok_config
Applies rewrite_grok_config to a file: writes <file>.bak-<unix secs> first, then the new text through a temp file and rename. A missing file is created (nothing to back up).
claim_pending
Takes the oldest live pending adoption of provider (one attach binds one session).
client_adopt
Client side (gate4agent-node m4a-adopt): owner token from the file /health names.
grok_config_path
<grok home>/config.toml: GROK_HOME, else ~/.grok.
handle
Handles /m4a/adopt.
is_loopback_http
Is url a loopback HTTP endpoint (a standalone local mailbox daemon)?
mcp_args
MCP server args the node’s own entry uses (no account, no secret: identity comes from attach).
process_cmdline
Command line of a live process (argv), best effort.
query_escape
Percent-encodes one query value (spaces, backslashes, colons, non-ASCII).
resolve_session
Session key resolution for an attach: explicit > provider command line > pending adoption.
resolve_session_in
resolve_session with the node’s saved adoptions: when the provider has exactly one adopted session, an attach with no session of its own is that session (any number of reloads, any time after the adoption, across node restarts). This keeps adopt and attach on one account (attach-<provider>-<session>).
rewrite_grok_config
Pure edit of a grok config.toml: drops mcp_servers.<stale> when it is a loopback HTTP url, and sets mcp_servers.m4a to the node’s stdio server. Other content is kept verbatim.
session_from_cmdline
Session id named on a provider command line (--resume <id>, --session <id>, = forms).
split_windows_cmdline
Minimal Windows command-line split (quotes group, backslashes kept).