2026-03-12 12:44:15 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# env.sh — Load environment and shared utilities
|
|
|
|
|
# Source this at the top of every script: source "$(dirname "$0")/lib/env.sh"
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
# Resolve script root (parent of lib/)
|
|
|
|
|
FACTORY_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
|
|
2026-03-24 18:53:55 +00:00
|
|
|
# Container detection: when running inside the agent container, DISINTO_CONTAINER
|
|
|
|
|
# is set by docker-compose.yml. Adjust paths so phase files, logs, and thread
|
|
|
|
|
# maps land on the persistent volume instead of /tmp (which is ephemeral).
|
|
|
|
|
if [ "${DISINTO_CONTAINER:-}" = "1" ]; then
|
|
|
|
|
DISINTO_DATA_DIR="${HOME}/data"
|
|
|
|
|
mkdir -p "${DISINTO_DATA_DIR}"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-25 07:10:55 +00:00
|
|
|
# Load secrets: prefer .env.enc (SOPS-encrypted), fall back to plaintext .env.
|
|
|
|
|
# Inside the container, compose already injects env vars via env_file + environment
|
|
|
|
|
# overrides (e.g. FORGE_URL=http://forgejo:3000). Re-sourcing .env would clobber
|
|
|
|
|
# those compose-level values, so we skip it when DISINTO_CONTAINER=1.
|
|
|
|
|
if [ "${DISINTO_CONTAINER:-}" != "1" ]; then
|
|
|
|
|
if [ -f "$FACTORY_ROOT/.env.enc" ] && command -v sops &>/dev/null; then
|
|
|
|
|
set -a
|
|
|
|
|
eval "$(sops -d --output-type dotenv "$FACTORY_ROOT/.env.enc" 2>/dev/null)" \
|
|
|
|
|
|| echo "Warning: failed to decrypt .env.enc — secrets not loaded" >&2
|
|
|
|
|
set +a
|
|
|
|
|
elif [ -f "$FACTORY_ROOT/.env" ]; then
|
|
|
|
|
set -a
|
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
|
source "$FACTORY_ROOT/.env"
|
|
|
|
|
set +a
|
|
|
|
|
fi
|
2026-03-12 12:44:15 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# PATH: foundry, node, system
|
2026-03-14 17:18:15 +01:00
|
|
|
export PATH="${HOME}/.local/bin:${HOME}/.foundry/bin:${HOME}/.nvm/versions/node/v22.20.0/bin:/usr/local/bin:/usr/bin:/bin:${PATH}"
|
2026-03-12 12:44:15 +00:00
|
|
|
export HOME="${HOME:-/home/debian}"
|
|
|
|
|
|
refactor: split supervisor into infra + per-project, make poll scripts config-driven
Supervisor split (#26):
- Layer 1 (infra): P0 memory, P1 disk, P4 housekeeping — runs once, project-agnostic
- Layer 2 (per-project): P2 CI/dev-agent, P3 PRs/deps — iterates projects/*.toml
- Adding a new project requires only a new TOML file, no code changes
Poll scripts accept project TOML arg (#27):
- dev-poll.sh, review-poll.sh, gardener-poll.sh accept optional project TOML as $1
- env.sh loads PROJECT_TOML if set, overriding .env defaults
- Cron: `dev-poll.sh projects/versi.toml` targets that project
New files:
- lib/load-project.sh: TOML to env var loader (Python tomllib)
- projects/versi.toml: current project config extracted from .env
Backwards compatible: scripts without a TOML arg fall back to .env config.
Closes #26, Closes #27
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 08:57:18 +01:00
|
|
|
# Load project TOML if PROJECT_TOML is set (by poll scripts that accept project arg)
|
|
|
|
|
if [ -n "${PROJECT_TOML:-}" ] && [ -f "$PROJECT_TOML" ]; then
|
|
|
|
|
source "${FACTORY_ROOT}/lib/load-project.sh" "$PROJECT_TOML"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-23 18:58:33 +00:00
|
|
|
# Forge token: new FORGE_TOKEN > legacy CODEBERG_TOKEN
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
if [ -z "${FORGE_TOKEN:-}" ]; then
|
|
|
|
|
FORGE_TOKEN="${CODEBERG_TOKEN:-}"
|
2026-03-12 12:44:15 +00:00
|
|
|
fi
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
export FORGE_TOKEN
|
|
|
|
|
export CODEBERG_TOKEN="${FORGE_TOKEN}" # backwards compat
|
|
|
|
|
|
|
|
|
|
# Review bot token: FORGE_REVIEW_TOKEN > legacy REVIEW_BOT_TOKEN
|
|
|
|
|
export FORGE_REVIEW_TOKEN="${FORGE_REVIEW_TOKEN:-${REVIEW_BOT_TOKEN:-}}"
|
|
|
|
|
export REVIEW_BOT_TOKEN="${FORGE_REVIEW_TOKEN}" # backwards compat
|
|
|
|
|
|
|
|
|
|
# Bot usernames filter: FORGE_BOT_USERNAMES > legacy CODEBERG_BOT_USERNAMES
|
|
|
|
|
export FORGE_BOT_USERNAMES="${FORGE_BOT_USERNAMES:-${CODEBERG_BOT_USERNAMES:-}}"
|
|
|
|
|
export CODEBERG_BOT_USERNAMES="${FORGE_BOT_USERNAMES}" # backwards compat
|
2026-03-12 12:44:15 +00:00
|
|
|
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
# Project config (FORGE_* preferred, CODEBERG_* fallback)
|
|
|
|
|
export FORGE_REPO="${FORGE_REPO:-${CODEBERG_REPO:-}}"
|
|
|
|
|
export CODEBERG_REPO="${FORGE_REPO}" # backwards compat
|
|
|
|
|
export FORGE_URL="${FORGE_URL:-http://localhost:3000}"
|
|
|
|
|
export FORGE_API="${FORGE_API:-${FORGE_URL}/api/v1/repos/${FORGE_REPO}}"
|
|
|
|
|
export FORGE_WEB="${FORGE_WEB:-${FORGE_URL}/${FORGE_REPO}}"
|
|
|
|
|
export CODEBERG_API="${FORGE_API}" # backwards compat
|
|
|
|
|
export CODEBERG_WEB="${FORGE_WEB}" # backwards compat
|
2026-03-25 12:20:15 +00:00
|
|
|
# tea CLI login name: derived from FORGE_URL (codeberg vs local forgejo)
|
|
|
|
|
if [ -z "${TEA_LOGIN:-}" ]; then
|
|
|
|
|
case "${FORGE_URL}" in
|
|
|
|
|
*codeberg.org*) TEA_LOGIN="codeberg" ;;
|
|
|
|
|
*) TEA_LOGIN="forgejo" ;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
export TEA_LOGIN
|
|
|
|
|
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
export PROJECT_NAME="${PROJECT_NAME:-${FORGE_REPO##*/}}"
|
2026-03-20 15:01:28 +00:00
|
|
|
export PROJECT_REPO_ROOT="${PROJECT_REPO_ROOT:-/home/${USER}/${PROJECT_NAME}}"
|
2026-03-14 13:49:09 +01:00
|
|
|
export PRIMARY_BRANCH="${PRIMARY_BRANCH:-master}"
|
2026-03-20 15:01:28 +00:00
|
|
|
export WOODPECKER_REPO_ID="${WOODPECKER_REPO_ID:-}"
|
2026-03-12 12:44:15 +00:00
|
|
|
export WOODPECKER_SERVER="${WOODPECKER_SERVER:-http://localhost:8000}"
|
|
|
|
|
export CLAUDE_TIMEOUT="${CLAUDE_TIMEOUT:-7200}"
|
|
|
|
|
|
2026-03-25 00:28:04 +00:00
|
|
|
# Matrix homeserver: inside compose Dendrite is at http://dendrite:8008,
|
|
|
|
|
# on bare metal it defaults to http://localhost:8008.
|
|
|
|
|
if [ -z "${MATRIX_HOMESERVER:-}" ]; then
|
|
|
|
|
if [ "${DISINTO_CONTAINER:-}" = "1" ]; then
|
|
|
|
|
export MATRIX_HOMESERVER="http://dendrite:8008"
|
|
|
|
|
else
|
|
|
|
|
export MATRIX_HOMESERVER="http://localhost:8008"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
export MATRIX_HOMESERVER
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-12 12:44:15 +00:00
|
|
|
# Shared log helper
|
|
|
|
|
log() {
|
|
|
|
|
printf '[%s] %s\n' "$(date -u '+%Y-%m-%d %H:%M:%S UTC')" "$*"
|
|
|
|
|
}
|
|
|
|
|
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
# Forge API helper — usage: forge_api GET /issues?state=open
|
|
|
|
|
forge_api() {
|
2026-03-12 12:44:15 +00:00
|
|
|
local method="$1" path="$2"
|
|
|
|
|
shift 2
|
|
|
|
|
curl -sf -X "$method" \
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
-H "Authorization: token ${FORGE_TOKEN}" \
|
2026-03-12 12:44:15 +00:00
|
|
|
-H "Content-Type: application/json" \
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
"${FORGE_API}${path}" "$@"
|
2026-03-12 12:44:15 +00:00
|
|
|
}
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
# Backwards-compat alias
|
|
|
|
|
codeberg_api() { forge_api "$@"; }
|
2026-03-12 12:44:15 +00:00
|
|
|
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
# Paginate a Forge API GET endpoint and return all items as a merged JSON array.
|
|
|
|
|
# Usage: forge_api_all /path (no existing query params)
|
|
|
|
|
# forge_api_all /path?a=b (with existing params — appends &limit=50&page=N)
|
|
|
|
|
# forge_api_all /path TOKEN (optional second arg: token; defaults to $FORGE_TOKEN)
|
|
|
|
|
forge_api_all() {
|
2026-03-18 08:13:43 +00:00
|
|
|
local path_prefix="$1"
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
local FORGE_TOKEN="${2:-${FORGE_TOKEN}}"
|
2026-03-18 08:13:43 +00:00
|
|
|
local sep page page_items count all_items="[]"
|
|
|
|
|
case "$path_prefix" in
|
|
|
|
|
*"?"*) sep="&" ;;
|
|
|
|
|
*) sep="?" ;;
|
|
|
|
|
esac
|
|
|
|
|
page=1
|
|
|
|
|
while true; do
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
page_items=$(forge_api GET "${path_prefix}${sep}limit=50&page=${page}")
|
2026-03-18 08:13:43 +00:00
|
|
|
count=$(printf '%s' "$page_items" | jq 'length')
|
|
|
|
|
[ "$count" -eq 0 ] && break
|
|
|
|
|
all_items=$(printf '%s\n%s' "$all_items" "$page_items" | jq -s 'add')
|
|
|
|
|
[ "$count" -lt 50 ] && break
|
|
|
|
|
page=$((page + 1))
|
|
|
|
|
done
|
|
|
|
|
printf '%s' "$all_items"
|
|
|
|
|
}
|
fix: Replace Codeberg dependency with local Forgejo instance (#611)
- Add setup_forge() to bin/disinto: provisions Forgejo via Docker,
creates admin + bot users (dev-bot, review-bot), generates API
tokens, creates repo, and pushes code — all automated
- Rename env vars: CODEBERG_TOKEN→FORGE_TOKEN, REVIEW_BOT_TOKEN→
FORGE_REVIEW_TOKEN, CODEBERG_REPO→FORGE_REPO, CODEBERG_API→
FORGE_API, CODEBERG_WEB→FORGE_WEB, CODEBERG_BOT_USERNAMES→
FORGE_BOT_USERNAMES (with backwards-compat fallbacks)
- Rename API helpers: codeberg_api()→forge_api(), codeberg_api_all()
→forge_api_all() (with compat aliases)
- Add forge_url field to project TOML; load-project.sh derives
FORGE_API/FORGE_WEB from forge_url + repo
- Update parse_repo_slug() to accept any host URL, not just codeberg
- Forgejo data stored under ~/.disinto/forgejo/ (not in factory repo)
- Update all 58 files: agent scripts, formulas, docs, site HTML
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:57:12 +00:00
|
|
|
# Backwards-compat alias
|
|
|
|
|
codeberg_api_all() { forge_api_all "$@"; }
|
2026-03-18 08:13:43 +00:00
|
|
|
|
2026-03-12 12:44:15 +00:00
|
|
|
# Woodpecker API helper
|
|
|
|
|
woodpecker_api() {
|
|
|
|
|
local path="$1"
|
|
|
|
|
shift
|
2026-03-14 16:25:33 +01:00
|
|
|
curl -sfL \
|
2026-03-12 12:44:15 +00:00
|
|
|
-H "Authorization: Bearer ${WOODPECKER_TOKEN}" \
|
|
|
|
|
"${WOODPECKER_SERVER}/api${path}" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Woodpecker DB query helper
|
|
|
|
|
wpdb() {
|
|
|
|
|
PGPASSWORD="${WOODPECKER_DB_PASSWORD}" psql \
|
|
|
|
|
-U "${WOODPECKER_DB_USER:-woodpecker}" \
|
|
|
|
|
-h "${WOODPECKER_DB_HOST:-127.0.0.1}" \
|
|
|
|
|
-d "${WOODPECKER_DB_NAME:-woodpecker}" \
|
|
|
|
|
-t "$@" 2>/dev/null
|
|
|
|
|
}
|
2026-03-14 16:25:33 +01:00
|
|
|
|
2026-03-18 00:20:11 +00:00
|
|
|
# Matrix messaging helper — usage: matrix_send <prefix> <message> [thread_event_id] [context_tag]
|
2026-03-14 16:25:33 +01:00
|
|
|
# Returns event_id on stdout. Registers threads for listener dispatch.
|
2026-03-18 00:20:11 +00:00
|
|
|
# context_tag is stored in the thread map (e.g. issue number) for routing replies.
|
2026-03-24 18:53:55 +00:00
|
|
|
# Thread map: use persistent data dir inside container, /tmp on bare metal
|
|
|
|
|
if [ "${DISINTO_CONTAINER:-}" = "1" ]; then
|
|
|
|
|
MATRIX_THREAD_MAP="${MATRIX_THREAD_MAP:-${DISINTO_DATA_DIR}/matrix-thread-map}"
|
|
|
|
|
else
|
|
|
|
|
MATRIX_THREAD_MAP="${MATRIX_THREAD_MAP:-/tmp/matrix-thread-map}"
|
|
|
|
|
fi
|
2026-03-14 16:25:33 +01:00
|
|
|
matrix_send() {
|
|
|
|
|
[ -z "${MATRIX_TOKEN:-}" ] && return 0
|
2026-03-18 00:20:11 +00:00
|
|
|
local prefix="$1" msg="$2" thread_id="${3:-}" ctx_tag="${4:-}"
|
2026-03-14 16:25:33 +01:00
|
|
|
local room_encoded="${MATRIX_ROOM_ID//!/%21}"
|
2026-03-18 01:53:02 +00:00
|
|
|
local txn
|
|
|
|
|
txn="$(date +%s%N)$$"
|
2026-03-14 16:25:33 +01:00
|
|
|
local body
|
|
|
|
|
if [ -n "$thread_id" ]; then
|
|
|
|
|
body=$(jq -nc --arg m "[${prefix}] ${msg}" --arg t "$thread_id" \
|
|
|
|
|
'{msgtype:"m.text",body:$m,"m.relates_to":{rel_type:"m.thread",event_id:$t}}')
|
|
|
|
|
else
|
|
|
|
|
body=$(jq -nc --arg m "[${prefix}] ${msg}" '{msgtype:"m.text",body:$m}')
|
|
|
|
|
fi
|
|
|
|
|
local response
|
|
|
|
|
response=$(curl -s -X PUT \
|
|
|
|
|
-H "Authorization: Bearer ${MATRIX_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
"${MATRIX_HOMESERVER}/_matrix/client/v3/rooms/${room_encoded}/send/m.room.message/${txn}" \
|
|
|
|
|
-d "$body" 2>/dev/null) || return 0
|
|
|
|
|
local event_id
|
|
|
|
|
event_id=$(printf '%s' "$response" | jq -r '.event_id // empty' 2>/dev/null)
|
|
|
|
|
if [ -n "$event_id" ]; then
|
|
|
|
|
printf '%s' "$event_id"
|
|
|
|
|
# Register thread root for listener dispatch (escalations only)
|
|
|
|
|
if [ -z "$thread_id" ]; then
|
2026-03-21 07:38:39 +00:00
|
|
|
printf '%s\t%s\t%s\t%s\t%s\n' "$event_id" "$prefix" "$(date +%s)" "${ctx_tag}" "${PROJECT_NAME:-}" >> "$MATRIX_THREAD_MAP" 2>/dev/null || true
|
2026-03-14 16:25:33 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
2026-03-18 00:20:11 +00:00
|
|
|
|
|
|
|
|
# matrix_send_ctx — Send rich Matrix message with HTML formatting
|
|
|
|
|
# Usage: matrix_send_ctx <prefix> <plain_text> <html_body> [thread_event_id]
|
|
|
|
|
# Use for notifications that benefit from links, code blocks, or structured content.
|
|
|
|
|
matrix_send_ctx() {
|
|
|
|
|
[ -z "${MATRIX_TOKEN:-}" ] && return 0
|
|
|
|
|
local prefix="$1" plain="$2" html="$3" thread_id="${4:-}"
|
|
|
|
|
local room_encoded="${MATRIX_ROOM_ID//!/%21}"
|
|
|
|
|
local txn
|
|
|
|
|
txn="$(date +%s%N)$$"
|
|
|
|
|
local body
|
|
|
|
|
if [ -n "$thread_id" ]; then
|
|
|
|
|
body=$(jq -nc \
|
|
|
|
|
--arg m "[${prefix}] ${plain}" \
|
|
|
|
|
--arg h "<b>[${prefix}]</b> ${html}" \
|
|
|
|
|
--arg t "$thread_id" \
|
|
|
|
|
'{msgtype:"m.text",body:$m,format:"org.matrix.custom.html",formatted_body:$h,"m.relates_to":{rel_type:"m.thread",event_id:$t}}')
|
|
|
|
|
else
|
|
|
|
|
body=$(jq -nc \
|
|
|
|
|
--arg m "[${prefix}] ${plain}" \
|
|
|
|
|
--arg h "<b>[${prefix}]</b> ${html}" \
|
|
|
|
|
'{msgtype:"m.text",body:$m,format:"org.matrix.custom.html",formatted_body:$h}')
|
|
|
|
|
fi
|
|
|
|
|
local response
|
|
|
|
|
response=$(curl -s -X PUT \
|
|
|
|
|
-H "Authorization: Bearer ${MATRIX_TOKEN}" \
|
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
|
"${MATRIX_HOMESERVER}/_matrix/client/v3/rooms/${room_encoded}/send/m.room.message/${txn}" \
|
|
|
|
|
-d "$body" 2>/dev/null) || return 0
|
|
|
|
|
local event_id
|
|
|
|
|
event_id=$(printf '%s' "$response" | jq -r '.event_id // empty' 2>/dev/null)
|
|
|
|
|
if [ -n "$event_id" ]; then
|
|
|
|
|
printf '%s' "$event_id"
|
|
|
|
|
fi
|
|
|
|
|
}
|
2026-03-25 12:20:15 +00:00
|
|
|
|
|
|
|
|
# Source tea helpers (available when tea binary is installed)
|
|
|
|
|
if command -v tea &>/dev/null; then
|
|
|
|
|
# shellcheck source=tea-helpers.sh
|
|
|
|
|
source "$(dirname "${BASH_SOURCE[0]}")/tea-helpers.sh"
|
|
|
|
|
fi
|