Skip to main content

Module computers

Module computers 

Source
Expand description

LeanCTX Cloud computers (/v1/computers, cloud design cloud-computer.md §4.3): list, create, start and stop the computers of the person and of their teams, for lean-ctx cloud computer … and LeanCTX Code.

The cloud enforces who may create or start a computer, its role, the free hours, the balance and the trial; this module only passes the request on and hands back what the cloud answered:

  • 200/201/202 with a row (or {computers: […]}) → Answer::Done;
  • an error with a code (402 balance_empty, 402 plan_required, 403 forbidden, 404 no_computer, 409 computer_exists, 409 computer_busy, 400/422 invalid_request, 429, 428 confirmation_required, 503 computer_provider_unavailable, 503 computer_not_available) → Answer::Refused, with the cloud’s own message and error.details;
  • 404 without a code, or 503 not_configured, from a cloud that does not offer computers, and a list 200 {available: false} (no provider yet) → Answer::NotOffered.

A create or a start costs money, so the CLI sends one only after the person confirmed the terms (--yes), and always with confirm: true. A cloud that still wants a confirmation answers 428 confirmation_required with the terms in error.details ({billing: free|billed, usd_per_hour, free_hours_left, topup_usd}, read with terms) and does nothing: a second guard.

Every exchange goes through an Exchange: connected for the connected instance (the session refreshes a refused token), on_client for one CloudClient.

No code and no file content is ever sent: the bodies carry only the request id, the name, the role, the team and the confirmation.

Structs§

ComputerList
GET /v1/computers, checked.
CreateRequest
POST /v1/computers body ({ request_id, name, team?, role, confirm }). The cloud picks size and region and does not stop an idle computer, so the CLI offers no size, region or idle stop: a computer runs, and is billed, until it is stopped.
Refusal
The cloud refused the request; passed on as it said it.
RunStartRequest
POST /v1/computers/{id}/start body for lean-ctx run --cloud (contract §35). A run is billed from the first minute (free hours are only for weave_host), so this body exists only after the person confirmed the terms (--yes, or yes at the prompt): confirm is always true. Carries no code, no task text, no file content.
Terms
The terms of a billable write, from a 428 confirmation_required (error.details): one shape for the cloud, the CLI and LeanCTX Code.

Enums§

Answer
What the cloud said.
Transition
A start or a stop.

Constants§

MAX_ROWS
Most rows kept from a list.
ROLES
The roles a computer is created with; fixed at create.
ROLE_GENERAL
The role of any other computer; the only one for a personal account.
ROLE_WEAVE_HOST
The role the free Team hours apply to (owner, 18.11.).

Functions§

connected
The exchanges of the connected instance: each one through its session, which refreshes a refused token.
create
POST /v1/computers: the new row (provisioning).
list
GET /v1/computers.
new_request_id
A fresh request id: a retry of the same command passes it again with --request-id, and the cloud answers the first answer.
on_client
The exchanges on client.
run_terms
The terms of a run on computer row, from the list row alone (no request to the cloud): billed from the first minute, at the row’s price (else its balance’s), with what is left of the top-up as listed (topup_usd). purpose: "run" is always billed: the free hours are a team’s weave_host’s, never a run’s. A malformed value is None, never a guess.
start_basis
Who pays a start, from the row the cloud answered (§3.3), in the words of Terms::billing: a team’s weave_host computer with free hours left starts on them (free); a personal computer never does (the free hours are the team’s) and a general one never does: they are billed (paid from the top-up). A team’s weave_host whose row carries no readable balance.free_hours_left is None: unknown, never guessed. The cloud decides; this only names it.
start_for_run
POST /v1/computers/{id}/start for a confirmed run (see RunStartRequest): the row (starting, or running when it already ran), or the cloud’s refusal.
terms
The terms in details; anything malformed is None, never a guess.
transition
POST /v1/computers/{id}/start or /stop: the row (starting or stopping). confirm (start only) as in CreateRequest::confirm.
valid_id
A computer id as the cloud sends it (cmp_…), safe in a path.
valid_request_id
A request id the cloud accepts: 8-64 of A-Z a-z 0-9 _ -.

Type Aliases§

Exchange
One exchange with the cloud: method, path (under /v1) and body → the HTTP status and the JSON answer.