Skip to main content

Sync Endpoints

Endpoints for synchronizing memory between local and cloud storage.

Sync Architecture

Kernle uses a local-first sync model:
  1. All changes write to local SQLite first
  2. Changes queue for sync
  3. Push sends queued changes to cloud
  4. Pull retrieves remote changes
Conflict Resolution: Last-write-wins based on local_updated_at timestamp.

Get Sync Status

Check sync status and pending operations.
GET /sync/status

Headers

Authorization: Bearer sk-your-api-key

Query Parameters

ParameterTypeDescription
agent_idstringRequired. Agent identifier

Response

{
  "success": true,
  "data": {
    "agent_id": "claire",
    "pending_operations": 5,
    "last_push": "2024-01-15T10:30:00Z",
    "last_pull": "2024-01-15T10:25:00Z",
    "remote_changes_available": 3,
    "status": "connected"
  }
}

CLI Equivalent

kernle -a claire sync status

Push Changes

Push local changes to cloud.
POST /sync/push

Headers

Authorization: Bearer sk-your-api-key
Content-Type: application/json

Request Body

{
  "agent_id": "claire",
  "operations": [
    {
      "table": "episodes",
      "record_id": "ep_abc123",
      "operation": "upsert",
      "data": {
        "objective": "Debugged API issue",
        "outcome": "success",
        "outcome_type": "success",
        "lessons": ["Check logs first"],
        "created_at": "2024-01-15T10:30:00Z",
        "local_updated_at": "2024-01-15T10:30:00Z"
      }
    }
  ],
  "limit": 100
}

Response

{
  "success": true,
  "data": {
    "pushed": 5,
    "failed": 0,
    "remaining": 0,
    "results": [
      {
        "record_id": "ep_abc123",
        "status": "synced",
        "remote_id": "cloud_ep_abc123"
      }
    ]
  }
}

CLI Equivalent

kernle -a claire sync push

Pull Changes

Pull remote changes to local.
POST /sync/pull

Headers

Authorization: Bearer sk-your-api-key
Content-Type: application/json

Request Body

{
  "agent_id": "claire",
  "since": "2024-01-15T00:00:00Z",
  "full": false
}
FieldTypeDescription
agent_idstringRequired. Agent identifier
sinceISO timestampPull changes after this time (default: last pull time)
fullbooleanIf true, pull all records regardless of timestamp

Response

{
  "success": true,
  "data": {
    "pulled": 12,
    "tables": {
      "episodes": 5,
      "beliefs": 3,
      "notes": 4
    },
    "last_sync": "2024-01-15T10:30:00Z"
  }
}

CLI Equivalent

# Incremental pull
kernle -a claire sync pull

# Full pull
kernle -a claire sync pull --full

Full Sync

Perform bidirectional sync (pull then push).
POST /sync/full

Headers

Authorization: Bearer sk-your-api-key
Content-Type: application/json

Request Body

{
  "agent_id": "claire"
}

Response

{
  "success": true,
  "data": {
    "pull": {
      "records": 8,
      "tables": ["episodes", "beliefs"]
    },
    "push": {
      "records": 3,
      "tables": ["notes", "raw_entries"]
    },
    "conflicts_resolved": 0,
    "sync_completed_at": "2024-01-15T10:30:00Z"
  }
}

CLI Equivalent

kernle -a claire sync full

Supported Tables

The sync API supports these memory tables:
TableDescription
episodesAutobiographical experiences
beliefsSemantic knowledge with confidence
notesQuick captures (decisions, insights)
agent_valuesCore principles
goalsActive objectives
drivesIntrinsic motivations
relationshipsModels of other entities
playbooksProcedural memory
raw_entriesUnprocessed captures
checkpointsSaved state

Webhook Notifications (Coming Soon)

Configure webhooks to receive notifications when sync events occur:
{
  "webhook_url": "https://your-app.com/kernle-webhook",
  "events": ["sync.completed", "memory.created", "conflict.detected"]
}