kit de gestion des crates du répertoire pmo
  • Shell 80.3%
  • Makefile 10%
  • Python 9.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Eric Coissac 5b1a3996f8
All checks were successful
Release / release (push) Successful in 16s
refactor: restructure forge token handling and extension kit setup
Update the extension kit to support hierarchical forge token files based on
host, owner, and repository, replacing the single-file layout. This change
introduces new helper functions for parsing URLs and locating secrets, updates
documentation to reflect the new precedence rules, and adds tests for the
token resolution logic.

- Add `forge_secrets_dir` and `forge_parse_url` functions to
  `kit/scripts/common.sh` to construct secret paths and parse registry URLs.
- Modify `forge_token` in `kit/scripts/common.sh` to look for tokens in
  `secrets/<host>/<owner>/<repo>.token` before falling back to
  `$FORGE_TOKEN_FILE`.
- Update `adopt-kit.sh` to generate extension kits with the new secret
  directory structure and remove references to the old `secrets/forge-token`
  file.
- Add `tests/forge-token.sh` to verify token precedence rules, including
  handling of `FORGETOKEN`, `FORGE_TOKEN_FILE`, and hierarchical files.
- Update `Makefile` to export `FORGE_SECRETS_DIR` for tests and include the
  new `forge-token.sh` test case.
- Delete `template-kit/secrets/README.md` as the single-token layout is
  deprecated; update `template-kit/README.md` to document the new
  `secrets/<host>.token` structure.
- Update `README.md` to document the new token file structure, precedence
  rules, and security requirements (mode 0600, first line only).
- Modify `kit/dev-patch.mk` to remove the include of `org.mk` and add
  `CARGO_TOML` default, clarifying that organization-specific values are
  provided by the extension.
- Update `template-kit/.gitignore` to remove the blanket `secrets/*` ignore
  and add `/dist/`, allowing specific secret files to be tracked if needed.
- Update `tests/adopt-kit.sh` to exclude `secrets/README.md` and
  `overlay/kit/VERSION` from the kit assembly check.
- Bump kit version in `kit/VERSION` from 0.3.2 to 0.3.3.
2026-12-01 14:36:50 +01:00
.gitea/workflows docs: translate project documentation and scripts to English 2026-11-30 07:08:03 +01:00
.serena
claude refactor: improve release tag checking and backlog guards 2026-12-01 12:25:25 +01:00
docs refactor: standardize agent configs and add static validation 2026-12-01 09:25:00 +01:00
kit refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
ollama docs: translate project documentation and scripts to English 2026-11-30 07:08:03 +01:00
ReleaseNotes refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
template docs: translate project documentation and scripts to English 2026-11-30 07:08:03 +01:00
template-kit refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
tests refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
tools refactor: replace jj new with new-commit script 2026-12-01 13:32:19 +01:00
.DS_Store
.gitignore
adopt-kit.sh refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
adopt.sh docs: translate project documentation and scripts to English 2026-11-30 07:08:03 +01:00
Makefile refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00
README.md refactor: restructure forge token handling and extension kit setup 2026-12-01 14:36:50 +01:00

crate-kit

Tooling for managing a set of Rust crates: build, quality, public API tracking, version number deduced from the API, release notes and tag locally; publication to a private registry, wiki update and release creation by the CI (Forgejo/Gitea workflow on the version-* tag). It contains nothing specific to an organization: the registry, the forge, and the special crate kinds (plugins, catalogs…) come from an extension kit (see below).

This repository is not a crate (no Cargo.toml, never published to a registry).

Principle

Each crate stays autonomous: it contains its own copy of the kit in .crate-kit/ (committed with it) and a Makefile of a few lines that includes it. A clone of the crate alone builds without this repository. No variant from one crate to another: at each make, the crate's Makefile resynchronizes .crate-kit/ from its source kit KIT_SRC: ../crate-kit without an organization, or an extension kit (../acme-kit) that assembles crate-kit and its own files (ignored if this directory is absent).

crate-kit/
├── kit/                  copied into each crate under .crate-kit/
│   ├── crate.mk          common make targets
│   ├── scripts/          logic (bash): api-level, api-snapshot, bump-version, release-notes, tag,
│   │                     publish, wiki, forgejo-release (the last three are called by the CI)
│   ├── kinds/            crate kinds (crate.mk: the ordinary kind)
│   └── VERSION
├── tools/                repository tools (kit-assemble, kit-copy, kit-sync, release-all, needs-commit-all, local-ask, cc-token-report, kit-release.mk)
├── claude/               generic Claude hooks and agents (install.sh)
├── template/             files of a new crate (Makefile, .gitignore, LICENSE,
│                         .gitea/workflows/release.yaml)
├── adopt.sh              installs the kit and the template into a crate
├── adopt-kit.sh          creates or completes an extension kit (template: template-kit/)
└── docs/                 procedures (making a crate autonomous…)

Adopting the kit in a crate

./adopt.sh --kit-src ../acme-kit ../acmexxx   # installs .crate-kit/ and the missing template files
# from a cluster: make -C acme-kit adopt CRATE=../acmexxx
cd ../acmexxx && make help

adopt.sh never replaces an existing file. An existing Makefile is migrated by hand: keep only what is specific to the crate and add include .crate-kit/crate.mk.

In the crate: synchronization is automatic at each make (other location: KIT_SRC=...); make kit-update forces it. Kit files modified or added by hand in .crate-kit/ are overwritten or deleted. Never modify .crate-kit/ in a crate: fix it here; the next make of each crate propagates it (the changes show up in jj st of the crate, to be committed with it).

Crate kind

CRATE_KIND (default crate) chooses a kind, that is, a kinds/<kind>.mk file. An unknown kind is refused. Kinds other than crate come from an extension kit: ./adopt.sh --kit-src ../acme-kit --kind <kind> ../acmexxx then installs the adoption template of that kind.

Keeping crates up to date

The kit copy in each crate is deliberate (the crate stays autonomous), so it can fall behind. Three safeguards:

  • make jjfetch (in a crate) fetches the origin and rebases local work on top of main@origin instead of leaving the working copy aside (unrebased work used to be lost from view, then forgotten by the next release). A revision already pushed but not yet merged (pending PR) is never rewritten: the work stays on top of it, with a warning. A local revision rewritten after its push and then merged on the server side (same change id, hence a divergent change) is never rebased: abandoned if its content is identical to the merged version, otherwise the script stops before rewriting anything, stating what to do. After the rebase, make is run again to resynchronize .crate-kit/ (derived copy of the kit): a rebase done right after a kit version bump would otherwise leave conflict markers in it.
  • make bookmark-check (in a crate; jjpush and jjrelease run it first) refuses a main@origin that the local main bookmark does not track: without this tracking, jj rejects the push of main at the very end of the release. The message gives the remedy: jj bookmark track main@origin. Read-only; without a jj repository or without main@origin, there is nothing to check.
  • make kit-check (in a crate) compares .crate-kit/ with the kit assembled from KIT_SRC (crate-kit alone, or with its extension); make jjrelease runs it first and stops if the kit is stale. Without a source kit alongside (clone of the crate alone, CI) the check is skipped. It compares the content, not VERSION. It also checks that .gitea/workflows/release.yaml matches the template of the crate's kind (comment lines and - name: labels ignored) and refuses a stale one, printing the cp remedy; a deliberate customization is declared with a # kit-workflow: custom line. kit-check.sh --fix replaces the stale workflow with the template instead of failing (this is what update-all FORCE=1 runs).
  • make check-all (here, or make -C acme-kit check-all: the extension sets the cluster and the registry) lists the neighboring crates whose kit differs, read-only.
  • make update-all (here) updates all the neighboring crates at once; FORCE=1 also replaces their stale release workflows with the template of their kind (to be run after fixing the kit) and shows what changes in each.

Keeping dependencies between registry crates up to date

When a crate of the private registry depends on another, nothing forces it to follow its new versions: for a 0.x, the requirement 0.1 never accepts 0.2, and Cargo says nothing. make deps-check (in a crate or in an application crate) reads the public index of the registry and fails as soon as a project risks running with a stale version:

  • the Cargo.toml requirement does not accept the latest published version;
  • Cargo.lock stayed on an older version;
  • the neighboring directory ../<crate>, which replaces the dependency in joint development, is behind the registry;
  • Cargo.lock contains a [[patch.unused]] (the local patch is ignored, a sign of a requirement that is too low);
  • a registry crate appears in several versions in the build (incompatible types).

A neighbor newer than the registry (pending publication) is reported without failing. make deps-bump raises the outdated requirements then runs cargo update -p. The check is part of make ci, make jjpush and make jjrelease. Requirements are declared on one line, in the form x.y (or x from 1.0 on). Without a network the check fails; DEPS_CHECK_OFFLINE=1 explicitly skips it. Locally, the lock is that of the patch (without source): the lock being behind is only seen on the committed lock (CI).

External dependencies (crates.io)

make deps-check also checks the direct dependencies coming from crates.io, because cargo outdated compares the lock to the latest published version but not the requirement written in the Cargo.toml (os_info = "3.8" with a lock at 3.15 goes unnoticed). It fails when:

  • the requirement does not accept the latest version (socket2 = "0.5" while 0.6 exists);
  • for a version ≥ 1, the required minor is behind (tokio = "1.35" while 1.54 exists); a 0.x is not checked at this level, its patch not counting;
  • Cargo.lock is not on the latest version that the requirement accepts.

Ignored are explicit requirements (=1.2.3, ~1.2, >=1, ranges) and path, git, registry or workspace dependencies. make deps-bump raises the requirements then runs cargo update -p. DEPS_CHECK_EXTERNAL=0 disables this check, DEPS_CHECK_EXTERNAL_IGNORE="crate1 crate2" sets crates aside (to be written in the Makefile, with the reason); CRATES_IO_INDEX changes the index (tests).

Writing an extension kit

An extension kit (example: acme-kit) is a directory next to crate-kit, with its own repository. It is overlaid on kit/: at each synchronization, tools/kit-assemble.sh copies kit/ then <extension>/kit/ on top (same path = replaced, other path = added), and the result is the .crate-kit/ copy of each crate. Nothing of the extension kit is needed outside this copy: the crate stays autonomous.

Plugging in the extension kit

crate-kit is unique: it knows no organization. The extension is the entry point: it includes crate-kit, delegates to it, and sets what is specific to the cluster. Each crate names its extension through KIT_SRC (instead of ../crate-kit):

KIT_SRC ?= ../acme-kit      # written by adopt.sh --kit-src; path relative to the crate

The extension kit provides:

  • tools/kit-assemble.sh and tools/kit-copy.sh: small scripts that export KIT_OVERLAY=<extension>/overlay then do exec "$CRATE_KIT/tools/<name>.sh" "$@". These are the only call points of the crate and of crate-kit (the first also accepts --overlay and --root).
  • a Makefile that exports CRATE_KIT, KIT_OVERLAY, CLUSTER_DIR (directory of the crates), reads overlay/kit/org.mk, then delegates to make -C $(CRATE_KIT) the cluster targets (update-all, check-all, needs-commit-all, release-plan, release-run, release-dry-run) and runs claude/install.sh (claude-install) and adopt.sh --kit-src (adopt).

Consequences:

  • The same copy of crate-kit serves several clusters (acme, zeta…): each has its extension, without declaring anything in crate-kit and without a chain of extensions.
  • KIT_OVERLAY is read only from the environment; absent or empty, there is no extension. Declared but not found, it is an error (the kit copy would otherwise lose org.mk without saying so).
  • In the CI or for a repository cloned alone, the extension is absent: the committed copy .crate-kit/ is used, it is not needed.
  • Without an extension, there is no registry: publish and deps-check stop and say so. The registry is not optional; it is chosen.
  • tools/kit-assemble.sh --root prints the directory of crate-kit (to find its generic template).

Language of generated documents

The kit itself (messages, comments, documentation) is in English. The documents that an LLM generates for the user (release notes, backlog tasks and notes written by the agents, answers of tools/local-ask.py) follow the KIT_LANG setting: any language name or ISO code, default en.

  • Release notes: KIT_LANG (make variable, exported; make KIT_LANG=fr jjrelease) is passed to jj release-notes as PMOJJ_RELEASE_LANG.
  • Commit messages: the same value is exported as PMOJJ_LANG, read by jj auto-doc (pmojj, describe); tools/backlog-save.sh takes it from KIT_LANG, else <cluster>/.claude/kit-lang.
  • Claude agents: claude/install.sh replaces {{KIT_LANG}} in the agent prompts. Value: environment variable KIT_LANG, else the first line of <overlay>/claude/lang, else en. The value is also stored in <cluster>/.claude/kit-lang.
  • tools/local-ask.py: --lang, else KIT_LANG, else <cluster>/.claude/kit-lang, else en.

An extension kit sets its own default with KIT_LANG ?= fr in overlay/kit/org.mk and a one-line file overlay/claude/lang. Re-run make claude-install after any change.

The registry

REGISTRY (in org.mk) takes one of these values:

Value Effect
a private registry name (acme, zeta) + REGISTRY_INDEX publication to this registry; deps-check, [patch] for joint development; forge token passed to cargo
crates-io publication to crates.io with CARGO_REGISTRY_TOKEN (supplied by the user, never the forge's); no index nor [patch]; deps-check checks only external dependencies
(empty) refused: publish and deps-check fail

A kind without publication (PUBLISH = no) does not need to publish but reads the registry for its dependencies.

crates.io safeguard. For a private registry, make check (hence ci) requires in the publishable Cargo.toml publish = ["<registry>"]: cargo then itself refuses to publish elsewhere, even by a hand-typed command. What crates-io does not cover: the release order of several crates and the neighboring [patch] are computed only for a private registry (registry = "<name>" in the dependencies).

Contents of overlay/

overlay/
├── kit/                      merged into .crate-kit/
│   ├── org.mk                organization values
│   ├── VERSION               extension kit version
│   ├── kinds/<kind>.mk       crate kinds
│   ├── scripts/              additional scripts (called by a kind)
│   └── schemas/              additional schemas
├── templates/<kind>/         files of a crate of this kind (Makefile, workflow, LICENSE…)
└── claude/                   hooks/*.sh, agents/*.md, compact-rules.txt (see claude/install.sh)

kit/org.mk: values read by the kit, all with ?= so that they stay overridable by the Makefile of a crate.

Variable Role
REGISTRY name of the private cargo registry, or crates-io (empty: publish and deps-check refuse)
REGISTRY_INDEX URL of the registry's sparse index
FORGE_URL forge that hosts repositories, wiki and releases
FORGE_TOKEN_FILE former single-token layout, last resort: file whose first line is the forge token. Prefer the files of the cluster (section "Forge tokens").

Forge tokens. A workstation holds one token per forge, or per organization or repository when needed. They are files of the cluster: secrets/ next to the repositories (the parent of the repository, outside every repository, so nothing can be committed; FORGE_SECRETS_DIR overrides). The forge is that of the origin remote (ssh or https), or that of the registry index for the cargo registry token. The most specific file wins:

File Used for
secrets/<host>/<owner>/<repo>.token this repository only
secrets/<host>/<owner>.token every repository of the owner (organization)
secrets/<host>.token every repository of the forge

Example: LLM/crate-kit on gargoton.petite-maison-orange.fr reads secrets/gargoton.petite-maison-orange.fr.token unless a more specific file exists. A file holds the token on its first line, nothing else, mode 0600 (chmod 600); rights of the token: packages, repository, wiki, releases. In the CI FORGETOKEN is used first: each forge gives its own repository secret to its own jobs. FORGE_TOKEN_FILE (org.mk) is the former single-token layout, last resort. Never put a token in a Makefile, a script, ~/.cargo/credentials.toml or a directory that is committed or backed up.

The kit exports CARGO_REGISTRIES_<REGISTRY>_INDEX and, if a token exists, CARGO_REGISTRIES_<REGISTRY>_TOKEN: cargo needs no other configuration.

kit/VERSION: the displayed version becomes <kit>+<extension> (e.g. 0.1.30+0.1.0). It is used by make kit-version; to be incremented with each change of the extension.

kit/kinds/<kind>.mk: included by crate.mk before the targets, when CRATE_KIND = <kind>. It sets the generic variables that the kit reads:

Variable Effect Default
BUILD_TARGET --target of the release/debug builds empty (host)
EXTRA_TARGETS additional targets traversed by check and clippy empty
PUBLISH no: publish not applicable, ignored by release-all yes
API_TRACKED no: api-level answers unchanged, no API snapshot yes
WIKI no: no wiki yes
AFTER_RELEASE command run by jjrelease after the tag empty

A kind can also add its own make targets (dist, install…) and call its scripts through $(KIT_DIR)/scripts/…. It cannot remove anything from the kit: it sets its variables. When a crate wants to read a make variable (an external tool, a test), make -s print-<VARIABLE> prints it.

templates/<kind>/: files copied by adopt.sh --kind <kind> (never over an existing file); make needs-commit uses them too: a file identical to its template is not a change to commit.

claude/: make -C <extension> claude-install (which runs crate-kit/claude/install.sh) installs the hooks and agents of crate-kit/claude/ then those of the extension (same name = replaced) into <root>/.claude/. compact-rules.txt is the text reinjected after a compaction; without it, the hook does nothing.

Creating an extension kit

adopt-kit.sh does for an extension what adopt.sh does for a crate:

./adopt-kit.sh --name acme --registry acme --forge-url https://forge.example.org ../acme-kit
./adopt-kit.sh --name demo --registry crates-io ../demo-kit
Option Role
--name organization name (required)
--registry publication registry: a private name or crates-io (required)
--registry-index sparse index of the private registry; by default deduced from --forge-url (Forgejo form)
--forge-url forge that hosts repositories, wiki and releases

A private registry without index or forge is refused. The directory is placed next to crate-kit. The script installs the skeleton of template-kit/: Makefile (delegated cluster targets, adopt, claude-install, ci, jjrelease), tools/kit-assemble.sh and tools/kit-copy.sh, overlay/kit/org.mk and VERSION, tests/overlay.sh, release workflow and README. It never replaces an existing file (it flags with = those it leaves): it is also used to complete an older extension. The kit's jj repository is not created by the script.

Releasing a kit. crate-kit and its extensions are published in exactly the same way: tools/kit-release.mk, included by their Makefile, provides dist, bump-version, jjpush and jjrelease (version from kit/VERSION or overlay/kit/VERSION, notes in ReleaseNotes/, push of main, tag version-x.y.z; the workflow creates the Forgejo release with the kit archive). For an extension, the workflow also clones crate-kit in order to use its scripts, from CRATE_KIT_REPO (owner/name; the repository variable of that name, default LLM/crate-kit), independent of the owner of the extension kit.

By hand, step by step

  1. Neighboring directory mykit/ with overlay/kit/org.mk (at minimum REGISTRY, REGISTRY_INDEX, FORGE_URL, FORGE_TOKEN_FILE) and overlay/kit/VERSION (0.1.0).
  2. tools/kit-assemble.sh, tools/kit-copy.sh and extension Makefile, modeled on template-kit/. Then ./adopt.sh --kit-src ../mykit ../mycrate and make -C ../mycrate print-REGISTRY: the value from org.mk must come out.
  3. For a kind: overlay/kit/kinds/<kind>.mk and, if needed, overlay/templates/<kind>/; in a crate, CRATE_KIND = <kind>; make help shows the added targets.
  4. make update-all (here) propagates the result into the neighboring crates.
  5. Tests: a Makefile in the extension kit that runs its tests/*.sh with CRATE_KIT set; adopt a throwaway crate with crate-kit/adopt.sh --kit-src <extension> --kind, then check variables and targets (see template-kit/ and tests/fixtures/overlay/ of this repository). The scripts of overlay/kit/scripts/ load common.sh from their directory: run them in an assembled kit (tools/kit-assemble.sh <directory>), not from overlay/.
  6. The token and any secret stay out of the extension kit's repository (gitignored directory, excluded from synchronization); the repository contains only the path.

crate-kit tests itself with a fictitious extension (tests/fixtures/overlay, registry reg, kind noapi): it is the smallest complete example. Sharing rule: what would serve another project stays in crate-kit, only what makes sense solely for the organization goes down into the extension.

Developing the kit

Command Effect
make check script syntax and shellcheck (warnings and errors)
make test tests on throwaway mini-crates (fictitious overlay tests/fixtures/overlay), including kinds and the token; end to end: adoption, API snapshot, verdicts unchanged/additive/breaking, next version in 0.x and from 1.0
make ci check + test
make dist archive dist/crate-kit-<version>.tar.gz of the kit/ directory
make jjrelease ci, bump of kit/VERSION, notes, direct push of main (no PR), tag; the CI (.gitea/workflows/release.yaml) creates the Forgejo release and attaches the archive; same target in every extension kit (tools/kit-release.mk)

Increment kit/VERSION with each kit fix (jjrelease does it): make kit-version and the kit-update message only make sense if the number follows.

Required tools

Tool Role Installation
cargo-public-api public API listing, diff cargo install cargo-public-api --locked
cargo-semver-checks breaking change detection cargo install cargo-semver-checks --locked
jj + aliases auto-doc, release-notes commits, notes, push, release tags (tag.sh, tag-exists.sh) user's jj configuration
git only the ephemeral clone of the wiki repository by wiki.sh (locally and in the CI); never in the working copy —
cargo-doc-md rustdoc JSON → Markdown for the wiki (CI and make wiki) cargo install cargo-doc-md --locked
jq, curl Forgejo release creation (CI) system packages

Version number

make bump-version (called by jjpush and jjrelease) compares the public API with the last snapshot in api/:

Verdict Next version (0.x) Next version (≥ 1.0)
breaking (element removed or modified, or breakage seen by cargo-semver-checks) 0.y+1.0 x+1.0.0
additions only (additive) 0.y.z+1 x.y+1.0
API unchanged (unchanged) 0.y.z+1 x.y.z+1

cargo-semver-checks only reports breaking changes: additions are spotted by the text diff of cargo public-api (one more line, none fewer), whose count is carried into the release notes. RELEASE=x.y.z forces the version.

Each version has a snapshot: api/<version>.txt (readable, diffable) and api/<version>.json.gz (compressed rustdoc JSON, reference for cargo-semver-checks; uncompressed it exceeds 1 MB, a jj limit). The JSON format depends on the compiler: if a toolchain change makes it unreadable, regenerate the snapshots from the tagged sources.

Known limitations

  • Private registries are not supported by cargo-semver-checks: the reference is always a local snapshot, never the registry.
  • Behavior changes without a signature change are not seen.
  • A crate that depends on another crate of the private registry has not yet been proven with the kit.