aether-agent-framework 1.3.0__py3-none-any.whl
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.
- aether/__init__.py +9 -0
- aether/__main__.py +4 -0
- aether/agent.py +222 -0
- aether/cli.py +118 -0
- aether/config.py +98 -0
- aether/llm.py +227 -0
- aether/memory.py +45 -0
- aether/planner.py +31 -0
- aether/tools/__init__.py +101 -0
- aether/tools/base.py +72 -0
- aether/tools/data.py +199 -0
- aether/tools/delegate.py +163 -0
- aether/tools/files.py +150 -0
- aether/tools/knowledge.py +247 -0
- aether/tools/loader.py +85 -0
- aether/tools/net.py +141 -0
- aether/tools/productivity.py +250 -0
- aether/tools/python_exec.py +59 -0
- aether/tools/shell.py +121 -0
- aether/tools/web.py +113 -0
- aether/web/__init__.py +18 -0
- aether/web/__main__.py +62 -0
- aether/web/server.py +321 -0
- aether/web/static/index.html +470 -0
- aether_agent_framework-1.3.0.dist-info/METADATA +254 -0
- aether_agent_framework-1.3.0.dist-info/RECORD +30 -0
- aether_agent_framework-1.3.0.dist-info/WHEEL +5 -0
- aether_agent_framework-1.3.0.dist-info/entry_points.txt +3 -0
- aether_agent_framework-1.3.0.dist-info/licenses/LICENSE +21 -0
- aether_agent_framework-1.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""Productivity tools: email (SMTP) and calendar events (.ics files).
|
|
2
|
+
|
|
3
|
+
Both are free and dependency-free (standard library only). Neither stores
|
|
4
|
+
credentials anywhere: SMTP settings are read from the environment at call
|
|
5
|
+
time, so keys live in your shell profile or server unit file, never in code.
|
|
6
|
+
|
|
7
|
+
Environment variables for ``send_email``:
|
|
8
|
+
|
|
9
|
+
AETHER_SMTP_HOST e.g. smtp.gmail.com
|
|
10
|
+
AETHER_SMTP_PORT default 587
|
|
11
|
+
AETHER_SMTP_USER login username (usually your address)
|
|
12
|
+
AETHER_SMTP_PASS password or app-specific password
|
|
13
|
+
AETHER_SMTP_STARTTLS "0" to disable STARTTLS (default on)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
import re
|
|
20
|
+
import smtplib
|
|
21
|
+
import ssl
|
|
22
|
+
import uuid
|
|
23
|
+
from datetime import datetime, timedelta, timezone
|
|
24
|
+
from email.message import EmailMessage
|
|
25
|
+
from email.utils import make_msgid
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
from .base import Tool
|
|
29
|
+
|
|
30
|
+
_EMAIL_SPLIT = re.compile(r"[;,]\s*")
|
|
31
|
+
_ICAL_TEXT_ESCAPE = {"\\": "\\\\", ";": "\\;", ",": "\\,", "\n": "\\n"}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _ics_escape(text: str) -> str:
|
|
35
|
+
return "".join(_ICAL_TEXT_ESCAPE.get(ch, ch) for ch in str(text))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _ics_fold(line: str) -> str:
|
|
39
|
+
"""RFC 5545 line folding: max 75 octets per line, continuations start with a space."""
|
|
40
|
+
out, encoded = [], line.encode("utf-8")
|
|
41
|
+
while len(encoded) > 74:
|
|
42
|
+
cut = 74
|
|
43
|
+
# never split inside a UTF-8 multi-byte sequence
|
|
44
|
+
while cut > 0 and (encoded[cut] & 0xC0) == 0x80:
|
|
45
|
+
cut -= 1
|
|
46
|
+
out.append(encoded[:cut].decode("utf-8"))
|
|
47
|
+
encoded = b" " + encoded[cut:]
|
|
48
|
+
out.append(encoded.decode("utf-8"))
|
|
49
|
+
return "\r\n".join(out)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _parse_local(value: str) -> datetime:
|
|
53
|
+
"""Parse 'YYYY-MM-DD HH:MM' (local time) or a full ISO-8601 stamp."""
|
|
54
|
+
value = value.strip().replace("T", " ")
|
|
55
|
+
for fmt in ("%Y-%m-%d %H:%M", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H"):
|
|
56
|
+
try:
|
|
57
|
+
return datetime.strptime(value, fmt).astimezone()
|
|
58
|
+
except ValueError:
|
|
59
|
+
continue
|
|
60
|
+
dt = datetime.fromisoformat(value) # full ISO string, incl. offsets
|
|
61
|
+
if dt.tzinfo is None:
|
|
62
|
+
dt = dt.astimezone()
|
|
63
|
+
return dt
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _ics_utc(dt: datetime) -> str:
|
|
67
|
+
return dt.astimezone(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class SendEmail(Tool):
|
|
71
|
+
"""SMTP email tool - configuration comes from the environment."""
|
|
72
|
+
|
|
73
|
+
name = "send_email"
|
|
74
|
+
description = (
|
|
75
|
+
"Send an email via SMTP. Requires the server to set AETHER_SMTP_HOST, "
|
|
76
|
+
"AETHER_SMTP_PORT, AETHER_SMTP_USER and AETHER_SMTP_PASS environment "
|
|
77
|
+
"variables. Use dry_run=true to preview without sending."
|
|
78
|
+
)
|
|
79
|
+
parameters = {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"to": {"type": "string", "description": "One address, or several separated by ; or ,"},
|
|
83
|
+
"subject": {"type": "string"},
|
|
84
|
+
"body": {"type": "string"},
|
|
85
|
+
"cc": {"type": "string", "description": "Optional, same rules as 'to'"},
|
|
86
|
+
"dry_run": {
|
|
87
|
+
"type": "boolean",
|
|
88
|
+
"description": "Render the message and return it without sending.",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
"required": ["to", "subject", "body"],
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
def _addresses(self, raw: str) -> list[str]:
|
|
95
|
+
return [a.strip() for a in _EMAIL_SPLIT.split(raw or "") if a.strip()]
|
|
96
|
+
|
|
97
|
+
def run(self, args: dict) -> str:
|
|
98
|
+
host = os.environ.get("AETHER_SMTP_HOST", "")
|
|
99
|
+
user = os.environ.get("AETHER_SMTP_USER", "")
|
|
100
|
+
password = os.environ.get("AETHER_SMTP_PASS", "")
|
|
101
|
+
port = int(os.environ.get("AETHER_SMTP_PORT", "587") or "587")
|
|
102
|
+
starttls = os.environ.get("AETHER_SMTP_STARTTLS", "1") not in ("0", "false", "no")
|
|
103
|
+
|
|
104
|
+
to = self._addresses(str(args.get("to", "")))
|
|
105
|
+
cc = self._addresses(str(args.get("cc", "")))
|
|
106
|
+
subject = str(args.get("subject", ""))
|
|
107
|
+
body = str(args.get("body", ""))
|
|
108
|
+
|
|
109
|
+
if not to:
|
|
110
|
+
return "ERROR: 'to' must contain at least one email address."
|
|
111
|
+
|
|
112
|
+
if not host or not user or not password:
|
|
113
|
+
missing = [
|
|
114
|
+
name
|
|
115
|
+
for name, value in (
|
|
116
|
+
("AETHER_SMTP_HOST", host),
|
|
117
|
+
("AETHER_SMTP_USER", user),
|
|
118
|
+
("AETHER_SMTP_PASS", password),
|
|
119
|
+
)
|
|
120
|
+
if not value
|
|
121
|
+
]
|
|
122
|
+
return (
|
|
123
|
+
"ERROR: send_email is not configured on this server. "
|
|
124
|
+
"Set these environment variables first: " + ", ".join(missing)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
msg = EmailMessage()
|
|
128
|
+
msg["From"] = user
|
|
129
|
+
msg["To"] = ", ".join(to)
|
|
130
|
+
if cc:
|
|
131
|
+
msg["Cc"] = ", ".join(cc)
|
|
132
|
+
msg["Subject"] = subject
|
|
133
|
+
msg.set_content(body)
|
|
134
|
+
msg["Message-ID"] = make_msgid()
|
|
135
|
+
|
|
136
|
+
if args.get("dry_run"):
|
|
137
|
+
preview = msg.as_string()
|
|
138
|
+
return f"[dry run] message rendered, not sent:\n\n{preview}"
|
|
139
|
+
|
|
140
|
+
context = ssl.create_default_context()
|
|
141
|
+
try:
|
|
142
|
+
if starttls:
|
|
143
|
+
with smtplib.SMTP(host, port, timeout=30) as smtp:
|
|
144
|
+
smtp.ehlo()
|
|
145
|
+
smtp.starttls(context=context)
|
|
146
|
+
smtp.login(user, password)
|
|
147
|
+
smtp.send_message(msg)
|
|
148
|
+
else: # implicit TLS (port 465 style)
|
|
149
|
+
with smtplib.SMTP_SSL(host, port, context=context, timeout=30) as smtp:
|
|
150
|
+
smtp.login(user, password)
|
|
151
|
+
smtp.send_message(msg)
|
|
152
|
+
except (smtplib.SMTPException, OSError) as exc:
|
|
153
|
+
return f"ERROR: SMTP send failed: {exc.__class__.__name__}: {exc}"
|
|
154
|
+
|
|
155
|
+
recipients = ", ".join(to + cc)
|
|
156
|
+
return f"Email sent to {recipients} (subject: {subject})."
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class CreateCalendarEvent(Tool):
|
|
160
|
+
"""Write a standards-compliant .ics calendar event into the workspace.
|
|
161
|
+
|
|
162
|
+
Pure standard library: the produced file imports into Google Calendar,
|
|
163
|
+
Outlook, Apple Calendar and GNOME Calendar. Times given as local
|
|
164
|
+
'YYYY-MM-DD HH:MM' are converted to UTC in the file.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
name = "create_calendar_event"
|
|
168
|
+
description = (
|
|
169
|
+
"Create a calendar event file (.ics) in the workspace - importable into "
|
|
170
|
+
"Google Calendar, Outlook and Apple Calendar. Give times as "
|
|
171
|
+
"'YYYY-MM-DD HH:MM' (local time)."
|
|
172
|
+
)
|
|
173
|
+
parameters = {
|
|
174
|
+
"type": "object",
|
|
175
|
+
"properties": {
|
|
176
|
+
"title": {"type": "string"},
|
|
177
|
+
"start": {"type": "string", "description": "e.g. 2026-01-15 09:30 (local time)"},
|
|
178
|
+
"end": {"type": "string", "description": "either end or duration_minutes"},
|
|
179
|
+
"duration_minutes": {"type": "integer"},
|
|
180
|
+
"location": {"type": "string"},
|
|
181
|
+
"description": {"type": "string"},
|
|
182
|
+
"filename": {"type": "string", "description": "output file name, .ics added if missing"},
|
|
183
|
+
},
|
|
184
|
+
"required": ["title", "start"],
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
def __init__(self, workspace: Path):
|
|
188
|
+
self.workspace = workspace
|
|
189
|
+
|
|
190
|
+
def run(self, args: dict) -> str:
|
|
191
|
+
title = str(args.get("title", "")).strip()
|
|
192
|
+
start_raw = str(args.get("start", "")).strip()
|
|
193
|
+
if not title or not start_raw:
|
|
194
|
+
return "ERROR: 'title' and 'start' are required."
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
start = _parse_local(start_raw)
|
|
198
|
+
except ValueError:
|
|
199
|
+
return "ERROR: 'start' must look like '2026-01-15 09:30' or a full ISO-8601 stamp."
|
|
200
|
+
|
|
201
|
+
if args.get("end"):
|
|
202
|
+
try:
|
|
203
|
+
end = _parse_local(str(args["end"]))
|
|
204
|
+
except ValueError:
|
|
205
|
+
return "ERROR: 'end' must look like '2026-01-15 10:30' or a full ISO-8601 stamp."
|
|
206
|
+
if end <= start:
|
|
207
|
+
return "ERROR: 'end' must be after 'start'."
|
|
208
|
+
else:
|
|
209
|
+
minutes = int(args.get("duration_minutes", 30) or 30)
|
|
210
|
+
end = start + timedelta(minutes=minutes)
|
|
211
|
+
|
|
212
|
+
lines = [
|
|
213
|
+
"BEGIN:VCALENDAR",
|
|
214
|
+
"VERSION:2.0",
|
|
215
|
+
"PRODID:-//Aether//Calendar tool//EN",
|
|
216
|
+
"CALSCALE:GREGORIAN",
|
|
217
|
+
"BEGIN:VEVENT",
|
|
218
|
+
f"UID:{uuid.uuid4().hex}@aether.local",
|
|
219
|
+
f"DTSTAMP:{_ics_utc(datetime.now(timezone.utc))}",
|
|
220
|
+
f"DTSTART:{_ics_utc(start)}",
|
|
221
|
+
f"DTEND:{_ics_utc(end)}",
|
|
222
|
+
f"SUMMARY:{_ics_escape(title)}",
|
|
223
|
+
]
|
|
224
|
+
if args.get("location"):
|
|
225
|
+
lines.append(f"LOCATION:{_ics_escape(str(args['location']))}")
|
|
226
|
+
if args.get("description"):
|
|
227
|
+
lines.append(f"DESCRIPTION:{_ics_escape(str(args['description']))}")
|
|
228
|
+
lines += ["END:VEVENT", "END:VCALENDAR"]
|
|
229
|
+
|
|
230
|
+
folded = "\r\n".join(_ics_fold(line) for line in lines) + "\r\n"
|
|
231
|
+
|
|
232
|
+
out_dir = self.workspace / "calendar"
|
|
233
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
234
|
+
raw_name = str(args.get("filename") or "").strip()
|
|
235
|
+
if raw_name:
|
|
236
|
+
# basename only - never let the filename escape workspace/calendar
|
|
237
|
+
raw_name = Path(raw_name.replace("\\", "/")).name
|
|
238
|
+
if raw_name in ("", ".", ".."):
|
|
239
|
+
slug = re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-") or "event"
|
|
240
|
+
raw_name = f"{slug}-{start.strftime('%Y%m%d-%H%M')}"
|
|
241
|
+
if not raw_name.endswith(".ics"):
|
|
242
|
+
raw_name += ".ics"
|
|
243
|
+
|
|
244
|
+
path = out_dir / raw_name
|
|
245
|
+
path.write_text(folded, encoding="utf-8")
|
|
246
|
+
return (
|
|
247
|
+
f"Calendar event written: {path}\n"
|
|
248
|
+
f" '{title}' from {start.strftime('%Y-%m-%d %H:%M')} to "
|
|
249
|
+
f"{end.strftime('%Y-%m-%d %H:%M')} (stored as UTC in the .ics file)."
|
|
250
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Run Python code in a subprocess for math, data crunching and quick scripts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import uuid
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .base import Tool
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ExecutePython(Tool):
|
|
14
|
+
name = "execute_python"
|
|
15
|
+
description = (
|
|
16
|
+
"Execute Python 3 code and get stdout/stderr back. Use for math, data "
|
|
17
|
+
"processing, quick experiments and generating files."
|
|
18
|
+
)
|
|
19
|
+
parameters = {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"code": {"type": "string"},
|
|
23
|
+
"timeout": {"type": "integer", "description": "Seconds (default 60, max 300)."},
|
|
24
|
+
},
|
|
25
|
+
"required": ["code"],
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def __init__(self, workspace: Path):
|
|
29
|
+
self.workspace = Path(workspace)
|
|
30
|
+
|
|
31
|
+
def run(self, args: dict) -> str:
|
|
32
|
+
code = str(args.get("code", ""))
|
|
33
|
+
if not code.strip():
|
|
34
|
+
return "ERROR: 'code' is required."
|
|
35
|
+
timeout = min(int(args.get("timeout") or 60), 300)
|
|
36
|
+
|
|
37
|
+
tmp = self.workspace / f".aether_pyexec_{uuid.uuid4().hex[:8]}.py"
|
|
38
|
+
tmp.parent.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
tmp.write_text(code, encoding="utf-8")
|
|
40
|
+
try:
|
|
41
|
+
proc = subprocess.run(
|
|
42
|
+
[sys.executable, str(tmp)],
|
|
43
|
+
cwd=str(self.workspace),
|
|
44
|
+
capture_output=True,
|
|
45
|
+
text=True,
|
|
46
|
+
timeout=timeout,
|
|
47
|
+
)
|
|
48
|
+
except subprocess.TimeoutExpired:
|
|
49
|
+
return f"ERROR: execution timed out after {timeout}s."
|
|
50
|
+
finally:
|
|
51
|
+
tmp.unlink(missing_ok=True)
|
|
52
|
+
|
|
53
|
+
parts = []
|
|
54
|
+
if proc.stdout:
|
|
55
|
+
parts.append(f"stdout:\n{proc.stdout.strip()}")
|
|
56
|
+
if proc.stderr:
|
|
57
|
+
parts.append(f"stderr:\n{proc.stderr.strip()}")
|
|
58
|
+
parts.append(f"exit_code: {proc.returncode}")
|
|
59
|
+
return "\n---\n".join(parts)
|
aether/tools/shell.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Shell execution with a hard blocklist for catastrophic commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
from .base import Tool
|
|
9
|
+
|
|
10
|
+
SYSTEM_PREFIXES = (
|
|
11
|
+
"/usr", "/etc", "/var", "/bin", "/sbin", "/boot",
|
|
12
|
+
"/dev", "/proc", "/sys", "/lib", "/opt", "/root",
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
CONFIRM_PATTERNS = [
|
|
16
|
+
r"\bgit\s+push\b",
|
|
17
|
+
r"\b(curl|wget)\b[^|]*\|\s*(sudo\s+)?(ba|z|da)?sh\b",
|
|
18
|
+
r"\bsudo\b",
|
|
19
|
+
r"\bapt(-get)?\s+(install|remove|purge|upgrade)\b",
|
|
20
|
+
r"\bpip\s+install\b",
|
|
21
|
+
r"\bnpm\s+(install|i)\b",
|
|
22
|
+
r"\bdocker\b",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _has_recursive_rm(command: str) -> bool:
|
|
27
|
+
if not re.search(r"\brm\s", command):
|
|
28
|
+
return False
|
|
29
|
+
if not re.search(r"(?:^|\s)-{1,2}[a-z]*r|\s--recursive\b", command, re.I):
|
|
30
|
+
return False
|
|
31
|
+
for tok in command.split()[1:]:
|
|
32
|
+
tok = tok.strip("'\"")
|
|
33
|
+
if tok.startswith("-"):
|
|
34
|
+
continue
|
|
35
|
+
if tok in ("/", "~", "$HOME", "/*", "~/*", "$HOME/*", "${HOME}", "${HOME}/*"):
|
|
36
|
+
return True
|
|
37
|
+
if tok.startswith(SYSTEM_PREFIXES) or tok.startswith("~/"):
|
|
38
|
+
return True
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _catastrophic_reason(command: str) -> str | None:
|
|
43
|
+
"""Return a reason string if this command must never run, else None."""
|
|
44
|
+
if re.search(r":\(\)\s*\{\s*:\|:\s*&\s*\}\s*;\s*:", command):
|
|
45
|
+
return "fork bomb"
|
|
46
|
+
if re.search(r"\b(mkfs|shutdown|reboot|halt|poweroff|init\s+[06])\b", command):
|
|
47
|
+
return "filesystem or power operation"
|
|
48
|
+
if re.search(r"\bdd\b[^;|&]*of=/dev/(sd|hd|nvme|vd|mmcblk)", command):
|
|
49
|
+
return "raw disk write (dd)"
|
|
50
|
+
if re.search(r">\s*/dev/(sd[a-z]|nvme|vd[a-z])", command):
|
|
51
|
+
return "direct disk overwrite"
|
|
52
|
+
if re.search(
|
|
53
|
+
r"\b(chmod|chown)\s+-R\s+\S+\s+/(usr|etc|var|bin|sbin|boot|lib|opt)(/|\s|$)",
|
|
54
|
+
command,
|
|
55
|
+
):
|
|
56
|
+
return "recursive permission change on a system directory"
|
|
57
|
+
if _has_recursive_rm(command):
|
|
58
|
+
return "recursive delete of a system or home root"
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class RunCommand(Tool):
|
|
63
|
+
name = "run_command"
|
|
64
|
+
description = (
|
|
65
|
+
"Run a shell command inside the workspace and get stdout, stderr and the "
|
|
66
|
+
"exit code. Use for builds, git, package managers, tests, ffmpeg, etc."
|
|
67
|
+
)
|
|
68
|
+
parameters = {
|
|
69
|
+
"type": "object",
|
|
70
|
+
"properties": {
|
|
71
|
+
"command": {"type": "string", "description": "The shell command to execute."},
|
|
72
|
+
"timeout": {"type": "integer", "description": "Seconds to wait (default 120, max 600)."},
|
|
73
|
+
},
|
|
74
|
+
"required": ["command"],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
def __init__(self, workspace, auto_approve: bool = False):
|
|
78
|
+
self.workspace = workspace
|
|
79
|
+
self.auto_approve = auto_approve
|
|
80
|
+
|
|
81
|
+
def run(self, args: dict) -> str:
|
|
82
|
+
command = str(args.get("command", "")).strip()
|
|
83
|
+
if not command:
|
|
84
|
+
return "ERROR: 'command' is required."
|
|
85
|
+
timeout = min(int(args.get("timeout") or 120), 600)
|
|
86
|
+
|
|
87
|
+
reason = _catastrophic_reason(command)
|
|
88
|
+
if reason:
|
|
89
|
+
return (
|
|
90
|
+
f"BLOCKED ({reason}): Aether never executes destructive system "
|
|
91
|
+
"commands - this protects your machine even in full-auto mode. "
|
|
92
|
+
"Rephrase the task safely."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
needs_confirm = any(re.search(p, command) for p in CONFIRM_PATTERNS)
|
|
96
|
+
if needs_confirm and not self.auto_approve:
|
|
97
|
+
answer = input(
|
|
98
|
+
f"\n[Aether] potentially impactful command:\n $ {command}\nApprove? [y/N] "
|
|
99
|
+
).strip().lower()
|
|
100
|
+
if answer not in ("y", "yes"):
|
|
101
|
+
return "DENIED by user. Choose a different approach or finish."
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
proc = subprocess.run(
|
|
105
|
+
command,
|
|
106
|
+
shell=True,
|
|
107
|
+
cwd=str(self.workspace),
|
|
108
|
+
capture_output=True,
|
|
109
|
+
text=True,
|
|
110
|
+
timeout=timeout,
|
|
111
|
+
)
|
|
112
|
+
except subprocess.TimeoutExpired:
|
|
113
|
+
return f"ERROR: command timed out after {timeout}s."
|
|
114
|
+
|
|
115
|
+
parts = []
|
|
116
|
+
if proc.stdout:
|
|
117
|
+
parts.append(f"stdout:\n{proc.stdout.strip()}")
|
|
118
|
+
if proc.stderr:
|
|
119
|
+
parts.append(f"stderr:\n{proc.stderr.strip()}")
|
|
120
|
+
parts.append(f"exit_code: {proc.returncode}")
|
|
121
|
+
return "\n---\n".join(parts)
|
aether/tools/web.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Free web access: DuckDuckGo search + page fetching. No API keys."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html as html_mod
|
|
6
|
+
import re
|
|
7
|
+
from urllib.parse import parse_qs, unquote, urlparse
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
from .base import Tool
|
|
12
|
+
|
|
13
|
+
HEADERS = {
|
|
14
|
+
"User-Agent": (
|
|
15
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
|
16
|
+
"(KHTML, like Gecko) Chrome/124.0 Safari/537.36"
|
|
17
|
+
),
|
|
18
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _strip_tags(raw: str) -> str:
|
|
23
|
+
raw = html_mod.unescape(raw)
|
|
24
|
+
raw = re.sub(r"(?is)<(script|style|noscript|svg)[^>]*>.*?</\1>", " ", raw)
|
|
25
|
+
raw = re.sub(r"(?s)<[^>]+>", " ", raw)
|
|
26
|
+
raw = re.sub(r"\s+", " ", raw)
|
|
27
|
+
return raw.strip()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _clean_ddg_url(raw: str) -> str:
|
|
31
|
+
if raw.startswith("//"):
|
|
32
|
+
raw = "https:" + raw
|
|
33
|
+
if "uddg=" in raw:
|
|
34
|
+
try:
|
|
35
|
+
qs = parse_qs(urlparse(raw).query)
|
|
36
|
+
return unquote(qs["uddg"][0])
|
|
37
|
+
except Exception: # noqa: BLE001
|
|
38
|
+
pass
|
|
39
|
+
return raw
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class WebSearch(Tool):
|
|
43
|
+
name = "web_search"
|
|
44
|
+
description = (
|
|
45
|
+
"Search the web with DuckDuckGo and get titles, URLs and snippets. "
|
|
46
|
+
"No API key needed."
|
|
47
|
+
)
|
|
48
|
+
parameters = {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"query": {"type": "string"},
|
|
52
|
+
"max_results": {"type": "integer", "description": "Default 6, max 10."},
|
|
53
|
+
},
|
|
54
|
+
"required": ["query"],
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
def run(self, args: dict) -> str:
|
|
58
|
+
query = str(args.get("query", "")).strip()
|
|
59
|
+
if not query:
|
|
60
|
+
return "ERROR: 'query' is required."
|
|
61
|
+
max_results = min(int(args.get("max_results") or 6), 10)
|
|
62
|
+
|
|
63
|
+
resp = requests.post(
|
|
64
|
+
"https://html.duckduckgo.com/html/",
|
|
65
|
+
data={"q": query},
|
|
66
|
+
headers=HEADERS,
|
|
67
|
+
timeout=30,
|
|
68
|
+
)
|
|
69
|
+
resp.raise_for_status()
|
|
70
|
+
|
|
71
|
+
results = []
|
|
72
|
+
for block in re.split(r'class="result\b', resp.text)[1:]:
|
|
73
|
+
link = re.search(
|
|
74
|
+
r'<a[^>]+class="result__a"[^>]+href="([^"]+)"[^>]*>(.*?)</a>',
|
|
75
|
+
block,
|
|
76
|
+
re.S,
|
|
77
|
+
)
|
|
78
|
+
if not link:
|
|
79
|
+
continue
|
|
80
|
+
url = _clean_ddg_url(link.group(1))
|
|
81
|
+
title = _strip_tags(link.group(2))
|
|
82
|
+
snippet_m = re.search(r'class="result__snippet"[^>]*>(.*?)</a>', block, re.S)
|
|
83
|
+
snippet = _strip_tags(snippet_m.group(1)) if snippet_m else ""
|
|
84
|
+
if url:
|
|
85
|
+
results.append(f"- {title}\n {url}\n {snippet[:300]}")
|
|
86
|
+
if len(results) >= max_results:
|
|
87
|
+
break
|
|
88
|
+
|
|
89
|
+
if not results:
|
|
90
|
+
return "No results parsed (DuckDuckGo markup may have changed). Try fetch_url on a known site."
|
|
91
|
+
return "\n".join(results)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class FetchURL(Tool):
|
|
95
|
+
name = "fetch_url"
|
|
96
|
+
description = "Fetch a web page and return its readable text (HTML stripped)."
|
|
97
|
+
parameters = {
|
|
98
|
+
"type": "object",
|
|
99
|
+
"properties": {"url": {"type": "string"}},
|
|
100
|
+
"required": ["url"],
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
def run(self, args: dict) -> str:
|
|
104
|
+
url = str(args.get("url", "")).strip()
|
|
105
|
+
parsed = urlparse(url)
|
|
106
|
+
if parsed.scheme not in ("http", "https") or not parsed.netloc:
|
|
107
|
+
return "ERROR: provide a valid http(s) URL."
|
|
108
|
+
resp = requests.get(url, headers=HEADERS, timeout=30, allow_redirects=True)
|
|
109
|
+
resp.raise_for_status()
|
|
110
|
+
content_type = resp.headers.get("Content-Type", "")
|
|
111
|
+
if "html" not in content_type and "text" not in content_type:
|
|
112
|
+
return f"[non-text content: {content_type}; {len(resp.content)} bytes]"
|
|
113
|
+
return _strip_tags(resp.text)
|
aether/web/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Aether live Web UI (optional: pip install flask).
|
|
2
|
+
|
|
3
|
+
The server module imports Flask at module level, so we expose it lazily:
|
|
4
|
+
importing ``aether.web`` alone never requires Flask, and ``python -m
|
|
5
|
+
aether.web`` can print a friendly install hint instead of a traceback.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
__all__ = ["RunManager", "create_app"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def __getattr__(name: str):
|
|
14
|
+
if name in ("RunManager", "create_app"):
|
|
15
|
+
from .server import RunManager, create_app
|
|
16
|
+
|
|
17
|
+
return {"RunManager": RunManager, "create_app": create_app}[name]
|
|
18
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
aether/web/__main__.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Entry point: python -m aether.web
|
|
2
|
+
|
|
3
|
+
Starts the local dashboard. The base provider/model/workspace come from
|
|
4
|
+
config.yaml / environment / CLI flags exactly like `python -m aether`;
|
|
5
|
+
each run can override provider, base_url, model and max_iterations from
|
|
6
|
+
the UI. API keys are never entered in the browser - set AETHER_API_KEY
|
|
7
|
+
in the environment instead.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main(argv: list[str] | None = None) -> int:
|
|
17
|
+
parser = argparse.ArgumentParser(
|
|
18
|
+
prog="aether.web", description="Aether live Web UI (local dashboard)"
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument("--host", default="127.0.0.1", help="bind address (default 127.0.0.1)")
|
|
21
|
+
parser.add_argument("--port", type=int, default=5000)
|
|
22
|
+
parser.add_argument("--config", help="path to config.yaml")
|
|
23
|
+
parser.add_argument("--provider", choices=["openai_compatible", "ollama", "mock"])
|
|
24
|
+
parser.add_argument("--base-url", help="API root for openai_compatible")
|
|
25
|
+
parser.add_argument("--model")
|
|
26
|
+
parser.add_argument("--workspace", help="directory the agent operates in")
|
|
27
|
+
parser.add_argument("--max-iterations", type=int)
|
|
28
|
+
parser.add_argument("--max-delegate-depth", type=int,
|
|
29
|
+
help="sub-agent nesting via delegate_task (0 disables)")
|
|
30
|
+
parser.add_argument("--delegate-max-iterations", type=int)
|
|
31
|
+
parser.add_argument("--debug", action="store_true")
|
|
32
|
+
args = parser.parse_args(argv)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
from .server import create_app
|
|
36
|
+
except ImportError:
|
|
37
|
+
print(
|
|
38
|
+
"The Web UI needs Flask. Install it with:\n"
|
|
39
|
+
" pip install flask\n"
|
|
40
|
+
"or, if you installed Aether from PyPI:\n"
|
|
41
|
+
" pip install 'aether-agent-framework[web]'",
|
|
42
|
+
file=sys.stderr,
|
|
43
|
+
)
|
|
44
|
+
return 1
|
|
45
|
+
|
|
46
|
+
app = create_app(
|
|
47
|
+
args.config,
|
|
48
|
+
provider=args.provider,
|
|
49
|
+
base_url=args.base_url,
|
|
50
|
+
model=args.model,
|
|
51
|
+
workspace=args.workspace,
|
|
52
|
+
max_iterations=args.max_iterations,
|
|
53
|
+
max_delegate_depth=args.max_delegate_depth,
|
|
54
|
+
delegate_max_iterations=args.delegate_max_iterations,
|
|
55
|
+
)
|
|
56
|
+
print(f"Aether Web UI on http://{args.host}:{args.port} (Ctrl-C to quit)")
|
|
57
|
+
app.run(host=args.host, port=args.port, threaded=True, debug=args.debug)
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
raise SystemExit(main())
|