@mu-cabin/muc-cli 0.5.5 → 0.6.0

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/REFERENCE.md CHANGED
@@ -1,781 +1,48 @@
1
- # muc-cli
1
+ # MUC 命令契约
2
2
 
3
- Terminal client for 东航 MUC IM (the `com.meicloud.im.dh` desktop app, also
4
- called MUC.app). Drives the same REST surface the desktop talks to, plus the
5
- binary chat protocol on raw TCP 8101 for sending messages, withdrawing, and
6
- syncing sessions.
3
+ 本文件描述 0.6.0 的命令契约。旧的 `send/history/daemon-*` 命令已移除。
7
4
 
8
- REST commands always coexist with the running desktop and phone — the server
9
- allows concurrent `accessToken`s. Chat-channel commands share online slots
10
- with real devices; see [Coexistence](#coexistence) below before sending.
5
+ ## 命令结构
11
6
 
12
- ## What it is
7
+ 全局参数放在命令之前:`muc [--config-root <绝对路径>] [--output json|jsonl|text] <命令>`。默认 JSON。配置根也可由 `MUC_CONFIG_DIR` 提供。
13
8
 
14
- A single command (`muc`) packaging:
9
+ | 命令 | 用途 |
10
+ | --- | --- |
11
+ | `init` | 从受保护 stdin 配置租户与初始 profile |
12
+ | `login [--account <账号>] [--profile-id <id>]` | 隐藏提示或 JSON stdin 登录 |
13
+ | `login --account <账号> --password-stdin` | stdin 仅提供密码 |
14
+ | `login --remember` / `login --no-remember` | 保存或移除该账号记住密码的选择 |
15
+ | `login --qr` | 在真实终端扫码登录 |
16
+ | `whoami [--profile-id <id>]` | 核验当前用户 |
17
+ | `profile list/create/update/login/logout` | 管理账号配置;修改输入来自 stdin |
18
+ | `daemon start/stop/status/logs` | 管理同包后台进程 |
19
+ | `runtime status/ensure/start/resume/stop` | 管理明确 profile 的连接状态 |
20
+ | `manifest` | 查询当前操作契约 |
21
+ | `exec <operation-id> --profile-id <id>` | 按 schema 执行业务操作 |
15
22
 
16
- - **Send** — 1:1 and group text, files, images, and voice clips. Add and
17
- remove emoticon reactions on existing messages.
18
- - **Read** — server-side chat history, profile lookups, group lists, sticker
19
- packs, directory search (people, departments, apps, service numbers), and
20
- long-lived `listen` tail of inbound messages with sender/keyword filters.
21
- - **Manage** — login / token refresh, withdraw a message, clear a session,
22
- download a chat-attached file, wait for a human emoticon reaction before
23
- proceeding (`wait-react`).
24
- - **Personal daemon** — foreground `daemon-start` process for the user's own
25
- account. It owns one chat socket, records raw `daemon-events`, and lets
26
- ordinary chat-channel commands share that socket instead of opening a second
27
- TCP login.
28
- - **Auto-reply** — long-running `assistantd` daemon plus named `assistant`s
29
- with their own backend (Claude Code / Codex / Gemini / Cursor / Antigravity), persona prompt,
30
- scope rules, optional slash-command claims, and a memory log. A
31
- structural signature tail on every outbound stops bot-vs-bot reply loops.
32
- This is separate from the personal daemon; ordinary commands do not borrow
33
- a dedicated assistant account's socket.
34
- - **Self-describe** — every command has a `--json` mode emitting a stable
35
- envelope; `muc manifest --json` returns the full command graph + per-command
36
- output JSON Schema for agent / script consumers.
23
+ 操作 ID 与输入结构以 `src/ipc/v2/operations.ts` 和实际 `muc manifest` 为准,不在文档维护另一份静态覆盖矩阵。
37
24
 
38
- ## Install
25
+ ## 输出与恢复
39
26
 
40
- ```bash
41
- npm i -g @mu-cabin/muc-cli
42
- muc --version
43
- ```
27
+ 成功输出包含 `ok`、`command`、`data`。错误输出到 stderr,包含 `ok:false` 与 `error.code`,不反射密码、token 或租户配置。
44
28
 
45
- Requirements: **Node ≥ 18**. macOS, Linux, and Windows are all supported.
46
- DES-CBC password encryption is `crypto-js` (pure JS) — no
47
- `--openssl-legacy-provider` flag needed.
29
+ `events.watch` 使用 JSONL:先输出订阅 metadata,再输出事件。保留 `startedAtCursor`、`highWatermark` 和每条已处理事件的游标。消费进程退出不停止 daemon。
48
30
 
49
- `~/.muc/credentials.json` and `~/.muc/config.json` are written with mode
50
- `600` and the parent dir with mode `700`. POSIX honors that; on Windows the
51
- modes are silently ignored — protect the files with NTFS ACLs if you're on a
52
- shared host.
31
+ 写操作使用稳定 idempotency key;dry-run 与真正提交使用不同 key。提交结果不明时使用原 key 或 deliveryId 查询 `deliveries.get`,不新建 key 重发。
53
32
 
54
- ## First-time setup
33
+ 认证恢复由 daemon 负责。明确认证失效后才进入下一种凭据,网络失败不触发密码兜底;恢复耗尽后由用户重新登录指定 profile。
55
34
 
56
- Before you can `login`, run `muc init` to seed the tenant configuration. The
57
- CLI is generic across MUC deployments — your MUC admin provides the
58
- tenant-specific values.
35
+ ## 初始配置
59
36
 
60
- ```bash
61
- muc init # interactive: walks through APP_KEY, APP_ID, signing secrets, hosts
62
- ```
37
+ `init` 输入为 `{ "profileId": "default", "tenant": {...}, "endpoints": {...} }`。
63
38
 
64
- What `muc init` collects:
39
+ - `tenant`:`schemaVersion:2`、8 位十六进制 `appKey`、24 位十六进制 `appId`、`signSecretRest`、`signSecretSecure`、毫秒时间 `savedAtMs`,可选 `passwordKey`。
40
+ - `endpoints`:`restOrigin`、`imHost`、`imPort`、`fileHost`、`filePort`。端点可以通过 `profile update` 显式修改。
65
41
 
66
- | Field | Source | Notes |
67
- |---|---|---|
68
- | `appKey` | admin | 8 hex chars |
69
- | `appId` | admin | 24 hex chars |
70
- | `signSecretRest` | admin | secret for the regular-API signing scheme |
71
- | `signSecretSecure` | admin | secret for the `/contacts/secure/...` signing scheme |
72
- | `pwdDesKey` | admin (optional) | DES-CBC key for password encryption; defaults to `appKey` |
73
- | `restHost` | default `https://muc.ceair.com/` | press enter to accept |
74
- | `ssoHost` | default `https://store.ceair.com/` | reserved (advanced) |
75
- | `imHost` / `imPort` | default `muc.ceair.com` / `8101` | TCP chat channel |
76
- | `fileHost` / `filePort` | default `muc.ceair.com` / `6101` | TCP file channel |
42
+ 这些值由管理员提供,只经受保护 stdin 输入;不要把真实配置写进仓库、命令行参数或聊天。
77
43
 
78
- Built-in defaults are provided **for hosts and ports only** — never for
79
- `appKey`, `appId`, or signing secrets.
44
+ 新私聊先用 `directory.search` 取得准确用户 ID,再调用 `chats.get`,输入 `{"conversationId":"dm:UPPERCASE_USER_ID"}`。发送时使用返回的正式 `conversationId`,不能直接向别名发送。
80
45
 
81
- ### Non-interactive (CI, scripts)
46
+ 认证错误退出码为 3,禁止访问为 8,配置缺失为 6、配置无效为 7,输入错误为 2;提交结果不明为 75,并带 `automaticReplay:false`。错误的 `hint` 提供可执行的恢复路径。
82
47
 
83
- You can supply values via flags or env vars:
84
-
85
- Get the four secrets from your MUC admin first; the snippets below use
86
- placeholder names — substitute the real values your admin gives you.
87
-
88
- ```bash
89
- # Flag form
90
- muc init --no-interactive \
91
- --app-key "$APP_KEY" \
92
- --app-id "$APP_ID" \
93
- --sign-secret-rest "$SIGN_SECRET_REST" \
94
- --sign-secret-secure "$SIGN_SECRET_SECURE" \
95
- --json
96
-
97
- # Env-var form
98
- MUC_APP_KEY="$APP_KEY" \
99
- MUC_APP_ID="$APP_ID" \
100
- MUC_SIGN_SECRET_REST="$SIGN_SECRET_REST" \
101
- MUC_SIGN_SECRET_SECURE="$SIGN_SECRET_SECURE" \
102
- muc init --no-interactive
103
- ```
104
-
105
- Environment variables: `MUC_APP_KEY`, `MUC_APP_ID`, `MUC_SIGN_SECRET_REST`,
106
- `MUC_SIGN_SECRET_SECURE`, `MUC_PWD_DES_KEY`, `MUC_REST_HOST`, `MUC_SSO_HOST`,
107
- `MUC_IM_HOST`, `MUC_IM_PORT`, `MUC_FILE_HOST`, `MUC_FILE_PORT`.
108
-
109
- > **Env-var leakage warning.** Values exported into the environment are
110
- > visible to other processes on the same machine via `/proc/<pid>/environ`
111
- > on Linux, and they land in shell history if you don't prefix the command
112
- > with a space (and `HISTCONTROL=ignorespace` is set). For production setups
113
- > prefer the **interactive** prompt or **flag-based** invocation — you can
114
- > protect the flag values with secret-manager retrieval that never touches
115
- > the env.
116
-
117
- ### Inspect, repair, reset
118
-
119
- ```bash
120
- muc init --check # validate; exit 0 ok, 6 missing, 7 invalid
121
- muc init --check --json # same, machine-readable
122
- muc init --show # print config (secrets always redacted)
123
- muc init --show --json # JSON envelope — secrets are also redacted here
124
- # (read ~/.muc/config.json directly for raw values)
125
- muc init --reset --yes # delete ~/.muc/config.json
126
- ```
127
-
128
- Resolution order per field: CLI flag → env var → existing saved value → built-in
129
- default (hosts/ports only) → interactive prompt (TTY) → fail.
130
-
131
- ## Login
132
-
133
- `muc login` is **non-interactive on the credential side** — it never prompts
134
- for a password. Pass it via flag, stdin, env var, or `--token-pwd` (reuse
135
- the saved tokenPwd).
136
-
137
- ```bash
138
- # Plaintext flag (avoid; lands in shell history)
139
- muc login --account WANGLULU8 --password '…'
140
-
141
- # Safer: read password from stdin, no flag value
142
- printf '%s' "$MY_PWD" | muc login --account WANGLULU8 --password-stdin
143
-
144
- # Reuse saved tokenPwd (no password needed; ~30 day TTL)
145
- muc login --token-pwd
146
-
147
- # Env-var form
148
- MUC_ACCOUNT=WANGLULU8 MUC_PASSWORD='…' muc login
149
- ```
150
-
151
- - `account` is your MUC uid (uppercase ASCII, e.g. `WANGLULU8`); falls back
152
- to `$MUC_ACCOUNT` or the previously-saved uid if `--account` is omitted.
153
- - One of `--password` / `--password-stdin` / `--token-pwd` / `$MUC_PASSWORD`
154
- is required — running `muc login` with no creds fails fast with
155
- `AUTH_REQUIRED` (exit 3).
156
- - The password is encrypted client-side (DES-CBC) before being sent — same
157
- scheme the desktop client uses.
158
- - A successful login saves to `~/.muc/credentials.json` (mode `600`):
159
- `accessToken` (short-lived; the server doesn't publish a fixed TTL —
160
- expect anywhere from hours to days) and `tokenPwd` (a longer-lived
161
- refresh token used for silent re-login with `--token-pwd`).
162
- - On any `61004` (access token expired/invalid), the CLI mirrors the
163
- desktop's `mucReLogin` recovery: it first probes `/emp/get` (which
164
- rotates `accessToken` server-side without burning the `tokenPwd`); only
165
- if that probe also fails does it fall back to the `tokenPwd → /emp/login`
166
- refresh.
167
- - If a command fails with `code: AUTH_EXPIRED` and `tokenPwd rejected`
168
- (server `61018`), the saved `tokenPwd` is gone — re-run
169
- `muc login --account <UID>` with your real password to mint fresh
170
- credentials.
171
- - A stable per-CLI device id is generated at `~/.muc/device-id` on first
172
- run. It is intentionally **different** from the desktop's machine-id so
173
- REST sessions stay independent.
174
-
175
- ## Output contract
176
-
177
- - **Default:** human-readable plain text on stdout, errors on stderr in the
178
- form `error: <msg>` / `hint: <hint>` / `code: <code> (exit <n>)`.
179
- - **`--json`** (anywhere on the command line): every command emits a single
180
- stable JSON envelope on stdout — `{ok:true, schema_version:1, data}` or
181
- `{ok:false, schema_version:1, code, msg, hint?}` — and stderr stays
182
- silent. Agents and scripts should always pass `--json`.
183
- - **Exit codes** are typed and identical in both modes: `0` success, `1`
184
- internal bug, `2` usage, `3` auth required / expired, `4` not found, `5`
185
- remote / network error, `6` config missing, `7` config invalid.
186
- - `--help` / `--version` are human escape hatches and bypass the JSON
187
- envelope by design. The canonical agent surface is `muc manifest --json`.
188
-
189
- ## Commands
190
-
191
- ### Setup
192
-
193
- | Command | What it does |
194
- |---|---|
195
- | `muc init` | Seed / inspect / reset tenant config (`~/.muc/config.json`). Run before `login`. See [First-time setup](#first-time-setup). |
196
- | `muc login` | Authenticate; persists `accessToken` + `tokenPwd` to `~/.muc/credentials.json`. See [Login](#login). |
197
- | `muc assistant-init` / `muc assistant-login` | Same as `init` / `login` but for the assistant daemon's **dedicated account** at `~/.muc/assistant/` — see [Dedicated account for the daemon](#dedicated-account-for-the-daemon). |
198
- | `muc whoami [--assistant]` | Show the saved account + token freshness. `--assistant` inspects `~/.muc/assistant/` instead. |
199
-
200
- ### REST commands (no impact on the desktop app)
201
-
202
- | Command | What it does |
203
- |---|---|
204
- | `muc login` | Authenticate, persist `accessToken` + `tokenPwd`. |
205
- | `muc whoami` | Show the saved profile + token freshness. Local only — does not read tenant config. |
206
- | `muc search <keyword>` | Org / employee directory search (12 results max, server-side). |
207
- | `muc search-dept <keyword>` | Department directory search (with employee count + path). |
208
- | `muc search-app <keyword>` | Search the user's MUC widgets/apps drawer. |
209
- | `muc search-sno <keyword>` | Search service-numbers (服务号); shows `★` for already-subscribed. |
210
- | `muc whois <UID>` | Employee info + ext info (`secureApi`). Renders `cn / id / mail / departmentName / positionName / empStatusText`. `--no-ext` skips the slower `getExtInfo` call. |
211
- | `muc set-signature [text]` | Update your personal signature (个人签名). ≤50 chars; pass `""` or `--clear` to clear. Read back via `muc whois <self-uid> --json` at `data.ext.sign` (the value lives on `getExtInfo`, not `empInfo`). Other personal-info fields (name / empId / dept / mobile / email) are HR-sourced and have no client-side write API. |
212
- | `muc groups` | Starred groups (flat list keyed by `team_id`) + department groups (keyed by `groupId / deptName`). |
213
- | `muc default-emojis` | Built-in default emoji names bundled by the desktop client. These can be used in text messages; `data.reactions` is the supported message-reaction subset. |
214
- | `muc history --peer UID \| --team TEAM_ID \| --to-self` | Server-side chat history via the roaming-messages endpoint. Stateless: each call fetches from the server. Default window: 30 days, 50 messages newest-first. |
215
- | `muc download --file-key <key> [--out <path>]` | Download a chat-attached file from the V5 file server (TCP 6101). **Read-only** — opens a fresh per-request session, no chat login, doesn't kick anyone. Pass `--mid <mid>` instead of `--file-key` plus `--peer/--team/--to-self` to look the file up via roaming history. Verifies md5 on completion. |
216
- | `muc react --mid <MID> [--emoji <name>] [target]` | Add a default message reaction emoji to an existing message. **Visible.** Defaults to `[点赞]` and `--to-self`; non-self chats need `--yes-not-self`. By default assumes the original message was sent by the current user; pass `--src-sender-id <UID>` (and `--src-sender-app <appkey>`) to react to someone else's message. |
217
- | `muc reactions --mid <MID>` | List all emoticon reactions on a single message. Read-only. |
218
- | `muc unreact --emoticon-id <id> [target]` | Revoke one of your own reactions (id from `muc react` or `muc reactions`). |
219
- | `muc manifest` | Print the full command graph + per-command output JSON Schema. Pair with `--json` for agents. |
220
-
221
- `history` flags: scope with one of `--peer UID`, `--team TEAM_ID`,
222
- `--sid <UID1|UID2 or teamId>`, or `--to-self`. `--limit N` (default 50),
223
- `--days N` (window from now, default 30), `--before <ts|ISO>` to fetch
224
- older than a moment, `--sub-type N` to filter to one type (e.g. `1` text,
225
- `7` file, `8` image), `--desc` for newest-first (default: oldest at top).
226
- The fetched `timestamp` is normalized to ms.
227
-
228
- ```bash
229
- muc history --peer YANWENYU --limit 100
230
- muc history --to-self --days 7
231
- muc history --team 9009876543210000 --before 2026-04-20 --json | jq .
232
- ```
233
-
234
- ### Chat-channel commands (TCP 8101) — see [Coexistence](#coexistence)
235
-
236
- | Command | What it does |
237
- |---|---|
238
- | `muc tcp-ping [--wait N] [--debug]` | TCP connect + NEGOTIATE only. Smoke test, no login frame, **zero** kick risk. |
239
- | `muc sync [--os OS]` | After chat-login, run `syncDone` / `syncSession` / `syncWithdraws`. Read-only. |
240
- | `muc search-team <keyword> [--enrich]` | Search groups you belong to via the chat channel; `--enrich` follows up with `team/get_team` per id to print names + member counts. |
241
- | `muc team-members <TEAM_ID> [--profiles]` | List members of a joined group via `team/get_team_members`; `--profiles` enriches each UID with org directory fields. |
242
- | `muc send (--to-self \| --peer UID \| --team TEAM_ID) <text> [--yes-not-self]` | Send a plain-text message. **Visible to the recipient.** |
243
- | `muc send-file <file> [target] [--yes-not-self]` | Upload a file (TCP 6101) and broadcast as `MESSAGE_CHAT_FILE` (subType=7). Returns persistent `fileKey` + `mid`. **Visible.** Uses both 6101 (upload) and 8101 (broadcast) — costs the chosen `--os` slot for the broadcast. |
244
- | `muc send-image <file> [target] [--width N --height N]` | Same as `send-file` but as `MESSAGE_CHAT_IMAGE` (subType=8). Width/height auto-probed from PNG/JPEG/GIF/BMP headers; pass `--width/--height` to override. |
245
- | `muc send-voice <file> --duration <ms> [target]` | Same as `send-file` but as `MESSAGE_CHAT_AUDIO` (subType=9). `--duration <ms>` is required (the desktop renders the bubble's clip length from this metadata, not from the file). |
246
- | `muc withdraw --mid <MID> [target]` | Recall a sent message. Original gets replaced server-side with "您撤回了一条消息". Target flag must match the original message's chat. |
247
- | `muc clear-session [target]` | Delete a session from your client-side history (syncs to all your devices). **Doesn't delete server-side history** — `history` still returns the messages. |
248
- | `muc pin (--to-self \| --peer UID \| --team TEAM_ID \| --sid sId)` | Pin a session to the top of the chat list (`user/setCacheField` → `sticky_on_top_id`). Multi-device. **Not** the same as starred groups (`muc groups`). |
249
- | `muc unpin [target]` | Unpin a session (same targets as `pin`). |
250
- | `muc pinned` | List currently pinned session sIds (and best-effort kind: team / p2p / self). |
251
- | `muc wait-react --mid <MID> [--from-uid UID] [--emoji <name>] [--timeout 300]` | Block until someone reacts with a default reaction emoji to `--mid`, then exit. Useful as a "human-in-the-loop approval" gate after `muc send`. Exits with `TIMEOUT` (exit 5) if no matching reaction arrives within `--timeout` seconds. |
252
- | `muc listen [--from-uid UID] [--team TEAM] [--peer UID] [--contains TEXT] [--regex …] [--at-me] [--max N]` | Long-lived TCP tap that emits one **NDJSON line per matching inbound message** (in `--json` mode each line is the standard envelope; in human mode it's a one-line summary). Supports repeatable filters (OR semantics within each kind, AND across kinds), `--at-me` to restrict to group messages where another user @-mentions you (implies excluding self), `--include-self` to include your own sends, `--include-reactions` to also surface type=3 sub=300/301 frames, `--max N` to exit after N matches. Stop with `^C`. |
253
-
254
- `--os` resolves as **per-call `--os` → `defaultChatOs` in `~/.muc/config.json`
255
- → built-in `iPad`**. Valid values: `Windows`, `OS X`, `Mac`, `iOS`, `Android`,
256
- and `iPad`. The existing option name is retained for compatibility: logical
257
- `iPad` serializes as `os:"iOS", browser:"iPad"` and selects the third slot.
258
- Set an override with `muc init --default-os <os>` or `MUC_DEFAULT_OS`.
259
-
260
- Sending to anyone other than yourself requires the explicit `--yes-not-self`
261
- flag — a guard against accidentally messaging real humans during testing.
262
-
263
- **Personal daemon routing.** When `muc daemon-start` is running for the same
264
- uid, every ordinary chat-channel command above (`send`, `send-file`,
265
- `send-image`, `send-voice`, `withdraw`, `clear-session`, `pin`, `unpin`,
266
- `pinned`, `sync`,
267
- `search-team`, `team-members`, `wait-react`, `listen`) routes its TCP work
268
- through the personal daemon's already-open socket. Dedicated `assistantd`
269
- is not borrowed by ordinary commands; it is only probed to avoid stealing a
270
- same-uid shared-profile assistant slot.
271
-
272
- Behavioural consequences while a daemon is running:
273
-
274
- - `--os` is **ignored** by these commands; the slot is fixed by whatever
275
- `--os` the daemon was started with. Passing an `--os` value that disagrees
276
- with the daemon's slot is rejected up front with `code:"USAGE"` (so the
277
- user can't ask the CLI to do something that would kick the daemon).
278
- - `muc listen --include-offline` is rejected with `code:"USAGE"` — the
279
- daemon already drained the offline batch at its own startup, so there
280
- are no offMsg frames left for `listen` to surface. Use `muc daemon-events`
281
- for raw replay, or stop the daemon and rerun without it if you need a
282
- direct offline flush.
283
- - `--json` output now carries a `route` field: `"daemon"` when the call was
284
- forwarded through the daemon's IPC socket, `"direct"` when the CLI opened
285
- its own TCP login. Routed ordinary commands also include
286
- `daemon_kind:"personal"` for compatibility-friendly disambiguation.
287
- - If the daemon is up but **not connected** (kicked, auth-expired, or
288
- network-error parked), commands fail fast with `code:"DAEMON_UNAVAILABLE"`
289
- (exit 5) rather than silently taking the slot the daemon is trying to
290
- reclaim. Inspect with `muc daemon-status --json`; resolve the pause or stop
291
- the daemon (`muc daemon-stop`) before sending directly.
292
- - If `assistantd` is explicitly running on the personal shared profile,
293
- direct ordinary TCP is blocked with `code:"DAEMON_CONFLICT"` so it cannot
294
- steal the assistant's slot. Stop `assistantd` or run the personal daemon.
295
-
296
- ### Personal daemon
297
-
298
- Foreground-only v1 daemon for the user's own `~/.muc` account. It records raw
299
- chat-channel events for 90 days by default (`MUC_DAEMON_HISTORY_DAYS`
300
- overrides retention) and exposes replay/tail by stable cursor.
301
-
302
- | Command | What it does |
303
- |---|---|
304
- | `muc daemon-start [--os OS] [--on-kicked POLICY] [--debug]` | Start the personal daemon in the foreground. Holds one chat socket for ordinary commands. `POLICY` is `pause`, `immediate`, or a duration such as `5m`; default `3m`. |
305
- | `muc daemon-status` | Show `kind:"personal"`, running status, uid, os, pid, socket, and retained history window. |
306
- | `muc daemon-stop` | Send `SIGTERM` to the personal daemon pid, or clean stale socket state. |
307
- | `muc daemon-events [--since CURSOR_OR_TIME] [--tail] [--if-missing error|earliest|latest]` | Replay raw daemon events and optionally continue live. `--since` accepts a cursor id, ISO timestamp, epoch milliseconds, or `now`. |
308
-
309
- `daemon-events` emits one envelope per NDJSON line. Event ids are ordered as
310
- `<epoch_ms>-<sequence>`; delivery is at-least-once, so consumers should
311
- deduplicate by event `id` and, for messages, by MUC `mid`.
312
-
313
- ### Assistant daemon (auto-reply)
314
-
315
- A long-lived daemon (`assistantd`) plus a registry of named **assistants**
316
- that auto-reply to inbound DMs and group `@me` mentions. The assistant daemon
317
- owns one TCP-8101 slot for assistant replies only. Ordinary commands route
318
- through `muc daemon-start`, not through a dedicated assistant account.
319
-
320
- #### Daemon lifecycle
321
-
322
- | Command | What it does |
323
- |---|---|
324
- | `muc assistantd-start [--os OS] [--on-kicked POLICY] [--debug]` | Start the assistant daemon in the foreground. Holds the chosen slot (priority: `--os` → active profile `defaultChatOs` → built-in `iPad`). Personal and dedicated-assistant behavior share this default. `POLICY` defaults to `3m`. Without a dedicated profile it fails unless `muc init --allow-assistant-shared-profile` explicitly opted into shared-profile mode. |
325
- | `muc assistantd-status` | Probe the daemon: running? slot? attached assistants? last paused-state message? |
326
- | `muc assistantd-stop` | Send `SIGTERM` to the daemon (graceful shutdown). |
327
- | `muc assistantd-resume` | Manual resume for `--on-kicked pause`, auth expiry, or exhausted network retries is reserved for v1.1. Today: `assistantd-stop` then `assistantd-start` again. |
328
-
329
- For both daemon types, `--on-kicked` accepts `pause`, `immediate`, a plain
330
- number of seconds, or a duration ending in `s`, `m`, `h`, or `d` (maximum
331
- `7d`). The default is `3m`. Immediate and delayed recovery open a new login
332
- after the selected delay, so they may kick the other device if it is still
333
- online. `daemon-status` / `assistantd-status` expose the resolved policy as
334
- `on_kicked`.
335
-
336
- If the daemon parks itself (`paused_kicked` with policy `pause`,
337
- `paused_auth` when `accessToken` / `tokenPwd` are stale, or
338
- `paused_network` after a dropped link), the process keeps running but stops
339
- handling events. The corresponding status command shows the `status` and
340
- `message`; chat-channel CLI calls fail fast with `code:"DAEMON_UNAVAILABLE"`
341
- (exit 5) until the daemon recovers or you stop it.
342
-
343
- #### Dedicated account for the daemon
344
-
345
- By default `assistantd` requires a dedicated profile under `~/.muc/assistant/`.
346
- Shared-profile assistant mode is an explicit advanced opt-in:
347
- `muc init --allow-assistant-shared-profile`. In shared mode it authenticates
348
- as the personal `~/.muc` account and is mutually exclusive with
349
- `muc daemon-start` for that uid.
350
-
351
- - **Chat slot.** A daemon and a real device on the **same** slot kick each
352
- other (`auth/kicked`, "same account login"). The built-in default is the
353
- separate iPad slot, so desktop and phone coexist; a real iPad may conflict.
354
- - **REST `tokenPwd`.** A fresh `muc login` rotates the account's refresh
355
- token; other devices on that account get logged out when their token
356
- next refreshes. Remembered-password daemon recovery is different: it uses
357
- `createTokenPwd=false`, refreshing only accessToken and preserving the
358
- phone's auto-login credential.
359
-
360
- The fix is to give the daemon its **own account**, stored under
361
- `~/.muc/assistant/` (next to its pid / socket / logs) and completely
362
- separate from your personal `~/.muc/`:
363
-
364
- ```bash
365
- muc assistant-init # tenant config → ~/.muc/assistant/config.json
366
- # (tenant secrets/hosts default to whatever your
367
- # personal `muc init` saved; defaultChatOs → iPad)
368
- muc assistant-login --account <BOT_UID> # → ~/.muc/assistant/credentials.json
369
- # (--platform defaults to mac)
370
- muc assistantd-start # picks up the dedicated profile
371
- muc whoami --assistant # confirm which account it's on
372
- ```
373
-
374
- Once provisioned, `muc assistantd-start` reads the dedicated profile
375
- automatically (every REST call the daemon makes follows it too). The
376
- daemon defaults to the **iPad slot**, so the account's desktop and phone
377
- slots remain independent. A real iPad logged into that same assistant
378
- account may be kicked. Remove the profile (`rm -rf ~/.muc/assistant/config.json
379
- ~/.muc/assistant/credentials.json`) only if you intend to use the explicit
380
- shared-profile mode.
381
-
382
- #### Assistant CRUD
383
-
384
- | Command | What it does |
385
- |---|---|
386
- | `muc assistant-new <name> [--template <id>] [--backend claude-code\|codex\|gemini\|cursor\|antigravity] [--model <id>] [--reasoning-effort <level>] [--commands /a,/b] [--description TEXT]` | Scaffold `~/.muc/assistants/<name>/` with `config.json`, a persona `system-prompt.md` (template substitutes `<SCOPE_DESCRIPTION>` from `--description`), and an empty `memory.jsonl`. **`--template <id>`** seeds the scaffold from a starter template (run `muc assistant-templates` to list); supplies the persona prompt, default `backend` / `model` / `reasoning_effort` / `commands`, and copies any `bin/` helpers into `~/.muc/assistants/<name>/bin/`. Explicit `--backend` / `--model` / `--reasoning-effort` / `--commands` flags still override the template's defaults. **`--reasoning-effort <level>`** is codex-only (`minimal` \| `low` \| `medium` \| `high` \| `xhigh`) and forwards to `codex -c model_reasoning_effort=<level>`; `xhigh` is model-dependent (codex falls back to `high` on models that don't support it). Other backends ignore the field. Omit the flag (and don't set `reasoning_effort` in the template) to let codex use its built-in default. After a template-based create the JSON output includes `setup_notes` (host-side prereqs the template can't auto-do, e.g. `glab auth login`) and `bin_files`. Backend defaults to `claude-code`; `codex` requires the `codex` CLI on PATH (logged in via `codex login` or `OPENAI_API_KEY`); `gemini` requires the `gemini` CLI on PATH (logged in via `gemini` interactive first-run, or `GEMINI_API_KEY` / `GOOGLE_API_KEY`); `cursor` requires the `cursor-agent` CLI on PATH (logged in via `cursor-agent login` OAuth, or `CURSOR_API_KEY`); `antigravity` requires the `agy` CLI on PATH (logged in via `agy` interactive Google-OAuth first-run) — its `--model` is advisory only (the active model is whatever you select in agy's own picker; defaults to `"Gemini 3.5 Flash (High)"`). `--commands` claims a comma-separated set of slash-commands (e.g. `--commands /img,/draw`); each must match `^/[a-z][a-z0-9-]{0,20}$`, must be globally unique across assistants, and `/help` is reserved for the daemon. Omit (or pass `""`, and don't use `--template`) to mark this assistant as a fallback that fires on messages with no `/cmd` match. The flag only takes bare names — to attach a per-command `desc` / `usage` (rendered in `/help`), edit each entry in `~/.muc/assistants/<name>/config.json` after creation: `{ "name": "/img", "desc": "AI 图像生成", "usage": "/img <prompt>" }`. |
387
- | `muc assistant-templates` | List starter templates available to `assistant-new --template <id>`. Two roots are searched: bundled (ships with muc-cli) and `~/.muc/templates/<id>/` (user-managed); when an id exists in both, **user wins**. Each row reports `id`, `source` (`bundled` \| `user`), `description`, default `backend` / `model` / `reasoning_effort` / `commands`, declared `placeholders`, host-side `prereqs`, whether the template ships a `bin/` helper directory, and the absolute `path`. To author a template, drop a directory under `~/.muc/templates/<your-id>/` containing `template.json` (with `id` matching `^[a-z][a-z0-9-]{0,40}$`), `system-prompt.md`, optional `setup-notes.md`, and an optional `bin/`. To override a bundled template without forking, copy it under `~/.muc/templates/<same-id>/` and edit in place. |
388
- | `muc assistant-list` | List registered assistants with their backend, priority, claimed `commands` (legacy name array) plus `command_specs` (rich `{name,desc?,usage?}` array), `is_fallback` flag, scope, and whether the daemon currently has them attached. |
389
- | `muc assistant-start <name>` | Tell the running daemon to start routing matching events to this assistant. |
390
- | `muc assistant-stop [name]` | Detach a single assistant; omit the name to detach **all**. Scaffolds stay on disk. |
391
- | `muc assistant-edit <name>` | Open this assistant's persona `system-prompt.md` in `$EDITOR` / `$VISUAL` / `vi`. |
392
- | `muc assistant-memory <name> [--tid <tid>] [--all] [--clear]` | Inspect the per-thread memory shards the backend sees. Default action: list every thread with its entry count. `--tid <tid>` (e.g. `team_g:<groupId>` or `p2p:<UID>`) shows one thread's journal; `--all` is the legacy cross-thread dump (debug only). `--clear` truncates — combine with `--tid` for one thread or `--all` for everything. Storage: `~/.muc/assistants/<name>/threads/<safe-tid>.jsonl`. |
393
- | `muc assistant-delete <name>` | Detach (if the daemon's up) and remove the scaffold (config, prompt, memory). |
394
-
395
- #### Starter templates
396
-
397
- `muc assistant-templates` lists every template available to `assistant-new --template <id>`. A template is a directory with this layout:
398
-
399
- ```
400
- <root>/<id>/
401
- template.json # id, description, default backend / model / reasoning_effort (codex only) / commands, declared placeholders, host-side prereqs
402
- system-prompt.md # persona prompt (with <PLACEHOLDER> substitutions)
403
- setup-notes.md # optional — printed verbatim after `assistant-new` finishes
404
- bin/ # optional — copied to ~/.muc/assistants/<name>/bin/ and chmod +x
405
- ```
406
-
407
- Two roots are searched user-first:
408
-
409
- - `~/.muc/templates/<id>/` — user-managed; sharable by `tar` / `cp`; no muc release needed.
410
- - bundled (ships with muc-cli) — listed with `source: "bundled"`.
411
-
412
- Same id in both → user wins. To override a bundled template without forking, copy it to `~/.muc/templates/<same-id>/` and edit in place.
413
-
414
- `<ASSISTANT_NAME>` / `<USER_NAME>` / `<MUC_ASSISTANT_DIR>` / `<MUC_ASSISTANT_BIN_DIR>` placeholders in `system-prompt.md` and `setup-notes.md` are substituted at create-time. At runtime, the daemon also exports `MUC_ASSISTANT_NAME` / `MUC_ASSISTANT_DIR` / `MUC_ASSISTANT_BIN_DIR` to the backend process, so a prompt can reference its own bundled scripts as `$MUC_ASSISTANT_BIN_DIR/<helper>` without absolute paths.
415
-
416
- Bundled today: **`code-handler`** — GitLab code assistant. A single `/code [<gitlab-url>] [<desc>]` command covers review / implement / refine / explain / Q&A; the assistant decides the action from the URL kind and description, and the URL can be omitted when it's resolvable from the conversation context. Authorization is keyed off GitLab project membership rather than a config-file allowlist; commit author is taken from the trigger's MUC UID. Prereqs: `glab auth login` against your internal GitLab. Run `muc assistant-templates --json` for the full list and per-template `prereqs`.
417
-
418
- #### Per-assistant config — `~/.muc/assistants/<name>/config.json`
419
-
420
- Hand-edit, or seeded by `assistant-new`:
421
-
422
- | Field | Type | Default | Notes |
423
- |---|---|---|---|
424
- | `name` | string | (arg) | `^[a-zA-Z0-9_-]{1,40}$` — also the directory name |
425
- | `backend` | enum | `claude-code` | `claude-code` requires the `claude` CLI on PATH; `codex` requires the `codex` CLI on PATH (logged in via `codex login` or `OPENAI_API_KEY`) — defaults to `gpt-5.6-sol`; `gpt-5.6-terra`, `gpt-5.6-luna`, and older model ids remain selectable through the `model` field; `gemini` requires the `gemini` CLI on PATH (logged in via `gemini` interactive first-run, or `GEMINI_API_KEY` / `GOOGLE_API_KEY`) — defaults to `auto-gemini-3` (lets gemini auto-route between gemini-3-pro and gemini-3-flash, falling back to gemini-2.5-pro if no preview access), override via the `model` field; `cursor` requires the `cursor-agent` CLI on PATH (logged in via `cursor-agent login` OAuth, or `CURSOR_API_KEY`) — defaults to `auto` (Cursor's router), override via the `model` field; `antigravity` requires the `agy` CLI on PATH (logged in via `agy` interactive Google-OAuth first-run) — the `model` field is advisory only (used for the disclosed label; agy runs whatever model is selected in its own picker, defaulting to `"Gemini 3.5 Flash (High)"`) |
426
- | `model` | string | — | optional backend-specific model override |
427
- | `reasoning_effort` | enum | — | codex backend only — `minimal` \| `low` \| `medium` \| `high` \| `xhigh`. Forwarded as `codex -c model_reasoning_effort=<level>`. `xhigh` is model-dependent (codex falls back to `high` on models that don't support it). Other backends ignore the field. Omit to let codex use its built-in default. Templates seed this from `template.json`'s `reasoning_effort`. |
428
- | `scope.scenes` | `("p2p"\|"team_g")[]` | — | restrict to DMs and / or group chats |
429
- | `scope.tids` | `string[]` | — | only these `team_id`s match (groups only — DMs are filtered via `scope.from_uids`) |
430
- | `scope.from_uids` | `string[]` | — | only messages from these senders match |
431
- | `scope.keywords` | `string[]` | — | substring-match on body text |
432
- | `commands` | `Array<string \| {name,desc?,usage?}>` | `[]` | slash-commands this assistant claims. Each entry is either a bare name (`"/img"`) or a rich spec (`{ "name":"/img", "desc":"AI 图像生成", "usage":"/img <prompt>" }`); both shapes coexist in one array. `name` matches `^/[a-z][a-z0-9-]{0,20}$`, is globally unique across assistants, and `/help` is reserved for the daemon. `desc`/`usage` ≤ 200 chars each — surfaced in the daemon's `/help` menu (defaults: `usage` falls back to `name`; `desc` falls back to `help_text`, then `<name>(<backend>[/<model>])`). Empty list = fallback assistant for its scope. |
433
- | `priority` | int | `100` | lower wins when multiple assistants tie for the same command or fallback bucket; ties are logged to `~/.muc/assistant/conflicts.log` |
434
- | `memory_window` | int (0–500) | `30` | rolling history entries kept per thread |
435
- | `bootstrap_history` | bool | `true` | seed memory from server-side roaming history on first event in a thread |
436
- | `reply_timeout_ms` | int (≥5s) | `120000` | backend invocation timeout |
437
- | `help_text` | string | built-in fallback | sent verbatim when the backend returns `{"action":"skip","blocks":[]}` |
438
- | `restrict.shell_grants` | `string[]` | — | optional opt-in tightening. **Absent** ⇒ permissive-by-default: every backend runs in its sandbox-but-permissive mode (writes inside the per-turn cwd, network on, native muc-verb deny still loads). **Set** ⇒ revert to a per-prefix allow-list backends enforce natively where possible (`claude --allowed-tools "Bash(<prefix>*)"`, cursor `cli.json` `permissions.allow`, gemini `--allowed-tools ShellTool(<prefix>)`). codex has no native flag — entries surface as a prompt-side advisory only. Templates seed this from `template.json`'s `restrict.shell_grants`; placeholders (`<MUC_ASSISTANT_BIN_DIR>` etc.) are pre-substituted at `assistant-new` time. |
439
-
440
- > **Per-turn workspace + repo cache.** Every dispatch gets a private dir
441
- > `~/.muc/assistants/<name>/workspace/turn-<msgId>/` that the daemon hands
442
- > the backend as `cwd` and exports as `MUC_ASSISTANT_REPO_CACHE`'s parent
443
- > (`MUC_ASSISTANT_REPO_CACHE=<turn-cwd>/.cache/repos`). Template-bundled
444
- > helper scripts (e.g. `prep-repo`) honor that var so all writes — bare-
445
- > caches, worktrees, scratch files — stay inside the turn dir and are
446
- > wiped on cleanup. There is no separate `writable_roots` config to
447
- > maintain anymore.
448
-
449
- #### Routing & dispatch
450
-
451
- 1. Inbound message passes the trigger gate (DMs always; groups only on `@me`; never self; only `kind:"text"`).
452
- 2. Per-assistant scope filter (scenes / tids / from_uids / keywords) narrows the eligible set.
453
- 3. **`/help`** is daemon-owned. Renders a per-thread menu of every claimed `command` from in-scope active assistants — one line per command, formatted as `• <usage> — <desc>` (with `usage`/`desc` pulled from each command's spec, falling back to `name` and `help_text` / `<name>(<backend>)` respectively). Includes a `• 其他消息 → <name>` line if a fallback is in scope. Reachable even when no assistants are active. Sent as a richtext bubble with a real `@<asker>` mention so the response is clickable in the group.
454
- 4. **`/<cmd>`** dispatches to the assistant that registered it (lower `priority` wins on ties). A `/cmd` that no in-scope assistant owns triggers the daemon's `unknown command <cmd> — type /help…` reply. A bare `/` or malformed `/CMD` (uppercase, leading digit, etc.) gets the same treatment — never silently flows into a fallback.
455
- 5. **No `/` prefix** falls back to the in-scope assistant whose `commands` list is empty (lowest `priority` wins). If no fallback is in scope, the daemon sends `no_route_hint` so the user knows there's nothing listening.
456
- 6. Backend returns a JSON envelope `{"action":"reply"|"skip","blocks":[…]}`. `action:"skip"` ⇒ daemon sends `help_text` (or the built-in fallback) to the thread. `action:"reply"` ⇒ daemon ships the blocks straight to the thread and appends a `\n\n— <assistant> · <model>` signature tail to every reply. (No self-DM mirror — use `muc assistant-ui` / `muc assistant-log` to audit outbound traffic.)
457
- 7. The signature tail is also the **loop-stop**: any inbound whose last paragraph matches that exact shape is dropped before routing, so two assistants on opposite ends can't ping-pong.
458
- 8. Outbound failures (server reject or socket throw) emit IPC `outbound_failed` and fire a macOS notification.
459
-
460
- ```bash
461
- # v1: foreground only; wrap in tmux/screen for persistence.
462
- muc assistantd-start # default iPad slot
463
- muc assistant-new desk-bot --description "out-of-hours triage in IT 值班群"
464
- $EDITOR ~/.muc/assistants/desk-bot/config.json # add scope.tids etc.
465
- muc assistant-edit desk-bot # tune the persona
466
- muc assistant-start desk-bot # attach to running daemon
467
- muc assistant-list --json | jq '.data.assistants[] | {name,active,commands,scope}'
468
-
469
- # Specialist with a slash-command claim (paired with a fallback chatter):
470
- muc assistant-new img-gen --commands /img,/draw --description "image generation"
471
- muc assistant-new chatter --description "general triage in IT 值班群"
472
- muc assistant-start img-gen
473
- muc assistant-start chatter
474
- # /img cat → img-gen ; /help → daemon menu ; anything else → chatter
475
-
476
- # Inspect / unwind
477
- muc assistantd-status --json
478
- muc assistant-memory desk-bot --clear
479
- muc assistant-stop desk-bot
480
- muc assistantd-stop
481
- ```
482
-
483
- **Message tail (signature)**: by default `muc send` appends a short tail to
484
- the text it sends (e.g. `"\n—— 来自王璐璐的muc-cli"`) so recipients can
485
- tell automated traffic from a typed message. The check is idempotent —
486
- if your text already ends with the resolved tail, it is not appended a
487
- second time. Customise it with the
488
- `messageTail` field in `~/.muc/config.json` — set to a non-empty string to
489
- override, or to `""` to disable entirely. You can also use
490
- `muc init --message-tail "<custom>"` / `muc init --no-message-tail` to
491
- write the value, and per-call flags `muc send --tail "<one-off>"` /
492
- `muc send --no-tail` to override on a single send. Only `muc send`
493
- (plain-text) is affected; `send-file` / `send-image` / `send-voice` are
494
- not.
495
-
496
- ```bash
497
- muc tcp-ping --wait 8 # safe protocol smoke test
498
- muc send "hello from the CLI" # to-self (default)
499
- muc send --peer ZHANG_W2 "ping" --yes-not-self
500
- muc send --team 9009876543210000 "team message" --yes-not-self
501
-
502
- muc send-file ./report.pdf --to-self # self test
503
- muc send-image ./screenshot.png --peer ZHANG_W2 --yes-not-self # auto width/height
504
- muc send-voice ./clip.amr --duration 3500 --to-self # 3.5 s clip
505
-
506
- muc download --file-key /chat/m/WANGLULU8/.../<md5> --out ./got.bin # by explicit key
507
- muc download --mid 69ef1ae07e5462c465c05e00 --to-self # look up body via roaming
508
- muc download --mid <MID> --peer YANWENYU --out ./inbox/ # save into a directory
509
- ```
510
-
511
- `download` is the only file-channel command that **doesn't** open a chat
512
- session — it speaks only port 6101 (and a one-time bucket lookup on first
513
- call). Run it from any environment without disturbing your desktop or phone.
514
-
515
- ## Coexistence
516
-
517
- **REST commands always coexist** with a running desktop and phone — the
518
- server allows concurrent `accessToken`s. `whoami`, `search`, `search-dept`,
519
- `search-app`, `search-sno`, `history`, `whois`, `set-signature`, `groups`, `default-emojis`, and
520
- `download` are REST-only (or 6101-only, in `download`'s case) and safe to
521
- run anytime.
522
-
523
- **Chat-channel commands** (`sync`, `search-team`, `team-members`, `send`, `send-file`,
524
- `send-image`, `send-voice`, `withdraw`, `clear-session`, `pin`, `unpin`, `pinned`) open a TCP-8101
525
- session and share a per-user **three-slot** model with real devices:
526
-
527
- | Slot | `--os` values |
528
- |---|---|
529
- | PC | `Windows`, `"OS X"`, `Mac` |
530
- | Mobile | `iOS`, `Android` |
531
- | iPad | `iPad` (default; wire `os:"iOS", browser:"iPad"`) |
532
-
533
- A second login in the same slot kicks the previous client off the realtime
534
- channel — the IM panel goes offline, but tokens stay valid (reopen to
535
- recover). The Mac desktop signs in as `"OS X"` (PC); the iPhone signs in as
536
- `iOS` (Mobile); the iPad app adds `browser:"iPad"` (iPad).
537
-
538
- The CLI defaults to `--os iPad`, so desktop and phone can remain online.
539
- Only a real iPad on the same account may be kicked by the default. Explicit
540
- PC or Mobile values intentionally target those older slots.
541
-
542
- `tcp-ping` only does TCP connect + NEGOTIATE (no `auth/login`), so it can't
543
- kick anything. Run it first to confirm the wire protocol is happy on your
544
- network.
545
-
546
- If you do get kicked, reopen the desktop's IM panel or relaunch the mobile
547
- app to recover — tokens stay valid.
548
-
549
- ## Examples
550
-
551
- ```bash
552
- $ printf '%s' "$MY_PWD" | muc login --account WANGLULU8 --password-stdin
553
- uid: WANGLULU8
554
- empId: 5394483846707200
555
- name: 王璐璐
556
- accessToken: TV5l…u9kQ (redacted; use --json for raw)
557
- accessTokenExpireAt: 1745678340000
558
- tokenPwdRefreshed: true
559
- tokenPwdExpireAt: 1748097540000
560
-
561
- $ muc whoami
562
- uid: WANGLULU8
563
- empId: 5394483846707200
564
- name: 王璐璐
565
- deviceId: 8e413b4141…
566
- deviceName: WANGLULU8-mbp.local (muc-cli)
567
- accessToken: TV5l…u9kQ (redacted; use --json for raw)
568
- accessTokenExpireAt: 1745678340000
569
- tokenPwdSet: true
570
- tokenPwdExpireAt: 1748097540000
571
- savedAt: 1745073540000
572
- credentialsPath: ~/.muc/credentials.json
573
-
574
- $ muc search 张
575
- ZHANG_W2 张伟 飞行部 / 机长室
576
- ZHANGSAN03 张三 地面服务部
577
- …
578
-
579
- $ muc whois ZHANG_W2
580
- uid ZHANG_W2
581
- name 张伟
582
- empId 4892173049281024
583
- mobile 1380013…
584
- email zhang.wei@ceair.com
585
- dept 飞行部 / 机长室
586
- title 机长
587
-
588
- $ muc groups
589
- starred:
590
- [常用] (3)
591
- 9001234567890123 IT 值班群
592
- 9001234567890124 运行联络
593
- 9001234567890125 部门通知
594
- dept groups: 1
595
- 9009876543210000 飞行部 / 机长室
596
-
597
- $ muc default-emojis
598
- emojis:
599
- - [+1]
600
- - [DONE]
601
- - [GET]
602
- ...
603
- reactions:
604
- - [+1]
605
- - [收到]
606
- - [加油]
607
- - [OK]
608
- - [点赞]
609
- - [鼓掌]
610
- - [DONE]
611
- defaultReaction: [点赞]
612
- ```
613
-
614
- ## Files & paths
615
-
616
- | Path | Purpose | Mode |
617
- |---|---|---|
618
- | `~/.muc/config.json` | tenant config: APP_KEY, APP_ID, signing secrets, hosts/ports | 600 |
619
- | `~/.muc/credentials.json` | accessToken, tokenPwd, profile | 600 |
620
- | `~/.muc/device-id` | stable per-CLI deviceId (sha256 hex) | 600 |
621
- | `~/.muc/remember.salt` | salt for the optional `--remember` password blob | 600 |
622
- | `~/.muc/runtime/daemon.sock`, `daemon.pid`, `daemon-state.json`, `daemon-events-*.ndjson` | personal daemon IPC, pid/state, and raw event history | — |
623
- | `~/.muc/assistant/config.json`, `credentials.json`, `device-id`, … | the daemon's [dedicated account](#dedicated-account-for-the-daemon), when provisioned — same file set as above, scoped to one profile dir | 600 |
624
- | `~/.muc/assistant/` (other files) | daemon runtime: `daemon.pid`, `assistant.sock`, `state.json`, `inbox.ndjson`, `events-*.ndjson`, `conflicts.log` | — |
625
- | `~/.muc/assistants/<name>/` | per-assistant persona: `config.json`, `system-prompt.md`, `threads/`, `workspace/` | — |
626
-
627
- Everything shares the `~/.muc/` parent (mode 700). The CLI creates these on
628
- first use; you should never need to edit the `config.json` / `credentials.json`
629
- files by hand.
630
-
631
- ## Changelog
632
-
633
- #### Unreleased
634
- - Add the third iPad chat slot. Logical `--os iPad` serializes as `os:"iOS", browser:"iPad"` and is now the built-in default for personal commands, the personal daemon, and assistantd. Existing explicit `defaultChatOs` values remain authoritative.
635
- - Slot safety guidance is now non-blocking: skills remind that a real iPad may be kicked and continue without asking for slot confirmation. Recipient, content, and destructive-action confirmations are unchanged.
636
- - Add the personal daemon command family: `muc daemon-start`, `daemon-status`, `daemon-stop`, and `daemon-events`. Ordinary chat-channel commands now route only through the personal daemon and report `daemon_kind:"personal"` when routed.
637
- - Dedicated `assistantd` is no longer borrowed by ordinary commands. Without a dedicated assistant profile, `assistantd-start` now requires explicit `muc init --allow-assistant-shared-profile`; same-uid shared-profile assistantd conflicts with the personal daemon / direct ordinary TCP via `DAEMON_CONFLICT`.
638
- - Add raw event cursors (`<epoch_ms>-<sequence>`), 90-day personal daemon event retention, and `CURSOR_NOT_FOUND` handling for missing retained cursors.
639
-
640
- #### `0.5.0`
641
- `2026.05.11`
642
- - Add `muc assistant-init` / `muc assistant-login` and `muc whoami --assistant`: the assistant daemon can authenticate as a **dedicated account** under `~/.muc/assistant/`, fully separate from the personal profile. At this release it defaulted to the PC slot; the current Unreleased behavior supersedes that with the iPad default. `assistant-login` still defaults REST `--platform` to `mac`.
643
- - Internals: `config.json` / `credentials.json` / `device-id` / `remember.salt` / `runtime/refresh-log.ndjson` paths now resolve through a process-wide *profile root* (default `~/.muc`) instead of being hardcoded. `configPath` / `credentialsPath` / `configDir` are now functions.
644
-
645
- #### `0.4.1`
646
- `2026.05.03`
647
- - Redesign assistant routing around globally-unique slash-commands (`assistant-new --commands /img,/draw`) plus a `commands:[]` fallback bucket; `/help` is now a daemon-owned per-thread menu reachable even when no assistants are active. Drop the draft / 👍 / DONE approval flow, `auto_send`, `cooldown_ms`, `draft_ttl_ms`, and `scope.default` — replies ship straight to the thread.
648
- - Loop-stop is now structural: every reply carries a `\n\n— <assistant> · <model>` signature tail, and any inbound whose last paragraph matches that shape is dropped before routing. The `__SKIP__` literal is gone — backends return `{"action":"skip","blocks":[]}` instead.
649
- - Outbound send failures emit IPC `outbound_failed` and fire a macOS notification. The monitor (`muc assistant-ui`) and `muc assistant-log` surface the daemon-owned routing replies (`help_menu_sent` / `unknown_command_sent` / `no_route_hint_sent`) under the synthetic `daemon` owner.
650
- - Existing `~/.muc/assistants/<name>/config.json` files are migrated in place on read: removed fields stripped, `commands: []` injected.
651
-
652
- #### `0.4.0`
653
- `2026.04.30`
654
- - Add `muc assistantd-start` / `assistantd-status` / `assistantd-stop` (foreground daemon, holds one TCP slot, owns the chat socket for the rest of the CLI via IPC)
655
- - Add `muc assistant-new` / `assistant-list` / `assistant-start` / `assistant-stop` / `assistant-edit` / `assistant-memory` / `assistant-delete` to manage named auto-reply assistants under `~/.muc/assistants/<name>/`
656
- - Pluggable backends (`claude-code`, `codex`, `gemini`, `cursor`); per-assistant scope rules, priority, persona overlay on a bundled safety-rails prompt, rolling memory window
657
- - Other chat-channel commands (`send`, `send-file`, `send-image`, `send-voice`, `withdraw`, `sync`, `wait-react`, `listen`) now route through the daemon when it's running; `--json` output gains `route: "daemon" \| "direct"`. Conflicting `--os` and `listen --include-offline` are rejected up front; a parked daemon yields `code:"DAEMON_UNAVAILABLE"`
658
-
659
- #### `0.3.1`
660
- `2026.04.29`
661
- - Add `defaultChatOs` to `~/.muc/config.json`. At this release the accepted values stopped at Android and the built-in fallback was `iOS`; current Unreleased behavior also accepts `ipad` and defaults to `iPad`.
662
-
663
- #### `0.3.0`
664
- `2026.04.29`
665
- - Add `muc react` / `muc unreact` / `muc reactions` to add, revoke, and list emoticon reactions on existing messages
666
- - Add `muc wait-react` to block until a human reacts to a given mid; useful as a "human-in-the-loop approval" gate after `muc send`
667
- - Add `muc listen`, a long-lived TCP tap with sender / chat / keyword / `--at-me` filters, one NDJSON line per match
668
- - Exit code `5` now also covers `TIMEOUT` and `KICKED`
669
-
670
- #### `0.2.2`
671
- `2026.04.28`
672
- - `muc send` plain-text now appends an idempotent signature tail by default; override via `--tail` / `--no-tail`, `muc init --message-tail`, or `messageTail` in `~/.muc/config.json`
673
-
674
- #### `0.2.1`
675
- `2026.04.28`
676
- - Skills unified across macOS / Linux / Windows
677
- - On Windows, file mode `600` is silently ignored — use NTFS ACLs on shared hosts to protect `~/.muc/`
678
-
679
- #### `0.2.0`
680
- `2026.04.27`
681
- - Add `muc init`: extract `appKey` / `appId` / signing secrets out of source code, write to `~/.muc/config.json` (mode 600)
682
- - Companion subcommands: `muc init --check` / `--show` / `--reset`
683
- - License changed to MIT; package published to npm with public access
684
-
685
- ## What it can't do (yet)
686
-
687
- - **Richtext messages** (`subType=11`, mixed text + image + @-mention in one
688
- bubble). The image segments share the file-channel upload path so the
689
- bulk of the work is already there; just needs a body-builder + a
690
- `send-rich` command.
691
- - **Forwarded / merged messages** (`subType=26`).
692
- - **SSO / scan-to-login.** REST username+password works; the SSO flow is
693
- not wired up.
694
- - **Image thumbnails.** The upload step asks the server to make `tn1`/`tn5`
695
- thumbs, but `muc download` only fetches the original `fileKey`.
696
- - **End-to-end-encrypted file content.** Not active on the default tenant
697
- and the CLI doesn't implement it.
698
-
699
- ## Troubleshooting
700
-
701
- - `code: CONFIG_MISSING` (exit 6) — `~/.muc/config.json` is absent. Run
702
- `muc init` to create it. The CLI cannot guess your tenant's signing
703
- secrets.
704
- - `code: CONFIG_INVALID` (exit 7) — the file exists but failed schema
705
- validation (corruption, manual edit gone wrong, or a stale schema after
706
- upgrade). Run `muc init` to repair it; `--reset --yes` to start clean.
707
- - `login failed: code=…` — sign or DES is wrong. Double-check the signing
708
- secrets and `appKey` / `appId` you supplied to `muc init` against the
709
- values your MUC admin provided. `muc init --show` (secrets redacted) lets
710
- you confirm what's currently saved; `muc init` (interactive) lets you
711
- re-enter the values.
712
- - `error: not logged in` (exit 3, code `AUTH_REQUIRED`) — the saved
713
- credentials file is missing or unreadable. Check `~/.muc/credentials.json`
714
- and re-run `muc login`.
715
- - `code: AUTH_EXPIRED` (exit 3) — accessToken or tokenPwd was rejected by
716
- the server. On the personal profile (`~/.muc`), re-run `muc login --token-pwd`
717
- (or full `muc login` if `tokenPwd` is also stale). On the dedicated
718
- assistant profile (`~/.muc/assistant/config.json` present — the daemon
719
- account), substitute `muc assistant-login --token-pwd` /
720
- `muc assistant-login` — `muc login` only touches the personal credentials.
721
- - `EPROTO` / TLS errors — corporate proxy or VPN intercepting traffic.
722
- `muc-cli` does not pin certificates, so adding the proxy CA to your Node
723
- trust store should suffice (`NODE_EXTRA_CA_CERTS=/path/to/ca.pem`).
724
- - A TCP command kicks a client off the IM panel — the CLI's `--os` value
725
- collided with that client's slot. The default `--os iPad` only risks a
726
- real iPad; explicit PC or Mobile values risk the matching client.
727
-
728
- ### 5.9 Gemini CLI headless timeout
729
-
730
- If a `backend: "gemini"` assistant times out with empty stdout/stderr,
731
- the current adapter is already passing `--skip-trust`, closing stdin,
732
- and killing the full process tree on timeout. Round-5 live probes against
733
- Gemini CLI `0.40.0` still found an environment-specific failure mode
734
- where Node `child_process.spawn()` never receives JSON output even after
735
- testing:
736
-
737
- - `stdin.end(payload)` vs `write()+destroy()`
738
- - `detached: true` vs `false`
739
- - explicit `TERM` / `CI` / `GEMINI_*` / `GOOGLE_*` / `NO_COLOR` env sync
740
- - `mkdtemp()` dir mode `0700` vs `0755`
741
- - `stdio: ['pipe','inherit','inherit']`
742
- - `GEMINI_CLI_TRUST_WORKSPACE=true`
743
-
744
- If the same `gemini ... --output-format json` command works in your
745
- interactive terminal but not when spawned from Node, treat it as an
746
- external Gemini CLI runtime issue rather than a muc prompt/JSON bug. The
747
- daemon now fails fast with a timeout instead of hanging indefinitely; use
748
- `claude-code` or `codex` for unattended runs on hosts where Gemini only
749
- works interactively.
750
-
751
- ### Exit-code summary
752
-
753
- | Exit | Code |
754
- |---|---|
755
- | 0 | success |
756
- | 1 | INTERNAL |
757
- | 2 | USAGE |
758
- | 3 | AUTH_REQUIRED, AUTH_EXPIRED |
759
- | 4 | NOT_FOUND |
760
- | 5 | REMOTE_ERROR, NETWORK, TIMEOUT, KICKED, DAEMON_UNAVAILABLE |
761
- | 6 | CONFIG_MISSING |
762
- | 7 | CONFIG_INVALID |
763
-
764
- ## Security
765
-
766
- - Both files in `~/.muc/` are written with mode `600`. **Don't** check them
767
- into git or copy them to shared machines.
768
- - **Don't share `~/.muc/config.json`** — it contains your tenant's signing
769
- secrets (`signSecretRest`, `signSecretSecure`, `pwdDesKey`, `appKey`).
770
- Anyone with these can impersonate API calls against your MUC tenant.
771
- - `MUC_PASSWORD` ends up in shell history; prefer `--password-stdin` or
772
- `--token-pwd` for refreshes.
773
- - **Prefer interactive `muc init` over env vars.** Environment variables
774
- leak through shell history and `/proc/<pid>/environ` to other processes
775
- on the same machine. Use the interactive prompt or one-shot flags pulled
776
- from a secret manager rather than persistent `MUC_*` exports.
777
- - TCP login over 8101 registers a device session in one of three slots per
778
- user (PC, Mobile, or iPad). A second login in the same slot kicks the first.
779
- Default `--os iPad` only risks a real iPad on the same account.
780
- - `tcp-ping` is the only chat-channel command that cannot kick anything —
781
- use it as a network smoke-test before trying TCP sends.
48
+ 普通文件发送默认不带尾注(包括带说明的文件消息);明确 `--tail` 才添加。文件上传须完成服务端扫描并取得未来有效期,才会进入消息发送;扫描失败不会降级发送过期文件。