Back to .md Directory

PRD.md — ⚡ AT Protocol Agent Network

Defines the autonomous development workflow for an AT Protocol agent network, including story selection, TDD execution, validation, and sprint tracking.

May 2, 2026
0 downloads
0 views
ai agent workflow
View source

What this file does

Defines the autonomous development workflow for an AT Protocol agent network, including story selection, TDD execution, validation, and sprint tracking.

When to use it

  • You want an AI agent to autonomously claim and complete GitHub issues
  • You need a structured TDD loop with validation gates for a monorepo
  • You are building an encrypted agent system on Cloudflare Workers
  • You want to coordinate multiple epics with dependency resolution

Assumes this stack

pnpmVitesttsupTurborepoCloudflare Workersbun

PRD.md — ⚡ AT Protocol Agent Network

The single source of truth for Ralph loop execution.

This document links directly to GitHub issues, contains SOP instructions, and defines the autonomous development workflow.

Repository: https://github.com/joelhooks/atproto-agent-network
Project Board: https://github.com/users/joelhooks/projects/1


Stack

ConcernChoiceNotes
Package ManagerpnpmStable monorepo support
Test RunnerVitestBest-in-class for TypeScript
Build TooltsupFast, simple ESM builds
MonorepoTurborepoTask orchestration + caching
RuntimeCloudflare WorkersDurable Objects for agents
CLI Binarybun compileSingle-file distribution

Commands

pnpm install              # Install deps
pnpm test                 # Run all tests (vitest via turbo)
pnpm turbo build          # Build all packages
pnpm turbo typecheck      # Type check all packages
pnpm vitest run <file>    # Run specific test file

Quick Links

Epics

PhaseEpicStatusSecurity Gate
0#13 Testing Infrastructure🟡 In Progress
1#1 Encrypted Single Agent⬜ Blocked on #13No plaintext in D1
2#2 Semantic Memory⬜ FutureSearch on embeddings only
3#3 Multi-Agent⬜ FutureE2E agent encryption
4#4 Federation⬜ FuturePrivate-by-default sharing
5#5 Polish⬜ Future

Container Issues (DO NOT CLAIM DIRECTLY)

IssueContainsStatus
#7 X25519 Key Generation#28, #29, #30, #31Work on children
#14 Setup Vitest#24, #25, #26, #27Work on children

Meta Issues (Gardening)

PurposeIssue
Sprint Retrospective#20
Sprint Planning#21
Backlog Grooming#22
Update Affected Issues#23

🤖 Ralph Loop Rules

Issue Categories

TypeLabelAgent Behavior
Leaf tasktype/task + agent/ready✅ Claim and execute
Containertype/container❌ Never claim — work on children
Epictype/epic❌ Never claim — tracking only
Metaloop/meta✅ Execute during gardening phase

Story Selection Algorithm

1. Query: gh issue list --label "agent/ready" --state open
2. Filter: Exclude type/container, type/epic
3. Sort: By priority in prd.json (lower = higher priority)
4. Check: dependsOn satisfied (all deps closed or in prd.json before this)
5. Select: First issue passing all checks

Validation Failures

If validation fails:

  1. Retry once with fix attempt
  2. On 2nd failure: Add agent/blocked label
  3. Comment with: Failure log + what was tried
  4. Move to: Next story in queue
  5. If all stories blocked: Ping Oracle with full status

Story Skip Conditions

Skip a story if:

  • Missing agent/ready label
  • Has agent/blocked label
  • Has type/container or type/epic label
  • Has unmet dependsOn (check via prd.json)
  • Parent epic is closed

Branch Strategy

# Each story gets a branch from main
git checkout main && git pull
git checkout -b feat/<issue-number>-<short-name>

# Work on branch
# ... commits ...

# Push and create PR
git push -u origin HEAD
gh pr create --title "feat(pkg): <title>" --body "Closes #<number>"

Dependency Resolution

Stories in prd.json have dependsOn arrays:

{
  "id": "envelope-encryption",
  "dependsOn": ["derive-shared-secret"]
}

Resolution rules:

  1. Check if dependency story is marked passes: true in prd.json
  2. OR check if dependency issue is closed on GitHub
  3. If neither, story is blocked

Sprints

Sprint 0: Bootstrap

StoryIssueValidationEst.
Setup monorepo#6pnpm turbo build --dry-run10m

Sprint 1: Testing Foundation

StoryIssueValidationEst.
Install Vitest#24pnpm vitest --passWithNoTests15m
First unit test#25pnpm vitest run identity.test20m
Workspace config#26Package tests work15m
Turbo test task#27pnpm turbo test15m
Test utilities#15Fixtures work25m
CI workflow#18.github/workflows/ci.yml20m
Pre-commit hooks#19Hooks trigger15m

Sprint 2: Crypto Primitives

StoryIssueValidationEst.
generateX25519Keypair#28crypto.test passes30m
generateEd25519Keypair#29crypto.test passes20m
exportPublicKey#30multibase works30m
deriveSharedSecret#31ECDH works20m
Envelope encryption#8encrypt/decrypt roundtrip45m

🚨 HITL Gate: Security review required after this sprint.

Sprint 3: Encrypted Storage

StoryIssueValidationEst.
D1 schema#9Schema valid30m
Pi agent wrapper#10Agent tests pass45m
EncryptedMemory#11Memory tests pass60m
Wire up AgentDO#12Integration works60m

🚨 HITL Gate: Phase 1 complete — verify no plaintext in D1.

Sprint 4: Advanced Testing

StoryIssueValidationEst.
Integration harness#16D1 mock works45m
E2E harness#17Miniflare works60m

Standard Operating Procedure (SOP)

1. Starting a Work Session

cd ~/Code/joelhooks/atproto-agent-network

# 1. Pull latest
git checkout main && git pull

# 2. Check current state
gh issue list --label "agent/ready" --limit 10
cat prd.json | jq '.stories | map(select(.passes != true)) | .[0:3]'

# 3. Read context
cat PRD.md          # This file
cat AGENTS.md       # Development guide

# 4. Claim next ready story (NOT container/epic)
gh issue edit <number> --remove-label "agent/ready" --add-label "agent/claimed"

2. TDD Execution (The Loop)

Every story follows RED → GREEN → REFACTOR:

┌─────────────────────────────────────────────────────────────────┐
│                        TDD CYCLE                                 │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  ┌─────────┐                                                     │
│  │   RED   │ Write failing test first                           │
│  │         │ - Copy test code from issue body                    │
│  │         │ - Run: pnpm vitest run <file> → MUST FAIL           │
│  └────┬────┘                                                     │
│       │                                                          │
│       ▼                                                          │
│  ┌─────────┐                                                     │
│  │  GREEN  │ Minimal code to pass                               │
│  │         │ - Copy implementation from issue body               │
│  │         │ - Adapt as needed                                   │
│  │         │ - Run: pnpm vitest run <file> → MUST PASS           │
│  └────┬────┘                                                     │
│       │                                                          │
│       ▼                                                          │
│  ┌─────────┐                                                     │
│  │REFACTOR │ Clean up                                            │
│  │         │ - Run: pnpm turbo typecheck                         │
│  │         │ - Commit: git commit -m "feat(...): ..."            │
│  └─────────┘                                                     │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

3. Validation

Each story in prd.json has a validationCommand:

# Get validation command for a story
cat prd.json | jq -r '.stories[] | select(.issue == 24) | .validationCommand'

# Run it
eval "$(cat prd.json | jq -r '.stories[] | select(.issue == 24) | .validationCommand')"

4. Completing a Story

# 1. Run full validation
pnpm turbo test
pnpm turbo typecheck

# 2. Commit with issue reference
git add -A
git commit -m "feat(pkg): description

Closes #<number>"

# 3. Push and create PR
git push -u origin HEAD
gh pr create --title "feat(pkg): description" --body "Closes #<number>

## Changes
- Added tests for X
- Implemented X

## Validation
\`\`\`
<paste validation output>
\`\`\`
"

# 4. Update issue labels
gh issue edit <number> --remove-label "agent/claimed" --add-label "agent/review"

# 5. Update parent epic/container
gh issue comment <parent> --body "✅ Completed #<number> - <summary>"

5. Gardening (After Each Sprint)

# 1. Check for newly unblocked issues
gh issue list --label "agent/blocked"
# For each: check if deps are now met
gh issue edit <number> --remove-label "agent/blocked" --add-label "agent/ready"

# 2. Update prd.json (mark completed stories)
# Edit prd.json, set "passes": true for completed stories

# 3. Create retrospective
gh issue create --title "[Retro] Sprint: <name>" \
  --label "loop/retro" --label "loop/meta" \
  --body "## What went well
- 

## What went poorly
- 

## Process improvements
- "

Label Reference

Agent Workflow

LabelMeaningColor
agent/readyReady for agent to claim🟢 Green
agent/claimedAgent is working on it🟡 Yellow
agent/blockedWaiting on dependency🔴 Red
agent/reviewAwaiting human review🟣 Purple

Issue Type

LabelMeaningClaimable?
type/taskIndividual work item✅ Yes
type/containerHas subtasks❌ No
type/epicPhase-level tracking❌ No
type/bugSomething broken✅ Yes
type/securitySecurity-related✅ Yes (careful)

Loop/Meta

LabelMeaning
loop/metaProject maintenance
loop/retroRetrospective
loop/planningSprint planning
loop/groomingBacklog maintenance
loop/testingTesting infrastructure

HITL Gates

LabelMeaning
hitl/security-gateRequires security review before proceeding

HITL Checkpoints

Do not proceed past these without Oracle approval:

Phase 1 Gate (After Sprint 3)

  • All memories encrypted (verify with D1 query)
  • No plaintext in any table
  • Key generation tests pass
  • Encryption/decryption round-trip works

Phase 2 Gate

  • Search works on embeddings only
  • Decryption only on explicit retrieval
  • No content in Vectorize metadata

Phase 3 Gate

  • E2E encryption between agents
  • Key exchange protocol verified
  • No shared secrets in logs

Phase 4 Gate

  • Sharing requires explicit opt-in
  • Public records clearly marked
  • Revocation works

Ralph Loop Configuration

From prd.json:

{
  "loopConfig": {
    "maxIterations": 20,
    "validationTimeout": 120,
    "autoCommit": true,
    "onStoryFail": {
      "maxRetries": 2,
      "addBlockedLabel": true,
      "commentWithLog": true
    }
  }
}

Running the Loop

# Check status
ralph_status --workdir ~/Code/joelhooks/atproto-agent-network

# Run single iteration
ralph_iterate --workdir ~/Code/joelhooks/atproto-agent-network

# Run full loop (background)
ralph_loop --workdir ~/Code/joelhooks/atproto-agent-network --maxIterations 5

File Structure

atproto-agent-network/
├── PRD.md               # THIS FILE - execution source of truth
├── AGENTS.md            # Development guide
├── PI-POC.md            # Implementation plan
├── prd.json             # Machine-readable stories (Ralph reads this)
├── progress.txt         # Ralph loop progress log
│
├── .github/
│   └── workflows/
│       └── ci.yml       # CI pipeline
│
├── .agents/
│   └── skills/          # Project-specific skills
│
├── packages/
│   ├── core/            # Types, crypto, lexicons
│   └── agent/           # Pi wrapper, encrypted memory
│
└── apps/
    └── network/         # Cloudflare Workers + DO

Skills Reference

# Read skill before implementing
cat .agents/skills/<skill-name>/SKILL.md
SkillWhenIssue Tags
envelope-encryptionCrypto worktype/security, pkg/core
cloudflare-doDurable Objectspkg/network
pi-agentAgent runtimepkg/agent
d1-patternsDatabasepkg/network
vectorize-searchEmbeddingsPhase 2+
zap-cliObservabilitypkg/cli

Quick Commands

# View ready issues (excludes containers/epics)
gh issue list --label "agent/ready" -L 20 | grep -v "type/container\|type/epic"

# Claim issue
gh issue edit <N> --remove-label "agent/ready" --add-label "agent/claimed"

# Complete issue  
gh issue edit <N> --remove-label "agent/claimed" --add-label "agent/review"

# Check story in prd.json
cat prd.json | jq '.stories[] | select(.issue == <N>)'

# Run validation for story
eval "$(cat prd.json | jq -r '.stories[] | select(.issue == <N>) | .validationCommand')"

Last updated: 2026-02-07

What's inside

12 sections including stack table, epic/container/meta issue tables, Ralph loop rules, sprint plans, SOP, label reference, HITL checkpoints, and file structure

Change this for your project

  • Replace joelhooks/atproto-agent-network with your own repository path
  • Replace https://github.com/users/joelhooks/projects/1 with your project board URL
  • Replace #1, #2, etc. with your own GitHub issue numbers
  • Replace ralph_status, ralph_iterate, ralph_loop with your agent's CLI commands

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Container issues that block claiming but allow work on children
  • HITL gates that pause the autonomous loop for security review
  • A prd.json file as machine-readable story source that the agent reads

Related Documents