agent-loft 0.2.78 → 0.2.80

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
@@ -29,6 +29,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
29
29
  | 🧑‍🏫 | **专家** | 自己配专家:选引擎、写提示词,定它能做什么(只能联网 / 读文件 / 改文件 / 跑命令),挂哪些技能和 MCP,能把活派给哪些子智能体。新对话、定时任务都能选 |
30
30
  | 🔀 | **飞书机器人灵活绑定 agent** | 机器人数量不限,每个机器人可以直接勾选内置或共享专家,并选择默认专家(可在会话里切换)。网页上扫码就能创建,改完立即生效;由服务端主动连向飞书,家里没有公网 IP 也能在外面用 |
31
31
  | 🔗 | **飞书续接 Web 任务** | 飞书里发 `/web` 接上一条 Web 会话,或者在网页聊天右上角「更多」或侧栏会话右键菜单里选「在飞书继续」。之后回复、授权、提问都发到飞书,发 `/detach` 回来 |
32
+ | 💬 | **微信 ClawBot** | 设置 → 账号里用微信扫码,就能在微信里和 agent 聊天、回数字处理授权和提问,网页上是同一条对话。每个人连自己的微信。微信限制较多,适合发起任务和接收回复,详见下面的说明 |
32
33
  | 🖥️ | **完整的 Web 工作台** | 流式回复、附件、语音输入、模型和思考程度切换、上下文占用、从任意回复分叉、按项目分组的侧栏、搜索会话、全部设置,电脑和手机(PWA)都能用 |
33
34
  | 🔔 | **飞书 + 苹果系统推送** | 除了飞书消息,Web 会话还能推送到 iPhone、iPad 锁屏和 Mac 通知中心(标准 Web Push,不需要开发者账号),图标上显示未读数 |
34
35
  | 🗂️ | **桌面端同时接入多台设备** | 桌面端(macOS / Windows / Linux)同时连多台服务器,菜单栏 / 托盘一眼看完各台的额度、待处理和运行中的会话 |
@@ -95,6 +96,11 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
95
96
  - 桌面:走 VNC 协议,网页里用 noVNC 显示,鼠标、键盘、剪贴板都能用,进来时不自动连、点「连接桌面」才连,工具栏上选画质:流畅 / 标准(默认)/ 高清由服务端把画面缩小到长边 1280 / 1920 / 2560、只把变了的地方压成 JPEG 发过来(macOS 屏幕共享只给无损的 ZRLE,5K 屏一整屏 30MB,原样转发隔着公网几秒一帧),原画是原样转发、只适合局域网;远程那边接了几块屏时可以只看其中一块(按系统里的显示器名称选,服务端只截那块再缩,比几块屏拼在一起缩小清楚得多;macOS 的各块屏位置要从屏幕共享发来的画面里学,第一次连上要几秒,原画下不能选);可以缩放到窗口或按原始大小看、全屏(手机上也能,iPhone 上是铺满页面)、「只看不控制」、发送 Ctrl+Alt+Del 之类的组合键。手机上有两种手势(右上角切换,「?」看说明):**触控板模式**(默认)屏幕上有个指针,单指滑动移动、轻点单击、双指轻点右键、长按后拖动是按住左键拖、双指滑动滚动;**触摸模式**点哪就点哪。两种模式都能双指捏合在本地放大画面(放大后小按钮也点得准,右下角「还原」),画面下面一排 Esc / Tab / Ctrl / Alt / Win / 方向键,Ctrl、Alt、Win 点一下会粘住,带给下一个按键或点击;键盘按钮弹出软键盘打字,中文输入法也能用。Linux 上 agent-loft 在有人连时用 x11vnc 共享当前的桌面(Xorg 会话;只听 127.0.0.1、随机端口、每次随机密码,需要 `sudo apt install x11vnc`),没人连着 30 分钟后停掉;macOS 上在 设置 → 远程控制 里改用「已有的 VNC 服务」,接系统自带的屏幕共享:填 VNC 密码,或者屏幕共享没开 VNC 密码时填 Mac 的用户名和登录密码(苹果认证,由服务端登录)。
96
97
  - 终端:新终端开在当前对话的工作目录里,可以开多个标签;`Ctrl+Shift+C` / `Ctrl+Shift+V` 复制粘贴。`` Ctrl+` `` 在对话下面拉出终端面板(高度可拖动),面板和远程控制里的是同一批终端。关掉页面、手机切到后台、断线都不结束 shell,重新打开时接着用、补上错过的输出,别的设备上也能接上;没有页面连着超过 30 分钟(设置里可改)才结束,点标签上的 × 立即结束。依赖可选的原生模块 `node-pty`:Linux 上安装时要现场编译(需要 `make`、`g++`、`python3`),没装好时终端用不了,其他功能照常。手机上单指上下滑翻看历史(在 less、vim 里是翻页),长按选中文字、接着拖动扩大选区,再点「复制」;终端下面多一排 Esc / Tab / Ctrl / Alt / 方向键 / Home / End / PgUp / PgDn / 粘贴。iOS 上软键盘弹出来时这排键会垫到键盘上面。
97
98
  - 管理员能用;成员要管理员在 设置 → 用户 里单独「开通远程控制」。终端、桌面在 设置 → 远程控制 里各有总开关。
99
+ - **微信 ClawBot**:设置 → 账号 → 微信 →「扫码连接微信」,用手机微信扫码并确认(要求微信 8.0.70 以上,「设置 → 插件」里有 ClawBot;这个功能腾讯还在逐步放量)。每个人连自己的微信,这条对话归扫码的人,用他的记忆和工具,只认扫码的这个微信号;服务端主动连向腾讯,不需要公网地址。微信里发文字或语音(要微信能转成文字),不发过程,只显示「正在输入」,结束后发结果;授权和提问是一条文字,回复数字处理(`1` 允许一次、`0` 拒绝,含义固定),网页上也能处理。`/new`、`/stop`、`/model`、`/expert` 等命令都能用。
100
+
101
+ 微信的限制(官方没公布具体数字,以下来自社区实测,agent-loft 按此处理):每条入站消息之后约能发 10 条,所以长回复每次发 3 段,回「继续」接着发,额度用完时在网页上说明;约 24 小时没在微信里说话后微信会拒绝发送,定时任务的结果可能发不过去,这时改走网页提示和系统推送。接口受理了但没给 `message_id` 时手机可能没收到(微信可能在静默限制账号),设置页和对话里会提示。Web 上说的话回复留在 Web,不花微信的额度。暂不支持群聊和收发图片、文件。
102
+
103
+ 消息会经过腾讯服务器,腾讯保留限制、拦截和终止服务的权利(《微信 ClawBot 功能使用条款》)。建议先用小号,不要反复重新扫码(有开发者反映会触发风控)。如果走了代理,让 `ilinkai.weixin.qq.com` 和 `*.cdn.weixin.qq.com` 直连。
98
104
  - **飞书账号绑定**:设置 → 账号 → 飞书账号 →「生成绑定码」,再在飞书私聊机器人发 `/bind 绑定码`(10 分钟内有效,群里发不算)。绑定后这个私聊就是你的个人会话:用你的记忆,`/sessions` 只列你的会话,`/web` 只能接上你自己的 Web 会话,管理员在 Web 上也看不到它。必须本人在两边各操作一次,管理员不能替人绑定(只能解除),否则就能借飞书读到别人的记忆。
99
105
 
100
106
  ## 安装
@@ -226,6 +232,7 @@ src/
226
232
  codex/ codex app-server 驱动
227
233
  channels/
228
234
  feishu/ 飞书:一个 FeishuBot 对应一个机器人,支持多个
235
+ weixin/ 微信 ClawBot(iLink 协议):一个 WeixinBot 对应一个用户扫码连上的微信
229
236
  web/ HTTP + WebSocket + 鉴权;terminal.ts 是终端的接口和 /ws/term,desktop.ts 是桌面的接口和 /ws/desktop(转给 VNC)
230
237
  web/ 前端(原生 JS,不需要构建)
231
238
  desktop/ 桌面端(Electron 外壳,macOS / Windows / Linux)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.78",
3
+ "version": "0.2.80",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -193,7 +193,7 @@ export class ClaudeDriver implements AgentDriver {
193
193
  };
194
194
  /** 问了、还没对上回答的:tool_use id → 那条 question */
195
195
  const asked = new Map<string, HistoryMessage>();
196
- /** 任务清单:哪条回复里改过,就在那条上挂一份改完的(页面取最后一份显示进度) */
196
+ /** 任务清单:哪条回复里改过,就在那条上挂一份改完的(页面只恢复最后一轮的进度) */
197
197
  const todos = new TodoTracker();
198
198
  for (const msg of raw) {
199
199
  if (msg.parent_tool_use_id) continue;
@@ -42,6 +42,7 @@ import {
42
42
  type CurateSettings,
43
43
  } from "../../core/memory.js";
44
44
  import { createLinkCode, listLinks, unlink, unlinkUser } from "../../core/feishu-links.js";
45
+ import { getWeixinAccount, removeWeixinAccount } from "../../core/weixin-accounts.js";
45
46
  import { purgeUserData } from "../../core/personal.js";
46
47
  import { countRecords, purgeHistory, readMeta, searchHistory, writeMeta } from "../../core/chat-history.js";
47
48
  import { curateNow, pendingCount } from "../../core/memory-curator.js";
@@ -50,6 +51,8 @@ import { isPermissionLevel, type PermissionLevel } from "../../core/permission.j
50
51
  import { agentAvailability, agentHealth, invalidateHealth } from "../../agents/health.js";
51
52
  import { installCodex, upgrade, useInstalledCodex, versionInfo } from "../../core/upgrade.js";
52
53
  import { feishuBots } from "../feishu/index.js";
54
+ import { weixinStatus } from "../weixin/index.js";
55
+ import { cancelWeixinLogin, startWeixinLogin, submitWeixinVerifyCode, weixinLoginStatus } from "../weixin/login.js";
53
56
  import { fromThisMachine, isLoopbackHost, lanAddresses, listening, rebind } from "./listen.js";
54
57
  import { beginRegistration, initRegistration, pollRegistration, qrSvg } from "../feishu/register.js";
55
58
  import { FeishuClient } from "../feishu/client.js";
@@ -531,6 +534,19 @@ function feishuLinksOf(userId: string) {
531
534
  }));
532
535
  }
533
536
 
537
+ /** 给设置页看的绑定情况:不带 token、令牌,微信号也只露一点 */
538
+ function weixinAccountView(userId: string) {
539
+ const account = getWeixinAccount(userId);
540
+ if (!account) return { linked: false };
541
+ return {
542
+ linked: true,
543
+ wechatShort: maskOpenId(account.ilinkUserId),
544
+ boundAt: account.boundAt,
545
+ lastInboundAt: account.lastInboundAt,
546
+ status: weixinStatus(userId) ?? { state: "stopped", since: account.boundAt },
547
+ };
548
+ }
549
+
534
550
  /**
535
551
  * 解除绑定后,那个人和机器人的私聊立刻不再是他的:交还给管理员的地盘,旧会话不带过去
536
552
  * (见 hub.reassignOwner)。不等他下次发消息 —— 万一他再也不发,那条对话就一直挂在他名下。
@@ -664,7 +680,8 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
664
680
  bots.add(c.channelId);
665
681
  keep.set(c.key, c);
666
682
  }
667
- if (c.busy || asking.has(c.key)) keep.set(c.key, c);
683
+ // 微信不在「最近」的分页里,但侧栏上总要有它那一行
684
+ if (c.busy || asking.has(c.key) || c.channel === "weixin") keep.set(c.key, c);
668
685
  }
669
686
  // 正开着的会话(可能是后面几页里的,重连时页面上还显示着它)
670
687
  const current = byKey.get(url.searchParams.get("current") ?? "");
@@ -1403,6 +1420,48 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
1403
1420
  return;
1404
1421
  }
1405
1422
 
1423
+ // ----- 我的微信 ClawBot -----
1424
+ if (p === "/api/account/weixin" && method === "GET") {
1425
+ sendJson(res, 200, weixinAccountView(user.id));
1426
+ return;
1427
+ }
1428
+ if (p === "/api/account/weixin" && method === "DELETE") {
1429
+ removeWeixinAccount(user.id);
1430
+ sendJson(res, 200, weixinAccountView(user.id));
1431
+ return;
1432
+ }
1433
+ if (p === "/api/account/weixin/login" && method === "POST") {
1434
+ try {
1435
+ sendJson(res, 200, await startWeixinLogin(user.id));
1436
+ } catch (err) {
1437
+ throw new HttpError(502, `连接微信失败:${err instanceof Error ? err.message : String(err)}`);
1438
+ }
1439
+ return;
1440
+ }
1441
+ const weixinLogin = /^\/api\/account\/weixin\/login\/([a-f0-9]+)(\/verify)?$/.exec(p);
1442
+ if (weixinLogin) {
1443
+ const id = weixinLogin[1]!;
1444
+ if (weixinLogin[2] && method === "POST") {
1445
+ const body = await readJsonBody<{ code?: unknown }>(req);
1446
+ const code = String(body.code ?? "").trim();
1447
+ if (!/^\d{1,12}$/.test(code)) throw new HttpError(400, "请输入手机微信上显示的数字");
1448
+ if (!submitWeixinVerifyCode(id, user.id, code)) throw new HttpError(409, "现在不需要输入数字,或者这次连接已经结束");
1449
+ sendJson(res, 200, { ok: true });
1450
+ return;
1451
+ }
1452
+ if (!weixinLogin[2] && method === "GET") {
1453
+ const login = weixinLoginStatus(id, user.id);
1454
+ if (!login) throw new HttpError(404, "这次连接已结束,请重新开始");
1455
+ sendJson(res, 200, login);
1456
+ return;
1457
+ }
1458
+ if (!weixinLogin[2] && method === "DELETE") {
1459
+ cancelWeixinLogin(id, user.id);
1460
+ sendJson(res, 200, { ok: true });
1461
+ return;
1462
+ }
1463
+ }
1464
+
1406
1465
  // 修改自己的登录名:只允许改名称,沿用现有设备和会话归属。
1407
1466
  if (p === "/api/account" && method === "PATCH") {
1408
1467
  const body = await readJsonBody<{ name?: unknown }>(req);
@@ -9,8 +9,8 @@ export type Cursor = { at: number; key: string };
9
9
  export type Page = { conversations: ConversationInfo[]; next: Cursor | null };
10
10
  type Tree = { root: ConversationInfo; convs: ConversationInfo[]; at: number };
11
11
 
12
- /** 最近:飞书以外的会话(飞书单独按机器人分组) */
13
- export const inRecent = (c: ConversationInfo): boolean => c.channel !== "feishu";
12
+ /** 最近:飞书、微信以外的会话(飞书按机器人分组,微信单独一行) */
13
+ export const inRecent = (c: ConversationInfo): boolean => c.channel !== "feishu" && c.channel !== "weixin";
14
14
  /** 项目:Web 会话按工作目录分组 */
15
15
  export const inDir = (dir: string) => (c: ConversationInfo): boolean => c.channel === "web" && c.cwd === dir;
16
16
 
@@ -12,6 +12,7 @@ import { config, onConfigChange } from "../../core/config.js";
12
12
  import { parseCommand } from "../../core/commands.js";
13
13
  import { GLOBAL_ALWAYS_DENIED, hub, type EventEnvelope } from "../../core/hub.js";
14
14
  import { interactions, type Interaction } from "../../core/interactions.js";
15
+ import { weixinEvents } from "../weixin/events.js";
15
16
  import { getConversation } from "../../core/store.js";
16
17
  import { taskEvents } from "../../core/tasks.js";
17
18
  import { skillEvents } from "../../core/skills.js";
@@ -309,6 +310,10 @@ type Notice = { title: string; body: string; tag: string };
309
310
  */
310
311
  function notify(key: string, notice: Notice): void {
311
312
  if (!isWebConv(key)) return;
313
+ deliverNotice(key, notice);
314
+ }
315
+
316
+ function deliverNotice(key: string, notice: Notice): void {
312
317
  for (const client of clients) if (canSeeKey(client.user, key)) send(client, { t: "notice", key, ...notice });
313
318
  if (!hasSubscriptions() || watching(key)) return;
314
319
  // 只推给这条会话的主人(没记主人的订阅算迁移出来的那个管理员的)
@@ -319,6 +324,10 @@ function notify(key: string, notice: Notice): void {
319
324
  }, (endpoint, owner) => !foregroundDevice(endpoint, owner ?? legacy));
320
325
  }
321
326
 
327
+ function onWeixinUndelivered({ key, body }: { key: string; body: string }): void {
328
+ deliverNotice(key, { title: "微信 · 消息没发出去", body: plainPreview(body), tag: `weixin:${key}` });
329
+ }
330
+
322
331
  function pushEvent(env: EventEnvelope): void {
323
332
  const ev = env.ev;
324
333
  if (ev.type !== "result" && ev.type !== "error") return;
@@ -581,6 +590,8 @@ export async function startWeb(): Promise<void> {
581
590
  expertEvents.on("changed", broadcastExperts);
582
591
  terminalEvents.on("changed", broadcastTerminals);
583
592
  userEvents.on("changed", broadcastUsersChanged);
593
+ // 微信发不出去的提醒:微信会话平时不走推送(微信自己会响),只有这时才推
594
+ weixinEvents.on("undelivered", onWeixinUndelivered);
584
595
  watchTerminalAccess();
585
596
  // 设置里关了远程桌面 / 换了桌面来源:连着的断开,自己起的 x11vnc 停掉(下次连时按新设置起)
586
597
  stopWatchingRemote = onConfigChange((next, prev) => {
@@ -630,6 +641,7 @@ export async function stopWeb(): Promise<void> {
630
641
  expertEvents.off("changed", broadcastExperts);
631
642
  terminalEvents.off("changed", broadcastTerminals);
632
643
  userEvents.off("changed", broadcastUsersChanged);
644
+ weixinEvents.off("undelivered", onWeixinUndelivered);
633
645
  stopWatchingRemote?.();
634
646
  stopWatchingRemote = null;
635
647
  closeTerminalClients();