@roomi-fields/grillhouse 0.50.3 → 0.51.0

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 (131) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +48 -0
  3. package/agents/developpeur.md +1 -1
  4. package/agents/direct.md +1 -1
  5. package/agents/explorateur.md +1 -1
  6. package/agents/questionneur.md +1 -1
  7. package/agents/relecteur.md +1 -1
  8. package/agents/testwriter.md +1 -1
  9. package/cadre/templates/c/package.json +1 -0
  10. package/cadre/templates/cargo/package.json +1 -0
  11. package/cadre/templates/python/package.json +1 -0
  12. package/charte.md +17 -12
  13. package/dist/machine/part-par-sorte.d.ts +16 -0
  14. package/dist/machine/part-par-sorte.js +36 -0
  15. package/dist/machine/part-par-sorte.js.map +1 -0
  16. package/dist/temporal/circuit/appel.js +1 -1
  17. package/dist/temporal/circuit/appel.js.map +1 -1
  18. package/dist/temporal/circuit/client.d.ts +5 -4
  19. package/dist/temporal/circuit/client.js +39 -16
  20. package/dist/temporal/circuit/client.js.map +1 -1
  21. package/dist/temporal/circuit/contrat.d.ts +11 -7
  22. package/dist/temporal/circuit/contrat.js +5 -9
  23. package/dist/temporal/circuit/contrat.js.map +1 -1
  24. package/dist/temporal/circuit/deroule.js +18 -6
  25. package/dist/temporal/circuit/deroule.js.map +1 -1
  26. package/dist/temporal/commande.js +12 -3
  27. package/dist/temporal/commande.js.map +1 -1
  28. package/dist/temporal/installation.d.ts +54 -3
  29. package/dist/temporal/installation.js +187 -17
  30. package/dist/temporal/installation.js.map +1 -1
  31. package/dist/temporal/places/client.d.ts +5 -1
  32. package/dist/temporal/places/client.js +23 -11
  33. package/dist/temporal/places/client.js.map +1 -1
  34. package/docs/ARCHITECTURE.md +23 -2700
  35. package/docs/INTERFACE.md +23 -8
  36. package/docs/architecture/circuit.md +59 -12
  37. package/docs/architecture/entree.md +20 -7
  38. package/docs/architecture/greffon.md +6 -2
  39. package/docs/architecture/installation.md +30 -11
  40. package/docs/architecture/machine.md +50 -37
  41. package/docs/architecture/tests.md +52 -14
  42. package/docs/lexique.md +154 -0
  43. package/hooks/register.tsx +1 -1
  44. package/package.json +1 -1
  45. package/scripts/activites.mjs +85 -60
  46. package/scripts/aiguillage.mjs +15 -7
  47. package/scripts/attente-de-la-machine.mjs +4 -8
  48. package/scripts/avancement.mjs +12 -8
  49. package/scripts/bilan.mjs +10 -7
  50. package/scripts/branche-de-nuit.mjs +2 -2
  51. package/scripts/ci-de-main.mjs +18 -21
  52. package/scripts/circuit.mjs +86 -43
  53. package/scripts/circuits-du-serveur.mjs +5 -5
  54. package/scripts/composants-affectes.mjs +30 -12
  55. package/scripts/composition-des-langages.mjs +5 -3
  56. package/scripts/conformite.mjs +1 -1
  57. package/scripts/consommation-des-passes.mjs +8 -6
  58. package/scripts/copies-finies.mjs +3 -14
  59. package/scripts/depart-du-ticket.d.mts +8 -2
  60. package/scripts/depart-du-ticket.mjs +26 -8
  61. package/scripts/direct.mjs +158 -72
  62. package/scripts/droits.mjs +63 -185
  63. package/scripts/engendres.mjs +3 -14
  64. package/scripts/enveloppe/enveloppe.mjs +75 -30
  65. package/scripts/enveloppe/lancer.sh +59 -45
  66. package/scripts/enveloppe/paquets-du-plan.mjs +38 -11
  67. package/scripts/enveloppe/travail-de-la-copie.mjs +115 -3
  68. package/scripts/etapes.mjs +84 -22
  69. package/scripts/faits-du-circuit.mjs +8 -2
  70. package/scripts/grillhouse-maj.mjs +43 -18
  71. package/scripts/groupe-cles.d.mts +15 -0
  72. package/scripts/groupe-cles.mjs +77 -2
  73. package/scripts/init.mjs +9 -2
  74. package/scripts/integration/rejeu.mjs +8 -1
  75. package/scripts/jointure.d.ts +22 -3
  76. package/scripts/langages/c/index.mjs +5 -2
  77. package/scripts/langages/cargo/commandes.mjs +35 -15
  78. package/scripts/langages/cargo/composants.mjs +45 -3
  79. package/scripts/langages/cargo/index.mjs +6 -3
  80. package/scripts/langages/python/index.mjs +5 -2
  81. package/scripts/langages/typescript/chemins-des-tests.mjs +1 -1
  82. package/scripts/langages/typescript/index.mjs +4 -2
  83. package/scripts/langages/typescript/mise-a-jour.mjs +1 -1
  84. package/scripts/langages/typescript/rapports-aux-lignes.mjs +74 -0
  85. package/scripts/langages/typescript/turbo-des-paquets.mjs +99 -36
  86. package/scripts/langages/typescript/verdict.mjs +29 -3
  87. package/scripts/langages/typescript/verifier.mjs +1 -1
  88. package/scripts/langages/typescript/vitest-config/changements.mjs +8 -6
  89. package/scripts/langages/typescript/vitest-config/lances.mjs +15 -32
  90. package/scripts/langages.mjs +54 -4
  91. package/scripts/matieres-lues.mjs +1 -1
  92. package/scripts/mesure/base-de-passe.mjs +32 -90
  93. package/scripts/migrations/serveurs-de-l-index.mjs +79 -0
  94. package/scripts/migrations.mjs +21 -7
  95. package/scripts/paquets.d.ts +3 -0
  96. package/scripts/paquets.mjs +88 -1
  97. package/scripts/passe-de-la-machine.mjs +109 -36
  98. package/scripts/places-de-la-machine.mjs +81 -29
  99. package/scripts/plafond-de-la-machine.d.mts +2 -5
  100. package/scripts/plafond-de-la-machine.mjs +9 -9
  101. package/scripts/reprise.mjs +42 -13
  102. package/scripts/resultats.mjs +76 -54
  103. package/scripts/retirer-les-copies-finies.mjs +1 -1
  104. package/scripts/seances.mjs +426 -115
  105. package/scripts/services-du-noyau.mjs +9 -1
  106. package/scripts/session-start.sh +14 -1
  107. package/scripts/sortie.mjs +37 -6
  108. package/scripts/sous-commandes.mjs +0 -2
  109. package/scripts/superviseur.mjs +33 -13
  110. package/scripts/tableau.mjs +61 -16
  111. package/scripts/transitions.d.mts +25 -2
  112. package/scripts/transitions.mjs +137 -29
  113. package/scripts/verrous/ecriture-hors-enveloppe.mjs +31 -9
  114. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  115. package/skills/developpeur/SKILL.md +38 -15
  116. package/skills/direct/SKILL.md +29 -9
  117. package/skills/domain-modeling/GLOSSARY-FORMAT.md +9 -9
  118. package/skills/domain-modeling/SKILL.md +14 -12
  119. package/skills/explorateur/SKILL.md +30 -6
  120. package/skills/pitmaster/SKILL.md +12 -16
  121. package/skills/pitmaster/references/consigne-agent.md +12 -11
  122. package/skills/relecteur/SKILL.md +12 -5
  123. package/skills/systematic-debugging/SKILL.md +281 -0
  124. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  125. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  126. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  127. package/skills/systematic-debugging/find-polluter.sh +72 -0
  128. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  129. package/skills/testwriter/SKILL.md +35 -29
  130. package/scripts/verrous/commande.mjs +0 -214
  131. package/scripts/verrous/verrou.mjs +0 -311
@@ -17,19 +17,20 @@
17
17
  // beside its copy, which no sweep touches); `integration`, the working directory of an
18
18
  // integration (scripts/integration/integrer.mjs); `file`, the results of the final pass of the queue
19
19
  // (scripts/integration/file.mjs); `enveloppe`, the throwaway state of a session's envelope
20
- // (scripts/enveloppe/enveloppe.mjs).
21
- // - The owner of a base is the process that opens it, for a pass and a session out of a ticket
22
- // (the night, a verification); a ticket (`ouvrirBaseDuTicket`: `<dans>/grillhouse-ticket-<id>/`,
23
- // the temporary directory of the agents of one ticket, which the launcher gives each session of
24
- // the ticket, scripts/enveloppe/lancer.sh, and `npx grillhouse temporaire <ticket>` the
25
- // supervisor), kept from one session and one resumption to the next, removed when its ticket is
26
- // closed (`balayerLesTickets`, which the removal of the finished copies plays,
27
- // scripts/copies-finies.mjs), frozen or not; 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. 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.
20
+ // (scripts/enveloppe/enveloppe.mjs); `seance`, the temporary directory of one session of an
21
+ // agent that the frame launches, opened by the launcher of the envelope
22
+ // (scripts/enveloppe/lancer.sh) or by the shell that carries a session out of the envelope
23
+ // (scripts/seances.mjs), which removes it at the session's end, even interrupted. What an agent
24
+ // needs to resume lives in its copy or its handover, never in this directory, which holds what
25
+ // is made again.
26
+ // - The owner of a base is the process that opens it, or the one the call names (`pid`: the
27
+ // process that lives as long as its session); or a directory (`cacheDeLaRacine`: the cache of a
28
+ // build rooted in the temporary directory), swept once that directory is gone, from the
29
+ // namespace that opened it, or, from the host (the next base of a pass, out of an envelope,
30
+ // where the home is read-only), untouched for 7 days whatever its namespace.
31
+ // - `npx grillhouse temporaire`, without argument, writes in a session the frame launched
32
+ // (`GRILLHOUSE_ENVELOPPE`, or `GRILLHOUSE_SEANCE` out of the envelope) the directory its
33
+ // `TMPDIR` names; anywhere else, or with an argument, it says so and ends at 2.
33
34
  // - The caches of compilation never lie in the temporary directory, a disk in memory that the
34
35
  // sessions of the machine share: they go under `${XDG_CACHE_HOME:-~/.cache}/grillhouse/<outil>`
35
36
  // (`cacheDeCompilation`); a build rooted in the temporary directory (a project of trial) keeps
@@ -122,8 +123,7 @@ function proprietaire(base) {
122
123
 
123
124
  // Whether the base <base> is an orphan: its owner, a directory or a process, belongs to this
124
125
  // namespace of processes and is gone; a directory another namespace sees (an envelope's private
125
- // /tmp) or a process of another namespace is never judged here. A ticket's base goes with its
126
- // ticket (`balayerLesTickets`).
126
+ // /tmp) or a process of another namespace is never judged here.
127
127
  function orpheline(base) {
128
128
  const p = proprietaire(base);
129
129
  const ici = espace();
@@ -170,6 +170,9 @@ function vieille(base) {
170
170
  }
171
171
  }
172
172
 
173
+ /** The variable that marks a session out of the envelope that the frame launched. */
174
+ export const VARIABLE_SEANCE = 'GRILLHOUSE_SEANCE';
175
+
173
176
  // Whether <env> is an agent's envelope, where the home is read-only (scripts/enveloppe/).
174
177
  const enEnveloppe = env => Boolean(env.GRILLHOUSE_ENVELOPPE);
175
178
 
@@ -294,20 +297,21 @@ function balayerLesEssais(env) {
294
297
  * Opens the base of a pass of <genre> in <dans>, after sweeping the orphan bases there, and the
295
298
  * orphan trial directories under the home.
296
299
  * @param {string} genre what the pass is (`vitest`, `circuit`…), in the base's name
297
- * @param {{ dans?: string }} options `dans`, the directory of the base (`os.tmpdir()`)
300
+ * @param {{ dans?: string, pid?: number }} options `dans`, the directory of the base
301
+ * (`os.tmpdir()`); `pid`, the process that owns it (this one)
298
302
  * @returns {{ base: string, dossier: string, env: Record<string, string>, restes: () => string[],
299
303
  * essais: () => string[], fermer: () => void }} the base; the directory its pass writes in; the
300
304
  * variables that name it to the pass's children (TMPDIR, TMP, TEMP); what is in it, sorted; the
301
305
  * names of the `grillhouse-essais-*` directories of the home's cache whose owner file names this
302
306
  * pass, read at the call; and the removal of the base
303
307
  */
304
- export function ouvrirBase(genre, { dans = tmpdir() } = {}) {
308
+ export function ouvrirBase(genre, { dans = tmpdir(), pid = process.pid } = {}) {
305
309
  balayer(dans);
306
310
  balayerLesCaches(process.env);
307
311
  balayerLesEssais(process.env);
308
312
  mkdirSync(dans, { recursive: true });
309
313
  const base = mkdtempSync(path.join(dans, `${PREFIXE}${genre}-`));
310
- const moi = { pid: process.pid, depart: departDe(process.pid), espace: espace() };
314
+ const moi = { pid, depart: departDe(pid), espace: espace() };
311
315
  writeFileSync(path.join(base, PROPRIETAIRE), `${JSON.stringify(moi)}\n`);
312
316
  const dossier = path.join(base, 't');
313
317
  mkdirSync(dossier);
@@ -328,67 +332,6 @@ export function ouvrirBase(genre, { dans = tmpdir() } = {}) {
328
332
  };
329
333
  }
330
334
 
331
- // The prefix of the base of a ticket, and the form of a ticket's id.
332
- const DU_TICKET = `${PREFIXE}ticket-`;
333
- const ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
334
-
335
- /**
336
- * The base of the ticket <ticket> in <dans>: `<dans>/grillhouse-ticket-<ticket>/`, its owner the
337
- * ticket, made when absent and the same at each call; the temporary directory of the agents of
338
- * one ticket, kept from one session to the next, removed when it is closed (`balayerLesTickets`).
339
- * @param {string} ticket the ticket's id
340
- * @param {{ dans?: string }} options `dans`, the directory of the base (`os.tmpdir()`)
341
- * @returns {{ base: string, dossier: string }} the base, and the directory its agents write in
342
- */
343
- export function ouvrirBaseDuTicket(ticket, { dans = tmpdir() } = {}) {
344
- if (!ID.test(ticket)) {
345
- throw new Error(`⛔ « ${ticket} » n'est pas l'identifiant d'un ticket.`);
346
- }
347
- const base = path.join(dans, `${DU_TICKET}${ticket}`);
348
- const dossier = path.join(base, 't');
349
- mkdirSync(dossier, { recursive: true });
350
- if (proprietaire(base) === null) {
351
- writeFileSync(path.join(base, PROPRIETAIRE), `${JSON.stringify({ ticket })}\n`);
352
- }
353
- return { base, dossier };
354
- }
355
-
356
- /**
357
- * Removes from <dans> the base of each ticket that is closed; the ids of the tickets whose base
358
- * went. A ticket open, frozen or not, keeps its base, as a retention policy fixed in advance.
359
- * <fermes> reads the closed tickets, null when they do not read: called once, and only when a
360
- * ticket's base is there.
361
- * @param {() => Set<string> | null} fermes
362
- * @param {{ dans?: string }} options `dans`, the directory of the bases (`os.tmpdir()`)
363
- * @returns {string[]}
364
- */
365
- export function balayerLesTickets(fermes, { dans = tmpdir() } = {}) {
366
- const tickets = contenu(dans)
367
- .filter(n => n.startsWith(DU_TICKET))
368
- .map(n => ({ base: path.join(dans, n), ticket: proprietaire(path.join(dans, n))?.ticket }))
369
- .filter(b => typeof b.ticket === 'string');
370
- if (tickets.length === 0) {
371
- return [];
372
- }
373
- const clos = fermes();
374
- if (clos === null) {
375
- return [];
376
- }
377
- const retires = tickets.filter(b => clos.has(b.ticket));
378
- for (const b of retires) {
379
- rmSync(b.base, { recursive: true, force: true });
380
- }
381
- return retires.map(b => b.ticket);
382
- }
383
-
384
- /**
385
- * The ticket whose base is the entry <nom> of the temporary directory, or null.
386
- * @param {string} nom
387
- */
388
- export function ticketDeLaBase(nom) {
389
- return nom.startsWith(DU_TICKET) ? nom.slice(DU_TICKET.length) : null;
390
- }
391
-
392
335
  // Whether <chemin> lies in <dossier> or is it.
393
336
  const sous = (chemin, dossier) => {
394
337
  const rel = path.relative(dossier, chemin);
@@ -455,19 +398,18 @@ export function cacheDeLaRacine(outil, racine, env = process.env, { creer = true
455
398
  return cache;
456
399
  }
457
400
 
458
- // `npx grillhouse temporaire <ticket>`: prints the directory of the ticket's agents.
459
- function commande(argv) {
460
- if (argv.length !== 1 || argv[0].startsWith('-')) {
461
- process.stderr.write('usage: npx grillhouse temporaire <ticket>\n');
462
- return 2;
463
- }
464
- try {
465
- process.stdout.write(`${ouvrirBaseDuTicket(argv[0]).dossier}\n`);
466
- return 0;
467
- } catch (e) {
468
- process.stderr.write(`${e.message}\n`);
401
+ // `npx grillhouse temporaire`: in a session the frame launched, prints the temporary directory
402
+ // that its TMPDIR names.
403
+ function commande(argv, env = process.env) {
404
+ const enSeance = enEnveloppe(env) || Boolean(env[VARIABLE_SEANCE]);
405
+ if (argv.length > 0 || !enSeance || !env.TMPDIR) {
406
+ process.stderr.write(
407
+ '⛔ usage: npx grillhouse temporaire, sans argument, dans une séance que le cadre lance : elle écrit le dossier temporaire de cette séance. Hors d’elle, un fichier temporaire va dans le scratchpad de la séance.\n'
408
+ );
469
409
  return 2;
470
410
  }
411
+ process.stdout.write(`${env.TMPDIR}\n`);
412
+ return 0;
471
413
  }
472
414
 
473
415
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
@@ -0,0 +1,79 @@
1
+ // Every project declares the servers of the index in its .mcp.json, the one the project commits
2
+ // and the sessions of its agents read (scripts/droits.mjs): codegraph, the code knowledge graph,
3
+ // and rtfm, the search over code and documents. `grillhouse init` plays this migration on the
4
+ // project it creates. Mechanism: installation.md §5.4 (packages/grillhouse/docs/architecture/).
5
+ //
6
+ // - `version`: null until the release that brings it, which `grillhouse sortie` numbers.
7
+ // - `migrer` adds to `mcpServers` each of the two that is missing, creating the file when the
8
+ // project has none; the other entries and keys stay, in their order, with the indentation of the
9
+ // file. A file that holds both is not rewritten. A file that is not a JSON object, or whose
10
+ // `mcpServers` is not one, stays as it is, left to the project.
11
+ // - `restes(projet)`: rtfm's entry names the program `rtfm-serve`, which the plugin rtfm ships;
12
+ // one line when the project declares that entry and its settings do not enable the plugin.
13
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
14
+ import path from 'node:path';
15
+
16
+ export const version = '0.51.0';
17
+ export const nom = 'serveurs de l index';
18
+
19
+ // Each server in the form its tool publishes: codegraph's own, and the .mcp.json of rtfm.
20
+ const SERVEURS = {
21
+ codegraph: { type: 'stdio', command: 'codegraph', args: ['serve', '--mcp'], env: {} },
22
+ rtfm: { type: 'stdio', command: 'rtfm-serve', args: [], env: { RTFM_DB: '.rtfm/library.db' } },
23
+ };
24
+
25
+ const estUnObjet = v => v !== null && typeof v === 'object' && !Array.isArray(v);
26
+
27
+ // The JSON of <fichier>, or undefined when it holds none.
28
+ function lireJson(fichier) {
29
+ try {
30
+ return JSON.parse(readFileSync(fichier, 'utf8'));
31
+ } catch {
32
+ return undefined;
33
+ }
34
+ }
35
+
36
+ /** The servers of the index added to the .mcp.json of <projet>; returns what it did. */
37
+ export function migrer(projet) {
38
+ const fichier = path.join(projet, '.mcp.json');
39
+ const texte = existsSync(fichier) ? readFileSync(fichier, 'utf8') : null;
40
+ const config = texte === null ? {} : lireJson(fichier);
41
+ const declares = config?.mcpServers ?? {};
42
+ if (!estUnObjet(config) || !estUnObjet(declares)) {
43
+ return [
44
+ {
45
+ aFaire: `.mcp.json : illisible comme configuration de serveurs (un objet JSON, « mcpServers » un objet) ; corrige-le, puis rejoue la montée, qui y ajoute les serveurs de l'index (${Object.keys(SERVEURS).join(', ')})`,
46
+ },
47
+ ];
48
+ }
49
+ const ajoutes = Object.keys(SERVEURS).filter(n => !Object.hasOwn(declares, n));
50
+ if (ajoutes.length === 0) {
51
+ return [];
52
+ }
53
+ config.mcpServers = {
54
+ ...declares,
55
+ ...Object.fromEntries(ajoutes.map(n => [n, SERVEURS[n]])),
56
+ };
57
+ const indent = /^\n?(\s+)"/m.exec(texte ?? '')?.[1] ?? 2;
58
+ const fin = texte === null || texte.endsWith('\n') ? '\n' : '';
59
+ writeFileSync(fichier, `${JSON.stringify(config, null, indent)}${fin}`);
60
+ return [
61
+ `.mcp.json : serveurs de l'index ajoutés (${ajoutes.join(', ')}), que les séances des agents lisent ; commite le fichier`,
62
+ ];
63
+ }
64
+
65
+ /** One line when the rtfm of <projet> waits for a program no enabled plugin ships; none otherwise. */
66
+ export function restes(projet) {
67
+ const mcp = lireJson(path.join(projet, '.mcp.json'));
68
+ if (mcp?.mcpServers?.rtfm?.command !== SERVEURS.rtfm.command) {
69
+ return [];
70
+ }
71
+ const greffons =
72
+ lireJson(path.join(projet, '.claude', 'settings.json'))?.enabledPlugins ?? {};
73
+ if (Object.entries(greffons).some(([id, actif]) => id.startsWith('rtfm@') && actif === true)) {
74
+ return [];
75
+ }
76
+ return [
77
+ '.claude/settings.json : le greffon rtfm n’est pas activé, qui porte le programme rtfm-serve que .mcp.json nomme, et tient son index ; active-le (« enabledPlugins » : « rtfm@roomi-fields »: true, comme le gabarit), puis rejoue npx grillhouse maj --poste.',
78
+ ];
79
+ }
@@ -1,9 +1,10 @@
1
1
  // The migrations of a project from one version of the frame to the next, as the transforms of
2
2
  // `npx @turbo/codemod migrate`: one module per change of form, written once, in
3
- // scripts/migrations/<version>-<nom>.mjs, which `grillhouse maj` plays (scripts/grillhouse-maj.mjs).
3
+ // scripts/migrations/ (`<nom>.mjs`; the older ones `<version>-<nom>.mjs`), which `grillhouse maj` plays (scripts/grillhouse-maj.mjs).
4
4
  // The mechanism is installation.md §5.4 (packages/grillhouse/docs/architecture/).
5
5
  //
6
- // - A migration exports `version` (the version of the package that brings the change of form),
6
+ // - A migration exports `version` (the version of the package that brings the change of form;
7
+ // null until that release, which `grillhouse sortie` numbers: no one else picks it),
7
8
  // `nom` and `migrer(projet)`, which brings the project at <projet> to the new form and returns
8
9
  // the lines of what it changed: none when the project already has it. A line `{ aFaire }` is
9
10
  // what it leaves to the project (a copy of the frame the project modified), which the update
@@ -15,7 +16,10 @@
15
16
  // of Nx carries its own (`migrationsDe`); the update plays those newer than the
16
17
  // version the project recorded (`grillhouse.version` of its package.json), in the order of their
17
18
  // versions; a project that recorded none plays them all. The package carries no migration newer
18
- // than itself once released, so the range ends with the package.
19
+ // than itself, so the range ends with the package. One without a version comes after the
20
+ // others and plays for a project that recorded none or a version below the package's: one that
21
+ // recorded the package's does not play it again, and the release, numbered above, brings it to
22
+ // every project.
19
23
  // - A migration may also export `restes(projet)`: the lines of what stays to the project once the
20
24
  // update is done, which the update plays after its own update and its regeneration, for each
21
25
  // migration it played, and reports (« reste au projet ») without holding back the version, as a
@@ -23,6 +27,7 @@
23
27
  // - Each migration has its test, tests/unit/migration.<nom>.spec.ts (a module's, under its
24
28
  // folder of tests, tests/unit/langages/<nom>/).
25
29
  import semver from 'semver';
30
+ import { VERSION } from './cadre.mjs';
26
31
  import { langageDe } from './langages.mjs';
27
32
  import * as charteImportee from './migrations/0.23.0-charte-importee.mjs';
28
33
  import * as crochetsDeSeance from './migrations/0.23.0-crochets-de-seance.mjs';
@@ -48,6 +53,7 @@ import * as ciDeclencheeParLaFile from './migrations/0.48.0-ci-declenchee-par-la
48
53
  import * as reservationDeTroisCoeurs from './migrations/0.49.0-reservation-de-trois-coeurs.mjs';
49
54
 
50
55
  import * as reglagesHorsDeLaCharte from './migrations/0.50.0-reglages-hors-de-la-charte.mjs';
56
+ import * as serveursDeLIndex from './migrations/serveurs-de-l-index.mjs';
51
57
 
52
58
  /** The migrations of the core. */
53
59
  export const MIGRATIONS = [
@@ -73,6 +79,7 @@ export const MIGRATIONS = [
73
79
  ciDeclencheeParLaFile,
74
80
  reservationDeTroisCoeurs,
75
81
  reglagesHorsDeLaCharte,
82
+ serveursDeLIndex,
76
83
  ];
77
84
 
78
85
  /**
@@ -83,13 +90,20 @@ export const migrationsDe = projet => [...MIGRATIONS, ...langageDe(projet).migra
83
90
 
84
91
  /**
85
92
  * The migrations of <liste> newer than <depuis> (all of them when it is null), in the order of
86
- * their versions; two of one version keep their order in the list.
93
+ * their versions; two of one version keep their order in the list. One without a version, not
94
+ * released yet, comes last, and is newer than a <depuis> below <paquet>, the version of the
95
+ * package.
87
96
  */
88
- export function migrationsAJouer(depuis, liste = MIGRATIONS) {
97
+ export function migrationsAJouer(depuis, liste = MIGRATIONS, paquet = VERSION) {
89
98
  return liste
90
99
  .map((m, rang) => ({ m, rang }))
91
- .filter(({ m }) => depuis === null || semver.gt(m.version, depuis))
92
- .sort((a, b) => semver.compare(a.m.version, b.m.version) || a.rang - b.rang)
100
+ .filter(({ m }) => depuis === null || semver.gt(m.version ?? paquet, depuis))
101
+ .sort(
102
+ (a, b) =>
103
+ (a.m.version === null) - (b.m.version === null) ||
104
+ (a.m.version === null ? 0 : semver.compare(a.m.version, b.m.version)) ||
105
+ a.rang - b.rang
106
+ )
93
107
  .map(({ m }) => m);
94
108
  }
95
109
 
@@ -6,6 +6,9 @@
6
6
  export const CODE: string;
7
7
  /** The script of a package that types it, which the verification plays in each package. */
8
8
  export const TYPAGE: string;
9
+ /** The patterns the text `texte` of a test file declares it reads: the words of each line
10
+ * `// @lit` of the comment at its head, each a glob from the top of the repository. */
11
+ export function lecturesDeclarees(texte: string): string[];
9
12
  /** The names listed in `racine`'s `docs/agents/hors-cadre.txt`: empty without the file. */
10
13
  export function horsCadre(racine: string): Set<string>;
11
14
  /** Those of `chemins` (absolute, under `racine`), each as given, that git ignores in the repository
@@ -22,7 +22,7 @@
22
22
  //
23
23
  // The packages are the nodes of the graph of the tasks: docs/architecture/tests.md §2.1 and §3.1.
24
24
  import { spawnSync } from 'node:child_process';
25
- import { existsSync, globSync, readdirSync, readFileSync } from 'node:fs';
25
+ import { existsSync, globSync, readdirSync, readFileSync, statSync } from 'node:fs';
26
26
  import path from 'node:path';
27
27
 
28
28
  /** The code of `src/` (the root's, or a package's under `packages/`), as a pattern of a path from
@@ -31,6 +31,93 @@ export const CODE = '^src/|^packages/[^/]+/src/';
31
31
  /** The script of a package that types it, which the verification plays in each package. */
32
32
  export const TYPAGE = 'typecheck';
33
33
 
34
+ // The tag of a test that declares the files it reads: a line `// @lit <motif> …` of the comment at
35
+ // the head of the file, before its first line of code, as the tag `@poste`.
36
+ const ETIQUETTE_DE_LECTURE = /^\/\/\s*@lit\b(.*)$/;
37
+
38
+ /**
39
+ * The patterns the text <texte> of a test file declares it reads, as the `data` of a Bazel target:
40
+ * the words of each line `// @lit` of the comment at its head, each a glob from the top of the
41
+ * repository. The modules of the languages whose comments open with `//` read their tests by it.
42
+ * @param {string} texte the text of the file
43
+ */
44
+ export function lecturesDeclarees(texte) {
45
+ const out = [];
46
+ for (const ligne of texte.split('\n')) {
47
+ const l = ligne.trim();
48
+ const m = ETIQUETTE_DE_LECTURE.exec(l);
49
+ if (m) {
50
+ out.push(...m[1].split(/\s+/).filter(Boolean));
51
+ } else if (l !== '' && !l.startsWith('//') && !l.startsWith('#!')) {
52
+ break;
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+ // A path a project declares it reads (`grillhouse.lit`, a generated file's `fichiers` and `lit`),
59
+ // as an input of Turborepo: a path, a directory or a file, or a glob pattern, which holds one of
60
+ // these characters.
61
+ const GLOB = /[*?[\]{}]/;
62
+
63
+ /** Whether the path read <lu> is a glob pattern.
64
+ * @param {string} lu */
65
+ export const estUnMotif = lu => GLOB.test(lu);
66
+
67
+ /** The path read <lu> as the frame compares it: without a leading `./` nor trailing slashes.
68
+ * @param {string} lu */
69
+ export const lectureNette = lu => String(lu ?? '').replace(/^\.\//, '').replace(/\/+$/, '');
70
+
71
+ /**
72
+ * Whether one of <motifs> covers the file <fichier>, both from the root, as the inputs of
73
+ * Turborepo read them: a path names that file, a directory every file under it, a glob pattern
74
+ * (`*`, `**`) the files it matches (`path.matchesGlob` of Node).
75
+ * @param {string[]} motifs
76
+ * @param {string} fichier
77
+ */
78
+ export function couvertPar(motifs, fichier) {
79
+ return motifs.some(m => {
80
+ const net = lectureNette(m);
81
+ return fichier === net || fichier.startsWith(`${net}/`) || path.matchesGlob(fichier, net);
82
+ });
83
+ }
84
+
85
+ /** The files of the repository at <racine> the pattern <motif> covers, from the root,
86
+ * `node_modules` left out.
87
+ * @param {string} racine
88
+ * @param {string} motif */
89
+ export const fichiersDuMotif = (racine, motif) =>
90
+ globSync(lectureNette(motif), {
91
+ cwd: racine,
92
+ exclude: f => path.basename(String(f)) === 'node_modules',
93
+ })
94
+ .filter(f => statSync(path.join(racine, f), { throwIfNoEntry: false })?.isFile())
95
+ .map(f => f.split(path.sep).join('/'));
96
+
97
+ /**
98
+ * Whether the path read <lu> and the directory or file <chemin> (from the root) overlap: a path
99
+ * that holds it or lies in it; a pattern that can name it or a file under it, segment by segment.
100
+ * @param {string} lu
101
+ * @param {string} chemin
102
+ */
103
+ export function recouvreLaLecture(lu, chemin) {
104
+ const net = lectureNette(lu);
105
+ if (!estUnMotif(net)) {
106
+ return net === chemin || net.startsWith(`${chemin}/`) || chemin.startsWith(`${net}/`);
107
+ }
108
+ const motif = net.split('/');
109
+ const segments = chemin.split('/');
110
+ for (const [i, segment] of segments.entries()) {
111
+ if (motif[i] === '**') {
112
+ return true;
113
+ }
114
+ if (i >= motif.length || !path.matchesGlob(segment, motif[i])) {
115
+ return false;
116
+ }
117
+ }
118
+ return true;
119
+ }
120
+
34
121
  // The list of the packages out of the frame: one line per package, « <package> <reason> », its
35
122
  // first word the name of a directory under `packages/` or `src/`; a blank line or a line starting
36
123
  // with `#` names nothing.
@@ -1,7 +1,7 @@
1
1
  // A pass on the machine: it takes its part of the budget (scripts/places-de-la-machine.mjs
2
2
  // `prendreUnePart`), waiting when the parts held leave too little, and plays held to that part
3
3
  // by a control group of its own (`systemd-run --user --scope`) whose CPU weight and memory bound
4
- // come from the part, with no hard CPU ceiling. Its tools receive the cores of its part
4
+ // come from the part (the bound its limit, else its memory), with no hard CPU ceiling. Its tools receive the cores of its part
5
5
  // (GRILLHOUSE_TRAVAILLEURS). A pass takes no place. Architecture:
6
6
  // docs/architecture/machine.md (§3.1, §5.1, §6).
7
7
  //
@@ -17,7 +17,9 @@
17
17
  // unit named, which a sampler reads. A pass that consumes clearly more than its part is said to
18
18
  // the board and to the figures (`depasseLaPart`).
19
19
  // - A pass under the part its parent holds (GRILLHOUSE_PART_TENUE) takes none of its own.
20
+ // - A session of an agent keeps its peak too (`mesureDeLaSeance`), read from its group.
20
21
  import { spawnSync } from 'node:child_process';
22
+ import { randomUUID } from 'node:crypto';
21
23
  import { readFileSync } from 'node:fs';
22
24
  import {
23
25
  coeursDeLaMachine,
@@ -86,7 +88,7 @@ export function lancementDeLaPasse({ lourde, cmd, args, env }) {
86
88
  /**
87
89
  * The command line that runs <cmd> in a control group of its own under the part <part>: `systemd-run
88
90
  * --user --scope` (the manager of the user, no privilege), its CPU weight and its memory bound
89
- * drawn from the part, no hard ceiling of CPU, the command of the pass whole at the end after
91
+ * (the limit of the part, else its memory) drawn from the part, no hard ceiling of CPU, the command of the pass whole at the end after
90
92
  * `--`, given as written (`--expand-environment=no`: systemd-run would otherwise expand each
91
93
  * `${…}` of its arguments, a shell script's included). <plafond> adds the hard CPU ceiling (`CPUQuota`, the cores of the part: the group of an
92
94
  * agent's session); <memoire> false leaves the memory unbound. <unite> names the scope, which a
@@ -94,8 +96,9 @@ export function lancementDeLaPasse({ lourde, cmd, args, env }) {
94
96
  * part, the system delegating the cpuset controller to the account) the group allows those
95
97
  * threads only (`AllowedCPUs`), under the slice of the frame, which the programs out of the frame
96
98
  * are kept out of.
97
- * @param {{ part: { coeurs: number, memoire: number }, cmd: string, args: string[],
98
- * unite?: string | null, fils?: number[] | null, plafond?: boolean, memoire?: boolean }} o
99
+ * @param {{ part: { coeurs: number, memoire: number, limite?: number | null }, cmd: string,
100
+ * args: string[], unite?: string | null, fils?: number[] | null, plafond?: boolean,
101
+ * memoire?: boolean }} o
99
102
  * @returns {{ cmd: string, args: string[] }}
100
103
  */
101
104
  export function commandeDuGroupe({ part, cmd, args, unite = null, fils = null, plafond = false, memoire = true }) {
@@ -112,7 +115,7 @@ export function commandeDuGroupe({ part, cmd, args, unite = null, fils = null, p
112
115
  'MemoryAccounting=yes',
113
116
  '-p',
114
117
  `CPUWeight=${poidsDeLaPart(part)}`,
115
- ...(memoire ? ['-p', `MemoryMax=${Math.floor(part.memoire)}`] : []),
118
+ ...(memoire ? ['-p', `MemoryMax=${Math.floor(part.limite ?? part.memoire)}`] : []),
116
119
  ...(plafond ? ['-p', `CPUQuota=${part.coeurs * 100}%`] : []),
117
120
  ...(fils ? ['-p', `AllowedCPUs=${listeDeCoeurs(fils)}`] : []),
118
121
  '--',
@@ -216,9 +219,47 @@ const issueDe = r => {
216
219
  return 'verte';
217
220
  };
218
221
 
219
- // Plays <jouer> in the group <ouvert> (`ouvrir()` of a scope), reads what it consumed before the
220
- // group goes, and, for a heavy pass, keeps the line in the register of the project, the pass red
221
- // or interrupted included: the figures, its part, and what exceeds it.
222
+ // Keeps in the register of the project the line of what the group <ouvert> consumed since <debut>:
223
+ // the figures, its part when it holds one, and what exceeds it; then closes the group.
224
+ function garderLaMesure({ ouvert, racine, ticket, sorte, part, horloge, coeurs, debut, issue }) {
225
+ let lecture = null;
226
+ try {
227
+ lecture = ouvert.lire();
228
+ } catch {
229
+ // an unreadable scope keeps a line without values
230
+ }
231
+ try {
232
+ const dureeMs = horloge() - debut;
233
+ const depasse =
234
+ lecture && part
235
+ ? depasseLaPart({ part, cpuNs: lecture.cpuNs, dureeMs, memoirePic: lecture.memoirePic })
236
+ : null;
237
+ const limite = part?.limite === undefined ? part?.memoire : part.limite;
238
+ garderLaConsommation(racine, {
239
+ sorte,
240
+ ...(ticket ? { ticket } : {}),
241
+ dureeMs,
242
+ cpuNs: lecture?.cpuNs ?? null,
243
+ memoirePic: lecture?.memoirePic ?? null,
244
+ coeurs,
245
+ ...(part
246
+ ? {
247
+ partCoeurs: part.coeurs,
248
+ partMemoire: part.memoire,
249
+ ...(limite === null ? {} : { partLimite: limite }),
250
+ }
251
+ : {}),
252
+ ...(depasse ? { depasse } : {}),
253
+ issue,
254
+ fin: new Date().toISOString(),
255
+ });
256
+ } finally {
257
+ ouvert.clore?.();
258
+ }
259
+ }
260
+
261
+ // Plays <jouer> in the group <ouvert> (`ouvrir()` of a scope) and, for a heavy pass, keeps its
262
+ // line, the pass red or interrupted included, read before the group goes.
222
263
  function jouerMesuree(jouer, { ouvert, racine, ticket, sorte, part, horloge, coeurs, lourde }) {
223
264
  const debut = horloge();
224
265
  let issue = 'rouge';
@@ -227,39 +268,71 @@ function jouerMesuree(jouer, { ouvert, racine, ticket, sorte, part, horloge, coe
227
268
  issue = issueDe(r);
228
269
  return r;
229
270
  } finally {
230
- let lecture = null;
231
- try {
232
- lecture = ouvert.lire();
233
- } catch {
234
- // an unreadable scope keeps a line without values
235
- }
236
- try {
237
- if (lourde) {
238
- const dureeMs = horloge() - debut;
239
- garderLaConsommation(racine, {
240
- sorte,
241
- ...(ticket ? { ticket } : {}),
242
- dureeMs,
243
- cpuNs: lecture?.cpuNs ?? null,
244
- memoirePic: lecture?.memoirePic ?? null,
245
- coeurs,
246
- partCoeurs: part.coeurs,
247
- partMemoire: part.memoire,
248
- ...(lecture
249
- ? (d => (d ? { depasse: d } : {}))(
250
- depasseLaPart({ part, cpuNs: lecture.cpuNs, dureeMs, memoirePic: lecture.memoirePic })
251
- )
252
- : {}),
253
- issue,
254
- fin: new Date().toISOString(),
255
- });
256
- }
257
- } finally {
271
+ if (lourde) {
272
+ garderLaMesure({ ouvert, racine, ticket, sorte, part, horloge, coeurs, debut, issue });
273
+ } else {
258
274
  ouvert.clore?.();
259
275
  }
260
276
  }
261
277
  }
262
278
 
279
+ /**
280
+ * The measure of a session of the agent <role> on the ticket <ticket>, which its control group
281
+ * gives: null where no group is given or on the machine a trial fixes
282
+ * (GRILLHOUSE_MESURE_D_ESSAI, without a <scope> of its own). Else the sampler of the group is
283
+ * started; `unite` names the group the session's command is to run in (`commandeDuGroupe`), and
284
+ * `garder(r)`, at the session's end (`r`, `{ status, signal, error }`), writes its line of the
285
+ * register, sort « seance-<role> ». <part>, the part the session holds, `id` the one that names
286
+ * the group; without one (a session out of the envelope) the line names no part.
287
+ * @param {{ racine: string, role: string, ticket?: string, env?: Record<string, string | undefined>,
288
+ * part?: { id: string, coeurs: number, memoire: number, limite?: number | null } | null,
289
+ * sonde?: () => boolean, scope?: { ouvrir: () => any }, horloge?: () => number,
290
+ * coeurs?: number }} o
291
+ * @returns {{ unite: string, garder: (r: unknown) => void } | null}
292
+ */
293
+ export function mesureDeLaSeance({
294
+ racine,
295
+ role,
296
+ ticket,
297
+ env = process.env,
298
+ part = null,
299
+ sonde,
300
+ scope,
301
+ horloge = Date.now,
302
+ coeurs = coeursDeLaMachine(),
303
+ }) {
304
+ if (
305
+ (env[VARIABLE_MESURE_D_ESSAI] && !scope) ||
306
+ groupeIndisponible({ env, ...(sonde ? { sonde } : {}) }) !== null
307
+ ) {
308
+ return null;
309
+ }
310
+ const sorte = sorteDeLaPasse(`séance ${role}`);
311
+ const ouvert = (
312
+ scope ??
313
+ scopeDeCommande({
314
+ racine,
315
+ sorte,
316
+ ticket,
317
+ coeurs,
318
+ part: {
319
+ coeurs: 1,
320
+ memoire: 0,
321
+ limite: null,
322
+ ...part,
323
+ id: part?.id ?? randomUUID(),
324
+ dossier: dossierDesParts(env),
325
+ },
326
+ })
327
+ ).ouvrir();
328
+ const debut = horloge();
329
+ return {
330
+ unite: ouvert.unite,
331
+ garder: r =>
332
+ garderLaMesure({ ouvert, racine, ticket, sorte, part, horloge, coeurs, debut, issue: issueDe(r) }),
333
+ };
334
+ }
335
+
263
336
  /**
264
337
  * How a pass asks whether the controller of the cores is delegated to the account: <delegation>
265
338
  * when its caller gives one; on the machine a trial fixes (GRILLHOUSE_MESURE_D_ESSAI) a function