Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ documentation site, [docs/](docs/src/content/docs/index.mdx).
```sh
make setup # once: the switch spindle, every dependency
make test # starts the test Postgres in Podman, runs every suite
make lint # formatting, odoc, the release build, and the opam files
make lint # formatting, odoc, the release build, Hypha's rules by litany, and the opam files
make fmt # format in place
make docs # the documentation site into _build/docs, as Pages publishes it; docs-serve serves it
make release VERSION=1.2.3 # once CHANGES.md names it: tag and release with open-opam
Expand Down Expand Up @@ -129,10 +129,20 @@ out you broke it, as it is true today. Cite one by its bold phrase.
since Logs drops every line until it is;
`Spindle.Log`'s default sink writes its lines to stderr; and
`spindle-cli`, a command line, prints its answer and its errors and
exits with its status. Symptom: `rg -n -w
'exit|stderr|print_string|print_endline|prerr_endline|Printf\.printf'
-g '*.ml' http core client postgres sqlite cli` finds one in a place this
list does not name.
exits with its status. Symptom: `make lint`'s litany reports
`restricted-dependency` or `suspicious-exit-in-library`, which each of
these places is allowed with its reason beside it, and `cli/` by a
`per-path` in the `litany` file.
- **Spindle owns the process in these places alone, beside those above.**
`Spindle.serve` handles SIGTERM and SIGINT, to stop as its `.mli` says;
`Spindle.Log.setup`, which an executable calls, sets the `Logs` reporter
and level, its reporter reads the system's clock, since it runs on
whichever thread logged and outside any event loop, and its writer
writes the lines still waiting as the process ends. Why: Spindle is the
framework a program's `main` hands the process to, and a library under
it does none of this. Symptom: `make lint`'s litany reports
`restricted-dependency` for a signal, `Logs`, a clock or `at_exit`
anywhere but `core/server.ml` and `core/log.ml`.
- **Spindle reads and writes HTTP itself, names no driver, and its client
installs and links no framework.** No library links another HTTP
implementation or names one; `spindle-postgres` and `spindle-sqlite`
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

## 0.15.2 (2026-12-03)

- `Spindle_client` keeps the backtrace of an exception it closes a
connection on, where closing could overwrite it.
- Every package installs the documentation for agents, `llms.txt` and every
page, in `$(opam var <package>:doc)`, and every interface it installs
names its page there, or `llms.txt`. The README's *With an agent* says so.

## 0.15.1 (2026-11-22)

- spindle installs its documentation for agents: each page of the site as
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ test/oidc/node_modules: test/oidc/package.json test/oidc/bun.lock
# unless told it is an error, and installing from source prints each one.
# The client's packages are built alone, as opam installs them for a
# program that wants no framework.
lint: ## check formatting, docs, the release build and the opam files
# litany holds the code to Hypha's rules, as the litany file selects them.
lint: ## check formatting, docs, the release build, Hypha's rules and the opam files
$(OPAM) dune build @all @fmt @doc
$(OPAM) dune build --profile release @all
$(OPAM) dune build -p spindle-http,spindle-client,spindle-mcp-client @install
$(OPAM) litany check
opam lint -W @1..99 *.opam

fmt: ## format the code
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ with the bounds from your types, and every error it may answer.

## With an agent

spindle installs its documentation at `$(opam var spindle:doc)`: each page
of the site as Markdown, the tutorial and guides among them, and
`llms.txt`, which lists them. Your agent reads it when told to, in a line in
your project's `AGENTS.md`:
Every package of spindle installs its documentation for an agent with it, at
`$(opam var <package>:doc)`: `llms.txt`, and every page in Markdown. An
agent reads it when your project's `AGENTS.md` tells it to:

```md
Before writing code with spindle, read `$(opam var spindle:doc)/llms.txt` and
the pages it lists for the parts you need, and use those parts rather than
writing your own.
Before working with spindle, read `llms.txt` in `$(opam var <package>:doc)`,
for any spindle package the project installs, then the pages it lists for the
parts you need, and use those parts rather than writing your own.
```

## Contributing
Expand Down
2 changes: 2 additions & 0 deletions cli/spindle_cli.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** An application's command line: its API, described from the routes.

Its documents, a page for each part: [$(opam var spindle-cli:doc)/llms.txt].

OCaml cannot load an application into a generic command, so each application
calls {!run} from an executable of its own:

Expand Down
19 changes: 13 additions & 6 deletions client/spindle_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,9 @@ let exchange ~sw t ~headers ~body meth target ~reused =
close_connection c;
attempt ~fresh:true
| exception ex ->
let bt = Printexc.get_raw_backtrace () in
close_connection c;
raise ex
Printexc.raise_with_backtrace ex bt
in
attempt ~fresh:false

Expand Down Expand Up @@ -879,8 +880,9 @@ let open_answer ~sw t ~headers ~body meth target =
close_connection c;
attempt ~fresh:true
| exception ex ->
let bt = Printexc.get_raw_backtrace () in
close_connection c;
raise ex
Printexc.raise_with_backtrace ex bt
in
attempt ~fresh:false

Expand Down Expand Up @@ -1093,11 +1095,14 @@ let refusal_body t c (head : Head.Response.t) =
| Error _ -> ""
| Ok framing -> (
let reader = Framing.reader framing c.reader ~max_trailer:max_head in
match Framing.read reader ~max:t.max_body ~reserve:(fun _ -> true) with
(match Framing.read reader ~max:t.max_body ~reserve:(fun _ -> true) with
| Ok body -> body
| Error _ -> ""
| exception (Eio.Cancel.Cancelled _ as ex) -> raise ex
| exception _ -> "")
[@litany.allow
"suspicious-catch-all-handler: the refusal stands whatever ended its \
body, and cancellation is raised again above"])

(* A socket's own writer rather than [Buf_write.with_flow], which waits for
everything written to go: to a server that stopped reading, a wait with
Expand Down Expand Up @@ -1181,8 +1186,9 @@ let open_websocket t ?timeout ?(headers = []) ?keep_alive ?max_message protocol
(fun () -> Ok (`Refused (head, refusal_body t c head)))
| head -> Ok (`Switching (c, head))
| exception ex ->
let bt = Printexc.get_raw_backtrace () in
close_connection c;
raise ex)
Printexc.raise_with_backtrace ex bt)
with
| Ok opened -> Ok opened
| Error `Timeout -> Error (match timed_out deadline with #error as e -> e)
Expand Down Expand Up @@ -1438,7 +1444,8 @@ module Otlp = struct
if List.length spans = batch_size then
send_waiting client q ~url ~headers ~service

let run ?ratio ?(headers = []) ~clock ~endpoint ~service client f =
let run (type a) ?ratio ?(headers = []) ~clock ~endpoint ~service client
(f : Trace.exporter -> a) : a =
let url =
(if String.ends_with ~suffix:"/" endpoint then
String.sub endpoint 0 (String.length endpoint - 1)
Expand Down Expand Up @@ -1477,7 +1484,7 @@ module Otlp = struct
else None);
false);
(fun () ->
ignore (Eio.Promise.await answer);
ignore (Eio.Promise.await answer : a);
true);
]
in
Expand Down
6 changes: 6 additions & 0 deletions client/spindle_client.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
(** Calling another server.

Its documents, a page for each part:
[$(opam var spindle-client:doc)/llms.txt].

Its page, with its examples:
[$(opam var spindle-client:doc)/pages/guide/client.md].

The request is written, and the response read, by [spindle_http] -- the
reader and writer the server is built on, so the framework has one account
of where a message ends. A 1xx before the answer is read and dropped, a
Expand Down
3 changes: 3 additions & 0 deletions core/access.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(** Who may do what: a policy decides, a dependency enforces.

Its page, with its examples:
[$(opam var spindle:doc)/pages/guide/access.md].

A policy is a function of the caller, an action and the object it is done
to, written in OCaml beside the routes it guards. A route reaches a guarded
object only through {!can}, which loads it, asks the policy, and hands the
Expand Down
2 changes: 2 additions & 0 deletions core/alarm.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** Wake-ups, one per key: "look at this again after so long".

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

Setting a key again supersedes what was set before: the earlier wake-up's
fiber is cancelled, not left asleep, and a key is forgotten once it has
fired or been cancelled -- so a table of alarms holds only what is still to
Expand Down
2 changes: 2 additions & 0 deletions core/app.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** An application: routes, what answers everything they do not match, and what
applies to all of it.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

A request is matched by method and path. A path some route claims under
another method is [405] with [Allow], which names [OPTIONS] too: a plain
[OPTIONS] of such a path, where no route declares one, is [204] with that
Expand Down
3 changes: 3 additions & 0 deletions core/background.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(** Work nobody is waiting for.

Its page, with its examples:
[$(opam var spindle:doc)/pages/guide/background.md].

A daemon, so a process shutting down is not held open by one. A failure is
{b logged}, never raised: a fiber's exception fails the switch it was forked
on, and when that switch is the server's, one bug in a background job would
Expand Down
2 changes: 2 additions & 0 deletions core/bearer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
challenge RFC 6750 §3 names, and described by the metadata document RFC 9728
has a client find the issuer from.

Its page, with its examples: [$(opam var spindle:doc)/pages/guide/oauth.md].

{[
let auth =
Spindle.Bearer.make ~issuer:"https://id.example.com"
Expand Down
2 changes: 2 additions & 0 deletions core/body.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** A request body read as it arrives: what {!Spindle.body_stream} hands a
route, for a body too large to hold -- an upload.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

{[
let rec save file body =
let* part = Spindle.Body.read body in
Expand Down
4 changes: 3 additions & 1 deletion core/body_repr.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** A request's body while a route runs: read whole once and kept for every
dependency that asks, or handed to the one that streams it. What {!Body} is,
underneath. *)
underneath.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type error = Request_repr.body_error

Expand Down
2 changes: 2 additions & 0 deletions core/broadcast.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** One event, rendered once, sent to everybody listening to a topic.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

There is no broker. A broker exists to carry an event from one process to a
socket held by another, and in one process three hundred listeners are three
hundred fibers parked on a read, which is the thing Eio is good at. What the
Expand Down
2 changes: 2 additions & 0 deletions core/cache.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** How long a browser may keep what the routes answer, apart from what they
serve: a policy of the application's, given among its middleware.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

{[
Spindle.serve env
~middleware:[ Spindle.Cache.forever ~under:Spindle.Path.[ s "assets" ] ]
Expand Down
3 changes: 3 additions & 0 deletions core/compress.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
process pays and the proxy in front often compresses already, and a route's
own in place of it where the route gives one ({!Route.maker}'s [compress]).

Its page, with its examples:
[$(opam var spindle:doc)/pages/guide/compression.md].

{[
Spindle.serve env ~compress:Spindle.Compress.default routes
]}
Expand Down
4 changes: 3 additions & 1 deletion core/compress_repr.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** What {!Compress} is, underneath: shared with the server, which decides
whether an answer is compressed. *)
whether an answer is compressed.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type policy = {
min_bytes : int; (** an answer shorter than this is sent as it is *)
Expand Down
4 changes: 3 additions & 1 deletion core/conditional.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** A [GET] of a representation: RFC 9110 §13.2.2's preconditions in their
order, then §14's range: one account for every file the framework serves. *)
order, then §14's range: one account for every file the framework serves.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type validators = {
tag : Spindle_http.Etag.t;
Expand Down
3 changes: 3 additions & 0 deletions core/cookie.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(** Cookies: the ones a response sets, and reading the ones a request carries.

Its page, with its examples:
[$(opam var spindle:doc)/pages/guide/cookies.md].

A cookie is declared once, by its name and the description its value is read
and written by, and used both ways:

Expand Down
2 changes: 1 addition & 1 deletion core/cookie_repr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ let decode s =
let make ?path ?max_age_s ?http_only ?same_site n v =
let max_age =
match (max_age_s, n.age) with
| Some a, Some b -> Some (min a b)
| Some a, Some b -> Some (Int.min a b)
| Some a, None | None, Some a -> Some a
| None, None -> None
in
Expand Down
4 changes: 3 additions & 1 deletion core/cookie_repr.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** A cookie as the framework holds it: writing [Set-Cookie], reading [Cookie],
encoding a value. What {!Cookie} is, underneath; each value {!Cookie}
exports is documented there. *)
exports is documented there.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type same_site = Strict | Lax

Expand Down
3 changes: 3 additions & 0 deletions core/cors.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
given, and a route's own in place of it where the route gives one
({!Route.maker}'s [cors]). A route the policy it has allows is covered.

Its page, with its examples:
[$(opam var spindle:doc)/pages/guide/cookies.md].

{[
let app_site =
Spindle.Cors.origins ~credentials:true [ "https://app.example.com" ]
Expand Down
4 changes: 3 additions & 1 deletion core/cors_repr.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** A CORS policy as the server applies it: what {!Cors.origins} or {!Cors.any}
makes, and the fields of the Fetch standard's answers it owes a cross-origin
request. *)
request.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type origins = Origins of string list | Any

Expand Down
2 changes: 1 addition & 1 deletion core/deadline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let remaining t =
if t.due_at = never then None
else
let left = t.due_at - now t.clock in
Some (Mtime.Span.of_uint64_ns (Int64.of_int (max 0 left)))
Some (Mtime.Span.of_uint64_ns (Int64.of_int (Int.max 0 left)))

let passed t = t.passed

Expand Down
2 changes: 2 additions & 0 deletions core/deadline.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
that domain's connections once a tick -- a deadline and its sweep are on the
same domain, always.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt].

Every read of the connection, and every flush of an answer to it, runs
against it, and moving it is a write to a field, not a timer: arming it for
a head, a body or an answer, and the bytes that go moving it on, cost
Expand Down
3 changes: 3 additions & 0 deletions core/dep.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(** Dependencies: what a handler needs, computed from the request.

Its page, with its examples:
[$(opam var spindle:doc)/pages/tutorial/dependencies.md].

A ['a t] is a value -- a body of some shape, a query parameter, a signed-in
person -- that is worked out when a request arrives, or a refusal that
answers the request instead. A handler lists what it needs with OCaml's own
Expand Down
4 changes: 3 additions & 1 deletion core/dep_repr.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** A dependency as the framework runs it: what it reads, how it refuses, its
two stages, and the identity its answer is shared by. What {!Dep} is,
underneath; the types {!Dep} names are documented there. *)
underneath; the types {!Dep} names are documented there.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type body =
| Raw : { content_types : string list } -> body
Expand Down
4 changes: 3 additions & 1 deletion core/described.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** An application's routes as the two printers read them: every description
walked, the answers first and then the bodies, so a component a response and
a request share takes the response's name. *)
a request share takes the response's name.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

type returns =
| Value of {
Expand Down
2 changes: 2 additions & 0 deletions core/event.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(** Server-Sent Events, declared: what a stream may send, by name and
description, and each event made from its declaration.

Its page, with its examples: [$(opam var spindle:doc)/pages/guide/sse.md].

{[
type room

Expand Down
4 changes: 3 additions & 1 deletion core/file_types.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(** A file's media type by its name, and the precompressed siblings a build
writes beside it, shared by {!Static} and {!Files}. *)
writes beside it, shared by {!Static} and {!Files}.

Its documents, a page for each part: [$(opam var spindle:doc)/llms.txt]. *)

val content_type : types:(string * string) list -> string -> string
(** The type of a file by its extension, compared without case, [types] before
Expand Down
Loading