@unionschool/easy-agents 1.0.27 → 1.0.44

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 CHANGED
@@ -88,7 +88,7 @@ npm exec --offline -- easy-agents run
88
88
 
89
89
  - Mac 和 Ubuntu 安装包能接平台任务分支上的执行、审核、部署和澄清运行(Codex、Claude,完整权限,与旧 Python 客户端的规则一致):执行在任务分支上工作并在成功后推送;审核和部署检出本轮交付的提交;工作目录有未提交改动时,在客户端配置目录的 `worktrees/` 里另建工作树,原目录不动,合并后的成员同步会清理这些工作树。Agent 通过提示里给出的平台命令调用工具;Agent 凭据缺失或已被平台撤销时,客户端自动领取新凭据(平台会同时撤销旧凭据)。旧的同目录文件交付和用户发布命令(`publish`)不支持。工作台读取任务、需求文档(“阅读”抽屉)也由这两种设备应答,只读 Git,不切分支、不改工作区。
90
90
  - **未完成**:Windows、Android 和单独运行的普通 npm 版还不能接任务分支运行,会回报 `handoff_unsupported`。这几端暂时用不上(用户 2026-11-22 定),以后需要时再单独升级。
91
- - Mac 和 Ubuntu 安装包支持 Codex、Claude 的文本对话、续聊和本地文本任务。它们可从项目卡片或对话页接收聊天和工作消息。普通聊天是纯文本:Codex 只读会话、Claude 不开工具。工作消息(负责人与任务角色的对话、平台的流程通知)与任务运行一样用完整权限,带平台操作入口,Agent 凭据缺失或被撤销时自动领取,所以负责人能在对话里登记需求、发布任务、合并上报。可用的会话编号、模型与用量会随结果回传。
91
+ - Mac 和 Ubuntu 安装包支持 Codex、Claude 的文本对话、续聊和本地文本任务;Agy、Cursor 只接对话,不接任务运行(2026-11-23,1.0.34 起含 Cursor)。它们可从项目卡片或对话页接收聊天和工作消息。普通聊天是纯文本: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 消息和用户选择目录里的计算文档。
package/bin/run.js CHANGED
@@ -20,6 +20,19 @@ const taskDelivery = () => Boolean(desktopResources());
20
20
  const DOC_READER = fileURLToPath(new URL('../runtime/doc_read.py', import.meta.url));
21
21
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
22
  const DOC_FAILED = { status: 'error', error: 'document_read_failed' };
23
+
24
+ // worker.log 每行带本机时间;运行没成功时写出失败代码和原因,本机就能查(2026-11-26,原先只有“已回传 failed”)。
25
+ const pad = n => String(n).padStart(2, '0');
26
+ export function stamped(text, now = new Date()) {
27
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())} ${text}`;
28
+ }
29
+ export function finishLine(id, result) {
30
+ const reason = [result.failure_code, String(result.failure_detail ?? '').replace(/\s+/g, ' ').trim().slice(0, 120)]
31
+ .filter(Boolean).join(':');
32
+ return '运行 ' + id + ' 已回传 ' + result.status + (result.status !== 'succeeded' && reason ? '(' + reason + ')' : '');
33
+ }
34
+ const info = text => console.log(stamped(text));
35
+ const warn = text => console.error(stamped(text));
23
36
  function readDocument(message, signal) {
24
37
  return new Promise(done => {
25
38
  const child = execFile(join(desktopResources(), 'python/bin/python3'), ['-I', '-B', '-X', 'utf8', DOC_READER],
@@ -123,7 +136,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
123
136
  if (typeof id !== 'string' || !UUID.test(id) || !desktopResources()) return;
124
137
  const body = await readDocument(msg, signal);
125
138
  try { await gatewayRequest('POST', '/api/client/documents/' + id, body); }
126
- catch { if (!signal.aborted) console.error('文档读取结果回传失败'); }
139
+ catch { if (!signal.aborted) warn('文档读取结果回传失败'); }
127
140
  }
128
141
  async function answerSteer(target, msg) {
129
142
  if (!UUID.test(msg.run_id || '') || !UUID.test(msg.message_id || '')) return;
@@ -185,7 +198,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
185
198
  await request('POST', id + '/finish', result);
186
199
  rmSync(join(folder, id + '.json'), { force: true });
187
200
  reporter?.patch({ lastResult: { id, status: result.status, at: Date.now() } });
188
- console.log('运行 ' + id + ' 已回传 ' + result.status);
201
+ info(finishLine(id, result));
189
202
  }
190
203
  function startQueue() {
191
204
  while (online && !signal.aborted && running.size < MAX_PARALLEL_RUNS) {
@@ -230,7 +243,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
230
243
  try { metadata = await reporter.hello(signal); }
231
244
  catch {
232
245
  if (signal.aborted) break;
233
- console.error('本机工具信息暂时不可用,正在重试');
246
+ warn('本机工具信息暂时不可用,正在重试');
234
247
  reporter.disconnect();
235
248
  await sleep(delay, undefined, { signal }).catch(() => {});
236
249
  delay = Math.min(60000, delay * 2);
@@ -260,7 +273,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
260
273
  if (msg.type !== 'welcome' || msg.device_id !== device.device_id) throw new Error();
261
274
  welcomed = online = true; delay = 1000;
262
275
  reporter?.welcome(hello, msg, reportQuota, () => current.terminate());
263
- console.log('设备已上线');
276
+ info('设备已上线');
264
277
  const pending = await request('GET', 'pending');
265
278
  if (current !== socket || current.readyState !== WebSocket.OPEN) return;
266
279
  for (const f of readdirSync(folder)) if (f.endsWith('.json')) enqueue(f.slice(0, -5));
@@ -290,7 +303,7 @@ export async function runDevice(device, configDir, version, signal, { reporter,
290
303
  for (const session of sessions.values()) session.terminate();
291
304
  }
292
305
  if (!signal.aborted && !fatal) {
293
- console.error('连接中断,正在重连');
306
+ warn('连接中断,正在重连');
294
307
  await sleep(delay, undefined, { signal }).catch(() => {});
295
308
  delay = Math.min(delay * 2, 60000);
296
309
  }
package/bin/tasks.js CHANGED
@@ -223,9 +223,9 @@ export async function execute(content, signal, workCredential, { agentCredential
223
223
  return { status: 'succeeded', reply_text: digest };
224
224
  }
225
225
  if (task && content.prompt) prompt = content.prompt + '\n\n' + prompt;
226
- // Agy 只接对话(2026-11-23),任务运行仍只有 Codex、Claude。
226
+ // Agy、Cursor 只接对话(2026-11-23),任务运行仍只有 Codex、Claude。
227
227
  if (resources && (['codex', 'claude_code'].includes(content.agent?.tool_type) && (task || content.run_kind === 'chat')
228
- || content.agent?.tool_type === 'antigravity' && content.run_kind === 'chat')) {
228
+ || ['antigravity', 'cursor'].includes(content.agent?.tool_type) && content.run_kind === 'chat')) {
229
229
  let credential;
230
230
  // Same rule as the platform: only chat_mode 'chat' is a plain conversation. Workflow notifications to the lead
231
231
  // (merge after deploy, answers, sync handoff) arrive with an empty chat_mode and must be able to act.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unionschool/easy-agents",
3
- "version": "1.0.27",
3
+ "version": "1.0.44",
4
4
  "description": "EasyAgents",
5
5
  "easyAgentsDesktop": 1,
6
6
  "type": "module",
@@ -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 != "antigravity" else None
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")