Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenMate

OpenMate 是一组开源(MIT)的 [Persona](https://github.com/nwverse/persona) 扩展,把聊天软件接进 Persona:私聊和群消息进收件箱和知识库,Persona 的助手和 Agent 可以在聊天软件里替你出面。助手以你身份主动发的每一条消息都要你先在手机上确认。有四种消息不再逐条确认,发出后会记进 Persona 的“以你身份发出的消息”记录(发出后扩展立刻退出等少数情况下,可能缺记一条):你自己发起的 `/agent` 请求的回复;你勾选的群里有人真正 @ 你时的自动代答;飞书文档评论里 @ 你时的文档代答(默认关闭,要单独打开);Persona 渠道在你指定的一个会话里的回答和问题(默认没有指定,一条都不发)。
OpenMate 是一组开源(MIT)的 [Persona](https://github.com/nwverse/persona) 扩展,把聊天软件接进 Persona:私聊和群消息进收件箱和知识库,Persona 的助手和 Agent 可以在聊天软件里替你出面。助手以你身份主动发的每一条消息都要你先在手机上确认。有五种消息不再逐条确认,发出后会记进 Persona 的“以你身份发出的消息”记录(发出后扩展立刻退出等少数情况下,可能缺记一条):你自己发起的 `/agent` 请求的回复;你勾选的群里有人真正 @ 你时的自动代答;飞书文档评论里 @ 你时的文档代答(默认关闭,要单独打开);Persona 渠道在你指定的一个会话里的回答和问题(默认没有指定,一条都不发);飞书 Agent 工作台在你指定的群里发的状态、回复和问题(默认关闭)。

第一个扩展是**飞书**(`openmate-feishu`)。第二个是**微信**(`openmate-wechat`,一期做 `/agent`、群里自动代答和收图片等媒体,见下文)。钉钉以后再做。

Expand Down Expand Up @@ -31,6 +31,7 @@ OpenMate 是一组开源(MIT)的 [Persona](https://github.com/nwverse/person
| 发送身份选项(`outbound_send`) | Persona 助手要往飞书会话发消息时,确认卡或发送人选择里多一个“以你本人身份发(飞书 · OpenMate)”的选项;还是要你在手机上选定并确认,OpenMate 才发,绝不在没确认时发出。会话按开放平台的 `oc_…` id 认:飞书在会话记录里带了这个 id,OpenMate 把它和自己的会话对上(只认你最近打开过、收到过消息的会话,认不出就显示为不可选并写明原因)。发送只用确认时那个账号,换了账号就不发;同一个请求只发一次,结果不确定时如实说不确定、不重发。要 @ 的人在这个会话的成员里按 id 或唯一的名字找,做成真 @,找不到或重名就不可选;不能 @所有人。要回到原话题里但认不出原消息时不可选(不会发成一条孤立的新消息);只是引用回复而认不出原消息时,作为新消息发并在选项上注明。不认识这项能力的旧版 Persona 会忽略它,其余功能照常 |
| `/agent` | 你自己在飞书里发 `/agent …`,或者发一条真正 @ 你自己的消息(`@自己 …`,@ 后面的话就是要办的事;不以“/”开头,群里别的机器人不会当成自己的命令;设置“@自己 也交给 Agent”默认打开,可关),交给 Agent 处理并以你的身份回复到提问的地方(富文本消息:标题行之后开头写 `/agent` 也算;里面的内嵌图片最多 4 张、每张 3 MB 以内随请求一起交给 Agent 看):话题里问的回到话题;话题里勾了“也发到群里”的,回复同样回到话题、也发到群里,并引用这条请求;群聊主界面问的(包括引用回复),在主界面引用回复这条请求;私聊里是引用回复,AI 标记放在回复最后一行(话题折叠时直接显示答案;设置“AI 标记位置”可改回第一行);同一话题里接着发会进同一个会话;助手已经把活派给 Agent(建了待办、Agent 还在做)时,话题里你自己的追问直接转给那个 Agent,话题里回一句“已转给正在做这件事的 Agent”,结果照常经助手回到话题(写“问 Persona”“问助手”、任务结束了、Agent 不在了,就照旧交给助手;设置“话题里的追问直接转给干活的 Agent”可关);`/stop`、`/停止`、`/停` 可以停下。请求上的表情说明状态:🤔 处理中,✅ 做完了,❌ 失败或超时(停下就撤掉 🤔;三个表情都能在设置里换)。中途进度只占一条消息、原地更新,最终结果另发一条新回复(会提醒你),那条进度消息标成已完成。助手把活派给 Agent(建了待办)后还没给最终回复就结束了这一轮时,请求不会自动收尾:🤔 留着,这一轮最后说的话只作为进度消息显示、不当成答案;最终回复来了才标 ✅;它派出的待办都结束了(或过了 24 小时)就把 🤔 换成 ✅,不再另发消息;读不到待办时也按还没结束算。回复默认就是答给提问的人;要真正 @ 群里的人或机器人,回复工具的 `at` 只收 `matefeishu_members` 核实过的 id 和名字,正文里打的「@名字」只是普通文字。回复不经手机确认,每一条都记进 Persona 的“以你身份发出的消息”记录,所以安装时 Persona 会提示这个扩展会“以你的身份发消息” |
| Persona 渠道 | 在 Persona 的“设置 › 渠道”里显示为“飞书(OpenMate)”(绑定、账号、开关跟着连接器走),不用装官方 larkx 也能把飞书当成 Persona 的一个渠道。只在你指定的一个会话里生效:扩展设置里的“Persona 渠道会话”填会话 id(问 Persona 助手“飞书里 xx 群的 chat id”即可,要是这个扩展收到过消息的会话),请用只有你自己的群;默认留空,留空时渠道什么都不收也不发。那个会话就是你和 Persona 的对话,相当于官方飞书机器人的私聊:你自己说的每一句都交给 Persona 统一的渠道流程(开头的 `/agent` 可写可不写;默认进主对话,可在“设置 › 渠道”改目标;`/new`、`/status` 等 Persona 渠道命令也能用),回答以你的身份回到提问处(话题里问的回到话题,主界面问的引用回复);`/stop`、`/停止`、`/停` 打断渠道正在跑的对话。Agent 要你回答或批准时(渠道驱动的对话,或“设置 › 渠道”里打开了“所有 Agent 的问题”),问题以你的身份发到这个会话,直接回复就是作答;你在 App 等别处答了,这条问题会自动撤回。别的会话里的 `/agent`、进度原地更新、自动代答、话题追问转给 Agent 都和原来一样 |
| Agent 工作台 | 默认关闭。扩展设置里打开“Agent 工作台”并填“工作台话题群”(建议新建一个只有你自己的话题群,不能和“Persona 渠道会话”同一个)后,Persona 管着的每个 Agent(各台电脑上的 Claude Code、Codex 等,经 hub 的 `agents.read` 读)在群里有自己的一个话题:第一条消息原地显示状态(🟡 执行中、🟠 等你确认、🟢 待命、⚫ 已结束)、项目、分支、电脑、最近指令和更新时间;你在话题里说的话直接发给这个 Agent(`agents.control`),这一轮的回复回到话题里,长回复按字数和 UTF-8 字节切成几条,代码块跨条自动闭合续上,格式发不出时改发纯文本。另有两个默认关闭的开关:“工作台:话题里作答”把 Agent 等你回答或批准的问题发到它的话题里,回复编号、y / n 或直接写回答就是作答,在别处答了自动撤回,Persona 不让扩展替你批准的卡片会提示去 App 里处理;“工作台:指令不过模型”让 `/ls`、`/tail [行数]`(看 Agent 终端的最后几行)、`/stop` 由扩展直接回答。不用 tmux,不装 Claude Code Hook,不改任何电脑上的 `~/.claude` 或 `~/.codex`;关着时 `/agent`、自动代答、收件箱、渠道都和原来一样 |
| 历史补收 | 首次登录和每次重连后补收最近会话里漏掉的消息。普通群话题里的回复(比如机器人在话题里回的卡片)不在群聊主界面里:话题推送和话题更新通知都会收;用 `matefeishu_messages` 按话题读时,会先从飞书补读这个话题最新的回复 |
| 卡片 | 机器人发的卡片读成标题加正文:新版卡片(JSON 2.0)不再读成“Upgrade to the latest app version…”,按钮不算,链接只留文字(不留地址和参数),卡片里 @ 你算 @我 |

Expand Down Expand Up @@ -118,6 +119,7 @@ OpenMate 是一组开源(MIT)的 [Persona](https://github.com/nwverse/person
- 群里自动代答:只在你勾选的群、有人真正 @ 你时回复,每群每天有上限。
- 文档代答:飞书文档评论里 @ 你时回复,默认关闭,要在设置里单独打开;它经 lark-cli 发出,发之前核对 lark-cli 登录的账号和飞书登录的账号同名(目前只能比对显示名,同名的另一个账号拦不住)。
- Persona 渠道:只发到你在设置里指定的“Persona 渠道会话”(默认没有,就一条都不发),内容是 Persona 对你在那里说的话的回答、Agent 要你回答或批准的问题和 Persona 的提示;在“设置 › 渠道”里打开“通知”“同步”后还有推送。
- 飞书 Agent 工作台:默认关闭;打开后只发到你指定的“工作台话题群”,内容是各个 Agent 的状态(原地编辑)、你在话题里发给 Agent 的话的回复,以及(打开“话题里作答”后)Agent 等你确认的问题和(打开“指令不过模型”后)指令的结果。

## 开发

Expand All @@ -141,7 +143,7 @@ tests/ 用假的平台后端和假的 hub 驱动完整

OpenMate is a set of open-source (MIT) [Persona](https://github.com/nwverse/persona) extensions that bridge chat apps
into Persona: direct and group messages flow into the Inbox and knowledge base, and Persona's assistant and Agents can
answer in the chat app as you. Every message the assistant sends as you is confirmed on your phone first. Four kinds
answer in the chat app as you. Every message the assistant sends as you is confirmed on your phone first. Five kinds
of message go out unconfirmed, and are recorded in Persona's sent-as-user ledger after they go (one can be missing when
the extension exits right after sending; the connector declares `sends_as_user`):
the replies to your own `/agent` requests (on Feishu also a message of yours that really @-mentions yourself,
Expand All @@ -151,7 +153,9 @@ document comment that @-mentions you (through lark-cli, only while lark-cli's ac
is not told apart yet); and what Persona's channel (listed under Settings › Channels) says in the one chat you
name in the setting `channel_chat` (your conversation with Persona, as a bot's direct chat is): the answers to what you say there, and the questions and
approvals an Agent waits on (taken back in Feishu once answered elsewhere); no chat is named by default, and then
nothing is sent. The first extension is Feishu / Lark (`openmate-feishu`, connector
nothing is sent; and, off unless you turn it on, the Feishu Agent desk (`workbench`) in the one group you name
(`workbench_chat`): one topic per Agent with its status edited in place, the answers to what you say in a topic, and
(with `workbench_asks`) the questions an Agent waits on, or (with `workbench_commands`) what `/ls`, `/tail` and `/stop` give. The first extension is Feishu / Lark (`openmate-feishu`, connector
`matefeishu`); the second is WeChat (`openmate-wechat`, connector `matewechat`: phase one is `/agent`, answering
real @-mentions in the groups you mark, and pictures, voice notes, videos, files and forwarded chat records fetched
into local files the assistant can read, over this repository's `native/matewechat-native`, built on thisnick/agent-wechat's
Expand Down
3 changes: 3 additions & 0 deletions core/openmate_core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ def on_message(self, row: dict, epoch: Optional[int] = None) -> None:
# the 「Persona 渠道会话」's: handed to Persona's channel flow (channel.py), whether /agent is on or not; its
# echoes are told by the channel's own record of what was sent there, not /agent's text cache
return
workbench = getattr(self.app, "workbench", None)
if workbench is not None and workbench.take(row, body, epoch):
return # a line in an Agent's topic of the Agent 工作台 (workbench.py; off unless the user turned it on)
if self._echo(text) or self._own_echo(row) or not self.enabled:
return
if body.lower() in STOP_WORDS:
Expand Down
6 changes: 6 additions & 0 deletions core/openmate_core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from . import views
from .agent import AgentRunner
from .channel import ChannelBridge
from .workbench import Workbench
from .ui import UI, ChatsToday
from .backend import Account, BackendError, Chat, CredentialsExpired, Message, SendRejected
from .events import Changed
Expand Down Expand Up @@ -180,6 +181,7 @@ def __init__(self, platform: Platform, timing: Optional[Timing] = None, backend_
self.changed: Optional[Changed] = None
self.agent: Optional[AgentRunner] = None
self.channel: Optional[ChannelBridge] = None # Persona's 渠道 (channel.py), made at the start with the agent
self.workbench: Optional[Workbench] = None # Agent 工作台 (workbench.py), off unless the user turned it on
self.people: Optional[People] = None # who is a bot (made at the start, with the store)
self._avatars_by: Optional[threading.Thread] = None # the round asking the service for chats' pictures
self._avatars_tried: Dict[str, float] = {} # chat id → when its picture was last asked for (monotonic)
Expand Down Expand Up @@ -355,6 +357,7 @@ def _startup(self) -> None:
self.agent.enabled = False
log.info("/agent and 代答 are off here (%s)", "the connector is off" if not self.connector_on else "a member hub")
self.channel = ChannelBridge(self)
self.workbench = Workbench(self)
self.people = People(self)
self._owner = self.store.meta_get("account_id") or "" # whose this store is
if self.backend is not None:
Expand All @@ -372,6 +375,7 @@ def _startup(self) -> None:
self._start_link(restore=True) # off: no link, nothing received or sent in the user's name
self.agent.start()
self.channel.start()
self.workbench.start()
if self.backend is not None and getattr(self.backend, "done_marks", False):
threading.Thread(target=self._done_loop, name="openmate-done", daemon=True).start()
self._ui().update_badge() # the hub forgets an extension's badges when it restarts
Expand Down Expand Up @@ -405,6 +409,8 @@ def shutdown(self) -> None:
self.agent.stop()
if self.channel is not None:
self.channel.stop()
if self.workbench is not None:
self.workbench.stop()
if self.changed is not None:
self.changed.stop()
if self.backend is not None:
Expand Down
Loading
Loading