agim-cli 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -1,476 +1,136 @@
1
- # Agim · 阿吉姆
2
-
3
- [中文文档](README.zh-CN.md)
4
-
5
- **Universal messenger-to-agent bridge** — connect WeChat / Feishu / DingTalk / Email to Claude Code / Codex / OpenCode, or any custom agent via ACP. Single Node.js process, no Docker, no Redis.
6
-
7
- > **Naming**: Agim ⟵ Agent + IM (with a hint of "agile"). Chinese name 阿吉姆.
8
- > npm package: **`agim-cli`** (the unscoped `agim` is reserved by npm's
9
- > anti-typosquat policy); the installed binary is **`agim`** — that's what
10
- > you type. The legacy `im-hub-pro` bin name is kept as an alias so existing
11
- > systemd units / shell aliases keep working unchanged.
12
- > On-disk paths default to **`~/.agim/`** for fresh installs but auto-detect
13
- > and continue using a pre-existing **`~/.agim/`** if one is present.
14
- > Env vars (`IMHUB_*`), HTTP headers (`X-IM-Hub-Token`), and the systemd
15
- > unit `im-hub.service` retain their legacy names for drop-in compatibility
16
- > with installations from the 0.x line — see [Migrating](#migrating).
17
-
18
- ## Highlights
19
-
20
- - **3 messengers + email, 6 agents** — WeChat (image / file / voice), Feishu, DingTalk (image / voice with server-side ASR), Email (SMTP); Claude Code, Codex, OpenCode, Antigravity, **Cursor (v1.2.49+ · `/cs`)**, and the in-process `native` LLM agent (DeepSeek / Kimi / Qwen / OpenAI / Anthropic compat — `/na`). Plus any ACP endpoint.
21
- - **Native LLM stack (v1.3.0+, hardened in v1.2.48)** — built-in in-process agent loop (`native` adapter) that talks directly to any OpenAI- / Anthropic-compatible API (DeepSeek, Kimi, GLM, Qwen, Ollama, vLLM, OpenAI, Anthropic). v1.2.48 makes native production-ready: **operator role definition** via `~/.agim-workspaces/native/AGENTS.md` (hot-reloaded, no restart), **multimodal vision** (image attachments → openai-compat `image_url` blocks), **auto-compact** long histories (>60k chars summarised by cheap role), **provider fallback chain** on transient 5xx/timeout, **turn-level heartbeat** every 3 min so multi-hop research turns never look dead, **28-min agent-loop timeout** (was 5-min default, killed long `call_agent` chains). Use it as a cheap router for `memory-distill` / `memory-consolidate` / `intent-llm`, as a local-first chat agent (`/na`), or as a peer in A2A. See [`docs/llm-backends.md`](docs/llm-backends.md) + [`docs/architecture-bridge-and-native.md`](docs/architecture-bridge-and-native.md).
22
- - **Native setup UX (latest)** — switching to `native` from `/chat` or `/m/chat` now opens a persistent setup modal when no usable backend exists; users can configure provider + model + API key inline and retry immediately. `llmRoles` role bindings are now optional preference wiring, not a hard blocker.
23
- - **Skills multi-root scan (v1.2.48+)** — `IMHUB_SKILLS_MODE=auto` (default) merges `~/.agim/skills/` (write target) with `~/.claude/skills/`, `~/.config/opencode/skills/`, `~/.codex/skills/` so a fresh install sees every skill you already have from CLI agents. Workspace skills shadow same-named inherited entries. Settings → 技能 has 2 subtabs (Installed editor + skillhub 热门); top-level `/skills` nav merged into Settings.
24
- - **Cross-channel outbox alert (v1.2.48+)** — when a thread's outbox is dead (e.g. wechat session expired), agim auto-invalidates the stale context-token + pushes a "⚠️ outbox 告警" to your configured backup channel (`IMHUB_OPERATOR_ALERT_PLATFORM` / `IMHUB_OPERATOR_ALERT_THREAD_ID`) so you find out before the user does.
25
- - **Per-thread sustained goals (v1.3.0+ · `/goal`)** — one active multi-turn objective per IM thread, auto-injected into every prompt so the agent stays on-mission across many user turns. Lifecycle: `set / body / progress / pause / resume / complete / cancel / list`. Cross-thread admin at `/tasks/goals`. See [`docs/goals.md`](docs/goals.md).
26
- - **Heartbeat scheduler (v1.3.0+ · `/heartbeat`)** — bind a thread to a periodic "anything to do right now?" tick. Each tick runs DECIDE (cheap LLM) → EXECUTE (the agent does the work) → EVALUATE (notification gate decides whether to ping the user). Cross-thread admin at `/tasks/heartbeat`.
27
- - **Structured agent → user choice (v1.3.0+ · `mcp__imhub__ask_user`)** — agents present an N-way multiple-choice question and reliably get a typed answer back (button + text reply, configurable timeout). Avoids the "free-form chat" ambiguity for disambiguation. Pending-queue admin at `/tasks/asks`. See [`docs/ask-user.md`](docs/ask-user.md).
28
- - **agim Skills engine (v1.3.0+ · `/skill`)** — drop a `SKILL.md` into `~/.agim/skills/<name>/`, every CLI agent + native sees it. 3-tier progressive disclosure (name+desc always-on, body on-demand via `mcp__imhub__read_skill`, scripts/refs via normal file-read). Web editor at `/settings/agim-skills`. See [`docs/skills.md`](docs/skills.md).
29
- - **`/router compare` A/B evaluator (v1.3.0+)** — run the same prompt against two backends side-by-side (any combo of CLI and native), get latency + tokens + outputs in one card so you can pick a winner before changing `defaultAgent`.
30
- - **Compliance-first defaults (v1.2.23+)** — global IM adapters (Discord, Telegram) and the remote-ACP-agent surface are **hidden** by default; no installer prompt or web-admin card exposes them. Mainland-China deployments should leave them disabled. For cross-border setups, opt-in via `IMHUB_ENABLE_GLOBAL_IM=1` / `IMHUB_ENABLE_REMOTE_AGENT=1`. See [`docs/security-hardening.md`](docs/security-hardening.md) for the full security control catalogue (~30 env vars / sensitive-path denylist / outbound secret scrubber / audit-events table / admin role on tokens / R14 systemctl-aware lifecycle).
31
- - **Agent-to-Agent (A2A)** — agents call other agents inline via `mcp__imhub__call_agent`. Just say *"用 codex 帮我跑 git status"* / *"ask opencode to run the tests"* — the active agent hands off, waits, integrates the reply. Guardrails: depth limit (default 3), self-call ban, workspace whitelist, per-user budget. Observability: `/a2a stats | recent | tree <id>`. Disable with `IMHUB_A2A_ENABLED=0`.
32
- - **A2A shared artifacts (v1.1.3+)** — caller drops files into the callee's workspace via `inputs[]` (`fromAbsolutePath` / `fromCallerOutput` / inline `content`), and callee writes products to `~/.agim/artifacts/<jobId>/_agim-output/`. Returned `outputs[]` lets the caller read files on demand. Hard-link first, copy fallback. Size caps configurable.
33
- - **IM long-message viewer (v1.1.6+)** — WeChat / Feishu and friends render rich markdown poorly. When an agent's reply exceeds the size threshold (or contains a markdown table / large code block), agim stashes the full markdown in `~/.agim/viewer.db` (permanent, local-only — content never leaves your host) and sends the IM a short summary + a link `https://<your-host>/v/<uuid>`. The link is served by agim's own web console — operator exposes the web port (cloudflared / caddy / tailscale of choice). Agents can opt in explicitly by wrapping long answers in `<im-summary>…</im-summary><full-md>…</full-md>`. Enable with `IMHUB_VIEWER_ENABLED=1` + `IMHUB_VIEWER_PUBLIC_BASE_URL=https://your-host`.
34
- - **Crash-safe delivery** — every outbound message (replies, reminders, approvals, restart notices) flows through a SQLite outbox; a worker drains pending rows with exponential backoff. IM glitches and brief disconnects no longer drop replies. `/outbox status | list | failed | retry <id>`.
35
- - **In-flight job recovery** — every inbound message becomes a tracked inline job. When agim is restarted mid-flight, the next startup notifies each affected thread within 10 min. **v1.2.0+** uses native inline-button cards (`🔁 重发 / ✖ 取消`) on Feishu and other platforms that support inline buttons, falling back to text on adapters without buttons. Bystander-safe: only the original requester can resolve in group chats.
36
- - **Long-term memory (v1.2.0+)** — per-user fact store + auto-distilled "persona" summary injected into every prompt. SQLite + FTS5 default; optional vector retrieval (local BGE via `@xenova/transformers` ONNX, or any OpenAI-compatible `/v1/embeddings` endpoint) with reciprocal-rank fusion. Default OFF; enable in Settings → 自动化记忆. Web admin pages `/memory/facts` + `/memory/persona` expose per-user persona editing, fact browsing, and JSON export. All data stays in `~/.agim/memory.db` locally.
37
- - **Cost & Health dashboard (v1.2.0+)** — `/observability/health` + `/observability/topn` aggregate per-day spend / calls / errors / p95 latency from the audit log. Filter 1 / 7 / 30 / 90 days; top-N by user / agent / platform; daily trend chart with metric toggle. Claude per-run cost extracted from `--output-format json`.
38
- - **Agent-initiated push (v1.2.0+)** — `mcp__imhub__push_message` MCP tool lets a running agent push a follow-up message back into the IM thread without an inbound trigger (long-running jobs, schedule-aware notifications). `POST /api/notify` exposes the same primitive to webhooks / cron. Per-user rate limit + cross-thread gating.
39
- - **IM admin assignment (v1.3+)** — Web admin token is the single authority. Any IM user who has chatted with agim is auto-discovered in `Settings → Admins`; operators grant/revoke admin in one click (no `/setup admin`, no manual userId typing). `agim admin list` / `agim admin known` show current state.
40
- - **`/remind` reminders subsystem** — one-shot + recurring (`每天8点喝水`); LLM auto-detects reminder intent in casual chat; LLM polishes delivery; agent MCP tools; web `/reminders` page; email + IM delivery
41
- - **`/memo` 5W1H persistent memory** — generic "what / who / when / where / how / why" notes with optional GPS capture (browser geolocation H5 + Baidu geocoder); permanent by default, transient bucket for parking spots / today's meeting; agents store + retrieve via MCP tools so casual mentions get remembered automatically
42
- - **Browser dashboard** — chat UI; Tasks panel with 12 tabs (jobs / background / subtasks / schedules / approvals / health / files / audit / outbox / a2a / **cost / memory**); reminders panel; memos panel; settings page with workspace CRUD + admin allowlist + Safety card (restart / stop). Bilingual (EN / 中文) with per-page lang switcher and contextual `(?)` help tooltips on jargon (v1.1.4+)
43
- - **Human-in-the-loop tool approval** — Claude tool calls pause for `y`/`n` in IM or in-page card; works across all platforms
44
- - **Rich media in WeChat / DingTalk** — receive images, files, videos; voice messages transcribed via WeChat STT, DingTalk's server-side ASR, OpenAI Whisper, or whisper.cpp (per-platform fallback chain)
45
- - **Smart routing** — intent classifier (CJK + ASCII), sticky sessions, circuit breaker, rate limiter
46
- - **Multi-tenant workspaces** — per-workspace agent whitelist, rate limits, command-level ACL
47
- - **Persistent jobs & cron** — SQLite-backed, survives restarts, 30-day retention (24h for auto-tracked inline jobs)
48
- - **Observability** — structured logging (pino + traceId), Prometheus metrics, audit log
49
- - **Security** — token-based admin/user roles (R13), sensitive-path hard-deny + outbound secret scrubber (R13), prompt-injection guard on memory + AGENTS.md (R13), per-IP WS rate limit, timing-safe auth, SSRF guards, credential file permissions, approval socket entropy, persistent `audit_events` table with 180-day retention (R12 ⑤), 25s graceful shutdown + reap (R14), startup PID self-check (R14)
50
-
51
- See [CHANGELOG.md](CHANGELOG.md) for the full version history.
52
-
53
- ## Quick Start
1
+ # Agim · Universal IM-to-Agent Bridge
54
2
 
55
- ```bash
56
- npm install -g agim-cli # Requires Node.js ≥ 18 (≥ 22 LTS recommended)
57
-
58
- # Configure at least one messenger
59
- agim # arrow-key wizard (recommended) — picks language,
60
- # then per-component setup for every messenger / agent
61
- # — or use the legacy per-component commands below:
62
- agim config wechat # QR-code login
63
- agim config feishu # App ID + Secret (no webhook needed)
64
- agim config dingtalk # ClientID + ClientSecret (Stream-mode bot)
3
+ [中文说明](README.zh-CN.md)
65
4
 
66
- # (Optional) Connect a custom remote agent over ACP
67
- agim config agent
5
+ Agim connects IM channels to AI agents with one Node.js process.
6
+ It is designed for production use: persistent delivery, session continuity, human approval, and observable operations.
68
7
 
69
- # Start the bridge
70
- agim start
71
- ```
8
+ ## What matters
72
9
 
73
- Web UI at `http://localhost:3000` chat at `/`, tasks at `/tasks`, settings at `/settings`.
10
+ - **Bridge first**: WeChat / Feishu / DingTalk / Email to multiple agent backends.
11
+ - **Agent flexibility**: Claude Code, Codex, OpenCode, Cursor, Antigravity, native LLM, and ACP remote agents.
12
+ - **AI workflows built-in**: memory, skills, goals, heartbeat scheduler, reminders, memos, ask-user.
13
+ - **Reliable runtime**: SQLite outbox, restart recovery, job board, structured audit.
14
+ - **Safety by default**: token auth, approval gate, sensitive-path denylist, optional global-IM disable.
74
15
 
75
- ### Migrating
16
+ ## Quick start
76
17
 
77
- #### From the original `agim`
78
18
  ```bash
79
- npm uninstall -g im-hub
80
19
  npm install -g agim-cli
81
- agim start # config, env vars, headers all unchanged
82
- ```
83
-
84
- #### From `agim` (0.x → 1.0)
85
- ```bash
86
- npm uninstall -g im-hub-pro
87
- npm install -g agim-cli
88
- agim start # same config dir, same env vars, same headers
89
- ```
90
-
91
- The npm package is named `agim-cli` (the unscoped name `agim` is reserved
92
- by npm's anti-typosquat policy); the **binary** it installs is `agim`,
93
- which is what you'll actually type. `agim` is also retained as a
94
- binary alias inside the package, so previous shell aliases and systemd
95
- units that call `agim` continue to work without any extra setup.
96
-
97
- ## Features
98
-
99
- | Category | Details |
100
- |----------|---------|
101
- | **Messengers** | WeChat (iLink — image / file / voice / video), Feishu (WebSocket), DingTalk (Stream mode — image / voice with built-in ASR), Email (SMTP, push-only) |
102
- | **Agents** | 6 built-in: Claude Code, Codex, OpenCode, Antigravity, Cursor (CLI via shared `AgentBase`), and **`native`** (in-process LLM loop, OpenAI/Anthropic compat). Any HTTP agent via ACP — all 7 share one `AgentAdapter` interface |
103
- | **Native LLM** | OpenAI- + Anthropic-compatible providers, external MCP server attach, multi-iteration agent loop with policy approval gate, optional role bindings (`cheap` / `evaluator` / `native-chat`) with auto-fallback to any usable backend |
104
- | **Reminders** | `/remind` slash, LLM intent detection, LLM-polished delivery, MCP tools for agents (claude-code + opencode), web `/reminders` UI |
105
- | **Goals + Heartbeat + Ask** | `/goal` per-thread objective, `/heartbeat` periodic DECIDE/EXECUTE/EVALUATE tick, `mcp__imhub__ask_user` structured multi-choice with `/tasks/{goals,heartbeat,asks}` cross-thread admin |
106
- | **Skills** | `~/.agim/skills/<name>/SKILL.md` discovered by every agent (CLI + native); 3-tier progressive disclosure; web editor at `/settings/agim-skills` |
107
- | **Web UI** | Chat with streaming, three-state theme (light / dark / system), bilingual (EN / 中文 — every new v1.3.0 page included), SSE dashboard, settings tabs for LLM / MCP / Native Agent / Skills |
108
- | **Tool Approval** | Human-in-the-loop over IM + in-page cards; MCP sidecar for Claude; allow-list policy gate for native |
109
- | **Jobs** | Persistent SQLite job board + cron scheduler; batch ops; background task reader |
110
- | **Routing** | Intent classifier, circuit breaker, rate limiter, sticky sessions, LLM judge fallback; `/router compare` A/B evaluator |
111
- | **Workspaces** | Multi-tenant; agent whitelist + rate limits; command-level ACL |
112
- | **Observability** | pino structured logs, traceId, Prometheus `/api/metrics`, SQLite audit log |
113
- | **ACP** | Client (connect to remote agents) + Server (Agim itself as an ACP agent), authenticated by the same Web token system (admin role) |
114
-
115
- ## CLI Commands
116
-
117
- ```
118
- agim # Arrow-key wizard (bilingual zh/en) — recommended entry
119
- agim start # Start the bridge + web UI (foreground)
120
- agim start --bg # Start as a background daemon
121
- agim status # Show service status (systemd / bg / fg)
122
- agim restart # Restart the running service
123
- agim stop # Stop the running service
124
- agim uninstall # Uninstall (keeps ~/.agim-workspaces/)
125
- agim config wechat # Configure WeChat
126
- agim config feishu # Configure Feishu
127
- agim config dingtalk # Configure DingTalk (Stream-mode internal app)
128
- agim config claude # Configure Claude Code
129
- agim config agent # Connect a custom ACP agent
130
- agim agents # List available agents
131
- agim messengers # List available messengers
132
-
133
- # v1.3.0+ — native LLM stack & diagnostics
134
- agim setup llm # Wizard: add/list/remove LLM backends, set secrets, optional role bindings
135
- agim setup llm native-enable # One-shot: enable `native` agent if a backend is configured
136
- agim setup mcp # Wizard: add/list/remove external MCP servers (stdio / HTTP / SSE)
137
- agim setup mcp health # Probe every configured MCP server
138
- agim diag llm # Ping every backend + show which role binds to what
139
- agim diag mcp # Connect-and-list-tools per MCP server
140
-
141
- # v1.1.10+ — Web token management
142
- agim token create [name] # Mint a new user/admin token for /api/* + /acp/*
143
- agim token list # List tokens (last 4 chars only)
144
- agim token revoke <id> # Revoke a token by id
145
- agim token bootstrap # Print one-shot web-bootstrap token (`~/.agim/web-bootstrap-token`)
146
-
147
- # (`im-hub-pro …` continues to work as a deprecated alias)
148
- ```
149
-
150
- ## Chat Commands
151
-
152
- | Command | What it does |
153
- |---------|-------------|
154
- | any text | Route to agent (sticky session, intent-classified) |
155
- | `/<agent> <prompt>` | Switch agent — `/cc`, `/oc`, `/cx`, `/co` |
156
- | `/new` | New conversation (clear context) |
157
- | `/model [id]` / `/models [filter]` | View / list / switch the active agent's model. Works for opencode (`provider/model`) and cursor (flat names like `gpt-5.2`, `sonnet-4-thinking`). v1.2.50+ |
158
- | `/think on\|off` | Toggle extended thinking |
159
- | `/remind …` | Reminders — see [Reminders](#reminders) below |
160
- | `/memo …` | 5W1H persistent memory — see [Memos](#memos) below (aliases `/记`, `/note`) |
161
- | `/job`, `/cron`, `/audit`, `/stats` | Manage jobs, cron schedules, audit, stats (`/schedule` aliases `/cron` until v0.4.0) |
162
- | `/outbox status\|list\|failed\|retry <id>` | Inspect & operate the persistent IM delivery queue (v1.1.2+) |
163
- | `/a2a stats\|recent\|tree <id>` | Agent-to-Agent observability — chain, latency, callee histogram (v1.1.2+) |
164
- | `/router status\|explain` | Inspect routing decisions |
165
- | `/router compare agent:<a> agent:<b> "<prompt>"` | A/B evaluator — run the same prompt against two backends, side-by-side card with latency / tokens / outputs (v1.3.0+) |
166
- | `/goal …` | Sustained per-thread objective — `set / body / progress / pause / resume / complete / cancel / list / show` (v1.3.0+) |
167
- | `/heartbeat …` | Periodic DECIDE→EXECUTE→EVALUATE tick — `bind / unbind / show / pause / resume / status` (v1.3.0+) |
168
- | `/skill list\|show <name>\|refresh` | Inspect agim Skills loaded from `~/.agim/skills/` (v1.3.0+) |
169
- | `/cc native …` / `/na …` / `/llm …` | Route to the in-process native LLM agent (v1.3.0+) |
170
- | `/cs …` / `/cur …` / `/cc cursor …` | Route to Cursor CLI agent (v1.2.49+); `/cs plan` enters plan mode for one turn |
171
- | `/agy …` / `/cc antigravity …` | Route to Google Antigravity (agy) CLI agent |
172
- | `y` / `n` / `批准` / `拒绝` | Approve / deny Claude tool call (or reminder confirmation card) |
173
- | `1` / `2` | After a service restart, reply `1` to redo the interrupted message or `2` to cancel (10 min window) |
174
-
175
- ## Human-in-the-loop Tool Approval
176
-
177
- When a Claude run tries to use a tool, Agim pauses and sends an approval card:
178
-
179
- ```
180
- 🔐 Tool approval request
181
- Tool: Bash
182
- Input: {"command":"rm -rf node_modules"}
183
- Reply y to approve / n to deny (auto-deny in 5 min)
184
- ```
185
-
186
- Reply `y` / `n` in IM, or click Allow / Deny in the web UI. Works identically across WeChat, Feishu, and DingTalk. Disable with `IMHUB_APPROVAL_DISABLED=1`.
187
-
188
- ## Reminders
189
-
190
- Built-in `/remind` subsystem — one-shot or recurring, with three creation paths and three delivery enhancements.
191
-
192
- ```bash
193
- # One-shot
194
- /remind 2m drink water
195
- /remind 40秒喝水
196
- /remind 下午6点下班
197
- /remind 18:30 出门
198
-
199
- # Recurring 🔁
200
- /remind 每5分钟看屏幕外
201
- /remind 每天早上8点喝水
202
- /remind 每周一三五9点站会
203
- /remind 每个工作日18:00下班
204
-
205
- # Email delivery ✉️ (requires SMTP — see Configuration)
206
- /remind email me@x.com 8:00 morning briefing
207
- /remind bindemail me@x.com # bind default → /remind email 每天8点 早安
208
- /remind unbindemail
209
-
210
- # Manage
211
- /remind list
212
- /remind cancel <id>
213
- /remind clear
214
- /remind snooze <id> 5m
215
- /remind aiwatch on|off # toggle the LLM intent detector
216
-
217
- # Disable LLM polish for one reminder
218
- /remind literal 每5分钟 喝水
20
+ agim # interactive setup wizard
21
+ agim start
219
22
  ```
220
23
 
221
- **Three creation paths** (all land in the same `~/.agim/reminders.db`):
222
-
223
- 1. **`/remind` slash** — explicit, structured input
224
- 2. **LLM intent detection** (default-on) — say "明天早上8点提醒我开会" without `/remind`, the bot pops a confirmation card; reply `y` to create
225
- 3. **Agent MCP tools** — claude-code and opencode (stdio) auto-call `create_reminder` when you mention future commitments in chat. Works with opencode (http) too via single-user agent-asserted context
226
-
227
- **Two delivery enhancements**:
228
-
229
- - **LLM polish** (default-on): at fire time the active agent rewrites the literal seed text into a natural one-liner ("早上好,记得喝杯水"). Tone constrained: *no flattery, no over-humor, no exaggeration*. Falls back to literal text on agent failure / timeout
230
- - **Late-delivery tag**: > 1 h overdue gets `⏰ 延迟投递` prefix so users know the bot was offline
24
+ Web console: `http://localhost:3000`
231
25
 
232
- Manage reminders in the web UI at `/reminders` (status filters, snooze, cancel).
26
+ - Chat: `/`
27
+ - Tasks: `/tasks`
28
+ - Settings: `/settings`
233
29
 
234
- Full design: [`docs/architecture/reminders.md`](docs/architecture/reminders.md).
30
+ ## Choose your AI backend
235
31
 
236
- ## Memos
32
+ | Scenario | Recommended path |
33
+ |---|---|
34
+ | Strong coding agent loop | `claude-code` / `codex` / `opencode` / `cursor` |
35
+ | API-only, low-cost native mode | `native` + `llmBackends` |
36
+ | Bring your own remote agent | ACP (`acpAgents`) |
237
37
 
238
- `/memo` is a 5W1H persistent memory database. Every memo can carry any subset of `what` / `who` / `when_at` / `where (lat/lng/label)` / `how` / `why` plus an optional `expires_at` lifecycle. Locations are just one axis — the same store also remembers "我爸生日 5月8日" or "苹果发了 AVP2".
38
+ Native setup details: `docs/llm-backends.md`
239
39
 
240
- ```bash
241
- # Slash
242
- /memo # search hint + recent memos
243
- /memo list # last 10
244
- /memo show <id>
245
- /memo delete <id>
246
- /memo search 茶馆
247
- /memo here [备注] # one-shot HTTPS link → browser GPS capture
248
- /memo 39.9,116.4 家 # raw coords + label
249
-
250
- # Aliases: /记, /note
251
- ```
40
+ ## Core AI workflows
252
41
 
253
- The agent (claude-code / opencode) sees 5 MCP tools and uses them automatically when you mention something worth remembering — no need to invoke a slash:
42
+ | Capability | Description | Docs |
43
+ |---|---|---|
44
+ | Long-term memory | facts + persona, optional vector retrieval | `docs/memory-and-vector.md` |
45
+ | Skills | shared `SKILL.md` capability layer across agents | `docs/skills.md` |
46
+ | Goals | sustained objective per thread (`/goal`) | `docs/goals.md` |
47
+ | Heartbeat | periodic proactive loop (`/heartbeat`) | `docs/architecture/reminders.md` |
48
+ | Ask user | structured agent->user choices | `docs/ask-user.md` |
49
+ | Reminders | one-shot / recurring reminders | `docs/architecture/reminders.md` |
50
+ | Memos | 5W1H persistent notes with optional location | `docs/im-workspaces-guide.md` |
51
+ | A2A | agent-to-agent calls with traceability | `CHANGELOG.md` |
254
52
 
255
- - `save_memo` — extract 5W1H from natural language and store; `address` arg triggers Baidu geocoder
256
- - `request_location_capture` — return a one-shot H5 link so the user can authorize browser geolocation
257
- - `search_memos` — multi-field AND-combined retrieval ("我的车在哪")
258
- - `update_memo` — patch existing entry (e.g. add `where_*` later, or pass `address` to geocode)
259
- - `delete_memo`
53
+ ## Security defaults
260
54
 
261
- **Lifecycle**: memos default to permanent. Agents only set `expires_in_hours` when content is clearly transient ("我把车停这了" / "今天下午3点开会"). A background sweep deletes expired rows.
55
+ - Web token auth enabled by default.
56
+ - Approval gate enabled by default.
57
+ - Sensitive files/paths are denied by policy.
58
+ - Global IM connectors can stay disabled in domestic deployments.
262
59
 
263
- **Time zone**: all times are interpreted as Asia/Shanghai (UTC+8) and stored as bare-local `YYYY-MM-DD HH:MM:SS`. Override with `IMHUB_TZ_OFFSET_HOURS` if your deployment is elsewhere.
60
+ Security reference: `docs/security-hardening.md`
264
61
 
265
- **Browser GPS capture**: `/memo here` and `request_location_capture` send a one-shot 10-min HTTPS link. Default base URL is `https://agent.iclaw.host`; override with `IMHUB_LOC_BASE_URL=https://your-host` if you want to keep H5 traffic on your own domain.
62
+ ## Essential IM commands
266
63
 
267
- **Address geocoding (optional)**: set `IMHUB_BAIDU_MAP_AK` to a Baidu Maps AK to enable `address: "中关村大街27号"` style inputs in `save_memo` / `update_memo`. Without it, those calls return "geocoding not configured" but raw coords + browser GPS still work. Get a free AK at [lbsyun.baidu.com](https://lbsyun.baidu.com/) → Console → 应用管理 → 创建应用 → 服务端 API. The default key flow doesn't need SN signing; if you enable SN校验 in the console, see notes in `src/core/locations.ts`.
64
+ | Command | Purpose |
65
+ |---|---|
66
+ | `/cc ...` `/oc ...` `/cx ...` `/cs ...` `/na ...` | Route to a target agent |
67
+ | `/new` | Start a new conversation session |
68
+ | `/model` `/models` | Inspect/switch model (where supported) |
69
+ | `/goal ...` | Manage per-thread long goal |
70
+ | `/heartbeat ...` | Manage heartbeat schedule |
71
+ | `/remind ...` | Manage reminders |
72
+ | `/memo ...` | Manage memo records |
73
+ | `/job ...` `/cron ...` `/audit ...` `/stats` | Runtime operations |
74
+ | `/outbox ...` | Delivery queue operations |
75
+ | `/a2a ...` | A2A runtime visibility |
268
76
 
269
- ## Configuration
77
+ ## Minimal config shape
270
78
 
271
- ### Config file
272
- `~/.agim/config.json` (validated by zod at startup):
79
+ `~/.agim/config.json`
273
80
 
274
81
  ```json
275
82
  {
276
- "messengers": ["wechat-ilink", "feishu"],
277
- "agents": ["claude-code", "opencode"],
83
+ "messengers": ["wechat-ilink"],
84
+ "agents": ["claude-code", "native"],
278
85
  "defaultAgent": "claude-code",
279
- "feishu": { "appId": "cli_***", "appSecret": "***" },
280
- "acpAgents": [
86
+ "llmBackends": [
281
87
  {
282
- "name": "my-agent",
283
- "endpoint": "https://api.example.com",
284
- "auth": { "type": "bearer", "token": "***" }
88
+ "name": "default-native",
89
+ "provider": "openai-compat",
90
+ "baseUrl": "https://api.openai.com/v1",
91
+ "model": "gpt-4o-mini"
285
92
  }
286
93
  ],
287
- "workspaces": [
288
- {
289
- "id": "team-data",
290
- "name": "Data team",
291
- "agents": ["opencode", "my-agent"],
292
- "members": ["user-123"],
293
- "rateLimit": { "rate": 30, "intervalSec": 60, "burst": 60 }
294
- }
295
- ]
94
+ "llmRoles": {
95
+ "cheap": "default-native"
96
+ }
296
97
  }
297
98
  ```
298
99
 
299
- ### Email reminders (SMTP)
300
-
301
- To enable `/remind email …`, set these environment variables before starting:
302
-
303
- ```bash
304
- # Required
305
- export IMHUB_SMTP_HOST=smtp.gmail.com
306
- export IMHUB_SMTP_USER=you@gmail.com
307
- export IMHUB_SMTP_PASS=<16-char-app-password> # NOT your normal password
308
-
309
- # Optional
310
- export IMHUB_SMTP_PORT=465 # default 465
311
- export IMHUB_SMTP_FROM=you@gmail.com # default = USER
312
- export IMHUB_SMTP_SECURE=auto # auto | true | false
313
- ```
314
-
315
- **Provider quick reference**:
316
-
317
- | Provider | HOST | PORT | Notes |
318
- |----------|------|------|-------|
319
- | Gmail | `smtp.gmail.com` | 465 | Use [App Password](https://myaccount.google.com/apppasswords) — 2-Step Verification required |
320
- | QQ Mail | `smtp.qq.com` | 465 | "授权码" (account → POP3/SMTP service) |
321
- | 163 Mail | `smtp.163.com` | 465 | "授权码" (account → POP3/SMTP/IMAP service) |
322
- | Outlook | `smtp-mail.outlook.com` | 587 | Set `IMHUB_SMTP_SECURE=false` (STARTTLS) |
323
- | Custom | any host | any port | Set `SECURE` per provider docs |
100
+ Secrets are stored separately from this file.
324
101
 
325
- Without these env vars, the email adapter still loads but `/remind email …` returns "Email adapter not configured" — IM reminders keep working.
102
+ ## Operations
326
103
 
327
- For systemd, put env in your unit file:
328
- ```ini
329
- [Service]
330
- Environment="IMHUB_SMTP_HOST=smtp.gmail.com"
331
- Environment="IMHUB_SMTP_USER=you@gmail.com"
332
- Environment="IMHUB_SMTP_PASS=xxxxxxxxxxxxxxxx"
333
- ```
104
+ - Deployment guide: `docs/deployment.md`
105
+ - Runbook: `docs/runbook.md`
106
+ - Architecture stance: `docs/architecture-bridge-and-native.md`
107
+ - Full changelog: `CHANGELOG.md`
334
108
 
335
- ### Other env vars
336
-
337
- | Env | Default | What it does |
338
- |-----|---------|-------------|
339
- | `IMHUB_WEB_BIND` | `127.0.0.1` | Web UI bind address (set `0.0.0.0` to expose; front with HTTPS reverse proxy) |
340
- | `IMHUB_APPROVAL_DISABLED` | unset | Set `=1` to skip the human-in-the-loop tool approval gate |
341
- | `IMHUB_OPENCODE_DRIVER` | `stdio` | `http` selects the HTTP driver (faster, but reminder MCP path uses single-user agent-asserted context) |
342
- | `IMHUB_OPENCODE_GATE` | `medium` | `strict` / `loose` / `none` — opencode permission gate |
343
- | `IM_HUB_LLM_JUDGE_AGENT` | unset | Agent name used as LLM router fallback judge |
344
- | `OPENAI_API_KEY` | unset | Enables OpenAI Whisper for voice transcription |
345
- | `IMHUB_WHISPERCPP_BIN` + `IMHUB_WHISPERCPP_MODEL` | unset | Local Whisper.cpp for voice transcription (no cloud) |
346
- | `IMHUB_BAIDU_MAP_AK` | unset | Baidu Maps AK; enables `/memo` address-based geocoding. Without it, raw coords + browser GPS still work. |
347
- | `IMHUB_LOC_BASE_URL` | `https://agent.iclaw.host` | Public HTTPS base URL the `/memo here` H5 capture link points at. Override for self-hosted deployments. |
348
- | `IMHUB_TZ_OFFSET_HOURS` | `8` | Hours offset from UTC for memo timestamps (Asia/Shanghai default). Change only if your deployment is elsewhere. |
349
- | `IMHUB_TELEGRAM_COORDS_GCJ02` | unset | Set to `1` to apply GCJ-02 → WGS-84 to Telegram native location/venue messages. Default off (WGS-84 pass-through). Turn on if your Telegram clients are Apple devices in mainland China — iOS Core Location applies the GCJ offset before handing coords to Telegram. |
350
- | `IMHUB_H5_COORDS_GCJ02` | unset | Set to `1` to apply GCJ-02 → WGS-84 to coords POSTed from `/memo here` H5 capture pages. Default off (WGS-84 pass-through, fits WeChat X5 webview + Android Chrome). Turn on if your users open the H5 link in iOS Safari / iOS WebKit in mainland China. See [`src/core/coord-systems.ts`](src/core/coord-systems.ts) for the full per-platform policy. |
351
- | `AGIM_HOME` | auto | Per-user state directory. By default Agim picks `~/.agim/` on a fresh install and `~/.im-hub/` on a legacy 0.x install (auto-detected). Set explicitly if you want to pin a location — e.g. on shared machines or for tests. `IMHUB_HOME` is also honored. |
352
- | `AGIM_WORKSPACES` | auto | Per-agent workspace root. Same dual-detect logic as `AGIM_HOME` (`~/.agim-workspaces/` preferred, `~/.im-hub-workspaces/` if it exists). `IMHUB_WORKSPACES` also honored. |
353
-
354
- ## Architecture
109
+ ## Docs index
355
110
 
356
- ```
357
- ┌─ IM ingress ─────────────────────────────────────┐
358
- │ WeChat iLink (long-poll + image/voice/file) │
359
- │ Telegram (grammy + photo/voice/audio) │
360
- │ Feishu (Lark SDK WebSocket) │
361
- │ DingTalk (Stream WebSocket + ASR baked in) │
362
- │ Discord (discord.js Gateway) │
363
- │ Web Chat (browser WebSocket) │
364
- └───────────────────────┬──────────────────────────┘
365
- │ MessageContext
366
-
367
- ┌── Pre-route gates ────────────────┐
368
- │ workspace · rate limiter · traceId │
369
- └────────────────┬──────────────────┘
370
-
371
- ┌── Intent router ──────────────────┐
372
- │ command → builtin │
373
- │ /agent → explicit switch │
374
- │ default → classify (regex/keyword/ │
375
- │ sticky/LLM judge) │
376
- └────────────────┬──────────────────┘
377
-
378
- ┌── Agent invocation ───────────────┐
379
- │ circuit breaker + spawn stream │
380
- └───┬──────┬──────┬──────┬───┘
381
- ▼ ▼ ▼ ▼
382
- claude opencode codex ACP
383
-
384
- ▼ (tool approval)
385
- MCP sidecar → approvalBus → IM thread
386
-
387
- ┌─ Cross-cutting ──────────────────────────────────┐
388
- │ SQLite (audit · jobs · schedules) │
389
- │ session (append-only JSONL) │
390
- │ Prometheus metrics · pino structured logging │
391
- └──────────────────────────────────────────────────┘
392
- ```
111
+ Start from: `docs/README.md`
393
112
 
394
- Single process, zero external dependencies — SQLite + session files are the entire persistence layer.
113
+ ## Migration notes
395
114
 
396
- For the full deep-dive see [`docs/architecture/current.md`](docs/architecture/current.md).
397
- For the native LLM stack and the peer-`AgentAdapter` design that lets CLI agents and the in-process loop share one router / approval bus / A2A / skills pipeline, see [`docs/architecture-bridge-and-native.md`](docs/architecture-bridge-and-native.md) and the PR-by-PR landing order in [`docs/nanobot-comparison-rollout.md`](docs/nanobot-comparison-rollout.md).
115
+ Legacy installs remain compatible:
398
116
 
399
- ## Requirements
400
-
401
- - **Node.js 18** (≥ 22 LTS recommended)
402
- - At least one agent CLI or ACP endpoint:
403
- - `npm i -g @anthropic-ai/claude-code`
404
- - `npm i -g @openai/codex`
405
- - `npm i -g opencode-ai`
117
+ - command alias compatibility retained
118
+ - legacy env naming retained
119
+ - old data path autodetected
406
120
 
407
121
  ## Development
408
122
 
409
123
  ```bash
410
- git clone https://github.com/benking007/imhub.git && cd imhub
411
- npm install
412
- npm run build # tsc + copy public/
413
- npm run dev # tsc --watch
414
- npm test # bun test
415
- npm run lint # biome lint
416
- npm run typecheck # tsc --noEmit
124
+ git clone https://github.com/benking007/agim.git
125
+ cd agim
126
+ npm install --no-package-lock
127
+ npm --prefix src/web-app install
128
+ npm run build
129
+ npm run lint
130
+ npm run typecheck
131
+ npm test
417
132
  ```
418
133
 
419
- ## Deployment
420
-
421
- See [`docs/deployment.md`](docs/deployment.md) for systemd, Docker, nginx, monitoring, admin-allowlist management, backup, and upgrade instructions. For long-term memory + vector retrieval setup / tuning / privacy, see [`docs/memory-and-vector.md`](docs/memory-and-vector.md).
422
-
423
- ## Roadmap
424
-
425
- ### Done
426
-
427
- | Version | Theme |
428
- |---------|-------|
429
- | v0.1.x | MVP — WeChat + 4 agents + command routing |
430
- | v0.2.0 | Multi-IM — Feishu, Telegram, sessions, ACP |
431
- | v0.2.13 | Foundations — logging, audit, intent, jobs, metrics, workspaces |
432
- | v0.2.14 | Human-in-the-loop tool approval |
433
- | v0.2.15 | Discord adapter + tasks dashboard |
434
- | v0.2.16–17 | Security hardening + observability |
435
- | v0.2.18–19 | IM reconnect backoff, Codex sandbox, dashboard filters |
436
- | v0.2.20–23 | Web console — theme, approvals, SSE, files, batch ops |
437
- | v0.2.30 | Production hardening — session isolation, serial WS, loopback bind |
438
- | v0.2.35 | WeChat & Telegram rich media — image / file / voice / video |
439
- | v0.2.37 | Reminders subsystem — `/remind`, LLM intent + polish, agent MCP tools, email channel, web `/reminders`, WeChat context_token persistence |
440
- | v0.3.0 | `/memo` 5W1H persistent memory — `/location` → `/memo` rename, address geocoding via Baidu Maps, opencode HTTP driver SSE drain |
441
- | v0.3.1 | Native location messages on Telegram + Feishu, GCJ-02 → WGS-84 fix across all ingest paths, `memo` column + LLM/heuristic `what` extractor |
442
- | v0.4.0 | codex agent now sees the full imhub MCP toolset (reminder + memo); Telegram + Feishu location messages routed through agent-driven decision making (matches WeChat H5 architecture) |
443
- | v0.5.0–0.5.2 | Bilingual arrow-key `agim` wizard (then `im-hub-pro` pre-rename); per-component flows (QR for WeChat, credentials prompts for Feishu / Telegram / Discord; live install detection for agents); systemd-unit env fallback for SMTP / Baidu prefill; full service lifecycle commands (`status / start --bg / restart / stop / uninstall`) |
444
- | v0.6.0 | DingTalk Stream-mode adapter — bidirectional bot bridge via WebSocket, image inbound (`messageFiles/download` → claude-code multimodal Read), voice inbound (server-side ASR `recognition` field, whisper.cpp fallback) |
445
- | v0.6.3 | Per-platform coord-system handling for native location messages (Telegram defaults WGS pass-through; H5 WGS pass-through fixes WeChat-X5 markers; DingTalk routes Baidu link URLs through BD-09→WGS) |
446
- | **v1.0.0** | Brand rename to **Agim · 阿吉姆**. New canonical bin `agim`; `im-hub-pro` retained as deprecation alias. On-disk paths / env vars / HTTP headers / systemd unit name kept stable for drop-in compat with 0.x installs. |
447
- | v1.1.2–1.1.3 | A2A L1 (call chain visualization) + L2 (shared artifact pool between agents) |
448
- | v1.1.4 | Web dashboard bilingual + jargon tooltips |
449
- | v1.1.6–1.1.8 | IM long-message viewer + cloudflared auto-tunnel |
450
- | v1.1.10 | Web console token authentication (cookie + Bearer + loopback bypass), restart message-order fix |
451
- | v1.1.11 | Viewer dark-mode readability |
452
- | **v1.2.0** | **Long-term memory** (SQLite + FTS5 + persona + 4 MCP tools + auto-distillation + Web admin tab); **vector retrieval** (local BGE / OpenAI-compatible, RRF fusion); **Cost & Health dashboard**; **agent-initiated push** (`mcp__imhub__push_message`); recovery card with native inline buttons. |
453
- | v1.2.1 | Vector backend auto-warm on restart; Memory + Cost tab i18n. |
454
- | v1.2.2 | `agim admin invite` for onboarding additional admins via IM; vector eager-warm at boot; async consolidate (jobId + polling). |
455
- | v1.2.27–v1.2.32 | R14/R15 lifecycle hardening — 25s graceful-shutdown hard cap, port-first teardown, reap stray agim processes, argv-strict /proc scan in `findAgimProcesses`, PID file on every successful start, CLI wizard "Web bind+port" section, ACP port gate (`IMHUB_ENABLE_REMOTE_AGENT`). |
456
- | **v1.3.0** | **nanobot-vs-agim comparison rollout** — `native` in-process AgentAdapter (LLM client + agent loop + MCP attach + policy approval gate, OpenAI/Anthropic-compatible); `llmBackends` + `llmRoles` + `~/.agim/llm-secrets.json` config; `/goal` per-thread sustained objective (P0 #2); `/heartbeat` 3-phase scheduler (P0 #1); `mcp__imhub__ask_user` structured choice (P0 #5); agim Skills 3-tier engine (Stage 3 + P0 #3); inline row-age annotations on memory facts (P0 #4); notification evaluator for `mcp__imhub__push_message` (P0 #9); `/router compare` A/B evaluator (Stage 5); `tryIntrospectChain` fallback helper; Web admin pages `/settings/{llm,mcp,native-agent,agim-skills}` + `/tasks/{heartbeat,goals,asks}`; CLI wizards `agim setup {llm,mcp}` + diagnostics `agim diag {llm,mcp}` + `agim setup llm native-enable` quick path; CLI + Web full i18n (en/zh) for every new surface; `acp-token` separation from `web-token`; `agim token bootstrap` printer; `gen-endpoints --check` drift guard. See [`docs/nanobot-comparison-rollout.md`](docs/nanobot-comparison-rollout.md). |
457
-
458
- ### Next
459
-
460
- - [ ] Slack adapter
461
- - [ ] DingTalk button-style approval cards (Feishu done)
462
- - [ ] Multi-instance event bus (Redis Streams / NATS)
463
- - [ ] Workspace member picker UI
464
- - [ ] Memory consolidation: scheduled boot+5min first run (currently waits a full 24h)
465
-
466
- ## Community
467
-
468
- <p align="center">
469
- <a href="https://deepseek.club/community/imhub">
470
- <img src="https://deepseek.club/assets/logo-DH6LfKkF.png" style="width: 150px; height: auto;" alt="DeepSeek">
471
- </a>
472
- </p>
473
-
474
134
  ## License
475
135
 
476
136
  MIT