Owner jobs and guests' own scheduled jobs are the cron-jobs live plugin's (forms move-ai-agent-cron-jobs-into-a-plugin_u0wa6b, cron-scheduled-in-the-cli-and-mcp_x4nk83). Gone: backend/cron/, schemas/cron.py, /api/cron*, /api/me/cron*, the cron scheduler thread, Settings → Cron and the guests' Tâches planifiées pages, `ai-agent cron` (now a pointer), MCP run_cron_job / set_cron_job / browse cron, the scheduled-jobs core skill, guestDefaults.cronLimits. The core keeps thin contracts: - runs.guest bridge (runs/guestjob.py): a guest's job run as that guest, confined by the core from their record; the plugin only names it. - runs.start's cron stamp → meta.cron. - delivery of a guest job's result (push, mail, mailHtml) off the stamp. - « Discuter »: POST /api/cron-runs/discuss. - runs.cron provider readers (plugins/cron_bridge.py): budget, auto-archive, agents catalog, the agents page's Schedule. - core/cronexpr.py, agents/runconfig.py; context.write create for a new agent definition; ui.pages[].unless; setRoute keeps a Settings page under /settings/p/. - carryover.cron_jobs: /data/cron-jobs.json → the plugin's jobs.json, cronLimits → limits.json, guests' qwen jobs → sonnet (PR #23's decision, superseded). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
157 lines
9.8 KiB
Python
157 lines
9.8 KiB
Python
"""Environment, paths and constants shared by every backend package."""
|
|
|
|
import os
|
|
import pathlib
|
|
import re
|
|
|
|
import accounts as accounts_mod
|
|
|
|
WORKSPACE = pathlib.Path(os.environ.get("WORKSPACE", "/workspace")).resolve()
|
|
STATIC_DIR = pathlib.Path(os.environ.get("STATIC_DIR", "/app/static")).resolve()
|
|
# Screenshots captured by the `screenshot` skill (docs/screenshots/, mounted
|
|
# read-only). Served by /api/screenshot and shown inline in the thread viewer.
|
|
SCREENSHOTS_DIR = pathlib.Path(
|
|
os.environ.get("SCREENSHOTS_DIR", "/screenshots")).resolve()
|
|
SCREENSHOT_EXTS = {".jpeg", ".jpg", ".png", ".webp", ".gif"}
|
|
# The repo's root `data/` tree (mounted read-only at /workspace/data). Generated
|
|
# artifacts (images, renders, charts) land here and are served by /api/data-asset
|
|
# so a `Read` of an image under data/ can be previewed inline in the thread.
|
|
DATA_DIR = (WORKSPACE / "data")
|
|
# Claude Code's per-session scratchpad root (mounted read-only). A session's
|
|
# temp dir is <root>/<encoded-cwd>/<sessionId>/scratchpad/…, which is where a
|
|
# run's throwaway renders and screenshots land when they aren't worth committing
|
|
# to a project's .ai/artefacts/. Served by /api/scratchpad-asset so those still
|
|
# preview inline in the thread instead of showing "not previewable".
|
|
SCRATCHPAD_DIR = pathlib.Path(
|
|
os.environ.get("SCRATCHPAD_DIR", "/scratchpads")).resolve()
|
|
IMAGE_EXTS = {".jpeg", ".jpg", ".png", ".webp", ".gif", ".svg", ".bmp", ".avif"}
|
|
# Files uploaded from the composer (SpawnBox/ResumeBox). Stored inside the
|
|
# service's own writable data dir; served back by /api/upload-file and read by
|
|
# the spawned `claude -p` session. UPLOADS_DIR is the container path; the repo
|
|
# prefix is what the host-side session (cwd = repo root) sees, so the composer
|
|
# injects "<prefix>/<batch>/<name>" into the prompt for Claude to Read.
|
|
UPLOADS_DIR = pathlib.Path(
|
|
os.environ.get("UPLOADS_DIR", "/data/uploads")).resolve()
|
|
UPLOADS_REPO_PREFIX = os.environ.get(
|
|
"UPLOADS_REPO_PREFIX", "services/ai-agent/data/uploads").strip("/")
|
|
# The same store as a lab run sees it on the host (absolute): the prompt names
|
|
# a file there, so a run whose cwd isn't the repo root finds it too
|
|
# (runs/attachments.py). Unset ⇒ the repo-relative path stays.
|
|
UPLOADS_HOST_DIR = os.environ.get("UPLOADS_HOST_DIR", "").rstrip("/")
|
|
# A guest's lab run can't read that store (its scope denies it): each upload
|
|
# its prompt names is hard-linked into the guest's own folder here, which every
|
|
# run of theirs may read (runs/attachments.py). Container path, then the host's
|
|
# — by default the store's sibling in the one data volume.
|
|
GUEST_UPLOADS_DIR = pathlib.Path(
|
|
os.environ.get("GUEST_UPLOADS_DIR", str(UPLOADS_DIR.parent / "guest-uploads"))).resolve()
|
|
GUEST_UPLOADS_HOST_DIR = os.environ.get("GUEST_UPLOADS_HOST_DIR", "").rstrip("/") or (
|
|
UPLOADS_HOST_DIR[:-len("uploads")] + "guest-uploads"
|
|
if UPLOADS_HOST_DIR.endswith("/uploads") else "")
|
|
MAX_UPLOAD_BYTES = int(os.environ.get("MAX_UPLOAD_BYTES", 50 * 1024 * 1024))
|
|
_UNSAFE_NAME_RE = re.compile(r"[^A-Za-z0-9._-]+")
|
|
DB_PATH = os.environ.get("DB_PATH", "/data/ai-agent.db")
|
|
_transcripts = os.environ.get("TRANSCRIPTS_DIR", "/transcripts")
|
|
# Live (read-only) Claude Code transcripts that get imported into the archive.
|
|
SOURCE_DIR = pathlib.Path(_transcripts).resolve() if _transcripts else None
|
|
# Second live source: transcripts mirrored by the pi-harness runner
|
|
# (services/ai-agent/runner writes Claude-Code-schema JSONL there).
|
|
_pi_transcripts = os.environ.get("PI_TRANSCRIPTS_DIR", "/pi-transcripts")
|
|
PI_SOURCE_DIR = (pathlib.Path(_pi_transcripts).resolve()
|
|
if _pi_transcripts else None)
|
|
# Third live source: the in-container runner (RUNNER_IN_CONTAINER=1, see
|
|
# docker-entrypoint.sh). The Claude Code CLI baked into the image writes its
|
|
# transcripts under the runner's own $HOME, inside the container — watching that
|
|
# dir is what makes an in-container session stream into the viewer like any other.
|
|
# Unset on the homelab, where the runner is the host sidecar and its transcripts
|
|
# arrive through the read-only /transcripts mount instead.
|
|
_runner_transcripts = os.environ.get("RUNNER_TRANSCRIPTS_DIR", "")
|
|
RUNNER_SOURCE_DIR = (pathlib.Path(_runner_transcripts).resolve()
|
|
if _runner_transcripts else None)
|
|
# Fourth: every non-default Claude account's own transcripts (accounts.py) —
|
|
# the work seat's CLI writes under ~/.claude-work/projects, mounted read-only
|
|
# at WORK_TRANSCRIPTS_DIR. Imported into the same archive; the indexer records
|
|
# which account each one came from (``meta.accountSource``).
|
|
ACCOUNT_SOURCE_DIRS = accounts_mod.transcripts_dirs() # {account: dir}
|
|
# Fifth: remote workers' transcripts (workers.py), pulled over each worker's
|
|
# /feed by the FeedMirror into this one dir with Claude Code's own layout. The
|
|
# mirror stamps which worker (and so which account) each session came from.
|
|
_workers_transcripts = os.environ.get("WORKERS_TRANSCRIPTS_DIR",
|
|
"/data/workers/transcripts")
|
|
WORKERS_SOURCE_DIR = (pathlib.Path(_workers_transcripts).resolve()
|
|
if _workers_transcripts else None)
|
|
# dict.fromkeys: order-preserving dedupe — pointing two of these at the same dir
|
|
# would otherwise import every transcript in it twice.
|
|
SOURCE_DIRS = list(dict.fromkeys(
|
|
d for d in (SOURCE_DIR, PI_SOURCE_DIR, RUNNER_SOURCE_DIR,
|
|
*ACCOUNT_SOURCE_DIRS.values(), WORKERS_SOURCE_DIR) if d))
|
|
# Persistent archive: imported transcripts live here and are indexed/read from
|
|
# it (so conversations Claude later prunes from the source survive).
|
|
ARCHIVE_DIR = pathlib.Path(
|
|
os.environ.get("ARCHIVE_DIR", "/data/transcripts")).resolve()
|
|
TRANSCRIPTS_DIR = ARCHIVE_DIR # the detail endpoint reads from the archive
|
|
# Where that archive sits on the host — only for the owner's "transcript path"
|
|
# chip under the conversation id. Defaults to the uploads dir's sibling (both
|
|
# live in the one data volume).
|
|
ARCHIVE_HOST_DIR = os.environ.get("ARCHIVE_HOST_DIR", "").rstrip("/") or (
|
|
UPLOADS_HOST_DIR[:-len("uploads")] + "transcripts"
|
|
if UPLOADS_HOST_DIR.endswith("/uploads") else "")
|
|
# Sidecar of per-conversation action metadata edited by the skill scripts.
|
|
META_PATH = os.environ.get("META_PATH", "/data/conversations-meta.json")
|
|
# The core's cron store, before the jobs became the cron-jobs plugin's
|
|
# (2026-11-28): read once by plugins/carryover.py, then renamed .migrated.
|
|
CRON_PATH = os.environ.get("CRON_PATH", "/data/cron-jobs.json")
|
|
# First-class notifications: webhook config + notification/ask log (notify.py).
|
|
NOTIFY_PATH = os.environ.get("NOTIFY_PATH", "/data/notifications.json")
|
|
FORMS_PATH = os.environ.get("FORMS_PATH", "/data/forms.json")
|
|
# A form's ``secret`` answers (forms/secrets.py) — 0600, purged after 24 h.
|
|
FORM_SECRETS_PATH = os.environ.get("FORM_SECRETS_PATH", "/data/form-secrets.json")
|
|
# The mirror of the standalone ask-form tool's forms (askform/store.py).
|
|
ASKFORM_PATH = os.environ.get("ASKFORM_PATH", "/data/askform.json")
|
|
# Settings → Fresh context: when the reply box nudges toward compacting a
|
|
# conversation, and what compacts it (runs/fresh.py).
|
|
FRESH_CONTEXT_PATH = os.environ.get("FRESH_CONTEXT_PATH", "/data/fresh-context.json")
|
|
# Server-side store for the PWA's small client state (Settings config + the
|
|
# notification feed's seen/new bookkeeping) — moved off browser localStorage so
|
|
# it follows the user across browsers/devices. See ui_state.py.
|
|
UI_STATE_PATH = os.environ.get("UI_STATE_PATH", "/data/ui-state.json")
|
|
# Composer drafts, per user (drafts/store.py): the home composer's per
|
|
# profile, each reply box's, the Save-as-draft shelves — across devices.
|
|
DRAFTS_PATH = os.environ.get("DRAFTS_PATH", "/data/drafts.json")
|
|
# Settings → Tags' overrides + uploaded icons (tags/store.py) — the hub's, so
|
|
# the `ai-agent tags` CLI and the app edit one file.
|
|
TAG_META_PATH = os.environ.get("TAG_META_PATH", "/data/tag-meta.json")
|
|
# Lab projects folded into a worker project ({lab slug: worker project slug},
|
|
# projects/merges.py) — e.g. the lab's stale orus-monorepo clone into the
|
|
# Orus Mac's own checkout.
|
|
PROJECT_MERGES_PATH = os.environ.get("PROJECT_MERGES_PATH", "/data/project-merges.json")
|
|
# Paired remote workers (workers.py) — url + bearer each, so 0600.
|
|
WORKERS_PATH = os.environ.get("WORKERS_PATH", "/data/workers.json")
|
|
# Profiles (Personal / Work): default account, runner and projects (profiles/).
|
|
PROFILES_PATH = os.environ.get("PROFILES_PATH", "/data/profiles.json")
|
|
# Named in the worker's logs at pairing ("paired with homelab").
|
|
HUB_NAME = os.environ.get("HUB_NAME", "homelab")
|
|
# What the app calls the hub machine — the local runner, "Runs on", Settings →
|
|
# Machines (`/api/me` ``hubName``): "Homelab" here, "Devbox" on a standalone
|
|
# hub. Default: HUB_NAME with a capital.
|
|
HUB_LABEL = (os.environ.get("HUB_LABEL") or "").strip() or HUB_NAME[:1].upper() + HUB_NAME[1:]
|
|
# A conversation whose last activity is within this window counts as "running".
|
|
RUNNING_WINDOW_SECS = float(os.environ.get("RUNNING_WINDOW_SECS", "600"))
|
|
# Host-side sidecar that actually launches `claude -p` (see services/ai-agent/
|
|
# sidecar/). The container reaches it over host.docker.internal.
|
|
SIDECAR_URL = os.environ.get("SIDECAR_URL", "http://host.docker.internal:8790")
|
|
SIDECAR_TOKEN = os.environ.get("SIDECAR_TOKEN", "")
|
|
|
|
# Directories never worth scanning (huge / generated / vendored).
|
|
IGNORE_DIRS = {
|
|
".git", "node_modules", ".forge", "dist", "build", "__pycache__",
|
|
".venv", "venv", ".cache", "history", "tmp", ".next", "coverage",
|
|
}
|
|
MD_EXTS = {".md", ".markdown"}
|
|
# Text-ish files worth surfacing from the repo's root `data/` tree (plans, logs,
|
|
# notes, kanban, widget templates). Binary/image files (screenshots, thumbnails)
|
|
# are skipped — the viewer is a text editor and can't render them.
|
|
DATA_TEXT_EXTS = {
|
|
".md", ".markdown", ".txt", ".json", ".yml", ".yaml", ".toml", ".ini",
|
|
".cfg", ".py", ".sh", ".js", ".ts", ".jinja", ".j2", ".log", ".csv",
|
|
}
|