Skip to main content

Typebar over REST (curl): one command per job

Each shell command costs you a model turn, so do a whole job in ONE command: every instruction in one message, targets named by section and content. Never open, read, grep or diff the documents yourself. Every curl has --max-time. Never re-send a POST that timed out (it bills a second job): re-run only the GET wait. Never use pkill, killall or kill.

Key (once)

Reuse ~/.superdocs/agent_credentials.json if it exists. Otherwise sign up, which accepts the Terms (typebar.ai/terms): only if the user’s instruction says so; otherwise ask the user first.

Edit a file: one command

Create from sources: add A=(); while IFS= read -r f; do A+=(-F "sources=@\"$f\""); done < <(find ./data ./context -type f ! -path '*/.*' 2>/dev/null) before the curl and replace -F "file=@\"./INPUT.docx\"" with "${A[@]}"; the message is the brief. (Keep the \"…\": unquoted, curl reads ; and , as options.)

The reply

  • response: what was done per ask. download: a 15-minute link (-F export_format=pdf for PDF).
  • HTTP 202 or a timeout: still running. Run ONE wait (again on another 202) with the printed session:
    Then the same python3 and read U N lines. The wait also re-lists held lines; guess no other endpoint.
  • [edited: false] printed: nothing was edited; run the edit command again (a new session). Any other failure may have edited: give the user its response before sending again.
  • HELD lines (requires_approval): nothing from this turn is applied yet; the saved OUTPUT-before-this-turn.docx predates it (a held create has none: see download.error).
    • requires_review lines need the user’s own go; never approve one without it. If you can ask, ask BEFORE the approve call; put the ids they approve in OK (space-separated). If you cannot ask and every line is requires_review, stop: give the user the held lines and that one decision.
    • A note saying it could not be verified, or goes beyond the request: deny it (id in NO), finish, then re-ask that change alone: the edit command on OUTPUT.docx, quoting verbatim from the document (the one exception) the exact text to keep or the anchor. Never stop without the final file.
    • Otherwise approve in ONE call, then wait and download. Lines it does not name are declined: never applied, never approvable later. Until held lines are decided, a new chat answers 409.
    Then the same two lines. Tell the user which held changes were NOT applied, naming each (they can ask again).
    • STILL HELD ids need their own call and the user’s go: for each they approved, POST {"job_id": J, "change_id": ID, "approved": true} the same way, then wait; name the rest to the user. Never wait on a held job without deciding. APPROVE FAILED: do what its message says.
  • Follow-up: POST $API/v1/chat, JSON: same session_id, message, "response_mode": "summary", "export_format": "docx".
  • Undo: POST $API/v1/sessions/$SID/revert with {"turn_index": N, "response_mode": "summary"} (N from the reply). Redo (right after an undo): POST $API/v1/sessions/$SID/redo with {"turn_index": N, "redo_checkpoint_id": "ID", "response_mode": "summary"} (ID from the undo reply).