@unionschool/easy-agents 1.0.24 → 1.0.34
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/bin/run.js +1 -1
- package/bin/tasks.js +51 -13
- package/package.json +1 -1
- package/runtime/desktop_chat.py +7 -2
- package/runtime/easyagents_core/git_sync.py +48 -0
- package/runtime/easyagents_core/member_sync.py +2 -1
- package/runtime/task_run.py +18 -2
package/bin/run.js
CHANGED
|
@@ -238,7 +238,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
if (signal.aborted) break;
|
|
241
|
-
// steer(协议第 16 节):桌面版的 Claude、Codex、Agy
|
|
241
|
+
// steer(协议第 16 节):桌面版的 Claude、Codex、Agy 对话,以及 Claude、Codex 的任务运行(2026-11-23)支持运行中补充;纯 npm 不支持。
|
|
242
242
|
// Cursor 实测只能取消当前一轮再发新的,不算补充(2026-11-23)。
|
|
243
243
|
const steer = { claude_code: taskDelivery(), codex: taskDelivery(), cursor: false, antigravity: taskDelivery() };
|
|
244
244
|
const hello = { type: 'hello', client_version: version, tools: [], terminal, task_delivery: taskDelivery(), doc_read: taskDelivery(), steer, ...metadata };
|
package/bin/tasks.js
CHANGED
|
@@ -86,26 +86,64 @@ function desktopConversation(resources, content, prompt, signal, credential, too
|
|
|
86
86
|
const TASK_KINDS = ['execute', 'review', 'deploy', 'clarify'];
|
|
87
87
|
|
|
88
88
|
// Mac and Ubuntu desktop installs: Git task-branch runs go to the packaged Python runner.
|
|
89
|
+
// 任务运行(执行、审核、部署、答疑):首行 JSON 是运行内容;之后 stdin 保持打开,任务对话里发给正在干活的人员的话
|
|
90
|
+
// 按行写入(运行中补充,2026-11-23),子进程从 fd 3 逐行回执,stdout 只放最终结果。
|
|
89
91
|
function desktopTask(resources, content, signal, options) {
|
|
90
92
|
const runner = fileURLToPath(new URL('../runtime/task_run.py', import.meta.url));
|
|
91
93
|
const seconds = content.timeout_seconds;
|
|
92
94
|
const timeout = Number.isSafeInteger(seconds) && seconds > 0 ? Math.min(seconds, 3600) : 3600;
|
|
93
95
|
const input = { content, timeout, credential: options.credential, worktrees: join(options.configDir, 'worktrees') };
|
|
96
|
+
const onSteer = options.onSteer;
|
|
94
97
|
return new Promise(resolveResult => {
|
|
98
|
+
const child = spawn(join(resources, 'python/bin/python3'), ['-I', '-B', '-X', 'utf8', runner],
|
|
99
|
+
{ stdio: ['pipe', 'pipe', 'ignore', 'pipe'], windowsHide: true });
|
|
100
|
+
const waiting = new Map();
|
|
101
|
+
let stdout = '', size = 0, settled = false, acks = '';
|
|
102
|
+
const finish = result => {
|
|
103
|
+
if (settled) return;
|
|
104
|
+
settled = true;
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
signal.removeEventListener('abort', cancel);
|
|
107
|
+
onSteer?.(null);
|
|
108
|
+
for (const done of waiting.values()) done('too_late');
|
|
109
|
+
waiting.clear();
|
|
110
|
+
resolveResult(result);
|
|
111
|
+
};
|
|
95
112
|
// Fetch, checkout and push get their own Git timeouts on top of the tool's.
|
|
96
|
-
const
|
|
97
|
-
{ timeout: (timeout + 600) * 1000, maxBuffer: 8 * 1024 * 1024 }, (error, stdout) => {
|
|
98
|
-
signal.removeEventListener('abort', cancel);
|
|
99
|
-
if (signal.aborted) return resolveResult({ status: 'cancelled', failure_code: 'cancelled' });
|
|
100
|
-
if (!error) {
|
|
101
|
-
try { return resolveResult(JSON.parse(stdout)); } catch {}
|
|
102
|
-
}
|
|
103
|
-
resolveResult({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' });
|
|
104
|
-
});
|
|
113
|
+
const timer = setTimeout(() => child.kill('SIGTERM'), (timeout + 600) * 1000);
|
|
105
114
|
const cancel = () => child.kill('SIGTERM');
|
|
115
|
+
child.stdout.on('data', chunk => {
|
|
116
|
+
size += chunk.length;
|
|
117
|
+
if (size > 8 * 1024 * 1024) { child.kill('SIGTERM'); return; }
|
|
118
|
+
stdout += chunk;
|
|
119
|
+
});
|
|
120
|
+
child.stdio[3].on('data', chunk => {
|
|
121
|
+
acks += chunk;
|
|
122
|
+
let line;
|
|
123
|
+
while ((line = acks.indexOf('\n')) >= 0) {
|
|
124
|
+
const raw = acks.slice(0, line); acks = acks.slice(line + 1);
|
|
125
|
+
try {
|
|
126
|
+
const ack = JSON.parse(raw);
|
|
127
|
+
waiting.get(ack.message_id)?.(ack.status);
|
|
128
|
+
waiting.delete(ack.message_id);
|
|
129
|
+
} catch {}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
child.on('error', () => finish({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' }));
|
|
133
|
+
child.on('close', () => {
|
|
134
|
+
if (signal.aborted) return finish({ status: 'cancelled', failure_code: 'cancelled' });
|
|
135
|
+
try { return finish(JSON.parse(stdout)); } catch {}
|
|
136
|
+
finish({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' });
|
|
137
|
+
});
|
|
106
138
|
signal.addEventListener('abort', cancel, { once: true });
|
|
107
139
|
child.stdin.on('error', () => {});
|
|
108
|
-
child.stdin.
|
|
140
|
+
child.stdin.write(JSON.stringify(input) + '\n');
|
|
141
|
+
onSteer?.((messageId, text) => new Promise(done => {
|
|
142
|
+
if (settled || !child.stdin.writable) return done('too_late');
|
|
143
|
+
const timeoutAck = setTimeout(() => { waiting.delete(messageId); done('failed'); }, 9000);
|
|
144
|
+
waiting.set(messageId, status => { clearTimeout(timeoutAck); done(status); });
|
|
145
|
+
child.stdin.write(JSON.stringify({ type: 'steer', message_id: messageId, content: text }) + '\n');
|
|
146
|
+
}));
|
|
109
147
|
if (signal.aborted) cancel();
|
|
110
148
|
});
|
|
111
149
|
}
|
|
@@ -164,7 +202,7 @@ export async function execute(content, signal, workCredential, { agentCredential
|
|
|
164
202
|
if (signal.aborted) return { status: 'cancelled', failure_code: 'cancelled' };
|
|
165
203
|
return { status: 'failed', failure_code: 'mcp_credential', failure_detail: '无法取得操作入口凭据,请检查设备认证及平台状态' };
|
|
166
204
|
}
|
|
167
|
-
return desktopTask(resources, content, signal, { credential, configDir });
|
|
205
|
+
return desktopTask(resources, content, signal, { credential, configDir, onSteer });
|
|
168
206
|
}
|
|
169
207
|
let prompt = content.prompt;
|
|
170
208
|
const task = content.run_kind === 'execute' && content.task;
|
|
@@ -185,9 +223,9 @@ export async function execute(content, signal, workCredential, { agentCredential
|
|
|
185
223
|
return { status: 'succeeded', reply_text: digest };
|
|
186
224
|
}
|
|
187
225
|
if (task && content.prompt) prompt = content.prompt + '\n\n' + prompt;
|
|
188
|
-
// Agy 只接对话(2026-11-23),任务运行仍只有 Codex、Claude。
|
|
226
|
+
// Agy、Cursor 只接对话(2026-11-23),任务运行仍只有 Codex、Claude。
|
|
189
227
|
if (resources && (['codex', 'claude_code'].includes(content.agent?.tool_type) && (task || content.run_kind === 'chat')
|
|
190
|
-
|| content.agent?.tool_type
|
|
228
|
+
|| ['antigravity', 'cursor'].includes(content.agent?.tool_type) && content.run_kind === 'chat')) {
|
|
191
229
|
let credential;
|
|
192
230
|
// Same rule as the platform: only chat_mode 'chat' is a plain conversation. Workflow notifications to the lead
|
|
193
231
|
// (merge after deploy, answers, sync handoff) arrive with an empty chat_mode and must be able to act.
|
package/package.json
CHANGED
package/runtime/desktop_chat.py
CHANGED
|
@@ -13,7 +13,7 @@ sys.path.insert(0, str(Path(resources) / "lib"))
|
|
|
13
13
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
14
14
|
# 工具适配器用 npm 核心包自带的那份(只依赖标准库),不用安装包 lib 里打包时的旧副本:
|
|
15
15
|
# 这样 /compact、/steer 等适配器修复随核心更新生效,不必重装应用(2026-11-23)。
|
|
16
|
-
from runtime.easyagents_core.tools import NO_OUTPUT_TEXT, AntigravityAdapter, ClaudeCodeAdapter, CodexAdapter, SteerError
|
|
16
|
+
from runtime.easyagents_core.tools import NO_OUTPUT_TEXT, AntigravityAdapter, ClaudeCodeAdapter, CodexAdapter, CursorAdapter, SteerError
|
|
17
17
|
from runtime.platform_prompt import platform_entry
|
|
18
18
|
|
|
19
19
|
# 聊天模式不是限制、是为了快(用户 2026-11-23:“chat 模式是为了减少聊天时间,不用花时间去看项目”“chat 的模式不是限制,是不用 agent 去看项目内容,除非用户有要求看项目”“聊天要使用工具”):
|
|
@@ -137,11 +137,16 @@ def run(content, cancelled):
|
|
|
137
137
|
# Agy 没有附加系统说明的参数,建议回复格式暂不告知。
|
|
138
138
|
adapter = AntigravityAdapter()
|
|
139
139
|
options = {}
|
|
140
|
+
elif tool == "cursor":
|
|
141
|
+
# Cursor 对话(2026-11-23:飞书私聊给 Cursor 发消息,独立客户端连回四次“不支持”):cursor-agent -p,
|
|
142
|
+
# 聊天、工作同一套参数。没有附加系统说明的参数,建议回复格式暂不告知;不支持运行中补充(平台改为排队)。
|
|
143
|
+
adapter = CursorAdapter()
|
|
144
|
+
options = {}
|
|
140
145
|
else:
|
|
141
146
|
return failed("unsupported_task", "此工具尚未接入设备文本对话")
|
|
142
147
|
if not shutil.which(adapter.executable):
|
|
143
148
|
return failed("tool_missing", "本机未找到 " + adapter.executable_name)
|
|
144
|
-
adapter.instructions = instructions_for(tool, tools, command) if tool
|
|
149
|
+
adapter.instructions = instructions_for(tool, tools, command) if tool not in ("antigravity", "cursor") else None
|
|
145
150
|
if content.get("_on_adapter"):
|
|
146
151
|
content["_on_adapter"](adapter)
|
|
147
152
|
|
|
@@ -78,6 +78,53 @@ def _address(value: str) -> str:
|
|
|
78
78
|
return value.rstrip("/").removesuffix(".git")
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
LOCKFILES = ('pnpm-lock.yaml', 'package-lock.json', 'yarn.lock')
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def link_dependencies(root: Path, worktree: Path) -> list[str]:
|
|
85
|
+
"""独立工作树复用原目录已装好的 node_modules(2026-11-23 T-176:执行者、审核人每次都在新工作树里重装工作台依赖)。
|
|
86
|
+
只在锁文件与原目录逐字节相同时建软链接;锁文件不同、原目录没装、工作树里已有的都不动。尽力而为,失败不影响运行。
|
|
87
|
+
node_modules 被 .gitignore 忽略,不算未提交改动;git worktree remove 只删链接,不删原目录的依赖。"""
|
|
88
|
+
linked = []
|
|
89
|
+
try:
|
|
90
|
+
listing = git(worktree, 'ls-files', '-z', '--', 'package.json', '*/package.json')
|
|
91
|
+
except GitError:
|
|
92
|
+
return linked
|
|
93
|
+
for name in filter(None, listing.split('\0')):
|
|
94
|
+
folder = Path(name).parent
|
|
95
|
+
if 'node_modules' in folder.parts:
|
|
96
|
+
continue
|
|
97
|
+
source, target = root / folder / 'node_modules', worktree / folder / 'node_modules'
|
|
98
|
+
if not source.is_dir() or target.exists() or target.is_symlink():
|
|
99
|
+
continue
|
|
100
|
+
same = [lock for lock in LOCKFILES if (root / folder / lock).is_file() and (worktree / folder / lock).is_file()
|
|
101
|
+
and (root / folder / lock).read_bytes() == (worktree / folder / lock).read_bytes()]
|
|
102
|
+
if not same:
|
|
103
|
+
continue
|
|
104
|
+
try:
|
|
105
|
+
target.symlink_to(source, target_is_directory=True)
|
|
106
|
+
linked.append(folder.as_posix())
|
|
107
|
+
except OSError:
|
|
108
|
+
continue
|
|
109
|
+
if linked:
|
|
110
|
+
_exclude_links(worktree)
|
|
111
|
+
return linked
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _exclude_links(worktree: Path) -> None:
|
|
115
|
+
"""仓库常写 `node_modules/`,带斜杠只匹配目录,软链接会显示成未跟踪文件,同步就不肯清理这个工作树。
|
|
116
|
+
在各工作树共用的本地排除文件里补一行不带斜杠的 `node_modules`(不进 Git)。"""
|
|
117
|
+
try:
|
|
118
|
+
exclude = Path(git(worktree, 'rev-parse', '--path-format=absolute', '--git-common-dir')) / 'info' / 'exclude'
|
|
119
|
+
text = exclude.read_text() if exclude.is_file() else ''
|
|
120
|
+
if 'node_modules' not in text.splitlines():
|
|
121
|
+
exclude.parent.mkdir(parents=True, exist_ok=True)
|
|
122
|
+
gap = '' if not text or text.endswith('\n') else '\n'
|
|
123
|
+
exclude.write_text(text + gap + '# EasyAgents 客户端:独立工作树里复用依赖的软链接\nnode_modules\n')
|
|
124
|
+
except (GitError, OSError):
|
|
125
|
+
pass
|
|
126
|
+
|
|
127
|
+
|
|
81
128
|
class GitWorkspace:
|
|
82
129
|
def __init__(self, cwd: Path, content: dict, cancel: threading.Event, worktrees: Path | None = None):
|
|
83
130
|
self.cwd, self.cancel = cwd, cancel
|
|
@@ -203,6 +250,7 @@ class GitWorkspace:
|
|
|
203
250
|
except OSError:
|
|
204
251
|
raise GitError('git_worktree', '无法建立隔离工作树目录') from None
|
|
205
252
|
self.run('worktree', 'add', '--detach', str(path), commit)
|
|
253
|
+
link_dependencies(root, path)
|
|
206
254
|
self.cwd = path / subdirectory
|
|
207
255
|
if not self.cwd.is_dir():
|
|
208
256
|
raise GitError('workspace_missing', '独立工作树缺少已登记的子目录')
|
|
@@ -110,6 +110,8 @@ def run(cwd: Path, content: dict, cancel: threading.Event, worktrees: Path | Non
|
|
|
110
110
|
return ToolResult(status="failed", failure_code="git_ahead", workspace_sync="sync_diverged",
|
|
111
111
|
failure_detail=f"本地 {default} 领先远程 {ahead} 个提交,交给智能体核对后推送")
|
|
112
112
|
notes = [f"已切回 {default} 并快进到远程最新"]
|
|
113
|
+
# 先清工作树再删分支:任务分支检出在部署人等的工作树里时删不掉(2026-11-23 T-177 本地任务分支因此留下)
|
|
114
|
+
removed = _remove_task_worktrees(root, branch or "", worktrees, cancel) if branch else []
|
|
113
115
|
if branch and _exists(root, f"refs/heads/{branch}", cancel):
|
|
114
116
|
try:
|
|
115
117
|
# -d 只删已合并的分支,未合并的保留。
|
|
@@ -117,7 +119,6 @@ def run(cwd: Path, content: dict, cancel: threading.Event, worktrees: Path | Non
|
|
|
117
119
|
notes.append(f"已删除本地任务分支 {branch}")
|
|
118
120
|
except GitError:
|
|
119
121
|
notes.append(f"本地任务分支 {branch} 有未合并提交,已保留")
|
|
120
|
-
removed = _remove_task_worktrees(root, branch or "", worktrees, cancel) if branch else []
|
|
121
122
|
if removed:
|
|
122
123
|
notes.append("已清理独立工作树 " + "、".join(removed))
|
|
123
124
|
return ToolResult(status="succeeded", reply_text=";".join(notes) + "。", workspace_sync="synced")
|
package/runtime/task_run.py
CHANGED
|
@@ -66,6 +66,8 @@ def run(request, cancelled):
|
|
|
66
66
|
return failed("unsupported_task", "此工具尚未接入独立客户端的任务运行")
|
|
67
67
|
if not shutil.which(adapter.executable):
|
|
68
68
|
return failed("tool_missing", "本机未找到 " + adapter.executable_name)
|
|
69
|
+
if request.get("_on_adapter"):
|
|
70
|
+
request["_on_adapter"](adapter) # 运行中补充:任务对话里给正在干活的人员发的话送进这一轮(2026-11-23)
|
|
69
71
|
resume = content.get("resume_session_ref")
|
|
70
72
|
if resume is not None:
|
|
71
73
|
try:
|
|
@@ -115,7 +117,21 @@ def run(request, cancelled):
|
|
|
115
117
|
return body
|
|
116
118
|
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
def main():
|
|
119
121
|
cancelled = threading.Event()
|
|
120
122
|
signal.signal(signal.SIGTERM, lambda *_: cancelled.set())
|
|
121
|
-
|
|
123
|
+
# 首行是运行内容;之后 stdin 保持打开,每行一条补充,回执写 fd 3(与对话运行同一协议,客户端协议第 16 节)。
|
|
124
|
+
request = json.loads(sys.stdin.readline())
|
|
125
|
+
try:
|
|
126
|
+
acks = os.fdopen(3, "w")
|
|
127
|
+
except OSError:
|
|
128
|
+
acks = None
|
|
129
|
+
if acks is not None:
|
|
130
|
+
from runtime.desktop_chat import serve_steers
|
|
131
|
+
request["_on_adapter"] = lambda adapter: threading.Thread(
|
|
132
|
+
target=serve_steers, args=(adapter, acks), daemon=True).start()
|
|
133
|
+
print(json.dumps(run(request, cancelled), ensure_ascii=False))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
main()
|