Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .archon/workflows/defaults/archon-adversarial-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ model: sonnet
nodes:
# ─── Phase 1: Planning ───────────────────────────────────────────────
- id: plan
model: opus
prompt: |
You are a product planning expert. Your job is to take a short user prompt and expand it
into a comprehensive product specification.
Expand Down
2 changes: 2 additions & 0 deletions .archon/workflows/defaults/archon-architect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: fix-failures
model: haiku
prompt: |
Review the validation output below.

Expand Down Expand Up @@ -298,6 +299,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: create-pr
model: haiku
prompt: |
Create a pull request for the architectural improvements.

Expand Down
2 changes: 2 additions & 0 deletions .archon/workflows/defaults/archon-create-issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: report-failure
model: haiku
prompt: |
The issue could not be reproduced. Report this to the user with actionable detail.

Expand Down Expand Up @@ -557,6 +558,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: create-issue
model: haiku
prompt: |
Create the GitHub issue using the drafted content.

Expand Down
82 changes: 81 additions & 1 deletion .archon/workflows/defaults/archon-fix-github-issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: extract-issue-number
model: haiku
prompt: |
Find the GitHub issue number for this request.

Expand Down Expand Up @@ -149,6 +150,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: create-pr
model: haiku
prompt: |
Create a draft pull request for the current branch.

Expand All @@ -169,7 +171,7 @@ nodes:
4. Check if a PR already exists for this branch: `gh pr list --head $(git branch --show-current)`
- If PR exists, skip creation and capture its number
5. Look for the project's PR template at `.github/pull_request_template.md`, `.github/PULL_REQUEST_TEMPLATE.md`, or `docs/PULL_REQUEST_TEMPLATE.md`. Read whichever one exists.
6. Create a DRAFT PR: `gh pr create --draft --base $BASE_BRANCH`
6. Create a PR: `gh pr create --base $BASE_BRANCH`
- Title: concise, imperative mood, under 70 chars
- Body: if a PR template was found, fill in **every section** with details from the artifacts. Don't skip sections or leave placeholders. If no template, write a body with summary, changes, validation evidence, and `Fixes #...`.
- Link to issue: include `Fixes #...` or `Closes #...`
Expand Down Expand Up @@ -308,3 +310,81 @@ nodes:
command: archon-issue-completion-report
depends_on: [simplify]
context: fresh

# ═══════════════════════════════════════════════════════════════
# PHASE 11: MARK PR READY & TRIGGER CI
# ═══════════════════════════════════════════════════════════════

- id: prepare-merge
bash: |
PR_NUMBER=$(cat "$ARTIFACTS_DIR/.pr-number" 2>/dev/null || echo "")
if [ -z "$PR_NUMBER" ]; then
echo "No PR number found, skipping auto-merge"
exit 0
fi
# Mark PR as ready for review (remove draft status)
gh pr ready "$PR_NUMBER" 2>/dev/null || true
# Push an empty commit to re-trigger CI on the final state.
# Prior steps (simplify, self-fix) may have pushed after the last CI run,
# leaving required status checks missing on HEAD.
git commit --allow-empty -m "ci: re-trigger checks for auto-merge"
git push
# Enable auto-merge early — GitHub will merge once CI passes.
# This way, if the watch-and-merge loop exits (max iterations),
# the PR still merges automatically when CI eventually goes green.
gh pr merge "$PR_NUMBER" --squash --auto --delete-branch 2>&1 || echo "Auto-merge not available, will retry in watch loop"
echo "$PR_NUMBER"
depends_on: [report]

# ═══════════════════════════════════════════════════════════════
# PHASE 12: WATCH CI, FIX FAILURES, AUTO-MERGE
# ═══════════════════════════════════════════════════════════════

- id: watch-and-merge
depends_on: [prepare-merge]
context: fresh
model: haiku
loop:
prompt: |
You are watching CI for a pull request. Auto-merge is already enabled —
GitHub will merge automatically once CI passes. Your job is to fix CI
failures so that auto-merge can proceed.

## Setup

1. Read the PR number from `$ARTIFACTS_DIR/.pr-number`
2. If empty, output CI_DONE immediately.

## Check CI Status

Run: `gh pr checks $(cat $ARTIFACTS_DIR/.pr-number) --watch --fail-fast 2>&1 || true`

This blocks until all checks complete. Then check the exit code / output.

## If ALL checks passed

Auto-merge is already enabled and GitHub will handle the merge.
Output: CI_DONE

## If any check FAILED

1. Identify which check failed from the output
2. Get the failure logs: `gh run view <RUN_ID> --log-failed 2>&1 | tail -80`
3. Read the relevant source files and fix the issue
4. Run the project's local validation/test commands to verify your fix
5. Commit the fix with a descriptive message and push:
```bash
git add -A
git commit -m "fix: <description of CI failure fix>"
git push
```
6. End this iteration normally (do NOT output CI_DONE) — the next iteration will re-check CI

## Important

- Be concise. Focus on fixing the failure, not explaining it.
- Only fix what CI reports as broken — don't refactor or improve unrelated code.
- If the failure is environmental (flaky test, infra issue), retry once before trying to fix code.
until: CI_DONE
max_iterations: 4
fresh_context: true
15 changes: 15 additions & 0 deletions .archon/workflows/defaults/archon-idea-to-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,18 @@ nodes:
command: archon-workflow-summary
depends_on: [implement-fixes]
context: fresh

# ═══════════════════════════════════════════════════════════════════
# PHASE 9: AUTO-MERGE
# ═══════════════════════════════════════════════════════════════════

- id: auto-merge
bash: |
PR_NUMBER=$(cat "$ARTIFACTS_DIR/.pr-number" 2>/dev/null || echo "")
if [ -z "$PR_NUMBER" ]; then
echo "No PR number found, skipping auto-merge"
exit 0
fi
gh pr ready "$PR_NUMBER" 2>/dev/null || true
gh pr merge "$PR_NUMBER" --squash --auto --delete-branch 2>&1 || echo "Auto-merge not available, PR left open for manual merge"
depends_on: [workflow-summary]
3 changes: 2 additions & 1 deletion .archon/workflows/defaults/archon-piv-loop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: fix-feedback
model: haiku
depends_on: [code-review]
loop:
prompt: |
Expand Down Expand Up @@ -734,7 +735,7 @@ nodes:
cat .github/pull_request_template.md 2>/dev/null || echo "NO_TEMPLATE"
```

Create with `gh pr create --draft --base $BASE_BRANCH`:
Create with `gh pr create --base $BASE_BRANCH`:
- Title from the plan's feature name
- Body summarizing the implementation
- Use a HEREDOC for the body
Expand Down
171 changes: 171 additions & 0 deletions .archon/workflows/defaults/archon-pr-maintenance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: archon-pr-maintenance
description: |
Use when: A single open PR needs rebasing, conflict resolution, or CI fixing.
Triggers: "fix stale PRs", "maintain PRs", "rebase open PRs", "merge open PRs",
"clean up PRs", "PR maintenance", "fix PR #123".
NOT for: Creating new PRs, reviewing code, fixing specific issues from scratch.

Picks the highest-priority open PR needing attention (or a specific PR if given),
rebases it, resolves conflicts, fixes CI failures, and enables auto-merge.
Designed to be run on a cron — one PR per run, zero AI cost if nothing to do.

provider: claude
model: sonnet

nodes:
# ═══════════════════════════════════════════════════════════════
# PHASE 1: FIND THE NEXT PR TO FIX (bash only — zero AI cost)
# ═══════════════════════════════════════════════════════════════

- id: find-pr
bash: |
# If a specific PR number was passed, use that
REQUESTED=$(echo "$ARGUMENTS" | grep -oE '[0-9]+' | head -1)

if [ -n "$REQUESTED" ]; then
# Validate the PR exists and is open
STATE=$(gh pr view "$REQUESTED" --json state -q '.state' 2>/dev/null)
if [ "$STATE" = "OPEN" ]; then
echo "$REQUESTED"
exit 0
else
echo "PR #$REQUESTED is not open (state: $STATE)" >&2
exit 1
fi
fi

# No specific PR requested — find the highest priority actionable one.
# Priority: BEHIND (just needs rebase) > DIRTY (conflicts) > UNSTABLE (CI failing)
# Skip CLEAN (handled by wrapper script) and BLOCKED (can't do anything).
for STATUS in BEHIND DIRTY UNSTABLE UNKNOWN; do
PR=$(gh pr list --state open --json number,mergeStateStatus,isDraft \
--jq "[.[] | select(.isDraft == false and .mergeStateStatus == \"$STATUS\")] | .[0].number // empty")
if [ -n "$PR" ]; then
echo "$PR"
exit 0
fi
done

echo "No PRs need maintenance" >&2
exit 1
timeout: 30000

# ═══════════════════════════════════════════════════════════════
# PHASE 2: CHECKOUT & DIAGNOSE (bash only — zero AI cost)
# ═══════════════════════════════════════════════════════════════

- id: checkout-and-diagnose
bash: |
PR_NUMBER="$find-pr.output"

# Checkout the PR branch
gh pr checkout "$PR_NUMBER"

# Gather diagnostic info
echo "=== PR INFO ==="
gh pr view "$PR_NUMBER" --json number,title,headRefName,baseRefName,mergeable,mergeStateStatus,statusCheckRollup \
--jq '{number, title, head: .headRefName, base: .baseRefName, mergeable, mergeState: .mergeStateStatus, checks: [.statusCheckRollup[]? | {name, status, conclusion}]}'

echo ""
echo "=== BEHIND COUNT ==="
BASE=$(gh pr view "$PR_NUMBER" --json baseRefName -q '.baseRefName')
git fetch origin "$BASE" --quiet
BEHIND=$(git rev-list --count HEAD.."origin/$BASE")
echo "$BEHIND commits behind $BASE"

echo ""
echo "=== FILES CHANGED ==="
gh pr diff "$PR_NUMBER" --name-only 2>/dev/null | head -30
depends_on: [find-pr]
timeout: 60000

# ═══════════════════════════════════════════════════════════════
# PHASE 3: FIX THE PR (AI — only runs if phases 1-2 succeeded)
# ═══════════════════════════════════════════════════════════════

- id: fix-pr
prompt: |
You are a PR maintenance agent. Fix this single PR so it can merge.

## PR Diagnostics

```
$checkout-and-diagnose.output
```

## Instructions

You are already on the PR's branch. Follow these steps:

### Step 1: Rebase onto base branch

```bash
BASE=$(gh pr view $find-pr.output --json baseRefName -q '.baseRefName')
git rebase "origin/$BASE"
```

If conflicts arise:
- Check conflicting files: `git diff --name-only --diff-filter=U`
- For each file, read the full file to understand the conflict markers
- Resolve based on intent:
- Both sides added different things → keep both
- One side updated, other didn't → keep the update
- Both changed same lines → understand the PR's intent from the title/diff and resolve accordingly
- Stage each resolved file: `git add <file>`
- Continue: `git rebase --continue`
- If the rebase has more than 5 conflicting files, abort (`git rebase --abort`) and report failure

### Step 2: Validate

Run the project's validation. Check for these in order and run the first that exists:
```bash
# Check what package manager / validation commands exist
if [ -f "pubspec.yaml" ]; then
flutter analyze && flutter test
elif [ -f "bun.lockb" ] || [ -f "bunfig.toml" ]; then
bun run type-check 2>/dev/null; bun test 2>/dev/null
elif [ -f "package.json" ]; then
npm test 2>/dev/null
elif [ -f "pyproject.toml" ] || [ -f "requirements.txt" ]; then
python -m pytest 2>/dev/null
elif [ -f "go.mod" ]; then
go test ./... 2>/dev/null
fi
```

If validation fails, fix the issue and re-run. If you can't fix it after one attempt,
proceed anyway — CI will catch it.

### Step 3: Push

```bash
git push --force-with-lease
```

### Step 4: Enable auto-merge

```bash
gh pr merge $find-pr.output --squash --auto --delete-branch 2>&1 || \
echo "Auto-merge not available"
```

If auto-merge is not available (no branch protection rules), check CI status
and merge directly once passing:
```bash
gh pr checks $find-pr.output --watch --fail-fast 2>&1 || true
gh pr merge $find-pr.output --squash --delete-branch 2>&1 || \
echo "Could not merge — may need manual review"
```

### Step 5: Report result

Output a brief summary: PR number, what you did, whether it merged or has auto-merge enabled.

## Important

- Be concise. Fix the problem, don't explain it at length.
- Only fix what's needed for the PR to merge — don't refactor or improve unrelated code.
- If a CI failure is environmental (flaky test, infra issue), push an empty commit to retry.
depends_on: [checkout-and-diagnose]
context: fresh
model: sonnet
2 changes: 1 addition & 1 deletion .archon/workflows/defaults/archon-ralph-dag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ nodes:

If no template was found, write a summary with: problem, what changed, stories table, and validation evidence.

3. **Create a draft PR** using `gh pr create --draft --base $BASE_BRANCH --title "feat: {PRD feature name}"` with the filled-in template as the body. Use a HEREDOC for the body.
3. **Create a PR** using `gh pr create --base $BASE_BRANCH --title "feat: {PRD feature name}"` with the filled-in template as the body. Use a HEREDOC for the body.

4. **Output completion signal:**
```
Expand Down
4 changes: 3 additions & 1 deletion .archon/workflows/defaults/archon-refactor-safely.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: execute-refactor
model: claude-opus-4-6[1m]
model: sonnet
prompt: |
You are executing a refactoring plan with strict safety guardrails.

Expand Down Expand Up @@ -327,6 +327,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: fix-failures
model: haiku
prompt: |
Review the validation output below.

Expand Down Expand Up @@ -430,6 +431,7 @@ nodes:
# ═══════════════════════════════════════════════════════════════

- id: create-pr
model: haiku
prompt: |
Create a pull request for the refactoring.

Expand Down
Loading