@roomi-fields/grillhouse 0.50.3 → 0.52.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 (150) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +68 -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/plan.md +47 -0
  13. package/charte/preuve.md +39 -0
  14. package/charte/superviseur.md +61 -0
  15. package/charte/tests.md +38 -0
  16. package/charte.md +39 -189
  17. package/dist/machine/part-par-sorte.d.ts +16 -0
  18. package/dist/machine/part-par-sorte.js +36 -0
  19. package/dist/machine/part-par-sorte.js.map +1 -0
  20. package/dist/temporal/circuit/appel.js +1 -1
  21. package/dist/temporal/circuit/appel.js.map +1 -1
  22. package/dist/temporal/circuit/client.d.ts +4 -4
  23. package/dist/temporal/circuit/client.js +38 -16
  24. package/dist/temporal/circuit/client.js.map +1 -1
  25. package/dist/temporal/circuit/contrat.d.ts +11 -7
  26. package/dist/temporal/circuit/contrat.js +5 -9
  27. package/dist/temporal/circuit/contrat.js.map +1 -1
  28. package/dist/temporal/circuit/deroule.js +18 -6
  29. package/dist/temporal/circuit/deroule.js.map +1 -1
  30. package/dist/temporal/commande.js +12 -3
  31. package/dist/temporal/commande.js.map +1 -1
  32. package/dist/temporal/installation.d.ts +54 -3
  33. package/dist/temporal/installation.js +187 -17
  34. package/dist/temporal/installation.js.map +1 -1
  35. package/dist/temporal/places/client.d.ts +5 -1
  36. package/dist/temporal/places/client.js +23 -11
  37. package/dist/temporal/places/client.js.map +1 -1
  38. package/docs/ARCHITECTURE.md +23 -2700
  39. package/docs/INTERFACE.md +26 -10
  40. package/docs/architecture/circuit.md +61 -14
  41. package/docs/architecture/entree.md +21 -8
  42. package/docs/architecture/greffon.md +49 -20
  43. package/docs/architecture/installation.md +46 -17
  44. package/docs/architecture/machine.md +79 -39
  45. package/docs/architecture/tests.md +59 -16
  46. package/docs/lexique.md +163 -0
  47. package/hooks/hooks.json +0 -10
  48. package/hooks/register.tsx +92 -4
  49. package/package.json +2 -1
  50. package/scripts/activites.mjs +105 -65
  51. package/scripts/aiguillage.mjs +15 -8
  52. package/scripts/attente-au-tour.mjs +2 -3
  53. package/scripts/attente-de-la-machine.mjs +4 -8
  54. package/scripts/avancement.mjs +12 -8
  55. package/scripts/bilan.mjs +126 -63
  56. package/scripts/bilans-gardes.mjs +37 -0
  57. package/scripts/branche-de-nuit.mjs +2 -2
  58. package/scripts/ci-de-main.mjs +18 -21
  59. package/scripts/circuit.mjs +89 -44
  60. package/scripts/circuits-du-serveur.mjs +5 -5
  61. package/scripts/composants-affectes.mjs +30 -12
  62. package/scripts/composition-des-langages.mjs +5 -3
  63. package/scripts/conformite.mjs +1 -1
  64. package/scripts/consommation-des-passes.mjs +8 -6
  65. package/scripts/copies-finies.mjs +3 -14
  66. package/scripts/depart-du-ticket.d.mts +8 -2
  67. package/scripts/depart-du-ticket.mjs +26 -8
  68. package/scripts/direct.mjs +158 -72
  69. package/scripts/droits.mjs +165 -208
  70. package/scripts/engendres.mjs +3 -14
  71. package/scripts/entree-de-seance.mjs +35 -0
  72. package/scripts/enveloppe/enveloppe.mjs +98 -46
  73. package/scripts/enveloppe/lancer.sh +90 -66
  74. package/scripts/enveloppe/paquets-du-plan.mjs +38 -11
  75. package/scripts/enveloppe/travail-de-la-copie.mjs +192 -3
  76. package/scripts/etapes.mjs +84 -22
  77. package/scripts/faits-du-circuit.mjs +8 -2
  78. package/scripts/grillhouse-maj.mjs +43 -18
  79. package/scripts/groupe-cles.d.mts +15 -0
  80. package/scripts/groupe-cles.mjs +77 -2
  81. package/scripts/init.mjs +9 -2
  82. package/scripts/integration/rejeu.mjs +8 -1
  83. package/scripts/jointure.d.ts +24 -4
  84. package/scripts/langages/c/index.mjs +5 -2
  85. package/scripts/langages/cargo/commandes.mjs +35 -15
  86. package/scripts/langages/cargo/composants.mjs +45 -3
  87. package/scripts/langages/cargo/index.mjs +6 -3
  88. package/scripts/langages/python/commandes.mjs +50 -7
  89. package/scripts/langages/python/index.mjs +5 -2
  90. package/scripts/langages/python/squelette.mjs +2 -1
  91. package/scripts/langages/typescript/chemins-des-tests.mjs +1 -1
  92. package/scripts/langages/typescript/index.mjs +16 -14
  93. package/scripts/langages/typescript/mise-a-jour.mjs +1 -1
  94. package/scripts/langages/typescript/rapports-aux-lignes.mjs +74 -0
  95. package/scripts/langages/typescript/turbo-des-paquets.mjs +151 -38
  96. package/scripts/langages/typescript/verdict.mjs +29 -3
  97. package/scripts/langages/typescript/verifier.mjs +28 -3
  98. package/scripts/langages/typescript/vitest-config/changements.mjs +8 -6
  99. package/scripts/langages/typescript/vitest-config/lances.mjs +15 -32
  100. package/scripts/langages.mjs +54 -4
  101. package/scripts/matieres-lues.mjs +1 -1
  102. package/scripts/mesure/base-de-passe.mjs +32 -90
  103. package/scripts/migrations/serveurs-de-l-index.mjs +79 -0
  104. package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
  105. package/scripts/migrations.mjs +23 -7
  106. package/scripts/nuit.sh +3 -2
  107. package/scripts/paquet.mjs +1 -1
  108. package/scripts/paquets.d.ts +3 -0
  109. package/scripts/paquets.mjs +88 -1
  110. package/scripts/passe-de-la-machine.mjs +109 -36
  111. package/scripts/places-de-la-machine.mjs +81 -29
  112. package/scripts/plafond-de-la-machine.d.mts +2 -5
  113. package/scripts/plafond-de-la-machine.mjs +9 -9
  114. package/scripts/reprise.mjs +42 -13
  115. package/scripts/resultats.mjs +78 -56
  116. package/scripts/retirer-les-copies-finies.mjs +1 -1
  117. package/scripts/seances.mjs +471 -133
  118. package/scripts/services-du-noyau.mjs +9 -1
  119. package/scripts/session-start.sh +22 -7
  120. package/scripts/sortie-de-seance.mjs +70 -0
  121. package/scripts/sortie.mjs +37 -6
  122. package/scripts/sous-commandes.mjs +0 -3
  123. package/scripts/superviseur.mjs +400 -162
  124. package/scripts/tableau.mjs +188 -65
  125. package/scripts/transitions.d.mts +25 -2
  126. package/scripts/transitions.mjs +137 -29
  127. package/scripts/verrous/ecriture-hors-enveloppe.mjs +31 -9
  128. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  129. package/skills/developpeur/SKILL.md +38 -15
  130. package/skills/direct/SKILL.md +29 -9
  131. package/skills/domain-modeling/GLOSSARY-FORMAT.md +9 -9
  132. package/skills/domain-modeling/SKILL.md +14 -12
  133. package/skills/explorateur/SKILL.md +32 -8
  134. package/skills/grill/SKILL.md +3 -2
  135. package/skills/pitmaster/SKILL.md +80 -50
  136. package/skills/pitmaster/references/cadre.md +1 -1
  137. package/skills/pitmaster/references/consigne-agent.md +12 -11
  138. package/skills/pitmaster/references/tour.md +6 -5
  139. package/skills/relecteur/SKILL.md +13 -6
  140. package/skills/systematic-debugging/SKILL.md +281 -0
  141. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  142. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  143. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  144. package/skills/systematic-debugging/find-polluter.sh +72 -0
  145. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  146. package/skills/testwriter/SKILL.md +37 -31
  147. package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
  148. package/scripts/attente-a-l-arret.mjs +0 -114
  149. package/scripts/verrous/commande.mjs +0 -214
  150. package/scripts/verrous/verrou.mjs +0 -311
@@ -3,7 +3,7 @@
3
3
  // Mechanism: greffon.md, §5.1 and §5.2. Played by the session start (scripts/session-start.sh),
4
4
  // which writes what it says to the session.
5
5
  //
6
- // npx grillhouse superviseur <racine>
6
+ // npx grillhouse superviseur <racine> [<source>]
7
7
  //
8
8
  // - Out of a git repository, in an agent's copy (a worktree whose git directory is not the common
9
9
  // one) and in a session of a role that the circuit launches (BEADS_ACTOR set), nothing is taken
@@ -12,11 +12,16 @@
12
12
  // copies, taken through scripts/verrou-de-fichier.mjs for the session's own process: the first
13
13
  // process above this one named `claude`, whatever stands between them; without one, the first
14
14
  // that is not a shell (sh, bash, dash, zsh). It holds as long as that process lives.
15
- // - Free, or held by a process that is gone: taken, nothing said. Held by the session itself (a
16
- // compaction or a /clear): kept, nothing said, circuits included. Held by another live session:
17
- // the section « ## Un autre superviseur tient ce dépôt » names its process and since when, and
18
- // asks to say so to the owner and to launch no circuit.
19
- // - The session whose opening takes the lock (`circuitsALOuverture`) receives « ## Les questions
15
+ // - <source> is the one of the SessionStart hook (`startup` without one). Free, or held by a
16
+ // process that is gone: taken. Held by the session itself: kept, and nothing is said after a
17
+ // compaction or a resume. After a /clear, the session that holds the lock receives « ## Reprise
18
+ // de la supervision après un /clear » (load `grillhouse:pitmaster`, take up the note of
19
+ // resumption, no whole round, put the owner's pending question again at the first turn), then
20
+ // what a session that takes the lock receives. Held by another live session: the section « ## Un
21
+ // autre superviseur tient ce dépôt » names its process and since when, and asks to say so to the
22
+ // owner and to launch no circuit. A declared milestone ends with the context that declared it: it
23
+ // is removed at every opening of the holder but after a compaction.
24
+ // - The session whose opening takes the lock (`ouvertureDuSuperviseur`) receives « ## Les questions
20
25
  // des circuits », then, when the repository has circuits (read from the Temporal server in one
21
26
  // call, scripts/circuits-du-serveur.mjs), « ## Les circuits du dépôt »: each circuit that runs;
22
27
  // each circuit stopped on a question, with the command that answers it; each circuit ended
@@ -24,34 +29,56 @@
24
29
  // written, else `--depuis <testwriter|developpeur> --contexte <texte>`); a server that does not
25
30
  // answer is said; then « ## La file des tickets », the tickets of the queue without their
26
31
  // section « ## Architecture », which the queue never starts (scripts/file-des-tickets.mjs).
32
+ // Last, « ## La note de reprise » gives the note of resumption, when one is written.
27
33
  // Exit 0, whatever it finds.
28
34
  //
29
- // npx grillhouse superviseur --relever [<dossier>]
35
+ // npx grillhouse superviseur --jalon <fichier>
36
+ // npx grillhouse superviseur --question <fichier>
37
+ //
38
+ // - Played by the session that holds the lock, from the root of the repository. The note of
39
+ // resumption, one per repository, is `<git common dir>/grillhouse-reprise.md`. `--jalon` replaces
40
+ // it whole by the text of <fichier> and declares a milestone, which replaces the one before
41
+ // (`<git common dir>/grillhouse-jalon.json`); `--question` adds the text at its end, creating it,
42
+ // and declares nothing. Exit 2 and the reason on the error stream, nothing written, on a file
43
+ // that is absent or empty, a session that does not hold the lock, a session of a role or a copy.
44
+ //
45
+ // npx grillhouse superviseur --renouveler <dossier> <arretA> <messageA>
46
+ //
47
+ // - Played by the greffon at each period: writes the message of resumption when the renewal is due
48
+ // (`renouvellement`), nothing otherwise.
49
+ //
50
+ // npx grillhouse superviseur --relever [<dossier>] [--compaction]
30
51
  //
31
52
  // - One reading of the circuits for the greffon (mods/grillhouse/hooks/register.tsx), which runs
32
53
  // it at each period and submits what it writes. It reads and writes nothing unless the session
33
54
  // that runs it holds the lock; a lock whose process is gone is taken over by the session that
34
55
  // reads. It writes the message (`texteDesQuestions`) when `relever` gives something, nothing
35
- // otherwise; exit 1 and the fault on the error stream when `grillhouse.rappel` is at fault.
56
+ // otherwise; exit 1 and the fault on the error stream when `grillhouse.rappel` of the project is
57
+ // at fault, or when the reading of another project of the group fails, the message of the others
58
+ // then written all the same. The message ends with the request to write the note and declare a
59
+ // milestone after a compaction (`--compaction`), and once for each night
60
+ // (`grillhouse.plageDeNuit`) at a reading where no question of a circuit waits for the
61
+ // supervisor.
36
62
  // - `superviseur --lue <dossier> <lueA> <envoyeesAvant>` marks read the questions sent up to
37
63
  // `envoyeesAvant`; `superviseur --chez-le-responsable <dossier> <ticket>` marks a question
38
64
  // carried to the owner: silent until the circuit answers.
39
65
  // - `relever` is the one function of the reading, of the re-presentation and of the file of the
40
66
  // stops gone up: a question that never went up, or was read <rappelMs> ago (`grillhouse.rappel`
41
67
  // minutes, 10 by default, scripts/circuits-cles.mjs), is given once per due time while its
42
- // circuit stands on the same stop; one answered leaves the file
68
+ // circuit stands on the same stop; one addressed to the owner goes up once, without reminder,
69
+ // and the opening lists it; one answered leaves the file
43
70
  // `.claude/worktrees/questions-remontees.json`. A stop is kept there by its ticket, the run of
44
71
  // its workflow, the rank of its question in that run and its stop, with the times of the first
45
- // going up and of the last presentation. The end of a circuit integrated is given once
46
- // (`integre`), kept in `.claude/worktrees/integrations-rendues.json`, and the alert of the CI of
47
- // main (a red, or a CI not read, scripts/ci-de-main.mjs) once per passage
48
- // (`.claude/worktrees/ci-de-main-rendue.json`), cleared at the next green.
72
+ // going up and of the last presentation. The alert of the CI of main (a red, or a CI not read,
73
+ // scripts/ci-de-main.mjs) is given once per passage (`.claude/worktrees/ci-de-main-rendue.json`),
74
+ // cleared at the next green. A circuit integrated gives nothing: it is read on the board.
49
75
  // - The reading covers the project and each other project of its group (`grillhouse.groupe`) that
50
76
  // no other live session of supervision holds, each under its name and its folder.
51
77
  import { spawnSync } from 'node:child_process';
52
- import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
78
+ import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
53
79
  import path from 'node:path';
54
80
  import { pathToFileURL } from 'node:url';
81
+ import { nuitEnCours, plageDeNuit } from './bilan.mjs';
55
82
  import { lireEtOuvrirLeDefautDeMain } from './ci-de-main.mjs';
56
83
  import { lacherVerrou, prendreVerrou } from './verrou-de-fichier.mjs';
57
84
  import { vivant } from './mesure/base-de-passe.mjs';
@@ -65,7 +92,14 @@ import {
65
92
  } from './tableau.mjs';
66
93
  import { rappelDuProjet, reglageDuRappel } from './circuits-cles.mjs';
67
94
  import { lireGroupe } from './groupe-cles.mjs';
68
- import { etapeDuCircuit, libelle, REPONSES, sansLesReponses, SUPERVISEUR } from './etapes.mjs';
95
+ import {
96
+ etapeDuCircuit,
97
+ libelle,
98
+ REPONSES,
99
+ RESPONSABLE,
100
+ sansLesReponses,
101
+ SUPERVISEUR,
102
+ } from './etapes.mjs';
69
103
  import { sigleDuProjet } from './sigle-du-projet.mjs';
70
104
  import {
71
105
  enFileSansArchitecture,
@@ -76,6 +110,15 @@ import {
76
110
  } from './file-des-tickets.mjs';
77
111
 
78
112
  const VERROU_SUPERVISEUR = 'grillhouse-superviseur.lock';
113
+ // In the common directory of git: the note of resumption of the supervisor, its declared milestone,
114
+ // and the start of the last night whose request was given.
115
+ const NOTE_DE_REPRISE = 'grillhouse-reprise.md';
116
+ const JALON = 'grillhouse-jalon.json';
117
+ const DEMANDE_DE_NUIT = 'grillhouse-demande-de-nuit.json';
118
+ // The message the greffon submits once the /clear of a renewal is done; the note, the questions and
119
+ // the circuits come with the opening.
120
+ const MESSAGE_DE_REPRISE =
121
+ "Reprends la supervision : ta séance vient de se renouveler au jalon que tu as déclaré. L'ouverture te donne la note de reprise, les questions et les circuits : suis-la.";
79
122
  const COQUILLES = new Set(['sh', 'bash', 'dash', 'zsh']);
80
123
  // The name of the process of a session of the engine.
81
124
  const MOTEUR = 'claude';
@@ -162,16 +205,21 @@ export function horsAttente(tickets, maintenant) {
162
205
 
163
206
  // Of the tickets <ids> of the repository at <racine>, those whose question does not wait now
164
207
  // (`horsAttente`); null when bd does not read them (unknown, never « none »): a machine under
165
- // load can take seconds to answer.
208
+ // load can take seconds to answer. One listing reads them all, whatever their number: `bd show`
209
+ // costs more than a second per ticket and overruns the time given when many circuits stand.
166
210
  export function ticketsHorsAttente(racine, ids) {
167
- const r = spawnSync('bd', ['show', ...ids, '--json'], {
211
+ const r = spawnSync('bd', ['list', '--all', '--limit', '0', '--id', ids.join(','), '--json'], {
168
212
  cwd: racine,
169
213
  encoding: 'utf8',
170
214
  timeout: 30_000,
171
215
  maxBuffer: 256 * 1024 * 1024,
172
216
  });
173
217
  try {
174
- return horsAttente(JSON.parse(r.stdout), Date.now());
218
+ const demandes = new Set(ids);
219
+ return horsAttente(
220
+ JSON.parse(r.stdout).filter(t => demandes.has(t.id)),
221
+ Date.now()
222
+ );
175
223
  } catch {
176
224
  return null;
177
225
  }
@@ -187,21 +235,6 @@ const ou = c => {
187
235
  // of the circuits (scripts/tableau.mjs reads it: its alerts).
188
236
  const etatsDe = racine => path.join(racine, '.claude', 'worktrees');
189
237
 
190
- // The integrations given by the waits of the repository at <racine>: `depuis`, the time (ms) of
191
- // the last reading of the last wait, from which an integration is new; `rendues`, the keys of the
192
- // integrations it gave, ended at that time or after. Absent or unreadable: none since <maintenant>.
193
- const integrationsDe = racine => path.join(etatsDe(racine), 'integrations-rendues.json');
194
- function lireLesIntegrations(racine, maintenant) {
195
- try {
196
- const lu = JSON.parse(readFileSync(integrationsDe(racine), 'utf8'));
197
- if (Number.isFinite(lu?.depuis) && Array.isArray(lu?.rendues)) {
198
- return { depuis: lu.depuis, rendues: new Set(lu.rendues.map(String)) };
199
- }
200
- } catch {
201
- // none yet
202
- }
203
- return { depuis: maintenant, rendues: new Set() };
204
- }
205
238
  // The alert of the CI of main of the project at <racine> (scripts/ci-de-main.mjs), read for the
206
239
  // supervisor: `{ cle, texte }` for a red or a CI not read, null for a green (the alert clears),
207
240
  // undefined for a project with no CI to read. The lots entered since the last green are named by
@@ -257,19 +290,6 @@ function releverLaCiDeMain(racine, alerte, toutes) {
257
290
  ];
258
291
  }
259
292
 
260
- // A file that cannot be written never costs the batch: the next wait reads the former one.
261
- function ecrireLesIntegrations(racine, depuis, rendues) {
262
- const f = integrationsDe(racine);
263
- try {
264
- mkdirSync(path.dirname(f), { recursive: true });
265
- const provisoire = `${f}.${process.pid}`;
266
- writeFileSync(provisoire, `${JSON.stringify({ depuis, rendues: [...rendues].sort() })}\n`);
267
- renameSync(provisoire, f);
268
- } catch {
269
- // kept as it was
270
- }
271
- }
272
-
273
293
  // The file of the stops gone up as text: each stop with its key, its times, and its reading and its
274
294
  // mark when it has them, sorted by key.
275
295
  const enTexteDesRemontees = liste =>
@@ -350,23 +370,22 @@ export function marquerChezLeResponsable(racine, { cle, depuisA }) {
350
370
  }
351
371
 
352
372
  /**
353
- * One reading of the circuits <circuits> (those integrated included) of the repository at <racine>,
373
+ * One reading of the circuits <circuits> of the repository at <racine>,
354
374
  * at <maintenant> ms, under the lock of the file of the stops gone up; what the greffon of the
355
375
  * session of supervision submits, and the opening lists. Each stop that waits for the supervisor
356
- * and never went up, or whose last presentation is <rappelMs> ms old or more (<toutes>: every
357
- * one), is given, its ticket <fermes> gives closed left out (bd is asked of those alone); a stop
376
+ * and never went up, or whose last presentation is <rappelMs> ms old or more, is given (a
377
+ * question addressed to the owner goes up once and is never given again; <toutes>: every
378
+ * one), its ticket <fermes> gives closed left out (bd is asked of those alone); a stop
358
379
  * given is presented now, and one that goes up has its `depuis` set now. The file is written whole
359
380
  * with the stops that still stand, their circuit waiting for the supervisor: a question answered
360
- * so leaves it, and the next stop of its circuit is new. The end of a circuit integrated since the
361
- * last reading is given once (`integre`; the file of the integrations holds the time of that
362
- * reading), and the alert of the CI of main <ciDeMain> (`{ cle, texte }`; null at a green, which
363
- * clears it; undefined when it is not read, which keeps what was given) once per passage. The
364
- * result is the questions given, each marked `representee` when it comes back, then the ends, then
365
- * the alert of the CI of main.
381
+ * so leaves it, and the next stop of its circuit is new. The alert of the CI of main <ciDeMain>
382
+ * (`{ cle, texte }`; null at a green, which clears it; undefined when it is not read, which keeps
383
+ * what was given) is given once per passage. A circuit integrated gives nothing. The result is the
384
+ * questions given, each marked `representee` when it comes back, then the alert of the CI of main.
366
385
  * @param {string} racine
367
386
  * @param {import('./circuits-du-serveur.mjs').CircuitDuServeur[]} circuits
368
387
  * @param {{ fermes: (racine: string, ids: string[]) => Set<string> | null, maintenant: number, rappelMs: number, toutes?: boolean, ciDeMain?: { cle: string, texte: string } | null }} options
369
- * @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean, integre?: boolean }[]}
388
+ * @returns {{ ticket: string, etape: string, question: string, qui: string, commande: string, cle: string, representee?: boolean }[]}
370
389
  */
371
390
  export function relever(
372
391
  racine,
@@ -379,34 +398,21 @@ export function relever(
379
398
  // Held for one reading of the circuits: older than that, abandoned.
380
399
  prendreVerrou(verrou, { attendre: true, perime: 30_000 });
381
400
  try {
382
- const { depuis: depuisIntegrations, rendues } = lireLesIntegrations(racine, maintenant);
383
- const integres = circuits
384
- .filter(
385
- c => c.integre && c.fin !== null && c.fin >= depuisIntegrations && !rendues.has(cleDe(c))
386
- )
387
- .map(enFin)
388
- .sort((a, b) => a.ticket.localeCompare(b.ticket, 'en'));
389
- const fins = new Map(circuits.map(c => [cleDe(c), c.fin]));
390
- ecrireLesIntegrations(
391
- racine,
392
- maintenant,
393
- [...rendues, ...integres.map(i => i.cle)].filter(
394
- k => (fins.get(k) ?? -Infinity) >= maintenant
395
- )
396
- );
397
401
  const rouges = ciDeMain === undefined ? [] : releverLaCiDeMain(racine, ciDeMain, toutes);
398
- circuits = circuits.filter(c => !c.integre);
399
402
  const avant = new Map(lireLesRemontees(racine, maintenant).map(r => [r.cle, r]));
400
403
  const debout = questionsEnAttente(racine, circuits, { fermes: aucunFerme });
401
- // A question comes back from its reading, never from its sending: one read, not carried to the
402
- // owner, whose delay has passed since its reading. One still in the queue (sent, unread) or
403
- // carried to the owner is never given again.
404
+ // A question comes back from its reading, never from its sending: one read, waiting for the
405
+ // supervisor, not carried to the owner, whose delay has passed since its reading. One still in
406
+ // the queue (sent, unread), addressed to the owner or carried to him is never given again.
404
407
  const aRendre = debout.filter(q => {
405
408
  const r = avant.get(q.cle);
406
409
  return (
407
410
  toutes ||
408
411
  !r ||
409
- (estLue(r) && r.chez === undefined && maintenant - r.lue >= rappelMs)
412
+ (q.qui !== RESPONSABLE &&
413
+ estLue(r) &&
414
+ r.chez === undefined &&
415
+ maintenant - r.lue >= rappelMs)
410
416
  );
411
417
  });
412
418
  const fermesDe = aRendre.length
@@ -442,7 +448,7 @@ export function relever(
442
448
  })
443
449
  );
444
450
  ecrireLesRemontees(racine, ecrit, debout.length === 0 && avant.size === 0);
445
- return [...rendu, ...integres, ...rouges];
451
+ return [...rendu, ...rouges];
446
452
  } finally {
447
453
  lacherVerrou(verrou);
448
454
  }
@@ -464,17 +470,6 @@ const enQuestion = c => ({
464
470
  arret: c.arret,
465
471
  });
466
472
 
467
- // The end of the circuit <c> integrated, given once by the wait: its ticket, its step, and its key.
468
- const enFin = c => ({
469
- ticket: c.ticket,
470
- etape: '5 Intégration',
471
- question: 'son lot est sur main.',
472
- qui: SUPERVISEUR,
473
- commande: '',
474
- cle: cleDe(c),
475
- integre: true,
476
- });
477
-
478
473
  // Of the circuits <lus> of the repository at <racine>, those whose ticket <fermes> does not give
479
474
  // closed, sorted by ticket.
480
475
  function enAttente(lus, racine, fermes) {
@@ -571,19 +566,13 @@ export const ligneDeQuestion = (q, o = {}) => {
571
566
  /**
572
567
  * The message the greffon submits to the session of supervision for the questions <questions> of
573
568
  * one reading (`relever`), and the lines of the opening: for each one, its ticket, step, who must
574
- * answer it, its question and the command that answers it; then each end of a circuit integrated
575
- * (`integre`), its ticket and its step. A question presented again (`representee`) says that it
576
- * still waits for an answer.
577
- * @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean, integre?: boolean }[]} questions
569
+ * answer it, its question and the command that answers it. A question presented again
570
+ * (`representee`) says that it still waits for an answer.
571
+ * @param {{ ticket: string, etape: string, question: string, qui: string, commande: string, representee?: boolean }[]} questions
578
572
  * @returns {string}
579
573
  */
580
574
  export function texteDesQuestions(questions, o = {}) {
581
- const fins = questions.filter(q => q.integre);
582
- const attente = questions.filter(q => !q.integre);
583
- return [
584
- ...attente.map(q => ligneDeQuestion(q, o)),
585
- ...fins.map(q => `${o.sigle ? `[${o.sigle}] ` : ''}Intégré · ${q.ticket}`),
586
- ].join('\n');
575
+ return questions.map(q => ligneDeQuestion(q, o)).join('\n');
587
576
  }
588
577
 
589
578
  /**
@@ -602,7 +591,7 @@ export function texteDesQuestions(questions, o = {}) {
602
591
  * then those whose lot is already on main (`enFileSurMain`, main read by <surMainDe>,
603
592
  * `lotEstSurMain` by default), which it never starts again.
604
593
  * @param {string} racine the root of the repository
605
- * The circuits are read once, by <circuitsDe> (one call to the Temporal server,
594
+ * The circuits are read once, by <circuitsDe> (lists of the Temporal server that it filters,
606
595
  * scripts/circuits-du-serveur.mjs, by default); a server that does not answer is said, and no
607
596
  * question goes up.
608
597
  * @param {{ fermes?: (racine: string, ids: string[]) => Set<string> | null,
@@ -631,7 +620,6 @@ export async function circuitsALOuverture(
631
620
  ? `${e.message} : les circuits ne se lisent pas.`
632
621
  : `Les circuits ne se lisent pas : ${message}.`;
633
622
  }
634
- ecrireLesIntegrations(racine, Date.now(), []);
635
623
  const ouverteA = Date.now();
636
624
  const questions = circuits
637
625
  ? relever(racine, circuits, {
@@ -640,7 +628,7 @@ export async function circuitsALOuverture(
640
628
  rappelMs: rappelDuProjet(racine) * 60_000,
641
629
  toutes: true,
642
630
  ciDeMain: ciDeMainDe(racine),
643
- }).filter(q => !q.integre)
631
+ })
644
632
  : [];
645
633
  // The opening lists every question that waits: the session reads them, and their reminder runs
646
634
  // from now (a question sent to a closed session, or whose message was never recognised, included).
@@ -675,7 +663,7 @@ export async function circuitsALOuverture(
675
663
  );
676
664
  return [
677
665
  '## Les questions des circuits',
678
- "Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur, et chaque fin de circuit, une fois ; il n'y a aucune attente à lancer. Une question sans réponse revient une fois lue, à intervalle réglable depuis sa lecture (`grillhouse.rappel`, 10 min par défaut) : ta réponse au circuit l'acquitte, et répondue elle ne revient plus ; une question que tu as portée au responsable se tait par `npx grillhouse circuit <ticket> --chez-le-responsable`, jusqu'à la réponse du circuit. Tu ne te mets pas en attente du responsable tant qu'une question d'un circuit attend ta réponse : le crochet de fin de tour te le rappelle. Les questions en attente sont listées ci-dessous.",
666
+ "Le greffon de ta séance pousse dans la file de tes messages chaque question neuve d'un circuit du dépôt, quel que soit son lanceur ; il n'y a aucune attente à lancer. Une question sans réponse au superviseur revient une fois lue, à intervalle réglable depuis sa lecture (`grillhouse.rappel`, 10 min par défaut) : ta réponse au circuit l'acquitte, et répondue elle ne revient plus ; une question que tu as portée au responsable se tait par `npx grillhouse circuit <ticket> --chez-le-responsable`, jusqu'à la réponse du circuit ; une question adressée au responsable part une fois, pour que tu la lui portes, et ne revient pas. Tu ne te mets pas en attente du responsable tant qu'une question d'un circuit attend ta réponse. Les questions en attente sont listées ci-dessous.",
679
667
  ...(panne ? ['', '## Les circuits du dépôt', panne] : []),
680
668
  ...(nommes.length ? ['', '## Les circuits du dépôt', ...nommes.map(n => n.ligne)] : []),
681
669
  ...(questions.length ? ['', `Les réponses à une question : ${REPONSES}`] : []),
@@ -698,41 +686,213 @@ const git = (racine, ...args) =>
698
686
  encoding: 'utf8',
699
687
  });
700
688
 
689
+ // Where the session of supervision of the directory <dossier> stands: the common directory of git
690
+ // and the lock; `refus` says why <dossier> or the session has none (a role's session, out of git, a
691
+ // copy).
692
+ function depotDuSuperviseur(dossier, env) {
693
+ if (env.BEADS_ACTOR) {
694
+ return { refus: "la séance d'un rôle ne supervise pas" };
695
+ }
696
+ const r = git(dossier, '--git-dir', '--git-common-dir');
697
+ if (r.status !== 0) {
698
+ return { refus: `${dossier} n'est pas dans un dépôt git` };
699
+ }
700
+ const [dossierGit, commun] = r.stdout.trim().split('\n');
701
+ if (path.resolve(dossierGit) !== path.resolve(commun)) {
702
+ return { refus: 'une copie de ticket ne supervise pas : joue la commande à la racine du dépôt' };
703
+ }
704
+ return { commun, verrou: path.join(commun, VERROU_SUPERVISEUR) };
705
+ }
706
+
707
+ // The process the lock <verrou> names; null when no lock reads.
708
+ function tenantDe(verrou) {
709
+ try {
710
+ const pid = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
711
+ return Number.isInteger(pid) ? pid : null;
712
+ } catch {
713
+ return null;
714
+ }
715
+ }
716
+
717
+ // `depotDuSuperviseur` for the session that holds the lock alone, its process in `tenant`.
718
+ function laSeanceQuiTient(dossier, env) {
719
+ const depot = depotDuSuperviseur(dossier, env);
720
+ if (depot.refus) {
721
+ return depot;
722
+ }
723
+ const tenant = tenantDe(depot.verrou);
724
+ return tenant !== null && estAuDessus(tenant)
725
+ ? { ...depot, tenant }
726
+ : { refus: 'cette séance ne tient pas le verrou du superviseur' };
727
+ }
728
+
729
+ // Writes <texte> whole into <f>, by a rename.
730
+ function ecrireEntier(f, texte) {
731
+ const provisoire = `${f}.${process.pid}`;
732
+ writeFileSync(provisoire, texte);
733
+ renameSync(provisoire, f);
734
+ }
735
+
736
+ function lireJson(f) {
737
+ try {
738
+ return JSON.parse(readFileSync(f, 'utf8'));
739
+ } catch {
740
+ return null;
741
+ }
742
+ }
743
+
744
+ function lireTexte(f) {
745
+ try {
746
+ return readFileSync(f, 'utf8');
747
+ } catch {
748
+ return '';
749
+ }
750
+ }
751
+
752
+ // The gesture of the holder of the lock on the note: <ecrire> is given its session and the text of
753
+ // <fichier>. Code 2 and the reason, nothing written, when the session or the file is refused.
754
+ function surLaNote(dossier, fichier, env, ecrire) {
755
+ const session = laSeanceQuiTient(dossier, env);
756
+ if (session.refus) {
757
+ return { code: 2, raison: session.refus };
758
+ }
759
+ let texte;
760
+ try {
761
+ texte = readFileSync(fichier, 'utf8');
762
+ } catch {
763
+ return { code: 2, raison: `le fichier ${fichier} ne se lit pas` };
764
+ }
765
+ if (!texte.trim()) {
766
+ return { code: 2, raison: `le fichier ${fichier} est vide` };
767
+ }
768
+ ecrire(session, texte);
769
+ return { code: 0, raison: '' };
770
+ }
771
+
772
+ /**
773
+ * The session that holds the lock of the supervisor of <dossier> declares a milestone: the text of
774
+ * <fichier> replaces its note of resumption whole, and the milestone, which holds for the context
775
+ * that declares it, replaces the one before (`superviseur --jalon`).
776
+ * @param {string} dossier
777
+ * @param {string} fichier
778
+ * @param {{ env?: Record<string, string | undefined> }} [options]
779
+ * @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
780
+ * refusal
781
+ */
782
+ export async function declarerLeJalon(dossier, fichier, { env = process.env } = {}) {
783
+ return surLaNote(dossier, fichier, env, ({ commun, tenant }, texte) => {
784
+ ecrireEntier(path.join(commun, NOTE_DE_REPRISE), texte);
785
+ ecrireEntier(path.join(commun, JALON), `${JSON.stringify({ declareA: Date.now(), tenant })}\n`);
786
+ });
787
+ }
788
+
789
+ /**
790
+ * The session that holds the lock adds the text of <fichier> at the end of its note of resumption,
791
+ * which it creates when there is none; no milestone is declared (`superviseur --question`).
792
+ * @param {string} dossier
793
+ * @param {string} fichier
794
+ * @param {{ env?: Record<string, string | undefined> }} [options]
795
+ * @returns {Promise<{ code: number, raison: string }>} code 2 and its reason, nothing written, on a
796
+ * refusal
797
+ */
798
+ export async function ajouterLaQuestion(dossier, fichier, { env = process.env } = {}) {
799
+ return surLaNote(dossier, fichier, env, ({ commun }, texte) => {
800
+ const note = path.join(commun, NOTE_DE_REPRISE);
801
+ const avant = lireTexte(note);
802
+ const joint = avant ? `${avant.replace(/\n*$/, '')}\n\n` : '';
803
+ ecrireEntier(note, `${joint}${texte}`);
804
+ });
805
+ }
806
+
701
807
  /**
702
- * The check of the supervisor at the opening of a session in <racine>: what it says (empty when
703
- * nothing), the lock taken when it is free.
704
- * @param {string} racine the directory the session opens in
705
- * @param {{ env?: Record<string, string | undefined> }} options
808
+ * The message of resumption when the renewal of the session of supervision of <dossier> is due,
809
+ * empty otherwise (`superviseur --renouveler`): the session holds the lock, a milestone it declared
810
+ * stands, and a quiet Stop (<arretA>, ms, 0 without one) is later than it. A message of the owner
811
+ * (<messageA>, ms, 0 without one) later than the declaration cancels the milestone. The reading
812
+ * keeps a milestone that is due: the opening that follows the /clear removes it.
813
+ * @param {string} dossier
814
+ * @param {{ arretA: number, messageA: number, env?: Record<string, string | undefined> }} options
706
815
  * @returns {Promise<string>}
707
816
  */
708
- async function superviseur(racine, { env = process.env } = {}) {
709
- if (env.BEADS_ACTOR) {
817
+ export async function renouvellement(dossier, { arretA, messageA, env = process.env }) {
818
+ const session = laSeanceQuiTient(dossier, env);
819
+ if (session.refus) {
710
820
  return '';
711
821
  }
712
- const r = git(racine, '--git-dir', '--git-common-dir');
713
- if (r.status !== 0) {
822
+ const f = path.join(session.commun, JALON);
823
+ const jalon = lireJson(f);
824
+ if (!jalon || jalon.tenant !== session.tenant) {
714
825
  return '';
715
826
  }
716
- const [dossierGit, commun] = r.stdout.trim().split('\n');
717
- if (path.resolve(dossierGit) !== path.resolve(commun)) {
827
+ if (messageA > jalon.declareA) {
828
+ rmSync(f, { force: true });
718
829
  return '';
719
830
  }
720
- const verrou = path.join(commun, VERROU_SUPERVISEUR);
721
- const moi = seance();
722
- const tenant = () => {
723
- try {
724
- return Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
725
- } catch {
726
- return null;
727
- }
728
- };
729
- if (tenant() === moi) {
831
+ return arretA > jalon.declareA ? MESSAGE_DE_REPRISE : '';
832
+ }
833
+
834
+ // The section the opening gives of the note of resumption <note>; empty when none is written.
835
+ function laNote(note) {
836
+ const texte = lireTexte(note).trimEnd();
837
+ return texte
838
+ ? [
839
+ '## La note de reprise',
840
+ `Elle est au fichier \`${note}\` : lis-le en entier si ce texte est coupé.`,
841
+ '',
842
+ texte,
843
+ ].join('\n')
844
+ : '';
845
+ }
846
+
847
+ // What the opening that follows a /clear asks, before the circuits and the note.
848
+ const APRES_CLEAR = [
849
+ '## Reprise de la supervision après un /clear',
850
+ 'Charge la compétence `grillhouse:pitmaster`, puis reprends la note de reprise donnée plus bas ; ne fais aucun tour complet.',
851
+ 'À ton premier tour, quel que soit le message qui l’ouvre, repose au responsable la question que la note tient en attente.',
852
+ ].join('\n');
853
+
854
+ /**
855
+ * The check of the supervisor at the opening of a session in <dossier> (greffon.md, §5.2): what it
856
+ * says (empty when nothing), the lock taken when it is free. <source> is the one of the
857
+ * SessionStart hook. The session that takes the lock, and the holder after a /clear, receive the
858
+ * circuits and the note of resumption; every opening of the holder but after a compaction removes
859
+ * the declared milestone.
860
+ * @param {string} dossier the directory the session opens in
861
+ * @param {{ source?: string, env?: Record<string, string | undefined>, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
862
+ * @returns {Promise<string>}
863
+ */
864
+ export async function ouvertureDuSuperviseur(
865
+ dossier,
866
+ { source = 'startup', env = process.env, circuitsDe = circuitsDuServeur } = {}
867
+ ) {
868
+ const depot = depotDuSuperviseur(dossier, env);
869
+ if (depot.refus) {
730
870
  return '';
731
871
  }
732
- if (prendreVerrou(verrou, { attendre: false, pid: moi })) {
733
- return circuitsALOuverture(path.dirname(commun));
872
+ const { commun, verrou } = depot;
873
+ const moi = seance();
874
+ const tenait = tenantDe(verrou) === moi;
875
+ if (!tenait && !prendreVerrou(verrou, { attendre: false, pid: moi })) {
876
+ return unAutreSuperviseur(verrou, moi);
734
877
  }
735
- const autre = tenant();
878
+ if (source !== 'compact') {
879
+ rmSync(path.join(commun, JALON), { force: true });
880
+ }
881
+ if (tenait && source !== 'clear') {
882
+ return '';
883
+ }
884
+ return [
885
+ source === 'clear' ? APRES_CLEAR : '',
886
+ await circuitsALOuverture(path.dirname(commun), { circuitsDe }),
887
+ laNote(path.join(commun, NOTE_DE_REPRISE)),
888
+ ]
889
+ .filter(Boolean)
890
+ .join('\n\n');
891
+ }
892
+
893
+ // The section a session receives when another live one holds the lock <verrou>; empty when none does.
894
+ function unAutreSuperviseur(verrou, moi) {
895
+ const autre = tenantDe(verrou);
736
896
  if (!autre || autre === moi || !vivant(autre)) {
737
897
  return '';
738
898
  }
@@ -748,60 +908,103 @@ async function superviseur(racine, { env = process.env } = {}) {
748
908
  ].join('\n');
749
909
  }
750
910
 
911
+ // Whether a question of the circuits <circuits> of the repository at <racine> waits for the
912
+ // supervisor, read or not: neither addressed to the owner, nor carried to him, nor deferred to a
913
+ // later time, its ticket open. null when the tickets do not read.
914
+ function uneQuestionAttend(racine, circuits) {
915
+ const chez = new Set(
916
+ lireLesRemontees(racine, Date.now())
917
+ .filter(r => r.chez !== undefined)
918
+ .map(r => r.cle)
919
+ );
920
+ const debout = circuits.filter(
921
+ c => attendLeSuperviseur(c) && c.qui !== RESPONSABLE && !chez.has(cleDe(c))
922
+ );
923
+ if (!debout.length) {
924
+ return false;
925
+ }
926
+ const hors = ticketsHorsAttente(
927
+ racine,
928
+ debout.map(c => c.ticket)
929
+ );
930
+ return hors === null ? null : debout.some(c => !hors.has(c.ticket));
931
+ }
932
+
933
+ // The request the reading submits to the session, for the reason <raison>.
934
+ const demandeDuJalon = raison =>
935
+ `Jalon · ${raison} : écris ta note de reprise et déclare le jalon (compétence \`grillhouse:pitmaster\`), par \`npx grillhouse superviseur --jalon <fichier>\`.`;
936
+
751
937
  /**
752
938
  * One reading for the greffon of the session of supervision of the repository at <racine>
753
939
  * (`npx grillhouse superviseur --relever`): the message of what `relever` gives (the questions of
754
- * the circuits due, the ends of circuits, the reds of main), empty when it gives nothing, when the
940
+ * the circuits due, the reds of main), empty when it gives nothing, when the
755
941
  * circuits do not read, or when the session that runs it is not the one that holds the lock of the
756
942
  * supervisor (a role's session, an agent's copy, another project's, a session that took no lock).
757
943
  * The interval of the re-presentation is the key `grillhouse.rappel` of the project, applied at
758
944
  * each reading. The session reads too each other project of its group (`grillhouse.groupe`) that
759
945
  * no other live session of supervision holds (`voisinsSansSuperviseur`): its part follows, under
760
946
  * the name and the folder of that project, where its answers are played, with that project's own
761
- * interval and state.
947
+ * interval and state. A fault in the reading of one of these projects costs the others nothing: it
948
+ * is thrown once all are read, each project at fault named with its reason, the message of the
949
+ * others in the `texte` of the error. Last comes the request to write the note of resumption and
950
+ * declare a milestone: after a compaction (<compaction>), and once for each night of the project
951
+ * (`grillhouse.plageDeNuit`) at a reading where every project read says that no question waits for
952
+ * the supervisor.
762
953
  * @param {string} racine
763
- * @param {{ env?: Record<string, string | undefined>, circuitsDe?: (racine: string, options?: { integres?: boolean }) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
954
+ * @param {{ env?: Record<string, string | undefined>, compaction?: boolean, circuitsDe?: (racine: string) => Promise<import('./circuits-du-serveur.mjs').CircuitDuServeur[]> }} [options]
764
955
  * @returns {Promise<string>}
765
- * @throws {Error} `grillhouse.rappel` is at fault, named with its value
956
+ * @throws {Error} `grillhouse.rappel` of the project of the session is at fault, named with its
957
+ * value; or the reading of another project of the group failed (its `texte`: the others' message)
766
958
  */
767
959
  export async function releverPourLeGreffon(
768
960
  racine,
769
- { env = process.env, circuitsDe = circuitsDuServeur } = {}
961
+ { env = process.env, circuitsDe = circuitsDuServeur, compaction = false } = {}
770
962
  ) {
771
- if (env.BEADS_ACTOR) {
963
+ const depot = depotDuSuperviseur(racine, env);
964
+ if (depot.refus) {
772
965
  return '';
773
966
  }
774
- const r = git(racine, '--git-dir', '--git-common-dir');
775
- if (r.status !== 0) {
776
- return '';
777
- }
778
- const [dossierGit, commun] = r.stdout.trim().split('\n');
779
- if (path.resolve(dossierGit) !== path.resolve(commun)) {
780
- return '';
781
- }
782
- const verrou = path.join(commun, VERROU_SUPERVISEUR);
783
- let tenant = null;
784
- try {
785
- tenant = Number(/^(\d+)/.exec(readFileSync(verrou, 'utf8'))?.[1]);
786
- } catch {
967
+ const { commun, verrou } = depot;
968
+ let tenant = tenantDe(verrou);
969
+ if (tenant === null) {
787
970
  return '';
788
971
  }
789
972
  // A lock whose process is gone is taken over, as the opening does: the session that reads holds it.
790
- if (Number.isInteger(tenant) && !estAuDessus(tenant) && !vivant(tenant)) {
973
+ if (!estAuDessus(tenant) && !vivant(tenant)) {
791
974
  const moi = seance();
792
975
  tenant = prendreVerrou(verrou, { attendre: false, pid: moi }) ? moi : null;
793
976
  }
794
- if (!Number.isInteger(tenant) || !estAuDessus(tenant)) {
977
+ if (tenant === null || !estAuDessus(tenant)) {
795
978
  return '';
796
979
  }
797
- const parts = [await leReleveDe(racine, circuitsDe)];
980
+ const demandeNocturne = path.join(commun, DEMANDE_DE_NUIT);
981
+ const nuit = nuitEnCours(Date.now(), plageDeNuit(racine));
982
+ const aDemander = nuit !== null && lireJson(demandeNocturne)?.nuit !== nuit;
983
+ const apresCompaction = compaction ? demandeDuJalon('une compaction a eu lieu') : '';
984
+ const parts = [];
985
+ try {
986
+ parts.push(await leReleveDe(racine, circuitsDe, { nocturne: aDemander }));
987
+ } catch (e) {
988
+ throw Object.assign(e, { texte: apresCompaction });
989
+ }
990
+ const fautes = [];
798
991
  for (const p of voisinsSansSuperviseur(racine)) {
799
- const texte = await leReleveDe(p.chemin, circuitsDe, true);
800
- if (texte) {
801
- parts.push(texte);
992
+ try {
993
+ parts.push(await leReleveDe(p.chemin, circuitsDe, { voisin: true, nocturne: aDemander }));
994
+ } catch (e) {
995
+ fautes.push(`${path.basename(p.chemin)} : ${e.message}`);
802
996
  }
803
997
  }
804
- return parts.filter(Boolean).join('\n\n');
998
+ let demande = apresCompaction;
999
+ if (aDemander && !fautes.length && parts.every(p => p.attend === false)) {
1000
+ ecrireEntier(demandeNocturne, `${JSON.stringify({ nuit })}\n`);
1001
+ demande ||= demandeDuJalon('la nuit a commencé');
1002
+ }
1003
+ const texte = [...parts.map(p => p.texte), demande].filter(Boolean).join('\n\n');
1004
+ if (fautes.length) {
1005
+ throw Object.assign(new Error(fautes.join('\n')), { texte });
1006
+ }
1007
+ return texte;
805
1008
  }
806
1009
 
807
1010
  // The package.json of the project at <racine>; empty when it does not read.
@@ -813,19 +1016,22 @@ function paquetDe(racine) {
813
1016
  }
814
1017
  }
815
1018
 
816
- // The message of one reading of the project at <racine>, under its own interval
817
- // (`grillhouse.rappel`) and its own state of the questions presented; empty when it gives nothing
818
- // or when its circuits do not read. A faulty interval throws, the project named.
819
- async function leReleveDe(racine, circuitsDe, voisin = false) {
1019
+ // One reading of the project at <racine>, under its own interval (`grillhouse.rappel`) and its own
1020
+ // state of the questions presented: `texte`, its message, empty when it gives nothing or when its
1021
+ // circuits do not read; `attend`, read for the request of the night (<o.nocturne>), whether a
1022
+ // question waits for the supervisor (`uneQuestionAttend`), null when unknown. A faulty interval
1023
+ // throws, the project of the session named (a neighbour is named by the caller, as for any fault of
1024
+ // its reading).
1025
+ async function leReleveDe(racine, circuitsDe, { voisin = false, nocturne = false } = {}) {
820
1026
  const { minutes, faute } = reglageDuRappel(paquetDe(racine));
821
1027
  if (faute) {
822
- throw new Error(`${path.basename(racine)} : ${faute}`);
1028
+ throw new Error(voisin ? faute : `${path.basename(racine)} : ${faute}`);
823
1029
  }
824
1030
  let circuits;
825
1031
  try {
826
- circuits = await circuitsDe(racine, { integres: true });
1032
+ circuits = await circuitsDe(racine);
827
1033
  } catch {
828
- return '';
1034
+ return { texte: '', attend: null };
829
1035
  }
830
1036
  const lot = relever(racine, circuits, {
831
1037
  fermes: ticketsHorsAttente,
@@ -837,7 +1043,10 @@ async function leReleveDe(racine, circuitsDe, voisin = false) {
837
1043
  const projet = voisin
838
1044
  ? { sigle: sigleDuProjet(racine).sigle ?? path.basename(racine), dossier: racine }
839
1045
  : {};
840
- return lot.length ? texteDesQuestions(lot, projet) : '';
1046
+ return {
1047
+ texte: lot.length ? texteDesQuestions(lot, projet) : '',
1048
+ attend: nocturne ? uneQuestionAttend(racine, circuits) : null,
1049
+ };
841
1050
  }
842
1051
 
843
1052
  // The other projects of the group of the project at <racine> (`grillhouse.groupe`) that no other
@@ -872,13 +1081,40 @@ function racineDe(dossier) {
872
1081
  }
873
1082
 
874
1083
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
875
- if (process.argv[2] === '--relever') {
1084
+ if (process.argv[2] === '--jalon' || process.argv[2] === '--question') {
1085
+ // superviseur --jalon|--question <fichier> : played from the root of the repository.
1086
+ const geste = process.argv[2] === '--jalon' ? declarerLeJalon : ajouterLaQuestion;
1087
+ const { code, raison } = process.argv[3]
1088
+ ? await geste(process.cwd(), process.argv[3])
1089
+ : { code: 2, raison: 'le fichier manque' };
1090
+ if (raison) {
1091
+ process.stderr.write(`${process.argv[2]} : ${raison}.\n`);
1092
+ }
1093
+ process.exitCode = code;
1094
+ } else if (process.argv[2] === '--renouveler') {
1095
+ // superviseur --renouveler <dossier> <arretA> <messageA> (the greffon, at each period).
1096
+ const [, , , dossier, arretA, messageA] = process.argv;
1097
+ const texte = await renouvellement(dossier ?? process.cwd(), {
1098
+ arretA: Number(arretA),
1099
+ messageA: Number(messageA),
1100
+ });
1101
+ if (texte) {
1102
+ process.stdout.write(`${texte}\n`);
1103
+ }
1104
+ } else if (process.argv[2] === '--relever') {
1105
+ const args = process.argv.slice(3);
1106
+ const dossier = args.find(a => a !== '--compaction') ?? process.cwd();
876
1107
  try {
877
- const texte = await releverPourLeGreffon(racineDe(process.argv[3] ?? process.cwd()));
1108
+ const texte = await releverPourLeGreffon(racineDe(dossier), {
1109
+ compaction: args.includes('--compaction'),
1110
+ });
878
1111
  if (texte) {
879
1112
  process.stdout.write(`${texte}\n`);
880
1113
  }
881
1114
  } catch (e) {
1115
+ if (e.texte) {
1116
+ process.stdout.write(`${e.texte}\n`);
1117
+ }
882
1118
  process.stderr.write(`${e.message}\n`);
883
1119
  process.exitCode = 1;
884
1120
  }
@@ -916,7 +1152,9 @@ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
916
1152
  }
917
1153
  }
918
1154
  } else {
919
- const texte = await superviseur(process.argv[2] ?? process.cwd());
1155
+ const texte = await ouvertureDuSuperviseur(process.argv[2] ?? process.cwd(), {
1156
+ source: process.argv[3] || undefined,
1157
+ });
920
1158
  if (texte) {
921
1159
  process.stdout.write(`${texte}\n`);
922
1160
  }