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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml }}
# litany, which make lint runs, is open-opam's.
opam-repositories: |
open-opam: https://github.com/open-opam/opam-repository.git
default: https://opam.ocaml.org
- uses: oven-sh/setup-bun@v2
- run: opam install . --deps-only --with-test --with-dev-setup -y
- run: bun install --frozen-lockfile
Expand Down
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation site, [docs/](docs/src/content/docs/index.mdx).
make setup # once: the switch wiretype, all dependencies, and Zod
make test # every suite, the kinds' rows through Zod, and the shared rows
# through the printed Melange module
make lint # formatting, odoc, and the release build
make lint # formatting, odoc, the release build, and Hypha's rules by litany
make fmt # format in place
make docs # the documentation site into _build/docs, as Pages publishes it, and
# agents/ from its pages; docs-serve serves it
Expand Down Expand Up @@ -185,8 +185,12 @@ break.
the pages on every pull request and fails if `agents/` then differs.
- **The opens are `Tuple`'s, inside `Tuple.( ... )` as its `.mli` says, and
the deriver's `Ppxlib` and `Ast_pattern`**, which every ppxlib rewriter
opens to read the AST it matches. Symptom:
`rg -n '\bopen |\b[A-Z]\w*\.[(\[{]' src ppx` finds any other.
opens to read the AST it matches. Symptom: `make lint`'s litany reports
`open-of-ordinary-module`, which each `open Ppxlib` is allowed with its
reason beside it.
- **The `litany` file's one addition is a `per-path` for `src/gen/`**:
build-time programs that print the tables dune writes into modules, which
the gold copy's paths take for the library's code.

## Changes and releases

Expand Down
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changes

## 0.7.2 (2026-12-03)

- What `[@@deriving wiretype]` writes for a type that holds itself names the
type of the description it forces, so a project that runs litany's
`untyped-ignore` no longer has a finding at each such type.
- 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.7.1 (2026-11-22)

- The wiretype package installs its documentation for agents: each page as
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ help: ## list targets
setup: ## create the switch and install dependencies
@command -v bun >/dev/null 2>&1 || echo "The Zod rows and the documentation site need Bun 1.3 or later."
@opam switch list --short | grep -qx $(SWITCH) || opam switch create $(SWITCH) --empty -y
opam repo add open-opam https://github.com/open-opam/opam-repository.git --switch=$(SWITCH) --rank=1
opam install . --switch=$(SWITCH) --deps-only --with-test --with-dev-setup -y
cd test/zod && bun install --frozen-lockfile

Expand All @@ -28,10 +29,12 @@ test: test-zod ## run the tests
test-zod: ## run the kinds' rows through Zod
cd test/zod && bun test

# Release is the profile opam installs with.
lint: ## check formatting, docs and the release build
# Release is the profile opam installs with. litany holds the code to
# Hypha's rules, as the litany file selects them.
lint: ## check formatting, docs, the release build and Hypha's rules
$(OPAM) dune build @all @fmt @doc
$(OPAM) dune build --profile release @all
$(OPAM) litany check

fmt: ## format the code
$(OPAM) dune fmt
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ and prints the same description as JSON Schema and Zod.

## With an agent

Each release installs its documentation for an agent with it, at
`$(opam var wiretype:doc)`: `llms.txt`, and every page in Markdown. An agent
reads it when your project's `AGENTS.md` tells it to:
Every package of wiretype 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 wiretype, read `$(opam var wiretype: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 wiretype, read `llms.txt` in `$(opam var <package>:doc)`,
for any wiretype 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
11 changes: 9 additions & 2 deletions dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
(:standard -w +a-4-40-41-42-44-45-48-67-70))))

; The documentation for a user's agent, agents/, written from the site's pages
; by `make docs`: wiretype installs it whole, so $(opam var wiretype:doc)
; holds llms.txt and each page.
; by `make docs`: every package installs it whole, so a package installed
; alone, ppx_wiretype without wiretype, still holds llms.txt and each page in
; $(opam var <package>:doc).

(install
(package ppx_wiretype)
(section doc)
(source_trees
(agents as .)))

(install
(package wiretype)
Expand Down
7 changes: 6 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
(ocamlformat
(and
:with-dev-setup
(= 0.29.0)))))
(= 0.29.0)))
(hypha-litany
(and
:with-dev-setup
(>= 1.3.0)
(< 2.0.0)))))

(package
(name ppx_wiretype)
Expand Down
230 changes: 230 additions & 0 deletions litany
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
; Hypha's lint set, as litany holds it. Every Hypha repository's litany file
; selects each rule here and keeps each forbid as it is written here; what is
; the repository's own -- a forbid more, a per-path -- is added with its
; reason. Hypha's OCAML.md says what each rule is for.

(litany-config 1)

(lint
(select default)
(extend
unsafe-partial-stdlib
unsafe-obj-magic
untyped-ignore
ignored-result
wildcard-over-owned-variant
open-of-ordinary-module
restricted-dependency))

(rule restricted-dependency
; Refused in every file.
(forbid Stdlib.failwith
(use "a result; a test that raises on purpose declares its own exception"))
(forbid Stdlib.compare
(use "the type's own comparison: Int.compare, String.compare"))
(forbid Stdlib.min
(use "the type's own: Int.min, Float.min"))
(forbid Stdlib.max
(use "the type's own: Int.max, Float.max"))
(forbid Unix.time
(use "the clock the caller gives, read as a Ptime.t"))
(forbid Unix.gettimeofday
(use "the clock the caller gives, read as a Ptime.t"))
(forbid Stdlib.Sys.time
(use "Eio.Time.Mono.now, for time that has passed"))
(forbid Unix.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Unix.alarm
(use "Eio.Time.Timeout.v"))
(forbid Unix.setitimer
(use "Eio.Time.Timeout.v"))
(forbid Unix.getitimer
(use "Eio.Time.Mono.now"))
(forbid Eio_unix.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Eio.Time.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Eio.Time.sleep_until
(use "Eio.Time.Mono.sleep_span, over the span from now to the instant"))
(forbid Eio.Time.with_timeout
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.with_timeout_exn
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.Timeout.seconds
(use "Eio.Time.Timeout.v, given an Mtime.Span.t"))
(forbid Eio.Time.Mono.sleep
(use "Eio.Time.Mono.sleep_span"))
(forbid Uri.query
(use "what the router decoded and validated"))
(forbid Uri.get_query_param
(use "what the router decoded and validated"))
; Refused outside a library's clock module.
(forbid Eio.Time.now
(use "the library's instant.ml, which gives a Ptime.t")
(except **/instant.ml))
(forbid Unix.sleepf
(use "the library's instant.ml, which takes an Mtime.Span.t")
(except **/instant.ml))
; Refused in a library: a program, a test and an example own their process,
; wherever in the tree its bin/, test/, examples/ or bench/ is.
(forbid Stdlib.Sys.getenv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.getenv_opt
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.getenv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.environment
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Unix.putenv
(use "an argument: a library sets no global state")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.argv
(use "a value the executable read at startup and passed in")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.signal
(use "the executable: it owns the process's signals")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.set_signal
(use "the executable: it owns the process's signals")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.chdir
(use "a directory capability the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Sys.command
(use "Eio.Process, on the process manager the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.at_exit
(use "Eio.Switch.on_release, on the switch the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Random.self_init
(use "a Random.State.t, or the secure random source the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Random.init
(use "a Random.State.t, or the secure random source the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Logs.set_reporter
(use "the executable: it configures the log reporter")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Logs.set_level
(use "the executable: it configures the log level")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_endline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_bytes
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_char
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_int
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_float
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.print_newline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_endline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_bytes
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_char
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_int
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_float
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.prerr_newline
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.stdout
(use "a sink the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.stderr
(use "a sink the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Printf.printf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Printf.eprintf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.printf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.eprintf
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.print_string
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.std_formatter
(use "a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Stdlib.Format.err_formatter
(use "a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Fmt.pr
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Fmt.epr
(use "a log on the library's own source, or a formatter the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Eio_main.run
(use "the env, switch or capability the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Ptime_clock.now
(use "the clock or ~now the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.now
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.elapsed
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Mtime_clock.counter
(use "the clock the caller gives")
(except **/bin/** **/test/** **/examples/** **/bench/**))
; Refused in a Melange library: the console is the page's.
(forbid Js.log
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log2
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log3
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.log4
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.logMany
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**))
(forbid Js.Console
(use "a value returned to the caller")
(except **/bin/** **/test/** **/examples/** **/bench/**)))

; wiretype's own.

(per-path
(paths src/gen/**)
(ignore restricted-dependency)
(reason "build-time programs: each prints the table dune writes into a module"))
10 changes: 7 additions & 3 deletions ppx/ppx_wiretype.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
open Ppxlib
open Ppxlib [@@litany.allow
"open-of-ordinary-module: every ppxlib rewriter opens Ppxlib to \
read the AST it matches"]

module B = Ast_builder.Default

(* ------------------------------------------------------------------ *)
Expand Down Expand Up @@ -1296,7 +1299,8 @@ let str_type_decl ~ctxt (rec_flag, tds) =
[%expr
Stdlib.ignore
(Stdlib.Lazy.force
[%e B.evar ~loc (lazy_name td.ptype_name.txt)])])
[%e B.evar ~loc (lazy_name td.ptype_name.txt)]
: _ Wiretype.t)])
plain));
];
])
Expand Down Expand Up @@ -1358,7 +1362,7 @@ let () =
Attribute.T A.ct_with;
]
in
ignore
Deriving.ignore
(Deriving.add "wiretype"
~str_type_decl:
(Deriving.Generator.V2.make_noarg ~attributes str_type_decl)
Expand Down
6 changes: 6 additions & 0 deletions ppx/ppx_wiretype.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
[<name>_json] -- [json] for a type named [t] -- and in a signature its
[val].

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

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

- A {b record} is an object named by the type (a [t] by its module), each
field a member; one with parameters is named only by [[@@kind]]. An
[option] field may be left out or [null] ([Object.opt_mem]). An option of
Expand Down
Loading