日本語 · English(未訳)

kairos-lang-http

決めたら、いつでも。
Write the rule once; list the dates.

A self-hosted HTTP shell for Kairos, the schedule definition language (https://kairos-lang.org). It takes a definition and a range as JSON and returns the reference implementation’s result as is. It keeps no state.

日本語: README.ja.md

Run

Node.js 20 or later. The shell is not published to npm or GHCR yet; build it from the repository.

git clone https://github.com/azathothx/kairos-lang.git
cd kairos-lang/http
npm ci && npm run build
node dist/bin.js                     # listen on :8080
node dist/bin.js --version
PORT=3000 node dist/bin.js

Docker (in the same http/ directory; build dist first):

npm ci && npm run build && docker build -t kairos-lang-http .
docker run --rm -p 8080:8080 kairos-lang-http
curl -s localhost:8080/v1/list -H 'Content-Type: application/json' -d '{
  "source": "premise P { calendar-system: Gregorian; tz: \"Asia/Tokyo\"; wkst: Mon }\n@P\neveryDay |> within(month) |> last\n",
  "from": "2026-01-01", "to": "2026-04-01", "tz": "Asia/Tokyo"
}'

Interface

Method and path Input (JSON body) Output
POST /v1/list source, from, to, tz, supply?, explain? The CliReport for [from, to) (every firing, interval annotations, coverage summary)
POST /v1/next source, tz, from? (default: today in tz), n? (default 1), horizonYears? (default 10), supply?, explain? The CliReport for the next n firings
POST /v1/validate source, tz {ok, version, diagnostics: [{kind, message}], expressions} (same as MCP kairos_validate)
GET /v1/version none {"kairosLang": "<evaluator version>", "shell": "<shell version>"}
GET /healthz none {"ok": true}

Limits and errors

Limits (accident prevention; the values match kairos-lang-mcp):

Item Limit
source 64 KiB
Evaluation window (to − from) 10 years
n 1000
horizonYears 10
Body expressions per source 100
Body 256 KiB
Response body 32 MiB
Concurrency (evaluation routes) KAIROS_HTTP_MAX_CONCURRENCY (default 4)
Evaluation time per request KAIROS_HTTP_TIMEOUT_MS (default 10 s)

Error bodies are the CLI --json error surface {command, version, error: {kind, message}}.

Status When Body
400 usage (invalid tz, non-existent date, window / n / expression count over the limit, missing field, wrong type, unknown key, malformed JSON, response over 32 MiB) / static (lexing, syntax, static rules, evaluation) error.kind is usage or static
422 supply (supply contract violation, missing binding) error.kind is supply
413 Body over 256 KiB (answered at once from the Content-Length declaration or mid-stream; the connection is closed) error.kind is usage
415 Content-Type is not application/json error.kind is usage
429 Concurrency limit reached (Retry-After: 1) {version, error}
504 Evaluation exceeded the time limit (cut off) {version, error: {kind: "timeout"}}
404 / 405 Unknown path / wrong method (405 carries Allow; GET routes also accept HEAD) {version, error}
500 Internal shell error, or a raw exception from the evaluator (including heap exhaustion) {version, error: {kind: "internal"}} (never includes source)

How evaluation runs

Environment variables

Name Default Meaning
PORT 8080 Port to listen on
KAIROS_HTTP_MAX_CONCURRENCY 4 Concurrency limit = number of resident workers; when all are busy, 429 at once
KAIROS_HTTP_TIMEOUT_MS 10000 Evaluation time limit per request (ms); over it, 504
KAIROS_HTTP_WORKER_HEAP_MB (Node’s default) Heap limit per worker (MB, --max-old-space-size). An evaluation that exceeds it becomes 500 and the worker is replaced; the container’s memory divided by the number of workers is a reasonable value
KAIROS_HTTP_LOG access access: one line per request (method, path, status, ms) to stderr. off: nothing. The body (source) is never logged
KAIROS_HTTP_EVALUATOR (unset) Where to load the evaluator from (a kairos-lang source tree). For testing against the co-located reference implementation; leave unset

What it does not have

Versions

The shell’s version follows kairos-lang (same number, same contract). The evaluator is npm kairos-lang, pinned by the lock; kairosLang in /v1/version is that version. The image tag is the evaluator’s version. With the same kairos-lang version, the CLI, MCP and HTTP agree on points, success and diagnostic text.

License

Apache-2.0.