@roomi-fields/grillhouse 0.33.1 → 0.34.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.
Files changed (129) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +81 -0
  3. package/cadre/templates/projet/CLAUDE.md +9 -3
  4. package/charte.md +23 -6
  5. package/dist/temporal/acte.d.ts +7 -0
  6. package/dist/temporal/acte.js +19 -2
  7. package/dist/temporal/acte.js.map +1 -1
  8. package/dist/temporal/circuit/activites.d.ts +3 -1
  9. package/dist/temporal/circuit/activites.js +25 -1
  10. package/dist/temporal/circuit/activites.js.map +1 -1
  11. package/dist/temporal/circuit/appel.d.ts +19 -0
  12. package/dist/temporal/circuit/appel.js +93 -0
  13. package/dist/temporal/circuit/appel.js.map +1 -0
  14. package/dist/temporal/circuit/client.d.ts +7 -0
  15. package/dist/temporal/circuit/client.js +20 -0
  16. package/dist/temporal/circuit/client.js.map +1 -1
  17. package/dist/temporal/circuit/commande.js +27 -87
  18. package/dist/temporal/circuit/commande.js.map +1 -1
  19. package/dist/temporal/circuit/contrat.d.ts +19 -0
  20. package/dist/temporal/circuit/contrat.js +2 -0
  21. package/dist/temporal/circuit/contrat.js.map +1 -1
  22. package/dist/temporal/circuit/deroule.js +86 -11
  23. package/dist/temporal/circuit/deroule.js.map +1 -1
  24. package/dist/temporal/file/activites.d.ts +3 -0
  25. package/dist/temporal/file/activites.js +9 -0
  26. package/dist/temporal/file/activites.js.map +1 -1
  27. package/dist/temporal/file/contrat.d.ts +58 -0
  28. package/dist/temporal/file/deroule.d.ts +8 -1
  29. package/dist/temporal/file/deroule.js +100 -2
  30. package/dist/temporal/file/deroule.js.map +1 -1
  31. package/dist/temporal/nuits/contrat.d.ts +2 -0
  32. package/dist/temporal/nuits/deroule.js +3 -0
  33. package/dist/temporal/nuits/deroule.js.map +1 -1
  34. package/dist/temporal/places/activites.d.ts +8 -0
  35. package/dist/temporal/places/activites.js +12 -1
  36. package/dist/temporal/places/activites.js.map +1 -1
  37. package/dist/temporal/places/client.d.ts +8 -1
  38. package/dist/temporal/places/client.js +25 -2
  39. package/dist/temporal/places/client.js.map +1 -1
  40. package/dist/temporal/places/contrat.d.ts +35 -3
  41. package/dist/temporal/places/contrat.js +5 -4
  42. package/dist/temporal/places/contrat.js.map +1 -1
  43. package/dist/temporal/places/deroule.js +55 -9
  44. package/dist/temporal/places/deroule.js.map +1 -1
  45. package/dist/temporal/tickets/activites.d.ts +3 -0
  46. package/dist/temporal/tickets/activites.js +73 -4
  47. package/dist/temporal/tickets/activites.js.map +1 -1
  48. package/dist/temporal/tickets/contrat.d.ts +31 -0
  49. package/dist/temporal/tickets/deroule.js +61 -10
  50. package/dist/temporal/tickets/deroule.js.map +1 -1
  51. package/docs/ARCHITECTURE.md +225 -57
  52. package/docs/CADRE.md +6 -1
  53. package/docs/INTERFACE.md +24 -8
  54. package/hooks/crochet.mjs +17 -2
  55. package/hooks/hooks.json +24 -0
  56. package/package.json +1 -1
  57. package/scripts/activites.mjs +77 -14
  58. package/scripts/aiguillage.mjs +2 -0
  59. package/scripts/attente-a-l-arret.mjs +141 -0
  60. package/scripts/attente-au-tour.mjs +32 -16
  61. package/scripts/avancement.mjs +5 -3
  62. package/scripts/branche-de-nuit.mjs +63 -3
  63. package/scripts/ci-des-branches.mjs +4 -2
  64. package/scripts/circuit.mjs +57 -4
  65. package/scripts/circuits-du-serveur.mjs +34 -1
  66. package/scripts/commandes-composees.mjs +11 -4
  67. package/scripts/copies-finies.mjs +43 -29
  68. package/scripts/crochets.mjs +1 -1
  69. package/scripts/dette.mjs +55 -4
  70. package/scripts/disque-des-copies.d.mts +28 -0
  71. package/scripts/disque-des-copies.mjs +155 -0
  72. package/scripts/droits.mjs +2 -0
  73. package/scripts/etapes.mjs +6 -4
  74. package/scripts/faits-du-circuit.mjs +24 -0
  75. package/scripts/file-des-tickets.d.mts +16 -0
  76. package/scripts/file-des-tickets.mjs +65 -7
  77. package/scripts/gardes-du-cadre.mjs +4 -2
  78. package/scripts/integration/file.mjs +308 -10
  79. package/scripts/jointure.d.ts +41 -2
  80. package/scripts/langages/cargo/commandes.mjs +81 -12
  81. package/scripts/langages/cargo/composants.mjs +12 -4
  82. package/scripts/langages/cargo/executables-de-tests.mjs +118 -0
  83. package/scripts/langages/cargo/exemples.mjs +17 -3
  84. package/scripts/langages/cargo/index.mjs +8 -3
  85. package/scripts/langages/cargo/migrations/0.28.4-tailles-des-tests.mjs +2 -2
  86. package/scripts/langages/cargo/migrations/0.34.0-executables-de-tests.mjs +35 -0
  87. package/scripts/langages/cargo/squelette.mjs +8 -3
  88. package/scripts/langages/cargo/tailles-des-tests.mjs +68 -6
  89. package/scripts/langages/cargo/tests-de-head.mjs +12 -9
  90. package/scripts/langages/cargo/verdict.mjs +40 -14
  91. package/scripts/langages/python/commandes.mjs +14 -2
  92. package/scripts/langages/python/index.mjs +12 -4
  93. package/scripts/langages/python/verdict.mjs +8 -1
  94. package/scripts/langages/typescript/index.mjs +9 -2
  95. package/scripts/langages/typescript/resume-du-lanceur.mjs +92 -0
  96. package/scripts/langages/typescript/tests.mjs +1 -1
  97. package/scripts/langages/typescript/verdict.mjs +4 -60
  98. package/scripts/langages/typescript/verifier.mjs +1 -1
  99. package/scripts/langages/typescript/vitest-config/changements.mjs +12 -7
  100. package/scripts/langages/typescript/vitest-config/lances.mjs +45 -0
  101. package/scripts/langages/typescript/vitest-config/machine.setup.mjs +1 -0
  102. package/scripts/messages-non-lus.mjs +166 -0
  103. package/scripts/mesure-de-la-machine.mjs +7 -4
  104. package/scripts/migrations-des-gardes.mjs +179 -0
  105. package/scripts/places-de-la-machine.mjs +44 -40
  106. package/scripts/places-du-serveur.mjs +82 -14
  107. package/scripts/plafond-de-la-machine.d.mts +18 -0
  108. package/scripts/plafond-de-la-machine.mjs +45 -0
  109. package/scripts/recommencer.d.mts +4 -0
  110. package/scripts/recommencer.mjs +29 -0
  111. package/scripts/regles-des-places.d.mts +35 -0
  112. package/scripts/regles-des-places.mjs +82 -1
  113. package/scripts/resultats.mjs +38 -4
  114. package/scripts/retirer-les-copies-finies.mjs +11 -7
  115. package/scripts/seances.mjs +1 -1
  116. package/scripts/services-du-noyau.mjs +1 -0
  117. package/scripts/sous-commandes.mjs +2 -0
  118. package/scripts/superviseur.mjs +235 -56
  119. package/scripts/tableau.mjs +468 -267
  120. package/scripts/taches-du-graphe.mjs +49 -8
  121. package/scripts/ticket-du-circuit.mjs +25 -0
  122. package/scripts/transitions.d.mts +27 -1
  123. package/scripts/transitions.mjs +96 -4
  124. package/scripts/verrou-de-machine.mjs +41 -17
  125. package/skills/explorateur/SKILL.md +8 -2
  126. package/skills/pitmaster/SKILL.md +18 -15
  127. package/skills/pitmaster/references/tour.md +3 -1
  128. package/skills/questionneur/SKILL.md +5 -1
  129. package/skills/testwriter/SKILL.md +32 -6
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+ // The guard of the migrations of the guards: a guard with a debt arrives with the migration that
3
+ // inscribes the existing debt of the projects (`trancher(projet, GARDE, constats, 'inscrire')`),
4
+ // as the codemods of `nx migrate` or the baselines of ESLint and Betterer; a project that updates
5
+ // then has no gesture to make by hand.
6
+ //
7
+ // npx grillhouse migrations-des-gardes (a guard of `grillhouse:gardes`)
8
+ //
9
+ // - A guard with a debt is a script under scripts/ or scripts/langages/*/ that imports `trancher`
10
+ // of scripts/dette.mjs and calls it; its name is the second argument of the call, a literal or
11
+ // the constant `GARDE` of the script. The definition of `trancher` itself is no guard.
12
+ // - A migration covers a guard when its text, under scripts/migrations/ or
13
+ // scripts/langages/*/migrations/, imports the script of the guard by its resolved path and calls
14
+ // `trancher(` with the same name (a literal, or the `GARDE` it imports from the script), and
15
+ // when scripts/migrations.mjs or a scripts/langages/*/index.mjs imports that migration: it is
16
+ // played.
17
+ // - The guard reads the texts and loads no module. Its findings (rule `garde-sans-migration`) are
18
+ // counted against the debt (scripts/dette.mjs), so the guards without migration at its entry
19
+ // are inscribed, frozen, and the entry of a guard that receives its migration is pruned.
20
+ // - It plays at the frame only: scripts installed under node_modules, or outside the root, are the
21
+ // frame's, whose debt the frame holds; a project that updates sees none refused.
22
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
23
+ import path from 'node:path';
24
+ import { fileURLToPath, pathToFileURL } from 'node:url';
25
+ import { MODE, trancher } from './dette.mjs';
26
+
27
+ export const GARDE = 'migrations-des-gardes';
28
+ export const REGLE = 'garde-sans-migration';
29
+ export const SCRIPT = fileURLToPath(import.meta.url);
30
+
31
+ const DOSSIER = path.dirname(SCRIPT);
32
+ const MODELE = '0.30.0-tailles-des-outils-lourds.mjs';
33
+
34
+ const sousDossiers = dir =>
35
+ existsSync(dir)
36
+ ? readdirSync(dir, { withFileTypes: true })
37
+ .filter(e => e.isDirectory())
38
+ .map(e => path.join(dir, e.name))
39
+ : [];
40
+ const scriptsDe = dir =>
41
+ existsSync(dir)
42
+ ? readdirSync(dir, { withFileTypes: true })
43
+ .filter(e => e.isFile() && e.name.endsWith('.mjs'))
44
+ .map(e => path.join(dir, e.name))
45
+ : [];
46
+ // The text of <fichier> without its whole-line comments.
47
+ const texte = fichier =>
48
+ readFileSync(fichier, 'utf8')
49
+ .split('\n')
50
+ .filter(l => !/^\s*\/\//.test(l))
51
+ .join('\n');
52
+
53
+ // The imports of <t> (the text of the file <de>): each { noms, chemin } with the path resolved.
54
+ function imports(t, de) {
55
+ const out = [];
56
+ const re = /import\s+(?:([^'"]*?)\s+from\s+)?['"]([^'"]+)['"]/g;
57
+ for (const m of t.matchAll(re)) {
58
+ if (m[2].startsWith('.')) {
59
+ out.push({ noms: m[1] ?? '', chemin: path.resolve(path.dirname(de), m[2]) });
60
+ }
61
+ }
62
+ return out;
63
+ }
64
+ const importe = (t, de, cible) => imports(t, de).some(i => i.chemin === cible);
65
+
66
+ // The second argument of each call to `trancher(` in <t>: a literal name or the identifier GARDE.
67
+ function secondsArguments(t) {
68
+ const out = [];
69
+ const re = /\btrancher\(\s*[^,()]*(?:\([^()]*\))?[^,()]*,\s*(?:'([^']+)'|"([^"]+)"|(GARDE)\b)/g;
70
+ for (const m of t.matchAll(re)) {
71
+ out.push(m[3] ? { constante: true } : { nom: m[1] ?? m[2] });
72
+ }
73
+ return out;
74
+ }
75
+ const constanteGarde = t => /\bconst\s+GARDE\s*=\s*['"]([^'"]+)['"]/.exec(t)?.[1];
76
+
77
+ // The names of the guard <fichier> (text <t>), or [] when it is not a guard with a debt.
78
+ function nomsDeGarde(fichier, t) {
79
+ if (
80
+ !imports(t, fichier).some(i => /\btrancher\b/.test(i.noms) && /\/dette(\.mjs)?$/.test(i.chemin))
81
+ ) {
82
+ return [];
83
+ }
84
+ const noms = new Set();
85
+ for (const a of secondsArguments(t)) {
86
+ const n = a.constante ? constanteGarde(t) : a.nom;
87
+ if (n) {
88
+ noms.add(n);
89
+ }
90
+ }
91
+ return [...noms];
92
+ }
93
+
94
+ // True when the scripts at <scripts> belong to the repository at <racine>: under its root and not
95
+ // installed under node_modules. A project that installs the frame judges none of its scripts.
96
+ function chezLeCadre(racine, scripts) {
97
+ const rel = path.relative(racine, scripts);
98
+ return (
99
+ !rel.startsWith('..') && !path.isAbsolute(rel) && !rel.split(path.sep).includes('node_modules')
100
+ );
101
+ }
102
+
103
+ // The refusals of the repository at <racine>, its frame's scripts at <scripts>.
104
+ export function verifier(racine, scripts = DOSSIER) {
105
+ if (!chezLeCadre(racine, scripts)) {
106
+ return [];
107
+ }
108
+ const langages = sousDossiers(path.join(scripts, 'langages'));
109
+ const gardes = [...scriptsDe(scripts), ...langages.flatMap(scriptsDe)].filter(
110
+ f => path.basename(f) !== 'dette.mjs'
111
+ );
112
+ const dossiersDeMigrations = [
113
+ path.join(scripts, 'migrations'),
114
+ ...langages.map(l => path.join(l, 'migrations')),
115
+ ];
116
+ const indexs = [
117
+ path.join(scripts, 'migrations.mjs'),
118
+ ...langages.map(l => path.join(l, 'index.mjs')),
119
+ ].filter(existsSync);
120
+ const textesDesIndex = indexs.map(f => ({ f, t: texte(f) }));
121
+ // The migrations played: imported by the index of the core or of a language.
122
+ const jouees = dossiersDeMigrations
123
+ .flatMap(scriptsDe)
124
+ .filter(m => textesDesIndex.some(({ f, t }) => importe(t, f, m)))
125
+ .map(m => ({ m, t: texte(m) }));
126
+ const constats = [];
127
+ for (const g of gardes) {
128
+ const t = texte(g);
129
+ const noms = nomsDeGarde(g, t);
130
+ for (const nom of noms) {
131
+ const couverte = jouees.some(({ m, t: tm }) => {
132
+ const lien = imports(tm, m).find(
133
+ i => i.chemin === g || i.chemin === g.replace(/\.mjs$/, '')
134
+ );
135
+ if (!lien) {
136
+ return false;
137
+ }
138
+ return secondsArguments(tm).some(a =>
139
+ a.constante ? /\bGARDE\b/.test(lien.noms) && nom === constanteGarde(t) : a.nom === nom
140
+ );
141
+ });
142
+ if (!couverte) {
143
+ const fichier = path.relative(racine, g).split(path.sep).join('/');
144
+ constats.push({
145
+ fichier,
146
+ regle: REGLE,
147
+ message: `${fichier} : la garde « ${nom} » a une dette sans migration qui l'inscrive chez les projets ; écris sa migration sur le patron de ${MODELE}, qui inscrit la dette existante des projets par trancher(projet, GARDE, constats, 'inscrire'), et déclare-la dans l'index de son langage (scripts/migrations.mjs pour le cœur).`,
148
+ });
149
+ }
150
+ }
151
+ }
152
+ return constats;
153
+ }
154
+
155
+ // The report of the guard at <racine>: its lines and its exit code, the findings counted against
156
+ // the debt. A repository whose frame's scripts are not its own (a project, or a copy that runs the
157
+ // scripts of another tree) is not measured: its debt is neither judged nor pruned, since no
158
+ // finding there says what is corrected.
159
+ export function rapport(racine, env = process.env, scripts = DOSSIER) {
160
+ if (!chezLeCadre(racine, scripts)) {
161
+ return { lignes: [], code: 0 };
162
+ }
163
+ const { refus, lignes } = trancher(
164
+ racine,
165
+ GARDE,
166
+ verifier(racine, scripts),
167
+ env[MODE] || undefined,
168
+ env
169
+ );
170
+ return { lignes: [...refus.map(r => `⛔ ${r.message}`), ...lignes], code: refus.length ? 1 : 0 };
171
+ }
172
+
173
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
174
+ const { lignes, code } = rapport(process.cwd());
175
+ for (const l of lignes) {
176
+ process.stderr.write(`${l}\n`);
177
+ }
178
+ process.exitCode = code;
179
+ }
@@ -22,10 +22,10 @@
22
22
  // (./verrou-de-machine.mjs): the place of the session, taken out of it by the circuit, covers its
23
23
  // commands, and the envelope passes on its mark; a number of process there means nothing on
24
24
  // the machine.
25
- // - The ceiling is PLAFOND_PAR_DEFAUT, 3, unless GRILLHOUSE_PLACES names another (a positive
26
- // integer; any other value is refused by the name of the variable); two starts are spaced by
27
- // ESPACEMENT_MS (GRILLHOUSE_ESPACEMENT_MS names another, in ms). The workflow reads both when it
28
- // starts.
25
+ // - The ceiling is a configuration of the poste (`plafondDe` of ./plafond-de-la-machine.mjs:
26
+ // GRILLHOUSE_PLACES of `~/.config/grillhouse/machine.env`, 3 without it), which the workflow
27
+ // reads again at each judgement; two starts are spaced by ESPACEMENT_MS
28
+ // (GRILLHOUSE_ESPACEMENT_MS names another, in ms), which the workflow reads when it starts.
29
29
  // - A wait says its reason (place, rank, load, memory or spacing) when it begins and every 30 s,
30
30
  // and is bounded as the wait for the lock of the machine, GRILLHOUSE_ATTENTE_MACHINE_MS: at the
31
31
  // bound, « à repasser » (75), the request withdrawn.
@@ -41,45 +41,24 @@ import { A_REPASSER } from './codes-de-sortie.mjs';
41
41
  import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
42
42
  import { ecrireLaTrace, traceDesPlaces } from './journal-des-etats.mjs';
43
43
  import { mesureDeLaMachine } from './mesure-de-la-machine.mjs';
44
+ import { plafondDe } from './plafond-de-la-machine.mjs';
44
45
  import { AttenteDeLaMachine, avecLaMachine, borneDe } from './verrou-de-machine.mjs';
45
46
 
46
- export const VARIABLE_PLACES = 'GRILLHOUSE_PLACES';
47
47
  export const VARIABLE_ESPACEMENT = 'GRILLHOUSE_ESPACEMENT_MS';
48
48
  export const VARIABLE_TRAVAILLEURS = 'GRILLHOUSE_TRAVAILLEURS';
49
49
  /** The mark of a place held, which the children of its holder inherit. */
50
50
  export const VARIABLE_TENUE = 'GRILLHOUSE_PLACE_TENUE';
51
- /** The measure of the machine a trial fixes, in JSON `{ coeurs, charge, memoireLibre }`. */
51
+ /** The measure of the machine a trial fixes, in JSON `{ coeurs, charge, memoireLibre, memoireTotale }`. */
52
52
  export const VARIABLE_MESURE_D_ESSAI = 'GRILLHOUSE_MESURE_D_ESSAI';
53
53
  // The server of the places of a trial machine.
54
54
  const VARIABLE_ESSAI = 'GRILLHOUSE_PLACES_D_ESSAI';
55
55
 
56
- /** The ceiling of the places of the machine when GRILLHOUSE_PLACES names none. */
57
- export const PLAFOND_PAR_DEFAUT = 3;
58
56
  /** The gap between two starts when GRILLHOUSE_ESPACEMENT_MS names none, in ms. */
59
57
  export const ESPACEMENT_MS = 10_000;
60
58
  const RAPPEL_MS = 30_000;
61
59
  // The reading and the taking of the places on the server, in a process of their own.
62
60
  const PONT = path.join(import.meta.dirname, 'places-du-serveur.mjs');
63
61
 
64
- /**
65
- * The ceiling of the places under <env>.
66
- * @param {Record<string, string | undefined>} [env]
67
- * @returns {number}
68
- * @throws {Error} naming GRILLHOUSE_PLACES when its value is not a positive integer
69
- */
70
- export function plafondDe(env = process.env) {
71
- const v = env[VARIABLE_PLACES];
72
- if (v === undefined || v === '') {
73
- return PLAFOND_PAR_DEFAUT;
74
- }
75
- if (!/^[1-9]\d*$/.test(v)) {
76
- throw new Error(
77
- `${VARIABLE_PLACES} vaut « ${v} » : un entier positif est attendu (3 par défaut).`
78
- );
79
- }
80
- return Number(v);
81
- }
82
-
83
62
  /**
84
63
  * The gap between two starts under <env>, in ms.
85
64
  * @param {Record<string, string | undefined>} [env]
@@ -132,13 +111,14 @@ export function travailleursDeLaSeance(env = process.env) {
132
111
  }
133
112
 
134
113
  /**
135
- * The environment the places are read under on <env>: the address of their server
114
+ * The environment the server of the machine is read under on <env>: the address of its server
136
115
  * (TEMPORAL_ADDRESS), or null where no place is taken (the CI, the envelope of an agent, a trial
137
- * machine without its server).
116
+ * machine without its server); the places and the night under way (scripts/circuits-du-serveur.mjs
117
+ * `nuitDuServeur`) read there.
138
118
  * @param {Record<string, string | undefined>} env
139
119
  * @returns {Record<string, string | undefined> | null}
140
120
  */
141
- function surLeServeur(env) {
121
+ export function surLeServeur(env) {
142
122
  if (env.CI || paquetsDeLEnveloppe(env)) {
143
123
  return null;
144
124
  }
@@ -162,6 +142,14 @@ function auServeur(env, args, ms = 30_000) {
162
142
  .split('\n')
163
143
  .filter(Boolean)
164
144
  .map(l => JSON.parse(l));
145
+ // A server still busy after the bridge's attempts: the measure is to be played again (75), as
146
+ // the bound of a wait is; only `prendre` gives a 75 of its own, its wait said in its lines.
147
+ if (r.status === A_REPASSER && args[0] !== 'prendre') {
148
+ throw new AttenteDeLaMachine(
149
+ `⏳ ${(r.stderr || 'les places de la machine ne répondent pas à temps').trim()}`,
150
+ A_REPASSER
151
+ );
152
+ }
165
153
  if (r.status !== 0 && r.status !== A_REPASSER) {
166
154
  throw new AttenteDeLaMachine(
167
155
  `✗ ${(r.stderr || r.error?.message || `les places de la machine ne se lisent pas, code ${r.status}`).trim()}`,
@@ -354,7 +342,9 @@ export function avecLaMachineEtUnePlace(mesure, options = {}) {
354
342
 
355
343
  /**
356
344
  * The places taken and the waits of the machine under <env>, as the server holds them: `{ plafond,
357
- * prises, attentes }`, `prises` `{ id, pid, depart, ticket, rang, depuis }`, `attentes` in the
345
+ * faute, prises, attentes, circuits }` (`faute`, a value of the ceiling the poste names and the
346
+ * server refused, the ceiling read before kept; `circuits`, the places of the circuits, held or
347
+ * waited for, `{ racine, ticket, rang, accordee, depuis, vu }`), `prises` `{ id, pid, depart, ticket, rang, depuis }`, `attentes` in the
358
348
  * order of arrival `{ id, pid, ticket, rang, raison, depuis }`; none where no place is taken.
359
349
  * @param {{ env?: Record<string, string | undefined> }} [o]
360
350
  */
@@ -367,9 +357,9 @@ export function lirePlaces({ env = process.env } = {}) {
367
357
 
368
358
  /**
369
359
  * The machine a trial fixes under <env> (GRILLHOUSE_MESURE_D_ESSAI, JSON `{ coeurs, charge,
370
- * memoireLibre }`), or null without the variable.
360
+ * memoireLibre, memoireTotale }`), or null without the variable.
371
361
  * @param {Record<string, string | undefined>} env
372
- * @returns {{ coeurs: number, charge: number, memoireLibre: number } | null}
362
+ * @returns {{ coeurs: number, charge: number, memoireLibre: number, memoireTotale: number } | null}
373
363
  * @throws {Error} naming GRILLHOUSE_MESURE_D_ESSAI when its value is not that JSON
374
364
  */
375
365
  function mesureDEssai(env) {
@@ -386,35 +376,49 @@ function mesureDEssai(env) {
386
376
  if (
387
377
  !m ||
388
378
  typeof m !== 'object' ||
389
- ['coeurs', 'charge', 'memoireLibre'].some(
379
+ ['coeurs', 'charge', 'memoireLibre', 'memoireTotale'].some(
390
380
  c => typeof m[c] !== 'number' || !Number.isFinite(m[c])
391
381
  )
392
382
  ) {
393
383
  throw new Error(
394
- `${VARIABLE_MESURE_D_ESSAI} vaut « ${v} » : un JSON { coeurs, charge, memoireLibre } de nombres est attendu.`
384
+ `${VARIABLE_MESURE_D_ESSAI} vaut « ${v} » : un JSON { coeurs, charge, memoireLibre, memoireTotale } de nombres est attendu.`
395
385
  );
396
386
  }
397
- return { coeurs: m.coeurs, charge: m.charge, memoireLibre: m.memoireLibre };
387
+ return {
388
+ coeurs: m.coeurs,
389
+ charge: m.charge,
390
+ memoireLibre: m.memoireLibre,
391
+ memoireTotale: m.memoireTotale,
392
+ };
398
393
  }
399
394
 
400
395
  /**
401
396
  * The places as the board shows them: taken and ceiling, the load over one minute and the cores,
402
- * the free memory in whole GB, and the waits (ticket, since when) in the order of arrival. The
397
+ * the free memory and the total memory in whole GB, and the waits (ticket, since when) in the order of arrival: those
398
+ * of a place for a session or a pass, then the tickets that wait for a place of a circuit, not
399
+ * started (`circuits` of the server, which the queue of each project reserves). The
403
400
  * machine is the one GRILLHOUSE_MESURE_D_ESSAI fixes, else the real one (`mesurer`).
404
401
  * @param {{ env?: Record<string, string | undefined>, mesurer?: () => { coeurs: number,
405
- * charge: number, memoireLibre: number } }} [o]
402
+ * charge: number, memoireLibre: number, memoireTotale: number } }} [o]
406
403
  * @throws {Error} naming GRILLHOUSE_MESURE_D_ESSAI when its value is faulty
407
404
  */
408
405
  export function etatDesPlaces({ env = process.env, mesurer = mesureDeLaMachine } = {}) {
409
406
  const fixee = mesureDEssai(env);
410
- const { plafond, prises, attentes } = lirePlaces({ env });
407
+ const { plafond, faute = null, prises, attentes, circuits = [] } = lirePlaces({ env });
411
408
  const m = fixee ?? mesurer();
412
409
  return {
413
410
  prises: prises.length,
414
411
  plafond,
412
+ faute,
415
413
  charge: Math.round(m.charge * 10) / 10,
416
414
  coeurs: m.coeurs,
417
415
  memoireGo: Math.floor(m.memoireLibre / 1024 ** 3),
418
- attentes: attentes.map(a => ({ ticket: a.ticket, depuis: a.depuis })),
416
+ memoireTotaleGo: Math.floor(m.memoireTotale / 1024 ** 3),
417
+ attentes: [
418
+ ...attentes.map(a => ({ ticket: a.ticket, depuis: a.depuis })),
419
+ ...circuits
420
+ .filter(c => !c.accordee)
421
+ .map(c => ({ ticket: c.ticket, depuis: c.depuis, disque: c.raison ?? null })),
422
+ ],
419
423
  };
420
424
  }
@@ -10,36 +10,94 @@
10
10
  // node places-du-serveur.mjs lire
11
11
  //
12
12
  // - Each mode first starts the workflow of the machine when none runs (`demarrerLesPlaces`, on the
13
- // task queue of the worker of the machine), its ceiling GRILLHOUSE_PLACES and its spacing
14
- // GRILLHOUSE_ESPACEMENT_MS (scripts/places-de-la-machine.mjs).
13
+ // task queue of the worker of the machine), its spacing GRILLHOUSE_ESPACEMENT_MS
14
+ // (scripts/places-de-la-machine.mjs); it reads its ceiling from the poste itself.
15
15
  // - `rang` writes the next rank of arrival of the machine, which a circuit draws at its launch.
16
16
  // - `prendre` asks for a place for <demande> (JSON: `{ pid, depart, ticket, rang, borneMs,
17
17
  // rappelMs }`, the process that holds it), then waits for it: each line it says, at the start of
18
18
  // a wait and every <rappelMs>, is one JSON line `{ dire }` on the standard output, then the place
19
19
  // given, `{ id, rang }`. At the bound <borneMs>, the request is withdrawn, its line said, exit 75.
20
20
  // - `rendre` gives the place <id> back (or withdraws its request), `rattacher` names the process
21
- // that holds it; `lire` writes the places as the board reads them (`{ plafond, prises, attentes
22
- // }`).
23
- // - A server that does not answer within 5 s, or a client not built, is said on the error stream,
24
- // exit 1; a malformed call, exit 2.
21
+ // that holds it; `lire` writes the places as the board reads them (`{ plafond, faute, prises,
22
+ // attentes }`).
23
+ // - Each call waits DELAI_MS for the server, and is played again ESSAIS times when it fails
24
+ // transiently. Still failing, its port open: the server is busy, said on the error stream, exit
25
+ // 75. A port refused (no server), another failure, or a client not built: said on the error
26
+ // stream, exit 1. A malformed call, exit 2.
25
27
  import { randomUUID } from 'node:crypto';
26
28
  import { existsSync } from 'node:fs';
29
+ import net from 'node:net';
27
30
  import path from 'node:path';
28
31
  import { pathToFileURL } from 'node:url';
29
32
  import { A_REPASSER } from './codes-de-sortie.mjs';
30
33
  import { duree } from './regles-des-places.mjs';
31
34
 
32
35
  const DIST = path.join(import.meta.dirname, '..', 'dist', 'temporal');
33
- // How long a call waits for the server to answer.
34
- const DELAI_MS = 5_000;
36
+ // How long a call waits for the server to answer, each attempt.
37
+ const DELAI_MS = 8_000;
38
+ // The attempts of a call the server fails transiently, and the pause before the next.
39
+ const ESSAIS = 3;
40
+ const RECUL_MS = 1_000;
41
+
42
+ // Whether <x> is a transient failure of the server, which a new attempt may pass: a deadline
43
+ // exceeded, or a call cancelled at its deadline (the connection slow to open under load), or the
44
+ // server unavailable, as Temporal's clients retry them (gRPC codes 1, 4 and 14).
45
+ export const transitoire = x =>
46
+ [1, 4, 14].includes(x?.code ?? x?.cause?.code) ||
47
+ /CANCELLED|DEADLINE_EXCEEDED|UNAVAILABLE/.test(`${x?.message ?? ''} ${x?.cause?.message ?? ''}`);
48
+
49
+ /**
50
+ * Plays <appel> (an async function), again after a pause growing by <reculMs>, while it fails
51
+ * transiently, at most <essais> times; any other failure, or the last, throws.
52
+ * @template T
53
+ * @param {() => Promise<T>} appel
54
+ * @param {{ essais?: number, reculMs?: number, attendre?: (ms: number) => Promise<void> }} [o]
55
+ * @returns {Promise<T>}
56
+ */
57
+ export async function avecReprises(
58
+ appel,
59
+ { essais = ESSAIS, reculMs = RECUL_MS, attendre = ms => new Promise(r => setTimeout(r, ms)) } = {}
60
+ ) {
61
+ for (let n = 1; ; n++) {
62
+ try {
63
+ return await appel();
64
+ } catch (x) {
65
+ if (n >= essais || !transitoire(x)) {
66
+ throw x;
67
+ }
68
+ await attendre(reculMs * n);
69
+ }
70
+ }
71
+ }
72
+ /**
73
+ * Whether something listens on <adresse> (`hote:port`): false when the connection is refused (no
74
+ * server), true when it opens or does not answer within <delaiMs> (a server busy).
75
+ * @param {string} adresse
76
+ * @param {number} [delaiMs]
77
+ * @returns {Promise<boolean>}
78
+ */
79
+ export function ecoute(adresse, delaiMs = 2_000) {
80
+ const deux = adresse.lastIndexOf(':');
81
+ return new Promise(ok => {
82
+ const s = net.connect({ host: adresse.slice(0, deux), port: Number(adresse.slice(deux + 1)) });
83
+ const fin = r => {
84
+ s.destroy();
85
+ ok(r);
86
+ };
87
+ s.once('connect', () => fin(true));
88
+ s.once('error', () => fin(false));
89
+ s.setTimeout(delaiMs, () => fin(true));
90
+ });
91
+ }
92
+
35
93
  // How often a wait reads its request again.
36
- const VEILLE_MS = 250;
94
+ const VEILLE_MS = 1_000;
37
95
 
38
- // The ceiling and the spacing of the machine under <env>, as scripts/places-de-la-machine.mjs reads
39
- // them; the workflow's veille, a second.
96
+ // The spacing of the machine under <env>, as scripts/places-de-la-machine.mjs reads it; the
97
+ // workflow's veille, a second. The ceiling, the workflow reads from the poste at each judgement.
40
98
  const entreeDe = async env => {
41
- const { plafondDe, espacementDe } = await import('./places-de-la-machine.mjs');
42
- return { plafond: plafondDe(env), espacementMs: espacementDe(env), veilleMs: 1_000 };
99
+ const { espacementDe } = await import('./places-de-la-machine.mjs');
100
+ return { espacementMs: espacementDe(env), veilleMs: 1_000 };
43
101
  };
44
102
 
45
103
  const MODES = { rang: 0, prendre: 1, rendre: 1, rattacher: 3, lire: 0 };
@@ -101,7 +159,8 @@ async function principal(mode, args) {
101
159
  const { ID_DES_PLACES, LA_DEMANDE, PRENDRE } = await depuisDist('places', 'contrat.js');
102
160
  const places = await depuisDist('places', 'client.js');
103
161
  const c = ouvrirLeClient();
104
- const sous = f => c.client.connection.withDeadline(Date.now() + DELAI_MS, f);
162
+ // Each attempt gets its own deadline, counted from its start.
163
+ const sous = f => avecReprises(() => c.client.connection.withDeadline(Date.now() + DELAI_MS, f));
105
164
  try {
106
165
  try {
107
166
  await sous(async () =>
@@ -147,6 +206,15 @@ async function principal(mode, args) {
147
206
  }
148
207
  return 0;
149
208
  } catch (x) {
209
+ if (transitoire(x) && (await ecoute(c.adresse))) {
210
+ // Still failing transiently after its attempts, its port open: the server is busy, not
211
+ // absent; the measure is to be played again (75), never a red. A port refused is a server
212
+ // absent, required on the poste, below.
213
+ process.stderr.write(
214
+ `les places de la machine ne répondent pas à temps sur le serveur Temporal (${c.adresse}), ${ESSAIS} essais : ${x?.message ?? x} ; à repasser.\n`
215
+ );
216
+ return A_REPASSER;
217
+ }
150
218
  process.stderr.write(
151
219
  `les places de la machine ne se lisent pas sur le serveur Temporal (${c.adresse}) : ${x?.message ?? x}${x?.cause?.message ? ` (${x.cause.message})` : ''} ; le serveur est requis sur le poste (\`npx grillhouse temporal installer\`).\n`
152
220
  );
@@ -0,0 +1,18 @@
1
+ // The types of the ceiling of the places of the machine (./plafond-de-la-machine.mjs), which the
2
+ // activities of the workflow of the machine (src/temporal/places/activites.ts) import.
3
+
4
+ export const VARIABLE_PLACES: 'GRILLHOUSE_PLACES';
5
+ /** The file of the poste that holds the ceiling, under `~/.config/grillhouse/`. */
6
+ export const FICHIER_DE_LA_MACHINE: 'machine.env';
7
+ /** The ceiling of the places of the machine when nothing names another. */
8
+ export const PLAFOND_PAR_DEFAUT: 3;
9
+
10
+ /**
11
+ * The ceiling of the places under <env>: GRILLHOUSE_PLACES of the environment, else of the file of
12
+ * the poste `machine.env`, else 3; throws naming GRILLHOUSE_PLACES on a value that is not a
13
+ * positive integer.
14
+ */
15
+ export function plafondDe(
16
+ env?: Record<string, string | undefined>,
17
+ o?: { lire?: (f: string) => string | null }
18
+ ): number;
@@ -0,0 +1,45 @@
1
+ // The ceiling of the places of the machine (scripts/places-de-la-machine.mjs), a configuration of
2
+ // the poste read again at each judgement, as Buildkite reads the number of its agents from its
3
+ // configuration and Nomad its `client.reserved`: the workflow of the machine reads it by an
4
+ // activity (src/temporal/places/activites.ts), the board and the number of workers of the tests
5
+ // by this same function, so that a ceiling changed counts without restarting anything.
6
+ //
7
+ // - The file of the poste `machine.env`, under the frame's directory of configuration
8
+ // (`~/.config/grillhouse/`, scripts/fichier-du-poste.mjs), holds `GRILLHOUSE_PLACES=<n>`, as
9
+ // `turbo-cache.env` holds the server of the cache.
10
+ // - The environment wins, as for every file of the poste: GRILLHOUSE_PLACES set (a trial machine,
11
+ // a test) is read instead of the file. Without either, PLAFOND_PAR_DEFAUT, 3.
12
+ // - A value that is not a positive integer is refused by its name and its place.
13
+ import path from 'node:path';
14
+ import { avecLeFichierDuPoste, configurationDuPoste } from './fichier-du-poste.mjs';
15
+
16
+ export const VARIABLE_PLACES = 'GRILLHOUSE_PLACES';
17
+ /** The file of the poste that holds the ceiling, under `~/.config/grillhouse/`. */
18
+ export const FICHIER_DE_LA_MACHINE = 'machine.env';
19
+ /** The ceiling of the places of the machine when nothing names another. */
20
+ export const PLAFOND_PAR_DEFAUT = 3;
21
+
22
+ /**
23
+ * The ceiling of the places under <env>: GRILLHOUSE_PLACES of the environment, else of the file
24
+ * of the poste `machine.env`, else 3.
25
+ * @param {Record<string, string | undefined>} [env]
26
+ * @param {{ lire?: (f: string) => string | null }} [o] the reading of the file, for a trial
27
+ * @returns {number}
28
+ * @throws {Error} naming GRILLHOUSE_PLACES and where it is set when its value is not a positive integer
29
+ */
30
+ export function plafondDe(env = process.env, o = {}) {
31
+ const dedans = env[VARIABLE_PLACES] !== undefined;
32
+ const v = avecLeFichierDuPoste(env, { fichier: FICHIER_DE_LA_MACHINE, ...o })[VARIABLE_PLACES];
33
+ if (v === undefined || v === '') {
34
+ return PLAFOND_PAR_DEFAUT;
35
+ }
36
+ if (!/^[1-9]\d*$/.test(v)) {
37
+ const ou = dedans
38
+ ? 'dans l’environnement'
39
+ : `dans ${path.join(configurationDuPoste(env) ?? '~/.config/grillhouse', FICHIER_DE_LA_MACHINE)}`;
40
+ throw new Error(
41
+ `${VARIABLE_PLACES} vaut « ${v} » ${ou} : un entier positif est attendu (${PLAFOND_PAR_DEFAUT} par défaut).`
42
+ );
43
+ }
44
+ return Number(v);
45
+ }
@@ -0,0 +1,4 @@
1
+ // The types of ./recommencer.mjs, for the frame's TypeScript (src/temporal/circuit/client.ts).
2
+
3
+ /** Removes the copy of <ticket> in <racine>, its branch, sheets, journal and working directory; returns the copy removed. */
4
+ export function retirerLaCopieDuTicket(racine: string, ticket: string): string;
@@ -0,0 +1,29 @@
1
+ // `grillhouse circuit <ticket> --recommencer`: the removal of what a ticket's circuit left, so that
2
+ // a fresh launch starts from the testwriter in a fresh copy. The copy (whatever work it carries, the
3
+ // gesture being asked for, as a reset of Temporal), its branch, its sheets, its journal and its
4
+ // working directory go; the ticket, its description, its plan and its comments are Beads' and stay.
5
+ import { spawnSync } from 'node:child_process';
6
+ import { existsSync, rmSync } from 'node:fs';
7
+ import path from 'node:path';
8
+
9
+ /**
10
+ * Removes the copy of <ticket> in the repository <racine> with its branch `agent/<ticket>`, its
11
+ * sheets (`<copie>.fiches.jsonl`), its journal (`<copie>.log`) and its working directory
12
+ * (`<copie>.travail`), and nothing else: the copy of another ticket stays. Returns the copy removed.
13
+ */
14
+ export function retirerLaCopieDuTicket(racine, ticket) {
15
+ const copie = path.join(racine, '.claude', 'worktrees', ticket);
16
+ const git = (...a) => spawnSync('git', ['-C', racine, ...a], { encoding: 'utf8' });
17
+ if (existsSync(copie)) {
18
+ const r = git('worktree', 'remove', '--force', '--force', copie);
19
+ if (r.status !== 0) {
20
+ rmSync(copie, { recursive: true, force: true });
21
+ }
22
+ }
23
+ git('worktree', 'prune');
24
+ git('branch', '-D', `agent/${ticket}`);
25
+ for (const suite of ['.fiches.jsonl', '.log', '.travail']) {
26
+ rmSync(`${copie}${suite}`, { recursive: true, force: true });
27
+ }
28
+ return copie;
29
+ }
@@ -34,3 +34,38 @@ export function refusDeLaPlace(
34
34
  mesurer: () => MesureDeLaMachine;
35
35
  }
36
36
  ): string | null;
37
+
38
+ /** A place of a circuit not given by its project's queue for this long is gone, in ms: 10 min. */
39
+ export const PERIME_MS: number;
40
+
41
+ /** The place of a circuit of the machine: held (`accordee`) or waited for, its rank of arrival. */
42
+ export interface PlaceDeCircuit {
43
+ racine: string;
44
+ ticket: string;
45
+ rang: number;
46
+ accordee: boolean;
47
+ depuis: number;
48
+ vu: number;
49
+ /** A circuit resumed after its question, which asks again by itself. */
50
+ reprise?: boolean;
51
+ /** Why it waits apart from the order of arrival (its disk of copies), null without. */
52
+ raison?: string | null;
53
+ }
54
+
55
+ /**
56
+ * The places of the circuits once a demand comes: the queue of a project gives its circuits active,
57
+ * the tickets it would start and the reason its disk lacks room; or a circuit resumed asks again by
58
+ * itself (`reprise`). Granted in the order of arrival of every project under the ceiling, a
59
+ * candidate short of disk aside; the tickets of the demand that hold a place.
60
+ */
61
+ export function reserverDesCircuits(
62
+ places: readonly PlaceDeCircuit[],
63
+ demande: {
64
+ racine: string;
65
+ vivants?: string[];
66
+ candidats?: string[];
67
+ disque?: string | null;
68
+ reprise?: { ticket: string; rang: number | null };
69
+ },
70
+ o: { rang: number; plafond: number; maintenant: number }
71
+ ): { circuits: PlaceDeCircuit[]; rang: number; accordes: string[] };