@unionschool/easy-agents 0.2.3 → 0.3.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 +81 -10
- package/bin/easy-agents.js +170 -16
- package/bin/mac-reports.js +149 -0
- package/bin/mac-service.js +119 -0
- package/bin/pair.js +79 -0
- package/bin/portable-service.js +66 -0
- package/bin/run.js +234 -0
- package/bin/tasks.js +134 -0
- package/bin/terminal.js +66 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +539 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +142 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +751 -0
- package/node_modules/ws/lib/sender.js +610 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +565 -0
- package/node_modules/ws/lib/websocket.js +1471 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +25 -2
- package/runtime/desktop_chat.py +105 -0
- package/runtime/easyagents_core/file_delivery.py +166 -0
- package/runtime/easyagents_core/git_sync.py +272 -0
- package/runtime/easyagents_core/mcp_call.py +165 -0
- package/runtime/easyagents_core/member_sync.py +128 -0
- package/runtime/easyagents_core/process_support.py +60 -0
- package/runtime/ssh_terminal.py +89 -0
- package/runtime/sync.py +17 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ws",
|
|
3
|
+
"version": "8.23.0",
|
|
4
|
+
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"HyBi",
|
|
7
|
+
"Push",
|
|
8
|
+
"RFC-6455",
|
|
9
|
+
"WebSocket",
|
|
10
|
+
"WebSockets",
|
|
11
|
+
"real-time"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/websockets/ws",
|
|
14
|
+
"bugs": "https://github.com/websockets/ws/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/websockets/ws.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"browser": "./browser.js",
|
|
25
|
+
"import": "./wrapper.mjs",
|
|
26
|
+
"require": "./index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"browser": "browser.js",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=10.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"browser.js",
|
|
36
|
+
"index.js",
|
|
37
|
+
"lib/*.js",
|
|
38
|
+
"wrapper.mjs"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js",
|
|
42
|
+
"integration": "mocha --throw-deprecation test/*.integration.js",
|
|
43
|
+
"lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"bufferutil": "^4.0.1",
|
|
47
|
+
"utf-8-validate": ">=5.0.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"bufferutil": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"utf-8-validate": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@eslint/js": "^10.0.1",
|
|
59
|
+
"benchmark": "^2.1.4",
|
|
60
|
+
"bufferutil": "^4.0.1",
|
|
61
|
+
"eslint": "^10.0.1",
|
|
62
|
+
"eslint-config-prettier": "^10.0.1",
|
|
63
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
64
|
+
"globals": "^17.0.0",
|
|
65
|
+
"mocha": "^8.4.0",
|
|
66
|
+
"nyc": "^15.0.0",
|
|
67
|
+
"prettier": "^3.0.0",
|
|
68
|
+
"utf-8-validate": "^6.0.0"
|
|
69
|
+
},
|
|
70
|
+
"allowScripts": {
|
|
71
|
+
"bufferutil": true,
|
|
72
|
+
"utf-8-validate": true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createWebSocketStream from './lib/stream.js';
|
|
2
|
+
import extension from './lib/extension.js';
|
|
3
|
+
import PerMessageDeflate from './lib/permessage-deflate.js';
|
|
4
|
+
import Receiver from './lib/receiver.js';
|
|
5
|
+
import Sender from './lib/sender.js';
|
|
6
|
+
import subprotocol from './lib/subprotocol.js';
|
|
7
|
+
import WebSocket from './lib/websocket.js';
|
|
8
|
+
import WebSocketServer from './lib/websocket-server.js';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
createWebSocketStream,
|
|
12
|
+
extension,
|
|
13
|
+
PerMessageDeflate,
|
|
14
|
+
Receiver,
|
|
15
|
+
Sender,
|
|
16
|
+
subprotocol,
|
|
17
|
+
WebSocket,
|
|
18
|
+
WebSocketServer
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default WebSocket;
|
package/package.json
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unionschool/easy-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "EasyAgents Client",
|
|
5
|
+
"easyAgentsDesktop": 1,
|
|
5
6
|
"type": "module",
|
|
6
7
|
"bin": {
|
|
7
8
|
"easy-agents": "bin/easy-agents.js"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
|
-
"bin/easy-agents.js"
|
|
11
|
+
"bin/easy-agents.js",
|
|
12
|
+
"bin/pair.js",
|
|
13
|
+
"bin/run.js",
|
|
14
|
+
"bin/terminal.js",
|
|
15
|
+
"bin/tasks.js",
|
|
16
|
+
"bin/mac-reports.js",
|
|
17
|
+
"bin/mac-service.js",
|
|
18
|
+
"bin/portable-service.js",
|
|
19
|
+
"runtime/sync.py",
|
|
20
|
+
"runtime/ssh_terminal.py",
|
|
21
|
+
"runtime/desktop_chat.py",
|
|
22
|
+
"runtime/easyagents_core/*.py"
|
|
11
23
|
],
|
|
12
24
|
"engines": {
|
|
13
25
|
"node": ">=22"
|
|
@@ -15,5 +27,16 @@
|
|
|
15
27
|
"publishConfig": {
|
|
16
28
|
"access": "public",
|
|
17
29
|
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"ws": "8.23.0"
|
|
33
|
+
},
|
|
34
|
+
"bundleDependencies": [
|
|
35
|
+
"ws"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prepack": "node scripts/bundle-core.js",
|
|
39
|
+
"pretest": "node scripts/bundle-core.js",
|
|
40
|
+
"test": "node --test"
|
|
18
41
|
}
|
|
19
42
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Run a project message with the tool adapters shipped in the desktop installation."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import signal
|
|
6
|
+
import sys
|
|
7
|
+
import threading
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from uuid import UUID
|
|
10
|
+
|
|
11
|
+
resources = os.environ.get("EASYAGENTS_MAC_RESOURCES") or os.environ["EASYAGENTS_DESKTOP_RESOURCES"]
|
|
12
|
+
sys.path.insert(0, str(Path(resources) / "lib"))
|
|
13
|
+
from easyagents_core.tools import ClaudeCodeAdapter, CodexAdapter
|
|
14
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TextClaude(ClaudeCodeAdapter):
|
|
18
|
+
def _command(self, resume_session_ref):
|
|
19
|
+
command = [self.executable, "--safe-mode", "--print", "--input-format", "stream-json",
|
|
20
|
+
"--output-format", "stream-json", "--verbose", "--tools", "", "--strict-mcp-config",
|
|
21
|
+
"--disable-slash-commands"]
|
|
22
|
+
if resume_session_ref:
|
|
23
|
+
command.extend(["--resume", resume_session_ref])
|
|
24
|
+
return command
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def failed(code, detail):
|
|
28
|
+
return {"status": "failed", "failure_code": code, "failure_detail": detail}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def workflow_guide(binding, run_id):
|
|
32
|
+
from runtime.easyagents_core.mcp_call import MCPError, request
|
|
33
|
+
|
|
34
|
+
auth = json.loads(Path(binding["file"]).read_text())
|
|
35
|
+
if auth["server"].rstrip("/") != binding["gateway"] or not auth["agent_token"]:
|
|
36
|
+
raise ValueError("Agent 凭据与已配对网关不一致")
|
|
37
|
+
auth["server"] = binding["gateway"]
|
|
38
|
+
os.environ["EASYAGENTS_RUN_ID"] = run_id
|
|
39
|
+
try:
|
|
40
|
+
result = request(auth, "tools/call", {"name": "get_workflow_guide", "arguments": {}})
|
|
41
|
+
except MCPError:
|
|
42
|
+
raise ValueError("平台规程读取失败") from None
|
|
43
|
+
if result.get("isError"):
|
|
44
|
+
raise ValueError("平台规程读取失败")
|
|
45
|
+
text = "\n".join(item["text"] for item in result["content"] if item.get("type") == "text")
|
|
46
|
+
if not text.strip():
|
|
47
|
+
raise ValueError("平台返回的规程为空")
|
|
48
|
+
return text
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def run(content, cancelled):
|
|
52
|
+
tool = content["tool"]
|
|
53
|
+
if tool == "codex":
|
|
54
|
+
adapter = CodexAdapter()
|
|
55
|
+
options = {"sandbox_policy": {"type": "readOnly", "networkAccess": False}}
|
|
56
|
+
elif tool == "claude_code":
|
|
57
|
+
adapter = TextClaude()
|
|
58
|
+
options = {}
|
|
59
|
+
else:
|
|
60
|
+
return failed("unsupported_task", "此工具尚未接入设备文本对话")
|
|
61
|
+
if not shutil.which(adapter.executable):
|
|
62
|
+
return failed("tool_missing", "本机未找到 " + adapter.executable_name)
|
|
63
|
+
|
|
64
|
+
resume = content.get("resume")
|
|
65
|
+
if resume is not None:
|
|
66
|
+
try:
|
|
67
|
+
UUID(resume)
|
|
68
|
+
except (ValueError, AttributeError, TypeError):
|
|
69
|
+
return failed("bad_session", "工具会话标识无效")
|
|
70
|
+
local = content.get("workspace")
|
|
71
|
+
if local:
|
|
72
|
+
cwd = (Path.home() / Path(local).expanduser()).resolve()
|
|
73
|
+
if not cwd.is_dir() or cwd == Path(cwd.anchor):
|
|
74
|
+
return failed("workspace_missing", "请核对该 Agent 在设备上登记的工作目录")
|
|
75
|
+
else:
|
|
76
|
+
# Claude locates earlier conversations by directory even when all tools are disabled.
|
|
77
|
+
cwd = Path(os.environ["EASYAGENTS_CONFIG_DIR"]) / "chat-workspace"
|
|
78
|
+
cwd.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
79
|
+
|
|
80
|
+
prompt = content["prompt"]
|
|
81
|
+
run_id = content.get("workRunId")
|
|
82
|
+
if run_id and not content.get("passthrough"):
|
|
83
|
+
guidance = "平台任务规程当前不可用。可回复普通项目消息;涉及平台登记、派发或审批时,须明确说明未办理。"
|
|
84
|
+
if content.get("credential"):
|
|
85
|
+
try:
|
|
86
|
+
guide = workflow_guide(content["credential"], run_id)
|
|
87
|
+
except (OSError, ValueError, KeyError, TypeError, RuntimeError):
|
|
88
|
+
pass
|
|
89
|
+
else:
|
|
90
|
+
guidance = "平台任务规程:\n" + guide
|
|
91
|
+
prompt = f"本次调度模式:platform;运行编号:{run_id}\n{guidance}\n\n{prompt}"
|
|
92
|
+
result = adapter.invoke(prompt=prompt, cwd=cwd, resume_session_ref=resume,
|
|
93
|
+
timeout_seconds=content["timeout"], cancel_event=cancelled,
|
|
94
|
+
model=content.get("model"), platform_run_id=run_id, **options)
|
|
95
|
+
if result.reply_text and len(result.reply_text) > 1_000_000:
|
|
96
|
+
return failed("bad_output", "工具回复超过平台长度上限")
|
|
97
|
+
fields = ("status", "reply_text", "tool_session_ref", "tool_version", "model_name",
|
|
98
|
+
"usage", "context", "failure_code", "failure_detail")
|
|
99
|
+
return {name: getattr(result, name) for name in fields if getattr(result, name) is not None}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
cancelled = threading.Event()
|
|
104
|
+
signal.signal(signal.SIGTERM, lambda *_: cancelled.set())
|
|
105
|
+
print(json.dumps(run(json.load(sys.stdin), cancelled), ensure_ascii=False))
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""运行前只核对本地文件;不依赖同步软件或 Git 元数据。"""
|
|
2
|
+
import hashlib
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import re
|
|
6
|
+
import stat
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
from .git_sync import GitError
|
|
10
|
+
|
|
11
|
+
INTERVAL = 10
|
|
12
|
+
TIMEOUT = 60
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def validate_name(name):
|
|
16
|
+
if (not isinstance(name, str) or not name or len(name) > 512
|
|
17
|
+
or '\\' in name or ':' in name or any(ord(c) < 32 or ord(c) == 127 for c in name)
|
|
18
|
+
or any(p in ('', '.', '..') or p.casefold() == '.git' for p in name.split('/'))):
|
|
19
|
+
raise GitError('file_delivery_invalid', '文件交付路径无效')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def target(root: Path, name: str) -> Path:
|
|
23
|
+
validate_name(name)
|
|
24
|
+
root = root.resolve()
|
|
25
|
+
path = root / name
|
|
26
|
+
if any(p.is_symlink() for p in (path, *path.parents) if p != root and root in p.parents):
|
|
27
|
+
raise GitError('file_delivery_invalid', '文件交付不能经过符号链接')
|
|
28
|
+
if not path.resolve().is_relative_to(root):
|
|
29
|
+
raise GitError('file_delivery_invalid', '文件交付路径超出工作目录')
|
|
30
|
+
return path
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def digest(path: Path, *, task_content=False, deadline=None, cancel=None) -> str | None:
|
|
34
|
+
try:
|
|
35
|
+
fd = os.open(path, os.O_RDONLY | getattr(os, 'O_NOFOLLOW', 0) | getattr(os, 'O_NONBLOCK', 0))
|
|
36
|
+
with os.fdopen(fd, 'rb') as stream:
|
|
37
|
+
info = os.fstat(stream.fileno())
|
|
38
|
+
if not stat.S_ISREG(info.st_mode):
|
|
39
|
+
raise GitError('file_delivery_read', '交付对象须为普通文件')
|
|
40
|
+
task_content = task_content and info.st_size <= 512 * 1024
|
|
41
|
+
hashed = hashlib.sha256()
|
|
42
|
+
blocks = iter(stream.readline, b'') if task_content else iter(lambda: stream.read(1024 * 1024), b'')
|
|
43
|
+
for index, line in enumerate(blocks):
|
|
44
|
+
if cancel is not None and cancel.is_set():
|
|
45
|
+
raise GitError('cancelled', '已取消')
|
|
46
|
+
if deadline is not None and time.monotonic() > deadline:
|
|
47
|
+
raise GitError('file_delivery_timeout', '文件核验等待到期')
|
|
48
|
+
if task_content:
|
|
49
|
+
# 发布后只回填平台任务ID,不应使同一份任务正文失配。
|
|
50
|
+
if index < 32 and line.startswith('- 平台任务 ID:'.encode()):
|
|
51
|
+
value = line.decode('utf-8', errors='replace').split(':', 1)[1].strip()
|
|
52
|
+
if value in ('待回填', '—') or re.fullmatch(r'[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}', value):
|
|
53
|
+
continue
|
|
54
|
+
hashed.update(line)
|
|
55
|
+
return hashed.hexdigest()
|
|
56
|
+
except FileNotFoundError:
|
|
57
|
+
return None
|
|
58
|
+
except OSError:
|
|
59
|
+
raise GitError('file_delivery_read', '暂时无法核对交付文件') from None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def manifest(root: Path, paths: list[str]) -> list[dict]:
|
|
63
|
+
# shortcut: 只核对声明的本次文件;需要自动发现漏报时再增加受控工作区快照。
|
|
64
|
+
if (not isinstance(paths, list) or not 1 <= len(paths) <= 5000
|
|
65
|
+
or not all(isinstance(p, str) for p in paths) or len(set(paths)) != len(paths)):
|
|
66
|
+
raise GitError('file_delivery_invalid', '须提供不重复的本次变更文件清单')
|
|
67
|
+
files = []
|
|
68
|
+
for name in paths:
|
|
69
|
+
path = target(root, name)
|
|
70
|
+
item = dict(path=name, sha256=digest(path))
|
|
71
|
+
if item['sha256'] and path.name in ('任务.md', 'task.md'):
|
|
72
|
+
item['task_sha256'] = digest(path, task_content=True)
|
|
73
|
+
files.append(item)
|
|
74
|
+
return files
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def validate(root: Path, files: list[dict], *, check_target=True):
|
|
78
|
+
if not isinstance(files, list) or not 1 <= len(files) <= 5000:
|
|
79
|
+
raise GitError('file_delivery_invalid', '缺少本次文件交付依据')
|
|
80
|
+
seen = set()
|
|
81
|
+
for item in files:
|
|
82
|
+
if (not isinstance(item, dict) or not {'path', 'sha256'} <= set(item)
|
|
83
|
+
or set(item) - {'path', 'sha256', 'task_sha256'}
|
|
84
|
+
or not isinstance(item['path'], str) or item['path'] in seen
|
|
85
|
+
or (item['sha256'] is not None and
|
|
86
|
+
(not isinstance(item['sha256'], str) or not re.fullmatch('[0-9a-f]{64}', item['sha256'])))):
|
|
87
|
+
raise GitError('file_delivery_invalid', '本次文件交付依据无效')
|
|
88
|
+
if 'task_sha256' in item and (Path(item['path']).name not in ('任务.md', 'task.md')
|
|
89
|
+
or not item['sha256'] or not isinstance(item['task_sha256'], str)
|
|
90
|
+
or not re.fullmatch('[0-9a-f]{64}', item['task_sha256'])):
|
|
91
|
+
raise GitError('file_delivery_invalid', '任务正文摘要无效')
|
|
92
|
+
if check_target:
|
|
93
|
+
target(root, item['path'])
|
|
94
|
+
else:
|
|
95
|
+
validate_name(item['path'])
|
|
96
|
+
seen.add(item['path'])
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def observed(root, item, *, deadline, cancel):
|
|
100
|
+
path = target(root, item['path'])
|
|
101
|
+
actual = digest(path, deadline=deadline, cancel=cancel)
|
|
102
|
+
matches = actual == item['sha256'] or (actual and item.get('task_sha256') and
|
|
103
|
+
digest(path, task_content=True, deadline=deadline, cancel=cancel) == item['task_sha256'])
|
|
104
|
+
return matches, actual
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def ready(root: Path, files: list[dict], *, deadline=None, cancel=None) -> bool:
|
|
108
|
+
validate(root, files)
|
|
109
|
+
try:
|
|
110
|
+
return all(observed(root, item, deadline=deadline, cancel=cancel)[0] for item in files)
|
|
111
|
+
except GitError as exc:
|
|
112
|
+
if exc.code not in ('file_delivery_read', 'file_delivery_timeout'):
|
|
113
|
+
raise
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def differences(root, files, *, deadline, cancel):
|
|
118
|
+
results = []
|
|
119
|
+
for item in files:
|
|
120
|
+
if cancel.is_set():
|
|
121
|
+
raise GitError('cancelled', '已取消')
|
|
122
|
+
try:
|
|
123
|
+
if deadline is not None and time.monotonic() > deadline:
|
|
124
|
+
raise GitError('file_delivery_timeout', '文件核验等待到期')
|
|
125
|
+
matched, actual = observed(root, item, deadline=deadline, cancel=cancel)
|
|
126
|
+
if matched:
|
|
127
|
+
continue
|
|
128
|
+
results.append(dict(path=item['path'], reason='changed' if actual else 'missing', sha256=actual))
|
|
129
|
+
except GitError as exc:
|
|
130
|
+
if exc.code not in ('file_delivery_invalid', 'file_delivery_read', 'file_delivery_timeout'):
|
|
131
|
+
raise
|
|
132
|
+
results.append(dict(path=item['path'], reason='unreadable', sha256=None))
|
|
133
|
+
except (OSError, RuntimeError):
|
|
134
|
+
results.append(dict(path=item['path'], reason='unreadable', sha256=None))
|
|
135
|
+
return results
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def wait(root: Path, files: list[dict], cancel, *, timeout=TIMEOUT, interval=INTERVAL,
|
|
139
|
+
report: list | None = None) -> bool:
|
|
140
|
+
validate(root, files, check_target=report is None)
|
|
141
|
+
deadline = time.monotonic() + timeout
|
|
142
|
+
final_check = deadline - min(0.25, timeout / 2)
|
|
143
|
+
while True:
|
|
144
|
+
if cancel.is_set():
|
|
145
|
+
raise GitError('cancelled', '已取消')
|
|
146
|
+
if report is not None:
|
|
147
|
+
last = time.monotonic() >= final_check
|
|
148
|
+
report[:] = differences(root, files, deadline=deadline if timeout else None,
|
|
149
|
+
cancel=cancel)
|
|
150
|
+
if not report:
|
|
151
|
+
return True
|
|
152
|
+
if last:
|
|
153
|
+
cancel.wait(max(0, deadline - time.monotonic()))
|
|
154
|
+
if cancel.is_set():
|
|
155
|
+
raise GitError('cancelled', '已取消')
|
|
156
|
+
return False
|
|
157
|
+
cancel.wait(max(0, min(interval, final_check - time.monotonic())))
|
|
158
|
+
continue
|
|
159
|
+
else:
|
|
160
|
+
is_ready = ready(root, files, deadline=deadline, cancel=cancel)
|
|
161
|
+
if is_ready:
|
|
162
|
+
return True
|
|
163
|
+
remaining = deadline - time.monotonic()
|
|
164
|
+
if remaining <= 0:
|
|
165
|
+
return False
|
|
166
|
+
cancel.wait(min(interval, remaining))
|