@roomi-fields/grillhouse 0.28.1 → 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.
Files changed (33) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/charte.md +13 -1
  3. package/docs/ARCHITECTURE.md +19 -2
  4. package/docs/INTERFACE.md +11 -2
  5. package/hooks/register.tsx +132 -161
  6. package/package.json +1 -1
  7. package/scripts/copies-finies.mjs +15 -4
  8. package/scripts/enveloppe/enveloppe.mjs +8 -5
  9. package/scripts/enveloppe/lancer.sh +12 -2
  10. package/scripts/enveloppe/travail-de-la-copie.mjs +13 -6
  11. package/scripts/jointure.d.ts +14 -0
  12. package/scripts/langages/cargo/composants.mjs +4 -0
  13. package/scripts/langages/cargo/index.mjs +4 -2
  14. package/scripts/langages/cargo/sccache.mjs +37 -6
  15. package/scripts/langages/python/commandes.mjs +9 -2
  16. package/scripts/langages/python/index.mjs +3 -2
  17. package/scripts/langages/typescript/consommateurs.mjs +3 -41
  18. package/scripts/langages/typescript/interfaces-contre-code.mjs +2 -1
  19. package/scripts/langages/typescript/lecteurs.mjs +2 -8
  20. package/scripts/langages/typescript/parcours.mjs +49 -0
  21. package/scripts/langages/typescript/references-par-les-types.mjs +2 -1
  22. package/scripts/langages/typescript/tests-de-nuit.mjs +10 -0
  23. package/scripts/langages/typescript/turbo-des-paquets.mjs +2 -1
  24. package/scripts/langages/typescript/vitest-config/lances.mjs +6 -15
  25. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +4 -1
  26. package/scripts/mesure/base-de-passe.mjs +202 -9
  27. package/scripts/services-du-noyau.mjs +9 -2
  28. package/scripts/sous-commandes.mjs +1 -0
  29. package/scripts/tableau.mjs +203 -77
  30. package/scripts/verrou-de-machine.mjs +147 -4
  31. package/skills/pitmaster/SKILL.md +6 -0
  32. package/skills/pitmaster/references/consigne-agent.md +4 -0
  33. package/types/index.d.ts +6 -14
@@ -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',