#!/usr/bin/env bash # Workstation consumer for FI daily research brief spawns. # # activity-core emits activity_task_spawn (state-hub sink) with # target_repo=freedom-intelligence. This script: # 1) checks fi_brief_status due (or open spawn) # 2) reminds operator / runs playbook path # 3) does NOT invent brief content — open a session with the playbook # # Schedule suggestion (Europe/Berlin, after 07:30 spawn): # 40 7 * * 1-5 /home/worsch/freedom-intelligence/scripts/consume-fi-brief-spawn.sh # # Env: # STATE_HUB_URL default http://127.0.0.1:8000 # FI_REPO default /home/worsch/freedom-intelligence set -euo pipefail STATE_HUB_URL="${STATE_HUB_URL:-http://127.0.0.1:8000}" FI_REPO="${FI_REPO:-/home/worsch/freedom-intelligence}" LOG_DIR="${FI_REPO}/.local/consumer-logs" mkdir -p "$LOG_DIR" log="$LOG_DIR/$(date +%Y-%m-%d).log" { echo "=== $(date -Is) consume-fi-brief-spawn ===" # Prefer activity-core resolver if available; else raw progress heuristic due_json="" if command -v uv >/dev/null 2>&1 && [[ -d /home/worsch/activity-core ]]; then due_json="$( cd /home/worsch/activity-core && STATE_HUB_URL="$STATE_HUB_URL" uv run python -c " from activity_core.context_resolvers.state_hub import _fi_brief_status import json print(json.dumps(_fi_brief_status({'repo': 'freedom-intelligence'}), default=str)) " 2>/dev/null || true )" fi if [[ -z "$due_json" ]]; then echo "WARN: could not query fi_brief_status; check STATE_HUB_URL=$STATE_HUB_URL" exit 0 fi echo "status: $due_json" due="$(python3 -c "import json,sys; d=json.loads(sys.argv[1]); print(d['items'][0]['due'])" "$due_json")" date_s="$(python3 -c "import json,sys; d=json.loads(sys.argv[1]); print(d['items'][0]['date'])" "$due_json")" if [[ "$due" != "True" && "$due" != "true" ]]; then echo "not due for $date_s — exit" exit 0 fi y="${date_s:0:4}" m="${date_s:5:2}" brief_path="$FI_REPO/briefs/$y/$m/$date_s.md" echo "DUE: produce brief at $brief_path" echo "Playbook: $FI_REPO/docs/daily-brief-playbook.md" echo "On completion POST event_type=fi_daily_brief detail.repo=freedom-intelligence detail.date=$date_s" # Non-interactive marker for operators / agents notice="$LOG_DIR/DUE-$date_s.txt" cat >"$notice" <