@roomi-fields/grillhouse 0.42.0 → 0.43.1

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.
@@ -12,19 +12,39 @@ import { departDe, leMemeVivant, vivant } from './mesure/base-de-passe.mjs';
12
12
  export { departDe };
13
13
 
14
14
  /**
15
- * The memory available now, in bytes (MemAvailable of the kernel, else the free memory of node).
16
- * @returns {number}
15
+ * What <texte> (/proc/meminfo) says the machine still gives, in bytes: the memory available
16
+ * (MemAvailable, null when it does not say it) and the free swap (SwapFree, 0 without swap).
17
+ * @param {string} texte
18
+ * @returns {{ disponible: number | null, echange: number }}
17
19
  */
18
- export function memoireDisponible() {
20
+ export function lireLaMemoire(texte) {
21
+ const kio = cle => new RegExp(`^${cle}:\\s+(\\d+) kB`, 'm').exec(texte)?.[1];
22
+ const disponible = kio('MemAvailable');
23
+ return {
24
+ disponible: disponible === undefined ? null : Number(disponible) * 1024,
25
+ echange: Number(kio('SwapFree') ?? 0) * 1024,
26
+ };
27
+ }
28
+
29
+ /**
30
+ * What the machine still gives now, as `lireLaMemoire`; nothing known where /proc/meminfo does
31
+ * not read.
32
+ * @returns {{ disponible: number | null, echange: number }}
33
+ */
34
+ export function memoireRestante() {
19
35
  try {
20
- const kio = /^MemAvailable:\s+(\d+) kB/m.exec(readFileSync('/proc/meminfo', 'utf8'))?.[1];
21
- if (kio) {
22
- return Number(kio) * 1024;
23
- }
36
+ return lireLaMemoire(readFileSync('/proc/meminfo', 'utf8'));
24
37
  } catch {
25
- // no /proc/meminfo: the free memory of node
38
+ return { disponible: null, echange: 0 };
26
39
  }
27
- return freemem();
40
+ }
41
+
42
+ /**
43
+ * The memory available now, in bytes (MemAvailable of the kernel, else the free memory of node).
44
+ * @returns {number}
45
+ */
46
+ export function memoireDisponible() {
47
+ return memoireRestante().disponible ?? freemem();
28
48
  }
29
49
 
30
50
  /**
package/scripts/nuit.sh CHANGED
@@ -291,7 +291,7 @@ process.exit(paquets(process.argv[2]).some(p => p.pkg.name === "@roomi-fields/gr
291
291
  GRILLHOUSE_ROUGES="$rouges" GRILLHOUSE_RESULTATS="$resultats" GRILLHOUSE_VERIFICATION_SORTE=Nuit monter npm --prefix "$copie" run verifier -- --force
292
292
  code=$?
293
293
  if [ "$code" -eq 75 ]; then
294
- echo "⏱ la passe complète est à repasser (code 75) : l'attente de la machine a atteint sa borne."
294
+ echo "⏱ la passe complète est à repasser (code 75) : l'attente de la machine a atteint sa borne, ou la veille de la mémoire a coupé la passe."
295
295
  return 75
296
296
  fi
297
297
  if [ "$code" -ne 0 ]; then
@@ -21,7 +21,8 @@ export function passeLourde({ args }) {
21
21
 
22
22
  /**
23
23
  * What a pass or a session out of the envelope launches: a heavy pass runs its command as it is,
24
- * every core kept (no GRILLHOUSE_TRAVAILLEURS, even inherited); any other runs under `nice` and
24
+ * without the workers it inherits (GRILLHOUSE_TRAVAILLEURS): it shares the cores between its own
25
+ * tasks of tests (scripts/langages/typescript/verifier.mjs); any other runs under `nice` and
25
26
  * `ionice`, GRILLHOUSE_TRAVAILLEURS set to max(1, cores ÷ places).
26
27
  * @param {{ lourde: boolean, cmd: string, args: string[], env: Record<string, string | undefined> }} o
27
28
  * @returns {{ cmd: string, args: string[], env: Record<string, string | undefined> }}
@@ -78,9 +78,9 @@ export function travailleursDe({
78
78
  }
79
79
 
80
80
  /**
81
- * The workers a session of an agent plays its tests on, as its environment gives them
82
- * (GRILLHOUSE_TRAVAILLEURS, set by the envelope): what the module of each language passes to its
83
- * tool. Null without the variable (a heavy pass): the tool keeps every core.
81
+ * The workers a task plays its tests on, as its environment gives them (GRILLHOUSE_TRAVAILLEURS,
82
+ * set by the envelope for a session, by the pass for a heavy pass): what the module of each
83
+ * language passes to its tool. Null without the variable: the tool keeps its own default.
84
84
  * @param {Record<string, string | undefined>} [env]
85
85
  * @returns {number | null}
86
86
  * @throws {Error} naming GRILLHOUSE_TRAVAILLEURS when its value is not a positive integer
@@ -7,6 +7,8 @@
7
7
  // repository).
8
8
  // - The core imports ./langages.mjs, never this entry: the command (bin/grillhouse.mjs) loads it
9
9
  // at each call, and a script of the core it loads before running one would not run again.
10
+ import { fileURLToPath } from 'node:url';
11
+
10
12
  export * from './langages.mjs';
11
13
 
12
14
  // The services of the core to a module of language: the plan of an envelope, the progress of a
@@ -57,12 +59,17 @@ export {
57
59
  ouvrirBase,
58
60
  retirerALInterruption,
59
61
  } from './mesure/base-de-passe.mjs';
60
- export { A_REPASSER } from './codes-de-sortie.mjs';
62
+ export { A_REPASSER, MEMOIRE_COUPEE } from './codes-de-sortie.mjs';
63
+ /** The watch of the memory of a pass (./garde-de-la-memoire.mjs), the script a pass runs under. */
64
+ export const GARDE_DE_LA_MEMOIRE = fileURLToPath(
65
+ new URL('./garde-de-la-memoire.mjs', import.meta.url)
66
+ );
61
67
  export { ecrirePression, lirePression, SEUIL_PRESSION } from './mesure/pression.mjs';
62
68
  export {
63
69
  avecLaMachineEtUnePlace,
64
70
  surUnePlace,
65
71
  travailleursDeLaSeance,
72
+ VARIABLE_TRAVAILLEURS,
66
73
  } from './places-de-la-machine.mjs';
67
74
  export { attendreDeLaPlace, AttenteDeLaMachine, nommerLAvancement } from './verrou-de-machine.mjs';
68
75
  export { CONFIG_BEADS, ecrireLePrefixe, prefixe } from './prefixe-des-tickets.mjs';
@@ -674,6 +674,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
674
674
  silence: dernier ? maintenant - dernier.mtime : null,
675
675
  entre: lu?.entre ?? null,
676
676
  jetons: lu?.jetons ?? 0,
677
+ minutes: lu?.minutes,
677
678
  travail: lu?.travail ?? 0,
678
679
  tours: lu?.tours ?? [],
679
680
  });
@@ -690,6 +691,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
690
691
  depuis: lu.premier ?? maintenant,
691
692
  entre: lu.entre,
692
693
  jetons: lu.jetons,
694
+ minutes: lu.minutes,
693
695
  travail: lu.travail,
694
696
  tours: lu.tours,
695
697
  });
@@ -714,6 +716,7 @@ export function lireVivant({ racine, home, prefix, maintenant, ps, cache = {} })
714
716
  depuis: lu.premier ?? maintenant,
715
717
  entre: lu.entre,
716
718
  jetons: lu.jetons,
719
+ minutes: lu.minutes,
717
720
  travail: lu.travail,
718
721
  tours: lu.tours,
719
722
  });
@@ -1068,13 +1071,24 @@ export function assembler({
1068
1071
  travail: l.reduce((s, x) => s + (x.travail ?? 0), 0),
1069
1072
  jetons: l.reduce((s, x) => s + (x.jetons ?? 0), 0),
1070
1073
  });
1071
- // A measure with its turns counts in the day the parts since midnight of their union; a register
1072
- // line written without them counts whole in the day it ended.
1074
+ // A measure with its turns counts in the day the parts since the day's marker of their union,
1075
+ // and, with its tokens by minute, those spent since it: a session opened days ago counts in the
1076
+ // day what it did today, time and tokens alike. A register line written without them counts
1077
+ // whole in the day it ended.
1073
1078
  const partDuJour = tours =>
1074
1079
  reunir(tours).reduce((s, [debut, fin]) => s + Math.max(0, fin - Math.max(debut, jour)), 0);
1080
+ const jetonsDuJour = minutes =>
1081
+ Object.entries(minutes).reduce(
1082
+ (s, [minute, n]) => s + (Number(minute) >= Math.floor(jour / MINUTE) ? n : 0),
1083
+ 0
1084
+ );
1075
1085
  const duJour = mesures
1076
1086
  .filter(m => m.quand >= jour)
1077
- .map(m => (m.tours ? { ...m, travail: partDuJour(m.tours) } : m));
1087
+ .map(m => ({
1088
+ ...m,
1089
+ ...(m.tours ? { travail: partDuJour(m.tours) } : {}),
1090
+ ...(m.minutes ? { jetons: jetonsDuJour(m.minutes) } : {}),
1091
+ }));
1078
1092
  // The discoveries (label `decouverte`, grillhouse-3uv.96): each counts in one case, the first that
1079
1093
  // applies. « rejetés » and « validés » count only since the day's marker <jour>; « new » and
1080
1094
  // « →check », states that await the owner, do not filter by it.
@@ -1107,7 +1121,16 @@ export function assembler({
1107
1121
  decouvertes[c]++;
1108
1122
  }
1109
1123
  }
1110
- const global = { compteurs, jour: somme(duJour), cumul: somme(mesures), decouvertes };
1124
+ // The time of the day and of the cumul is the work of the agents and of the circuits: the
1125
+ // supervisor's own session, a measure with neither ticket nor role, open for weeks and counting
1126
+ // its waits, gives its tokens to both, never its time.
1127
+ const sansLeTempsDuSuperviseur = l => l.map(m => (m.ticket || m.role ? m : { ...m, travail: 0 }));
1128
+ const global = {
1129
+ compteurs,
1130
+ jour: somme(sansLeTempsDuSuperviseur(duJour)),
1131
+ cumul: somme(sansLeTempsDuSuperviseur(mesures)),
1132
+ decouvertes,
1133
+ };
1111
1134
 
1112
1135
  // Chantiers.
1113
1136
  const sous = t => [t, ...(enfants.get(t.id) ?? []).flatMap(sous)];
@@ -1462,15 +1485,19 @@ export function assembler({
1462
1485
  };
1463
1486
  }
1464
1487
 
1488
+ // A count of tokens as a line says it: « 512 », « 40 k », « 3,1 M », « 1,2 G »; a count that would
1489
+ // round to a thousand of its unit takes the next one.
1465
1490
  export const k = n =>
1466
- n >= 1e6
1467
- ? `${(n / 1e6).toFixed(1).replace('.', ',')} M`
1468
- : n >= 1e3
1469
- ? `${Math.round(n / 1e3)} k`
1470
- : `${n}`;
1491
+ n >= 999.95e6
1492
+ ? `${(n / 1e9).toFixed(1).replace('.', ',')} G`
1493
+ : n >= 999.5e3
1494
+ ? `${(n / 1e6).toFixed(1).replace('.', ',')} M`
1495
+ : n >= 1e3
1496
+ ? `${Math.round(n / 1e3)} k`
1497
+ : `${n}`;
1471
1498
  export const duree = ms => {
1472
1499
  const min = Math.round(ms / MINUTE);
1473
- return min < 60 ? `${min} min` : `${Math.floor(min / 60)} h ${String(min % 60).padStart(2, '0')}`;
1500
+ return min < 60 ? `${min} min` : `${Math.floor(min / 60)}h${String(min % 60).padStart(2, '0')}`;
1474
1501
  };
1475
1502
 
1476
1503
  // The local day and month of the instant <t>, « 16/10 ».
@@ -2485,8 +2512,25 @@ export function ligneEtat(t, voisins = []) {
2485
2512
  return `${alerte}${ch.numero} ${ch.faits}/${ch.total} · ${dAgents} · ${k(t.global.jour.jetons)} aujourd'hui`;
2486
2513
  }
2487
2514
 
2488
- // The answer of Beads to <args> in the repository at <racine>, as JSON (`liste`), or the first line
2489
- // of its fault (`faute`), its error output first.
2515
+ /**
2516
+ * The fault of a call of Beads that threw <e>, as an alert says it: the command `bd` missing from
2517
+ * the PATH with its gesture, as the session start names it; else the first line of its error
2518
+ * output, else of its message.
2519
+ * @param {unknown} e
2520
+ * @returns {string}
2521
+ */
2522
+ export function fauteDeBeads(e) {
2523
+ if (/** @type {{ code?: string }} */ (e)?.code === 'ENOENT') {
2524
+ return 'la commande bd est absente du PATH de cette séance : `npm install -g @beads/bd`';
2525
+ }
2526
+ const message =
2527
+ String(/** @type {{ stderr?: unknown }} */ (e)?.stderr ?? '').trim() ||
2528
+ String(/** @type {{ message?: unknown }} */ (e)?.message ?? e);
2529
+ return message.split('\n')[0];
2530
+ }
2531
+
2532
+ // The answer of Beads to <args> in the repository at <racine>, as JSON (`liste`), or its fault
2533
+ // (`faute`, `fauteDeBeads`).
2490
2534
  const bdJson = (racine, ...args) => {
2491
2535
  try {
2492
2536
  return {
@@ -2501,8 +2545,7 @@ const bdJson = (racine, ...args) => {
2501
2545
  faute: null,
2502
2546
  };
2503
2547
  } catch (e) {
2504
- const message = String(e?.stderr ?? '').trim() || String(e?.message ?? e);
2505
- return { liste: [], faute: message.split('\n')[0] };
2548
+ return { liste: [], faute: fauteDeBeads(e) };
2506
2549
  }
2507
2550
  };
2508
2551