@alfe.ai/gateway

中文文档
0.14.5发布于 2026/11/05UNLICENSEDTypeScriptES Module近 30 天下载 2374

Alfe local gateway daemon — persistent control plane for agent integrations

原始使用文档
文档目录16 节
  1. Overview
  2. Architecture
  3. Prerequisites
  4. Usage
  5. Via alfe CLI (recommended)
  6. Via standalone binary
  7. IPC Protocol
  8. Request (plugin → daemon)
  9. Response (daemon → plugin)
  10. Event (daemon → plugin)
  11. Current methods
  12. File Locations
  13. Security
  14. Development
  15. Cloud Protocol
  16. Links

@alfe.ai/gateway

Local gateway daemon for Alfe — the always-on control plane between an agent VM, its runtime, and Alfe cloud.

Overview

The gateway daemon is a standalone Node.js process that:

  • Maintains a persistent WebSocket connection to Alfe cloud (@alfe/gateway-service on Fly.io)
  • Exposes a Unix socket at ~/.alfe/gateway.sock for local plugin IPC
  • Reconciles integrations and state-shaped runtime config from full cloud snapshots
  • Supervises the selected runtime (openclaw, hermes, or claude-code)
  • Hosts the local AI proxy and MCP bundler
  • Survives runtime restarts and reports lifecycle/health back to cloud

Architecture

Alfe Cloud ←—— control WS ——→ @alfe.ai/gateway (daemon)
                                     ├── runtime supervisor → OpenClaw/Hermes/Claude host
                                     ├── integration reconciliation
                                     ├── local AI proxy + MCP bundler
                                     └── IPC (~/.alfe/gateway.sock) ← runtime plugins/CLI

Prerequisites

  1. Run alfe setup (or managed provisioning) to configure agent identity
  2. Node.js 22+
  3. pnpm

Usage

# Start daemon (foreground)
alfe gateway start

# Check status
alfe gateway status

# Stop daemon
alfe gateway stop

# Install as system service (auto-start on boot)
alfe gateway install

# Remove system service
alfe gateway uninstall

# View logs
alfe gateway logs

# Full health check
alfe doctor

Via standalone binary

# Start daemon in foreground
alfe-gateway start

# Status
alfe-gateway status

# Stop
alfe-gateway stop

IPC Protocol

Plugins connect to ~/.alfe/gateway.sock and speak newline-delimited JSON:

Request (plugin → daemon)

{ "type": "req", "id": "uuid", "method": "register", "params": { "name": "my-plugin", "version": "1.0.0", "protocolVersion": 1, "capabilities": ["integrations"] } }

Response (daemon → plugin)

{ "id": "uuid", "ok": true, "payload": { "status": "registered", "daemonVersion": "<current CLI version>", "protocolVersion": 1 } }

Event (daemon → plugin)

{ "type": "event", "event": "cloud.status", "payload": { "connected": true } }

Current methods

DirectionMethodDescription
Daemon→Pluginruntime.activityProbe whether a chat turn is in flight before a planned restart
Plugin→DaemonregisterRegister plugin with daemon
Plugin→DaemonstatusGet daemon health status
Plugin→Daemonintegration.listList known integrations
Plugin→Daemonintegration.reportReport integration status
Plugin→Daemonmcp.list_tools / mcp.call_toolInspect or invoke bundled MCP tools
Plugin→Daemonmcp.list_servers / mcp.add_server / mcp.remove_serverManage local MCP servers

IPC is owner-only, newline-delimited JSON. Requests must contain non-empty id/method fields and an object params; individual messages are capped at 1 MiB.

File Locations

FilePath
Config~/.alfe/config.toml
Socket~/.alfe/gateway.sock
PID file~/.alfe/gateway.pid
Logs~/.alfe/logs/gateway.log
launchd plist~/Library/LaunchAgents/ai.alfe.gateway.plist
systemd unit~/.config/systemd/user/alfe-gateway.service
managed systemd environment~/.alfe/gateway.env (or /etc/alfe/gateway.env for root)

Security

  • Socket file is chmod 0600 (owner-only access)
  • PID ownership is verified against the live process command before signals are sent
  • Managed systemd credentials are stored in an owner-only (0600) environment file, not the unit text
  • Credential fragments are never logged
  • Auth uses the agent API key from managed environment or ~/.alfe/config.toml

Development

# From monorepo root
pnpm install
pnpm --filter @alfe.ai/gateway build
pnpm --filter @alfe.ai/gateway test
pnpm --filter @alfe.ai/gateway lint
pnpm --filter @alfe.ai/gateway typecheck

# Dev mode (auto-restart on changes)
pnpm --filter @alfe.ai/gateway dev

Cloud Protocol

The daemon speaks the following message types with the cloud gateway service:

DirectionMessageDescription
OutboundSERVICE_REGISTERRegister daemon with cloud
InboundSERVICE_ACKCloud acknowledges registration
InboundCOMMANDCloud sends a command to execute
OutboundCOMMAND_ACKDaemon reports command result
InboundDESIRED_STATECloud pushes desired integration state
OutboundRECONCILIATION_REPORTDaemon reports reconciliation results
OutboundCOMMANDS_AVAILABLEDaemon advertises integration commands
InboundPINGCloud heartbeat
OutboundPONGDaemon heartbeat response

DESIRED_STATE is an atomic, deletion-capable snapshot. The daemon validates every nested entry and rejects the entire frame when one row is malformed or duplicated. It also skips all mutation if local integration state cannot be read. See src/protocol.ts, src/reconciliation.ts, and DEVELOPING.md for the full contracts.

版本与发布记录

@alfe.ai/gateway 共发布 124 个版本,首次发布于 2026/03/27;过去 12 个月发布了 124 个版本。

版本发布日期距今
0.14.5latest2026/11/052 天前
0.14.42026/10/2810 天前
0.14.32026/10/2810 天前
0.14.22026/10/2810 天前
0.14.12026/10/2810 天前
0.14.02026/10/2216 天前

关于 @alfe.ai/gateway 的常见问题

@alfe.ai/gateway 是什么?

Alfe local gateway daemon — persistent control plane for agent integrations

如何安装 @alfe.ai/gateway?

在项目目录运行 npm install @alfe.ai/gateway,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 alfe-gateway,可以用 npx alfe-gateway 直接运行。

@alfe.ai/gateway 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alfe.ai/gateway 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alfe.ai/gateway 可以商用吗?

@alfe.ai/gateway 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@alfe.ai/gateway 的下载量有多少?

根据 npm 官方下载统计,@alfe.ai/gateway 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,374 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alfe.ai/gateway 还在维护吗?

最新版本 0.14.5 发布于 2026/11/05(2 天前);至今共发布 124 个版本,其中过去 12 个月发布了 124 个;首次发布于 2026/03/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。