@unionschool/easy-agents 0.4.1 → 1.0.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 +1 -1
- package/bin/credentials.js +73 -0
- package/bin/tasks.js +9 -4
- package/package.json +3 -1
- package/runtime/desktop_chat.py +8 -2
- package/runtime/platform_prompt.py +21 -0
- package/runtime/task_run.py +1 -15
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ npm exec --offline -- easy-agents run
|
|
|
88
88
|
|
|
89
89
|
- Mac 和 Ubuntu 安装包能接平台任务分支上的执行、审核、部署和澄清运行(Codex、Claude,完整权限,与旧 Python 客户端的规则一致):执行在任务分支上工作并在成功后推送;审核和部署检出本轮交付的提交;工作目录有未提交改动时,在客户端配置目录的 `worktrees/` 里另建工作树,原目录不动,合并后的成员同步会清理这些工作树。Agent 通过提示里给出的平台命令调用工具;Agent 凭据缺失或已被平台撤销时,客户端自动领取新凭据(平台会同时撤销旧凭据)。旧的同目录文件交付和用户发布命令(`publish`)不支持。
|
|
90
90
|
- **未完成**:Windows、Android 和单独运行的普通 npm 版还不能接任务分支运行,会回报 `handoff_unsupported`。这几端暂时用不上(用户 2026-11-22 定),以后需要时再单独升级。
|
|
91
|
-
- Mac 和 Ubuntu 安装包支持 Codex、Claude
|
|
91
|
+
- Mac 和 Ubuntu 安装包支持 Codex、Claude 的文本对话、续聊和本地文本任务。它们可从项目卡片或对话页接收聊天和工作消息。普通聊天是纯文本:Codex 只读会话、Claude 不开工具。工作消息(负责人与任务角色的对话、平台的流程通知)与任务运行一样用完整权限,带平台操作入口,Agent 凭据缺失或被撤销时自动领取,所以负责人能在对话里登记需求、发布任务、合并上报。可用的会话编号、模型与用量会随结果回传。
|
|
92
92
|
- Mac 和 Windows 面板可显示检测到的 Codex、Claude、Cursor、Agy 登录和上报状态。平台控制额度上报开关,绿色胶囊显示已获得的剩余额度,测得零时显示零。Windows 和单独运行的普通 npm 版支持单次 Claude 文本任务,使用 bare 模式可用的认证。桌面对话功能需要安装包提供的工具适配和内置运行环境。
|
|
93
93
|
- 在支持的 Unix 主机上,网页终端使用本机运行用户进行 SSH 登录,需要 Python 3、OpenSSH、可读的本机 SSH 公钥和监听回环端口 22 的 SSH 服务。可在工作台的「AI → 设备管理 → 终端」打开。普通 npm 可在启动前用 `EASYAGENTS_TERMINAL=0` 关闭。
|
|
94
94
|
- Node 核心支持 `/sha256 <文本>`、本地 Markdown 文档里的同类计算和成员同步。文档与同步的目录需与本机选定工作目录相符,可用 `EASYAGENTS_WORKSPACE` 指定。成员同步使用包内实现、系统 Git 和 Python 3.10+,更新已有检出目录。Android 首版可执行 SHA-256 消息和用户选择目录里的计算文档。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Agent credentials for the platform tools (MCP). Shared by the background runner and `easy-agents agent-credential`.
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { protectDeviceFile } from './pair.js';
|
|
7
|
+
|
|
8
|
+
const AGENT_ID = /^[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}$/i;
|
|
9
|
+
|
|
10
|
+
export function checkAgentId(id) {
|
|
11
|
+
if (!AGENT_ID.test(id)) throw new Error('Agent 编号无效');
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// An existing, private credential file for this agent, or null. The Mac app also accepts the old Python client's folder.
|
|
16
|
+
export function findAgentCredential(configDir, id) {
|
|
17
|
+
checkAgentId(id);
|
|
18
|
+
const files = [join(configDir, 'agents', id + '.json')];
|
|
19
|
+
if (process.platform === 'darwin' && configDir === join(homedir(), 'Library/Application Support/EasyAgents Client')) {
|
|
20
|
+
files.push(join(homedir(), '.easyagents', 'agents', id + '.json'));
|
|
21
|
+
}
|
|
22
|
+
for (const path of files) {
|
|
23
|
+
try {
|
|
24
|
+
const info = lstatSync(path);
|
|
25
|
+
if (!info.isFile() || info.uid !== process.getuid() || (info.mode & 0o077)) throw new Error('Agent 凭据文件无效');
|
|
26
|
+
return path;
|
|
27
|
+
} catch (err) { if (err.code !== 'ENOENT') throw err; }
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// False when the file is unreadable, bound to another gateway, or refused by the platform (401/403).
|
|
33
|
+
async function credentialWorks(file, origin, version, signal) {
|
|
34
|
+
let auth;
|
|
35
|
+
try { auth = JSON.parse(readFileSync(file, 'utf8')); } catch { return false; }
|
|
36
|
+
if (typeof auth?.server !== 'string' || auth.server.replace(/\/+$/, '') !== origin || !auth.agent_token) return false;
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(new URL('/mcp', origin), { method: 'POST', redirect: 'error',
|
|
39
|
+
headers: { Authorization: 'Bearer ' + auth.agent_token, 'Content-Type': 'application/json',
|
|
40
|
+
Accept: 'application/json, text/event-stream' },
|
|
41
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-03-26',
|
|
42
|
+
capabilities: {}, clientInfo: { name: 'easyagents-client', version } } }),
|
|
43
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(20000)]) });
|
|
44
|
+
await res.body?.cancel();
|
|
45
|
+
return ![401, 403].includes(res.status);
|
|
46
|
+
} catch {
|
|
47
|
+
return true; // Network trouble is not proof of a revoked credential; the caller reports what fails.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A working credential file path. A missing, mismatched or revoked one is replaced; the platform revokes the
|
|
52
|
+
// previous credential when it issues a new one. `issue` asks the platform for a new token with the device token.
|
|
53
|
+
export async function ensureAgentCredential({ configDir, origin, id, version, signal, issue }) {
|
|
54
|
+
checkAgentId(id);
|
|
55
|
+
let found = null;
|
|
56
|
+
try { found = findAgentCredential(configDir, id); } catch {}
|
|
57
|
+
if (found && await credentialWorks(found, origin, version, signal)) return found;
|
|
58
|
+
const issued = await issue(id);
|
|
59
|
+
if (typeof issued?.agent_token !== 'string' || !issued.agent_token) throw new Error('Agent 凭据响应无效');
|
|
60
|
+
const dir = join(configDir, 'agents');
|
|
61
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
62
|
+
const file = join(dir, id + '.json');
|
|
63
|
+
const tmp = join(dir, '.agent-' + randomUUID());
|
|
64
|
+
try {
|
|
65
|
+
writeFileSync(tmp, '', { flag: 'wx', mode: 0o600 });
|
|
66
|
+
protectDeviceFile(tmp);
|
|
67
|
+
writeFileSync(tmp, JSON.stringify({ server: origin, agent_token: issued.agent_token }));
|
|
68
|
+
renameSync(tmp, file);
|
|
69
|
+
} finally {
|
|
70
|
+
rmSync(tmp, { force: true });
|
|
71
|
+
}
|
|
72
|
+
return file;
|
|
73
|
+
}
|
package/bin/tasks.js
CHANGED
|
@@ -14,13 +14,13 @@ function invoke(file, args, cwd, input, signal, timeout) {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function desktopConversation(resources, content, prompt, signal, credential) {
|
|
17
|
+
function desktopConversation(resources, content, prompt, signal, credential, tools = false) {
|
|
18
18
|
const bridge = fileURLToPath(new URL('../runtime/desktop_chat.py', import.meta.url));
|
|
19
19
|
const seconds = content.timeout_seconds;
|
|
20
20
|
const timeout = Number.isSafeInteger(seconds) && seconds > 0 ? Math.min(seconds, 3600) : 3600;
|
|
21
21
|
const input = { tool: content.agent.tool_type, prompt, model: content.requested_model,
|
|
22
22
|
resume: content.resume_session_ref, workspace: content.workspace?.local_path, timeout,
|
|
23
|
-
workRunId: content.chat_mode
|
|
23
|
+
workRunId: content.chat_mode !== 'chat' ? content.run_id : undefined, passthrough: content.passthrough === true, credential, tools };
|
|
24
24
|
return new Promise(resolveResult => {
|
|
25
25
|
const child = execFile(join(resources, 'python/bin/python3'), ['-I', '-B', '-X', 'utf8', bridge],
|
|
26
26
|
{ timeout: (timeout + 12) * 1000, maxBuffer: 8 * 1024 * 1024 }, (error, stdout) => {
|
|
@@ -143,14 +143,19 @@ export async function execute(content, signal, workCredential, { agentCredential
|
|
|
143
143
|
if (task && content.prompt) prompt = content.prompt + '\n\n' + prompt;
|
|
144
144
|
if (resources && ['codex', 'claude_code'].includes(content.agent?.tool_type) && (task || content.run_kind === 'chat')) {
|
|
145
145
|
let credential;
|
|
146
|
-
|
|
146
|
+
// Same rule as the platform: only chat_mode 'chat' is a plain conversation. Workflow notifications to the lead
|
|
147
|
+
// (merge after deploy, answers, sync handoff) arrive with an empty chat_mode and must be able to act.
|
|
148
|
+
const work = content.chat_mode !== 'chat' && !content.passthrough;
|
|
149
|
+
if (work && workCredential) {
|
|
150
|
+
// A revoked or missing credential would leave the lead unable to register, publish or merge.
|
|
151
|
+
try { if (agentCredential) await agentCredential(content); } catch {}
|
|
147
152
|
try {
|
|
148
153
|
credential = workCredential(content);
|
|
149
154
|
} catch {
|
|
150
155
|
credential = null;
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
|
-
return desktopConversation(resources, content, prompt, signal, credential);
|
|
158
|
+
return desktopConversation(resources, content, prompt, signal, credential, work);
|
|
154
159
|
}
|
|
155
160
|
if ((!task && (content.run_kind !== 'chat' || content.chat_mode !== 'chat')) || content.agent?.tool_type !== 'claude_code') {
|
|
156
161
|
return { status: 'failed', failure_code: 'unsupported_task', failure_detail: '当前独立客户端支持计算、成员同步及 Claude 文本任务' };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unionschool/easy-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "EasyAgents Client",
|
|
5
5
|
"easyAgentsDesktop": 1,
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"bin/easy-agents.js",
|
|
12
12
|
"bin/pair.js",
|
|
13
13
|
"bin/run.js",
|
|
14
|
+
"bin/credentials.js",
|
|
14
15
|
"bin/terminal.js",
|
|
15
16
|
"bin/tasks.js",
|
|
16
17
|
"bin/mac-reports.js",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"runtime/desktop_chat.py",
|
|
22
23
|
"runtime/task_run.py",
|
|
23
24
|
"runtime/mcp.py",
|
|
25
|
+
"runtime/platform_prompt.py",
|
|
24
26
|
"runtime/easyagents_core/git_sync.py",
|
|
25
27
|
"runtime/easyagents_core/member_sync.py",
|
|
26
28
|
"runtime/easyagents_core/process_support.py",
|
package/runtime/desktop_chat.py
CHANGED
|
@@ -12,6 +12,7 @@ resources = os.environ.get("EASYAGENTS_MAC_RESOURCES") or os.environ["EASYAGENTS
|
|
|
12
12
|
sys.path.insert(0, str(Path(resources) / "lib"))
|
|
13
13
|
from easyagents_core.tools import ClaudeCodeAdapter, CodexAdapter
|
|
14
14
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
15
|
+
from runtime.platform_prompt import platform_entry
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class TextClaude(ClaudeCodeAdapter):
|
|
@@ -50,11 +51,14 @@ def workflow_guide(binding, run_id):
|
|
|
50
51
|
|
|
51
52
|
def run(content, cancelled):
|
|
52
53
|
tool = content["tool"]
|
|
54
|
+
# Work messages (lead and task-role conversations) act on the platform and the repository like task runs:
|
|
55
|
+
# full permissions (T-44) and the platform entry. Plain chat stays a read-only text conversation.
|
|
56
|
+
tools = content.get("tools") is True
|
|
53
57
|
if tool == "codex":
|
|
54
58
|
adapter = CodexAdapter()
|
|
55
|
-
options = {"sandbox_policy": {"type": "readOnly", "networkAccess": False}}
|
|
59
|
+
options = {} if tools else {"sandbox_policy": {"type": "readOnly", "networkAccess": False}}
|
|
56
60
|
elif tool == "claude_code":
|
|
57
|
-
adapter = TextClaude()
|
|
61
|
+
adapter = ClaudeCodeAdapter() if tools else TextClaude()
|
|
58
62
|
options = {}
|
|
59
63
|
else:
|
|
60
64
|
return failed("unsupported_task", "此工具尚未接入设备文本对话")
|
|
@@ -89,6 +93,8 @@ def run(content, cancelled):
|
|
|
89
93
|
else:
|
|
90
94
|
guidance = "平台任务规程:\n" + guide
|
|
91
95
|
prompt = f"本次调度模式:platform;运行编号:{run_id}\n{guidance}\n\n{prompt}"
|
|
96
|
+
if tools and content.get("credential"):
|
|
97
|
+
prompt += platform_entry(content["credential"]["file"])
|
|
92
98
|
result = adapter.invoke(prompt=prompt, cwd=cwd, resume_session_ref=resume,
|
|
93
99
|
timeout_seconds=content["timeout"], cancel_event=cancelled,
|
|
94
100
|
model=content.get("model"), platform_run_id=run_id, **options)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""How an agent reaches the platform tools from a tool-enabled run (task runs and lead work messages)."""
|
|
2
|
+
import shlex
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
PACKAGE = Path(__file__).resolve().parents[1]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def platform_entry(credential_file):
|
|
10
|
+
command = shlex.join([sys.executable, "-I", "-B", str(PACKAGE / "runtime" / "mcp.py"),
|
|
11
|
+
"--credential", str(credential_file)])
|
|
12
|
+
return ("\n平台操作入口:通过终端运行 " + command + " list 查看全部工具及参数;"
|
|
13
|
+
"调用方式:同一命令后接工具名及单个 JSON 对象参数。"
|
|
14
|
+
"先调用 get_workflow_guide 获取任务规程,按需用 get_project_context 获取项目编号与安排。"
|
|
15
|
+
"登记需求用 register_requirement,提交方案用 submit_plan,用户同意后用 record_approval 登记批准,"
|
|
16
|
+
"派任务用 publish_task;领取、提问、交付、审核、部署、合并上报也必须调用真实平台工具。"
|
|
17
|
+
"本次平台调度优先于仓库中默认的本地任务流程;文档仍按规程写入仓库,"
|
|
18
|
+
"不能仅写 docs/需求.md 或任务.md 就声称平台已登记或派发,"
|
|
19
|
+
"派发一律用任务分支经平台进行(publish_task 带 task_branch),同设备、同一智能体也不例外,不再本地派发。"
|
|
20
|
+
"平台调用失败应明确报告未登记/未派发,不得改走本地;"
|
|
21
|
+
"不要读取、打印或提交凭据文件。部署只由部署阶段的部署人做;数据库迁移、修改生产数据、删除远程内容前先用 ask_user 询问用户。")
|
package/runtime/task_run.py
CHANGED
|
@@ -6,7 +6,6 @@ clarify uses the default branch. Tools run with full permissions like every task
|
|
|
6
6
|
"""
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
9
|
-
import shlex
|
|
10
9
|
import shutil
|
|
11
10
|
import signal
|
|
12
11
|
import sys
|
|
@@ -20,6 +19,7 @@ from easyagents_core.tools import ClaudeCodeAdapter, CodexAdapter
|
|
|
20
19
|
PACKAGE = Path(__file__).resolve().parents[1]
|
|
21
20
|
sys.path.insert(0, str(PACKAGE))
|
|
22
21
|
from runtime.easyagents_core.git_sync import GitError, GitWorkspace
|
|
22
|
+
from runtime.platform_prompt import platform_entry
|
|
23
23
|
|
|
24
24
|
KINDS = ("execute", "review", "deploy", "clarify")
|
|
25
25
|
FIELDS = ("status", "reply_text", "tool_session_ref", "tool_version", "model_name",
|
|
@@ -30,20 +30,6 @@ def failed(code, detail, status="failed"):
|
|
|
30
30
|
return {"status": status, "failure_code": code, "failure_detail": detail}
|
|
31
31
|
|
|
32
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
33
|
def checkout_notes(sync, original):
|
|
48
34
|
notes = ""
|
|
49
35
|
if sync.isolated and sync.kind == "deploy":
|