This document defines the operational rules, patterns, and accumulated knowledge for all P0G agents.
- Core Principles
- Directory Structure
- File Operations
- Workflow Execution
- Coding Standards
- Verification Patterns
- State Management
- Communication Protocol
- Error Handling
- Learned Patterns
Every agent invocation is stateless. Never assume:
- Previous file states
- Cached variables or context
- Prior agent actions completed successfully
Always: Read, verify, then act.
- Document all decisions
- Log all actions to
progress.txt - Never rely on side effects
- Change only what's necessary
- Prefer edits over rewrites
- Avoid creating unnecessary files
- Every action must be verifiable
- If it can't be verified, it didn't happen
- Trust shell exit codes
project_root/
├── .agent/
│ ├── workflows/ # Slash commands (/p0g-*)
│ │ ├── p0g-np.md # Phase 1: Discovery
│ │ ├── p0g-plan.md # Phase 2: Architecture
│ │ ├── p0g-tasks.md # Phase 3: Task breakdown
│ │ ├── p0g-loop.md # Phase 4: Execution
│ │ └── p0g-surgeon.md # Reactive: Bug decomposer
│ └── rules/ # Optional: paradigm rules (e.g., functional.md)
├── agents/
│ └── p0g/
│ ├── prompts/ # Agent personalities
│ │ ├── discovery.md
│ │ ├── architect.md
│ │ ├── tasker.md
│ │ ├── executor.md
│ │ └── surgeon.md
│ └── skills/
│ └── SKILL.md # Backup/rollback/recovery
├── .p0g/ # Safety infrastructure
│ ├── backups/ # Full project snapshots
│ ├── snapshots/ # Task-level before/after
│ ├── checkpoints/ # Feature-level milestones
│ └── surgery.json # Active surgical plan (if any)
├── prd.json # Single source of truth
├── progress.txt # Append-only execution log
├── errors.log # Error tracking
└── AGENTS.md # This file: guidelines and patterns
| Path | Purpose | Access |
|---|---|---|
.p0g/ |
Safety infrastructure | Read/Write (system only) |
.p0g/backups/ |
Full project snapshots | Write before edits |
.p0g/snapshots/ |
Task-level snapshots | Write during execution |
.p0g/checkpoints/ |
Feature milestones | Write on feature completion |
.p0g/surgery.json |
Active surgical plan | Read/Write during /p0g-surgeon |
.agent/rules/ |
Paradigm rules (optional) | Read only (loaded by Antigravity) |
prd.json |
Project definition | Read/Write (structured) |
progress.txt |
Execution log | Append only |
AGENTS.md |
Guidelines and patterns | Append patterns only |
- Always use absolute paths within the project
- Never hardcode user home directories
- Resolve symlinks before operating on files
- Check existence before any file operation
1. Verify file exists (or parent directory for new files)
2. Create backup in .p0g/backups/<timestamp>/
3. Read current content
4. Plan minimal changes
5. Execute modification
6. Verify result
# Before modifying src/auth/index.ts
mkdir -p .p0g/backups/$(date +%Y%m%d_%H%M%S)
cp src/auth/index.ts .p0g/backups/$(date +%Y%m%d_%H%M%S)/# Verify parent exists
test -d src/utils || mkdir -p src/utils
# Create file only if it doesn't exist
test -f src/utils/helpers.ts || touch src/utils/helpers.ts# Never delete without confirmation
test -f target.ts && rm target.ts
# For directories
test -d target_dir && rm -rf target_dir/p0g-np → /p0g-plan → /p0g-tasks → /p0g-loop
│ │ │ │
▼ ▼ ▼ ▼
Discover Design Atomize Execute
project architecture tasks & verify
/p0g-surgeon (reactive — any phase)
│
▼
Diagnose problem
Decompose into micro-fixes
Apply & verify each
| Phase | Requires | Produces |
|---|---|---|
/p0g-np |
User input | Project understanding |
/p0g-plan |
Discovery complete | prd.json["features"] + stack |
/p0g-tasks |
Features defined | prd.json["tasks"] |
/p0g-loop |
Tasks defined | Implemented code |
/p0g-surgeon |
Problem description | Micro-fixes applied |
- Commands starting with
/p0g-are blocking - Each phase must complete before the next begins
- Verify phase completion by checking
prd.json["status"]
| Status | Meaning |
|---|---|
discovery |
Run /p0g-np |
planning |
Run /p0g-plan |
ready_for_execution |
Run /p0g-loop |
in_progress |
Execution ongoing |
completed |
All tasks passed |
blocked |
Human intervention needed |
- Match existing patterns — Read similar files before implementing
- No placeholders —
// TODO,FIXME, or incomplete code is forbidden - Complete implementations — Every function must be fully working
- Self-documenting code — Clear names over comments
// Prefer explicit types
function processUser(user: User): ProcessedUser { }
// Use early returns
if (!user) return null;
// Destructure when clearer
const { name, email } = user;# Type hints for public functions
def process_user(user: User) -> ProcessedUser:
# Guard clauses
if not user:
return None
# f-strings over format
message = f"Hello, {user.name}"# Always quote variables
"$variable"
# Use [[ ]] for conditionals
[[ -f "$file" ]] && echo "exists"
# Exit on error in scripts
set -euo pipefail| Type | Convention | Example |
|---|---|---|
| Files | kebab-case | user-service.ts |
| Classes | PascalCase | UserService |
| Functions | camelCase | processUser |
| Constants | UPPER_SNAKE | MAX_RETRIES |
| Variables | camelCase | userName |
Prefer single-line commands for verification_cmd:
# File operations
test -f path/to/file.ts # File exists
test -d path/to/directory # Directory exists
test -s path/to/file.ts # File exists and not empty
test -x path/to/script.sh # File is executable
# Content verification
grep -q 'pattern' file.ts # Pattern exists
grep -c 'pattern' file.ts | grep -q '^[1-9]' # Pattern appears at least once
head -1 file.ts | grep -q '^import' # First line matches
# JSON validation
jq empty config.json # Valid JSON
jq -e '.key' config.json > /dev/null # Key exists
jq -e '.array | length > 0' data.json > /dev/null # Array not empty
# Build/test verification
npm run build --silent # Build succeeds
npm test -- --silent # Tests pass
npm run typecheck --silent # Types valid
# Combined checks
test -f file.ts && grep -q 'export' file.ts # File exists AND has exports
npm run build --silent && npm test --silent # Build AND tests pass| Avoid | Why | Instead |
|---|---|---|
ls file.ts |
Exit code always 0 | test -f file.ts |
cat file.ts | grep |
Unnecessary pipe | grep -q pattern file.ts |
echo $? |
Doesn't verify anything | Use exit code directly |
| Multi-line scripts | Hard to track | Combine with && |
{
"name": "Project Name",
"description": "Project description",
"status": "ready_for_execution",
"features": [
{
"id": 1,
"name": "Feature name",
"description": "What it does"
}
],
"tasks": [
{
"id": 1,
"feature_id": 1,
"description": "Task description",
"type": "create",
"passes": false,
"dependencies": [],
"verification_cmd": "test -f file.ts"
}
]
}Task States:
pending (passes: false, not started)
↓
in_progress (being executed)
↓
passed (passes: true) ←── retry ←── failed
↓
blocked (needs human)
Always append to progress.txt:
## [2024-01-15T10:30:00Z] Task #5 - STARTED
- Description: Create user validation utility
- Dependencies: [#3, #4] - all passed
## [2024-01-15T10:32:00Z] Task #5 - COMPLETED
- Files created: src/utils/validation.ts
- Verification: PASSED (exit code 0)
- Duration: 2m
Use consistent prefixes:
| Prefix | Meaning |
|---|---|
[INFO] |
General information |
[START] |
Beginning an action |
[DONE] |
Action completed successfully |
[FAIL] |
Action failed |
[WARN] |
Non-blocking issue |
[BLOCK] |
Requires human intervention |
[START] Task #5: Create user validation utility
[INFO] Checking dependencies: #3 ✓, #4 ✓
[INFO] Creating src/utils/validation.ts
[INFO] Running verification...
[DONE] Task #5: PASSED
When human intervention is needed:
[BLOCK] Task #7 requires human decision
Problem: Ambiguous requirement for authentication method
Options:
A) JWT tokens (stateless, scalable)
B) Session cookies (simpler, requires state)
C) OAuth integration (third-party, complex)
Waiting for input before proceeding.
| Type | Retry? | Action |
|---|---|---|
| Syntax error | Yes | Fix and re-run |
| Missing file | Yes | Check path, create if needed |
| Permission denied | No | Escalate to human |
| Missing dependency | Yes | Install and retry |
| Network error | Yes | Retry with backoff |
| Ambiguous requirement | No | Escalate to human |
Append to errors.log:
[2024-01-15T10:35:00Z] ERROR in Task #5
Type: FileNotFound
Message: Cannot read src/models/user.ts
Context: Required for type imports
Attempted: Check path, verify dependencies
Resolution: Found file at src/model/user.ts (typo in task)
Status: RESOLVED
1. Log error immediately
2. Classify error type
3. If retryable:
a. Attempt fix (max 3 tries)
b. Log each attempt
c. If fixed → continue
d. If not → escalate
4. If not retryable:
a. Log as BLOCKED
b. Notify human
c. Do NOT proceed
This section accumulates patterns discovered during execution. Agents should consult this before implementing similar functionality.
### Pattern: <Name>
- **Context**: When this pattern applies
- **Problem**: What issue it solves
- **Solution**: How to implement
- **Example**: Code or command snippet
- **Discovered**: Date and task reference- Context: Creating new TypeScript modules
- Problem: Inconsistent export styles break imports
- Solution: Always use named exports with explicit types
- Example:
// Correct export function validateEmail(email: string): boolean { } export interface ValidationResult { valid: boolean; errors: string[] } // Avoid export default function() { } // Harder to refactor module.exports = { } // CommonJS mixing
- Discovered: Initial setup
- Context: Modifying prd.json or config files
- Problem: Partial writes can corrupt JSON
- Solution: Read → Modify in memory → Write complete file → Validate
- Example:
# Read, modify with jq, write atomically jq '.status = "completed"' prd.json > prd.json.tmp && mv prd.json.tmp prd.json
- Discovered: Initial setup
- Context: Before executing a task with dependencies
- Problem: Executing tasks with failed dependencies wastes cycles
- Solution: Check all dependencies recursively before starting
- Example:
# Verify all dependencies passed jq -e '.tasks[] | select(.id == 3) | .passes' prd.json > /dev/null
- Discovered: Initial setup
Add new patterns below this line as they are discovered.