Core Components

Agent Mail: Agent Coordination

Advisory file reservations, hard leases, message threading, and intent broadcasting. Agents coordinate through data — conflicts are information, not errors.

Message Types

TypeDescription
task.help_neededAgent needs help with a task
task.handoffAgent hands off a task to another
task.claimedAgent claimed a task
task.completedTask finished successfully
task.failedTask execution failed
task.progressTask progress update
task.files_changedAgent reports files modified during task
task.file_conflictFile reservation conflict detected
file.lock_requestRequest exclusive file lock
file.lock_grantedFile lock granted
file.lock_deniedFile lock denied
coordination.syncCoordination sync between agents
info.discoveryInformation discovery broadcast
agent.startedAgent came online
agent.stoppedAgent went offline
agent.intent.announceAgent announces intent (files it will touch)
agent.intent.completeAgent completed announced intent
agent.workspace.declareAgent declares workspace/files it will touch
reservation.conflictFile reservation conflict detected
reservation.releasedFile reservation released
system.shutdownSystem shutdown signal
customCustom user-defined message type

Message API

import { createLibSQLLocalDataLayer } from '@jetpack-agent/data';

const dataLayer = await createLibSQLLocalDataLayer('.jetpack/jetpack.db');

// Broadcast a message to all agents
await dataLayer.messages.broadcast(
  'task.files_changed',
  agentId,
  { files: ['src/auth.ts', 'src/middleware.ts'] }
);

// Send a message to a specific agent
await dataLayer.messages.send(
  'task.file_conflict',
  fromAgentId,
  toAgentId,
  { filePath: 'src/auth.ts', conflictingAgent: 'agent-2' }
);

// Receive messages for an agent
const messages = await dataLayer.messages.receive(agentId);

Dual Coordination Model

Jetpack uses two coordination mechanisms: advisory file reservations (non-blocking, conflicts as data) and hard leases (exclusive locks for critical sections). AgentHarness uses both — hard leases for atomic task claiming and advisory reservations for file coordination.

Advisory File Reservations

Multiple agents can reserve the same file. Conflicts surface as data — agents see who else is working nearby and can coordinate. Enforcement is optional via a pre-commit Git hook.

Agent-1 wants to edit Button.tsx
    │
    ▼
reserve({ agentId, taskId, filePath, reservationType: 'edit' })
    │
    ├─► Insert reservation into file_reservations table
    ├─► Check for other active reservations on same file
    │      └─► If conflicts exist: RETURN { granted: true, conflicts: [...] }
    │      └─► If no conflicts: RETURN { granted: true, conflicts: [] }
    │
    │  (Note: Reservation is ALWAYS granted — conflicts are advisory)
    │
Agent-1 edits file, sees Agent-2 also working on it
    │
    ▼
releaseAll(agentId)  // Release all reservations for this agent

Hard Leases

For exclusive access (e.g., atomic task claiming), AgentHarness uses hard leases via dataLayer.leases.acquire() and dataLayer.leases.release().

Reservation API

// Reserve a file (always succeeds — advisory model)
const grant = await dataLayer.reservations.reserve({
  agentId: 'agent-1',
  taskId: 'task-1',
  filePath: 'src/auth.ts',
  reservationType: 'edit',  // 'edit' | 'read' | 'create' | 'delete'
});
// Returns: { granted: true, reservationId, conflicts: [...] }

// Check conflicts for multiple files at once
const conflicts = await dataLayer.reservations.checkConflictsBatch(
  ['src/auth.ts', 'src/middleware.ts'],
  'agent-1'
);

// Release all reservations for an agent
await dataLayer.reservations.releaseAll('agent-1');

// Cleanup old reservations (older than specified ms)
await dataLayer.reservations.cleanup(3600000); // 1 hour

Message Threading

// Messages can be organized into threads
const thread = await dataLayer.messages.getThread(threadId);

Git Hook Enforcement

# Install optional pre-commit hook
jetpack hook install

# Manually check reservation conflicts
jetpack check-reservations

Advisory Reservations vs Hard Leases

FeatureAdvisory ReservationsHard Leases
BlockingNever — always grantedExclusive — acquire can fail
ConflictsReturned as data arrayPrevents concurrent access
Use caseFile coordination between agentsAtomic task claiming
Cleanupcleanup(olderThanMs)Auto-expires via TTL
EnforcementOptional (pre-commit Git hook)Always enforced