Detect changes in the Clarive backend Public API and update the SDKs to match. Reads the backend source at ~/Clarive, compares with the current SDK models, errors, and API spec, then applies changes across C#, Python, and TypeScript. Use when the user says "sync the API", "update SDKs from backend", "API changed", "check for API drift", or "sync-api".
Read the Clarive backend source to detect Public API changes, then update the SDK models, error handling, and API spec document to match.
Parse $ARGUMENTS:
--dry-run: Report what changed without modifying any files. Remove flag before parsing rest.csharp, python, typescript (space-separated). If omitted, sync all three.The Clarive Public API contract is defined by these files in ~/Clarive/src/backend/Clarive.Api/:
| What | File |
|---|---|
| Endpoints (routes, handlers) | Endpoints/PublicApiEndpoints.cs |
| Response: PromptEntry |
Models/Responses/PublicPromptEntry.cs |
| Response: GenerateResponse | Models/Responses/PublicGenerateResponse.cs |
| Response: Error | Models/Responses/ErrorResponse.cs |
| Request: Generate | Models/Requests/PublicGenerateRequest.cs |
| Entity: TemplateField | Models/Entities/TemplateField.cs |
| Enum: TemplateFieldType | Models/Enums/TemplateFieldType.cs |
| Error codes | Helpers/DomainErrors.cs |
| Field validation | Helpers/TemplateFieldValidator.cs |
| Template rendering | Services/TemplateParser.cs |
| Auth handler | Auth/ApiKeyAuthHandler.cs |
| Rate limiting | Program.cs (search for AddPolicy("auth") |
Read ALL the backend files listed above. From each, extract:
ctx.ErrorResult(401, "UNAUTHORIZED", ...))PublicApiEndpoints.cs and EntryService.GetPublishedEntryAsyncFor each SDK being synced, read the corresponding files:
sdks/csharp/src/ClariveSDK/):Models/PromptEntry.cs, Models/Prompt.cs, Models/TemplateField.csModels/GenerateRequest.cs, Models/GenerateResponse.cs, Models/RenderedPrompt.csExceptions/ClariveApiException.cs (the FromApiError switch statement)sdks/python/src/clarive/):models.py — all dataclass definitions and from_dict() methodsexceptions.py — the from_response() match statementsdks/typescript/src/):models.ts — all interface definitionserrors.ts — the fromResponse() switch statementAlso read:
CLARIVE_PUBLIC_API.md — the API spec document at the repo rootCompare backend vs SDK state. Check for drift in these categories:
For each response/request type, compare:
string → int, nullable → required)Map property names between languages:
SystemMessage → SystemMessage / system_message / systemMessageCompare the set of error codes in the backend's DomainErrors.cs and inline usage
with the SDK error factories:
PublicApiEndpoints.csPresent a clear summary of all detected drift:
## API Sync Report
### Model Changes
| Change | Backend | C# SDK | Python SDK | TypeScript SDK |
|--------|---------|--------|------------|----------------|
| Added field `Foo` on `PromptEntry` | ✓ | Missing | Missing | Missing |
| ...
### Error Code Changes
| Code | Backend Status | SDK Status |
|------|----------------|------------|
| NEW_CODE | 404 (new) | Not mapped |
| ...
### Endpoint Changes
- (none, or list)
### Validation Changes
- (none, or list)
### No Changes Detected
- (list categories with no drift)
If --dry-run: Stop here. Report what would change without modifying anything.
For each detected drift, apply the fix to all selected SDKs:
from_dict() mapping
(camelCase key → snake_case field). Maintain frozen=True, slots=True.FromApiError switch in ClariveApiException.cs.
If it maps to an existing exception type (e.g. another 404 variant), add it to
that case's or pattern. If it needs a new exception class, create one.from_response() match in exceptions.py.
Use | for multiple codes mapping to the same exception.fromResponse() switch in errors.ts.
Use fallthrough for multiple codes mapping to the same class.For any change detected, update the API spec document to match the current backend state. This is the source-of-truth document for SDK consumers.
For each SDK that was modified:
cd sdks/csharp && dotnet testcd sdks/python && uv run pytestcd sdks/typescript && npx vitest runIf tests fail, fix the issue before proceeding.
Run language-specific checks:
uv run ruff check src/ tests/ && uv run mypy --strict src/npx biome check src/ tests/ && npx tsc --noEmitdotnet build (warnings are errors)Fix any issues found.
## Sync Complete
### Changes Applied
- {description of each change}
### Files Modified
| SDK | Files |
|-----|-------|
| C# | {list} |
| Python | {list} |
| TypeScript | {list} |
| API Spec | CLARIVE_PUBLIC_API.md |
### Tests
- C#: {N} passed
- Python: {N} passed
- TypeScript: {N} passed
### Next Steps
- Review the changes: `git diff`
- Commit: `git add -A && git commit -m "chore: sync SDKs with backend API changes"`
- Release: `/release {version}`
Do NOT commit automatically. Let the user review the diff first.
~/Clarive/ — the backend is read-only from this repo's perspective