Skip to content

Endpoint

POST /api/v2/hygiene

The hygiene endpoint runs an AI-powered agent that analyzes memory items and proposes cleanup actions. It operates in a safe two-phase workflow: first analyze, then apply selected actions.

Authentication

Supports Bearer token or session cookie authentication.

Request body

FieldTypeRequiredDescription
projectIdstringYesThe project ID
actionstringYes"analyze" or "apply"
modestringNo"quick" (20 items) or "weekly" (200 items). Default: "quick"
selectedActionIdsarrayConditionalRequired when action is "apply". Array of action IDs to execute
planobjectConditionalRequired when action is "apply". The plan object from the analyze phase

Phase 1: Analyze

Request the hygiene agent to analyze items and propose actions:

bash
curl -X POST https://contox.dev/api/v2/hygiene \
  -H "Authorization: Bearer contox_sk_yourkey" \
  -H "Content-Type: application/json" \
  -d '{
    "projectId": "proj_abc123",
    "action": "analyze",
    "mode": "quick"
  }'

Analysis response

json
{
  "planId": "plan_abc123",
  "itemsAnalyzed": 20,
  "actions": [
    {
      "id": "act_001",
      "type": "RENAME_TITLE",
      "itemId": "item_abc123",
      "description": "Rename 'auth stuff' to 'JWT Authentication Middleware'",
      "confidence": 0.92,
      "requiresHumanApproval": false,
      "before": "auth stuff",
      "after": "JWT Authentication Middleware"
    },
    {
      "id": "act_002",
      "type": "MERGE_MEMORIES",
      "itemIds": ["item_def456", "item_ghi789"],
      "description": "Merge duplicate items about database connection pooling",
      "confidence": 0.85,
      "requiresHumanApproval": true
    },
    {
      "id": "act_003",
      "type": "DEPRECATE_MEMORY",
      "itemId": "item_jkl012",
      "description": "Deprecate outdated reference to Express.js (project uses Hono)",
      "confidence": 0.88,
      "requiresHumanApproval": false
    }
  ]
}

Action types

ActionDescription
RENAME_TITLEImprove the title of a memory item for clarity
RETAGUpdate the type or schema key of an item
MERGE_MEMORIESCombine duplicate or overlapping items
DEPRECATE_MEMORYMark an outdated item as deprecated
REDACTRemove potentially sensitive information
FLAG_QUALITYFlag an item for manual review

Phase 2: Apply

After reviewing the proposed actions, apply the ones you approve:

bash
curl -X POST https://contox.dev/api/v2/hygiene \
  -H "Authorization: Bearer contox_sk_yourkey" \
  -H "Content-Type: application/json" \
  -d '{
    "projectId": "proj_abc123",
    "action": "apply",
    "selectedActionIds": ["act_001", "act_003"],
    "plan": { ... }
  }'

Apply response

json
{
  "applied": 2,
  "skipped": 1,
  "results": [
    { "actionId": "act_001", "status": "success" },
    { "actionId": "act_003", "status": "success" }
  ]
}

Safety guarantees

The hygiene agent is designed with safety as a priority:

  • Never auto-applies -- All actions must be explicitly approved
  • Confidence scores -- Each action includes a confidence score to help prioritize review
  • Human approval flag -- Actions with requiresHumanApproval: true indicate higher risk and should be reviewed carefully
  • Reversible -- Deprecated items can be re-approved; merged items retain source references

Modes

ModeItems analyzedUse case
quick20 most recentDaily maintenance
weeklyUp to 200 itemsPeriodic deep cleanup

Next steps