Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b87a51afc0 | ||
|
|
d527164434 | ||
|
|
1c4ba234d0 | ||
|
|
64f89df289 | ||
|
|
f5b026070b |
@@ -1,10 +1,13 @@
|
|||||||
# Cayce Ops
|
# Cayce Ops
|
||||||
|
|
||||||
Cayce Ops is the autonomous operations stack of **Cayce** — an autonomous entity
|
CayceOps es el stack de operaciones de Cayce, un experimento de operaciones
|
||||||
operating under the Próspera ZEDE agentic-companies jurisdiction pilot. Cayce runs
|
agénticas de Cayce Co. Toda acción con efectos externos requiere aprobación
|
||||||
[bitcoinhotels.org](https://bitcoinhotels.org) (Bitcoin-native travel guides) and
|
humana firmada criptográficamente, con una clave que nunca reside en la
|
||||||
[hardcap.news](https://hardcap.news) (Bitcoin security intelligence). The
|
infraestructura de Cayce.
|
||||||
experiment is managed by Cayce itself.
|
|
||||||
|
Cayce operates [bitcoinhotels.org](https://bitcoinhotels.org)
|
||||||
|
(Bitcoin-native travel guides) and [hardcap.news](https://hardcap.news)
|
||||||
|
(Bitcoin security intelligence).
|
||||||
|
|
||||||
Five decoupled components share one Postgres database. Each is a CLI command,
|
Five decoupled components share one Postgres database. Each is a CLI command,
|
||||||
driven by cron/systemd timers. Nothing runs without an audit trail.
|
driven by cron/systemd timers. Nothing runs without an audit trail.
|
||||||
|
|||||||
@@ -19,10 +19,17 @@ from cayceops.models import MailClassification
|
|||||||
|
|
||||||
_APPROVAL_WORDS = re.compile(r"\b(approv|accept|welcome)", re.I)
|
_APPROVAL_WORDS = re.compile(r"\b(approv|accept|welcome)", re.I)
|
||||||
|
|
||||||
# any of these tokens anywhere in the mail vetoes an `approval` result
|
# any of these tokens anywhere in the mail vetoes an `approval` result.
|
||||||
|
# English and Spanish (merchants write in both; mixed mails are common).
|
||||||
_NEGATIONS = re.compile(
|
_NEGATIONS = re.compile(
|
||||||
r"\b(not|no|never|cannot|can'?t|won'?t|hasn'?t|isn'?t|"
|
r"\b(not|no|never|cannot|can'?t|won'?t|hasn'?t|isn'?t|"
|
||||||
r"no\s+longer|unable|decline\w*|regret\w*|unfortunately)\b",
|
r"no\s+longer|unable|decline\w*|regret\w*|unfortunately|"
|
||||||
|
# spanish: standalone negation words
|
||||||
|
r"nunca|jam[aá]s|tampoco|ning[uú]n(?:a|o)?|nadie|nada|"
|
||||||
|
# spanish: multi-word negations and rejection stems
|
||||||
|
r"no\s+podemos|no\s+es\s+posible|no\s+acept(?:amos|ar[aá])|"
|
||||||
|
r"rechaz\w*|lamentablemente|descartad\w*|"
|
||||||
|
r"no\s+ha\s+sido\s+aprobad\w*|no\s+procede)\b",
|
||||||
re.I,
|
re.I,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,11 +41,24 @@ _RULES: list[tuple[MailClassification, re.Pattern[str], float]] = [
|
|||||||
re.compile(r"\b(declin|reject|not able to|unable to|we regret|won.t be able)\w*", re.I), # noqa: E501
|
re.compile(r"\b(declin|reject|not able to|unable to|we regret|won.t be able)\w*", re.I), # noqa: E501
|
||||||
0.9,
|
0.9,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
MailClassification.REJECTION,
|
||||||
|
# spanish rejections (strong stems, not just negation words)
|
||||||
|
re.compile(r"\b(rechaz\w*|no\s+vamos\s+a\s+pod(?:er|emos)|su\s+solicitud\s+ha\s+sido\s+denegada|no\s+cumple\s+los\s+requisitos)\b", re.I), # noqa: E501
|
||||||
|
0.9,
|
||||||
|
),
|
||||||
(
|
(
|
||||||
MailClassification.APPROVAL,
|
MailClassification.APPROVAL,
|
||||||
re.compile(r"\b(approv|accept|welcome to the|you.re (in|approved)|live|activated|glad to)\w*", re.I), # noqa: E501
|
re.compile(r"\b(approv|accept|welcome to the|you.re (in|approved)|live|activated|glad to)\w*", re.I), # noqa: E501
|
||||||
0.85,
|
0.85,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
MailClassification.APPROVAL,
|
||||||
|
# spanish approvals (standalone positive stems; the veto still
|
||||||
|
# downgrades if ANY negation appears elsewhere in the mail)
|
||||||
|
re.compile(r"\b(aprob\w*|aceptad\w*|bienvenid\w*|ha\s+sido\s+aceptada|encantados?\s+de\s+(trabajar|colaborar))\b", re.I), # noqa: E501
|
||||||
|
0.85,
|
||||||
|
),
|
||||||
(
|
(
|
||||||
MailClassification.QUESTION,
|
MailClassification.QUESTION,
|
||||||
re.compile(r"\b(could you|can you|please (provide|clarify|confirm)|what (is|are)|how (do|does|can)|need more (info|details))\b", re.I), # noqa: E501
|
re.compile(r"\b(could you|can you|please (provide|clarify|confirm)|what (is|are)|how (do|does|can)|need more (info|details))\b", re.I), # noqa: E501
|
||||||
|
|||||||
Executable
+119
@@ -0,0 +1,119 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# cayce-backup — encrypted daily backup of CayceOps + Gitea + config.
|
||||||
|
#
|
||||||
|
# Design contract (Tanda B):
|
||||||
|
# - EVERY artifact is encrypted with age BEFORE it leaves the tmpdir.
|
||||||
|
# No plaintext is ever written outside the tmpdir, which is removed
|
||||||
|
# by a trap even on failure.
|
||||||
|
# - The age recipient lives in /etc/cayce-backup/age-recipient.pub
|
||||||
|
# (public key only). The PRIVATE key never touches this server:
|
||||||
|
# decryption happens on the operator's machine after a pull.
|
||||||
|
# - Any step failure => non-zero exit => journald entry (run via systemd).
|
||||||
|
# - Retention: 7 daily directories under /var/backups/cayce/.
|
||||||
|
#
|
||||||
|
# The restore procedure lives in deploy/backup/RESTORE.md.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
DATE="$(date -u +%F)"
|
||||||
|
BACKUP_ROOT="/var/backups/cayce"
|
||||||
|
DEST="$BACKUP_ROOT/$DATE"
|
||||||
|
RECIPIENT_FILE="/etc/cayce-backup/age-recipient.pub"
|
||||||
|
CAYCE_DIR="/home/ubuntu/cayce-ops"
|
||||||
|
ENV_FILE="$CAYCE_DIR/.env"
|
||||||
|
RETENTION_DAYS=7
|
||||||
|
|
||||||
|
log() { echo "[cayce-backup] $(date -u +%FT%TZ) $*"; }
|
||||||
|
die() { echo "[cayce-backup] FATAL: $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
# --- preconditions -------------------------------------------------------------
|
||||||
|
[[ $EUID -eq 0 ]] || die "must run as root (systemd)"
|
||||||
|
command -v age >/dev/null || die "age not installed"
|
||||||
|
[[ -r "$RECIPIENT_FILE" ]] || die "age recipient not configured: create $RECIPIENT_FILE (public key only)"
|
||||||
|
RECIPIENT="$(tr -d "[:space:]" < "$RECIPIENT_FILE")"
|
||||||
|
[[ "$RECIPIENT" == age1* ]] || die "$RECIPIENT_FILE does not look like an age1... public key"
|
||||||
|
|
||||||
|
# --- workspace: everything plaintext lives here and dies here ------------------
|
||||||
|
TMP="$(mktemp -d /tmp/cayce-backup.XXXXXX)"
|
||||||
|
# 711: root-only listing, but the git user must be able to traverse into
|
||||||
|
# its own 700 subdir for gitea dump; plaintext root files stay unreadable
|
||||||
|
chmod 711 "$TMP"
|
||||||
|
cleanup() {
|
||||||
|
rm -rf "$TMP"
|
||||||
|
if [[ "${FAILED:-0}" == "1" ]]; then
|
||||||
|
rm -rf "$DEST" # never leave a partial day directory
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
STAGE="$TMP/stage" # encrypted artifacts land here before install
|
||||||
|
install -d -m 700 "$STAGE"
|
||||||
|
|
||||||
|
encrypt() { # encrypt <plaintext-path> <name.age>
|
||||||
|
age -r "$RECIPIENT" -o "$STAGE/$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 1. Postgres dump (cayce-ops DB) --------------------------------------------
|
||||||
|
DB_URL="${CAYCE_OPS_DATABASE_URL:-}"
|
||||||
|
if [[ -z "$DB_URL" && -r "$ENV_FILE" ]]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
DB_URL="$(grep -E "^CAYCE_OPS_DATABASE_URL=" "$ENV_FILE" | head -1 | cut -d= -f2-)"
|
||||||
|
fi
|
||||||
|
[[ -n "$DB_URL" ]] || die "no CAYCE_OPS_DATABASE_URL in env or $ENV_FILE"
|
||||||
|
PG_URL="$(printf "%s" "$DB_URL" | sed -E "s#postgresql\+[a-z]+://#postgresql://#")"
|
||||||
|
log "dumping database from ${PG_URL%%@*@}***@..."
|
||||||
|
pg_dump "$PG_URL" --format=custom --file "$TMP/cayce-ops-db.dump"
|
||||||
|
encrypt "$TMP/cayce-ops-db.dump" "cayce-ops-db.dump.age"
|
||||||
|
log "database dump: $(du -h "$TMP/cayce-ops-db.dump" | cut -f1) plaintext, encrypted ok"
|
||||||
|
|
||||||
|
# --- 2. Gitea dump (repos + sqlite + attachments) -------------------------------
|
||||||
|
GITEA_BIN="$(command -v gitea || echo /usr/local/bin/gitea)"
|
||||||
|
[[ -x "$GITEA_BIN" ]] || die "gitea binary not found"
|
||||||
|
install -d -o git -g git -m 700 "$TMP/gitea-work"
|
||||||
|
log "running gitea dump (live; see RESTORE.md for consistency notes)..."
|
||||||
|
sudo -u git "$GITEA_BIN" dump -c /etc/gitea/app.ini \
|
||||||
|
--file "$TMP/gitea-work/gitea-dump.zip" --tempdir "$TMP/gitea-work" --quiet
|
||||||
|
encrypt "$TMP/gitea-work/gitea-dump.zip" "gitea-dump.zip.age"
|
||||||
|
log "gitea dump: $(du -h "$TMP/gitea-work/gitea-dump.zip" | cut -f1) plaintext, encrypted ok"
|
||||||
|
|
||||||
|
# --- 3. Config tar (Caddy, Gitea app.ini + internal_token, units, .env) ----------
|
||||||
|
CONF="$TMP/config"
|
||||||
|
install -d -m 700 "$CONF"
|
||||||
|
mkdir -p "$CONF/caddy" "$CONF/gitea" "$CONF/systemd" "$CONF/cayce-ops"
|
||||||
|
cp -a /etc/caddy/Caddyfile "$CONF/caddy/" 2>/dev/null || true
|
||||||
|
cp -a /etc/caddy/Caddyfile.d "$CONF/caddy/" 2>/dev/null || true
|
||||||
|
cp -a /etc/gitea/app.ini "$CONF/gitea/" 2>/dev/null || true
|
||||||
|
cp -a /etc/gitea/internal_token "$CONF/gitea/" 2>/dev/null || true
|
||||||
|
find /etc/systemd/system -maxdepth 1 -name "cayce-*" \
|
||||||
|
-exec cp -a {} "$CONF/systemd/" \; 2>/dev/null || true
|
||||||
|
[[ -r "$ENV_FILE" ]] && cp -a "$ENV_FILE" "$CONF/cayce-ops/dot-env" \
|
||||||
|
|| log "WARNING: $ENV_FILE not present — config backup continues without it"
|
||||||
|
# at least Caddy or Gitea config must exist, else the tar is useless
|
||||||
|
[[ -e "$CONF/caddy/Caddyfile" || -e "$CONF/gitea/app.ini" ]] \
|
||||||
|
|| die "no config sources found (Caddyfile/app.ini missing)"
|
||||||
|
tar -C "$CONF" -czf "$TMP/config.tar.gz" .
|
||||||
|
encrypt "$TMP/config.tar.gz" "config.tar.gz.age"
|
||||||
|
log "config tar: $(du -h "$TMP/config.tar.gz" | cut -f1) plaintext, encrypted ok"
|
||||||
|
|
||||||
|
# --- 4. install + manifest -------------------------------------------------------
|
||||||
|
install -d -m 750 -o root -g backup-pull "$BACKUP_ROOT" 2>/dev/null \
|
||||||
|
|| install -d -m 700 "$BACKUP_ROOT" # backup-pull group may not exist yet
|
||||||
|
install -d -m 750 -o root -g backup-pull "$DEST" 2>/dev/null \
|
||||||
|
|| install -d -m 700 "$DEST"
|
||||||
|
install -m 640 -o root -g backup-pull "$STAGE"/*.age "$DEST/" 2>/dev/null \
|
||||||
|
|| install -m 600 "$STAGE"/*.age "$DEST/"
|
||||||
|
( cd "$DEST" && sha256sum ./*.age > "$TMP/manifest.sha256" )
|
||||||
|
install -m 640 -o root -g backup-pull "$TMP/manifest.sha256" "$DEST/manifest.sha256" 2>/dev/null \
|
||||||
|
|| install -m 600 "$TMP/manifest.sha256" "$DEST/manifest.sha256"
|
||||||
|
log "manifest written: $(wc -l < "$DEST/manifest.sha256") artifacts"
|
||||||
|
|
||||||
|
# --- 5. retention -----------------------------------------------------------------
|
||||||
|
PRUNED=0
|
||||||
|
while IFS= read -r old; do
|
||||||
|
rm -rf "$old"
|
||||||
|
PRUNED=$((PRUNED + 1))
|
||||||
|
log "retention: removed $old"
|
||||||
|
done < <(find "$BACKUP_ROOT" -mindepth 1 -maxdepth 1 -type d -name "2*-*-*" -mtime +"$RETENTION_DAYS")
|
||||||
|
log "retention: kept last $RETENTION_DAYS days (pruned $PRUNED)"
|
||||||
|
|
||||||
|
log "BACKUP OK → $DEST ($(du -sh "$DEST" | cut -f1))"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Cayce — encrypted daily backup (CayceOps DB + Gitea + config)
|
||||||
|
After=network-online.target postgresql.service
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/bin/cayce-make-backup
|
||||||
|
# hardening
|
||||||
|
NoNewPrivileges=true
|
||||||
|
ProtectHome=read-only
|
||||||
|
ReadWritePaths=/var/backups/cayce /tmp
|
||||||
|
ProtectSystem=strict
|
||||||
|
PrivateTmp=false
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Cayce — daily backup schedule (03:15 UTC)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 03:15:00 UTC
|
||||||
|
Persistent=true
|
||||||
|
RandomizedDelaySec=300
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
"""Spanish negation tests (round-3 point 4): merchants write in Spanish;
|
||||||
|
negations like 'nunca', 'lamentablemente' or 'no podemos' must veto
|
||||||
|
`approval` exactly like their English counterparts. Veto rule unchanged:
|
||||||
|
when in doubt -> needs_review."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from cayceops.components.maild import classify as clf
|
||||||
|
from cayceops.models import MailClassification
|
||||||
|
|
||||||
|
APPROVAL_ONLY = MailClassification.APPROVAL
|
||||||
|
|
||||||
|
|
||||||
|
def _never_approval(cfg_factory, text: str) -> None:
|
||||||
|
kind, _ = clf.classify(text, cfg_factory())
|
||||||
|
assert kind is not APPROVAL_ONLY, f"{text!r} classified as APPROVAL"
|
||||||
|
|
||||||
|
|
||||||
|
def test_english_baseline_still_works(cfg):
|
||||||
|
config = cfg()
|
||||||
|
kind, _ = clf.classify("Your application was approved, welcome to the program", config)
|
||||||
|
assert kind is APPROVAL_ONLY
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"text",
|
||||||
|
[
|
||||||
|
# 1. rejection stem
|
||||||
|
"Lamentamos informarle que su solicitud fue rechazada",
|
||||||
|
# 2. nunca
|
||||||
|
"Nunca aceptamos negocios de criptomonedas",
|
||||||
|
# 3. jamás
|
||||||
|
"Jamás hemos trabajado con affiliates externos",
|
||||||
|
# 4. tampoco
|
||||||
|
"No podemos aceptar su sitio, tampoco podemos ofrecerle otro acuerdo",
|
||||||
|
# 5. ningún/ninguna
|
||||||
|
"En este momento no tenemos ningún hueco para nuevos partners",
|
||||||
|
# 6. no podemos (multi-word)
|
||||||
|
"Su propuesta es interesante pero no podemos proceder",
|
||||||
|
# 7. no es posible (multi-word)
|
||||||
|
"Gracias por escribir, pero no es posible colaborar este trimestre",
|
||||||
|
# 8. lamentablemente
|
||||||
|
"Lamentablemente su aplicación no ha sido aprobada",
|
||||||
|
# 9. no aceptamos
|
||||||
|
"Por política interna no aceptamos sitios de viajes",
|
||||||
|
# 10. mixed spanish/english: negation in spanish, approval word in english
|
||||||
|
"Thanks for reaching out! Lamentablemente we cannot approve your site",
|
||||||
|
# 11. mixed: approval in spanish, negation in english
|
||||||
|
"Apreciamos su interés, but we are not accepting new partners",
|
||||||
|
# 12. nadie / nada
|
||||||
|
"Aquí nadie decidiría eso, así que no hay nada que aprobar",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_spanish_and_mixed_negations_veto_approval(cfg, text):
|
||||||
|
_never_approval(cfg, text)
|
||||||
|
|
||||||
|
|
||||||
|
def test_spanish_pure_approval_still_approves(cfg):
|
||||||
|
"""A clean Spanish approval WITHOUT any negation must still classify
|
||||||
|
approval — the veto must not over-fire."""
|
||||||
|
config = cfg()
|
||||||
|
kind, confidence = clf.classify(
|
||||||
|
"Su solicitud fue aprobada. Bienvenido al programa, estamos encantados "
|
||||||
|
"de trabajar con ustedes.",
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
assert kind is APPROVAL_ONLY
|
||||||
|
assert confidence >= 0.5
|
||||||
|
|
||||||
|
|
||||||
|
def test_spanish_rejection_classifies_rejection(cfg):
|
||||||
|
config = cfg()
|
||||||
|
kind, conf = clf.classify(
|
||||||
|
"Lamentamos informarle que su solicitud fue rechazada por el comité",
|
||||||
|
config,
|
||||||
|
)
|
||||||
|
assert kind is MailClassification.REJECTION
|
||||||
|
assert conf >= 0.9
|
||||||
Reference in New Issue
Block a user