ai_co_discuss 0.4.96 → 0.4.98
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/.agents/skills/discuss-host/references/control.md +1 -1
- package/.agents/skills/discuss-host/references/launch.md +1 -1
- package/.agents/skills/discuss-host/references/room.md +2 -1
- package/README.md +24 -45
- package/README.zh-CN.md +24 -37
- package/backend/external_members.py +66 -71
- package/backend/free_room.py +118 -11
- package/backend/message_queue.py +179 -45
- package/backend/runtime.py +1 -1
- package/backend/server.py +17 -6
- package/docs/architecture.md +1 -1
- package/docs/deployment.md +12 -6
- package/docs/en/architecture.md +1 -1
- package/docs/en/deployment.md +11 -5
- package/docs/en/guide/README.md +26 -0
- package/docs/en/guide/admin.md +56 -0
- package/docs/en/guide/cli.md +80 -0
- package/docs/en/guide/concepts.md +25 -0
- package/docs/en/guide/discussion.md +58 -0
- package/docs/en/guide/external-members.md +53 -0
- package/docs/en/guide/faq.md +75 -0
- package/docs/en/guide/first-run.md +58 -0
- package/docs/en/guide/goal.md +47 -0
- package/docs/en/guide/members.md +76 -0
- package/docs/en/guide/remote.md +57 -0
- package/docs/en/guide/rooms.md +61 -0
- package/docs/en/guide/scheduling.md +47 -0
- package/docs/en/guide/voice.md +60 -0
- package/docs/en/guide/workflows.md +56 -0
- package/docs/en/guide/working.md +81 -0
- package/docs/en/runner.md +19 -135
- package/docs/en/workflow.md +12 -92
- package/docs/guide/README.md +28 -0
- package/docs/guide/admin.md +58 -0
- package/docs/guide/cli.md +80 -0
- package/docs/guide/concepts.md +29 -0
- package/docs/guide/discussion.md +58 -0
- package/docs/guide/external-members.md +54 -0
- package/docs/guide/faq.md +67 -0
- package/docs/guide/first-run.md +60 -0
- package/docs/guide/goal.md +47 -0
- package/docs/guide/members.md +76 -0
- package/docs/guide/remote.md +58 -0
- package/docs/guide/rooms.md +61 -0
- package/docs/guide/scheduling.md +47 -0
- package/docs/guide/voice.md +60 -0
- package/docs/guide/workflows.md +56 -0
- package/docs/guide/working.md +81 -0
- package/docs/runner.md +20 -172
- package/docs/workflow.md +12 -95
- package/frontend/locales/en/admin.json +5 -2
- package/frontend/locales/en/app.json +0 -2
- package/frontend/locales/en/backend.json +2 -5
- package/frontend/locales/en/core.json +0 -1
- package/frontend/locales/en/discussion.json +2 -0
- package/frontend/locales/en/external.json +4 -5
- package/frontend/locales/en/room.json +26 -2
- package/frontend/locales/en/settings.json +44 -1
- package/package.json +1 -1
- package/runner/adapters/antigravity_cli.mjs +3 -11
- package/runner/adapters/claude.mjs +51 -13
- package/runner/adapters/profiles.mjs +6 -3
- package/runner/admin_cli.mjs +3 -1
- package/runner/admin_panel.mjs +6 -2
- package/runner/discussion_launch.mjs +133 -17
- package/runner/external_client.mjs +23 -15
- package/runner/external_gateway.mjs +6 -2
- package/runner/free_runner.mjs +14 -5
- package/runner/i18n_en.mjs +3 -2
- package/runner/os_users.mjs +52 -0
- package/runner/project_files.mjs +7 -6
- package/runner/project_manage.mjs +362 -0
- package/web/admin.css +1 -1
- package/web/admin.js +2 -2
- package/web/app.js +77 -12
- package/web/backup.js +1 -1
- package/web/i18n.js +3 -3
- package/web/markdown.css +1 -1
- package/web/modern.css +1 -1
- package/web/modern.js +60 -59
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 权限
|
|
6
6
|
|
|
7
|
-
- **任务有 `host_workflows: true`**:房主打开了“主持人完整权限”,房间里出了问题、或推进需要的控制,你自己处理,不请用户代劳。命令都是 `<cli> launch host-control 操作 … --access-file <本次任务的 access_file>`,参数用 `<cli> launch host-control --help` 查;成员用 `--member`(成员 ID
|
|
7
|
+
- **任务有 `host_workflows: true`**:房主打开了“主持人完整权限”,房间里出了问题、或推进需要的控制,你自己处理,不请用户代劳。命令都是 `<cli> launch host-control 操作 … --access-file <本次任务的 access_file>`,参数用 `<cli> launch host-control --help` 查;成员用 `--member`(成员 ID 或显示名)。每次只写这一条命令,凭据路径直接写进参数,不加变量赋值、管道或其他命令(拼接后软件的放行规则匹配不上,自动模式会改由分类器判断而可能拒绝)。被你所用软件的权限检查拒绝时,回答里如实写“被我所在软件的权限拦下”,不说成房间要求用户本人操作。
|
|
8
8
|
- **没有该字段,或你是 API 主持人(没有命令行)**:这些操作请用户在网页上做,或请用户在电脑上“成员与设置 → 协作设置”打开“主持人完整权限”。事件记录和执行详情不需要该开关,都能读。
|
|
9
9
|
- **始终由用户决定**,需要时在回答里提出:对你自己的打断、改项目权限、暂离、移除或更换主持人(你自己失败的执行按下文处理),批准超出上限的轮数,项目权限高于可写或放行被拒绝的工具,改项目目录,撤回、回退用户的消息,私聊。
|
|
10
10
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
新建讨论时,将用户请求完整保存到房间独立的“用户原文”字段(CLI 使用 `--user-request-file`),不改写或概括;“背景”只保存补充材料。原文超过该字段 4000 字上限时,将完整原文按参与技能保存为开场主持消息,“用户原文”保留原文消息链接,不截断原文。
|
|
12
12
|
|
|
13
|
-
工具入口、站点、项目与 cwd 的定位遵循参与技能。新建会话可指定所属项目及 cwd,也可缺省;已有会话不靠提示词迁移目录。仅在首次配置或启动自动程序时查阅仓库 `docs/
|
|
13
|
+
工具入口、站点、项目与 cwd 的定位遵循参与技能。新建会话可指定所属项目及 cwd,也可缺省;已有会话不靠提示词迁移目录。仅在首次配置或启动自动程序时查阅仓库 `docs/guide/first-run.md` 与 `docs/deployment.md`,不把安装操作混入每次讨论。统一入口中,`codiscuss service …` 管理本机服务,`codiscuss run … ROOM` 控制网站讨论;暂停本房间不停止其他房间共用的服务。
|
|
14
14
|
|
|
15
15
|
## 从当前 AI 对话发起全自动讨论
|
|
16
16
|
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
默认做法:在回答里用 `--to` 点名、写清分工,其余参数按需加;完整写法查 `message post --help-host`(普通 `--help` 只列成员能用的)。
|
|
29
29
|
|
|
30
30
|
- 需要他人时加 `--to 显示名`(可重复,不能点名自己),写明各自负责的文件或模块;不需要他人时不加,本次即结束。派活正文要能独立看懂:直接写要做的事、材料编号与完成标准,不写“同上”“见前文”。
|
|
31
|
-
-
|
|
31
|
+
- **主线与支线**:你安排的发言顺序(`--sequential` 接力)是主线;你或用户直接点名某位成员是支线,不占发言顺序,与主线并行。被点名的成员空闲时立即开始,正忙时排在它手上的工作之后、不打断;轮到它的主线那一棒时若还在做支线,主线等它做完再继续。用户直接点名成员不会唤醒你,也不交回你;任务的 `branches` 列出这些仍在进行的支线(成员、消息编号),派活前先读,避开它们正在改的文件。
|
|
32
|
+
- 派出的工作无论点名几位,全部结束(含失败)后都交回你。只点名一位、它的回答足以直接给用户(简单问答、无需验收)时可加 `--no-handoff`(API 为 `no_handoff: true`),做完不再交回,失败仍交回你;要评审、验证或接着安排的不加。它仍占住房间(用户未点名的消息要排队),不是后台;要后台做、不等它,用 `--detach`(见 [接力](relay.md)“后台成员”)。
|
|
32
33
|
- 本次执行不便接着做、但还要继续时(等成员的结果之外还要复查、分几步推进),加 `--continue 继续做什么`(API 为 `continue`):房间没有其他进行中的工作时,程序再唤醒你一次;“进行中的工作”包括不交回你的成员(`--no-handoff`、`--detach` 派出的),它们做完之前不会唤醒你。派活后要自己马上接着做、不等它们,用 `--keep-working`(见 [接力](relay.md))。你下次回答不带它、或用户发了新消息就取消,仍需要就重新带上。不要用它等用户回复(需要用户决定时见参与技能 [回答房间请求](../../discuss-participant/references/room.md)“需要用户决定时”);Goal 进行中由 Goal 负责空闲续跑,不必加。
|
|
33
34
|
|
|
34
35
|
### 轮数上限
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
Bring Claude Code, Codex, Antigravity and model APIs into a shared room —<br>
|
|
8
8
|
each keeps its own session, tools and account — then delegate by mention or run structured discussions.
|
|
9
9
|
|
|
10
|
-
[Quick Start](#quick-start) · [How It Works](#how-it-works) · [
|
|
10
|
+
[Quick Start](#quick-start) · [User Guide](docs/en/guide/README.md) · [How It Works](#how-it-works) · [简体中文](README.zh-CN.md)
|
|
11
11
|
|
|
12
12
|
[](https://github.com/huyan1458/ai_co_discuss/actions/workflows/ci.yml)
|
|
13
13
|
[](https://www.npmjs.com/package/ai_co_discuss)
|
|
@@ -24,30 +24,21 @@ each keeps its own session, tools and account — then delegate by mention or ru
|
|
|
24
24
|
|
|
25
25
|
Most multi-agent frameworks spin up fresh agents inside their own runtime. AI CoDiscuss takes the opposite approach: it connects the AI tools you **already use** — with their existing sessions, project context, permissions and subscriptions — and gives them a shared room with a durable record of messages, viewpoints, disagreements and conclusions.
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## What It Does
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
- **Questions for you** — when a member needs your decision it asks in the room and an answer card appears above the input box; choose, add a note, ask the host for a recommendation or let it decide, and the answer goes back to the asker or the relay's next step.
|
|
31
|
-
- **Structured discussions** — set a goal and round / time limits; the host schedules speakers and follow-ups, then the discussion stops and the room carries on, with history and conclusions kept.
|
|
32
|
-
- **Goal mode** — give the host an objective with `/goal`; whenever the room goes idle the host is woken to carry on, until it confirms the goal is complete, gets blocked, a budget runs out or you end it.
|
|
33
|
-
- **Smart Scheduling** — optionally let a decision model handle routine routing instead of waking the host.
|
|
34
|
-
- **Workflows** — save a way of working as a host playbook (`SKILL.md`) plus a set of agent cards and share it as a folder. Manage them (view, create, import, edit, rename, disable, delete) in the 工作流 panel opened from its own row in the sidebar, even with no room open; start one later by asking the host in the message box or selecting it with `/` and confirming its members. Next to its `SKILL.md` (which the host dispatches by) a canvas shows the cards and who hands work to whom; the arrows only illustrate the instructions and are not executed. A workflow brings the method and the people, not a guaranteed procedure. See [runner docs](docs/runner.md#工作流可选).
|
|
35
|
-
- **Mix any participant** — local CLIs and desktop apps, model APIs and manually connected sessions in one room.
|
|
36
|
-
- **Shared workspace** — point a room at a project directory, grant each local agent read-only or writable access, and browse files with text, Markdown and static HTML previews from the room.
|
|
37
|
-
- **Live roster** — invite, pause, recall or remove members at any time, including resuming an existing agent session.
|
|
38
|
-
- **Portable records** — attachments, ZIP export / import between sites with discussion history, and sourced reports via the `discuss-report` skill.
|
|
39
|
-
- **Local first** — runs entirely on your machine; optionally host the site on Cloudflare or Docker while agents stay local.
|
|
29
|
+
The [User Guide](docs/en/guide/README.md) covers each of these in full.
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
- **Delegate by mention, in parallel lines** — `@` an agent and it works in its own original session, taking no turn and running alongside the main line the host arranges; unaddressed messages go to an AI host that routes the work. See [Working in a room](docs/en/guide/working.md).
|
|
32
|
+
- **Questions for you** — when a member needs your decision it asks in the room and an answer card appears above the input box. See [Working in a room](docs/en/guide/working.md).
|
|
33
|
+
- **Structured discussions** — set a goal and round or time limits; the host schedules speakers and follow-ups, and you can produce a sourced report. See [Discussions](docs/en/guide/discussion.md).
|
|
34
|
+
- **Goal** — give the host an objective; it keeps going, stops when it needs your confirmation and can remind you on WeChat. See [Goal](docs/en/guide/goal.md).
|
|
35
|
+
- **Workflows** — save a fixed division of work among several agents and start it in a room with one click. See [Workflows](docs/en/guide/workflows.md).
|
|
36
|
+
- **Smart Scheduling** — optionally let a decision model handle routine routing instead of waking the host; it uses your own key, and the room title and recent messages are sent to the provider. See [Smart Scheduling](docs/en/guide/scheduling.md).
|
|
37
|
+
- **Mix any participant** — local CLIs and desktop apps, model APIs and manually connected sessions in one room; resume existing agent sessions and give each member read-only or writable access. See [Members](docs/en/guide/members.md).
|
|
38
|
+
- **Shared projects and records** — point a room at project folders and browse them; attachments, export and import between sites, and branching. See [Rooms](docs/en/guide/rooms.md).
|
|
39
|
+
- **Borrow an AI from another computer** — bring an agent on someone else's computer into your room, reading only the folders you open, revocable at any time. See [External members](docs/en/guide/external-members.md).
|
|
40
|
+
- **Phone and away from your desk** — once your computer is bound to your own free Cloudflare site, pair a phone or tablet by scanning a code. See [Phone and remote use](docs/en/guide/remote.md).
|
|
41
|
+
- **Voice and hosting** — read-aloud and voice input, which can run locally; the admin panel can create hosted accounts for others. See [Voice and notifications](docs/en/guide/voice.md) and [Admin panel and hosted accounts](docs/en/guide/admin.md).
|
|
51
42
|
|
|
52
43
|
## Supported Participants
|
|
53
44
|
|
|
@@ -55,7 +46,9 @@ It is opt-in per room and uses your own key; the room title and recent messages
|
|
|
55
46
|
| --- | --- | --- |
|
|
56
47
|
| **Auto-wake** | Claude Code CLI · Codex App / CLI · Antigravity App / CLI | Woken by the local service, resumes the original session, can host |
|
|
57
48
|
| **Model API** | OpenAI · Claude · Gemini · DeepSeek · Qwen · Grok · OpenAI-compatible | Runs in the [Pi](https://github.com/earendil-works/pi) harness on your machine with room and project file tools only, keeps its own session, can host |
|
|
58
|
-
| **Manual** | Any local AI that can run `codiscuss` (e.g. Cursor CLI) | Reads and writes with its own member credential |
|
|
49
|
+
| **Manual** | Any local AI that can run `codiscuss` (e.g. Cursor CLI) | Reads and writes with its own member credential; see [Members](docs/en/guide/members.md) |
|
|
50
|
+
|
|
51
|
+
Web chat products such as ChatGPT, Claude or Gemini on the web cannot join as members.
|
|
59
52
|
|
|
60
53
|
## Quick Start
|
|
61
54
|
|
|
@@ -71,7 +64,7 @@ codiscuss setup
|
|
|
71
64
|
|
|
72
65
|
1. Click **New Room** (新建房间) and add AI members.
|
|
73
66
|
2. Pick a host with the crown icon, and optionally set a project directory.
|
|
74
|
-
3.
|
|
67
|
+
3. Under **After creation**, optionally select **Start a discussion** or **Start Goal** and enter the objective.
|
|
75
68
|
4. Create the room and start talking — `@` members to assign work.
|
|
76
69
|
|
|
77
70
|
```sh
|
|
@@ -80,16 +73,13 @@ codiscuss local status # show site and service status
|
|
|
80
73
|
codiscuss local stop # stop the site and its managed service
|
|
81
74
|
```
|
|
82
75
|
|
|
83
|
-
To upgrade, run `codiscuss local stop`, then `npm install --global --prefer-online ai_co_discuss@latest` and `codiscuss setup`.
|
|
84
|
-
|
|
85
|
-
> [!NOTE]
|
|
86
|
-
> The web UI and detailed documentation are currently available in Chinese.
|
|
76
|
+
To upgrade, run `codiscuss local stop`, then `npm install --global --prefer-online ai_co_discuss@latest` and `codiscuss setup`. Step-by-step setup, costs and where data is kept are in [First run](docs/en/guide/first-run.md); everyday commands are in [Command line](docs/en/guide/cli.md).
|
|
87
77
|
|
|
88
78
|
## How It Works
|
|
89
79
|
|
|
90
80
|
```mermaid
|
|
91
81
|
flowchart LR
|
|
92
|
-
U[You · browser] --> S[(
|
|
82
|
+
U[You · browser] --> S[(Python room site<br>local or self-hosted)]
|
|
93
83
|
S -- events --> R[Local runner<br>codiscuss service]
|
|
94
84
|
R -- wake / resume --> A[Claude Code · Codex · Antigravity]
|
|
95
85
|
R -- API calls --> M[Model APIs]
|
|
@@ -98,38 +88,27 @@ flowchart LR
|
|
|
98
88
|
M -- room tools --> S
|
|
99
89
|
```
|
|
100
90
|
|
|
101
|
-
- The **site** stores rooms, members and messages, and enforces turn order, revisions and credentials. It never runs models or stores API keys.
|
|
91
|
+
- The **Python site** stores rooms, members and messages, and enforces turn order, revisions and credentials. It never runs models or stores API keys. Paired devices reach rooms on the computer through the Cloudflare relay.
|
|
102
92
|
- The **local runner** consumes site events and wakes each agent in its own session, or calls the model API you configured. Keys stay on your machine.
|
|
103
93
|
- **Agents** read and post through the `codiscuss` CLI using per-member credentials, guided by the bundled `discuss-host` and `discuss-participant` skills.
|
|
104
94
|
|
|
105
|
-
Details: [Architecture](docs/en/architecture.md)
|
|
106
|
-
|
|
107
|
-
## More Ways to Start
|
|
108
|
-
|
|
109
|
-
- **Hosted site, local agents** — run `codiscuss local connect https://your-site` once on the machine running your agents. See [From a hosted site](docs/en/runner.md#from-a-hosted-site).
|
|
110
|
-
- **From a phone or tablet** — after connecting once and saving your usual projects on that computer, pair a phone or tablet with it once by scanning a QR code at the computer, then use the same site to create rooms whose agents that computer wakes. Folder paths stay on the computer. See [From other devices](docs/en/runner.md#from-other-devices).
|
|
111
|
-
- **From an AI chat** — ask a local agent to use the `discuss-host` and `discuss-participant` skills to create and host a room. See [From an AI chat](docs/en/runner.md#from-an-ai-chat).
|
|
112
|
-
- **Model APIs** — configure provider, base URL, protocol and model per member. See [API access](docs/en/runner.md#api-access).
|
|
113
|
-
- **Borrow an AI from another computer** — invite an agent running on someone else's computer (or another of yours) into your room as an external member: it reads only the project folders you open, answers in the room, and you can see every file it read and revoke it at any time. Both computers need CoDiscuss, and your computer must be connected to a hosted site with the relay and stay on. What it reads reaches that computer's model provider. The default trust levels rely on limiting the agent to CoDiscuss commands, supported for Claude Code (tested on version 2.1.325), the Antigravity CLI (tested on version 1.5.12) and model APIs (backed by unit tests); Codex and the Antigravity desktop app do not support it. See [External members](docs/en/runner.md#external-members-borrowing-an-ai-from-another-computer).
|
|
95
|
+
Details: [Architecture](docs/en/architecture.md).
|
|
114
96
|
|
|
115
97
|
## Deployment
|
|
116
98
|
|
|
117
99
|
The site can be self-hosted on **Cloudflare Pages + D1** or **Docker**; agents and the runner still run on your own machine. A Docker site keeps its own rooms; the Cloudflare site keeps none and shows the rooms on your paired computer to paired devices through an encrypted relay. See [Deployment](docs/en/deployment.md).
|
|
118
100
|
|
|
119
101
|
> [!WARNING]
|
|
120
|
-
>
|
|
102
|
+
> Self-hosted Python sites, including Docker deployments, support administrator sign-in. Room reads have no per-room access controls, so anyone who can reach the room site can read its rooms. The Cloudflare site stores no rooms and shows them only to devices paired at your computer. Read the [security policy](.github/SECURITY.md) before exposing a site publicly.
|
|
121
103
|
|
|
122
104
|
## Documentation
|
|
123
105
|
|
|
124
106
|
| Topic | Document |
|
|
125
107
|
| --- | --- |
|
|
126
|
-
|
|
|
127
|
-
| Installation, entry points, API access, command line, troubleshooting | [Setup](docs/en/runner.md) |
|
|
108
|
+
| How to use every feature, from first run to troubleshooting | [User Guide](docs/en/guide/README.md) |
|
|
128
109
|
| Local, Docker and Cloudflare deployment | [Deployment](docs/en/deployment.md) |
|
|
129
110
|
| Design principles, components and data boundaries | [Architecture](docs/en/architecture.md) |
|
|
130
111
|
|
|
131
|
-
Documentation is written in Chinese.
|
|
132
|
-
|
|
133
112
|
## Contributing
|
|
134
113
|
|
|
135
114
|
Issues and pull requests are welcome. See the [contributing guide](.github/CONTRIBUTING.md) for development setup, running from source and testing.
|
package/README.zh-CN.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
把 Claude Code、Codex、Antigravity 和模型 API 拉进共享房间——<br>
|
|
8
8
|
各自保留原有会话、工具与账号,按点名分工,或围绕目标多轮讨论。
|
|
9
9
|
|
|
10
|
-
[快速开始](#快速开始) · [
|
|
10
|
+
[快速开始](#快速开始) · [用户手册](docs/guide/README.md) · [工作原理](#工作原理) · [English](README.md)
|
|
11
11
|
|
|
12
12
|
[](https://github.com/huyan1458/ai_co_discuss/actions/workflows/ci.yml)
|
|
13
13
|
[](https://www.npmjs.com/package/ai_co_discuss)
|
|
@@ -24,27 +24,21 @@
|
|
|
24
24
|
|
|
25
25
|
多数多智能体框架在自己的运行时里新建 Agent。AI CoDiscuss 反过来:接入你**已经在用**的 AI 软件——连同它们现有的会话、项目上下文、权限和订阅——为它们提供一个共享房间,持久保存消息、观点、分歧与结论。
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## 能做什么
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
- **向你提问**:需要你拍板时,成员在房间里提问,输入框上方出现答题卡;可直接选择、补充意见,或请主持人先给推荐、交给主持人决定,答案交回提问者或接力的下一棒。
|
|
31
|
-
- **结构化讨论**:设定目标与轮次 / 时长上限,主持人安排发言与追问;结束后回到自由协作,记录与结论保留。
|
|
32
|
-
- **智能调度**:可选由决策模型处理日常分派,不必每次唤醒主持人。
|
|
33
|
-
- **混合接入**:本地 CLI 与桌面 App、模型 API、手动接入的会话可同房协作。
|
|
34
|
-
- **共享项目**:为房间指定项目目录,并为每位本地 AI 设置只读或可写。房间“文件”页可浏览目录,悬浮预览文本、Markdown 和静态 HTML。
|
|
35
|
-
- **随时调整成员**:随时邀请、暂离、请回或移除成员,也可以续接一个已有的 AI 会话。
|
|
36
|
-
- **可迁移记录**:附件、包含讨论历史的跨站点 ZIP 导出 / 导入,并可用 `discuss-report` 技能生成带来源的报告。
|
|
37
|
-
- **本机优先**:完全在本机运行;也可将网站部署到 Cloudflare 或 Docker,AI 仍在本机执行。
|
|
29
|
+
每项的完整用法见[用户手册](docs/guide/README.md)。
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
- **点名分工,多线并行**:`@` 哪位 AI,它就在自己的原会话里处理,不占发言顺序,与主持人安排的主线并行;未点名的消息由 AI 主持人分派。见[在房间里干活](docs/guide/working.md)。
|
|
32
|
+
- **向你提问**:需要你拍板时,成员在房间里提问,输入框上方出现答题卡。见[在房间里干活](docs/guide/working.md)。
|
|
33
|
+
- **结构化讨论**:设定目标与轮次或时长上限,主持人安排发言与追问,可生成带来源的报告。见[讨论](docs/guide/discussion.md)。
|
|
34
|
+
- **Goal**:交给主持人一个目标,它持续推进,需要你确认时停下,可发微信提醒。见 [Goal](docs/guide/goal.md)。
|
|
35
|
+
- **工作流**:把固定的多人分工存成工作流,在房间里一键启用。见[工作流](docs/guide/workflows.md)。
|
|
36
|
+
- **智能调度**:可选由决策模型处理日常分派,不必每次唤醒主持人;使用你自己的密钥,房间标题与最近消息会发给所选供应商。见[智能调度](docs/guide/scheduling.md)。
|
|
37
|
+
- **混合接入**:本地 CLI 与桌面 App、模型 API、手动接入的会话同房协作;可续接已有的 AI 会话,为每位成员设置只读或可写。见[成员](docs/guide/members.md)。
|
|
38
|
+
- **共享项目与记录**:为房间指定项目目录并在“文件”页浏览;附件、跨站点导出导入与分支。见[房间目录与建房](docs/guide/rooms.md)。
|
|
39
|
+
- **借用另一台电脑上的 AI**:把别人电脑上的 AI 请进你的房间,只读你开放的目录,随时撤销。见[跨电脑协作](docs/guide/external-members.md)。
|
|
40
|
+
- **手机与外出**:电脑绑定自托管的免费 Cloudflare 站点后,手机或平板扫码配对即可远程使用。见[手机与外出](docs/guide/remote.md)。
|
|
41
|
+
- **语音与托管**:朗读与语音输入,可在本机运行;管理面板可给别人开托管账号。见[语音与通知](docs/guide/voice.md)、[管理面板与托管账号](docs/guide/admin.md)。
|
|
48
42
|
|
|
49
43
|
## 支持的参与者
|
|
50
44
|
|
|
@@ -52,7 +46,9 @@
|
|
|
52
46
|
| --- | --- | --- |
|
|
53
47
|
| **自动唤醒** | Claude Code CLI · Codex App / CLI · Antigravity App / CLI | 由本机服务唤醒并续接原会话,可担任主持人 |
|
|
54
48
|
| **模型 API** | OpenAI · Claude · Gemini · DeepSeek · Qwen · Grok · OpenAI 兼容服务 | 在本机的 [Pi](https://github.com/earendil-works/pi) 中运行,只有房间与项目文件工具,有自己的会话,可担任主持人 |
|
|
55
|
-
| **手动接入** | 任何可运行 `codiscuss` 的本地 AI(如 Cursor CLI) |
|
|
49
|
+
| **手动接入** | 任何可运行 `codiscuss` 的本地 AI(如 Cursor CLI) | 凭自己的成员凭证读写,见[手动接入](docs/guide/members.md#手动接入) |
|
|
50
|
+
|
|
51
|
+
网页版 ChatGPT、Claude、Gemini 不能作为成员接入。
|
|
56
52
|
|
|
57
53
|
## 快速开始
|
|
58
54
|
|
|
@@ -68,7 +64,7 @@ codiscuss setup
|
|
|
68
64
|
|
|
69
65
|
1. 点击 **新建房间**,添加 AI 成员。
|
|
70
66
|
2. 点皇冠指定主持人,按需填写项目目录。
|
|
71
|
-
3.
|
|
67
|
+
3. 需要多轮讨论或持续推进目标时,在“创建后”选择“开启讨论”或“开启 Goal”,并填写目标。
|
|
72
68
|
4. 创建房间,用 `@` 点名成员开始协作。
|
|
73
69
|
|
|
74
70
|
```sh
|
|
@@ -77,13 +73,13 @@ codiscuss local status # 查看网站与服务状态
|
|
|
77
73
|
codiscuss local stop # 停止网站及其管理的服务
|
|
78
74
|
```
|
|
79
75
|
|
|
80
|
-
升级时先 `codiscuss local stop`,再运行 `npm install --global --prefer-online ai_co_discuss@latest` 和 `codiscuss setup
|
|
76
|
+
升级时先 `codiscuss local stop`,再运行 `npm install --global --prefer-online ai_co_discuss@latest` 和 `codiscuss setup`。逐步说明、费用与数据位置见[第一次使用](docs/guide/first-run.md),常用命令见[命令行](docs/guide/cli.md)。
|
|
81
77
|
|
|
82
78
|
## 工作原理
|
|
83
79
|
|
|
84
80
|
```mermaid
|
|
85
81
|
flowchart LR
|
|
86
|
-
U[你 · 浏览器] --> S[(房间网站<br
|
|
82
|
+
U[你 · 浏览器] --> S[(Python 房间网站<br>本机或自托管)]
|
|
87
83
|
S -- 事件 --> R[本机接入服务<br>codiscuss service]
|
|
88
84
|
R -- 唤醒 / 续接 --> A[Claude Code · Codex · Antigravity]
|
|
89
85
|
R -- API 调用 --> M[模型 API]
|
|
@@ -92,33 +88,24 @@ flowchart LR
|
|
|
92
88
|
M -- 房间工具 --> S
|
|
93
89
|
```
|
|
94
90
|
|
|
95
|
-
-
|
|
91
|
+
- **Python 网站**保存房间、成员与消息,校验发言安排、版本与凭据;不运行模型,也不保存 API 密钥。配对设备经 Cloudflare 中转访问电脑上的房间。
|
|
96
92
|
- **本机接入服务**消费网站事件,在各 AI 的原会话中唤醒它,或调用你配置的模型 API;密钥只留在本机。
|
|
97
93
|
- **AI 成员**按随包提供的 `discuss-host`、`discuss-participant` 技能,凭各自的成员凭证通过 `codiscuss` CLI 读写房间。
|
|
98
94
|
|
|
99
|
-
详见 [架构](docs/architecture.md)
|
|
100
|
-
|
|
101
|
-
## 更多入口
|
|
102
|
-
|
|
103
|
-
- **线上网站 + 本机 AI**:在运行 AI 的电脑上执行一次 `codiscuss local connect https://你的站点`。见 [线上网页连接本机](docs/runner.md#线上网页连接本机)。
|
|
104
|
-
- **手机或平板建房**:在电脑上连接一次并保存常用项目后,在电脑前扫码配对一次手机或平板,之后用同一网站即可新建房间,由那台电脑唤醒 AI,项目路径只留在电脑上。见 [其他设备经已配对电脑建房](docs/runner.md#其他设备经已配对电脑建房)。
|
|
105
|
-
- **从 AI 对话发起**:让本地 AI 使用 `discuss-host` 和 `discuss-participant` 技能建房并主持。见 [从 AI 对话发起](docs/runner.md#从-ai-对话发起)。
|
|
106
|
-
- **模型 API**:按成员配置供应商、Base URL、请求协议与模型。见 [API 接入](docs/runner.md#api-接入)。
|
|
107
|
-
- **借用另一台电脑上的 AI**:邀请别人电脑(或你自己另一台电脑)上的 AI 作为外部成员进入你的房间,它只读你开放的项目目录、在房间里回答,你能看到它读过的每个文件并随时撤销。两台电脑都要安装共议,你的电脑须连接带中转的线上网站并保持开机;它读到的内容会发送给对方的模型服务商。默认的信任等级依赖把对方 AI 限制为只用共议命令,目前支持 Claude Code(已在 2.1.325 版实测)、Antigravity CLI(已在 1.5.12 版实测)与模型 API(以单元测试为据),Codex 与 Antigravity 桌面版不支持。见 [外部成员](docs/runner.md#外部成员借用另一台电脑上的-ai)。
|
|
95
|
+
详见 [架构](docs/architecture.md)。
|
|
108
96
|
|
|
109
97
|
## 部署
|
|
110
98
|
|
|
111
99
|
网站支持自托管于 **Cloudflare Pages + D1** 或 **Docker**;AI 与接入服务仍在你的电脑运行。Docker 站点自己保存房间;Cloudflare 站点不保存房间,已配对的设备经加密中转看到电脑上的房间。见 [部署指南](docs/deployment.md)。
|
|
112
100
|
|
|
113
101
|
> [!WARNING]
|
|
114
|
-
>
|
|
102
|
+
> 自托管 Python 站点(含 Docker)支持管理员登录。房间没有逐房间的读取权限隔离,能访问房间站点的人即可阅读其中的房间。Cloudflare 站点不保存房间,只向在电脑前配对过的设备显示。公开部署前请阅读 [安全说明](.github/SECURITY.md)。
|
|
115
103
|
|
|
116
104
|
## 文档
|
|
117
105
|
|
|
118
106
|
| 主题 | 文档 |
|
|
119
107
|
| --- | --- |
|
|
120
|
-
|
|
|
121
|
-
| 安装、入口、API 接入、命令行与故障排查 | [安装与接入](docs/runner.md) |
|
|
108
|
+
| 全部功能的用法,从第一次使用到常见问题 | [用户手册](docs/guide/README.md) |
|
|
122
109
|
| 本地、Docker 与 Cloudflare 部署 | [部署](docs/deployment.md) |
|
|
123
110
|
| 设计原则、组成与数据边界 | [架构](docs/architecture.md) |
|
|
124
111
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"""External members: AIs that run on another computer and reach this room only through the runner's gateway.
|
|
2
2
|
|
|
3
3
|
An external member is a `room_members` row with `access='external'` plus one `external_members` row holding where it
|
|
4
|
-
runs, what it may read
|
|
5
|
-
|
|
4
|
+
runs, what it may read and until when. This module is the room-side authority (DESIGN D4): it decides validity,
|
|
5
|
+
expiry and revocation, keeps the read audit, and serves the only routes an external
|
|
6
6
|
credential may use (`/api/external/rooms/{room}/...`). Every other route refuses an external credential or a request
|
|
7
7
|
the gateway marked as external; see `guard_route`. Contract: .dev/plans/远程协作与多人房间/子Task1_B侧后端/CONTRACT.md.
|
|
8
8
|
"""
|
|
@@ -10,11 +10,12 @@ the gateway marked as external; see `guard_route`. Contract: .dev/plans/远程
|
|
|
10
10
|
import hashlib
|
|
11
11
|
import json
|
|
12
12
|
import posixpath
|
|
13
|
+
import re
|
|
13
14
|
import time
|
|
14
15
|
from datetime import datetime, timezone
|
|
15
16
|
|
|
16
17
|
from . import free_room
|
|
17
|
-
from .identity import AI_PLATFORMS, MAX_ROOM_AGENTS, PLATFORM_NICKNAMES, is_ai
|
|
18
|
+
from .identity import AI_PLATFORMS, JOINED_NICKNAMES, MAX_ROOM_AGENTS, PLATFORM_NICKNAMES, is_ai
|
|
18
19
|
from .runtime import begin_write, require_owner, token_hash
|
|
19
20
|
from .texts import Text, text_payload
|
|
20
21
|
|
|
@@ -24,9 +25,7 @@ EXTERNAL_PREFIX = ["api", "external", "rooms"]
|
|
|
24
25
|
SCOPES = ("discuss", "read")
|
|
25
26
|
# How many ended external members the roster still lists.
|
|
26
27
|
MAX_ENDED_SHOWN = 10
|
|
27
|
-
|
|
28
|
-
DEFAULT_QUOTA = {"hourly_bytes": 4 * 1024 * 1024, "total_bytes": 64 * 1024 * 1024, "hourly_reads": 600}
|
|
29
|
-
MAX_QUOTA = {"hourly_bytes": 1024 ** 3, "total_bytes": 100 * 1024 ** 3, "hourly_reads": 100000}
|
|
28
|
+
# Reads are no longer limited (user 2026-11-19); the old quota columns stay in the table, written as 0 and never read.
|
|
30
29
|
MAX_EXTERNAL_SECONDS = 365 * 86400
|
|
31
30
|
PENDING_SEAT_SECONDS = 7 * 86400
|
|
32
31
|
MAX_DIRECTORIES = 20
|
|
@@ -35,7 +34,6 @@ MAX_MACHINE = 200
|
|
|
35
34
|
MAX_MACHINE_LABEL = 80
|
|
36
35
|
MAX_ADAPTER = 40
|
|
37
36
|
MAX_MODEL = 120
|
|
38
|
-
HOUR_SECONDS = 3600
|
|
39
37
|
READ_OPS = ("ls", "read", "grep")
|
|
40
38
|
READ_OUTCOMES = ("ok", "denied")
|
|
41
39
|
MAX_READ_PATH = 1000
|
|
@@ -90,20 +88,6 @@ def guard_route(connect, headers, parts):
|
|
|
90
88
|
raise classified(PermissionError, Text("外部成员只能使用成员范围接口"), "external_route_forbidden")
|
|
91
89
|
|
|
92
90
|
|
|
93
|
-
def quota_of(row):
|
|
94
|
-
"""The member's three quota limits."""
|
|
95
|
-
return {key: row[key] for key in QUOTA_KEYS}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def usage_of(connection, member_id, now=None):
|
|
99
|
-
"""Read counts from the persisted audit: allowed bytes and reads in the last hour, allowed bytes in total, denials."""
|
|
100
|
-
since = ((now or int(time.time())) - HOUR_SECONDS) * 1000
|
|
101
|
-
row = connection.execute("""SELECT COALESCE(SUM(CASE WHEN allowed=1 AND at>? THEN bytes END),0),
|
|
102
|
-
COALESCE(SUM(CASE WHEN allowed=1 AND at>? THEN 1 END),0),COALESCE(SUM(CASE WHEN allowed=1 THEN bytes END),0),
|
|
103
|
-
COALESCE(SUM(CASE WHEN allowed=0 THEN 1 END),0) FROM external_reads WHERE member_id=?""", (since, since, member_id)).fetchone()
|
|
104
|
-
return {"hour_bytes": row[0], "hour_reads": row[1], "total_bytes": row[2], "denied": row[3]}
|
|
105
|
-
|
|
106
|
-
|
|
107
91
|
def directory_names(directories):
|
|
108
92
|
"""Directory roots by number with only their last segment, for views that must not show local paths."""
|
|
109
93
|
return [{"root": index, "name": posixpath.basename(path.replace("\\", "/").rstrip("/")) or path}
|
|
@@ -111,12 +95,12 @@ def directory_names(directories):
|
|
|
111
95
|
|
|
112
96
|
|
|
113
97
|
def owner_view(connection, row):
|
|
114
|
-
"""Describe one external member for the owner, with full directory paths
|
|
98
|
+
"""Describe one external member for the owner, with full directory paths."""
|
|
115
99
|
labels = free_room.member_display_names(connection, row["room_id"])
|
|
116
100
|
return {"member_id": row["id"], "name": row["name"], "label": labels.get(row["name"], row["name"]), "adapter": row["adapter"],
|
|
117
101
|
"status": row["status"], "machine": row["machine"], "machine_label": row["machine_label"], "platform": row["platform"],
|
|
118
|
-
"model": row["model"], "scope": row["scope"], "directories": json.loads(row["directories"]), "expires_at": row["expires_at"],
|
|
119
|
-
"
|
|
102
|
+
"model": row["model"], "scope": row["scope"], "directories": json.loads(row["directories"]), "expires_at": row["expires_at"],
|
|
103
|
+
"created_at": row["created_at"], "updated_at": row["updated_at"],
|
|
120
104
|
"ended_at": row["ended_at"], "end_reason": row["end_reason"],
|
|
121
105
|
"claimed_at": row["claimed_at"], "invite_version": row["invite_version"], "duration": row["invite_duration"]}
|
|
122
106
|
|
|
@@ -204,20 +188,6 @@ def checked_expiry(value, now):
|
|
|
204
188
|
return value
|
|
205
189
|
|
|
206
190
|
|
|
207
|
-
def checked_quota(value, current):
|
|
208
|
-
"""Merge given quota limits over `current`; each is a positive integer within its maximum."""
|
|
209
|
-
if value is None:
|
|
210
|
-
return dict(current)
|
|
211
|
-
if not isinstance(value, dict) or set(value) - set(QUOTA_KEYS):
|
|
212
|
-
raise ValueError(Text("quota 只能包含 hourly_bytes、total_bytes、hourly_reads"))
|
|
213
|
-
merged = dict(current)
|
|
214
|
-
for key, item in value.items():
|
|
215
|
-
if type(item) is not int or not 0 < item <= MAX_QUOTA[key]:
|
|
216
|
-
raise ValueError(Text("配额 {key} 须为 1–{limit} 的整数", key=key, limit=MAX_QUOTA[key]))
|
|
217
|
-
merged[key] = item
|
|
218
|
-
return merged
|
|
219
|
-
|
|
220
|
-
|
|
221
191
|
def checked_text(value, limit, field, required=False):
|
|
222
192
|
"""Validate a bounded single-line text field."""
|
|
223
193
|
if value is None and not required:
|
|
@@ -284,7 +254,6 @@ def create_external(connection, room_id, token, payload, now):
|
|
|
284
254
|
label = checked_text(payload.get("machine_label"), MAX_MACHINE_LABEL, "machine_label")
|
|
285
255
|
directories = checked_scope(payload.get("scope"), payload.get("directories", []))
|
|
286
256
|
expires_at = now + PENDING_SEAT_SECONDS if pending else checked_expiry(payload.get("expires_at"), now)
|
|
287
|
-
quota = checked_quota(payload.get("quota"), DEFAULT_QUOTA)
|
|
288
257
|
if connection.execute("SELECT 1 FROM room_members WHERE room_id=? AND name=? AND status<>'removed'", (room_id, name)).fetchone():
|
|
289
258
|
raise FileExistsError(Text("{name} 已是本房间成员", name=name))
|
|
290
259
|
if connection.execute("SELECT COUNT(*) FROM room_members WHERE room_id=? AND status<>'removed'", (room_id,)).fetchone()[0] >= MAX_ROOM_AGENTS:
|
|
@@ -296,7 +265,7 @@ def create_external(connection, room_id, token, payload, now):
|
|
|
296
265
|
connection.execute("""INSERT INTO external_members (member_id,room_id,token_hash,machine,machine_label,scope,directories,expires_at,
|
|
297
266
|
hourly_bytes,total_bytes,hourly_reads,created_at,updated_at,claimed_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
|
298
267
|
(cursor.lastrowid, room_id, hashed, machine, label, payload["scope"], json.dumps(directories, ensure_ascii=False),
|
|
299
|
-
expires_at,
|
|
268
|
+
expires_at, 0, 0, 0, now, now, 0 if pending else now))
|
|
300
269
|
if pending:
|
|
301
270
|
duration = payload.get("duration", "1h")
|
|
302
271
|
if duration not in ("1h", "today", "3d", "7d", "30d"):
|
|
@@ -337,11 +306,9 @@ def update_external(connection, room_id, member_id, token, payload, now):
|
|
|
337
306
|
directories = payload.get("directories", [] if scope == "discuss" and "directories" not in payload else json.loads(row["directories"]))
|
|
338
307
|
directories = checked_scope(scope, directories)
|
|
339
308
|
expires_at = checked_expiry(payload["expires_at"], now) if "expires_at" in payload else row["expires_at"]
|
|
340
|
-
quota = checked_quota(payload.get("quota"), quota_of(row))
|
|
341
309
|
label = checked_text(payload["machine_label"], MAX_MACHINE_LABEL, "machine_label") if "machine_label" in payload else row["machine_label"]
|
|
342
|
-
connection.execute("""UPDATE external_members SET scope=?,directories=?,expires_at=?,
|
|
343
|
-
|
|
344
|
-
quota["hourly_bytes"], quota["total_bytes"], quota["hourly_reads"], label, now, member_id))
|
|
310
|
+
connection.execute("""UPDATE external_members SET scope=?,directories=?,expires_at=?,machine_label=?,updated_at=? WHERE member_id=?""",
|
|
311
|
+
(scope, json.dumps(directories, ensure_ascii=False), expires_at, label, now, member_id))
|
|
345
312
|
return owner_view(connection, external_row(connection, room_id, member_id))
|
|
346
313
|
|
|
347
314
|
|
|
@@ -412,19 +379,28 @@ def save_label(connection, room_id, name, label, now):
|
|
|
412
379
|
ON CONFLICT(room_id,name) DO UPDATE SET label=excluded.label,updated_at=excluded.updated_at""", (room_id, name, label, now))
|
|
413
380
|
|
|
414
381
|
|
|
382
|
+
# A name this module gave after the AI (外部 Claude, 外部 Gemini2 …): the owner or host has not renamed it.
|
|
383
|
+
AUTO_LABEL = re.compile(rf"外部 ({'|'.join(map(re.escape, sorted(JOINED_NICKNAMES, key=len, reverse=True)))})\d*")
|
|
384
|
+
|
|
385
|
+
|
|
415
386
|
def name_joined(connection, row, now):
|
|
416
|
-
"""
|
|
387
|
+
"""Name an external member after its AI (外部 Claude, 外部 Claude2 …), on joining and whenever its AI changes.
|
|
417
388
|
|
|
418
|
-
A
|
|
419
|
-
|
|
389
|
+
A seat still under its pending name takes the AI's, and so does a name given earlier after another AI: the other
|
|
390
|
+
computer switched AI, or the member was invited back and sent a different one (user 2026-11-19, #5835). A name the
|
|
391
|
+
owner or host gave is kept, and so is the current one when the AI is unknown or a custom API, which has no name of
|
|
392
|
+
its own. Only the label changes; the member name that requests and records use stays.
|
|
420
393
|
"""
|
|
421
394
|
platform = connection.execute("SELECT platform FROM external_members WHERE member_id=?", (row["id"],)).fetchone()[0]
|
|
422
395
|
current = free_room.member_labels(connection, row["room_id"]).get(row["name"])
|
|
423
396
|
legacy = "另一台电脑" + row["name"].removeprefix("Custom-ext")
|
|
424
|
-
|
|
397
|
+
automatic = AUTO_LABEL.fullmatch(current or "")
|
|
398
|
+
if platform in ("", "Custom") or (current not in (pending_label(row["name"], row["id"]), legacy) and not automatic):
|
|
425
399
|
return
|
|
426
400
|
nickname = PLATFORM_NICKNAMES.get(platform, platform)
|
|
427
|
-
|
|
401
|
+
if automatic and automatic.group(1) == nickname:
|
|
402
|
+
return
|
|
403
|
+
taken = set(free_room.member_display_names(connection, row["room_id"]).values()) - {current}
|
|
428
404
|
label = next(candidate for number in range(1, MAX_ROOM_AGENTS + 2)
|
|
429
405
|
if (candidate := f"外部 {nickname}{number if number > 1 else ''}") not in taken)
|
|
430
406
|
save_label(connection, row["room_id"], row["name"], label, now)
|
|
@@ -457,8 +433,8 @@ def checked_read(payload):
|
|
|
457
433
|
return op, root, path, size, outcome, reason
|
|
458
434
|
|
|
459
435
|
|
|
460
|
-
def read_decision(row, root,
|
|
461
|
-
"""Decide one read: (allowed, code, reason).
|
|
436
|
+
def read_decision(row, root, outcome, reason):
|
|
437
|
+
"""Decide one read: (allowed, code, reason)."""
|
|
462
438
|
if row["status"] != "active":
|
|
463
439
|
return False, "member_ended", ENDED_TEXTS.get(row["end_reason"], ENDED_TEXTS["revoked"])
|
|
464
440
|
if outcome == "denied":
|
|
@@ -467,17 +443,11 @@ def read_decision(row, root, size, outcome, reason, usage):
|
|
|
467
443
|
return False, "not_readable", Text("该外部成员只讨论,未开放读取项目")
|
|
468
444
|
if root >= len(json.loads(row["directories"])):
|
|
469
445
|
return False, "bad_root", Text("该目录未对外部成员开放")
|
|
470
|
-
if usage["hour_reads"] + 1 > row["hourly_reads"]:
|
|
471
|
-
return False, "quota_hour_reads", Text("本小时读取次数已达上限")
|
|
472
|
-
if usage["hour_bytes"] + size > row["hourly_bytes"]:
|
|
473
|
-
return False, "quota_hour_bytes", Text("本小时读取量已达上限")
|
|
474
|
-
if usage["total_bytes"] + size > row["total_bytes"]:
|
|
475
|
-
return False, "quota_total_bytes", Text("读取总量已达上限")
|
|
476
446
|
return True, "ok", ""
|
|
477
447
|
|
|
478
448
|
|
|
479
449
|
def record_read(connection, room_id, member_id, token, payload):
|
|
480
|
-
"""Audit one read, then judge it
|
|
450
|
+
"""Audit one read, then judge it, and commit before the gateway may return content.
|
|
481
451
|
|
|
482
452
|
The audit row and the room event are written first (as not allowed), the decision updates them in the same
|
|
483
453
|
transaction, and the transaction commits here: a failure anywhere raises, so the gateway returns nothing.
|
|
@@ -495,14 +465,13 @@ def record_read(connection, room_id, member_id, token, payload):
|
|
|
495
465
|
read_id = cursor.lastrowid
|
|
496
466
|
event = connection.execute("INSERT INTO room_events (room_id,at,kind,data) VALUES (?,?,'external.read',?)",
|
|
497
467
|
(room_id, at, json.dumps({"member_id": member_id, "read_id": read_id}))).lastrowid
|
|
498
|
-
allowed, code, why = read_decision(row, root,
|
|
468
|
+
allowed, code, why = read_decision(row, root, outcome, reason)
|
|
499
469
|
connection.execute("UPDATE external_reads SET allowed=?,code=?,reason=? WHERE id=?", (int(allowed), code, str(why), read_id))
|
|
500
470
|
data = {"member_id": member_id, "member": row["name"], "read_id": read_id, "op": op, "root": root, "directory": directory,
|
|
501
471
|
"path": path, "bytes": size, "allowed": allowed, "code": code, "reason": str(why)}
|
|
502
472
|
connection.execute("UPDATE room_events SET data=? WHERE id=?", (json.dumps(data, ensure_ascii=False), event))
|
|
503
473
|
connection.commit()
|
|
504
|
-
return {"allowed": allowed, "code": code, "reason": why, "reason_text": text_payload(why), "read_id": read_id, "recorded": True
|
|
505
|
-
"usage": usage_of(connection, member_id)}
|
|
474
|
+
return {"allowed": allowed, "code": code, "reason": why, "reason_text": text_payload(why), "read_id": read_id, "recorded": True}
|
|
506
475
|
|
|
507
476
|
|
|
508
477
|
def require_external(connection, room_id, token):
|
|
@@ -540,8 +509,7 @@ def member_room_view(connection, room_id, member):
|
|
|
540
509
|
latest = connection.execute("""SELECT COALESCE(MAX(id),0) FROM messages m WHERE room_id=?
|
|
541
510
|
AND NOT EXISTS (SELECT 1 FROM internal_task_messages t WHERE t.message_id=m.id)""", (room_id,)).fetchone()[0]
|
|
542
511
|
me = {"member_id": member["id"], "name": member["name"], "label": labels.get(member["name"], member["name"]), "scope": member["scope"],
|
|
543
|
-
"expires_at": member["expires_at"], "directories": directory_names(json.loads(member["directories"]))
|
|
544
|
-
"quota": quota_of(member), "usage": usage_of(connection, member["id"])}
|
|
512
|
+
"expires_at": member["expires_at"], "directories": directory_names(json.loads(member["directories"]))}
|
|
545
513
|
return {"room": {"id": room["id"], "title": room["title"], "goal": room["goal"], "archived": bool(room["archived"])},
|
|
546
514
|
"me": me, "members": members, "latest_message_id": latest}
|
|
547
515
|
|
|
@@ -594,15 +562,41 @@ def answer_payload(member, payload):
|
|
|
594
562
|
def report_ai(connection, member, payload):
|
|
595
563
|
"""The member's computer switched its AI: only what the room displays changes, never what the member may do."""
|
|
596
564
|
checked_text(payload.get("adapter"), MAX_ADAPTER, "adapter", required=True)
|
|
597
|
-
|
|
565
|
+
now = int(time.time())
|
|
566
|
+
save_ai(connection, member["id"], payload, now)
|
|
567
|
+
name_joined(connection, member, now)
|
|
598
568
|
return {"reported": True}
|
|
599
569
|
|
|
600
570
|
|
|
601
|
-
def lend_until(connection,
|
|
602
|
-
"""The member's computer sets how long it lends its AI; only its own end changes, never what it may read (red line 1 exception).
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
571
|
+
def lend_until(connection, room_id, token, payload):
|
|
572
|
+
"""The member's computer sets how long it lends its AI; only its own end changes, never what it may read (red line 1 exception).
|
|
573
|
+
|
|
574
|
+
A member whose time ran out comes back at once with the new end (user 2026-11-19): how long it is lent was its own
|
|
575
|
+
choice, so letting it lapse is not a decision of the owner's. One the owner revoked, or that left, stays ended.
|
|
576
|
+
"""
|
|
577
|
+
begin_write(connection)
|
|
578
|
+
now = int(time.time())
|
|
579
|
+
expires_at = checked_expiry(payload.get("expires_at"), now)
|
|
580
|
+
hashed = token_hash(token)
|
|
581
|
+
row = connection.execute(f"{EXTERNAL_SQL} WHERE x.room_id=? AND x.token_hash=?", (room_id, hashed)).fetchone() if hashed else None
|
|
582
|
+
if not row or not row["claimed_at"]:
|
|
583
|
+
raise classified(PermissionError, Text("需要本房间外部成员的凭证"), "external_credential_required")
|
|
584
|
+
revived = row["status"] != "active"
|
|
585
|
+
if revived:
|
|
586
|
+
if row["end_reason"] != "expired":
|
|
587
|
+
raise classified(PermissionError, ENDED_TEXTS.get(row["end_reason"], ENDED_TEXTS["revoked"]), "external_ended",
|
|
588
|
+
reason=row["end_reason"] or "revoked")
|
|
589
|
+
if connection.execute("SELECT 1 FROM room_members WHERE room_id=? AND name=? AND status<>'removed' AND id<>?",
|
|
590
|
+
(room_id, row["name"], row["id"])).fetchone():
|
|
591
|
+
raise FileExistsError(Text("{name} 已是本房间成员", name=row["name"]))
|
|
592
|
+
if connection.execute("SELECT COUNT(*) FROM room_members WHERE room_id=? AND status<>'removed'", (room_id,)).fetchone()[0] >= MAX_ROOM_AGENTS:
|
|
593
|
+
raise FileExistsError(Text("房间成员已满"))
|
|
594
|
+
connection.execute("UPDATE room_members SET status='active' WHERE id=?", (row["id"],))
|
|
595
|
+
connection.execute("UPDATE external_members SET ended_at=0,end_reason='' WHERE member_id=?", (row["id"],))
|
|
596
|
+
connection.execute("UPDATE external_members SET expires_at=?,updated_at=? WHERE member_id=?", (expires_at, now, row["id"]))
|
|
597
|
+
if revived:
|
|
598
|
+
free_room.sync_participants(connection, room_id)
|
|
599
|
+
return {"expires_at": expires_at, "revived": revived}
|
|
606
600
|
|
|
607
601
|
|
|
608
602
|
def leave_room(connection, member):
|
|
@@ -624,6 +618,9 @@ def external_api(connection, parts, params, method, token, read_payload, hooks):
|
|
|
624
618
|
(body, status)
|
|
625
619
|
"""
|
|
626
620
|
room_id, route = parts[3], parts[4:]
|
|
621
|
+
# Renewing is the one route a member whose time ran out may still use: it brings the member back.
|
|
622
|
+
if method == "POST" and route == ["expiry"]:
|
|
623
|
+
return lend_until(connection, room_id, token, read_payload()), 200
|
|
627
624
|
member = require_external(connection, room_id, token)
|
|
628
625
|
reading = {key: params[key] for key in MESSAGE_PARAMS if key in params}
|
|
629
626
|
if method == "GET" and route == ["view"]:
|
|
@@ -652,8 +649,6 @@ def external_api(connection, parts, params, method, token, read_payload, hooks):
|
|
|
652
649
|
return hooks["answer"](connection, room_id, answer_payload(member, payload), member), 201
|
|
653
650
|
if route == ["ai"]:
|
|
654
651
|
return report_ai(connection, member, payload), 200
|
|
655
|
-
if route == ["expiry"]:
|
|
656
|
-
return lend_until(connection, member, payload), 200
|
|
657
652
|
if route == ["leave"]:
|
|
658
653
|
return leave_room(connection, member), 200
|
|
659
654
|
raise LookupError(Text("地址不存在"))
|