ai_co_discuss 0.4.73 → 0.4.74
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/room.md +1 -1
- package/.agents/skills/discuss-participant/references/room.md +1 -1
- package/.agents/skills/discuss-session/references/host.md +1 -1
- package/.agents/skills/workflow-creator/SKILL.md +1 -1
- package/.agents/skills/workflow-creator/references/model-selection.md +1 -1
- package/docs/en/runner.md +1 -1
- package/docs/runner.md +2 -2
- package/frontend/locales/en/backend.json +1 -0
- package/frontend/locales/en/discussion.json +2 -1
- package/frontend/locales/en/room.json +0 -2
- package/package.json +1 -1
- package/runner/adapters/antigravity_cli.mjs +12 -1
- package/runner/adapters/api.mjs +18 -9
- package/runner/adapters/api_files.mjs +45 -3
- package/runner/adapters/api_pi.mjs +26 -8
- package/runner/adapters/api_pi_extension.mjs +2 -1
- package/runner/adapters/claude.mjs +1 -11
- package/runner/adapters/common.mjs +11 -1
- package/runner/adapters/profiles.mjs +2 -2
- package/web/backup.js +1 -1
- package/web/i18n.js +2 -2
- package/web/modern.css +1 -1
- package/web/modern.js +56 -56
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
30
|
- 需要他人时加 `--to 显示名`(可重复,不能点名自己),写明各自负责的文件或模块;不需要他人时不加,本次即结束。派活正文要能独立看懂:直接写要做的事、材料编号与完成标准,不写“同上”“见前文”。
|
|
31
31
|
- 派出的工作无论点名几位,全部结束(含失败)后都交回你。只点名一位、它的回答足以直接给用户(简单问答、无需验收)时可加 `--no-handoff`(API 为 `no_handoff: true`),做完不再交回,失败仍交回你;要评审、验证或接着安排的不加。
|
|
32
|
-
- 本次执行不便接着做、但还要继续时(等成员的结果之外还要复查、分几步推进),加 `--continue 继续做什么`(API 为 `continue
|
|
32
|
+
- 本次执行不便接着做、但还要继续时(等成员的结果之外还要复查、分几步推进),加 `--continue 继续做什么`(API 为 `continue`):房间没有其他进行中的工作时,程序再唤醒你一次;“进行中的工作”包括不交回你的成员(`--no-handoff`、`--detach` 派出的),它们做完之前不会唤醒你。派活后要自己马上接着做、不等它们,用 `--keep-working`(见 [接力](relay.md))。你下次回答不带它、或用户发了新消息就取消,仍需要就重新带上。不要用它等用户回复(需要用户决定时见参与技能 [回答房间请求](../../discuss-participant/references/room.md)“需要用户决定时”);Goal 进行中由 Goal 负责空闲续跑,不必加。
|
|
33
33
|
|
|
34
34
|
### 轮数上限
|
|
35
35
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- 新消息从任务的已读起点之后读起(`message list ROOM --after ID`),后面的消息可以修正前面的,以用户最新的要求为准。`request_messages` 可能指向已读起点之前的原回答,需要时 `message view ROOM ID` 补读。
|
|
6
6
|
- 完成后用 `message post --body-file 草稿.md` 提交一次回答。手动接入的成员没有执行编号:从 `room view` 的 `free.requests` 找到自己的待处理请求,用 `--request 请求编号` 关闭。
|
|
7
7
|
- 工作中收到“又有请求 #N 在排队等你”时,`execution view` 的 `queued_requests` 列出它们;这次回答能一并交付的,提交时加 `--also-request N`(API 填 `also_request_ids`)一起关闭,其余答完会再交给你。
|
|
8
|
-
-
|
|
8
|
+
- 多步的工作,在关键转折处用请求者的语言写一两句进展:这些中途文字会显示在网页的处理中卡片上,用户靠它知道你在做什么。不复述工具输出或操作步骤,不代替最终回答。
|
|
9
9
|
- 请求带 `sequence`、`question` 或 `question_needed`,任务有 `image`,或用户在你自己的窗口里要你发言时,另读 [按需场景](situations.md)。
|
|
10
10
|
|
|
11
11
|
## 需要用户决定时
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
- 安排须带本次读取的 `revision`;整轮计划还须包含 `waiting` 中的每位专家。`unregistered` 中尚未注册的手动专家不能排入,它注册后会自动加入本轮队列。名单变化后 `revision` 失效需重取,缺人或未带 `revision` 都会被拒绝;本轮不需要某人时先让其暂离。
|
|
54
54
|
- 计划只覆盖当前一轮,跨轮追问要看本轮回答后再定;只有各轮问题不依赖回答的固定流程(如依次报数)才可排满多轮。后一位的问题取决于前一位回答时也不必等前一位答完:把问题写成“先读取最新回答,再按……回应”,由专家自己读取。
|
|
55
55
|
- 网站在专家间自动接力,末位答完才交回主持。用户留言或打断时服务端会自动把控制权交回主持。
|
|
56
|
-
- `members` 中 `adapter` 为 `api`
|
|
56
|
+
- `members` 中 `adapter` 为 `api` 的专家:项目只读时只有文件工具、没有命令行;可写时和 CLI 专家一样能运行命令;没有项目目录时读不到本地文件。议题涉及本地文件时,开场说明写明相关路径和要点让它自己读;它读不到或索要信息时,由能读文件的专家补充。只读的 API 专家要跑测试、构建时交给能运行命令的专家。
|
|
57
57
|
|
|
58
58
|
## 推进判断
|
|
59
59
|
|
|
@@ -74,7 +74,7 @@ description: AI CoDiscuss 工作流的创建与修改技能。用户要把房间
|
|
|
74
74
|
|
|
75
75
|
### 登记命令(给模型 API 成员)
|
|
76
76
|
|
|
77
|
-
以 API
|
|
77
|
+
以 API 方式加入的只读成员没有命令行(可写成员直接用命令行,登记的命令对它不生效)。某个角色需要自己跑检查脚本之类的命令时,在文件夹根目录放 `commands.json` 登记,脚本本身也放进文件夹(如 `tools/`),这样随工作流一起分享:
|
|
78
78
|
|
|
79
79
|
```json
|
|
80
80
|
{ "commands": [
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
写卡片时:
|
|
20
20
|
|
|
21
21
|
- 只写本机已配置的平台;不确定时 `model`、`effort` 省略,用本机默认值。
|
|
22
|
-
- 纯 API 平台(`OpenAI`、`DeepSeek`、`Qwen`、`Grok`、`Custom`)的成员不读 `effort
|
|
22
|
+
- 纯 API 平台(`OpenAI`、`DeepSeek`、`Qwen`、`Grok`、`Custom`)的成员不读 `effort`;项目只读时没有命令行,只能用文件工具和 `commands.json` 登记的命令,可写时能直接运行命令;只读又要跑脚本的角色,要么登记命令,要么用 `Claude`、`Codex`、`Antigravity` 这类本机软件。
|
|
23
23
|
- 要出图、改图的角色(插画、封面、配图)任选平台,在提示词里写明由它负责出图;房间添加了“生图”卡片(图片模型在卡片里配置)后才能画。出图角色优先用能看图的本机软件(如 `Claude`),它能下载附件自查;API 成员看不到自己画的图,用它出图时另配一张本机软件的审图卡片。
|
|
24
24
|
- 同一件事要两个视角审时,两张卡片用不同平台,避免同一家模型的盲点重叠。
|
package/docs/en/runner.md
CHANGED
|
@@ -122,7 +122,7 @@ Choose **OpenAI** in the member picker, flip its card, enter your official OpenA
|
|
|
122
122
|
|
|
123
123
|
Choose **自定义 API** (Custom API) for another service, then enter its base URL, API key and full model ID. It defaults to Chat Completions and also supports Responses, Anthropic Messages and Gemini generateContent. Use the name and description button on the card's back to set a display name; add the slot again to configure multiple independent members. Official presets for Anthropic, Google Gemini, DeepSeek, Alibaba Cloud Model Studio (Qwen) and xAI (Grok) remain available.
|
|
124
124
|
|
|
125
|
-
API members can act as experts or hosts. When the room has a project folder,
|
|
125
|
+
API members can act as experts or hosts. When the room has a project folder, read-only members read and search its files through file tools the runner provides (secret files such as `.env` and private keys, the `.git` folder and the local service folder are not available); with writable project access they work like Claude Code and Codex, with Pi's own read, edit, write and command line, so they can run tests, builds and git, and can also reach any file your account can on this computer. Whatever they read is sent to the model provider you configured. Keys stay on your machine, and calls are billed to your account. To let an API member see images, turn on image input in its card's API settings (only when the model supports it, otherwise requests fail); without it the member cannot see image content. API members can always read UTF-8 text attachments on demand; PDFs and other files are not readable for them, and their answers say so.
|
|
126
126
|
|
|
127
127
|
## Smart Scheduling
|
|
128
128
|
|
package/docs/runner.md
CHANGED
|
@@ -153,7 +153,7 @@ API 成员在房间里的工作由 [Pi](https://github.com/earendil-works/pi)
|
|
|
153
153
|
|
|
154
154
|
选择 **自定义 API** 可接入其他服务:翻开卡片填写 Base URL、API Key 和完整模型 ID,默认使用 Chat Completions,也可选择 Responses、Anthropic Messages 或 Gemini generateContent。卡片背面的“名称与描述”按钮可修改显示名称;重复点击添加可配置多个不同的 API 成员。Anthropic、Google Gemini、DeepSeek、阿里云百炼(Qwen)、xAI(Grok)也保留官方地址预设。
|
|
155
155
|
|
|
156
|
-
API
|
|
156
|
+
API 成员可以担任专家或主持人。房间指定了项目目录时,只读时它用接入程序提供的文件工具读取、搜索项目文件(`.env`、私钥等密钥文件、`.git` 目录和本机服务目录不开放);项目权限设为可写时,它和 Claude Code、Codex 一样用 Pi 自带的读写、编辑和命令行工作,能运行测试、构建和 git,也能读到这台电脑上你的账号能访问的文件。读到的内容会发给你配置的模型服务商。密钥只保存在本机,调用费用按你的账号计费。
|
|
157
157
|
|
|
158
158
|
**给成员发截图或文件**:在输入框粘贴、拖入或用回形针添加附件后,输入框上方出现缩略图,正文光标处插入 `[图片 #1]`、`[文件 #2]` 这样的占位,用来说明哪段话对应哪个文件。编号在整个房间里连续、不重复(像 Claude Code 里贴的图那样),翻聊天记录时按编号就能找到那张图。占位像 @成员一样高亮成小标签,按一次退格或 Delete 就整段删掉;删掉缩略图或删掉占位,两边同步移除。消息发出后,正文里的占位可点开对应附件。被点名的成员收到任务时,附件已下载到这台电脑,任务里按占位列出位置;Claude Code 和 Codex CLI 会像在自己窗口里贴图一样直接看到图片,其他软件按位置自行打开。API 成员要看图,在它卡片的 API 设置里打开“看图”(只在模型本身支持看图时打开,否则请求会出错);没打开时它看不到图片内容。UTF-8 文本附件 API 成员都能按需读取原文;PDF 等其他文件它读不到,回答里会说明没有读取。执行中插话和私聊只能发文字。
|
|
159
159
|
|
|
@@ -176,7 +176,7 @@ API 成员可以担任专家或主持人。房间指定了项目目录时,它
|
|
|
176
176
|
- **主持人完整权限的其他控制**:同一个开关打开后,主持人会自己处理房间里的问题、持续推进:成员跑偏时插话、卡住时打断或重试(它自己的执行失败时程序会提醒它一次,它可以重试自己、补交结果,或给自己换模型)、模型不可用时换模型、无法恢复时换人;你也可以直接说“停下写手”“全部停下”“下一个让批评家先说”“请一位 Codex 进来只读评审”“把记录员请出去”“开个 Goal 把剩下几集写完”“暂停讨论”。邀请只用本机已配置的软件,项目权限默认只读、最高可写,邀请暂离中的成员会把它按原名请回;它自己开的 Goal 用你的默认预算(不限时为 8 次续跑、90 分钟)。成员连续 10 分钟没有新输出时,系统会提醒主持人检查;主持人派出长任务时还可以给自己设定时检查(每 5–120 分钟一次;房间空闲时再提醒它最后一次,确认做完了还是还有下一步,之后结束)。它也能撤回自己派出的活,正在循环的接力会立即停下。以下仍由你决定:对主持人自己的其他操作(打断、改项目权限、暂离、移除)或更换主持人、批准超出上限的轮数、高于可写的权限或放行工具、改项目目录、撤回你的消息、私聊。API 主持人没有命令行,不能这样做。
|
|
177
177
|
- **分享**:工作流存在本机服务目录的 `workflows` 文件夹,一个工作流一个文件夹;编辑页可复制路径,把整个文件夹(或打成 zip)发给对方即可分享。导入时会列出每张卡片的提示词和项目权限;要求写文件的卡片默认按只读导入,逐张勾选后才放开。
|
|
178
178
|
- **子工作流**:主线之外按需用的一套做法(比如检查成稿的 AI 率、请几位专家代入主角试演一场戏)可以做成子工作流:它有自己的 SKILL.md、成员卡片和画布,放在工作流文件夹的 `workflows/<子工作流ID>/` 下。在工作流页画布左上角工具条下方的“主线与子工作流”列表里切换、新建或删除,切过去后画布和右侧(手机上为“子工作流”页签)显示它自己的内容,和主线一起保存;手机上这个列表默认收起,显示当前在看哪一个。工作流进行中,在输入框打 `/` 会多出“工作流「名称」的子工作流”一组,选一项就写好请求交给主持人;主持人也会在合适的时候自己用。用到它的成员时,主持人把这些成员请进来,用完设为离开,会话保留,下次接着用。整个工作流文件夹仍是标准的技能格式,拷到别的 AI 软件里也能当技能读。
|
|
179
|
-
- **给 API
|
|
179
|
+
- **给 API 成员登记命令**:只读的 API 成员没有命令行(可写的直接用 Pi 自带的命令行,不需要登记)。工作流文件夹里放一个 `commands.json`(写法见 `workflow-creator` 技能),登记它们能运行的命令(例如检查脚本,脚本也放在工作流文件夹里),随工作流一起分享;启用后 API 成员只能按名字运行这些命令,改不了命令行,只读成员只能运行标为只读的命令。命令以你的身份在本机运行,所以导入别人的工作流时,编辑页会列出每条完整命令,勾选“允许这些命令在本机运行”才会带上;主持人起草或修改工作流时不能增删命令。
|
|
180
180
|
- **修改与结束**:修改工作流会作用于所有启用它的房间,成员下一次执行就按新内容;新增的卡片不会自动进入房间,主持人用到时会自己补上,也可以在右栏工作流一行点刷新图标立即补齐(删掉的卡片,其成员留作普通成员;与库一致时不显示该图标);工作流卡片的提示词只读,在工作流页的画布上修改。工作流进行中时,主持人只在请求和它的用途相符(或你说按工作流做)时才用,其他请求照常处理。用完在“成员与设置 → 协作设置”的工作流一行点请离成员图标(或逐个让成员离开):工作流带来的成员离开(主持人保留),正在进行的工作随之停止,工作流结束,右栏这一块消失;成员会话保留,下次在输入框打 `/` 选它就把原成员请回来,接着原来的上下文。换工作流时直接选另一个,原来的成员留作普通成员。
|
|
181
181
|
|
|
182
182
|
## 朗读与语音输入(可选)
|
|
@@ -559,6 +559,7 @@
|
|
|
559
559
|
"{name} 的登录已失效,处理 {messages} 的执行失败(执行 #{execution_id}):{reason}。需要用户在本机重新登录该软件后才能再用它;程序不自动重试,请主持人改派其他成员或告知用户。": "{name} is signed out; its execution for {messages} failed (execution #{execution_id}): {reason}. It can work again only after the user signs that software in again on this computer; it is not retried automatically. Host: reassign the work to another member or tell the user.",
|
|
560
560
|
"这次执行因登录失效失败;用户在本机重新登录该软件之前,重试仍会失败。": "This execution failed because the member is signed out; retrying will keep failing until the user signs that software in again on this computer.",
|
|
561
561
|
"模型输出在 {tokens} 个 token 处达到输出上限后结束,未提交结果{reply}": "The model's output stopped at its output limit after {tokens} tokens, without submitting a result{reply}",
|
|
562
|
+
"回复在 {tokens} 个 token 处达到输出上限被截断,已提醒模型直接提交(第 {count} 次)": "Reply cut off at the output limit of {tokens} tokens; asked the model to submit directly (attempt {count})",
|
|
562
563
|
"模型结束了本次执行,没有提交结果(最后一次回复输出 {tokens} 个 token,结束原因 {stop}){reply}": "The model ended this execution without submitting a result (its last reply output {tokens} tokens, stop reason {stop}){reply}",
|
|
563
564
|
"模型结束了本次执行,没有调用房间工具保存结果(最后一次回复输出 {tokens} 个 token,结束原因 {stop}){reply}": "The model ended this execution without calling a room tool to save a result (its last reply output {tokens} tokens, stop reason {stop}){reply}",
|
|
564
565
|
"讨论 {session_id} 已到轮数上限并结束。请主持人决定:总结结论、告知用户,或请用户批准后再开一次讨论。": "Discussion {session_id} reached its round limit and ended. The host should decide: summarize the conclusions, tell the user, or ask the user to approve another discussion.",
|
|
@@ -295,5 +295,6 @@
|
|
|
295
295
|
"发送 · Enter": "Send · Enter",
|
|
296
296
|
"换行": "new line",
|
|
297
297
|
"接力在等你回答上方的问题卡;这条消息只发给主持人 {value1}": "The relay is waiting for your answer on the question card above; this message goes only to the host {value1}",
|
|
298
|
-
"接力在等你回答问题卡…": "The relay is waiting for your answer on the question card…"
|
|
298
|
+
"接力在等你回答问题卡…": "The relay is waiting for your answer on the question card…",
|
|
299
|
+
"修改注释 {value1} · {value2}": "Editing note {value1} · {value2}"
|
|
299
300
|
}
|
|
@@ -760,8 +760,6 @@
|
|
|
760
760
|
"正在读取改动…": "Reading changes…",
|
|
761
761
|
"读取改动失败:{value1}": "Could not read changes: {value1}",
|
|
762
762
|
"改动较长,只显示前面一部分": "Long change; only the first part is shown",
|
|
763
|
-
"其他来源 {count} 个文件": "{count} files from other sources",
|
|
764
|
-
"同一时间被改动、但不是这位成员的编辑工具写的文件,可能来自其他窗口、成员或构建": "Files changed at the same time but not written by this member's edit tools; they may come from another window, member or a build",
|
|
765
763
|
"正在上传附件 {value1}/{value2}…": "Uploading attachments {value1}/{value2}…",
|
|
766
764
|
"正在上传": "Uploading",
|
|
767
765
|
"{value1} 已停止": "{value1} stopped",
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
12
12
|
import { atomic_json } from '../files.mjs';
|
|
13
13
|
import { cli_delivery } from './cli.mjs';
|
|
14
14
|
import { DENIAL_FIELD, EDIT_TOOLS, json_line, launch_directory, MAX_DENIALS, model_entry, MODEL_PATTERN, not_sent, page_sessions, project_directory,
|
|
15
|
-
prompt_title, query_catalog, read_json, same_path, TASK_SUBCOMMANDS, trim_preview } from './common.mjs';
|
|
15
|
+
prompt_title, query_catalog, read_json, same_path, shell_written_paths, TASK_SUBCOMMANDS, trim_preview } from './common.mjs';
|
|
16
16
|
|
|
17
17
|
// agy stores its generation settings as protobuf; field 28 (tag bytes 0xe2 0x01) holds the model actually used.
|
|
18
18
|
const AGY_MODEL_TAG = [0xe2, 0x01];
|
|
@@ -356,6 +356,17 @@ const events = {
|
|
|
356
356
|
responses.delete(step.step_index);
|
|
357
357
|
return text;
|
|
358
358
|
},
|
|
359
|
+
// A finished file tool names its file (agy 1.5.x: write_file / edit_file with `Path`); a command that writes claims the
|
|
360
|
+
// paths it names, as for Claude. Without this the card could not tell agy's own edits from others' (user 2026-11-17).
|
|
361
|
+
edits(event) {
|
|
362
|
+
const step = event.step_update;
|
|
363
|
+
if (step?.step_type !== 'tool' || step.state !== 'DONE') return [];
|
|
364
|
+
const parameters = step.tool_info?.parameters || {};
|
|
365
|
+
if (step.tool_name === 'run_command') return shell_written_paths(parameters.CommandLine);
|
|
366
|
+
if (!EDIT_TOOLS.test(step.tool_name || '')) return [];
|
|
367
|
+
const path = parameters.Path ?? parameters.AbsolutePath ?? parameters.TargetFile;
|
|
368
|
+
return typeof path === 'string' && path ? [path] : [];
|
|
369
|
+
},
|
|
359
370
|
detail: agy_detail,
|
|
360
371
|
};
|
|
361
372
|
|
package/runner/adapters/api.mjs
CHANGED
|
@@ -87,7 +87,8 @@ function role_tools(context) {
|
|
|
87
87
|
tool('read_attachment', `按附件 ID 读取:返回名称、大小、类型与所属消息;UTF-8 文本附件同时返回正文,长的用 offset(从第几个字符起)与 limit(默认 ${ATTACHMENT_CHARS},最多 ${MAX_ATTACHMENT_CHARS})续读;${context.image_input ? '图片随结果附上,可以直接看;' : ''}其余读不到内容的(${context.image_input ? '' : '图片、'}PDF、音视频等)返回 readable: false 与原因`,
|
|
88
88
|
{ id: TEXT, offset: { type: 'integer', minimum: 0 }, limit: { type: 'integer', minimum: 1, maximum: MAX_ATTACHMENT_CHARS } }, ['id']),
|
|
89
89
|
tool('read_goal', '读取 Goal 的目标、状态、续跑次数、用时与是否空闲'),
|
|
90
|
-
|
|
90
|
+
// With Pi's own tools (a writable member) its read/edit/write/bash replace our file tools and registered commands.
|
|
91
|
+
...repo_tools(context), ...(context.native_shell ? [] : [...file_tools(context.project), ...command_tools(context.commands, context.project)]), ...image_tools(context.image)];
|
|
91
92
|
const answer = { text: { ...TEXT, maxLength: 32000 }, summary: { ...TEXT, maxLength: 1000 }, reply_to: NUMBER,
|
|
92
93
|
also_request_ids: { type: 'array', items: NUMBER, maxItems: 20, description: '执行中又排队给你、这条回答已一并交付的普通请求编号(read_execution 的 queued_requests),同时关闭;不相关的不要填' },
|
|
93
94
|
...(context.image ? { attachments: { type: 'array', maxItems: MAX_MESSAGE_ATTACHMENTS, items: TEXT,
|
|
@@ -536,17 +537,22 @@ function skill_text(name, file = 'SKILL.md') {
|
|
|
536
537
|
}
|
|
537
538
|
|
|
538
539
|
/** What this member can do with project files, in its environment notes. */
|
|
539
|
-
function project_text(project, commands, image_input = false) {
|
|
540
|
+
function project_text(project, commands, image_input = false, native_shell = false) {
|
|
540
541
|
// A model the owner marked as reading images gets the woken messages' images with the task, as task.attachments lists.
|
|
541
542
|
const seen = image_input ? '唤醒你的消息里的图片(task.attachments 中的 [图片 #n])已随任务附上,可以直接看;其余' : '';
|
|
542
543
|
const attachments = `${seen}消息附件用 read_attachment 按 ID 读取:UTF-8 文本能读到正文${image_input ? ',图片随结果附上' : ''},返回 readable: false 时内容读不到`;
|
|
543
544
|
if (!project) return `- 本地文件你读不到;${attachments}。读不到的以其他成员贴出的为准,不凭文件名猜测;回答涉及时说明你没有读取,缺信息就写明缺什么。`;
|
|
544
|
-
|
|
545
|
+
if (native_shell) {
|
|
546
|
+
const others = project.roots.slice(1).map(item => item.root).join('、');
|
|
547
|
+
return `- 你在项目目录 ${project.root} 中工作,可用 read、bash、edit、write 工具读写文件、运行命令(测试、构建、git 等),和本地 CLI 成员一样;修改已有文件前先 read,局部修改优先用 edit。${others ? `本房间另有项目目录:${others}。` : ''}技能里的草稿文件与 --body-file 不适用:回答正文直接放进 submit_chat,不要写草稿文件。
|
|
548
|
+
- ${attachments};读不到的以其他成员贴出的为准,不凭文件名猜测;回答涉及时说明你没有读取,缺信息就写明缺什么。`;
|
|
549
|
+
}
|
|
550
|
+
const tools = project.writable ? 'read、glob、grep、git、write、edit' : 'read、glob、grep、git';
|
|
545
551
|
const extras = project.roots.slice(1).map(item => `${item.root}(${item.writable ? '可读写' : '只读'})`).join('、');
|
|
546
552
|
const runnable = command_tools(commands, project).length > 0;
|
|
547
553
|
const no_shell = runnable ? '没有通用命令行,只能用 run_command 运行工作流登记的命令(工具说明里列出),其他测试或构建不能运行,需要验证时在回答里说明,交给能运行命令的成员。'
|
|
548
554
|
: '没有命令行,不能运行测试或构建,需要验证时在回答里说明,交给能运行命令的成员。';
|
|
549
|
-
return `- 可用 ${tools} 工具${project.writable ? '读写' : '只读'}
|
|
555
|
+
return `- 可用 ${tools} 工具${project.writable ? '读写' : '只读'}本房间的项目目录,路径相对项目目录,不能越出;密钥文件、版本库元数据和接入程序的私有文件会被拒绝;git 只能运行 diff、log、show、status 查看改动与历史。${project.writable
|
|
550
556
|
? `修改已有文件前先 read,局部修改优先用 edit;${no_shell}技能里的草稿文件与 --body-file 不适用:回答正文直接放进 submit_chat,不要用 write 写草稿。`
|
|
551
557
|
: `项目只读,不能修改文件。${runnable ? '可用 run_command 运行工作流登记的只读命令(工具说明里列出)。' : ''}`}${extras ? `
|
|
552
558
|
- 本房间另有项目目录,用绝对路径访问:${extras}。` : ''}
|
|
@@ -577,10 +583,10 @@ export function system_prompt(context) {
|
|
|
577
583
|
const discussion = Boolean(context.discussion_request);
|
|
578
584
|
const environment = `你是 AI CoDiscuss 房间中的 ${context.participant},职责为 ${context.role}(${discussion ? '房间开启的讨论中的执行' : '房间请求'})。使用中文。
|
|
579
585
|
下文是本项目的参与技能${host ? '与主持技能' : ''},与本地软件参与者使用同一份。你经本机接入程序以 API 参与,环境差异如下,与技能冲突时以本段为准:
|
|
580
|
-
-
|
|
586
|
+
- ${context.native_shell ? '房间操作只用提供的房间工具:bash 里没有本次执行的凭据,不要运行 codiscuss 或 python runner/discuss.py 读写房间。' : `只能使用提供的${context.project ? '房间工具和项目文件工具' : '房间工具'},没有${command_tools(context.commands, context.project).length ? '通用' : ''}命令行、浏览器或其他软件。`}接入程序负责执行认领、续租和凭据管理;你的房间写入工具都绑定本次执行。submit_chat 结果不明(outcome: unknown)时用完全相同的内容再调用一次:提交编号不变,不会产生第二条;其他结果不明的写入不要重试。
|
|
581
587
|
- 命令与工具对应:room view → read_room;message list / view → read_messages / read_message;execution view → read_execution;attachment view / download → read_attachment;goal view → read_goal;room events → read_events;message post --kind chat → submit_chat。${host ? 'state decision → read_decision(按任务的决策编号读取完整判断);message post --proactive → submit_chat 的 proactive。' : ''}${discussion && host
|
|
582
588
|
? '主持讨论工具还包括 state set → save_state;room update → update_topic;turn create --plan-file → arrange_turns;turn continue → continue_plan;turn roster → read_roster,读后 turn ask → ask_interjection;取消安排 → cancel_turn;room limits --done → finish_discussion / declare_done。' : ''}${host ? ' 派活用 to,派出的工作结束后都会交回你;房间空闲后要接着推进时填 continue;message post --sequential / --loop / --with / --checkpoint / --repeat / --detach → submit_chat 的 sequential / loop / parallel / gates / detach;sequence view → read_sequence;sequence continue → continue_sequence。' : ''}${goal_host(context) ? ' goal start → start_goal;goal done / block → finish_goal;goal state → set_goal_state。' : ''}
|
|
583
|
-
${project_text(context.project, context.commands, context.image_input)}${context.external_access ? `
|
|
589
|
+
${project_text(context.project, context.commands, context.image_input, context.native_shell)}${context.external_access ? `
|
|
584
590
|
- 你是经另一台电脑加入的外部成员:只有 read_room、read_messages、read_message、submit_chat 与 repo 工具,读不到附件、事件记录,也不能提问。本房间的项目在邀请你的那台电脑上:用 repo_list / repo_read / repo_grep 只读查看对方开放的目录(对应 codiscuss repo ls / read / grep),先用不带参数的 repo_list 取得目录序号 root。` : ''}${context.image ? `
|
|
585
591
|
- 可用 generate_image 按文字生成图片(含 GIF 动图、SVG 矢量图),edit_image 按消息里的图片附件 ID${context.project ? '或项目内图片' : ''}修改、合成图片,图片模型为 ${context.image.model}。生成的图片存为本次执行的附件,submit_chat 时自动随回答发出(每条最多 ${MAX_MESSAGE_ATTACHMENTS} 张,可用 attachments 选择);task.unsent_images 列出你之前的执行生成后没能发出的图片(那次执行失败了),与本次任务相关时用 attachments 附上,不必重画。${context.project?.writable ? '图片要插进项目文档(如 Markdown)时,用 save_path 存进项目,文档里按相对路径引用。' : ''}你看不到图片内容:回答里说明画了什么、用了哪些参数,不描述没看到的细节,需要人看图确认时请用户或能看图的成员确认。每次调用都计费,不为试探反复生成;被拒或报错时按返回原因调整后再试。` : ''}
|
|
586
592
|
- ${max_requests(context) ? `本次执行最多 ${max_requests(context)} 次模型请求,每轮都计入;` : ''}互不依赖的读取或修改(如同一文件的多处 edit)在同一轮一次调用多个工具,减少模型请求次数。
|
|
@@ -694,6 +700,7 @@ export async function api_delivery(profile, binding, task, spawn_process) {
|
|
|
694
700
|
project: open_project(task.api_context, [task.api_context.home, task.directory]) };
|
|
695
701
|
if (context.image) context.unsent_images = unsent_images(context);
|
|
696
702
|
context.image_input = takes_images(profile);
|
|
703
|
+
context.native_shell = Boolean(context.project?.writable);
|
|
697
704
|
prompt = await task_prompt(context);
|
|
698
705
|
images = (task.images || []).filter(image => image.size <= MAX_INLINE_IMAGE_BYTES)
|
|
699
706
|
.map(image => ({ type: 'image', data: readFileSync(image.path).toString('base64'), mimeType: image.content_type }));
|
|
@@ -702,7 +709,7 @@ export async function api_delivery(profile, binding, task, spawn_process) {
|
|
|
702
709
|
throw not_sent(new Error(key ? message.replaceAll(key, '[已隐藏]') : message));
|
|
703
710
|
}
|
|
704
711
|
const setup = { ...task.api_context, participant: task.participant, directory: task.directory, task_id: task.id,
|
|
705
|
-
expert_prompt: context.expert_prompt, base_url: api_base_url(profile.base_url),
|
|
712
|
+
native_shell: context.native_shell, expert_prompt: context.expert_prompt, base_url: api_base_url(profile.base_url),
|
|
706
713
|
profile: Object.fromEntries(PROFILE_FIELDS.filter(field => profile[field] !== undefined).map(field => [field, profile[field]])) };
|
|
707
714
|
const context_file = join(task.directory, `${task.id}-pi-context.json`);
|
|
708
715
|
const system_file = join(task.directory, `${task.id}-pi-system.md`);
|
|
@@ -710,9 +717,11 @@ export async function api_delivery(profile, binding, task, spawn_process) {
|
|
|
710
717
|
writeFileSync(system_file, system_prompt(context), { mode: 0o600 });
|
|
711
718
|
// Without a command line, every file it writes goes through the write tools, so its edit list is complete; a registered
|
|
712
719
|
// command that changes files writes without telling, so then the list is left untracked.
|
|
713
|
-
|
|
720
|
+
// Pi's own tools (a writable member) are tracked as Claude's are: its write/edit by path and bash by the paths a writing
|
|
721
|
+
// command names.
|
|
722
|
+
if (context.project && (context.native_shell || !runs_write_commands(context.commands, context.project))) task.on_edits?.([]);
|
|
714
723
|
return pi_delivery({ cli, profile, key, binding, task, context_file, system_file, prompt, images, max_requests: max_requests(context),
|
|
715
|
-
project_root: context.project?.root || '', service_home: task.api_context.home, ...(spawn_process ? { spawn_process } : {}) });
|
|
724
|
+
project_root: context.project?.root || '', native_shell: context.native_shell, service_home: task.api_context.home, ...(spawn_process ? { spawn_process } : {}) });
|
|
716
725
|
}
|
|
717
726
|
|
|
718
727
|
// The call is the runner's own, so it can be aborted and its tool steps are seen.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Project file tools of a model API member: read, glob
|
|
2
|
+
* Project file tools of a model API member: read, glob, grep and a read-only git (diff, log, show, status), and at 可写
|
|
3
|
+
* also write and edit.
|
|
3
4
|
*
|
|
4
5
|
* Ported from the read / write / edit (packages/fs/tool-fs) and glob / grep (packages/fs/tool-fs-search) tools of
|
|
5
6
|
* DeepSeek Harness, https://github.com/deepseek-ai/deepseek-harness at ce7073d, MIT License, Copyright (c) 2026 DeepSeek:
|
|
@@ -25,11 +26,21 @@ const GREP_MAX_MATCHES = 250;
|
|
|
25
26
|
const GREP_MAX_LINE_LENGTH = 2000;
|
|
26
27
|
const MAX_WALK_ENTRIES = 100_000;
|
|
27
28
|
const GIT_TIMEOUT_MS = 15_000;
|
|
29
|
+
// The git tool: only commands that read, only options that neither write a file (--output), run a program (external
|
|
30
|
+
// diff, textconv, a pager) nor reach outside the repository (--no-index); a revision never names a file (`HEAD:.env`).
|
|
31
|
+
const GIT_COMMANDS = ['diff', 'log', 'show', 'status'];
|
|
32
|
+
const GIT_OPTION = /^-(?:-(?:stat|numstat|shortstat|name-only|name-status|cached|staged|patch|oneline|graph|decorate|abbrev-commit|follow|reverse|no-merges|merges|word-diff|ignore-all-space|ignore-space-change|summary|short|porcelain|branch|untracked-files(?:=(?:no|normal|all))?|stat=\d+(?:,\d+)?|unified=\d+|max-count=\d+|skip=\d+|since=[^=\s]+|until=[^=\s]+|after=[^=\s]+|before=[^=\s]+|author=.+|grep=.+|format=[\w%:.,\-<>()\[\] ]*|pretty=(?:oneline|short|medium|full|fuller)|date=(?:short|iso|relative|local))|[pswnU]\d*|[MC])$/;
|
|
33
|
+
const GIT_REVISION = /^[\w./~^@{}\-]+(?:\.\.\.?[\w./~^@{}\-]+)?$/;
|
|
34
|
+
// Secret files stay out of every diff and log, as the read tool refuses them.
|
|
35
|
+
const GIT_SECRET_EXCLUDES = [':(exclude,glob)**/.env', ':(exclude,glob)**/.env.*', ':(exclude,glob)**/*.pem', ':(exclude,glob)**/*.key',
|
|
36
|
+
':(exclude,glob)**/*.p12', ':(exclude,glob)**/*.pfx', ':(exclude,glob)**/*.jks', ':(exclude,glob)**/*.keystore',
|
|
37
|
+
':(exclude,glob)**/id_rsa*', ':(exclude,glob)**/id_dsa*', ':(exclude,glob)**/id_ecdsa*', ':(exclude,glob)**/id_ed25519*',
|
|
38
|
+
':(exclude,glob)**/.npmrc', ':(exclude,glob)**/.pypirc', ':(exclude,glob)**/.netrc'];
|
|
28
39
|
const VCS_DIRECTORIES = ['.git', '.svn', '.hg', '.bzr', '.jj', '.sl'];
|
|
29
40
|
// Their content would reach the model provider and could be posted into the room, which has no read isolation.
|
|
30
41
|
const SECRET_NAMES = [/^\.env(\..+)?$/i, /\.(pem|key|p12|pfx|jks|keystore)$/i, /^id_(rsa|dsa|ecdsa|ed25519)/i, /^\.(npmrc|pypirc|netrc)$/i];
|
|
31
42
|
const SECRET_EXAMPLES = /^\.env\.(example|sample|template)$/i;
|
|
32
|
-
const READ_TOOLS = ['read', 'glob', 'grep'];
|
|
43
|
+
const READ_TOOLS = ['read', 'glob', 'grep', 'git'];
|
|
33
44
|
export const WRITE_TOOLS = ['write', 'edit'];
|
|
34
45
|
const TEXT = { type: 'string' };
|
|
35
46
|
const NUMBER = { type: 'integer', minimum: 1 };
|
|
@@ -57,6 +68,15 @@ const DEFINITIONS = {
|
|
|
57
68
|
path: { ...TEXT, description: 'File or directory to search. Defaults to the project directory; a relative path resolves against it, an absolute one may name another listed project directory.' },
|
|
58
69
|
include: { ...TEXT, description: 'One glob filter for which files to search (e.g. "*.ts", "*.{js,jsx}"). Not a list; negation is not supported.' },
|
|
59
70
|
}, ['pattern']),
|
|
71
|
+
git: tool('git', 'Run a read-only git command in a project directory: diff, log, show or status. '
|
|
72
|
+
+ 'Use it to see what changed (e.g. diff, diff --stat HEAD~1, log --oneline -n 10, show HEAD --stat). '
|
|
73
|
+
+ `Output is cut at ${READ_MAX_BYTES} bytes; narrow it with paths or --stat.`, {
|
|
74
|
+
command: { type: 'string', enum: GIT_COMMANDS, description: 'The git subcommand.' },
|
|
75
|
+
args: { type: 'array', items: TEXT, description: 'Options and revisions, e.g. ["--stat", "HEAD~1"]. '
|
|
76
|
+
+ 'Options that write files, run external programs or read outside the project are refused.' },
|
|
77
|
+
paths: { type: 'array', items: TEXT, description: 'Limit to these paths, relative to the directory.' },
|
|
78
|
+
directory: { ...TEXT, description: 'Directory to run in. Defaults to the project directory; an absolute path may name another listed project directory.' },
|
|
79
|
+
}, ['command']),
|
|
60
80
|
write: tool('write', 'Create or fully replace a UTF-8 text file.', {
|
|
61
81
|
file_path: { ...TEXT, description: 'Path to write, relative to the project directory, or absolute inside another listed project directory. Provide `file_path` before `content` in the arguments.' },
|
|
62
82
|
content: { ...TEXT, description: 'Full UTF-8 text content to write.' },
|
|
@@ -395,7 +415,29 @@ export function write_new_project_file(project, requested, data) {
|
|
|
395
415
|
return file;
|
|
396
416
|
}
|
|
397
417
|
|
|
398
|
-
|
|
418
|
+
/** A read-only git command in one project directory; its paths stay inside the project and away from protected files. */
|
|
419
|
+
function git(project, args) {
|
|
420
|
+
if (!GIT_COMMANDS.includes(args.command)) throw new Error(`command must be one of ${GIT_COMMANDS.join(', ')}`);
|
|
421
|
+
const options = args.args ?? [], paths = args.paths ?? [];
|
|
422
|
+
if (!Array.isArray(options) || !Array.isArray(paths) || [...options, ...paths].some(item => typeof item !== 'string')) throw new Error('args and paths must be arrays of strings');
|
|
423
|
+
for (const option of options) {
|
|
424
|
+
if (option.startsWith('-') ? !GIT_OPTION.test(option) : !GIT_REVISION.test(option)) throw new Error(`"${option}" is not allowed in the git tool`);
|
|
425
|
+
}
|
|
426
|
+
const base = directory_target(project, args.directory);
|
|
427
|
+
const scoped = paths.map(path => relative(base.path, target(project, resolve(base.path, path), false).path) || '.');
|
|
428
|
+
const command = ['-C', base.path, '--no-pager', '-c', 'core.quotepath=false', '-c', 'color.ui=never', args.command,
|
|
429
|
+
...(args.command === 'status' ? [] : ['--no-ext-diff', '--no-textconv']), ...options, '--', ...(scoped.length ? scoped : ['.']), ...GIT_SECRET_EXCLUDES];
|
|
430
|
+
const result = spawnSync('git', command, { encoding: 'utf8', windowsHide: true, timeout: GIT_TIMEOUT_MS, maxBuffer: 16 * 1024 * 1024,
|
|
431
|
+
env: { ...process.env, GIT_PAGER: 'cat', GIT_EXTERNAL_DIFF: '', GIT_TERMINAL_PROMPT: '0' } });
|
|
432
|
+
if (result.error) throw new Error(`git failed: ${result.error.message}`);
|
|
433
|
+
if (result.status !== 0) throw new Error(`git ${args.command} failed: ${(result.stderr || '').trim().slice(0, 500)}`);
|
|
434
|
+
const output = result.stdout || '(no output)';
|
|
435
|
+
const bytes = Buffer.byteLength(output);
|
|
436
|
+
if (bytes <= READ_MAX_BYTES) return output;
|
|
437
|
+
return `${Buffer.from(output).subarray(0, READ_MAX_BYTES).toString('utf8')}\n\n(Output cut at ${READ_MAX_BYTES} of ${bytes} bytes. Narrow it with paths or --stat.)`;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const RUNNERS = { read, glob, grep, git, write, edit };
|
|
399
441
|
|
|
400
442
|
/** Whether a tool name is one of the file tools. */
|
|
401
443
|
export function is_file_tool(name) {
|
|
@@ -17,7 +17,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from
|
|
|
17
17
|
import { homedir } from 'node:os';
|
|
18
18
|
import { dirname, join, resolve } from 'node:path';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
-
import { marked, prompt_text, tree_killable } from './common.mjs';
|
|
20
|
+
import { marked, prompt_text, shell_written_paths, tree_killable } from './common.mjs';
|
|
21
21
|
import { WRITE_TOOLS } from './api_files.mjs';
|
|
22
22
|
import { room_text } from '../room_text.mjs';
|
|
23
23
|
import { adapter_profile, takes_images } from './profiles.mjs';
|
|
@@ -27,8 +27,10 @@ export const PI_PROVIDER = 'codiscuss';
|
|
|
27
27
|
const EXTENSION = fileURLToPath(new URL('./api_pi_extension.mjs', import.meta.url));
|
|
28
28
|
// Our wire protocols and the Pi API that speaks each one.
|
|
29
29
|
const PI_APIS = { responses: 'openai-responses', chat: 'openai-completions', anthropic: 'anthropic-messages', gemini: 'google-generative-ai' };
|
|
30
|
-
// Output cap sent with each request
|
|
31
|
-
|
|
30
|
+
// Output cap sent with each request. Reasoning counts toward it: at 8192 DeepSeek flash spent the whole cap thinking
|
|
31
|
+
// and never reached its tool call (2026-11-17). 32768 leaves room to think and still answer; DeepSeek accepts up to
|
|
32
|
+
// 393216, and the other protocols' current models take at least this much.
|
|
33
|
+
const MAX_OUTPUT_TOKENS = 32768;
|
|
32
34
|
const CONTEXT_WINDOW = 128_000;
|
|
33
35
|
const STOP_GRACE_MS = 3000;
|
|
34
36
|
const EXIT_GRACE_MS = 5000;
|
|
@@ -47,6 +49,10 @@ export function tool_note(name, args = {}) {
|
|
|
47
49
|
return [name, ...shown].join(' ');
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
// A reply cut at the output cap (often all of it spent thinking) is not the end: the model is asked, in the same
|
|
53
|
+
// session, to stop deliberating and submit; only after this many cuts in one execution does it fail.
|
|
54
|
+
export const OUTPUT_CUT_REMINDER = '上一次回复超过单次输出上限被截断,没有完成任何操作。请不要再长篇推理,直接调用工具完成剩下的步骤并提交结果;内容很长时分段写入。';
|
|
55
|
+
const MAX_OUTPUT_CUTS = 2;
|
|
50
56
|
export const NO_TOOL_REMINDER = '普通文本不会被保存。请调用写入工具提交真实结果;确实无法继续才不调用工具直接结束。';
|
|
51
57
|
const API_CALL = { stoppable: true, progress: true };
|
|
52
58
|
|
|
@@ -180,12 +186,15 @@ function on_records(stream, handle) {
|
|
|
180
186
|
* `service_home` (the service directory, whose `pi` folder holds Pi's config and sessions), `spawn_process`.
|
|
181
187
|
* @returns {{status: string, session_id: string, capabilities: object, steer: function}}
|
|
182
188
|
*/
|
|
183
|
-
export function pi_delivery({ cli, profile, key, binding, task, context_file, system_file, prompt, images = [], max_requests, project_root, service_home, spawn_process = spawn }) {
|
|
189
|
+
export function pi_delivery({ cli, profile, key, binding, task, context_file, system_file, prompt, images = [], max_requests, project_root, native_shell = false, service_home, spawn_process = spawn }) {
|
|
184
190
|
const dirs = pi_home(service_home);
|
|
185
191
|
for (const path of Object.values(dirs)) mkdirSync(path, { recursive: true });
|
|
186
192
|
const existing = session_file(dirs.sessions, binding.session_id);
|
|
187
193
|
const session_id = existing ? binding.session_id : randomUUID();
|
|
188
|
-
|
|
194
|
+
// A writable member works as Claude Code or Codex do: Pi's own read, bash, edit and write in the project (user
|
|
195
|
+
// 2026-11-17: Pi is a coding agent like them, do not treat it differently). Read-only keeps our confined file tools:
|
|
196
|
+
// Pi has no sandbox, so its bash could not be held to reading.
|
|
197
|
+
const args = [cli, '--mode', 'rpc', ...(native_shell ? [] : ['--no-builtin-tools']), '--no-context-files', '--no-skills', '--no-prompt-templates',
|
|
189
198
|
'--no-themes', '--no-mcp', '--no-approve', '-e', EXTENSION, '--session-dir', dirs.sessions,
|
|
190
199
|
...(existing ? ['--session', existing] : ['--session-id', session_id]),
|
|
191
200
|
'--provider', PI_PROVIDER, '--model', profile.model, ...(pi_thinking(profile) ? ['--thinking', pi_thinking(profile)] : []),
|
|
@@ -202,7 +211,7 @@ export function pi_delivery({ cli, profile, key, binding, task, context_file, sy
|
|
|
202
211
|
const log = text => {
|
|
203
212
|
try { task.on_output?.(log_path, redact(text)); } catch { /* The room's directory is gone. */ }
|
|
204
213
|
};
|
|
205
|
-
const state = { running: true, terminal: false, stopped: false, failure: '', failure_details: {}, reminded: false, used_tools: false,
|
|
214
|
+
const state = { running: true, terminal: false, stopped: false, failure: '', failure_details: {}, reminded: false, cuts: 0, used_tools: false,
|
|
206
215
|
turns: 0, last_text: '', last_error: '', last_stop: '', last_output: 0, compaction_error: '', diagnostic: '', tools: new Map() };
|
|
207
216
|
const handle = new EventEmitter();
|
|
208
217
|
const send = value => { if (child.stdin.writable) child.stdin.write(`${JSON.stringify(value)}\n`); };
|
|
@@ -253,8 +262,12 @@ export function pi_delivery({ cli, profile, key, binding, task, context_file, sy
|
|
|
253
262
|
// An interjection still queued would make the model answer again after its answer was saved.
|
|
254
263
|
send({ type: 'clear_queue' });
|
|
255
264
|
}
|
|
256
|
-
|
|
257
|
-
|
|
265
|
+
// Our write tools name `file_path`, Pi's own `path`; a bash command that writes claims the paths it names, as for Claude.
|
|
266
|
+
const path = call?.args?.file_path ?? call?.args?.path;
|
|
267
|
+
if (call && WRITE_TOOLS.includes(call.name) && !event.isError && typeof path === 'string' && project_root) task.on_edits?.([resolve(project_root, path)]);
|
|
268
|
+
if (call?.name === 'bash' && project_root) {
|
|
269
|
+
const written = shell_written_paths(call.args?.command).map(item => resolve(project_root, item));
|
|
270
|
+
if (written.length) task.on_edits?.(written);
|
|
258
271
|
}
|
|
259
272
|
} else if (event.type === 'message_end' && event.message?.role === 'assistant') {
|
|
260
273
|
const text = (event.message.content || []).filter(part => part?.type === 'text').map(part => part.text || '').join('').trim();
|
|
@@ -280,6 +293,11 @@ export function pi_delivery({ cli, profile, key, binding, task, context_file, sy
|
|
|
280
293
|
if (state.last_error) { fail(`模型请求失败:${state.last_error}`); return finish(); }
|
|
281
294
|
const reply = state.last_text.slice(0, REPLY_EXCERPT_CHARS);
|
|
282
295
|
// The provider stopped the reply at its output cap: say so as it happened, without guessing why (V14-V16).
|
|
296
|
+
if (state.last_stop === 'length' && state.cuts < MAX_OUTPUT_CUTS) {
|
|
297
|
+
state.cuts += 1;
|
|
298
|
+
task.on_note?.(room_text('回复在 {tokens} 个 token 处达到输出上限被截断,已提醒模型直接提交(第 {count} 次)', { tokens: state.last_output, count: state.cuts }));
|
|
299
|
+
return send({ type: 'prompt', message: OUTPUT_CUT_REMINDER });
|
|
300
|
+
}
|
|
283
301
|
if (state.last_stop === 'length') {
|
|
284
302
|
fail(room_text('模型输出在 {tokens} 个 token 处达到输出上限后结束,未提交结果{reply}',
|
|
285
303
|
{ tokens: state.last_output, reply: reply ? `:${reply}` : '' }), { failure_class: 'output_truncated' });
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Pi extension loaded into the `pi --mode rpc` process of one model API execution (api_pi.mjs starts it). It registers
|
|
3
3
|
* the member's provider and exactly the tools the old in-runner loop offered: room tools bound to this execution,
|
|
4
4
|
* project file tools, registered commands and image tools (api.mjs, api_files.mjs, api_commands.mjs, api_images.mjs).
|
|
5
|
-
* Pi's
|
|
5
|
+
* A writable member also has Pi's own read, bash, edit and write in place of our file tools and registered commands;
|
|
6
|
+
* otherwise Pi's built-in tools are off, so the model has no shell and every path still goes through our checks.
|
|
6
7
|
*
|
|
7
8
|
* Input: `CODISCUSS_PI_CONTEXT` names the execution's private context file; `CODISCUSS_PI_KEY` holds the API key, which
|
|
8
9
|
* the model never sees. Output to the runner: each tool result's `details.codiscuss` says whether it saved the answer
|
|
@@ -13,7 +13,7 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
13
13
|
import { runs_commands } from '../expert_prompts.mjs';
|
|
14
14
|
import { bind_access, cli_max_run_ms, cli_timeout_reason, DENIAL_FIELD, EDIT_TOOLS, edge_entries, launch_directory, log_entries, marked, MAX_DENIALS, model_entry, json_line,
|
|
15
15
|
clock_reset_at, newest_record, not_sent, page_sessions, preview_messages, project_directory, prompt_text, prompt_title, query_catalog,
|
|
16
|
-
same_path, TASK_SUBCOMMANDS, tree_killable, typed_prompt, watch_events } from './common.mjs';
|
|
16
|
+
same_path, TASK_SUBCOMMANDS, tree_killable, typed_prompt, watch_events, shell_written_paths } from './common.mjs';
|
|
17
17
|
|
|
18
18
|
// A message posted to an open Claude window that has not started by then is reported, not failed.
|
|
19
19
|
const INBOX_CHECK_MS = 90_000;
|
|
@@ -28,16 +28,6 @@ const CHAT_TURN_MS = 30 * 60_000;
|
|
|
28
28
|
const LASTING_ERRORS = ['rate_limit', 'authentication_failed'];
|
|
29
29
|
const EDIT_TOOL_NAMES = /^(Edit|MultiEdit|Write|NotebookEdit)$/;
|
|
30
30
|
const SHELL_TOOL_NAMES = /^(Bash|PowerShell)$/;
|
|
31
|
-
// A shell command that may write files: a redirect into a file, an in-place edit, a script writing, a copy, move or
|
|
32
|
-
// delete. Only such a command claims the paths it names; reading commands (cat, grep, git diff) claim none.
|
|
33
|
-
const SHELL_WRITES = /(?<![=\-<>])>{1,2}(?!=)\s*(?!&|\/dev\/null|\$null|nul\b)|\bsed\s+-i|\.write\w*\(|write_text|writeFileSync|\b(?:Set|Add)-Content\b|\bOut-File\b|\btee\b|\b(?:mv|cp|rm)\s|\b(?:Move|Copy|Remove|Rename)-Item\b|\bgit\s+(?:checkout|restore|apply|mv|rm)\b/i;
|
|
34
|
-
|
|
35
|
-
/** The paths a file-writing shell command names (with a folder or an extension), so files it wrote count as the agent's own. */
|
|
36
|
-
function shell_written_paths(command) {
|
|
37
|
-
const text = String(command || '');
|
|
38
|
-
if (!SHELL_WRITES.test(text)) return [];
|
|
39
|
-
return text.split(/[\s'"`;|&<>(),=]+/).filter(token => /[\\/]/.test(token) && /\.[\w-]+$/.test(token));
|
|
40
|
-
}
|
|
41
31
|
// The Messages API refuses an image whose base64 form passes 5 MB, failing the whole turn; larger ones go by path only.
|
|
42
32
|
const MAX_INLINE_IMAGE_BYTES = 3_750_000;
|
|
43
33
|
// Claude Code logs side queries (titles, compaction, subagents) too; only these sources are the member's own turns.
|
|
@@ -19,7 +19,17 @@ export function cli_timeout_reason(milliseconds) {
|
|
|
19
19
|
return t('CLI 运行超过 {seconds} 秒仍未结束,已终止', { seconds: Math.round(milliseconds / 1000) });
|
|
20
20
|
}
|
|
21
21
|
/** Tool names that edit files, across the softwares' event streams. */
|
|
22
|
-
|
|
22
|
+
// A shell command that may write files: a redirect into a file, an in-place edit, a script writing, a copy, move or
|
|
23
|
+
// delete. Only such a command claims the paths it names; reading commands (cat, grep, git diff) claim none.
|
|
24
|
+
const SHELL_WRITES = /(?<![=\-<>])>{1,2}(?!=)\s*(?!&|\/dev\/null|\$null|nul\b)|\bsed\s+-i|\.write\w*\(|write_text|writeFileSync|\b(?:Set|Add)-Content\b|\bOut-File\b|\btee\b|\b(?:mv|cp|rm)\s|\b(?:Move|Copy|Remove|Rename)-Item\b|\bgit\s+(?:checkout|restore|apply|mv|rm)\b/i;
|
|
25
|
+
|
|
26
|
+
/** The paths a file-writing shell command names (with a folder or an extension), so files it wrote count as the agent's own. */
|
|
27
|
+
export function shell_written_paths(command) {
|
|
28
|
+
const text = String(command || '');
|
|
29
|
+
if (!SHELL_WRITES.test(text)) return [];
|
|
30
|
+
return text.split(/[\s'"`;|&<>(),=]+/).filter(token => /[\\/]/.test(token) && /\.[\w-]+$/.test(token));
|
|
31
|
+
}
|
|
32
|
+
export const EDIT_TOOLS = /^(Edit|MultiEdit|Write|NotebookEdit|write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content)$/;
|
|
23
33
|
/** A refused operation's detail and rule are cut to this length; a run reports at most this many. */
|
|
24
34
|
export const DENIAL_FIELD = 300;
|
|
25
35
|
export const MAX_DENIALS = 20;
|
|
@@ -137,8 +137,8 @@ export const ADAPTER_PROFILES = {
|
|
|
137
137
|
// so only the three levels every protocol takes are offered. A chat endpoint without a reasoning parameter ignores it.
|
|
138
138
|
efforts: ['low', 'medium', 'high'], models: false, access_levels: ['read', 'write'], per_tool_allow: false, adopt: '', host_existing: false,
|
|
139
139
|
access_hints: { read: '用接入程序的文件工具读取、搜索项目文件,可运行工作流登记的只读命令',
|
|
140
|
-
write: '
|
|
141
|
-
unsupported_hints: { auto: '
|
|
140
|
+
write: '用 Pi 自带的读写、编辑与命令行在项目里工作,和本地 CLI 可写一致;Pi 没有审批,可写即可直接运行命令' },
|
|
141
|
+
unsupported_hints: { auto: 'Pi 没有需要软件审批的操作,可写即可直接运行命令', full: 'Pi 没有需要软件审批的操作,可写即可直接运行命令' },
|
|
142
142
|
// Runs in the Pi harness (api_pi.mjs), which keeps a session the runner cuts like a CLI's.
|
|
143
143
|
// Whether a model reads images depends on the model, not the protocol: the owner says so on the card (`image_input`).
|
|
144
144
|
// Its answer is only what submit_chat saves (an unknown result is recovered by the same submission), never its last text.
|