@roomi-fields/grillhouse 0.45.0 → 0.46.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 (80) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +46 -0
  3. package/cadre/templates/projet/.github/workflows/machine-vierge.yml +101 -0
  4. package/cadre/templates/projet/CLAUDE.md +22 -5
  5. package/charte.md +45 -15
  6. package/dist/temporal/circuit/appel.d.ts +7 -0
  7. package/dist/temporal/circuit/appel.js +17 -0
  8. package/dist/temporal/circuit/appel.js.map +1 -1
  9. package/dist/temporal/circuit/client.d.ts +14 -0
  10. package/dist/temporal/circuit/client.js +17 -4
  11. package/dist/temporal/circuit/client.js.map +1 -1
  12. package/dist/temporal/circuit/commande.js +16 -4
  13. package/dist/temporal/circuit/commande.js.map +1 -1
  14. package/dist/temporal/circuit/contrat.d.ts +22 -2
  15. package/dist/temporal/circuit/contrat.js +76 -0
  16. package/dist/temporal/circuit/contrat.js.map +1 -1
  17. package/dist/temporal/circuit/deroule.js +68 -11
  18. package/dist/temporal/circuit/deroule.js.map +1 -1
  19. package/dist/temporal/commande.js +3 -0
  20. package/dist/temporal/commande.js.map +1 -1
  21. package/dist/temporal/file/contrat.d.ts +2 -0
  22. package/dist/temporal/installation.d.ts +5 -0
  23. package/dist/temporal/installation.js +23 -15
  24. package/dist/temporal/installation.js.map +1 -1
  25. package/dist/temporal/tickets/activites.d.ts +1 -0
  26. package/dist/temporal/tickets/activites.js +37 -2
  27. package/dist/temporal/tickets/activites.js.map +1 -1
  28. package/dist/temporal/tickets/contrat.d.ts +14 -0
  29. package/dist/temporal/tickets/deroule.js +16 -3
  30. package/dist/temporal/tickets/deroule.js.map +1 -1
  31. package/docs/ARCHITECTURE.md +204 -55
  32. package/docs/INTERFACE.md +8 -5
  33. package/hooks/register.tsx +30 -0
  34. package/package.json +1 -1
  35. package/scripts/activites.mjs +64 -15
  36. package/scripts/attente-a-l-arret.mjs +29 -52
  37. package/scripts/attente-au-tour.mjs +8 -26
  38. package/scripts/circuit.mjs +204 -64
  39. package/scripts/circuits-cles.d.mts +9 -0
  40. package/scripts/circuits-cles.mjs +38 -0
  41. package/scripts/coeurs-dedies.mjs +4 -3
  42. package/scripts/dernier-vert.mjs +66 -2
  43. package/scripts/enveloppe/travail-de-la-copie.mjs +5 -2
  44. package/scripts/etapes.mjs +6 -1
  45. package/scripts/faits-du-circuit.mjs +22 -3
  46. package/scripts/fichiers-nommes.mjs +55 -0
  47. package/scripts/file-des-tickets.d.mts +17 -0
  48. package/scripts/file-des-tickets.mjs +39 -0
  49. package/scripts/grillhouse-maj.mjs +20 -1
  50. package/scripts/integration/file.mjs +11 -5
  51. package/scripts/integration/integrer.mjs +4 -2
  52. package/scripts/langages/cargo/clippy.mjs +16 -9
  53. package/scripts/langages/cargo/commandes.mjs +7 -2
  54. package/scripts/langages/cargo/sccache.mjs +19 -6
  55. package/scripts/langages/typescript/tests.mjs +31 -5
  56. package/scripts/langages/typescript/turbo-des-paquets.mjs +51 -3
  57. package/scripts/langages/typescript/vitest-config/changements.mjs +32 -3
  58. package/scripts/langages/typescript/vitest-config/lances.mjs +16 -0
  59. package/scripts/limite-d-usage.mjs +88 -0
  60. package/scripts/outils-cles.d.mts +13 -5
  61. package/scripts/outils-cles.mjs +157 -17
  62. package/scripts/passe-de-la-machine.mjs +26 -2
  63. package/scripts/places-de-la-machine.mjs +52 -6
  64. package/scripts/plafond-de-la-machine.d.mts +10 -2
  65. package/scripts/plafond-de-la-machine.mjs +39 -13
  66. package/scripts/reponses-du-circuit.d.mts +16 -0
  67. package/scripts/reponses-du-circuit.mjs +39 -3
  68. package/scripts/resultats.mjs +32 -11
  69. package/scripts/seances.mjs +211 -59
  70. package/scripts/session-start.sh +2 -2
  71. package/scripts/sous-commandes.mjs +5 -2
  72. package/scripts/superviseur.mjs +178 -226
  73. package/scripts/tableau.mjs +50 -37
  74. package/scripts/transitions.d.mts +22 -1
  75. package/scripts/transitions.mjs +111 -13
  76. package/scripts/workflows-du-cadre.mjs +21 -1
  77. package/skills/explorateur/SKILL.md +34 -13
  78. package/skills/pitmaster/SKILL.md +24 -20
  79. package/skills/relecteur/SKILL.md +6 -0
  80. package/skills/testwriter/SKILL.md +4 -0
@@ -0,0 +1,88 @@
1
+ // The usage limit of `claude -p`: its text « limit · resets <time> (<zone>) », read in the result
2
+ // of a session or at the end of its log. It gives the hour the usage returns, understood in the
3
+ // zone written, at the next instant after now. A « resets » whose time or zone does not read is a
4
+ // limit without a readable hour: the circuit waits an hour. A text that cites « limit » without
5
+ // « resets », or elsewhere than at the end of the log, is not one.
6
+
7
+ const HEURE = 3_600_000;
8
+ const LIGNES_DE_FIN = 20;
9
+
10
+ // The offset of <fuseau> from UTC at the instant <ms>, in ms; throws on an unknown zone.
11
+ function decalage(fuseau, ms) {
12
+ const p = Object.fromEntries(
13
+ new Intl.DateTimeFormat('en-US', {
14
+ timeZone: fuseau,
15
+ hourCycle: 'h23',
16
+ year: 'numeric',
17
+ month: 'numeric',
18
+ day: 'numeric',
19
+ hour: 'numeric',
20
+ minute: 'numeric',
21
+ second: 'numeric',
22
+ })
23
+ .formatToParts(ms)
24
+ .map(x => [x.type, Number(x.value)])
25
+ );
26
+ return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - Math.floor(ms / 1000) * 1000;
27
+ }
28
+
29
+ // The first instant after <maintenant> at which the wall clock of <fuseau> reads <h>:<m>, or null.
30
+ function prochainInstant(h, m, fuseau, maintenant) {
31
+ try {
32
+ const jour = new Date(maintenant + decalage(fuseau, maintenant));
33
+ for (let plus = 0; plus <= 2; plus++) {
34
+ const local = Date.UTC(
35
+ jour.getUTCFullYear(),
36
+ jour.getUTCMonth(),
37
+ jour.getUTCDate() + plus,
38
+ h,
39
+ m
40
+ );
41
+ const instant = local - decalage(fuseau, local - decalage(fuseau, local));
42
+ if (instant > maintenant) {
43
+ return instant;
44
+ }
45
+ }
46
+ } catch {
47
+ // An unknown zone: no readable hour.
48
+ }
49
+ return null;
50
+ }
51
+
52
+ // The limit <texte> says, `{ reprise, lisible }`, or null.
53
+ function lire(texte, maintenant) {
54
+ const dit = /limit\s*·\s*resets\b([^\n"]*)/i.exec(texte ?? '');
55
+ if (!dit) {
56
+ return null;
57
+ }
58
+ const heure =
59
+ /(?:[A-Za-z]{3,9}\s+\d{1,2},?\s+)?\b(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*\(([^)]+)\)/i.exec(dit[1]);
60
+ if (heure) {
61
+ const h12 = Number(heure[1]);
62
+ if (h12 >= 1 && h12 <= 12) {
63
+ const h = (h12 % 12) + (heure[3].toLowerCase() === 'pm' ? 12 : 0);
64
+ const reprise = prochainInstant(h, Number(heure[2] ?? 0), heure[4].trim(), maintenant);
65
+ if (reprise !== null) {
66
+ return { reprise, lisible: true };
67
+ }
68
+ }
69
+ }
70
+ return { reprise: maintenant + HEURE, lisible: false };
71
+ }
72
+
73
+ /**
74
+ * The usage limit that stops a session, `{ reprise, lisible }` (<reprise> the hour it returns, in
75
+ * ms; one hour after <maintenant> when the text gives none that reads), or null: read in the
76
+ * result <resultat>, else in the last lines of <journal>.
77
+ */
78
+ export function limiteDUsage({ resultat = null, journal = null }, maintenant = Date.now()) {
79
+ const dansLeResultat = lire(resultat, maintenant);
80
+ if (dansLeResultat) {
81
+ return dansLeResultat;
82
+ }
83
+ const fin = String(journal ?? '')
84
+ .split('\n')
85
+ .slice(-LIGNES_DE_FIN)
86
+ .join('\n');
87
+ return lire(fin, maintenant);
88
+ }
@@ -10,15 +10,23 @@ export function lireOutils(
10
10
  reel?: (p: string) => string;
11
11
  montages?: string[];
12
12
  }
13
- ): { outils: Record<string, string>; fautes: string[] };
13
+ ): { outils: Record<string, string>; contenu: string[]; fautes: string[] };
14
+ /** The SHA-256 of the tool at <chemin>, a file or a directory; throws an unreadable or special file. */
15
+ export function empreinteDeLOutil(chemin: string, nomme?: string): string;
16
+ /** `<VARIABLE>_EMPREINTE` of each tool of the project that holds <dir> hashed by content. */
17
+ export function empreintesDe(dir: string, options?: { montages?: string[] }): Record<string, string>;
14
18
  /** The main tree of the repository that holds <dir>. */
15
19
  export function arbrePrincipal(dir: string): string;
16
20
  /** The tools of the project that holds <dir>; throws the faults of the key. */
17
21
  export function outilsDe(dir: string, options?: { montages?: string[] }): Record<string, string>;
18
- /** The environment <env> of a pass with the tools <outils>, the tools winning. */
22
+ /** The environment <env> of a pass with the tools <outils> and their fingerprints, the key winning. */
19
23
  export function avecLesOutils<T extends Record<string, string | undefined>>(
20
24
  outils: Record<string, string>,
21
- env: T
25
+ env: T,
26
+ empreintes?: Record<string, string>
22
27
  ): T & Record<string, string>;
23
- /** The shell's text that exports the tools <outils>, one line each. */
24
- export function exportsDesOutils(outils: Record<string, string>): string;
28
+ /** The shell's text that exports the tools <outils> and the fingerprints, one line each. */
29
+ export function exportsDesOutils(
30
+ outils: Record<string, string>,
31
+ empreintes?: Record<string, string>
32
+ ): string;
@@ -17,13 +17,27 @@
17
17
  // the machine keeps its credentials, but `~/.local` and `~/.cache`; nor under or holding
18
18
  // `~/.local/share/keyrings`, the keyrings of the machine's credentials. A path that is a link is
19
19
  // judged by its target too, which the envelope mounts with it.
20
+ // - A tool is a string path (unhashed) or `{ "chemin": "<chemin>", "contenu": true }`: hashed by
21
+ // content, Bazel counting the tools of an action among its inputs. Its fingerprint
22
+ // (`empreinteDeLOutil`, `empreintesDe`) is given to every pass as `<VARIABLE>_EMPREINTE`, which
23
+ // the root turbo.json's `globalEnv` names so that Turborepo hashes its value. Any other object
24
+ // form is refused, its key named; a hashed tool absent, unreadable or special is refused too.
20
25
  // - The key is read from the package.json of the main tree of the repository (`outilsDe`), never of
21
26
  // a copy: an agent never opens a path for its next session.
22
27
  // - `node outils-cles.mjs <dir>` writes one line `export VARIABLE='chemin'` per tool of the project
23
28
  // that holds <dir>, the path resolved and quoted for the shell (`exportsDesOutils`), which the
24
29
  // night evaluates, exit 0; a faulty key writes its faults on stderr, exit 1.
25
30
  import { spawnSync } from 'node:child_process';
26
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
31
+ import { createHash } from 'node:crypto';
32
+ import {
33
+ existsSync,
34
+ lstatSync,
35
+ readdirSync,
36
+ readFileSync,
37
+ readlinkSync,
38
+ realpathSync,
39
+ statSync,
40
+ } from 'node:fs';
27
41
  import os from 'node:os';
28
42
  import path from 'node:path';
29
43
  import { pathToFileURL } from 'node:url';
@@ -90,11 +104,12 @@ export function lireOutils(
90
104
  ) {
91
105
  const o = pkg?.grillhouse?.outils;
92
106
  if (o === undefined || o === null) {
93
- return { outils: {}, fautes: [] };
107
+ return { outils: {}, contenu: [], fautes: [] };
94
108
  }
95
109
  if (typeof o !== 'object' || Array.isArray(o)) {
96
110
  return {
97
111
  outils: {},
112
+ contenu: [],
98
113
  fautes: [
99
114
  `la clé grillhouse.outils vaut ${JSON.stringify(o)}, pas un objet { VARIABLE: chemin }.`,
100
115
  ],
@@ -104,9 +119,29 @@ export function lireOutils(
104
119
  const fautes = [];
105
120
  /** @type {Record<string, string>} */
106
121
  const outils = {};
107
- for (const [nom, v] of Object.entries(o)) {
122
+ /** @type {string[]} */
123
+ const contenu = [];
124
+ for (const [nom, forme] of Object.entries(o)) {
108
125
  const cle = `grillhouse.outils.${nom}`;
109
- if (!NOM.test(nom)) {
126
+ let v = forme;
127
+ let haché = false;
128
+ let faute = null;
129
+ if (forme !== null && typeof forme === 'object' && !Array.isArray(forme)) {
130
+ const inconnue = Object.keys(forme).find(k => k !== 'chemin' && k !== 'contenu');
131
+ if (inconnue !== undefined) {
132
+ faute = `la clé ${cle} nomme « ${inconnue} », une clé inconnue (seuls « chemin » et « contenu » existent).`;
133
+ } else if (typeof forme.chemin !== 'string') {
134
+ faute = `la clé ${cle}.chemin vaut ${JSON.stringify(forme.chemin)}, pas un chemin.`;
135
+ } else if ('contenu' in forme && typeof forme.contenu !== 'boolean') {
136
+ faute = `la clé ${cle}.contenu vaut ${JSON.stringify(forme.contenu)}, pas un booléen.`;
137
+ } else {
138
+ v = forme.chemin;
139
+ haché = forme.contenu === true;
140
+ }
141
+ }
142
+ if (faute) {
143
+ fautes.push(faute);
144
+ } else if (!NOM.test(nom)) {
110
145
  fautes.push(`la clé grillhouse.outils nomme « ${nom} », pas un nom de variable.`);
111
146
  } else if (typeof v !== 'string') {
112
147
  fautes.push(`la clé ${cle} vaut ${JSON.stringify(v)}, pas un chemin.`);
@@ -125,12 +160,89 @@ export function lireOutils(
125
160
  fautes.push(`${refusDeLaCible} (la cible du lien ${chemin})`);
126
161
  } else if (existe(chemin)) {
127
162
  outils[nom] = chemin;
163
+ if (haché) {
164
+ contenu.push(nom);
165
+ }
128
166
  } else {
129
167
  fautes.push(`la clé ${cle} nomme ${chemin}, qui n'existe pas.`);
130
168
  }
131
169
  }
132
170
  }
133
- return { outils: fautes.length ? {} : outils, fautes };
171
+ return fautes.length ? { outils: {}, contenu: [], fautes } : { outils, contenu, fautes };
172
+ }
173
+
174
+ // The directories the fingerprint of a directory tool leaves out: the compilation caches an
175
+ // interpreter writes when used.
176
+ const SANS_EMPREINTE = new Set(['__pycache__']);
177
+
178
+ // The entries of the tool <racine> as lines [relative path, type, executable bit, content digest],
179
+ // the directory walked in the order of the bytes of the names.
180
+ function entreesDe(racine, rel, lignes, nomme) {
181
+ const dossier = path.join(racine, rel);
182
+ let noms;
183
+ try {
184
+ noms = readdirSync(dossier, { encoding: 'buffer' }).sort(Buffer.compare);
185
+ } catch (e) {
186
+ throw new Error(`${nomme} : ${dossier} est illisible (${/** @type {Error} */ (e).message}).`);
187
+ }
188
+ for (const buf of noms) {
189
+ const nom = buf.toString('utf8');
190
+ const r = rel ? path.join(rel, nom) : nom;
191
+ const p = path.join(racine, r);
192
+ const st = lstatSync(p);
193
+ if (st.isDirectory()) {
194
+ if (!SANS_EMPREINTE.has(nom)) {
195
+ entreesDe(racine, r, lignes, nomme);
196
+ }
197
+ } else if (st.isSymbolicLink()) {
198
+ lignes.push(['l', r, '0', readlinkSync(p)]);
199
+ } else if (st.isFile()) {
200
+ lignes.push(['f', r, st.mode & 0o111 ? '1' : '0', contenuDe(p, nomme)]);
201
+ } else {
202
+ throw new Error(`${nomme} : ${p} est un fichier spécial (ni fichier, ni dossier, ni lien).`);
203
+ }
204
+ }
205
+ }
206
+
207
+ // The SHA-256 of the file <p>, the tool <nomme> named when it is unreadable.
208
+ function contenuDe(p, nomme) {
209
+ try {
210
+ return createHash('sha256').update(readFileSync(p)).digest('hex');
211
+ } catch (e) {
212
+ throw new Error(`${nomme} : ${p} est illisible (${/** @type {Error} */ (e).message}).`);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * The fingerprint of the tool at <chemin>: for a file, the SHA-256 of its content; for a
218
+ * directory, the SHA-256 of the list of its entries sorted by the bytes of their relative path,
219
+ * each by its path, its type, its executable bit and its content (a link by the text of its target,
220
+ * never followed); the `__pycache__` directories are left out; no date, owner or absolute path
221
+ * enters it, so a directory moved or touched keeps it.
222
+ * @param {string} chemin
223
+ * @param {string} [nomme] what an error names (the tool), the path by default
224
+ * @returns {string} a hex digest
225
+ * @throws {Error} an unreadable file or a special file, named
226
+ */
227
+ export function empreinteDeLOutil(chemin, nomme = chemin) {
228
+ // The tool itself, a link or not, is read through (the envelope mounts what it leads to).
229
+ const st = statSync(chemin);
230
+ if (!st.isDirectory()) {
231
+ return contenuDe(chemin, nomme);
232
+ }
233
+ /** @type {string[][]} */
234
+ const lignes = [];
235
+ entreesDe(chemin, '', lignes, nomme);
236
+ const h = createHash('sha256');
237
+ for (const l of lignes) {
238
+ // Each field is prefixed by its length: the boundaries of names and contents count.
239
+ for (const champ of l) {
240
+ const b = Buffer.from(champ, 'utf8');
241
+ h.update(`${b.length}:`).update(b);
242
+ }
243
+ h.update('\n');
244
+ }
245
+ return h.digest('hex');
134
246
  }
135
247
 
136
248
  // The main tree of the repository that holds <dir>, from git's common directory; <dir> itself out
@@ -156,41 +268,69 @@ export function arbrePrincipal(dir) {
156
268
  * @throws {Error} the faults of the key, one per line
157
269
  */
158
270
  export function outilsDe(dir, { montages = [] } = {}) {
271
+ return lectureDuProjet(dir, montages).outils;
272
+ }
273
+
274
+ // The reading of the key of the project that holds <dir>: `outils` and the variables hashed by
275
+ // content, `contenu`; throws the faults of the key.
276
+ function lectureDuProjet(dir, montages = []) {
159
277
  const racine = arbrePrincipal(dir);
160
278
  const f = path.join(racine, 'package.json');
161
279
  if (!existsSync(f)) {
162
- return {};
280
+ return { outils: {}, contenu: [] };
163
281
  }
164
282
  const temporaires = [process.env.CLAUDE_CODE_TMPDIR, os.tmpdir(), '/tmp'].filter(Boolean);
165
- const { outils, fautes } = lireOutils(JSON.parse(readFileSync(f, 'utf8')), {
283
+ const { outils, contenu, fautes } = lireOutils(JSON.parse(readFileSync(f, 'utf8')), {
166
284
  montages: [racine, ...temporaires, ...montages],
167
285
  });
168
286
  if (fautes.length) {
169
287
  throw new Error(fautes.join('\n'));
170
288
  }
171
- return outils;
289
+ return { outils, contenu };
290
+ }
291
+
292
+ /**
293
+ * The fingerprints of the tools of the project that holds <dir> declared hashed by content
294
+ * (`{ chemin, contenu: true }`): `<VARIABLE>_EMPREINTE` and the SHA-256 of the tool
295
+ * (`empreinteDeLOutil`), read again at each call; none for a tool of the short form.
296
+ * @param {string} dir a directory of the project: its main tree or a copy
297
+ * @param {{ montages?: string[] }} [o]
298
+ * @returns {Record<string, string>}
299
+ * @throws {Error} the faults of the key, or a hashed tool unreadable, its variable named
300
+ */
301
+ export function empreintesDe(dir, { montages = [] } = {}) {
302
+ const { outils, contenu } = lectureDuProjet(dir, montages);
303
+ return Object.fromEntries(
304
+ contenu.map(nom => [
305
+ `${nom}_EMPREINTE`,
306
+ empreinteDeLOutil(outils[nom], `la clé grillhouse.outils.${nom}`),
307
+ ])
308
+ );
172
309
  }
173
310
 
174
311
  /**
175
- * The environment <env> of a pass with the tools <outils> (`outilsDe`), the tools winning.
312
+ * The environment <env> of a pass with the tools <outils> (`outilsDe`) and the fingerprints
313
+ * <empreintes> (`empreintesDe`), the key winning.
176
314
  * @param {Record<string, string>} outils
177
315
  * @param {Record<string, string | undefined>} env
316
+ * @param {Record<string, string>} [empreintes]
178
317
  */
179
- export function avecLesOutils(outils, env) {
180
- return { ...env, ...outils };
318
+ export function avecLesOutils(outils, env, empreintes = {}) {
319
+ return { ...env, ...outils, ...empreintes };
181
320
  }
182
321
 
183
- // The shell's text that exports the tools <outils> (`outilsDe`), one `export VARIABLE='chemin'`
184
- // per line, each path quoted for the shell: what the night evaluates before its commands.
185
- export const exportsDesOutils = outils =>
186
- Object.entries(outils)
322
+ // The shell's text that exports the tools <outils> (`outilsDe`) and the fingerprints
323
+ // <empreintes> (`empreintesDe`), one `export VARIABLE='valeur'` per line, each value quoted for
324
+ // the shell: what the night evaluates before its commands.
325
+ export const exportsDesOutils = (outils, empreintes = {}) =>
326
+ Object.entries({ ...outils, ...empreintes })
187
327
  .map(([n, c]) => `export ${n}='${c.replaceAll("'", "'\\''")}'\n`)
188
328
  .join('');
189
329
 
190
330
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
191
331
  try {
192
- const outils = outilsDe(path.resolve(process.argv[2] ?? '.'));
193
- process.stdout.write(exportsDesOutils(outils));
332
+ const dir = path.resolve(process.argv[2] ?? '.');
333
+ process.stdout.write(exportsDesOutils(outilsDe(dir), empreintesDe(dir)));
194
334
  } catch (e) {
195
335
  process.stderr.write(`${/** @type {Error} */ (e).message}\n`);
196
336
  process.exitCode = 1;
@@ -48,6 +48,7 @@ import {
48
48
  prendreUnePart,
49
49
  sousNiceEtIonice,
50
50
  travailleursDe,
51
+ VARIABLE_MESURE_D_ESSAI,
51
52
  VARIABLE_TRAVAILLEURS,
52
53
  } from './places-de-la-machine.mjs';
53
54
 
@@ -260,6 +261,28 @@ function jouerMesuree(jouer, { ouvert, racine, ticket, sorte, part, horloge, coe
260
261
  }
261
262
  }
262
263
 
264
+ /**
265
+ * How a pass asks whether the controller of the cores is delegated to the account: <delegation>
266
+ * when its caller gives one; on the machine a trial fixes (GRILLHOUSE_MESURE_D_ESSAI) a function
267
+ * that answers no without asking the system, so that a trial's measure is held by the affinity of
268
+ * its launch and moves no program of the user's machine off its cores; else undefined, the
269
+ * system's own answer (`attacheDesCoeurs`).
270
+ * @param {{ env?: Record<string, string | undefined>, delegation?: () => boolean }} o
271
+ * @returns {(() => boolean) | undefined}
272
+ */
273
+ export const delegationDeLaPasse = ({ env = process.env, delegation }) =>
274
+ delegation ?? (env[VARIABLE_MESURE_D_ESSAI] ? () => false : undefined);
275
+
276
+ /**
277
+ * Whether a pass judges the load of its dedicated cores while it plays: a measure of time
278
+ * (<dediee>) held on its cores (<voie>, a group or an affinity), on the user's machine. On the
279
+ * machine a trial fixes (GRILLHOUSE_MESURE_D_ESSAI) it does not: no trial reads the load of the
280
+ * user's machine, and its red keeps its code.
281
+ * @param {{ dediee?: boolean, voie?: string, env?: Record<string, string | undefined> }} o
282
+ */
283
+ export const jugeLaChargeDuJeu = ({ dediee, voie, env = process.env }) =>
284
+ Boolean(dediee) && voie !== undefined && voie !== 'aucune' && !env[VARIABLE_MESURE_D_ESSAI];
285
+
263
286
  /**
264
287
  * Plays <mesure> on its part of the machine, held to it by the system, and returns what it
265
288
  * returns; <mesure> receives the environment of its children (the mark of the part, the workers
@@ -306,10 +329,11 @@ export function avecLaPasse(
306
329
  const direSansPart = direUneFois(dire);
307
330
  // How the precise threads of the part are held: the allowed cores of a group, the affinity of
308
331
  // the launch, or not at all; a measure of time says it once.
332
+ const delegationLue = delegationDeLaPasse({ env, delegation });
309
333
  const attache = prise.fils
310
334
  ? attacheDesCoeurs({
311
335
  env,
312
- ...(delegation ? { delegation } : {}),
336
+ ...(delegationLue ? { delegation: delegationLue } : {}),
313
337
  ...(affinite ? { affinite } : {}),
314
338
  })
315
339
  : null;
@@ -361,7 +385,7 @@ export function avecLaPasse(
361
385
  // A measure of time judges the load of its dedicated cores while it plays: the busy time of
362
386
  // those cores out of its own (read from its group), a red on loaded cores « à repasser ».
363
387
  const jugee = (jouer, ouvert) => () => {
364
- if (!prise.dediee || !attache || attache.voie === 'aucune') {
388
+ if (!jugeLaChargeDuJeu({ dediee: prise.dediee, voie: attache?.voie, env })) {
365
389
  return jouer();
366
390
  }
367
391
  const avant = lireLesTempsOccupes(tempsDuSysteme());
@@ -63,6 +63,7 @@ import { mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync } from 'node:fs
63
63
  import { availableParallelism, homedir } from 'node:os';
64
64
  import path from 'node:path';
65
65
  import { departDe } from './mesure/base-de-passe.mjs';
66
+ import { lireLaConsommation } from './consommation-des-passes.mjs';
66
67
  import { ecrireAtomique } from './mesure/avancement.mjs';
67
68
  import { A_REPASSER } from './codes-de-sortie.mjs';
68
69
  import {
@@ -469,7 +470,40 @@ export function partDeLaPasse({ racine, env = process.env }) {
469
470
  if (faute) {
470
471
  throw new AttenteDeLaMachine(`✗ ${faute}`, 1);
471
472
  }
472
- return partDe({ declaree, budget: budgetDeLaPasse(env) });
473
+ return partDe({
474
+ declaree,
475
+ budget: budgetDeLaPasse(env),
476
+ places: plafondDe(env),
477
+ pic: plusGrandPicDeJour(racineDuDepot(racine)),
478
+ });
479
+ }
480
+
481
+ // The kinds of pass the night and the measures of time write: their peaks are not those of a day.
482
+ const SORTES_HORS_JOUR = new Set(['nuit', 'tests-de-nuit', 'mesure']);
483
+
484
+ /**
485
+ * The largest peak of memory (bytes) of the day passes in the register of the project at <racine>;
486
+ * undefined without one. A line without a readable peak, a malformed one and those of the night
487
+ * and of the measures of time do not count.
488
+ * @param {string} racine
489
+ * @returns {number | undefined}
490
+ */
491
+ function plusGrandPicDeJour(racine) {
492
+ let pic;
493
+ for (const l of lireLaConsommation(racine)) {
494
+ const p = l.memoirePic;
495
+ if (
496
+ SORTES_HORS_JOUR.has(l.sorte) ||
497
+ l.sorte.startsWith('mesure') ||
498
+ typeof p !== 'number' ||
499
+ !Number.isFinite(p) ||
500
+ p <= 0
501
+ ) {
502
+ continue;
503
+ }
504
+ pic = Math.max(pic ?? 0, p);
505
+ }
506
+ return pic;
473
507
  }
474
508
 
475
509
  // The `package.json` of the main tree of the repository at <racine>; empty without one (a
@@ -489,12 +523,12 @@ function packageDuDepot(racine) {
489
523
  * @returns {number}
490
524
  * @throws {AttenteDeLaMachine} naming the key (code 1) when its value is faulty, before any work
491
525
  */
492
- function coeursDeLaMesure({ racine, budget }) {
526
+ function coeursDeLaMesure({ racine, budget, env }) {
493
527
  const { declaree, faute } = mesureDeclareeDe(packageDuDepot(racine));
494
528
  if (faute) {
495
529
  throw new AttenteDeLaMachine(`✗ ${faute}`, 1);
496
530
  }
497
- return coeursDeLaMesureDe({ declaree, budget });
531
+ return coeursDeLaMesureDe({ declaree, budget, places: plafondDe(env) });
498
532
  }
499
533
 
500
534
  const RANGS = { 1: 'mesure du cadre', 2: "mesure d'un projet" };
@@ -515,6 +549,18 @@ function sousLAdmission(dossier, f) {
515
549
  }
516
550
  }
517
551
 
552
+ /**
553
+ * How a measure reads the load of the threads it was given under <env>: on the machine a trial
554
+ * fixes (GRILLHOUSE_MESURE_D_ESSAI) they are at rest, no trial reading the load of the user's
555
+ * machine; else the load the system gives (<systeme>).
556
+ * @param {Record<string, string | undefined>} [env]
557
+ * @param {(fils: number[]) => number | null} [systeme]
558
+ * @returns {(fils: number[]) => number | null}
559
+ */
560
+ export function lecteurDeLaCharge(env = process.env, systeme = chargeDesCoeursDuSysteme) {
561
+ return env[VARIABLE_MESURE_D_ESSAI] ? () => 0 : systeme;
562
+ }
563
+
518
564
  /**
519
565
  * Takes the part of a pass of the project at <racine>, waiting for it, saying what it waits for
520
566
  * (`dire`) when it begins and every <rappelMs>, and returns it. Room first on the disks the pass
@@ -524,7 +570,7 @@ function sousLAdmission(dossier, f) {
524
570
  * « tient ». The night (VARIABLE_JETON) and a pass that asks for the <entiere> budget take the
525
571
  * whole budget: they play alone. A <mesure> of time takes dedicated cores (`fils`, whole physical
526
572
  * cores), waits for them and for their rest (<chargeDesCoeurs>: the load of the threads it gives,
527
- * null without a reading; <topologie>, the topology of the system, for a trial). Where no part is taken (the envelope of an agent, a part already
573
+ * null without a reading, by default `lecteurDeLaCharge`; <topologie>, the topology of the system, for a trial). Where no part is taken (the envelope of an agent, a part already
528
574
  * held: GRILLHOUSE_PART_TENUE) the part returned holds nothing.
529
575
  * @param {{ env?: Record<string, string | undefined>, racine?: string, ticket?: string | null,
530
576
  * sorte?: string, entiere?: boolean, borneMs?: number, rappelMs?: number,
@@ -546,7 +592,7 @@ export function prendreUnePart({
546
592
  entiere = false,
547
593
  mesure = false,
548
594
  topologie,
549
- chargeDesCoeurs = chargeDesCoeursDuSysteme,
595
+ chargeDesCoeurs = lecteurDeLaCharge(env),
550
596
  borneMs = borneDe(env),
551
597
  rappelMs = RAPPEL_MS,
552
598
  dire = l => process.stdout.write(`${l}\n`),
@@ -576,7 +622,7 @@ export function prendreUnePart({
576
622
  topo = topologie ?? lireLaTopologie({ nombreDeFils: machineDe(env).coeurs });
577
623
  budgetFils = budgetEnFils({ topologie: topo, budget: budget.coeurs });
578
624
  if (mesure) {
579
- const demande = coeursDeLaMesure({ racine, budget });
625
+ const demande = coeursDeLaMesure({ racine, budget, env });
580
626
  let fils = filsDeLaMesure({ budget: budgetFils, topologie: topo, demande });
581
627
  if (fils === null || !topo.lisible) {
582
628
  // No whole core in the budget, or a topology that does not read: each thread is a core.
@@ -41,13 +41,21 @@ export function budgetDe(
41
41
  reserve: PartDeLaPasse
42
42
  ): PartDeLaPasse;
43
43
 
44
- /** The part of a pass when its project declares none. */
45
- export function partParDefautDe(budget: PartDeLaPasse): PartDeLaPasse;
44
+ /** The part of a pass when its project declares none: the budget divided by the places (2 cores
45
+ * at least), the largest measured peak of memory plus a quarter, never under its floor, a third of
46
+ * the budget (the floor alone without a measure). */
47
+ export function partParDefautDe(
48
+ budget: PartDeLaPasse,
49
+ places: number,
50
+ pic: number | undefined
51
+ ): PartDeLaPasse;
46
52
 
47
53
  /** The part of a pass: the declared one, its missing values from the default, within the budget. */
48
54
  export function partDe(o: {
49
55
  declaree: { coeurs?: number; memoire?: number } | null;
50
56
  budget: PartDeLaPasse;
57
+ places: number;
58
+ pic: number | undefined;
51
59
  }): PartDeLaPasse;
52
60
 
53
61
  /** The part a project declares in `grillhouse.part` of its package.json, or the fault naming it. */
@@ -19,10 +19,12 @@
19
19
  // `machine.env`; zero is admitted, a value that is not a whole number ≥ 0 is refused by its name.
20
20
  // - The budget is the cores and the memory of the machine less the reserve; a reserve that leaves
21
21
  // no core or no memory is refused by its name.
22
- // - The part of a pass is its cores and its memory: the default part has MIN_COEURS_DE_LA_PART
23
- // cores at least (a third of the budget when that is more), its memory in proportion; a part a project
24
- // declares (`grillhouse.part` of its `package.json`) replaces it; a part larger than the budget
25
- // is the budget (one pass at a time), and never under one core.
22
+ // - The part of a pass is its cores and its memory: the default part has the budget divided by the
23
+ // places of the machine in cores (whole division, 2 at least), and in memory the largest peak the
24
+ // project measured plus a quarter, never under its floor (the cores' proportion of the budget
25
+ // before the division, a third of it, which it is without a measure); a
26
+ // part a project declares (`grillhouse.part` of its `package.json`) replaces its own values; a
27
+ // part larger than the budget is the budget (one pass at a time), and never under one core.
26
28
  import { readFileSync } from 'node:fs';
27
29
  import { cpus, totalmem } from 'node:os';
28
30
  import path from 'node:path';
@@ -150,32 +152,56 @@ export function budgetDe({ coeurs, memoireTotale }, reserve) {
150
152
  return { coeurs: coeurs - reserve.coeurs, memoire: memoireTotale - reserve.memoire };
151
153
  }
152
154
 
155
+ /** The margin over the largest measured peak of memory: a quarter. */
156
+ const MARGE_DE_LA_MEMOIRE = 1.25;
157
+
153
158
  /**
154
- * The part of a pass when its project declares none: MIN_COEURS_DE_LA_PART cores (a third of the
155
- * budget, rounded up, when that is more), within the budget and one core at least, its memory in proportion of its
156
- * cores.
159
+ * The part of a pass when its project declares none, pure: the budget divided by the <places> of
160
+ * the machine in cores (whole division, 2 at least, within the budget and one core at least), and
161
+ * in memory the largest measured peak <pic> plus a quarter (the hard ceiling of the group kills a
162
+ * pass above it, so a percentile would not do), within the budget and never under its floor, the
163
+ * proportion of the cores of a part before the division (a third of the budget): the peak raises
164
+ * the memory, it does not lower it; the floor alone when <pic> is absent.
157
165
  * @param {{ coeurs: number, memoire: number }} budget
166
+ * @param {number} places
167
+ * @param {number | undefined} pic the largest peak of memory of the day passes, absent unmeasured
158
168
  * @returns {{ coeurs: number, memoire: number }}
159
169
  */
160
- export function partParDefautDe(budget) {
170
+ export function partParDefautDe(budget, places, pic) {
161
171
  const coeurs = Math.max(
172
+ 1,
173
+ Math.min(budget.coeurs, Math.max(2, Math.floor(budget.coeurs / places)))
174
+ );
175
+ return { coeurs, memoire: memoireParDefautDe(budget, pic) };
176
+ }
177
+
178
+ // The default memory, independent of the division by the places: its floor, the proportion of the
179
+ // cores a part had before the division (MIN_COEURS_DE_LA_PART, or a third of the budget rounded up
180
+ // when that is more), raised to the peak plus a quarter when the register measured more. A
181
+ // register that holds light passes alone (the guards, a pass of 50 ms: a peak of 16 Mo) would
182
+ // else give the next pass a ceiling its kernel kills it under, as the Vertical Pod Autoscaler
183
+ // bounds its recommendation by a minimum (`minAllowed`).
184
+ function memoireParDefautDe(budget, pic) {
185
+ const coeursDAvant = Math.max(
162
186
  1,
163
187
  Math.min(budget.coeurs, Math.max(MIN_COEURS_DE_LA_PART, Math.ceil(budget.coeurs / 3)))
164
188
  );
165
- return { coeurs, memoire: Math.floor((budget.memoire * coeurs) / budget.coeurs) };
189
+ const plancher = Math.floor((budget.memoire * coeursDAvant) / budget.coeurs);
190
+ return Math.min(budget.memoire, Math.max(plancher, Math.floor((pic ?? 0) * MARGE_DE_LA_MEMOIRE)));
166
191
  }
167
192
 
168
193
  /**
169
194
  * The part of a pass: the one its project declares (`partDeclareeDe`), its missing values from the
170
195
  * default part, within the budget and one core at least.
171
196
  * @param {{ declaree: { coeurs?: number, memoire?: number } | null,
172
- * budget: { coeurs: number, memoire: number } }} o
197
+ * budget: { coeurs: number, memoire: number }, places: number, pic: number | undefined }} o
173
198
  * @returns {{ coeurs: number, memoire: number }}
174
199
  */
175
- export function partDe({ declaree, budget }) {
176
- const defaut = partParDefautDe(budget);
200
+ export function partDe({ declaree, budget, places, pic }) {
201
+ const defaut = partParDefautDe(budget, places, pic);
202
+ const coeurs = Math.max(1, Math.min(budget.coeurs, declaree?.coeurs ?? defaut.coeurs));
177
203
  return {
178
- coeurs: Math.max(1, Math.min(budget.coeurs, declaree?.coeurs ?? defaut.coeurs)),
204
+ coeurs,
179
205
  memoire: Math.min(budget.memoire, declaree?.memoire ?? defaut.memoire),
180
206
  };
181
207
  }
@@ -4,3 +4,19 @@
4
4
  export const SANS_ISSUE: Set<string>;
5
5
  /** The answers accepted for the circuit of <ticket> whose workflow has the status <statut>. */
6
6
  export function lesReponses(ticket: string, statut: string, ecrit: boolean): string;
7
+ /** The stops of the testwriter that `--mecanique` answers. */
8
+ export const ARRETS_DU_TESTWRITER: string[];
9
+ /** The sort of a ticket, as the plan says it (scripts/resultats.mjs `sorteDuPlan`). */
10
+ export interface SorteDuTicket {
11
+ genre: string;
12
+ raison: string | null;
13
+ comportement?: 'changé' | 'tests-adaptés' | 'inchangé';
14
+ commande?: string;
15
+ }
16
+ /** The answer `--mecanique` to the stop <etat> of a ticket of sort <sorte>: a refusal, or its new sort and step. */
17
+ export function reponseMecanique(o: {
18
+ etat: { etape: string; raison?: string | null } | null;
19
+ sorte: { genre: string } | null;
20
+ commande: string | null;
21
+ contexte: string | null;
22
+ }): { refus: string } | { sorte: SorteDuTicket; suivant: { etape: string } };