agentleFS
mkalkeremkalkere/agent-coordinator/.claude/CLAUDE.md

agent-coordinator

CLAUDE.md4 starsChanged 9 months agoMITView on GitHub

CANONICAL SOURCE: Master instructions for all AI coding agents. Maintenance: Update only when fundamental patterns change. Read these files when: - You seem confused about what you're working on - User asks "what were we doing?" or "continue" - Starting significant new work Performance: conftest.py caches schema DDL — migrations run ONCE per session. Do NOT add init_database() to test fixtures — _isolate_db autouse fixture handles it. Gotcha: sqlite3.Row has no .get() method. Use row["column"] not row.get("column"). 17 routers extracted.…

  • Reads credentials

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

26 rules. About 0 are common, 14 are distinctive, and 12 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 12

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    NEVER commit directly to main: - ALL changes require feature branches and PRs

    line 34
  2. Very specific:

    Do NOT add init_database() to test fixtures — _isolate_db autouse fixture handles it.

    line 68
  3. Distinctive:

    Every agent follows this protocol on every session.

    line 172
  4. Distinctive:

    If unreachable, warn the user and continue without coordination.

    line 180
  5. Distinctive:

    Never crash on coordinator being unavailable.

    line 181
  6. Very specific:

    Register: If you are running inside the agent wrapper (you'll see [wrapper] in your system prompt), registration is handled automatically — …

    line 183
  7. Distinctive:

    If running standalone (no wrapper), register yourself:

    line 185
  8. Very specific:

    After completing a significant deliverable, notify relevant agents via POST /messages.

    line 206
  9. Distinctive:

    Check for new messages periodically during long sessions.

    line 207
  10. Very specific:

    If running inside the wrapper ([wrapper] in system prompt), session cleanup is handled automatically — do NOT send a sleeping heartbeat …

    line 211
  11. Very specific:

    If running standalone: POST /agents/{your-id}/heartbeat with {"status": "sleeping"}

    line 213
  12. Very specific:

    Use your publishes list from identity.yaml as guidance for what you announce.

    line 217
  13. Distinctive:

    When you need to message someone but don't know who:

    line 241
  14. Very specific:

    Check each agent's capabilities for relevant skills

    line 243
  15. Distinctive:

    If coordinator is unavailable:

    line 248
  16. Very specific:

    When you are launched as an autonomous agent (via the coordinator or work-on-issue skill), follow these instructions to understand who you …

    line 282
  17. Very specific:

    Do NOT read all skills at once.

    line 304
  18. Very specific:

    How: Write YAML or markdown files.

    line 313
  19. Distinctive:

    When: After completing significant work, after learning something important, before session ends

    line 314
  20. Distinctive:

    Commit with code: When you commit code changes, include your memory files in the same commit

    line 315
  21. Distinctive:

    When assigned a task for a repository you don't have locally:

    line 340
  22. Distinctive:

    Check if the repo exists in your workspace area

    line 342
  23. Very specific:

    If not, clone it: git clone <repo-url> <workspace-path>

    line 343
  24. Very specific:

    If yes, pull latest: cd <workspace-path> && git checkout main && git pull

    line 344
  25. Distinctive:

    NO GitHub Actions changes without approval

    line 364
  26. Distinctive:

    NO secrets in commits

    line 365

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Agent Coordinator AI Instructions

CANONICAL SOURCE: Master instructions for all AI coding agents. Maintenance: Update only when fundamental patterns change.


Context Restoration (When Lost or Uncertain)

Read these files when:

  • You seem confused about what you're working on
  • User asks "what were we doing?" or "continue"
  • Starting significant new work
FilePurposeWhen to Read
.claude/memory/PROJECT_CONTEXT.mdWhat is Agent Coordinator?When unfamiliar with project

Context Anchors (Verify BEFORE Every Task)

1. Port Allocation (CRITICAL)

  • Agent Coordinator runs on port 9889
  • SQLite database at data/coordination.db - no separate DB port needed
  • Standalone Python process - NOT in Docker

2. Atomic Operations (CRITICAL)

  • Task claiming uses INSERT...SELECT for atomicity
  • File locks use leases that auto-expire
  • Database operations use SQLite with WAL mode for concurrent reads

3. Branch Policy (NO EXCEPTIONS)

  • NEVER commit directly to main - ALL changes require feature branches and PRs
  • Feature branches: feat/description
  • Fix branches: fix/description

Quick Commands (WSL/Linux)

# Start server
AC_DB_PATH=$HOME/agent-coordinator-data/coordination.db \
PYTHONPATH=src python3 -m uvicorn agent_os.server.main:app --host 0.0.0.0 --port 9889

# Run tests (use python3, NOT py)
PYTHONPATH=src python3 -m pytest tests/ -v

# Run single test file (fast — cached schema DDL)
PYTHONPATH=src python3 -m pytest tests/test_server.py -v --timeout=30

# Health check
curl http://localhost:9889/health

Testing

PYTHONPATH=src python3 -m pytest tests/ -v              # All tests
PYTHONPATH=src python3 -m pytest tests/test_server.py -v # Single file (~3s)
PYTHONPATH=src python3 -m pytest tests/ -k "health" -v   # By keyword

Performance: conftest.py caches schema DDL — migrations run ONCE per session. Do NOT add init_database() to test fixtures — _isolate_db autouse fixture handles it.

Gotcha: sqlite3.Row has no .get() method. Use row["column"] not row.get("column").


Before Committing

  1. Tests pass: PYTHONPATH=src python3 -m pytest tests/test_server.py --timeout=30
  2. Pre-commit hooks: pre-commit run --all-files
  3. NO git add . — use specific files
  4. Conventional Commits: type(scope): summary
  5. Review every PR before merging

Architecture Note

17 routers extracted. Only 9 system endpoints in main.py. Roadmap: .claude/docs/ROADMAP-v1.md


API Overview

Agent Management

EndpointMethodDescription
/agents/registerPOSTRegister at session start
/agents/{id}/heartbeatPOSTUpdate status (every 15 min)
/agentsGETList all agents
/agents/{id}DELETEMark offline at session end

Task Management

EndpointMethodDescription
/tasks/claimPOSTAtomically claim an issue
/tasks/{id}/releasePOSTGive up a claimed task
/tasks/{id}/completePOSTMark task done
/tasksGETList all tasks

File Locks

EndpointMethodDescription
/locks/acquirePOSTGet lock with lease
/locks/{id}/renewPOSTExtend lease
/locks/{id}DELETERelease lock
/locksGETList all locks

Messages

EndpointMethodDescription
/messagesPOSTSend message
/messages/{agent_id}GETGet your messages
/messages/{id}/ackPOSTAcknowledge message

Advanced Features

EndpointMethodDescription
/tasks/auctionPOSTCreate task auction
/decisionsPOSTCreate decision vote
/standup/todayGETGet daily standup
/activityGETActivity feed

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Agent Coordinator                         │
│                   localhost:9889                             │
├─────────────────────────────────────────────────────────────┤
│  FastAPI Server                                              │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │   Agents    │  │    Tasks    │  │    Locks    │         │
│  │ Management  │  │  Claiming   │  │   Leases    │         │
│  └─────────────┘  └─────────────┘  └─────────────┘         │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │  Messages   │  │  Auctions   │  │  Decisions  │         │
│  │   Queue     │  │   Bidding   │  │   Voting    │         │
│  └─────────────┘  └─────────────┘  └─────────────┘         │
├─────────────────────────────────────────────────────────────┤
│  SQLite Database (data/coordination.db)                      │
│  - WAL mode for concurrent reads                             │
│  - Background log worker for non-blocking audit              │
└─────────────────────────────────────────────────────────────┘

Health Monitoring

The server automatically monitors agent health:

ThresholdStatusAction
30+ min no heartbeatSTALELog warning
60+ min no heartbeatDEADRelease all locks and tasks
2+ hours no heartbeatOFFLINEMark agent offline (resources already released at DEAD)

Coordinator Protocol (MANDATORY for all agents)

Every agent follows this protocol on every session. It is generic — not tied to any specific role or workflow.

Session Start (before any work)

  1. Read your identity: Load .os/agents/{your-name}/identity.yaml for your agent ID, skills, and message subscriptions (listens_to / publishes).
  2. Check coordinator: GET ${AC_COORDINATOR_URL:-http://localhost:9889}/health
    • If unreachable, warn the user and continue without coordination.
    • Never crash on coordinator being unavailable.
  3. Register: If you are running inside the agent wrapper (you'll see [wrapper] in your system prompt), registration is handled automatically — do NOT register again. If running standalone (no wrapper), register yourself:
    POST /agents/register
    {
      "id": "<name from identity.yaml>",
      "workspace": "<cwd>",
      "capabilities": ["<skill categories from identity.yaml, e.g. 'development', 'review'>"]
    }
    Capabilities are the category prefixes of your skills (the part before /). For example, skill review/pr-review → capability review.
  4. Check messages: GET /messages/{your-id}?unread_only=true
    • Process any pending messages before starting new work.
    • Acknowledge each: POST /messages/{msg-id}/ack?agent_id={your-id}
  5. Discover peers: GET /agents
    • Know who else is registered and available.

During Work

  • After completing a significant deliverable, notify relevant agents via POST /messages.
  • Check for new messages periodically during long sessions.

Session End

  • If running inside the wrapper ([wrapper] in system prompt), session cleanup is handled automatically — do NOT send a sleeping heartbeat yourself.
  • If running standalone: POST /agents/{your-id}/heartbeat with {"status": "sleeping"}

Sending Messages

Use your publishes list from identity.yaml as guidance for what you announce. Address messages to specific agents or all for broadcast.

POST /messages
{
  "from_agent": "<your-id>",
  "to_agent": "<target-id or 'all'>",
  "type": "<info|request|status|alert>",
  "priority": "<low|normal|high|urgent>",
  "subject": "<concise summary>",
  "body": "<details>",
  "requires_ack": true
}

Priority guidelines:

  • urgent — blocked, need immediate help
  • high — deliverable ready, review needed, fix needed
  • normal — status update, question, FYI
  • low — informational, non-blocking

Agent Discovery

When you need to message someone but don't know who:

  1. GET /agents — list all registered agents
  2. Check each agent's capabilities for relevant skills
  3. Send to the most appropriate agent, or broadcast to all if unclear

Graceful Degradation

If coordinator is unavailable:

  • Warn the user, continue working normally
  • PRs and commits still work (git doesn't need the coordinator)
  • Note needs in deliverables (e.g., PR description says "needs review")

Helper Scripts

# Check if coordinator is running
.\scripts\coordinator-check.ps1

# Register + check messages in one step
.\scripts\agent-checkin.ps1 <agent-id> [workspace]
# Check if coordinator is running
./scripts/coordinator-check.sh

# Register + check messages in one step
./scripts/agent-checkin.sh <agent-id> [workspace]

Environment Variables

VariableDefaultPurpose
AC_COORDINATOR_URLhttp://localhost:9889Coordinator base URL
AC_API_KEY(from .os/config.yaml)API authentication key

Agent Operating Instructions (for CLI Agents)

When you are launched as an autonomous agent (via the coordinator or work-on-issue skill), follow these instructions to understand who you are and what you can do.

Know Yourself

On session start, read these files to understand your identity and purpose:

FileWhat It ContainsWhen to Read
.os/agents/{your-name}/identity.yamlYour name, skills list, provider config, message subscriptionsAlways — first thing
.os/agents/{your-name}/SOUL.mdYour personality, values, working styleAlways — shapes how you work
.os/agents/{your-name}/state.jsonYour current status, level, XPWhen resuming work (created on first run)

Your agent name is provided in the first prompt you receive. Use it to locate your files.

Know Your Skills

Your skills are listed in identity.yaml under the skills key. Each skill has documentation:

  • Skill instructions: .os/skills/{category}/{skill-name}/SKILL.md — read when you need to use that skill
  • Tool schema: .os/skills/{category}/{skill-name}/tool.yaml — defines inputs/outputs for the skill's tools

Do NOT read all skills at once. Read a skill's SKILL.md when you need it for the current task. For example, when assigned a development task, read .os/skills/development/work-on-issue/SKILL.md.

Save Your Learnings

As you work, save what you learn to persist across sessions:

  • Where: .os/agents/{your-name}/memory/ directory
  • What to save: Domain knowledge about the codebase, patterns that worked or failed, decisions and their reasoning, gotchas you encountered
  • How: Write YAML or markdown files. Use descriptive names (e.g., codebase-patterns.md, api-gotchas.md)
  • When: After completing significant work, after learning something important, before session ends
  • Commit with code: When you commit code changes, include your memory files in the same commit

Memory types:

  • Episodic: What happened — "Fixed auth bug by changing token validation in middleware"
  • Semantic: Facts about the codebase — "The API uses FastAPI with SQLite WAL mode on port 9889"
  • Procedural: How-to knowledge — "To run tests: py -m pytest tests/ -v"

Save Context Periodically

Long sessions may lose early context due to context window limits. Protect against this:

  1. Every 15-20 minutes (or after completing a significant step), save your working context:
    • What you're currently working on
    • What you've done so far
    • What's left to do
    • Key decisions made and why
  2. Where: .os/agents/{your-name}/context/working.yaml
  3. Keep it concise — this is a checkpoint, not a full log

Session Auto-Restart

Sessions automatically restart when you exhaust your context window (CLI: up to 3 times, API: up to 2 times by default). On restart, you'll receive a continuation prompt telling you to read your memory files and continue. Your memory files at .os/agents/{your-name}/memory/ persist across restarts — use them to save progress. Commit early and often to prevent lost work.

Workspace Management

When assigned a task for a repository you don't have locally:

  1. Check if the repo exists in your workspace area
  2. If not, clone it: git clone <repo-url> <workspace-path>
  3. If yes, pull latest: cd <workspace-path> && git checkout main && git pull
  4. Work in the cloned repo, not in the coordinator's directory

Each agent should have its own workspace clone to prevent conflicts with other agents.


Detailed Documentation (Load on Demand)

TopicFile
API Reference@.claude/docs/api-reference.md
Coordinator Wiring Spec@.claude/docs/phase-c-coordinator-wiring-spec.md
Architecture Decision: SQLite@.claude/decisions/001-sqlite-over-postgres.md
Architecture Decision: Idle Ping@.claude/decisions/002-idle-ping-across-paths.md

Constraints

  • NO GitHub Actions changes without approval
  • NO secrets in commits
  • Stage files carefully - no git add .

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.