mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 12:17:45 +02:00
[eric] scheduled tasks: agent can now manage workflows itself + tons of safety, cross-platform polish, and edge-case fixes
This commit is contained in:
+16
-24
@@ -106,10 +106,7 @@ else
|
||||
echo "WARNING: Claude binary not found at $CLAUDE_BIN"
|
||||
fi
|
||||
|
||||
# Clean up build artifacts to reduce size. Drop test packages and any
|
||||
# stale __pycache__/.pyc from the upstream Python tarball — we want our
|
||||
# own freshly-compiled bytecode (next step), not whatever the upstream
|
||||
# build happened to ship.
|
||||
# Drop test packages + stale __pycache__/.pyc; we recompile our own bytecode next.
|
||||
echo "Cleaning up..."
|
||||
find "$PYTHON_ENV_DIR" -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
||||
find "$PYTHON_ENV_DIR" -name "*.pyc" -delete 2>/dev/null || true
|
||||
@@ -119,22 +116,22 @@ find "$PYTHON_ENV_DIR" -type d -name "test" -exec rm -rf {} + 2>/dev/null || tru
|
||||
# Strip parts of the Python distribution we provably don't use at runtime.
|
||||
# Each removal here has been individually verified.
|
||||
echo "Stripping unused Python distribution files..."
|
||||
# C headers — only needed when building C extensions, never at runtime.
|
||||
# C headers: only for building C extensions, never at runtime.
|
||||
rm -rf "$PYTHON_ENV_DIR/include"
|
||||
# IDLE editor + Tk GUI toolkit — embedded headless backend has no UI.
|
||||
# IDLE + Tk: headless backend has no GUI.
|
||||
rm -rf "$PYTHON_ENV_DIR/lib/python3.13/idlelib"
|
||||
rm -rf "$PYTHON_ENV_DIR/lib/python3.13/tkinter"
|
||||
# Pip bootstrap module — backend never installs packages at runtime.
|
||||
# Pip bootstrap: backend never installs packages at runtime.
|
||||
rm -rf "$PYTHON_ENV_DIR/lib/python3.13/ensurepip"
|
||||
# Educational drawing examples that ship with stdlib — never imported.
|
||||
# Stdlib turtle examples, never imported.
|
||||
rm -rf "$PYTHON_ENV_DIR/lib/python3.13/turtledemo"
|
||||
# Man pages / desktop-integration files — embedded Python doesn't read these.
|
||||
# Man pages / desktop integration files.
|
||||
rm -rf "$PYTHON_ENV_DIR/share"
|
||||
|
||||
# ----- Babel locale-data trim (~30 MB / ~900 files) -----
|
||||
# Babel ships 1,084 CLDR locale .dat files (~30 MB). Our backend doesn't use
|
||||
# babel directly, but trafilatura's transitive dep `courlan/filters.py:184`
|
||||
# calls `Locale.parse(seg)` on URL path segments — if a stripped locale's
|
||||
# calls `Locale.parse(seg)` on URL path segments. If a stripped locale's
|
||||
# .dat is missing courlan raises `UnknownLocaleError`, which IS caught at
|
||||
# line 188 (graceful degradation: that URL just doesn't get language-
|
||||
# filtered). Even so, keeping the most-common 20 base languages preserves
|
||||
@@ -144,12 +141,12 @@ if [[ -d "$SP/babel/locale-data" ]]; then
|
||||
echo "Trimming babel/locale-data..."
|
||||
LOCALE_DIR="$SP/babel/locale-data"
|
||||
# Keep:
|
||||
# - root.dat — fallback for unknown locales
|
||||
# - LICENSE.unicode — required by Unicode/CLDR license
|
||||
# - en*.dat — every English variant (130 files; small)
|
||||
# - root.dat fallback for unknown locales
|
||||
# - LICENSE.unicode required by Unicode/CLDR license
|
||||
# - en*.dat every English variant (130 files; small)
|
||||
# - <lang>.dat for the 20 most common base languages we'd plausibly see
|
||||
# in URL path segments. Country-suffix variants (fr_CA.dat, de_AT.dat
|
||||
# etc.) get dropped — courlan only uses .language so the base is enough.
|
||||
# etc.) get dropped; courlan only uses .language so the base is enough.
|
||||
KEEP_LANGS="ar de es fr it ja ko nl pl pt ru sv tr zh hi th vi id da no fi cs el he uk"
|
||||
# Build a regex of "files to KEEP" so find can delete the rest.
|
||||
KEEP_RE='^(root\.dat|LICENSE\.unicode|en($|_).*\.dat'
|
||||
@@ -164,7 +161,7 @@ fi
|
||||
# ----- dist-info noise trim (~2 MB / ~280 files) -----
|
||||
# pip metadata that's only consulted by pip itself (which we don't run at
|
||||
# runtime). RECORD/INSTALLER/WHEEL/entry_points.txt/top_level.txt have zero
|
||||
# runtime readers in our shipped deps. METADATA we KEEP — some packages and
|
||||
# runtime readers in our shipped deps. METADATA we KEEP; some packages and
|
||||
# transitive deps occasionally call importlib.metadata.metadata("pkg").
|
||||
echo "Trimming pip dist-info noise..."
|
||||
find "$SP" -path '*.dist-info/RECORD' -delete 2>/dev/null
|
||||
@@ -176,12 +173,7 @@ find "$SP" -path '*.dist-info/entry_points.txt' -delete 2>/dev/null
|
||||
# Pre-compile bytecode so cold backend startup skips the parse+compile
|
||||
# step on every imported .py. Worth ~5-10s on Windows under Defender
|
||||
# (parsing Python source is parser-bound; loading .pyc is just bytes).
|
||||
# Concurrency capped at 4 — `-j 0` (all cores) is fine on dev boxes
|
||||
# but unstable on small CI runners. Failures on individual files are
|
||||
# survivable (compileall continues on SyntaxError-tagged files used by
|
||||
# version-shim packages); a non-zero exit here would rather be visible
|
||||
# than silent so we don't `|| true` the whole thing — but missing .pyc
|
||||
# is non-fatal at runtime, so a hard fail isn't warranted either.
|
||||
# Concurrency capped at 4; `-j 0` is fine on dev boxes but unstable on small CI runners. Surface the exit but don't `|| true`; missing .pyc is non-fatal at runtime.
|
||||
echo "Pre-compiling bytecode..."
|
||||
"$PYTHON_BIN" -m compileall -q -j 4 "$PYTHON_ENV_DIR/lib" || \
|
||||
echo "WARNING: some files failed to compile; runtime will fall back to in-memory compile."
|
||||
@@ -199,7 +191,7 @@ echo "Pre-compiling bytecode..."
|
||||
#
|
||||
# Invariants this layout depends on (don't break them):
|
||||
# - codesign rejects symlinks as CFBundleExecutable ("the main executable
|
||||
# or Info.plist must be a regular file (no symlinks, etc.)") — so
|
||||
# or Info.plist must be a regular file (no symlinks, etc.)"), so
|
||||
# python3 inside Python.app MUST be a real Mach-O copy, not a symlink.
|
||||
# We copy bin/python3.13 in and rewrite its LC_LOAD_DYLIB so it still
|
||||
# finds the single libpython3.13.dylib at python-env/lib/.
|
||||
@@ -208,7 +200,7 @@ echo "Pre-compiling bytecode..."
|
||||
# wrapper bundle. All stdlib + site-packages discovery is unchanged.
|
||||
# - The launcher binary is tiny (~50 KB), so the duplicate copy is
|
||||
# negligible. We deliberately do NOT duplicate libpython3.13.dylib
|
||||
# (~18 MB) — only the launcher.
|
||||
# (~18 MB); only the launcher.
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
echo "Creating Python.app launcher (LSUIElement=1, hides from Dock)..."
|
||||
PY_APP="$PYTHON_ENV_DIR/Python.app"
|
||||
@@ -241,7 +233,7 @@ PLIST
|
||||
# Copy the launcher binary into the bundle. codesign requires a
|
||||
# regular file here (symlinks are rejected outright). Then rewrite
|
||||
# the LC_LOAD_DYLIB so @executable_path resolves correctly from
|
||||
# Python.app/Contents/MacOS/ — three levels up reaches python-env/,
|
||||
# Python.app/Contents/MacOS/: three levels up reaches python-env/,
|
||||
# then ../lib gets us to libpython3.13.dylib without duplication.
|
||||
cp "$PYTHON_ENV_DIR/bin/python3.13" "$PY_APP/Contents/MacOS/python3"
|
||||
chmod +x "$PY_APP/Contents/MacOS/python3"
|
||||
|
||||
Reference in New Issue
Block a user