Skip to content

API Reference

http://127.0.0.1:8787

All endpoints (except /status) require token authentication via the X-Agent-Token header:

X-Agent-Token: your-token-here

If no token is configured on the server, authentication is disabled.


Server status check. No authentication required.

Response 200 OK

{
"ok": true,
"pending_count": 3,
"denied_count": 1,
"token_required": true,
"version": "0.1.0"
}

Detailed health information with system metrics.

Response 200 OK

{
"status": "healthy",
"uptime_seconds": 3621.4,
"memory_mb": 42.7,
"pending_count": 3,
"runs_count": 15,
"timestamp": "2025-01-15T14:30:22"
}

Queue a command for human approval.

Request Body

FieldTypeRequiredDefaultDescription
commandstringYesPowerShell command (1-10,000 chars)
cwdstring|nullNonullWorking directory (max 500 chars)
timeout_sintegerNo300Timeout in seconds (1-3600)
notestring|nullNonullOptional note (max 1000 chars)

Example Request

Terminal window
curl -X POST http://127.0.0.1:8787/plan \
-H "X-Agent-Token: your-token" \
-H "Content-Type: application/json" \
-d '{"command": "Get-Process python", "note": "checking processes"}'

Response 200 OK

{
"pending_id": "20250115_143022_a1b2c3d4",
"queued": true,
"command": "Get-Process python"
}

Errors

  • 401 — Invalid or missing token
  • 422 — Validation error (command too long, invalid timeout, etc.)
  • 429 — Rate limit exceeded

List pending commands awaiting approval. Returns newest first.

Query Parameters

ParameterTypeDefaultDescription
limitinteger50Maximum items to return

Response 200 OK

[
{
"command": "Get-Process python",
"cwd": null,
"timeout_s": 300,
"note": "checking processes",
"pending_id": "20250115_143022_a1b2c3d4",
"ts": 1705329022.123,
"queued_at": "2025-01-15T14:30:22"
}
]

Approve and execute a pending command.

Path Parameters

ParameterTypeDescription
pending_idstringThe pending command ID

Response 200 OK

{
"run_id": "20250115_143122_e5f6g7h8",
"cwd": "C:\\provara",
"command": "Get-Process python",
"exit_code": 0,
"stdout": "Handles NPM(K) ...",
"stderr": "",
"ts": 1705329082.456,
"duration_ms": 142.5
}

Errors

  • 401 — Invalid or missing token
  • 403 — Command blocked by policy (includes reason and command in detail)
  • 404 — Pending command not found

403 Response Example

{
"detail": {
"error": "policy_blocked",
"reason": "deny:\\b(Remove-Item|del\\s|erase",
"command": "Remove-Item C:\\Windows\\System32",
"cwd": null
}
}

Deny a pending command. Moves it to the denied archive.

Response 200 OK

{
"pending_id": "20250115_143022_a1b2c3d4",
"denied": true
}

Errors

  • 401 — Invalid or missing token
  • 404 — Pending command not found

Get recent command execution history.

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Maximum items to return

Response 200 OK

[
{
"run_id": "20250115_143122_e5f6g7h8",
"cwd": "C:\\provara",
"command": "Get-Process python",
"exit_code": 0,
"stdout": "...",
"stderr": "",
"ts": 1705329082.456,
"duration_ms": 142.5
}
]

Get a specific command execution record.

Response 200 OK — Same schema as individual items in /runs

Errors

  • 404 — Run not found

Server-Sent Events endpoint for real-time notifications.

Event Types

EventEmitted When
run_startedCommand execution begins
run_finishedCommand execution completes

Example Event

data: {"type": "run_started", "run_id": "...", "ts": 1705329082.456, "command": "whoami", "cwd": "C:\\provara"}
data: {"type": "run_finished", "run_id": "...", "ts": 1705329082.598, "exit_code": 0, "stdout": "...", "stderr": ""}

Usage (JavaScript)

const events = new EventSource(
'http://127.0.0.1:8787/events',
{ headers: { 'X-Agent-Token': token } }
);
events.onmessage = (e) => {
const event = JSON.parse(e.data);
console.log(event.type, event.run_id);
};

Read a file from the project directory.

Request Body

FieldTypeDescription
pathstringRelative or absolute path

Response 200 OK

{
"path": "C:\\provara\\README.md",
"content": "# Provara\n...",
"size": 1234,
"exists": true,
"error": null
}

Write a file to the project directory.

Request Body

FieldTypeDefaultDescription
pathstringRelative or absolute path
contentstringFile content
create_dirsbooleanfalseCreate parent directories

List files in a directory under the project root.

Query Parameters

ParameterTypeDefaultDescription
pathstring.Directory path
patternstring*Glob pattern

Response 200 OK

{
"path": "C:\\provara",
"files": [
{ "name": "README.md", "path": "...", "is_dir": false, "size": 1234 },
{ "name": "src", "path": "...", "is_dir": true, "size": null }
]
}

All errors follow this format:

{
"error": "Error type",
"detail": "Human-readable description"
}
StatusMeaning
401Authentication failed
403Blocked by policy or path restriction
404Resource not found
422Validation error
429Rate limit exceeded
500Internal server error

The API enforces per-client rate limiting:

  • Default: 100 requests per 60-second window
  • 429 Response:
{
"error": "Rate limit exceeded",
"retry_after_seconds": 60
}

The server allows cross-origin requests only from localhost:

allow_origin_regex=r"^https?://(localhost|127\.0\.0\.1)(:\d+)?$"