@roomi-fields/grillhouse 0.28.2 → 0.28.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,5 +5,5 @@
5
5
  "author": {
6
6
  "name": "Romain Peyrichou"
7
7
  },
8
- "version": "0.28.2"
8
+ "version": "0.28.3"
9
9
  }
package/charte.md CHANGED
@@ -172,7 +172,8 @@ dossier.
172
172
 
173
173
  ## Outils
174
174
 
175
- - ⛔ **Des commandes sans invite** : tout fichier temporaire dans le scratchpad de session ;
175
+ - ⛔ **Des commandes sans invite** : tout fichier temporaire dans le scratchpad de session, ou
176
+ dans le dossier temporaire du ticket ;
176
177
  `env -C <dossier>` ou `git -C` à la place de `cd`, et le greffon refuse une commande qui
177
178
  commence par `cd` ; une suppression passe par un script node du
178
179
  scratchpad (`rmSync` de `node:fs`) sur un chemin nommé et lu ; un signal vise seulement un
@@ -191,6 +192,17 @@ dossier.
191
192
  qu'un test y laisse ; le module de chaque langage nomme son outil et porte cette garde. Ainsi le
192
193
  dossier temporaire, souvent un disque en mémoire que partagent les séances du poste, ne sature
193
194
  jamais.
195
+ - **Un fichier temporaire meurt avec son propriétaire** : une passe ou une séance hors ticket (la
196
+ nuit, une vérification) écrit sous un dossier temporaire à elle, retiré à sa fin, même
197
+ interrompue, et balayé par la suivante quand son processus est tué ; un agent écrit sous celui
198
+ de son ticket, que donne `npx grillhouse temporaire <ticket>`, qui vit le temps de son ticket,
199
+ d'une séance et d'une reprise à l'autre, gel compris, et part quand le ticket se ferme. Ce qu'un
200
+ agent doit avoir pour
201
+ reprendre vit dans la copie du ticket ou sa passation, jamais dans le seul dossier temporaire,
202
+ qui ne porte que ce qui se refait. Le dossier temporaire ne tient ni copie du dépôt, ni
203
+ `node_modules`, ni cache : un cache de compilation va sous `~/.cache/grillhouse/`. Une passe
204
+ lourde qui y trouve moins de 4 Go libres attend la place et dit ce qui l'occupe, le ticket
205
+ nommé. Ainsi le poste ne sature jamais son disque en mémoire.
194
206
  - **Main reste vert** : l'intégration exige un `npm run verifier` vert. Un test connu rouge se met
195
207
  en quarantaine dans le test lui-même (`it.skip` ou `it.fails`), avec le ticket qui le corrige.
196
208
  Ainsi chaque rouge a son ticket.
@@ -437,6 +437,23 @@ tests (typescript : la base de chaque lancement de Vitest, `mkdtempSync` retiré
437
437
  cargo : `tester` et `verifier`, le crate `tempfile`). Ainsi un essai oublié ne remplit jamais le
438
438
  dossier temporaire de la machine, et le test qui l'oublie est nommé.
439
439
 
440
+ **Un fichier temporaire meurt avec son propriétaire** : une base a pour propriétaire un
441
+ processus, un ticket ou un dossier, comme `PrivateTmp=` de systemd donne à un service un /tmp
442
+ détruit avec lui. Une passe et une séance hors ticket ont la base de leur processus. Le dossier
443
+ temporaire d'un ticket, `grillhouse-ticket-<id>/`, est celui de ses agents : le lanceur le donne à
444
+ chaque séance du ticket (son `TMPDIR`, `TMP` et `TEMP`, ses scratchpads et son dossier de travail
445
+ dedans), `npx grillhouse temporaire <ticket>` au superviseur pour ses sous-agents ; il reste d'une
446
+ séance et d'une reprise à l'autre, gel compris, et part avec les copies finies quand le ticket
447
+ est fermé, comme une politique de rétention fixée d'avance. Ce qu'un agent doit avoir pour reprendre vit dans
448
+ la copie du ticket ou sa passation, jamais dans le seul dossier temporaire. Les caches de compilation ne vivent jamais dans le dossier temporaire : sccache et uv sous
449
+ `~/.cache/grillhouse/` (`cacheDeCompilation`), comme l'output_base de Bazel, et un espace cargo
450
+ enraciné dans le dossier temporaire compile sous `~/.cache/grillhouse/cargo/`, balayé quand sa
451
+ racine n'est plus, vue de l'espace de processus qui l'a ouvert, ou, depuis l'hôte, après 7 jours
452
+ sans usage, comme un cache de GitHub Actions. Une passe lourde (le verrou de la machine, les tests de nuit) qui trouve moins
453
+ de 4 Go libres dans le dossier temporaire attend la place sous la borne du verrou et dit ce qui
454
+ l'occupe, le ticket dont le dossier tient la place nommé, au lieu d'échouer faute de place (la nuit du 2026-11-01 : 25 rouges, 8 Go de
455
+ scratchpads sur 16). Ainsi le disque en mémoire du poste ne sature jamais.
456
+
440
457
  **Le dossier du circuit appartient au ticket** : `.claude/worktrees/<ticket>.travail` vit autant
441
458
  que le ticket, comme l'espace de travail d'un pipeline ; aucun balayage n'y touche, la file
442
459
  l'efface à la clôture, `npx grillhouse retirer-copie` avec la copie d'un ticket fermé sans
@@ -696,7 +713,7 @@ la tâche `test` de Turborepo dépend de `build` : des tests qui ne compilent pa
696
713
  « construction de <crate> » de la preuve du rouge, et se jouent aux contrôles ; la vérification par cargo-deny,
697
714
  sous le verrou de la machine ; chaque commande qui compile (tests, vérification, typage, clippy)
698
715
  à travers sccache (`RUSTC_WRAPPER=sccache`), le cache de compilation de Mozilla qu'emploient
699
- Firefox et les CI Rust, son cache sous la maison (`~/.cache/sccache`), commun aux copies du poste
716
+ Firefox et les CI Rust, son cache sous la maison (`~/.cache/grillhouse/sccache`), commun aux copies du poste
700
717
  et que l'enveloppe ouvre en écriture : chaque copie garde son `target/`, sans le verrou que cargo
701
718
  pose sur un dossier commun, et ne recompile pas ce qu’une autre a compilé ; un serveur de sccache par copie et par espace de processus (`/proc/self/ns/pid`, que chaque enveloppe crée), sur un socket unix abstrait nommé d'après eux (`SCCACHE_SERVER_UDS`), puisque le serveur par défaut écoute 127.0.0.1:4226 pour toute la machine et que l'enveloppe partage le réseau ; ce serveur démarre avant chaque lancement de cargo qui compile, sous `/tmp` (celui de la machine, ou dans une enveloppe celui, vide, de la séance), car sccache 0.19.0 démarre le sien par un socket au chemin sous TMPDIR, refusé au-delà des 108 octets d'un chemin de socket, et le dossier temporaire d'une passe sous le dossier de travail d'une séance les dépasse ; un lanceur de rustc que le projet pose reste le sien, sans sccache, lu comme cargo le lit (l'environnement, puis `build.rustc-wrapper` des `.cargo/config.toml` du projet vers la racine, puis de `$CARGO_HOME`) ; sans sccache sur le PATH, ces commandes refusent avant cargo, en une ligne qui nomme `npx grillhouse maj` ; le refus, avant tout lancement de cargo, d'un espace dont git ne
702
719
  suit pas le Cargo.lock, comme `npm ci` refuse un projet sans package-lock.json : les tests, la
@@ -715,7 +732,7 @@ dans chaque paquet, leur rapport JUnit, le typage par `python -m compileall`, la
715
732
  `.python-version` ; le code-octet sous un seul `__pycache__` à la racine, PYTHONPYCACHEPREFIX, que
716
733
  l'enveloppe rend propre à la séance ; l'environnement de uv et le cache de pytest de chaque paquet
717
734
  sous `.venv/<dossier>` et `.pytest_cache/<dossier>` à la racine, que l'enveloppe ouvre en écriture
718
- avec `~/.cache/uv`, plutôt que dans le dossier du paquet, qu'une séance dont le plan ne l'écrit pas
735
+ avec le cache de uv, `~/.cache/grillhouse/uv` (UV_CACHE_DIR), plutôt que dans le dossier du paquet, qu'une séance dont le plan ne l'écrit pas
719
736
  ne pourrait écrire ; les Python de uv en lecture ; la garde des tailles des tests en Python, et celle
720
737
  du dossier temporaire, `tempfile` et jamais `mkdtemp` à la main ; l'index des interfaces, qu'il
721
738
  engendre comme cargo, et que l'index du noyau remplace dans un projet de plusieurs langages), ses
package/docs/INTERFACE.md CHANGED
@@ -142,7 +142,7 @@ noyau, et chaque réponse décrit sans agir, sauf `verifier` d'un fichier engend
142
142
  dépendances git, ses avis de sécurité et les fichiers de ses verrous et du cache de ses paquets
143
143
  écrits ; `~/.cargo/` (son `env`, que les shells sourcent, sa configuration, ses binaires) et
144
144
  `~/.rustup/` lus ; `python` : `.venv/` et `.pytest_cache/`, où ses commandes font écrire uv et pytest pour chaque
145
- paquet, et `~/.cache/uv/` écrits,
145
+ paquet, et `~/.cache/grillhouse/uv/` écrits,
146
146
  `__pycache__` propre (le code-octet de Python, sous un seul arbre à la racine), les Python de uv,
147
147
  `~/.local/share/uv/python/`, lus.
148
148
  - `droits` : les règles de Claude Code qui refusent à un rôle qui écrit l'outil de test lancé
@@ -235,7 +235,16 @@ qu'il emploie, et `scripts/jointure.d.ts` les type : le plan d'une enveloppe, l'
235
235
  passe et sa mesure, la base d'une passe (son dossier temporaire, nommé dans `TMPDIR`, `TMP` et
236
236
  `TEMP` ; la ligne de sa garde, qui nomme ce que les tests y laissent ; son retrait à
237
237
  l'interruption), la pression de la machine et son verrou, le dernier vert,
238
- les arbitrages d'un ticket, les fichiers sources d'un projet. Un module n'importe rien d'autre du noyau que ses entrées publiées
238
+ les arbitrages d'un ticket, les fichiers sources d'un projet. Pour le dossier temporaire et les
239
+ caches de compilation : `dansLeTemporaire(chemin, env)`, si un chemin est sous le dossier
240
+ temporaire (`TMPDIR`, celui du système, `/tmp`) ; `cacheDeCompilation(outil, env)`, le cache d'un
241
+ outil sous `${XDG_CACHE_HOME:-~/.cache}/grillhouse/<outil>`, jamais sous le dossier temporaire ;
242
+ `cacheDeLaRacine(outil, racine, env, { creer })`, le cache d'une construction enracinée sous le
243
+ dossier temporaire, balayé quand sa racine n'est plus, vue du même espace de processus, ou depuis l'hôte
244
+ après 7 jours sans usage, son seul
245
+ chemin quand `creer` est faux ;
246
+ `attendreDeLaPlace(options)`, l'attente de 4 Go libres dans le dossier temporaire avant une passe
247
+ lourde, qui nomme ce qui l'occupe et rend 75 à sa borne. Un module n'importe rien d'autre du noyau que ses entrées publiées
239
248
  (`./jointure`, `./paquets`, `./dette`, `./resultats`, `./conformite`).
240
249
 
241
250
  ## La conformité
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomi-fields/grillhouse",
3
- "version": "0.28.2",
3
+ "version": "0.28.3",
4
4
  "description": "Roomi's Grillhouse: the frame's scripts, called by one command, grillhouse <sous-commande>",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -44,7 +44,14 @@
44
44
  // - The line of each copy kept names the place it holds, as `du -sk` counts it (« 2,7 Go »).
45
45
  // - The branch of a copy removed goes (`git branch -D`), its content being HEAD's, on main; main
46
46
  // and a branch another copy holds stay.
47
- // - One line per copy removed or kept, on the output, which the night adds to its log. The exit is
47
+ // - The temporary directory of each closed ticket goes too (`grillhouse-ticket-<id>/` of the
48
+ // temporary directory, which the launcher gives each session of the ticket and
49
+ // `npx grillhouse temporaire <ticket>` the supervisor, `balayerLesTickets` of
50
+ // scripts/mesure/base-de-passe.mjs), as its copy goes; a ticket open, frozen or not, keeps it, as
51
+ // a retention policy fixed in advance. The closed tickets are read only when such a directory
52
+ // is there.
53
+ // - One line per copy removed or kept, and per ticket's temporary directory removed, on the
54
+ // output, which the night adds to its log. The exit is
48
55
  // 0 whatever is removed or kept: the removal never changes the night's verdict.
49
56
  import { spawnSync } from 'node:child_process';
50
57
  import { existsSync, lstatSync, realpathSync, rmSync } from 'node:fs';
@@ -52,6 +59,7 @@ import path from 'node:path';
52
59
  import { pathToFileURL } from 'node:url';
53
60
  import { PILOTE } from './fusion-du-changelog.mjs';
54
61
  import { langageDe } from './langages.mjs';
62
+ import { balayerLesTickets } from './mesure/base-de-passe.mjs';
55
63
 
56
64
  const RETIRER = path.join(import.meta.dirname, 'retirer-copie.sh');
57
65
  const PRINCIPALE = 'main';
@@ -322,19 +330,22 @@ function ignoresDuLangage(racine) {
322
330
 
323
331
  /**
324
332
  * The removal of the copies of the repository at <racine> (`retirerLesCopiesFinies`), the copy of
325
- * the night and the copies <garder> left out, the tickets read by bd: what the night and the end
326
- * of each circuit (scripts/circuit.mjs) run. Its lines.
333
+ * the night and the copies <garder> left out, the tickets read by bd, then of the temporary
334
+ * directories of its closed tickets (`balayerLesTickets`): what the night and the end of each
335
+ * circuit (scripts/circuit.mjs) run. Its lines.
327
336
  * @param {string} racine the main tree
328
337
  * @param {string[]} [garder]
329
338
  * @returns {string[]}
330
339
  */
331
340
  export function retirerLesCopiesDuDepot(racine, garder = []) {
332
- return retirerLesCopiesFinies(racine, {
341
+ const lignes = retirerLesCopiesFinies(racine, {
333
342
  garder: [path.join(racine, NUIT), ...garder],
334
343
  lireEnCours: () => tickets(racine, 'in_progress'),
335
344
  lireFermes: () => tickets(racine, 'closed'),
336
345
  ignorer: ignoresDuLangage(racine),
337
346
  });
347
+ const retires = balayerLesTickets(() => tickets(racine, 'closed'));
348
+ return [...lignes, ...retires.map(t => `✓ dossier temporaire du ticket ${t} retiré.`)];
338
349
  }
339
350
 
340
351
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
@@ -49,8 +49,9 @@
49
49
  // sudo's env_reset and bwrap's --clearenv give it: the base of a login session, claude's own
50
50
  // configuration and credentials (`ANTHROPIC_*`, `CLAUDE_CODE_OAUTH_TOKEN`), the author of its
51
51
  // comments at the ticket (`BEADS_ACTOR`, which bd reads), the npm cache it
52
- // mounts, `npm_config_ignore_scripts=true`, and `TMPDIR`, the session's working directory, where
53
- // `mktemp` and `os.tmpdir()` write. With it npm runs no lifecycle script (`npm install` leaves the
52
+ // mounts, `npm_config_ignore_scripts=true`, and `TMPDIR`, `TMP` and `TEMP`, the session's working
53
+ // directory, where `mktemp`, `os.tmpdir()` and Python's `tempfile` write: under a launch, in the
54
+ // temporary directory of the ticket (scripts/enveloppe/lancer.sh), which goes with the ticket. With it npm runs no lifecycle script (`npm install` leaves the
54
55
  // `prepare` that writes under the read-only `.git`; the launcher installs outside the session),
55
56
  // while `npm test` and `npm run <script>` still run their script, without its `pre` or `post`
56
57
  // (npm's `ignore-scripts`, docs/content/using-npm/config.md); no script of the frame has one. bwrap
@@ -221,7 +222,7 @@ function scratchpadsDe(copie, env = process.env) {
221
222
 
222
223
  // The working directory of a session in <copie> under the environment <env> of the launch:
223
224
  // `travail` in the copy's scratchpads, which the envelope mounts in writing. The envelope creates
224
- // it and names it in `TMPDIR`; the launcher names it in the instruction.
225
+ // it and names it in `TMPDIR`, `TMP` and `TEMP`; the launcher names it in the instruction.
225
226
  export function dossierDeTravail(copie, env = process.env) {
226
227
  return path.join(scratchpadsDe(copie, env), 'travail');
227
228
  }
@@ -230,8 +231,8 @@ export function dossierDeTravail(copie, env = process.env) {
230
231
  // variables and families that <env> holds, `npm_config_cache` set to the npm cache that the
231
232
  // envelope mounts in writing, `npm_config_ignore_scripts` set to `true` (npm runs no lifecycle
232
233
  // script: a `prepare` that writes under the read-only `.git` would fail `npm install`; the
233
- // launcher installs outside the session), `TMPDIR` set to the session's working directory
234
- // <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets>; with them, each tool of the
234
+ // launcher installs outside the session), `TMPDIR`, `TMP` and `TEMP` set to the session's working
235
+ // directory <travail>, and `GRILLHOUSE_ENVELOPPE` set to the plan <paquets>; with them, each tool of the
235
236
  // project <outils> (`grillhouse.outils`), its variable set to its path. Nothing else of <env>
236
237
  // enters.
237
238
  export function environnementDeLaSeance(env, { cacheNpm, paquets, travail, outils = {} }) {
@@ -246,6 +247,8 @@ export function environnementDeLaSeance(env, { cacheNpm, paquets, travail, outil
246
247
  npm_config_cache: cacheNpm,
247
248
  npm_config_ignore_scripts: 'true',
248
249
  TMPDIR: travail,
250
+ TMP: travail,
251
+ TEMP: travail,
249
252
  [VARIABLE]: ecrireLaListe(paquets),
250
253
  };
251
254
  }
@@ -80,7 +80,10 @@
80
80
  # --publie <plan>`, a command of the module of the copy's language, read in the prepared copy; a reading that fails stops the launch,
81
81
  # CODE_COPIE), then the
82
82
  # section « Ton dossier de travail », which names the session's working directory, where every
83
- # temporary file goes (`dossierDeTravail` of enveloppe.mjs, the envelope's TMPDIR), then the
83
+ # temporary file goes (`dossierDeTravail` of enveloppe.mjs, the envelope's TMPDIR, TMP and TEMP,
84
+ # in the temporary directory of the ticket, which the launcher opens once the call is judged and
85
+ # which stays from one session and one resumption to the next, removed when the ticket is
86
+ # closed, scripts/mesure/base-de-passe.mjs), then the
84
87
  # section « La construction échoue » when it fails. The prompt
85
88
  # carries « TON TICKET : <ticket> », which the role's locks read. The envelope is the sandbox, so
86
89
  # the session runs without permission prompts, under the rights and the context of its role
@@ -184,6 +187,13 @@ if node --input-type=module -e "import { lireEntrees } from '$ici/../integration
184
187
  echo "$refus" >&2
185
188
  exit "$CODE_COPIE"
186
189
  fi
190
+ # The temporary directory of the ticket (`ouvrirBaseDuTicket`, scripts/mesure/base-de-passe.mjs):
191
+ # TMPDIR, TMP and TEMP of the rest of the launch and of the session, whose scratchpads and working
192
+ # directory lie in it. It stays from one session and one resumption of the ticket to the next, and
193
+ # goes when the ticket is closed (scripts/copies-finies.mjs).
194
+ temporaire=$(node "$ici/../mesure/base-de-passe.mjs" "$ticket" 2>> "$journal") \
195
+ || { echo "⛔ Le dossier temporaire du ticket n'a pas pu s'ouvrir : voir $journal." >&2; exit "$CODE_COPIE"; }
196
+ export TMPDIR="$temporaire" TMP="$temporaire" TEMP="$temporaire"
187
197
  # The output of the session's build, when it fails, behind its first line, which says what failed
188
198
  # and what was built: the module's command `construire` writes it.
189
199
  echec=$(mktemp)
@@ -323,6 +323,18 @@ export function ecrireLaMesure(o: {
323
323
  }): void;
324
324
  /** Opens the base of a pass of the kind `genre` (scripts/mesure/base-de-passe.mjs). */
325
325
  export function ouvrirBase(genre: string, o?: { dans?: string }): unknown;
326
+ /** Whether `chemin` lies in a temporary directory under `env` (scripts/mesure/base-de-passe.mjs). */
327
+ export function dansLeTemporaire(chemin: string, env?: NodeJS.ProcessEnv): boolean;
328
+ /** The cache of compilation of `outil`, under `~/.cache/grillhouse/`, never in the temporary
329
+ * directory. */
330
+ export function cacheDeCompilation(outil: string, env?: NodeJS.ProcessEnv): string;
331
+ /** The cache of `outil` for the build rooted at `racine`, swept once `racine` is gone. */
332
+ export function cacheDeLaRacine(
333
+ outil: string,
334
+ racine: string,
335
+ env?: NodeJS.ProcessEnv,
336
+ o?: { creer?: boolean }
337
+ ): string;
326
338
  /** The line of the guard of a pass of tests, what its tests left in their temporary directory
327
339
  * named; null when they left nothing. */
328
340
  export function ligneDesRestes(restes: string[]): string | null;
@@ -354,6 +366,8 @@ export function mesure(racine: string, o?: { tout?: boolean; dans?: string }): u
354
366
  export class AttenteDeLaMachine extends Error {}
355
367
  /** Runs `faire` under the lock of the machine. */
356
368
  export function avecLaMachine(...args: unknown[]): unknown;
369
+ /** Waits for room in the temporary directory, as a heavy pass does before it plays. */
370
+ export function attendreDeLaPlace(o?: Record<string, unknown>): void;
357
371
  /** The source files of the project at `racine` under `dossier`, as paths from `racine`, what the
358
372
  * tools of its language write left out (scripts/sources.mjs). */
359
373
  export function sources(racine: string, dossier?: string): string[];
@@ -46,6 +46,7 @@ import { existsSync, readdirSync, statSync } from 'node:fs';
46
46
  import { createRequire } from 'node:module';
47
47
  import path from 'node:path';
48
48
  import { isDeepStrictEqual } from 'node:util';
49
+ import { cibleDeCompilation } from './sccache.mjs';
49
50
 
50
51
  // The loader of the optional peers this module reads when it needs them (smol-toml), under the
51
52
  // name by which knip reads a dependency.
@@ -63,8 +64,11 @@ export function metadonnees(racine) {
63
64
  if (!existsSync(path.join(racine, 'Cargo.toml'))) {
64
65
  return null;
65
66
  }
67
+ // The target directory cargo reports is the one the compilations use (./sccache.mjs), named
68
+ // without being made: a reading writes nothing in the home.
66
69
  const r = spawnSync('cargo', ['metadata', '--format-version', '1', '--no-deps', '--offline'], {
67
70
  cwd: racine,
71
+ env: { ...process.env, ...cibleDeCompilation(racine, process.env, { creer: false }) },
68
72
  encoding: 'utf8',
69
73
  maxBuffer: 256 * 1024 * 1024,
70
74
  });
@@ -48,7 +48,7 @@ import { elementsDuLot } from './elements-du-lot.mjs';
48
48
  import { enRetard, entreesDeLIndex, SORTIE } from './index-interfaces.mjs';
49
49
  import { miseAJour } from './mise-a-jour.mjs';
50
50
  import { squelette } from './squelette.mjs';
51
- import { CACHE } from './sccache.mjs';
51
+ import { CACHE, CIBLES } from './sccache.mjs';
52
52
  import { touches } from './touches.mjs';
53
53
  import { verdict } from './verdict.mjs';
54
54
 
@@ -70,7 +70,8 @@ export default {
70
70
  // registry's index and sources, the git dependencies, cargo-deny's advisories, and the files of
71
71
  // its locks and of the SQLite cache of its packages (`.package-cache`, `.package-cache-mutate`,
72
72
  // `.global-cache`), files without a trailing `/`; the cache of sccache, common to the copies
73
- // (./sccache.mjs), where a server of sccache the session starts writes. What it reads, read-only: its home, `~/.cargo`
73
+ // (./sccache.mjs), where a server of sccache the session starts writes; the targets of the
74
+ // workspaces rooted in the temporary directory, `~/.cache/grillhouse/cargo/` (./sccache.mjs). What it reads, read-only: its home, `~/.cargo`
74
75
  // (its binaries, its `env`, which the shells source, and its configuration stay unwritten), and
75
76
  // rustup's toolchains, `~/.rustup`. Measured on 2026-10-30: `cargo fetch --locked` of
76
77
  // osc-bridge in bwrap with these mounts alone, green, the cache of its packages written.
@@ -84,6 +85,7 @@ export default {
84
85
  '~/.cargo/.package-cache-mutate',
85
86
  '~/.cargo/.global-cache',
86
87
  CACHE,
88
+ CIBLES,
87
89
  ],
88
90
  propres: [],
89
91
  lues: ['~/.cargo/', '~/.rustup/'],
@@ -2,8 +2,14 @@
2
2
  // (`RUSTC_WRAPPER=sccache`) that Firefox and the CI of Rust use, which the update installs
3
3
  // (./binaires.json). Each copy keeps its own target directory, so that two compilations never wait
4
4
  // on the lock cargo takes on a target directory; sccache shares their compilations, its cache one
5
- // directory of the home (`SCCACHE_DIR`, ~/.cache/sccache, sccache's default on Linux, named so
6
- // that the envelope opens the same, ./index.mjs `sorties`), common to every copy of the machine.
5
+ // directory of the home (`SCCACHE_DIR`, ~/.cache/grillhouse/sccache, the frame's caches of
6
+ // compilation, `cacheDeCompilation` of scripts/mesure/base-de-passe.mjs, named so that the envelope
7
+ // opens the same, ./index.mjs `sorties`), common to every copy of the machine.
8
+ // - A workspace rooted in the temporary directory (a project of trial) builds out of it: its
9
+ // target directory is `CARGO_TARGET_DIR`, a cache of the root under ~/.cache/grillhouse/cargo/
10
+ // (`cacheDeLaRacine`), swept once the root is gone, as Bazel keeps its output_base under
11
+ // ~/.cache and never on a disk in memory; a `CARGO_TARGET_DIR` already set stays
12
+ // (`cibleDeCompilation`).
7
13
  // Every command of the module that compiles (tests, verification, typing, clippy) runs cargo
8
14
  // under this environment, in a copy as in an agent's envelope.
9
15
  //
@@ -37,12 +43,17 @@ import { accessSync, constants, readFileSync, readlinkSync, realpathSync } from
37
43
  import { createRequire } from 'node:module';
38
44
  import { homedir } from 'node:os';
39
45
  import path from 'node:path';
46
+ import { cacheDeCompilation, cacheDeLaRacine, dansLeTemporaire } from '../../services-du-noyau.mjs';
40
47
 
41
48
  // The loader of smol-toml, an optional peer of the package, a tool of this module.
42
49
  const require = createRequire(import.meta.url);
43
50
 
44
51
  /** The cache of sccache, from the home: what the envelope opens in writing. */
45
- export const CACHE = '~/.cache/sccache/';
52
+ export const CACHE = '~/.cache/grillhouse/sccache/';
53
+
54
+ /** The targets of the workspaces rooted in the temporary directory, from the home: what the
55
+ * envelope opens in writing (`cibleDeCompilation`). */
56
+ export const CIBLES = '~/.cache/grillhouse/cargo/';
46
57
 
47
58
  // The machine's temporary directory, short whatever the copy: the one the server of sccache starts
48
59
  // under (`demarrerLeServeur`), an empty one proper to the session in an envelope.
@@ -152,21 +163,41 @@ export function demarrerLeServeur(racine, env) {
152
163
  });
153
164
  }
154
165
 
166
+ /**
167
+ * The target directory of the workspace at <racine> under <env>, out of the temporary directory:
168
+ * `{ CARGO_TARGET_DIR }`, a cache of the root (`cacheDeLaRacine`), for a root in the temporary
169
+ * directory; nothing otherwise, or when <env> sets one already. With `creer` false, a reading
170
+ * (`cargo metadata`): the path alone, nothing written.
171
+ * @param {string} racine
172
+ * @param {NodeJS.ProcessEnv} env
173
+ * @param {{ creer?: boolean }} [options]
174
+ * @returns {{ CARGO_TARGET_DIR?: string }}
175
+ */
176
+ export function cibleDeCompilation(racine, env, { creer = true } = {}) {
177
+ if (env.CARGO_TARGET_DIR || !dansLeTemporaire(racine, env)) {
178
+ return {};
179
+ }
180
+ return { CARGO_TARGET_DIR: cacheDeLaRacine('cargo', racine, env, { creer }) };
181
+ }
182
+
155
183
  /**
156
184
  * <env> with rustc wrapped by sccache for the copy at <racine>, its cache the home's, its server
157
- * the copy's; <env> as it is when the project sets its own wrapper.
185
+ * the copy's, its target out of the temporary directory (`cibleDeCompilation`); without sccache
186
+ * when the project sets its own wrapper.
158
187
  * @param {string} racine
159
188
  * @param {NodeJS.ProcessEnv} env
160
189
  * @returns {NodeJS.ProcessEnv}
161
190
  */
162
191
  export function avecSccache(racine, env) {
192
+ const cible = cibleDeCompilation(racine, env);
163
193
  if (lanceurDuProjet(racine, env)) {
164
- return env;
194
+ return { ...env, ...cible };
165
195
  }
166
196
  return {
167
197
  ...env,
198
+ ...cible,
168
199
  RUSTC_WRAPPER: 'sccache',
169
- SCCACHE_DIR: path.join(env.HOME || homedir(), '.cache', 'sccache'),
200
+ SCCACHE_DIR: cacheDeCompilation('sccache', env),
170
201
  SCCACHE_SERVER_UDS: socketDuServeur(racine),
171
202
  };
172
203
  }
@@ -43,7 +43,8 @@
43
43
  // environment of each package under `.venv/<dossier>` at the root (UV_PROJECT_ENVIRONMENT), and
44
44
  // pytest its cache under `.pytest_cache/<dossier>` (`cache_dir`), where the envelope opens them
45
45
  // in writing, rather than in the package's folder, which a session whose plan does not write the
46
- // package could not write.
46
+ // package could not write; uv its cache under ~/.cache/grillhouse/uv (UV_CACHE_DIR), the frame's
47
+ // caches of compilation, never in the temporary directory.
47
48
  // - While the environment names a results directory (`GRILLHOUSE_RESULTATS`), the run writes
48
49
  // there what ./verdict.mjs reads: its tasks, each planned before it plays, and the JUnit report
49
50
  // of each run of pytest.
@@ -59,6 +60,7 @@ import { RESULTATS } from '../../resultats.mjs';
59
60
  import {
60
61
  AttenteDeLaMachine,
61
62
  avecLaMachine,
63
+ cacheDeCompilation,
62
64
  CHANGEMENTS,
63
65
  DEPUIS_LE_VERT,
64
66
  garderLeVert,
@@ -113,7 +115,12 @@ function passe(racine, env) {
113
115
  const id = `${Date.now()}-${process.pid}`;
114
116
  const taches = [];
115
117
  const rapports = {};
116
- const environnement = { ...env, PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE) };
118
+ // uv keeps its cache with the frame's caches of compilation, out of the temporary directory.
119
+ const environnement = {
120
+ ...env,
121
+ PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE),
122
+ UV_CACHE_DIR: cacheDeCompilation('uv', env),
123
+ };
117
124
  const ecrire = () => {
118
125
  if (!dossier) {
119
126
  return;
@@ -11,7 +11,8 @@
11
11
  // `.pytest_cache`, `__pycache__` (`ignorer`).
12
12
  // - Where they write, which the envelope opens to a session (`sorties`): in writing, `.venv` and
13
13
  // `.pytest_cache` at the root, where the commands make uv and pytest write for each package
14
- // (./commandes.mjs), and uv's cache, `~/.cache/uv`; proper to the session, the
14
+ // (./commandes.mjs), and uv's cache, `~/.cache/grillhouse/uv` (UV_CACHE_DIR, ./commandes.mjs: the
15
+ // frame's caches of compilation, never in the temporary directory); proper to the session, the
15
16
  // tree of the bytecode at the root, `__pycache__` (PYTHONPYCACHEPREFIX, ./commandes.mjs); read,
16
17
  // the Pythons uv installs, `~/.local/share/uv/python`. The version of Python is uv's choice, from
17
18
  // `requires-python` and `.python-version`. The rules that refuse a role that writes pytest run
@@ -56,7 +57,7 @@ export default {
56
57
  binaires: JSON.parse(readFileSync(ici('binaires.json'), 'utf8')),
57
58
  ignorer: ['.venv', '.pytest_cache', PYCACHE],
58
59
  sorties: {
59
- ecrites: ['.venv/', '.pytest_cache/', '~/.cache/uv/'],
60
+ ecrites: ['.venv/', '.pytest_cache/', '~/.cache/grillhouse/uv/'],
60
61
  propres: [PYCACHE],
61
62
  lues: ['~/.local/share/uv/python/'],
62
63
  },
@@ -13,10 +13,13 @@
13
13
  // the copy, a bench or a night test alone as well: `npx --no-install vitest run --root <copie>
14
14
  // --config <configuration>`. Its exit code is this command's: 75, « à repasser », when every
15
15
  // failure depended on a duration, one under load (./vitest-config/duree.reporter.mjs).
16
+ // - They play once the temporary directory has room, as every heavy pass
17
+ // (`attendreDeLaPlace` of scripts/verrou-de-machine.mjs): a wait that reaches its bound ends at 75.
16
18
  import { spawnSync } from 'node:child_process';
17
19
  import { readdirSync } from 'node:fs';
18
20
  import path from 'node:path';
19
21
  import { fileURLToPath, pathToFileURL } from 'node:url';
22
+ import { attendreDeLaPlace } from '../../services-du-noyau.mjs';
20
23
 
21
24
  const CONFIGURATION = fileURLToPath(new URL('./vitest.nuit.config.mjs', import.meta.url));
22
25
  const HORS = new Set(['node_modules', 'dist', '.git']);
@@ -44,6 +47,13 @@ export function testsDeNuit(racine) {
44
47
  if (!enTient(racine)) {
45
48
  return 0;
46
49
  }
50
+ try {
51
+ attendreDeLaPlace();
52
+ } catch (e) {
53
+ if (e?.name !== 'AttenteDeLaMachine') throw e;
54
+ process.stdout.write(`${e.message}\n`);
55
+ return e.code;
56
+ }
47
57
  const r = spawnSync(
48
58
  'npx',
49
59
  ['--no-install', 'vitest', 'run', '--root', racine, '--config', CONFIGURATION],
@@ -3,7 +3,9 @@
3
3
  // directory named after its process and a token, scripts/verrou-de-machine.mjs), which every
4
4
  // process it starts inherits: a `npm run verifier` or a circuit that a test plays in a repository
5
5
  // of trial neither waits for the lock of the machine nor holds it, and no test writes in the
6
- // user's cache. A lock already named in the environment stays.
6
+ // user's cache. A lock already named in the environment stays. Its heavy passes want no room in
7
+ // the temporary directory (GRILLHOUSE_TEMPORAIRE_LIBRE, 0): the room of the machine is the pass's
8
+ // that plays the file, which waited for it.
7
9
  import { randomUUID } from 'node:crypto';
8
10
  import { tmpdir } from 'node:os';
9
11
  import path from 'node:path';
@@ -12,3 +14,4 @@ process.env.GRILLHOUSE_VERROU_MACHINE ||= path.join(
12
14
  tmpdir(),
13
15
  `grillhouse-mesure-${process.pid}-${randomUUID()}.lock`
14
16
  );
17
+ process.env.GRILLHOUSE_TEMPORAIRE_LIBRE ||= '0';
@@ -17,6 +17,23 @@
17
17
  // beside its copy, which no sweep touches); `integration`, the working directory of an
18
18
  // integration (scripts/integration/integrer.mjs); `enveloppe`, the throwaway state of a session's envelope
19
19
  // (scripts/enveloppe/enveloppe.mjs).
20
+ // - The owner of a base is the process that opens it, for a pass and a session out of a ticket
21
+ // (the night, a verification); a ticket (`ouvrirBaseDuTicket`: `<dans>/grillhouse-ticket-<id>/`,
22
+ // the temporary directory of the agents of one ticket, which the launcher gives each session of
23
+ // the ticket, scripts/enveloppe/lancer.sh, and `npx grillhouse temporaire <ticket>` the
24
+ // supervisor), kept from one session and one resumption to the next, removed when its ticket is
25
+ // closed (`balayerLesTickets`, which the removal of the finished copies plays,
26
+ // scripts/copies-finies.mjs), as a finished copy goes, and only then, frozen or not, as a
27
+ // retention policy fixed in advance; or a directory
28
+ // (`cacheDeLaRacine`: the cache of a build rooted in the temporary directory), swept once that
29
+ // directory is gone, from the namespace that opened it, or, from the host (the next base of a
30
+ // pass, out of an envelope, where the home is read-only), untouched for 7 days whatever its
31
+ // namespace, as GitHub Actions removes a cache unused for 7 days. What an agent needs to resume lives in its copy or its handover, never in
32
+ // the ticket's temporary directory alone, which holds what is made again.
33
+ // - The caches of compilation never lie in the temporary directory, a disk in memory that the
34
+ // sessions of the machine share: they go under `${XDG_CACHE_HOME:-~/.cache}/grillhouse/<outil>`
35
+ // (`cacheDeCompilation`), as Bazel keeps its output_base under ~/.cache; a build rooted in the
36
+ // temporary directory (a project of trial) keeps its outputs there too (`cacheDeLaRacine`).
20
37
  // - The base is removed at the end of the pass, green or red (`fermer`), and when the pass is
21
38
  // interrupted (SIGINT, SIGTERM, SIGHUP: `retirerALInterruption`), as pytest's `tmp_path` and
22
39
  // Rust's `tempfile` remove theirs.
@@ -29,17 +46,22 @@
29
46
  // namespace of the sweeper (an envelope has its own, bwrap --unshare-pid, where a number means
30
47
  // nothing outside): a base of another namespace, a base without a readable owner (one being
31
48
  // created) and a base whose owner lives are never touched.
49
+ import { createHash } from 'node:crypto';
32
50
  import {
51
+ existsSync,
33
52
  mkdirSync,
34
53
  mkdtempSync,
35
54
  readdirSync,
36
55
  readFileSync,
37
56
  readlinkSync,
38
57
  rmSync,
58
+ statSync,
59
+ utimesSync,
39
60
  writeFileSync,
40
61
  } from 'node:fs';
41
- import { tmpdir } from 'node:os';
62
+ import { homedir, tmpdir } from 'node:os';
42
63
  import path from 'node:path';
64
+ import { pathToFileURL } from 'node:url';
43
65
 
44
66
  // The prefix of a base's name, and the file of its owner.
45
67
  const PREFIXE = 'grillhouse-';
@@ -84,20 +106,31 @@ function espace() {
84
106
  }
85
107
  }
86
108
 
87
- // Whether the base <base> is an orphan: its owner reads, lives in this namespace, and is gone.
88
- function orpheline(base) {
89
- let p;
109
+ // The owner of the base <base>, or null when it does not read.
110
+ function proprietaire(base) {
90
111
  try {
91
- p = JSON.parse(readFileSync(path.join(base, PROPRIETAIRE), 'utf8'));
112
+ return JSON.parse(readFileSync(path.join(base, PROPRIETAIRE), 'utf8'));
92
113
  } catch {
93
- return false;
114
+ return null;
94
115
  }
116
+ }
117
+
118
+ // Whether the base <base> is an orphan: its owner, a directory or a process, belongs to this
119
+ // namespace of processes and is gone; a directory another namespace sees (an envelope's private
120
+ // /tmp) or a process of another namespace is never judged here. A ticket's base goes with its
121
+ // ticket (`balayerLesTickets`).
122
+ function orpheline(base) {
123
+ const p = proprietaire(base);
95
124
  const ici = espace();
96
- return ici !== null && p.espace === ici && Number.isInteger(p.pid) && !vivant(p.pid);
125
+ if (p === null || ici === null || p.espace !== ici) return false;
126
+ if (typeof p.racine === 'string') return !existsSync(p.racine);
127
+ return Number.isInteger(p.pid) && !vivant(p.pid);
97
128
  }
98
129
 
99
130
  // Removes every orphan base in <dans>.
100
- function balayer(dans) {
131
+ // <vieilles> true (on the host): a base of a cache of a root untouched for AGE_DU_CACHE_MS goes too,
132
+ // whatever namespace opened it.
133
+ function balayer(dans, { vieilles = false } = {}) {
101
134
  let noms;
102
135
  try {
103
136
  noms = readdirSync(dans);
@@ -106,10 +139,36 @@ function balayer(dans) {
106
139
  }
107
140
  for (const nom of noms) {
108
141
  const base = path.join(dans, nom);
109
- if (nom.startsWith(PREFIXE) && orpheline(base)) rmSync(base, { recursive: true, force: true });
142
+ if (nom.startsWith(PREFIXE) && (orpheline(base) || (vieilles && vieille(base))))
143
+ rmSync(base, { recursive: true, force: true });
144
+ }
145
+ }
146
+
147
+ /** How long a cache of a root lives untouched: 7 days, as GitHub Actions keeps a cache unused. */
148
+ export const AGE_DU_CACHE_MS = 7 * 24 * 3600 * 1000;
149
+
150
+ // Whether <base> is a base of a cache of a root untouched (its directory's mtime) for
151
+ // AGE_DU_CACHE_MS.
152
+ function vieille(base) {
153
+ if (typeof proprietaire(base)?.racine !== 'string') return false;
154
+ try {
155
+ return Date.now() - statSync(base).mtimeMs > AGE_DU_CACHE_MS;
156
+ } catch {
157
+ return false;
110
158
  }
111
159
  }
112
160
 
161
+ // Whether <env> is an agent's envelope, where the home is read-only (scripts/enveloppe/).
162
+ const enEnveloppe = env => Boolean(env.GRILLHOUSE_ENVELOPPE);
163
+
164
+ // The sweep of the caches of the roots under <env> (`cacheDeLaRacine`, in each tool's directory of
165
+ // the frame's caches), from the host only: the orphans and the old ones.
166
+ function balayerLesCaches(env) {
167
+ if (enEnveloppe(env)) return;
168
+ const racine = path.dirname(cacheDeCompilation('-', env));
169
+ for (const outil of contenu(racine)) balayer(path.join(racine, outil), { vieilles: true });
170
+ }
171
+
113
172
  // The variables that name the temporary directory: TMPDIR (POSIX, Node, Rust), TMP and TEMP
114
173
  // (Windows, Python's `tempfile`).
115
174
  const TEMPORAIRES = ['TMPDIR', 'TMP', 'TEMP'];
@@ -167,6 +226,7 @@ export function retirerALInterruption(retirer) {
167
226
  */
168
227
  export function ouvrirBase(genre, { dans = tmpdir() } = {}) {
169
228
  balayer(dans);
229
+ balayerLesCaches(process.env);
170
230
  mkdirSync(dans, { recursive: true });
171
231
  const base = mkdtempSync(path.join(dans, `${PREFIXE}${genre}-`));
172
232
  writeFileSync(
@@ -183,3 +243,136 @@ export function ouvrirBase(genre, { dans = tmpdir() } = {}) {
183
243
  fermer: () => rmSync(base, { recursive: true, force: true }),
184
244
  };
185
245
  }
246
+
247
+ // The prefix of the base of a ticket, and the form of a ticket's id.
248
+ const DU_TICKET = `${PREFIXE}ticket-`;
249
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
250
+
251
+ /**
252
+ * The base of the ticket <ticket> in <dans>: `<dans>/grillhouse-ticket-<ticket>/`, its owner the
253
+ * ticket, made when absent and the same at each call; the temporary directory of the agents of
254
+ * one ticket, kept from one session to the next, removed when it is closed (`balayerLesTickets`).
255
+ * @param {string} ticket the ticket's id
256
+ * @param {{ dans?: string }} options `dans`, the directory of the base (`os.tmpdir()`)
257
+ * @returns {{ base: string, dossier: string }} the base, and the directory its agents write in
258
+ */
259
+ export function ouvrirBaseDuTicket(ticket, { dans = tmpdir() } = {}) {
260
+ if (!ID.test(ticket)) throw new Error(`⛔ « ${ticket} » n'est pas l'identifiant d'un ticket.`);
261
+ const base = path.join(dans, `${DU_TICKET}${ticket}`);
262
+ const dossier = path.join(base, 't');
263
+ mkdirSync(dossier, { recursive: true });
264
+ if (proprietaire(base) === null) {
265
+ writeFileSync(path.join(base, PROPRIETAIRE), `${JSON.stringify({ ticket })}\n`);
266
+ }
267
+ return { base, dossier };
268
+ }
269
+
270
+ /**
271
+ * Removes from <dans> the base of each ticket that is closed; the ids of the tickets whose base
272
+ * went. A ticket open, frozen or not, keeps its base, as a retention policy fixed in advance.
273
+ * <fermes> reads the closed tickets, null when they do not read: called once, and only when a
274
+ * ticket's base is there.
275
+ * @param {() => Set<string> | null} fermes
276
+ * @param {{ dans?: string }} options `dans`, the directory of the bases (`os.tmpdir()`)
277
+ * @returns {string[]}
278
+ */
279
+ export function balayerLesTickets(fermes, { dans = tmpdir() } = {}) {
280
+ const tickets = contenu(dans)
281
+ .filter(n => n.startsWith(DU_TICKET))
282
+ .map(n => ({ base: path.join(dans, n), ticket: proprietaire(path.join(dans, n))?.ticket }))
283
+ .filter(b => typeof b.ticket === 'string');
284
+ if (tickets.length === 0) return [];
285
+ const clos = fermes();
286
+ if (clos === null) return [];
287
+ const retires = tickets.filter(b => clos.has(b.ticket));
288
+ for (const b of retires) rmSync(b.base, { recursive: true, force: true });
289
+ return retires.map(b => b.ticket);
290
+ }
291
+
292
+ /**
293
+ * The ticket whose base is the entry <nom> of the temporary directory, or null.
294
+ * @param {string} nom
295
+ */
296
+ export function ticketDeLaBase(nom) {
297
+ return nom.startsWith(DU_TICKET) ? nom.slice(DU_TICKET.length) : null;
298
+ }
299
+
300
+ // Whether <chemin> lies in <dossier> or is it.
301
+ const sous = (chemin, dossier) => {
302
+ const rel = path.relative(dossier, chemin);
303
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
304
+ };
305
+
306
+ // The temporary directories under <env>: the one it names, the system's, and /tmp.
307
+ const temporaires = env =>
308
+ [env.TMPDIR || env.TMP || env.TEMP, tmpdir(), '/tmp'].filter(Boolean).map(d => path.resolve(d));
309
+
310
+ /**
311
+ * Whether <chemin> lies in a temporary directory under <env> (`TMPDIR`, `os.tmpdir()`, `/tmp`).
312
+ * @param {string} chemin
313
+ * @param {Record<string, string | undefined>} [env]
314
+ */
315
+ export function dansLeTemporaire(chemin, env = process.env) {
316
+ return temporaires(env).some(t => sous(path.resolve(chemin), t));
317
+ }
318
+
319
+ /**
320
+ * The cache of compilation of <outil> under <env>: `${XDG_CACHE_HOME:-$HOME/.cache}/grillhouse/
321
+ * <outil>`, as the lock of the machine lives there (scripts/verrou-de-machine.mjs).
322
+ * @param {string} outil `sccache`, `uv`, `cargo`…
323
+ * @param {Record<string, string | undefined>} [env]
324
+ */
325
+ export function cacheDeCompilation(outil, env = process.env) {
326
+ const cache = env.XDG_CACHE_HOME || path.join(env.HOME || homedir(), '.cache');
327
+ return path.join(path.resolve(cache), 'grillhouse', outil);
328
+ }
329
+
330
+ /**
331
+ * The cache of <outil> for the build rooted at <racine>: `<cacheDeCompilation(outil)>/
332
+ * grillhouse-<empreinte of racine>/`, its owner <racine> and the namespace of processes that
333
+ * opened it, made when absent; the caches of the roots that this namespace sees gone are swept
334
+ * first, and from the host the ones untouched for 7 days, whatever their namespace (`AGE_DU_CACHE_MS`,
335
+ * as GitHub Actions and cargo-sweep); each use renews its age. With `creer` false, its path alone, nothing made nor swept (a reading, `cargo metadata`).
336
+ * @param {string} outil
337
+ * @param {string} racine
338
+ * @param {Record<string, string | undefined>} [env]
339
+ */
340
+ export function cacheDeLaRacine(outil, racine, env = process.env, { creer = true } = {}) {
341
+ const dans = cacheDeCompilation(outil, env);
342
+ const reelle = path.resolve(racine);
343
+ const empreinte = createHash('sha256').update(reelle).digest('hex').slice(0, 16);
344
+ const cache = path.join(dans, `${PREFIXE}${empreinte}`);
345
+ if (!creer) return cache;
346
+ if (enEnveloppe(env)) balayer(dans);
347
+ else balayerLesCaches(env);
348
+ mkdirSync(cache, { recursive: true });
349
+ // A use renews it: its age counts from the last.
350
+ const maintenant = new Date();
351
+ utimesSync(cache, maintenant, maintenant);
352
+ if (proprietaire(cache) === null) {
353
+ writeFileSync(
354
+ path.join(cache, PROPRIETAIRE),
355
+ `${JSON.stringify({ racine: reelle, espace: espace() })}\n`
356
+ );
357
+ }
358
+ return cache;
359
+ }
360
+
361
+ // `npx grillhouse temporaire <ticket>`: prints the directory of the ticket's agents.
362
+ function commande(argv) {
363
+ if (argv.length !== 1 || argv[0].startsWith('-')) {
364
+ process.stderr.write('usage: npx grillhouse temporaire <ticket>\n');
365
+ return 2;
366
+ }
367
+ try {
368
+ process.stdout.write(`${ouvrirBaseDuTicket(argv[0]).dossier}\n`);
369
+ return 0;
370
+ } catch (e) {
371
+ process.stderr.write(`${e.message}\n`);
372
+ return 2;
373
+ }
374
+ }
375
+
376
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
377
+ process.exitCode = commande(process.argv.slice(2));
378
+ }
@@ -18,7 +18,14 @@ export { sources } from './sources.mjs';
18
18
  export { CHANGEMENTS, DEPUIS_LE_VERT, garderLeVert, mesure } from './dernier-vert.mjs';
19
19
  export { lireLaListe, paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
20
20
  export { AVANCEMENT, ecrireTache } from './mesure/avancement.mjs';
21
- export { ligneDesRestes, ouvrirBase, retirerALInterruption } from './mesure/base-de-passe.mjs';
21
+ export {
22
+ cacheDeCompilation,
23
+ cacheDeLaRacine,
24
+ dansLeTemporaire,
25
+ ligneDesRestes,
26
+ ouvrirBase,
27
+ retirerALInterruption,
28
+ } from './mesure/base-de-passe.mjs';
22
29
  export {
23
30
  A_REPASSER,
24
31
  attendreLeRepos,
@@ -27,4 +34,4 @@ export {
27
34
  lirePression,
28
35
  SEUIL_PRESSION,
29
36
  } from './mesure/pression.mjs';
30
- export { AttenteDeLaMachine, avecLaMachine } from './verrou-de-machine.mjs';
37
+ export { attendreDeLaPlace, AttenteDeLaMachine, avecLaMachine } from './verrou-de-machine.mjs';
@@ -52,6 +52,7 @@ export const SOUS_COMMANDES = {
52
52
  'structure-guard': 'structure-guard.sh',
53
53
  superviseur: 'superviseur.mjs',
54
54
  tableau: 'tableau.mjs',
55
+ temporaire: 'mesure/base-de-passe.mjs',
55
56
  tests: { langage: 'tester' },
56
57
  ticket: 'ticket.sh',
57
58
  'ticket-du-sous-agent': 'verrous/ticket-du-sous-agent.mjs',
@@ -48,27 +48,43 @@
48
48
  // names no one and goes. Between measures of one rank, the first to find the lock free takes
49
49
  // it. The bound of the wait is the same for both ranks, and the wait says its rank.
50
50
  // - The lock is let go at the end of the measure, whether it succeeds or throws.
51
+ // - A measure first wants room in the temporary directory (`os.tmpdir()` under its environment),
52
+ // a disk in memory that the sessions of the machine share: under LIBRE_MIN, 4 GB free
53
+ // (GRILLHOUSE_TEMPORAIRE_LIBRE names another floor, in bytes; the base configuration of the
54
+ // tests sets 0, scripts/langages/typescript/vitest-config/machine.setup.mjs), it waits for room
55
+ // instead of failing for lack of it (ENOSPC: 25 reds of the night of 2026-11-01, the
56
+ // scratchpads holding 8 GB of 16), as Kubernetes schedules no new pod on a node under
57
+ // DiskPressure. It says so, with what holds the directory (its largest
58
+ // entries, by the blocks their files hold, the temporary directory of a ticket naming its
59
+ // ticket), when it begins and every 30 s, under the same bound as the
60
+ // lock's, then « à repasser » (75).
51
61
  import { randomUUID } from 'node:crypto';
52
62
  import {
63
+ lstatSync,
53
64
  mkdirSync,
54
65
  readdirSync,
55
66
  readFileSync,
56
67
  readlinkSync,
57
68
  rmSync,
69
+ statfsSync,
58
70
  statSync,
59
71
  writeFileSync,
60
72
  } from 'node:fs';
61
- import { homedir } from 'node:os';
73
+ import { homedir, tmpdir } from 'node:os';
62
74
  import path from 'node:path';
63
75
  import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
64
76
  import { paquets } from './paquets.mjs';
65
77
  import { attendreUnPeu, lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
66
- import { vivant } from './mesure/base-de-passe.mjs';
78
+ import { ticketDeLaBase, vivant } from './mesure/base-de-passe.mjs';
67
79
  import { A_REPASSER } from './mesure/pression.mjs';
68
80
 
69
81
  const VARIABLE_VERROU = 'GRILLHOUSE_VERROU_MACHINE';
70
82
  const VARIABLE_TENUE = 'GRILLHOUSE_MESURE_TENUE';
71
83
  const VARIABLE_ATTENTE = 'GRILLHOUSE_ATTENTE_MACHINE_MS';
84
+ const VARIABLE_LIBRE = 'GRILLHOUSE_TEMPORAIRE_LIBRE';
85
+
86
+ /** The room a heavy measure wants free in the temporary directory, in bytes: 4 GB. */
87
+ export const LIBRE_MIN = 4 * 1024 ** 3;
72
88
 
73
89
  // The name of the frame's package, which a repository of the first rank develops.
74
90
  const CADRE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).name;
@@ -227,6 +243,128 @@ function ancetre(pid) {
227
243
  return false;
228
244
  }
229
245
 
246
+ // The floor of room under <env>, in bytes.
247
+ function plancherDe(env) {
248
+ const n = Number(env[VARIABLE_LIBRE]);
249
+ return env[VARIABLE_LIBRE] && Number.isFinite(n) && n >= 0 ? n : LIBRE_MIN;
250
+ }
251
+
252
+ // The room free in <dossier>, in bytes; Infinity when it does not read.
253
+ function libreDans(dossier) {
254
+ try {
255
+ const s = statfsSync(dossier);
256
+ return s.bavail * s.bsize;
257
+ } catch {
258
+ return Infinity;
259
+ }
260
+ }
261
+
262
+ const go = octets => `${(octets / 1024 ** 3).toFixed(1).replace('.', ',')} Go`;
263
+
264
+ // The entries a count of what holds the temporary directory reads at most, so that it stays
265
+ // short on a directory of millions of files: past it, a size is a floor.
266
+ const ENTREES_LUES = 500_000;
267
+
268
+ // The largest entries of <dossier>, the five first, each by the blocks its files hold, as `du`
269
+ // counts them: « claude-1000 (8,0 Go), grillhouse-vitest-x (1,2 Go) ».
270
+ function occupants(dossier) {
271
+ let noms;
272
+ try {
273
+ noms = readdirSync(dossier);
274
+ } catch {
275
+ return 'illisible';
276
+ }
277
+ if (noms.length === 0) return 'rien';
278
+ let budget = ENTREES_LUES;
279
+ const taille = racine => {
280
+ let octets = 0;
281
+ const pile = [racine];
282
+ while (pile.length > 0 && budget-- > 0) {
283
+ const p = pile.pop();
284
+ let e;
285
+ try {
286
+ e = lstatSync(p);
287
+ } catch {
288
+ continue;
289
+ }
290
+ octets += e.blocks * 512;
291
+ if (e.isDirectory()) {
292
+ try {
293
+ for (const n of readdirSync(p)) pile.push(path.join(p, n));
294
+ } catch {
295
+ // an unreadable directory counts for itself alone
296
+ }
297
+ }
298
+ }
299
+ return octets;
300
+ };
301
+ return noms
302
+ .map(nom => ({ nom, octets: taille(path.join(dossier, nom)) }))
303
+ .sort((a, b) => b.octets - a.octets)
304
+ .slice(0, 5)
305
+ .map(o => {
306
+ const ticket = ticketDeLaBase(o.nom);
307
+ return `${o.nom} (${ticket ? `le ticket ${ticket}, ` : ''}${go(o.octets)})`;
308
+ })
309
+ .join(', ');
310
+ }
311
+
312
+ // Waits until <dossier> holds <plancher> bytes free (`libre`, a statfs at each turn), saying so
313
+ // (`dire`) with what holds it (`occupe`, counted only when a line is written) when it begins and
314
+ // every <rappelMs>. Throws an AttenteDeLaMachine (75) at <borneMs>.
315
+ function attendreLaPlace(dossier, { plancher, libre, occupe, dire, borneMs, rappelMs }) {
316
+ const debut = Date.now();
317
+ let dit = null;
318
+ for (;;) {
319
+ const l = libre(dossier);
320
+ if (l >= plancher) {
321
+ if (dit !== null)
322
+ dire(`✓ place dans le dossier temporaire après ${duree(Date.now() - debut)}.`);
323
+ return;
324
+ }
325
+ const t = Date.now();
326
+ const etat = () =>
327
+ `le dossier temporaire (${dossier}) n'a que ${go(l)} libres, moins des ${go(plancher)} qu'une passe lourde demande (${VARIABLE_LIBRE}) ; l'occupent : ${occupe(dossier)}`;
328
+ if (t - debut >= borneMs)
329
+ throw new AttenteDeLaMachine(
330
+ `⏱ attente de place bornée à ${duree(borneMs)} (${VARIABLE_ATTENTE}) : ${etat()} ; à repasser (code ${A_REPASSER}).`,
331
+ A_REPASSER
332
+ );
333
+ if (dit === null) dire(`⏳ ${etat()} ; attente de place, ${duree(borneMs)} au plus.`);
334
+ else if (t - dit >= rappelMs)
335
+ dire(`⏳ attente de place depuis ${duree(t - debut)} : ${etat()}.`);
336
+ if (dit === null || t - dit >= rappelMs) dit = t;
337
+ attendreUnPeu(Math.max(1, Math.min(200, borneMs - (Date.now() - debut))));
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Waits for room in the temporary directory under <env> (`os.tmpdir()` as it reads it): what a
343
+ * heavy pass does before it plays (`avecLaMachine`, the night tests).
344
+ * @param {{ env?: Record<string, string | undefined>, dire?: (ligne: string) => void,
345
+ * borneMs?: number, rappelMs?: number, libre?: (dossier: string) => number,
346
+ * occupe?: (dossier: string) => string }} [options] as `avecLaMachine`'s
347
+ * @throws {AttenteDeLaMachine} at the bound of the wait (code 75)
348
+ */
349
+ export function attendreDeLaPlace({
350
+ env = process.env,
351
+ dire = l => process.stdout.write(`${l}\n`),
352
+ borneMs = borneDe(env),
353
+ rappelMs = RAPPEL_MS,
354
+ libre = libreDans,
355
+ occupe = occupants,
356
+ } = {}) {
357
+ const temporaire = env.TMPDIR || env.TMP || env.TEMP || tmpdir();
358
+ attendreLaPlace(temporaire, {
359
+ plancher: plancherDe(env),
360
+ libre,
361
+ occupe,
362
+ dire,
363
+ borneMs,
364
+ rappelMs,
365
+ });
366
+ }
367
+
230
368
  // The bound of the wait under <env>, in ms.
231
369
  function borneDe(env) {
232
370
  const n = Number(env[VARIABLE_ATTENTE]);
@@ -282,11 +420,13 @@ function attendreAuRang(verrou, { rang, dire, borneMs, rappelMs }) {
282
420
  * environment of its children, which carries the lock to them.
283
421
  * @param {(envEnfant: Record<string, string | undefined>) => T} mesure a synchronous measure
284
422
  * @param {{ env?: Record<string, string | undefined>, racine?: string,
285
- * dire?: (ligne: string) => void, borneMs?: number, rappelMs?: number }} options `racine`, the
423
+ * dire?: (ligne: string) => void, borneMs?: number, rappelMs?: number,
424
+ * libre?: (dossier: string) => number, occupe?: (dossier: string) => string }} options `racine`, the
286
425
  * root of the repository the measure plays in, which gives its rank (`rangDeLaMesure`; the
287
426
  * working directory by default); `borneMs`, the bound of the wait
288
427
  * (GRILLHOUSE_ATTENTE_MACHINE_MS, else ATTENTE_MACHINE_MS); `rappelMs`, the gap between two
289
- * lines that say the wait goes on (30 s)
428
+ * lines that say the wait goes on (30 s); `libre`, the room free in a directory, in bytes
429
+ * (`statfs`, at each turn); `occupe`, what holds it, counted when a line of the wait is written
290
430
  * @returns {T}
291
431
  * @throws {AttenteDeLaMachine} at the bound of the wait (code 75), or at once when an ancestor
292
432
  * holds the lock (code 1)
@@ -300,11 +440,14 @@ export function avecLaMachine(
300
440
  dire = l => process.stdout.write(`${l}\n`),
301
441
  borneMs = borneDe(env),
302
442
  rappelMs = RAPPEL_MS,
443
+ libre = libreDans,
444
+ occupe = occupants,
303
445
  } = {}
304
446
  ) {
305
447
  if (paquetsDeLEnveloppe(env)) return mesure(env);
306
448
  const verrou = verrouDeMachine(env);
307
449
  if (env[VARIABLE_TENUE] && lire(verrou) === env[VARIABLE_TENUE]) return mesure(env);
450
+ attendreDeLaPlace({ env, libre, occupe, dire, borneMs, rappelMs });
308
451
  mkdirSync(path.dirname(verrou), { recursive: true });
309
452
  const rang = rangDeLaMesure(racine);
310
453
  if (!(peutPrendre(verrou, rang) && prendreVerrou(verrou, { attendre: false }))) {
@@ -66,6 +66,12 @@ nomme le responsable, ce qui décide, les documents qu'il valide et les commande
66
66
  `npx grillhouse retirer-copie <copie>`, qui retire avec elle le dossier de travail de son
67
67
  circuit (`<copie>.travail`). Ainsi le dépôt garde seulement le travail commité, et rien ne se
68
68
  supprime sans avoir été lu.
69
+ - **Le dossier temporaire d'un ticket** : la consigne d'un sous-agent que je lance sur un ticket
70
+ nomme le dossier que donne `npx grillhouse temporaire <ticket>`, où vont ses fichiers
71
+ temporaires, légers, jamais une copie du dépôt, un `node_modules` ni un cache ; c'est celui que
72
+ le lanceur donne aux séances du ticket ; il vit tant que le ticket est ouvert, gel compris, et
73
+ part avec les copies finies quand le ticket se ferme. Ainsi mon scratchpad ne grossit pas des
74
+ agents du ticket.
69
75
 
70
76
  ## Un agent, un ticket
71
77
 
@@ -83,6 +83,8 @@ Le lanceur a avancé ta copie sur main avant d'ouvrir ta séance : tu pars du de
83
83
  Hors de ta copie, la machine est en lecture seule, `.git` compris : tu ne commites pas et tu n'écris pas l'index. Ton lot est ton travail dans la copie : le circuit le construit, le fait relire, puis le commite par le script d'intégration. Ainsi seul le circuit écrit l'histoire du dépôt.
84
84
 
85
85
  Les outils se prennent dans le `node_modules` de ta copie.
86
+
87
+ Ton dossier temporaire est celui de ton ticket : `$TMPDIR` le nomme, il reste d'une séance et d'une reprise à l'autre, gel compris, et part quand le ticket se ferme ; il ne porte que ce qui se refait : ce qu'il te faut pour reprendre vit dans ta copie ou ta passation, jamais dans le seul dossier temporaire. Tu n'y mets ni copie du dépôt, ni `node_modules`, ni cache de compilation ; un cache va sous `~/.cache/grillhouse/`. Ainsi le disque en mémoire du poste, que partagent ses séances, ne sature jamais.
86
88
  ```
87
89
 
88
90
  ## Relecteur (rempli par le circuit)
@@ -121,6 +123,8 @@ Tu relis le lot dans la copie du ticket (`.claude/worktrees/{{ticket}}`) et tu y
121
123
  Ton verdict est ta fiche, qui finit ta séance : le circuit l'écrit au ticket et la lit. Sur ACCEPTÉ, il intègre le lot ; sur RENDU, il relance l'agent que nomme chaque constat bloquant et chaque élément non conforme (`role`), et chaque constat reste ouvert jusqu'à la relecture qui le juge levé (`suivi`) ; il écrit ta conformité et tes remarques au ticket.
122
124
 
123
125
  Hors de ta copie, la machine est en lecture seule, `.git` compris : tu ne commites pas et tu n'écris pas l'index. Ainsi seul le circuit écrit l'histoire du dépôt.
126
+
127
+ Le dossier temporaire ne reçoit de toi rien de lourd : ni copie du dépôt, ni `node_modules`, ni cache de compilation ; un cache va sous `~/.cache/grillhouse/`. Ainsi le disque en mémoire du poste, que partagent ses séances, ne sature jamais.
124
128
  ```
125
129
 
126
130
  ## Toute séance, sur une fiche absente ou non conforme (rempli par le circuit)