@unionschool/easy-agents 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/bin/easy-agents.js +18 -0
- package/bin/run.js +11 -26
- package/bin/tasks.js +64 -15
- package/package.json +8 -4
- package/runtime/easyagents_core/mcp_call.py +24 -2
- package/runtime/mcp.py +16 -0
- package/runtime/sync.py +4 -1
- package/runtime/task_run.py +134 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
| 设备 | 安装和打开 | 设备配置位置 |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| macOS 14+ |
|
|
9
|
+
| macOS 14+ | Intel 和 Apple 芯片都使用 `EasyAgents-Mac-Universal.zip`。解压后把 `EasyAgents Client.app` 拖入「应用程序」并打开,点菜单栏图标。 | `~/Library/Application Support/EasyAgents Client/` |
|
|
10
10
|
| Windows x64 | 双击 `EasyAgents-Setup.exe`,按当前用户安装。从开始菜单打开 **EasyAgents Client**,以后可点托盘图标。在新终端输入 `easy-agents` 也可打开面板。 | `%APPDATA%\EasyAgents\` |
|
|
11
11
|
| Ubuntu x64 | 在压缩包所在目录执行下面两行,以运行客户端的普通用户安装。 | `~/.easyagents/` |
|
|
12
12
|
| Android 8+ | 安装交付的 `EasyAgents-Android-test.apk`,打开应用,用 Linux 设备配对码接入,点「上线接任务」。前台通知显示服务状态。 | 应用私有存储和 Android Keystore |
|
|
@@ -74,6 +74,7 @@ npm exec --offline -- easy-agents run
|
|
|
74
74
|
| `easy-agents autostart on` / `off` | 切换开机启动。系统可能要求管理员授权 |
|
|
75
75
|
| `easy-agents update`、`auto-update on` / `off` | 检查兼容的 npm 稳定版核心或切换自动检查。重连验证失败会回退,原生面板和内置解释器通过安装包升级 |
|
|
76
76
|
| `easy-agents terminal on` / `off` | 在支持的 Unix 设备上切换工作台网页终端 |
|
|
77
|
+
| `easy-agents agent-credential <Agent编号>` | 为本机设备上的 Agent 检查平台凭据,缺失或被撤销(401)时领取新凭据(旧凭据随之作废),只输出凭据文件路径。负责人在本机用 `skills/easyagents-task/register.py` 登记任务前用它 |
|
|
77
78
|
|
|
78
79
|
## 已安装设备怎么升级
|
|
79
80
|
|
|
@@ -85,10 +86,14 @@ npm exec --offline -- easy-agents run
|
|
|
85
86
|
|
|
86
87
|
## 各端能执行什么
|
|
87
88
|
|
|
89
|
+
- Mac 和 Ubuntu 安装包能接平台任务分支上的执行、审核、部署和澄清运行(Codex、Claude,完整权限,与旧 Python 客户端的规则一致):执行在任务分支上工作并在成功后推送;审核和部署检出本轮交付的提交;工作目录有未提交改动时,在客户端配置目录的 `worktrees/` 里另建工作树,原目录不动,合并后的成员同步会清理这些工作树。Agent 通过提示里给出的平台命令调用工具;Agent 凭据缺失或已被平台撤销时,客户端自动领取新凭据(平台会同时撤销旧凭据)。旧的同目录文件交付和用户发布命令(`publish`)不支持。
|
|
90
|
+
- **未完成**:Windows、Android 和单独运行的普通 npm 版还不能接任务分支运行,会回报 `handoff_unsupported`。这几端暂时用不上(用户 2026-11-22 定),以后需要时再单独升级。
|
|
88
91
|
- Mac 和 Ubuntu 安装包支持 Codex、Claude 的文本对话、续聊和本地文本任务。它们可从项目卡片或对话页接收聊天和工作消息。工作消息可用已有 Agent 凭据读取平台任务规程。Codex 使用只读会话,Claude 使用纯文本会话。可用的会话编号、模型与用量会随结果回传。
|
|
89
92
|
- Mac 和 Windows 面板可显示检测到的 Codex、Claude、Cursor、Agy 登录和上报状态。平台控制额度上报开关,绿色胶囊显示已获得的剩余额度,测得零时显示零。Windows 和单独运行的普通 npm 版支持单次 Claude 文本任务,使用 bare 模式可用的认证。桌面对话功能需要安装包提供的工具适配和内置运行环境。
|
|
90
93
|
- 在支持的 Unix 主机上,网页终端使用本机运行用户进行 SSH 登录,需要 Python 3、OpenSSH、可读的本机 SSH 公钥和监听回环端口 22 的 SSH 服务。可在工作台的「AI → 设备管理 → 终端」打开。普通 npm 可在启动前用 `EASYAGENTS_TERMINAL=0` 关闭。
|
|
91
94
|
- Node 核心支持 `/sha256 <文本>`、本地 Markdown 文档里的同类计算和成员同步。文档与同步的目录需与本机选定工作目录相符,可用 `EASYAGENTS_WORKSPACE` 指定。成员同步使用包内实现、系统 Git 和 Python 3.10+,更新已有检出目录。Android 首版可执行 SHA-256 消息和用户选择目录里的计算文档。
|
|
92
|
-
-
|
|
95
|
+
- 客户端保存待回传结果,重连后补传。独立版尚未接入运行中 `/steer`、手动 `/sync`、平台远程读文档和编辑设备上的工具规则。
|
|
93
96
|
|
|
94
|
-
开发者在 `new-client/` 中执行 `npm ci`、`npm pack`
|
|
97
|
+
开发者在 `new-client/` 中执行 `npm ci`、`npm pack` 构建通用包。包内包含 `runtime/easyagents_core/` 中的 Git、文件交付和 MCP 模块及其进程支持,并随包附带 WebSocket 依赖。桌面安装器从同一目录取工具、模型、额度和平台 API 模块,按 `scripts/desktop-requirements.txt` 安装固定版本的 Python 依赖。
|
|
98
|
+
|
|
99
|
+
在 Mac 上,从仓库根目录运行 `uv run --no-project --python 3.12 python new-client/macos/install.py --zip /path/to/EasyAgents-Mac-Universal.zip` 生成通用 ZIP。该模式只写出压缩包。菜单栏程序、Node 和内置 Python 都包含 `x86_64` 与 `arm64`。
|
package/bin/easy-agents.js
CHANGED
|
@@ -92,6 +92,7 @@ try {
|
|
|
92
92
|
+ 'easy-agents configure <网关地址> <端口>\n'
|
|
93
93
|
+ 'easy-agents pair\n'
|
|
94
94
|
+ 'easy-agents run\n'
|
|
95
|
+
+ 'easy-agents agent-credential <Agent编号>\n'
|
|
95
96
|
+ 'easy-agents status' + (desktop ? '\neasy-agents show | start | stop | restart | logs | doctor | update\neasy-agents auto-update on|off\neasy-agents autostart on|off\neasy-agents terminal on|off\neasy-agents accounts --json' : ''));
|
|
96
97
|
} else if (['--version', '-v'].includes(command) && !args.length) {
|
|
97
98
|
console.log(version);
|
|
@@ -208,6 +209,23 @@ try {
|
|
|
208
209
|
+ '\n当前任务:' + (status.task || '空闲') + '\n最近回传:' + (status.report.lastResult?.status || '暂无')
|
|
209
210
|
+ '\n开机启动:' + (status.autostart ? '开启' : '关闭') + '\n自动更新:' + (status.autoUpdate ? '开启' : '关闭')
|
|
210
211
|
+ (status.updateMessage ? '\n更新:' + status.updateMessage : '') : ''));
|
|
212
|
+
} else if (command === 'agent-credential' && args.length === 1) {
|
|
213
|
+
// Gives the lead a working credential for this device's agent to call the platform tools locally
|
|
214
|
+
// (for example skills/easyagents-task/register.py). Prints only the file path, never the token.
|
|
215
|
+
const device = readSettings(devicePath);
|
|
216
|
+
if (!device) throw new Error('请先配对设备');
|
|
217
|
+
const { ensureAgentCredential } = await import('./credentials.js');
|
|
218
|
+
const origin = new URL(device.gateway).origin;
|
|
219
|
+
const file = await ensureAgentCredential({ configDir, origin, id: args[0], version, signal: AbortSignal.timeout(60000),
|
|
220
|
+
issue: async id => {
|
|
221
|
+
const res = await fetch(new URL('/api/client/agents/' + id + '/credential', origin), { method: 'POST', redirect: 'error',
|
|
222
|
+
headers: { Authorization: 'Bearer ' + device.device_token, 'Content-Type': 'application/json' }, body: '{}',
|
|
223
|
+
signal: AbortSignal.timeout(20000) });
|
|
224
|
+
const data = await res.json().catch(() => null);
|
|
225
|
+
if (!res.ok || data?.code !== 0) throw new Error('平台没有发放凭据(HTTP ' + res.status + (data?.msg ? ',' + data.msg : '') + ')');
|
|
226
|
+
return data.data;
|
|
227
|
+
} });
|
|
228
|
+
console.log(file);
|
|
211
229
|
} else {
|
|
212
230
|
throw new Error('命令或参数无效。请运行 easy-agents --help');
|
|
213
231
|
}
|
package/bin/run.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { homedir } from 'node:os';
|
|
2
|
+
import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
6
5
|
import WebSocket from 'ws';
|
|
7
6
|
import { execute } from './tasks.js';
|
|
8
7
|
import { openTerminal, terminalAvailable } from './terminal.js';
|
|
9
8
|
import { protectDeviceFile } from './pair.js';
|
|
9
|
+
import { ensureAgentCredential, findAgentCredential } from './credentials.js';
|
|
10
10
|
|
|
11
11
|
const validId = id => typeof id === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(id);
|
|
12
12
|
|
|
@@ -41,7 +41,8 @@ export async function runDevice(device, configDir, version, signal, { reporter,
|
|
|
41
41
|
let socket, worker, online = false, active, fatal;
|
|
42
42
|
const gatewayRequest = async (method, path, body, extraSignal) => {
|
|
43
43
|
const res = await fetch(new URL(path, url), { method,
|
|
44
|
-
|
|
44
|
+
// Without the Git delivery header the platform withholds task-branch runs (42298).
|
|
45
|
+
headers: { ...headers, 'X-EasyAgents-Git-Delivery': '1', 'Content-Type': 'application/json' }, redirect: 'error',
|
|
45
46
|
signal: AbortSignal.any([signal, AbortSignal.timeout(20000), ...(extraSignal ? [extraSignal] : [])]),
|
|
46
47
|
body: body === undefined ? undefined : JSON.stringify(body) });
|
|
47
48
|
const data = await res.json().catch(() => null);
|
|
@@ -52,23 +53,12 @@ export async function runDevice(device, configDir, version, signal, { reporter,
|
|
|
52
53
|
const request = (method, path, body) => gatewayRequest(method, '/api/client/runs/' + path, body);
|
|
53
54
|
const reportQuota = (id, body, cancel) => gatewayRequest('POST', '/api/client/agents/' + id + '/quota', body, cancel);
|
|
54
55
|
function workCredential(content) {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const dir = join(configDir, 'agents');
|
|
58
|
-
const file = join(dir, id + '.json');
|
|
59
|
-
const files = [file];
|
|
60
|
-
if (process.platform === 'darwin' && configDir === join(homedir(), 'Library/Application Support/EasyAgents Client')) {
|
|
61
|
-
files.push(join(homedir(), '.easyagents', 'agents', id + '.json'));
|
|
62
|
-
}
|
|
63
|
-
for (const path of files) {
|
|
64
|
-
try {
|
|
65
|
-
const info = lstatSync(path);
|
|
66
|
-
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077)) throw new Error('Agent 凭据文件无效');
|
|
67
|
-
return { file: path, gateway: url.origin };
|
|
68
|
-
} catch (err) { if (err.code !== 'ENOENT') throw err; }
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
56
|
+
const file = findAgentCredential(configDir, content.agent?.agent_id);
|
|
57
|
+
return file ? { file, gateway: url.origin } : null;
|
|
71
58
|
}
|
|
59
|
+
// Task runs need a working Agent credential for the platform tools (credentials.js).
|
|
60
|
+
const agentCredential = content => ensureAgentCredential({ configDir, origin: url.origin, id: content.agent?.agent_id,
|
|
61
|
+
version, signal, issue: id => gatewayRequest('POST', '/api/client/agents/' + id + '/credential', {}) });
|
|
72
62
|
function checkDrained() {
|
|
73
63
|
if (drain?.aborted && !active && !queue.size && !readdirSync(folder).some(f => f.endsWith('.json'))) onDrained?.();
|
|
74
64
|
}
|
|
@@ -100,16 +90,11 @@ export async function runDevice(device, configDir, version, signal, { reporter,
|
|
|
100
90
|
rmSync(join(folder, id + '.json'), { force: true });
|
|
101
91
|
return;
|
|
102
92
|
}
|
|
103
|
-
|
|
104
|
-
try { content = await request('GET', id); }
|
|
105
|
-
catch (err) {
|
|
106
|
-
if (err.code !== 42298) throw err;
|
|
107
|
-
result = { status: 'failed', failure_code: 'git_delivery_unsupported', failure_detail: '此版尚不支持 Git 任务分支交付' };
|
|
108
|
-
}
|
|
93
|
+
const content = await request('GET', id);
|
|
109
94
|
await request('POST', id + '/start', { tool_version: version });
|
|
110
95
|
checkpoint(id, { started: true });
|
|
111
96
|
if (ack?.status === 'running') result = { status: 'interrupted', failure_code: 'client_interrupted' };
|
|
112
|
-
try { result ??= await execute(content, controller.signal, workCredential); }
|
|
97
|
+
try { result ??= await execute(content, controller.signal, workCredential, { agentCredential, configDir }); }
|
|
113
98
|
catch { result = controller.signal.aborted ? { status: 'cancelled', failure_code: 'cancelled' } :
|
|
114
99
|
{ status: 'failed', failure_code: 'client_error', failure_detail: '客户端执行失败' }; }
|
|
115
100
|
}
|
package/bin/tasks.js
CHANGED
|
@@ -39,24 +39,59 @@ function desktopConversation(resources, content, prompt, signal, credential) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const TASK_KINDS = ['execute', 'review', 'deploy', 'clarify'];
|
|
43
|
+
|
|
44
|
+
// Mac and Ubuntu desktop installs: Git task-branch runs go to the packaged Python runner.
|
|
45
|
+
function desktopTask(resources, content, signal, options) {
|
|
46
|
+
const runner = fileURLToPath(new URL('../runtime/task_run.py', import.meta.url));
|
|
47
|
+
const seconds = content.timeout_seconds;
|
|
48
|
+
const timeout = Number.isSafeInteger(seconds) && seconds > 0 ? Math.min(seconds, 3600) : 3600;
|
|
49
|
+
const input = { content, timeout, credential: options.credential, worktrees: join(options.configDir, 'worktrees') };
|
|
50
|
+
return new Promise(resolveResult => {
|
|
51
|
+
// Fetch, checkout and push get their own Git timeouts on top of the tool's.
|
|
52
|
+
const child = execFile(join(resources, 'python/bin/python3'), ['-I', '-B', '-X', 'utf8', runner],
|
|
53
|
+
{ timeout: (timeout + 600) * 1000, maxBuffer: 8 * 1024 * 1024 }, (error, stdout) => {
|
|
54
|
+
signal.removeEventListener('abort', cancel);
|
|
55
|
+
if (signal.aborted) return resolveResult({ status: 'cancelled', failure_code: 'cancelled' });
|
|
56
|
+
if (!error) {
|
|
57
|
+
try { return resolveResult(JSON.parse(stdout)); } catch {}
|
|
58
|
+
}
|
|
59
|
+
resolveResult({ status: 'failed', failure_code: 'tool_start_failed', failure_detail: '设备任务执行器异常,请检查客户端安装' });
|
|
60
|
+
});
|
|
61
|
+
const cancel = () => child.kill('SIGTERM');
|
|
62
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
63
|
+
child.stdin.on('error', () => {});
|
|
64
|
+
child.stdin.end(JSON.stringify(input));
|
|
65
|
+
if (signal.aborted) cancel();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Plain npm serves the one folder it was started in. Mac and Ubuntu desktop installs run as a background
|
|
70
|
+
// service from the home folder and serve every workspace registered for this device, resolved under home.
|
|
71
|
+
async function workspace(content, desktop = false) {
|
|
43
72
|
const local = content.workspace?.local_path;
|
|
44
73
|
if (!local || typeof local !== 'string') throw new Error('缺少工作目录');
|
|
45
|
-
const selected = await realpath(process.env.EASYAGENTS_WORKSPACE || process.cwd());
|
|
46
74
|
const directory = await realpath(resolve(homedir(), local.replace(/^~\//, '')));
|
|
47
|
-
if (
|
|
75
|
+
if (directory === homedir() || directory === parse(directory).root) throw new Error('工作目录不能是主目录或根目录');
|
|
76
|
+
if (!desktop && await realpath(process.env.EASYAGENTS_WORKSPACE || process.cwd()) !== directory) {
|
|
48
77
|
throw new Error('派发目录与本机启动时指定的工作目录不同');
|
|
49
78
|
}
|
|
50
79
|
return directory;
|
|
51
80
|
}
|
|
52
81
|
|
|
53
|
-
async function sync(content, signal) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
async function sync(content, signal, resources) {
|
|
83
|
+
let directory;
|
|
84
|
+
try {
|
|
85
|
+
directory = await workspace(content, Boolean(resources));
|
|
86
|
+
const gitRoot = (await invoke('git', ['rev-parse', '--show-toplevel'], directory, '', signal, 10000)).trim();
|
|
87
|
+
if (await realpath(gitRoot) !== directory) throw new Error('工作目录不是仓库根目录');
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (signal.aborted) return { status: 'cancelled', failure_code: 'cancelled' };
|
|
90
|
+
return { status: 'failed', failure_code: 'workspace_missing', failure_detail: error.message || '工作目录不可用' };
|
|
91
|
+
}
|
|
57
92
|
const script = fileURLToPath(new URL('../runtime/sync.py', import.meta.url));
|
|
58
93
|
try {
|
|
59
|
-
const python = process.platform === 'win32' ? 'python' : 'python3';
|
|
94
|
+
const python = resources ? join(resources, 'python/bin/python3') : process.platform === 'win32' ? 'python' : 'python3';
|
|
60
95
|
const result = await invoke(python, ['-I', '-S', '-B', script], directory, JSON.stringify(content), signal, 600000);
|
|
61
96
|
return JSON.parse(result);
|
|
62
97
|
} catch (error) {
|
|
@@ -65,15 +100,31 @@ async function sync(content, signal) {
|
|
|
65
100
|
}
|
|
66
101
|
}
|
|
67
102
|
|
|
68
|
-
export async function execute(content, signal, workCredential) {
|
|
103
|
+
export async function execute(content, signal, workCredential, { agentCredential, configDir } = {}) {
|
|
69
104
|
signal.throwIfAborted();
|
|
70
|
-
|
|
105
|
+
const resources = process.platform === 'darwin' ? process.env.EASYAGENTS_MAC_RESOURCES
|
|
106
|
+
: process.platform === 'linux' ? process.env.EASYAGENTS_DESKTOP_RESOURCES : undefined;
|
|
107
|
+
if (content.run_kind === 'sync') return sync(content, signal, resources);
|
|
108
|
+
const versioned = content.task && (content.task.git_delivery || content.task.file_delivery || content.task.document_commit_sha);
|
|
109
|
+
if (TASK_KINDS.includes(content.run_kind) && (versioned || content.run_kind !== 'execute')) {
|
|
110
|
+
// Windows, Android and the plain npm install do not run task branches yet (user 2026-11-22).
|
|
111
|
+
if (!resources || !agentCredential || !configDir) {
|
|
112
|
+
return { status: 'failed', failure_code: 'handoff_unsupported', failure_detail: '任务分支运行目前只支持 Mac 和 Ubuntu 桌面版客户端' };
|
|
113
|
+
}
|
|
114
|
+
if (!['codex', 'claude_code'].includes(content.agent?.tool_type)) {
|
|
115
|
+
return { status: 'failed', failure_code: 'unsupported_task', failure_detail: '此工具尚未接入独立客户端的任务运行' };
|
|
116
|
+
}
|
|
117
|
+
let credential;
|
|
118
|
+
try { credential = await agentCredential(content); }
|
|
119
|
+
catch {
|
|
120
|
+
if (signal.aborted) return { status: 'cancelled', failure_code: 'cancelled' };
|
|
121
|
+
return { status: 'failed', failure_code: 'mcp_credential', failure_detail: '无法取得操作入口凭据,请检查设备认证及平台状态' };
|
|
122
|
+
}
|
|
123
|
+
return desktopTask(resources, content, signal, { credential, configDir });
|
|
124
|
+
}
|
|
71
125
|
let prompt = content.prompt;
|
|
72
126
|
const task = content.run_kind === 'execute' && content.task;
|
|
73
127
|
if (task) {
|
|
74
|
-
if (task.git_delivery || task.file_delivery || task.document_commit_sha) {
|
|
75
|
-
return { status: 'failed', failure_code: 'handoff_unsupported', failure_detail: '当前运行入口尚不支持版本化任务文件交付' };
|
|
76
|
-
}
|
|
77
128
|
const root = await workspace(content);
|
|
78
129
|
const path = task.document_path;
|
|
79
130
|
if (typeof path !== 'string' || isAbsolute(path) || !path.endsWith('.md')) throw new Error('任务文档路径无效');
|
|
@@ -90,8 +141,6 @@ export async function execute(content, signal, workCredential) {
|
|
|
90
141
|
return { status: 'succeeded', reply_text: digest };
|
|
91
142
|
}
|
|
92
143
|
if (task && content.prompt) prompt = content.prompt + '\n\n' + prompt;
|
|
93
|
-
const resources = process.platform === 'darwin' ? process.env.EASYAGENTS_MAC_RESOURCES
|
|
94
|
-
: process.platform === 'linux' ? process.env.EASYAGENTS_DESKTOP_RESOURCES : undefined;
|
|
95
144
|
if (resources && ['codex', 'claude_code'].includes(content.agent?.tool_type) && (task || content.run_kind === 'chat')) {
|
|
96
145
|
let credential;
|
|
97
146
|
if (content.chat_mode === 'work' && !content.passthrough && workCredential) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unionschool/easy-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "EasyAgents Client",
|
|
5
5
|
"easyAgentsDesktop": 1,
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,13 @@
|
|
|
19
19
|
"runtime/sync.py",
|
|
20
20
|
"runtime/ssh_terminal.py",
|
|
21
21
|
"runtime/desktop_chat.py",
|
|
22
|
-
"runtime/
|
|
22
|
+
"runtime/task_run.py",
|
|
23
|
+
"runtime/mcp.py",
|
|
24
|
+
"runtime/easyagents_core/git_sync.py",
|
|
25
|
+
"runtime/easyagents_core/member_sync.py",
|
|
26
|
+
"runtime/easyagents_core/process_support.py",
|
|
27
|
+
"runtime/easyagents_core/file_delivery.py",
|
|
28
|
+
"runtime/easyagents_core/mcp_call.py"
|
|
23
29
|
],
|
|
24
30
|
"engines": {
|
|
25
31
|
"node": ">=22"
|
|
@@ -35,8 +41,6 @@
|
|
|
35
41
|
"ws"
|
|
36
42
|
],
|
|
37
43
|
"scripts": {
|
|
38
|
-
"prepack": "node scripts/bundle-core.js",
|
|
39
|
-
"pretest": "node scripts/bundle-core.js",
|
|
40
44
|
"test": "node --test"
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -4,6 +4,7 @@ import argparse
|
|
|
4
4
|
import json
|
|
5
5
|
import os
|
|
6
6
|
import re
|
|
7
|
+
import sys
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
|
|
9
10
|
import httpx
|
|
@@ -74,6 +75,11 @@ def require_pushed_commit(branch, commit):
|
|
|
74
75
|
return remote
|
|
75
76
|
|
|
76
77
|
|
|
78
|
+
def deployable(path):
|
|
79
|
+
"""规程 5.4:`docs/`、`skills/` 和各处 `*.md` 不部署,其余都算会被部署的改动。"""
|
|
80
|
+
return not (path.startswith(('docs/', 'skills/')) or path.endswith('.md'))
|
|
81
|
+
|
|
82
|
+
|
|
77
83
|
def require_current_delivery(branch, commit):
|
|
78
84
|
cwd = Path.cwd()
|
|
79
85
|
remote = require_pushed_commit(branch, commit)
|
|
@@ -87,8 +93,24 @@ def require_current_delivery(branch, commit):
|
|
|
87
93
|
'--no-write-fetch-head', '--refmap=', remote, latest)
|
|
88
94
|
except GitError as exc:
|
|
89
95
|
raise MCPError(f'无法拉取远端主分支提交 {latest}。{exc.message}') from None
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
base = git(cwd, 'merge-base', latest, commit, allowed=(0, 1))
|
|
97
|
+
if base == latest:
|
|
98
|
+
return
|
|
99
|
+
message = f'本轮交付尚未包含远端主分支提交 {latest},请合入后重跑测试、推送并重新提交'
|
|
100
|
+
if not base:
|
|
101
|
+
raise MCPError(message)
|
|
102
|
+
# 规程 5.4:主分支只多了文档、规程、skill、记忆这类不部署的提交时不算落后,照常交付。
|
|
103
|
+
try:
|
|
104
|
+
names = git(cwd, 'diff', '--name-only', '--no-renames', '-z', base, latest)
|
|
105
|
+
except GitError as exc:
|
|
106
|
+
raise MCPError(f'{message}(无法比较主分支多出的改动:{exc.message})') from None
|
|
107
|
+
behind = [name for name in names.split('\0') if name.strip()]
|
|
108
|
+
missing = [name.strip() for name in behind if deployable(name.strip())]
|
|
109
|
+
if missing:
|
|
110
|
+
shown = '、'.join(missing[:5]) + (f' 等 {len(missing)} 个' if len(missing) > 5 else '')
|
|
111
|
+
raise MCPError(f'{message}(主分支上有会被部署的改动不在本轮交付里:{shown})')
|
|
112
|
+
print(f'提示:远端主分支 {latest[:12]} 比本轮交付多 {len(behind)} 个文档类文件的改动,'
|
|
113
|
+
'按规程 5.4 不算落后,照常交付。', file=sys.stderr)
|
|
92
114
|
|
|
93
115
|
|
|
94
116
|
def publish_branch(branch, commit, document):
|
package/runtime/mcp.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Platform MCP entry for the agent inside a task run: the packaged mcp_call with the desktop install's httpx."""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
package = Path(__file__).resolve().parents[1]
|
|
7
|
+
resources = os.environ.get("EASYAGENTS_MAC_RESOURCES") or os.environ.get("EASYAGENTS_DESKTOP_RESOURCES")
|
|
8
|
+
# The desktop build extracts this package to <resources>/package next to <resources>/lib.
|
|
9
|
+
for lib in ([Path(resources) / "lib"] if resources else []) + [package.parent / "lib"]:
|
|
10
|
+
if lib.is_dir():
|
|
11
|
+
sys.path.insert(0, str(lib))
|
|
12
|
+
break
|
|
13
|
+
sys.path.insert(0, str(package))
|
|
14
|
+
from runtime.easyagents_core.mcp_call import main
|
|
15
|
+
|
|
16
|
+
main()
|
package/runtime/sync.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Run the packaged member-sync implementation using only Python's standard library."""
|
|
2
2
|
import json
|
|
3
|
+
import os
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
import signal
|
|
5
6
|
import sys
|
|
@@ -11,7 +12,9 @@ from easyagents_core import member_sync
|
|
|
11
12
|
cancel = Event()
|
|
12
13
|
signal.signal(signal.SIGTERM, lambda *_: cancel.set())
|
|
13
14
|
request = json.load(sys.stdin)
|
|
14
|
-
|
|
15
|
+
# Task runs on Mac and Ubuntu leave isolated worktrees here (task_run.py); the member sync removes them.
|
|
16
|
+
config = os.environ.get('EASYAGENTS_CONFIG_DIR')
|
|
17
|
+
result = member_sync.run(Path.cwd(), request, cancel, Path(config) / 'worktrees' if config else None)
|
|
15
18
|
print(json.dumps({key: getattr(result, key) for key in (
|
|
16
19
|
'status', 'reply_text', 'workspace_sync', 'failure_code', 'failure_detail'
|
|
17
20
|
) if getattr(result, key) is not None}))
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Run a platform task (execute, review, deploy, clarify) on its Git task branch with the desktop tool adapters.
|
|
2
|
+
|
|
3
|
+
Mac and Ubuntu desktop installs only. The Git checkout and push rules are the shared ones in git_sync:
|
|
4
|
+
execute works on the task branch and pushes it, review and deploy check out the delivered commit,
|
|
5
|
+
clarify uses the default branch. Tools run with full permissions like every task run (T-44).
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import shlex
|
|
10
|
+
import shutil
|
|
11
|
+
import signal
|
|
12
|
+
import sys
|
|
13
|
+
import threading
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from uuid import UUID
|
|
16
|
+
|
|
17
|
+
resources = os.environ.get("EASYAGENTS_MAC_RESOURCES") or os.environ["EASYAGENTS_DESKTOP_RESOURCES"]
|
|
18
|
+
sys.path.insert(0, str(Path(resources) / "lib"))
|
|
19
|
+
from easyagents_core.tools import ClaudeCodeAdapter, CodexAdapter
|
|
20
|
+
PACKAGE = Path(__file__).resolve().parents[1]
|
|
21
|
+
sys.path.insert(0, str(PACKAGE))
|
|
22
|
+
from runtime.easyagents_core.git_sync import GitError, GitWorkspace
|
|
23
|
+
|
|
24
|
+
KINDS = ("execute", "review", "deploy", "clarify")
|
|
25
|
+
FIELDS = ("status", "reply_text", "tool_session_ref", "tool_version", "model_name",
|
|
26
|
+
"usage", "context", "failure_code", "failure_detail")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def failed(code, detail, status="failed"):
|
|
30
|
+
return {"status": status, "failure_code": code, "failure_detail": detail}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def platform_entry(credential_file):
|
|
34
|
+
command = shlex.join([sys.executable, "-I", "-B", str(PACKAGE / "runtime" / "mcp.py"),
|
|
35
|
+
"--credential", credential_file])
|
|
36
|
+
return ("\n平台操作入口:通过终端运行 " + command + " list 查看全部工具及参数;"
|
|
37
|
+
"调用方式:同一命令后接工具名及单个 JSON 对象参数。"
|
|
38
|
+
"先调用 get_workflow_guide 获取任务规程,按需用 get_project_context 获取项目编号与安排。"
|
|
39
|
+
"领取、提问、交付、审核都必须调用真实平台工具。"
|
|
40
|
+
"本次平台调度优先于仓库中默认的本地任务流程;文档仍按规程写入仓库,"
|
|
41
|
+
"不能仅写 docs/需求.md 或任务.md 就声称平台已登记或派发,"
|
|
42
|
+
"派发一律用任务分支经平台进行(publish_task 带 task_branch),不再本地派发。"
|
|
43
|
+
"平台调用失败应明确报告未登记/未派发,不得改走本地;"
|
|
44
|
+
"不要读取、打印或提交凭据文件。部署只由部署阶段的部署人做;数据库迁移、修改生产数据、删除远程内容前先用 ask_user 询问用户。")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def checkout_notes(sync, original):
|
|
48
|
+
notes = ""
|
|
49
|
+
if sync.isolated and sync.kind == "deploy":
|
|
50
|
+
notes += ("\n本次部署在独立工作树里,没有 .venv、node_modules、.env、密钥等被忽略的本机文件;"
|
|
51
|
+
"原工作目录(带有这些文件):" + str(original) +
|
|
52
|
+
"。按部署 skill 从那里带入所需依赖和配置,不要修改原目录的分支和未提交改动。")
|
|
53
|
+
if sync.isolated and sync.kind == "execute":
|
|
54
|
+
notes += ("\n本次在独立工作树中执行,HEAD 为分离状态。直接在这里提交,"
|
|
55
|
+
"用 git push <仓库远程名> HEAD:refs/heads/<原任务分支> 推送后再交付。")
|
|
56
|
+
if sync.handoff:
|
|
57
|
+
notes += ("\n仓库同步需由你处理:" + sync.handoff +
|
|
58
|
+
";客户端已fetch远端引用并保留当前分支、索引和未提交改动,没有自动合并。"
|
|
59
|
+
"先检查git status和本地/远端差异,按任务分支及文档提交读取任务(必要时git show <document_commit_sha>:<document_path>)。"
|
|
60
|
+
"解决冲突后推进任务;把冲突文件、双方取舍和理由追加任务.md的「冲突记录」。"
|
|
61
|
+
"无法安全解决时保留双方内容,标记待负责人裁定,继续不受影响部分;本次客户端不自动补推。")
|
|
62
|
+
return notes
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def run(request, cancelled):
|
|
66
|
+
content = request["content"]
|
|
67
|
+
kind = content.get("run_kind")
|
|
68
|
+
if kind not in KINDS:
|
|
69
|
+
return failed("unsupported_task", "运行类型无效")
|
|
70
|
+
task = content.get("task") or {}
|
|
71
|
+
if isinstance(task.get("file_delivery"), dict):
|
|
72
|
+
return failed("handoff_unsupported", "独立客户端只支持任务分支交付,不支持旧的同目录文件交付")
|
|
73
|
+
tool = (content.get("agent") or {}).get("tool_type")
|
|
74
|
+
if tool == "codex":
|
|
75
|
+
adapter = CodexAdapter()
|
|
76
|
+
elif tool == "claude_code":
|
|
77
|
+
adapter = ClaudeCodeAdapter()
|
|
78
|
+
else:
|
|
79
|
+
return failed("unsupported_task", "此工具尚未接入独立客户端的任务运行")
|
|
80
|
+
if not shutil.which(adapter.executable):
|
|
81
|
+
return failed("tool_missing", "本机未找到 " + adapter.executable_name)
|
|
82
|
+
resume = content.get("resume_session_ref")
|
|
83
|
+
if resume is not None:
|
|
84
|
+
try:
|
|
85
|
+
UUID(resume)
|
|
86
|
+
except (ValueError, AttributeError, TypeError):
|
|
87
|
+
return failed("bad_session", "工具会话标识无效")
|
|
88
|
+
run_id = content.get("run_id")
|
|
89
|
+
if not isinstance(run_id, str) or not run_id:
|
|
90
|
+
return failed("bad_dispatch_context", "运行缺少编号")
|
|
91
|
+
|
|
92
|
+
workspace = content.get("workspace") or {}
|
|
93
|
+
local = workspace.get("local_path")
|
|
94
|
+
if not isinstance(local, str) or local.strip() in ("", ".", "~", "~/"):
|
|
95
|
+
return failed("workspace_missing", "未配置工作目录")
|
|
96
|
+
original = (Path.home() / Path(local).expanduser()).resolve()
|
|
97
|
+
if not original.is_dir() or original == Path(original.anchor) or original == Path.home().resolve():
|
|
98
|
+
return failed("workspace_missing", "请核对该 Agent 在设备上登记的工作目录")
|
|
99
|
+
|
|
100
|
+
sync = None
|
|
101
|
+
cwd = original
|
|
102
|
+
try:
|
|
103
|
+
if workspace.get("scope") != "project":
|
|
104
|
+
sync = GitWorkspace(original, content, cancelled, Path(request["worktrees"]))
|
|
105
|
+
sync.prepare()
|
|
106
|
+
cwd = sync.cwd
|
|
107
|
+
if cancelled.is_set():
|
|
108
|
+
raise GitError("cancelled", "已取消")
|
|
109
|
+
prompt = content.get("prompt") if isinstance(content.get("prompt"), str) else ""
|
|
110
|
+
if sync is not None:
|
|
111
|
+
prompt += checkout_notes(sync, original)
|
|
112
|
+
prompt = (f"本次调度模式:platform(EasyAgents 平台调度);运行编号:{run_id}。\n"
|
|
113
|
+
+ prompt + platform_entry(request["credential"]))
|
|
114
|
+
result = adapter.invoke(prompt=prompt, cwd=cwd, resume_session_ref=resume,
|
|
115
|
+
timeout_seconds=request["timeout"], cancel_event=cancelled,
|
|
116
|
+
model=content.get("requested_model"), platform_run_id=run_id)
|
|
117
|
+
if result.status == "succeeded" and sync is not None:
|
|
118
|
+
sync.finish()
|
|
119
|
+
except GitError as exc:
|
|
120
|
+
return failed(exc.code, exc.message, "cancelled" if exc.code == "cancelled" else "failed")
|
|
121
|
+
if result.reply_text and len(result.reply_text) > 1_000_000:
|
|
122
|
+
return failed("bad_output", "工具回复超过平台长度上限")
|
|
123
|
+
body = {name: getattr(result, name) for name in FIELDS if getattr(result, name) is not None}
|
|
124
|
+
if sync is not None and sync.shared and not sync.isolated:
|
|
125
|
+
body["workspace_sync"] = "shared_with_publisher"
|
|
126
|
+
elif sync is not None and sync.handoff:
|
|
127
|
+
body["workspace_sync"] = "conflict_pending" if sync.conflict_pending else "conflict_handoff"
|
|
128
|
+
return body
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == "__main__":
|
|
132
|
+
cancelled = threading.Event()
|
|
133
|
+
signal.signal(signal.SIGTERM, lambda *_: cancelled.set())
|
|
134
|
+
print(json.dumps(run(json.load(sys.stdin), cancelled), ensure_ascii=False))
|