diff --git a/.env.example b/.env.example index 0062b9e..6124671 100644 --- a/.env.example +++ b/.env.example @@ -26,7 +26,8 @@ FORGE_GARDENER_TOKEN= # [SECRET] gardener-bot API token FORGE_VAULT_TOKEN= # [SECRET] vault-bot API token FORGE_SUPERVISOR_TOKEN= # [SECRET] supervisor-bot API token FORGE_PREDICTOR_TOKEN= # [SECRET] predictor-bot API token -FORGE_BOT_USERNAMES=dev-bot,review-bot,planner-bot,gardener-bot,vault-bot,supervisor-bot,predictor-bot +FORGE_ARCHITECT_TOKEN= # [SECRET] architect-bot API token +FORGE_BOT_USERNAMES=dev-bot,review-bot,planner-bot,gardener-bot,vault-bot,supervisor-bot,predictor-bot,architect-bot # ── Backwards compatibility ─────────────────────────────────────────────── # If CODEBERG_TOKEN is set but FORGE_TOKEN is not, env.sh falls back to diff --git a/AGENTS.md b/AGENTS.md index a6ac1fd..299ff45 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,11 +3,11 @@ ## What this repo is -Disinto is an autonomous code factory. It manages six agents (dev, review, -gardener, supervisor, planner, predictor) that pick up issues from forge, -implement them, review PRs, plan from the vision, and keep the system healthy — -all via cron and `claude -p`. The dispatcher executes formula-based operational -tasks. +Disinto is an autonomous code factory. It manages seven agents (dev, review, +gardener, supervisor, planner, predictor, architect) that pick up issues from +forge, implement them, review PRs, plan from the vision, and keep the system +healthy — all via cron and `claude -p`. The dispatcher executes formula-based +operational tasks. > **Note:** The vault is being redesigned as a PR-based approval workflow on the > ops repo (see issues #73-#77). See [docs/VAULT.md](docs/VAULT.md) for details. Old vault scripts are being removed. @@ -26,6 +26,7 @@ disinto/ (code repo) ├── supervisor/ supervisor-run.sh — formula-driven health monitoring (cron wrapper) │ preflight.sh — pre-flight data collection for supervisor formula │ supervisor-poll.sh — legacy bash orchestrator (superseded) +├── architect/ architect-run.sh — strategic decomposition of vision into sprints ├── vault/ vault-env.sh — shared env setup (vault redesign in progress, see #73-#77) ├── lib/ env.sh, agent-session.sh, ci-helpers.sh, ci-debug.sh, load-project.sh, parse-deps.sh, guard.sh, mirrors.sh, pr-lifecycle.sh, issue-lifecycle.sh, worktree.sh, formula-session.sh, profile.sh, build-graph.py ├── projects/ *.toml.example — templates; *.toml — local per-box config (gitignored) @@ -93,6 +94,7 @@ bash dev/phase-test.sh | Supervisor | `supervisor/` | Health monitoring | [supervisor/AGENTS.md](supervisor/AGENTS.md) | | Planner | `planner/` | Strategic planning | [planner/AGENTS.md](planner/AGENTS.md) | | Predictor | `predictor/` | Infrastructure pattern detection | [predictor/AGENTS.md](predictor/AGENTS.md) | +| Architect | `architect/` | Strategic decomposition | [architect/AGENTS.md](architect/AGENTS.md) | > **Vault:** Being redesigned as a PR-based approval workflow (issues #73-#77). > See [docs/VAULT.md](docs/VAULT.md) for the vault PR workflow details. diff --git a/architect/AGENTS.md b/architect/AGENTS.md new file mode 100644 index 0000000..c2e99ba --- /dev/null +++ b/architect/AGENTS.md @@ -0,0 +1,65 @@ + +# Architect — Agent Instructions + +## What this agent is + +The architect is a strategic decomposition agent that breaks down vision issues +into development sprints. It proposes sprints via PRs on the ops repo and +converses with humans through PR comments. + +## Role + +- **Input**: Vision issues from VISION.md, prerequisite tree from ops repo +- **Output**: Sprint proposals as PRs on the ops repo, sub-issue files +- **Mechanism**: Formula-driven execution via `formulas/run-architect.toml` +- **Identity**: `architect-bot` on Forgejo + +## Responsibilities + +1. **Strategic decomposition**: Break down large vision items into coherent + sprints that can be executed by the dev agent +2. **Design fork identification**: When multiple implementation approaches exist, + identify the forks and file sub-issues for each path +3. **Sprint PR creation**: Propose sprints as PRs on the ops repo with clear + acceptance criteria and dependencies +4. **Human conversation**: Respond to PR comments, refine sprint proposals based + on human feedback +5. **Sub-issue filing**: After design forks are resolved, file concrete sub-issues + for implementation + +## Formula + +The architect is driven by `formulas/run-architect.toml`. This formula defines +the steps for: +- Research: analyzing vision items and prerequisite tree +- Design: identifying implementation approaches and forks +- Sprint proposal: creating structured sprint PRs +- Sub-issue filing: creating concrete implementation issues + +## Execution + +Run via `architect/architect-run.sh`, which: +- Acquires a cron lock and checks available memory +- Sources shared libraries (env.sh, formula-session.sh) +- Uses FORGE_ARCHITECT_TOKEN for authentication +- Loads the formula and builds context from VISION.md, AGENTS.md, and ops repo +- Executes the formula via `agent_run` + +## Cron + +Suggested cron entry (every 6 hours): +```cron +0 */6 * * * cd /path/to/disinto && bash architect/architect-run.sh +``` + +## State + +Architect state is tracked in `state/.architect-active` (disabled by default — +empty file not created, just document it). + +## Related issues + +- #96: Architect agent parent issue +- #100: Architect formula — research + design fork identification +- #101: Architect formula — sprint PR creation with questions +- #102: Architect formula — answer parsing + sub-issue filing diff --git a/architect/architect-run.sh b/architect/architect-run.sh new file mode 100755 index 0000000..d510ab6 --- /dev/null +++ b/architect/architect-run.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash +# ============================================================================= +# architect-run.sh — Cron wrapper: architect execution via SDK + formula +# +# Synchronous bash loop using claude -p (one-shot invocation). +# No tmux sessions, no phase files — the bash script IS the state machine. +# +# Flow: +# 1. Guards: cron lock, memory check +# 2. Source lib/env.sh, lib/formula-session.sh +# 3. Override FORGE_TOKEN with FORGE_ARCHITECT_TOKEN +# 4. Load formula from formulas/run-architect.toml +# 5. Build context: VISION.md, AGENTS.md, prerequisite tree from ops repo +# 6. Call agent_run to execute formula +# +# Usage: +# architect-run.sh [projects/disinto.toml] # project config (default: disinto) +# +# Cron: 0 */6 * * * # every 6 hours +# ============================================================================= +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +FACTORY_ROOT="$(dirname "$SCRIPT_DIR")" + +# Accept project config from argument; default to disinto +export PROJECT_TOML="${1:-$FACTORY_ROOT/projects/disinto.toml}" +# shellcheck source=../lib/env.sh +source "$FACTORY_ROOT/lib/env.sh" +# Override FORGE_TOKEN with architect-bot's token (#747) +FORGE_TOKEN="${FORGE_ARCHITECT_TOKEN:-${FORGE_TOKEN}}" +# shellcheck source=../lib/formula-session.sh +source "$FACTORY_ROOT/lib/formula-session.sh" +# shellcheck source=../lib/worktree.sh +source "$FACTORY_ROOT/lib/worktree.sh" +# shellcheck source=../lib/guard.sh +source "$FACTORY_ROOT/lib/guard.sh" +# shellcheck source=../lib/agent-sdk.sh +source "$FACTORY_ROOT/lib/agent-sdk.sh" + +LOG_FILE="$SCRIPT_DIR/architect.log" +# shellcheck disable=SC2034 # consumed by agent-sdk.sh +LOGFILE="$LOG_FILE" +# shellcheck disable=SC2034 # consumed by agent-sdk.sh +SID_FILE="/tmp/architect-session-${PROJECT_NAME}.sid" +SCRATCH_FILE="/tmp/architect-${PROJECT_NAME}-scratch.md" +WORKTREE="/tmp/${PROJECT_NAME}-architect-run" + +log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%S)Z] $*" >> "$LOG_FILE"; } + +# Ensure AGENT_IDENTITY is set for profile functions +if [ -z "${AGENT_IDENTITY:-}" ] && [ -n "${FORGE_ARCHITECT_TOKEN:-}" ]; then + AGENT_IDENTITY=$(curl -sf -H "Authorization: token ${FORGE_ARCHITECT_TOKEN}" \ + "${FORGE_URL:-http://localhost:3000}/api/v1/user" 2>/dev/null | jq -r '.login // empty' 2>/dev/null || true) +fi + +# ── Guards ──────────────────────────────────────────────────────────────── +check_active architect +acquire_cron_lock "/tmp/architect-run.lock" +check_memory 2000 + +log "--- Architect run start ---" + +# ── Load formula + context ─────────────────────────────────────────────── +load_formula "$FACTORY_ROOT/formulas/run-architect.toml" +build_context_block VISION.md AGENTS.md ops:prerequisites.md ops:sprints/.gitkeep + +# ── Build structural analysis graph ────────────────────────────────────── +build_graph_section + +# ── Ensure ops repo is available ─────────────────────────────────────── +ensure_ops_repo + +# ── Load lessons from .profile repo (pre-session) ──────────────────────── +profile_load_lessons || true +LESSONS_INJECTION="${LESSONS_CONTEXT:-}" + +# ── Read scratch file (compaction survival) ─────────────────────────────── +SCRATCH_CONTEXT=$(read_scratch_context "$SCRATCH_FILE") +SCRATCH_INSTRUCTION=$(build_scratch_instruction "$SCRATCH_FILE") + +# ── Build prompt ───────────────────────────────────────────────────────── +build_sdk_prompt_footer " + Relabel: curl -sf -H \"Authorization: token \${FORGE_TOKEN}\" -X PUT -H 'Content-Type: application/json' '${FORGE_API}/issues/{number}/labels' -d '{\"labels\":[LABEL_ID]}' + Comment: curl -sf -H \"Authorization: token \${FORGE_TOKEN}\" -X POST -H 'Content-Type: application/json' '${FORGE_API}/issues/{number}/comments' -d '{\"body\":\"...\"}' + Close: curl -sf -H \"Authorization: token \${FORGE_TOKEN}\" -X PATCH -H 'Content-Type: application/json' '${FORGE_API}/issues/{number}' -d '{\"state\":\"closed\"}' +" + +PROMPT="You are the architect agent for ${FORGE_REPO}. Work through the formula below. + +## Project context +${CONTEXT_BLOCK}${LESSONS_INJECTION:+## Lessons learned +${LESSONS_INJECTION} +} +${GRAPH_SECTION}${SCRATCH_CONTEXT:+${SCRATCH_CONTEXT} +} +## Formula +${FORMULA_CONTENT} + +${SCRATCH_INSTRUCTION} + +${PROMPT_FOOTER}" + +# ── Create worktree ────────────────────────────────────────────────────── +formula_worktree_setup "$WORKTREE" + +# ── Run agent ───────────────────────────────────────────────────────────── +export CLAUDE_MODEL="opus" + +agent_run --worktree "$WORKTREE" "$PROMPT" +log "agent_run complete" + +# Write journal entry post-session +profile_write_journal "architect-run" "Architect run $(date -u +%Y-%m-%d)" "complete" "" || true + +rm -f "$SCRATCH_FILE" +log "--- Architect run done ---" diff --git a/formulas/run-architect.toml b/formulas/run-architect.toml new file mode 100644 index 0000000..5a2df6a --- /dev/null +++ b/formulas/run-architect.toml @@ -0,0 +1,36 @@ +# formulas/run-architect.toml — Architect formula (stub) +# +# Executed by architect-run.sh via cron — strategic decomposition of vision +# issues into development sprints. +# +# This is a stub formula — steps will be filled in by follow-up issues: +# #100: research + design fork identification +# #101: sprint PR creation with questions +# #102: answer parsing + sub-issue filing +# +# AGENTS.md maintenance is handled by the gardener (#246). + +name = "run-architect" +description = "Architect: strategic decomposition of vision into sprints" +version = 1 +model = "opus" + +[context] +files = ["VISION.md", "AGENTS.md"] +# Prerequisite tree loaded from ops repo (ops: prefix) +# Sprints directory tracked in ops repo + +[[steps]] +id = "placeholder" +title = "TODO: implement formula steps" +description = """ +This step is a placeholder. The actual formula steps will be implemented in +follow-up issues: + +- #100: research + design fork identification +- #101: sprint PR creation with questions +- #102: answer parsing + sub-issue filing + +The architect formula will decompose vision items into coherent sprints, +identify design forks, and file sub-issues after design decisions are made. +""" diff --git a/lib/env.sh b/lib/env.sh index a2c98a9..33d7737 100755 --- a/lib/env.sh +++ b/lib/env.sh @@ -95,6 +95,7 @@ export FORGE_GARDENER_TOKEN="${FORGE_GARDENER_TOKEN:-${FORGE_TOKEN}}" export FORGE_VAULT_TOKEN="${FORGE_VAULT_TOKEN:-${FORGE_TOKEN}}" export FORGE_SUPERVISOR_TOKEN="${FORGE_SUPERVISOR_TOKEN:-${FORGE_TOKEN}}" export FORGE_PREDICTOR_TOKEN="${FORGE_PREDICTOR_TOKEN:-${FORGE_TOKEN}}" +export FORGE_ARCHITECT_TOKEN="${FORGE_ARCHITECT_TOKEN:-${FORGE_TOKEN}}" # Bot usernames filter: FORGE_BOT_USERNAMES > legacy CODEBERG_BOT_USERNAMES export FORGE_BOT_USERNAMES="${FORGE_BOT_USERNAMES:-${CODEBERG_BOT_USERNAMES:-dev-bot,review-bot,planner-bot,gardener-bot,vault-bot,supervisor-bot,predictor-bot}}"